|
|
| version 1.22, 2001/04/28 08:43:47 | version 1.26, 2001/05/11 17:45:10 |
|---|---|
| Line 25 | Line 25 |
| class MImage : public Methoded { | class MImage : public Methoded { |
| public: // VStateless_class | public: // VStateless_class |
| Value *create_new_value(Pool& pool) { return new(pool) VImage(pool); } | Value *create_new_value(Pool& pool) { return new(pool) VImage(pool); } |
| public: | public: |
| MImage(Pool& pool); | MImage(Pool& pool); |
| public: // Methoded | |
| bool used_directly() { return true; } | bool used_directly() { return true; } |
| }; | }; |
| Line 253 static size_t read_disk(void*& buf, size | Line 254 static size_t read_disk(void*& buf, size |
| // methods | // methods |
| /// ^image:measure[DATA] | |
| static void _measure(Request& r, const String& method_name, MethodParams *params) { | static void _measure(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 297 static void append_attrib_pair(const Has | Line 297 static void append_attrib_pair(const Has |
| Value& value=*static_cast<Value *>(val); | Value& value=*static_cast<Value *>(val); |
| // src="a.gif" width=123 ismap[=-1] | // src="a.gif" width=123 ismap[=-1] |
| *ai.tag << " " << key; | *ai.tag << " " << key; |
| if(value.is_string() || value.as_double()>=0) | if(value.is_string() || value.as_int()>=0) |
| *ai.tag << "=\"" << value.as_string() << "\""; | *ai.tag << "=\"" << value.as_string() << "\""; |
| } | } |
| /** ^image.html[] | |
| ^image.html[hash] | |
| */ | |
| static void _html(Request& r, const String& method_name, MethodParams *params) { | static void _html(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 334 static gdImage *load(Request& r, const S | Line 331 static gdImage *load(Request& r, const S |
| const char *file_name_cstr=r.absolute(file_name).cstr(String::UL_FILE_NAME); | const char *file_name_cstr=r.absolute(file_name).cstr(String::UL_FILE_NAME); |
| if(FILE *f=fopen(file_name_cstr, "rb")) { | if(FILE *f=fopen(file_name_cstr, "rb")) { |
| gdImage& image=*new(pool) gdImage(pool); | gdImage& image=*new(pool) gdImage(pool); |
| image.CreateFromGif(f); | bool ok=image.CreateFromGif(f); |
| fclose(f); | fclose(f); |
| if(!ok) | |
| PTHROW(0, 0, | |
| &file_name, | |
| "is not in GIF format"); | |
| return ℑ | return ℑ |
| } else { | } else { |
| PTHROW(0, 0, | PTHROW(0, 0, |
| Line 346 static gdImage *load(Request& r, const S | Line 347 static gdImage *load(Request& r, const S |
| } | } |
| /// ^image.load[background.gif] | |
| static void _load(Request& r, const String& method_name, MethodParams *params) { | static void _load(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 359 static void _load(Request& r, const Stri | Line 359 static void _load(Request& r, const Stri |
| static_cast<VImage *>(r.self)->set(&file_name, width, height, &image); | static_cast<VImage *>(r.self)->set(&file_name, width, height, &image); |
| } | } |
| /** ^image.create[width;height] bgcolor=white | |
| ^image.create[width;height;bgcolor] | |
| */ | |
| static void _create(Request& r, const String& method_name, MethodParams *params) { | static void _create(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| int width=(int)r.process(params->get(0)).as_double(); | int width=r.process(params->get(0)).as_int(); |
| int height=(int)r.process(params->get(1)).as_double(); | int height=r.process(params->get(1)).as_int(); |
| int bgcolor_value=0xffFFff; | int bgcolor_value=0xffFFff; |
| if(params->size()>2) | if(params->size()>2) |
| bgcolor_value=(int)r.process(params->get(2)).as_double(); | bgcolor_value=r.process(params->get(2)).as_int(); |
| gdImage& image=*new(pool) gdImage(pool); | gdImage& image=*new(pool) gdImage(pool); |
| image.Create(width, height); | image.Create(width, height); |
| image.FilledRectangle(0, 0, width-1, height-1, image.Color(bgcolor_value)); | image.FilledRectangle(0, 0, width-1, height-1, image.Color(bgcolor_value)); |
| static_cast<VImage *>(r.self)->set(0, width, height, &image); | static_cast<VImage *>(r.self)->set(0, width, height, &image); |
| } | } |
| /// ^image.gif[] | |
| static void _gif(Request& r, const String& method_name, MethodParams *params) { | static void _gif(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 398 static void _gif(Request& r, const Strin | Line 394 static void _gif(Request& r, const Strin |
| r.write_no_lang(vfile); | r.write_no_lang(vfile); |
| } | } |
| /// ^image.line(x0;y0;x1;y1;color) | |
| static void _line(Request& r, const String& method_name, MethodParams *params) { | static void _line(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 409 static void _line(Request& r, const Stri | Line 404 static void _line(Request& r, const Stri |
| "does not contain an image"); | "does not contain an image"); |
| image->Line( | image->Line( |
| (int)r.process(params->get(0)).as_double(), | r.process(params->get(0)).as_int(), |
| (int)r.process(params->get(1)).as_double(), | r.process(params->get(1)).as_int(), |
| (int)r.process(params->get(2)).as_double(), | r.process(params->get(2)).as_int(), |
| (int)r.process(params->get(3)).as_double(), | r.process(params->get(3)).as_int(), |
| image->Color((int)r.process(params->get(4)).as_double())); | image->Color(r.process(params->get(4)).as_int())); |
| } | } |
| /// ^image.fill(x;y;color) | |
| static void _fill(Request& r, const String& method_name, MethodParams *params) { | static void _fill(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 427 static void _fill(Request& r, const Stri | Line 421 static void _fill(Request& r, const Stri |
| "does not contain an image"); | "does not contain an image"); |
| image->Fill( | image->Fill( |
| (int)r.process(params->get(0)).as_double(), | r.process(params->get(0)).as_int(), |
| (int)r.process(params->get(1)).as_double(), | r.process(params->get(1)).as_int(), |
| image->Color((int)r.process(params->get(2)).as_double())); | image->Color(r.process(params->get(2)).as_int())); |
| } | } |
| /// ^image.rectangle(x0;y0;x1;y1;color) | |
| static void _rectangle(Request& r, const String& method_name, MethodParams *params) { | static void _rectangle(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 443 static void _rectangle(Request& r, const | Line 436 static void _rectangle(Request& r, const |
| "does not contain an image"); | "does not contain an image"); |
| image->Rectangle( | image->Rectangle( |
| (int)r.process(params->get(0)).as_double(), | r.process(params->get(0)).as_int(), |
| (int)r.process(params->get(1)).as_double(), | r.process(params->get(1)).as_int(), |
| (int)r.process(params->get(2)).as_double(), | r.process(params->get(2)).as_int(), |
| (int)r.process(params->get(3)).as_double(), | r.process(params->get(3)).as_int(), |
| image->Color((int)r.process(params->get(4)).as_double())); | image->Color(r.process(params->get(4)).as_int())); |
| } | } |
| /// ^image.bar(x0;y0;x1;y1;color) | |
| static void _bar(Request& r, const String& method_name, MethodParams *params) { | static void _bar(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 461 static void _bar(Request& r, const Strin | Line 453 static void _bar(Request& r, const Strin |
| "does not contain an image"); | "does not contain an image"); |
| image->FilledRectangle( | image->FilledRectangle( |
| (int)r.process(params->get(0)).as_double(), | r.process(params->get(0)).as_int(), |
| (int)r.process(params->get(1)).as_double(), | r.process(params->get(1)).as_int(), |
| (int)r.process(params->get(2)).as_double(), | r.process(params->get(2)).as_int(), |
| (int)r.process(params->get(3)).as_double(), | r.process(params->get(3)).as_int(), |
| image->Color((int)r.process(params->get(4)).as_double())); | image->Color(r.process(params->get(4)).as_int())); |
| } | } |
| /// ^image.replace(color-source;color-dest)(x;y)... point coord pairs | |
| static void _replace(Request& r, const String& method_name, MethodParams *params) { | static void _replace(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 487 static void _replace(Request& r, const S | Line 478 static void _replace(Request& r, const S |
| gdImage::Point *p=(gdImage::Point *)pool.malloc(sizeof(gdImage::Point)*n); | gdImage::Point *p=(gdImage::Point *)pool.malloc(sizeof(gdImage::Point)*n); |
| for(int i=0; i<n; i++) { | for(int i=0; i<n; i++) { |
| p[i].x=(int)r.process(params->get(2+i*2+0)).as_double(); | p[i].x=r.process(params->get(2+i*2+0)).as_int(); |
| p[i].y=(int)r.process(params->get(2+i*2+1)).as_double(); | p[i].y=r.process(params->get(2+i*2+1)).as_int(); |
| } | } |
| image->FilledPolygonReplaceColor(p, n, | image->FilledPolygonReplaceColor(p, n, |
| image->Color((int)r.process(params->get(0)).as_double()), // src color | image->Color(r.process(params->get(0)).as_int()), // src color |
| image->Color((int)r.process(params->get(1)).as_double()));// dest color | image->Color(r.process(params->get(1)).as_int()));// dest color |
| } | } |
| /// ^image.polygon(color)(x;y)... point coord pairs | |
| static void _polygon(Request& r, const String& method_name, MethodParams *params) { | static void _polygon(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 514 static void _polygon(Request& r, const S | Line 504 static void _polygon(Request& r, const S |
| gdImage::Point *p=(gdImage::Point *)pool.malloc(sizeof(gdImage::Point)*n); | gdImage::Point *p=(gdImage::Point *)pool.malloc(sizeof(gdImage::Point)*n); |
| for(int i=0; i<n; i++) { | for(int i=0; i<n; i++) { |
| p[i].x=(int)r.process(params->get(1+i*2+0)).as_double(); | p[i].x=r.process(params->get(1+i*2+0)).as_int(); |
| p[i].y=(int)r.process(params->get(1+i*2+1)).as_double(); | p[i].y=r.process(params->get(1+i*2+1)).as_int(); |
| } | } |
| image->Polygon(p, n, | image->Polygon(p, n, |
| image->Color((int)r.process(params->get(0)).as_double())); | image->Color(r.process(params->get(0)).as_int())); |
| } | } |
| /// ^image.polybar(color)(x;y)... point coord pairs | |
| static void _polybar(Request& r, const String& method_name, MethodParams *params) { | static void _polybar(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Line 540 static void _polybar(Request& r, const S | Line 529 static void _polybar(Request& r, const S |
| gdImage::Point *p=(gdImage::Point *)pool.malloc(sizeof(gdImage::Point)*n); | gdImage::Point *p=(gdImage::Point *)pool.malloc(sizeof(gdImage::Point)*n); |
| for(int i=0; i<n; i++) { | for(int i=0; i<n; i++) { |
| p[i].x=(int)r.process(params->get(1+i*2+0)).as_double(); | p[i].x=r.process(params->get(1+i*2+0)).as_int(); |
| p[i].y=(int)r.process(params->get(1+i*2+1)).as_double(); | p[i].y=r.process(params->get(1+i*2+1)).as_int(); |
| } | } |
| image->FilledPolygon(p, n, | image->FilledPolygon(p, n, |
| image->Color((int)r.process(params->get(0)).as_double())); | image->Color(r.process(params->get(0)).as_int())); |
| } | } |
| // font | // font |
| Line 614 public: | Line 603 public: |
| } | } |
| }; | }; |
| /** | |
| ^image.font[alPHAbet;font-file-name.gif](height) | |
| ^image.font[alPHAbet;font-file-name.gif](height;width) | |
| */ | |
| static void _font(Request& r, const String& method_name, MethodParams *params) { | static void _font(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| Value& valphabet=params->get_no_junction(0, "alphabet must not be code"); | Value& valphabet=params->get_no_junction(0, "alphabet must not be code"); |
| Value& file_name=params->get_no_junction(1, "file_name must not be code"); | Value& file_name=params->get_no_junction(1, "file_name must not be code"); |
| int height=(int)r.process(params->get(2)).as_double(); | int height=r.process(params->get(2)).as_int(); |
| int width=params->size()>3?(int)r.process(params->get(3)).as_double():0; | int width=params->size()>3?r.process(params->get(3)).as_int():0; |
| static_cast<VImage *>(r.self)->font=new(pool) Font(pool, | static_cast<VImage *>(r.self)->font=new(pool) Font(pool, |
| valphabet.as_string(), | valphabet.as_string(), |
| Line 633 static void _font(Request& r, const Stri | Line 618 static void _font(Request& r, const Stri |
| height, width); | height, width); |
| } | } |
| /// ^image.text(x;y)[text] | |
| static void _text(Request& r, const String& method_name, MethodParams *params) { | static void _text(Request& r, const String& method_name, MethodParams *params) { |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| int x=(int)r.process(params->get(0)).as_double(); | int x=r.process(params->get(0)).as_int(); |
| int y=(int)r.process(params->get(1)).as_double(); | int y=r.process(params->get(1)).as_int(); |
| const String& s=r.process(params->get(2)).as_string(); | const String& s=r.process(params->get(2)).as_string(); |
| VImage& vimage=*static_cast<VImage *>(r.self); | VImage& vimage=*static_cast<VImage *>(r.self); |
| Line 664 MImage::MImage(Pool& apool) : Methoded(a | Line 648 MImage::MImage(Pool& apool) : Methoded(a |
| // ^image:measure[DATA] | // ^image:measure[DATA] |
| add_native_method("measure", Method::CT_DYNAMIC, _measure, 1, 1); | add_native_method("measure", Method::CT_DYNAMIC, _measure, 1, 1); |
| /// ^image.html[] | // ^image.html[] |
| /// ^image.html[hash] | // ^image.html[hash] |
| add_native_method("html", Method::CT_DYNAMIC, _html, 0, 1); | add_native_method("html", Method::CT_DYNAMIC, _html, 0, 1); |
| /// ^image.load[background.gif] | // ^image.load[background.gif] |
| add_native_method("load", Method::CT_DYNAMIC, _load, 1, 1); | add_native_method("load", Method::CT_DYNAMIC, _load, 1, 1); |
| /// ^image.create[width;height] bgcolor=white | // ^image.create[width;height] bgcolor=white |
| /// ^image.create[width;height;bgcolor] | // ^image.create[width;height;bgcolor] |
| add_native_method("create", Method::CT_DYNAMIC, _create, 2, 3); | add_native_method("create", Method::CT_DYNAMIC, _create, 2, 3); |
| /// ^image.gif[] | // ^image.gif[] |
| add_native_method("gif", Method::CT_DYNAMIC, _gif, 0, 0); | add_native_method("gif", Method::CT_DYNAMIC, _gif, 0, 0); |
| /// ^image.line(x0;y0;x1;y1;color) | // ^image.line(x0;y0;x1;y1;color) |
| add_native_method("line", Method::CT_DYNAMIC, _line, 5, 5); | add_native_method("line", Method::CT_DYNAMIC, _line, 5, 5); |
| /// ^image.fill(x;y;color) | // ^image.fill(x;y;color) |
| add_native_method("fill", Method::CT_DYNAMIC, _fill, 3, 3); | add_native_method("fill", Method::CT_DYNAMIC, _fill, 3, 3); |
| /// ^image.rectangle(x0;y0;x1;y1;color) | // ^image.rectangle(x0;y0;x1;y1;color) |
| add_native_method("rectangle", Method::CT_DYNAMIC, _rectangle, 5, 5); | add_native_method("rectangle", Method::CT_DYNAMIC, _rectangle, 5, 5); |
| /// ^image.bar(x0;y0;x1;y1;color) | // ^image.bar(x0;y0;x1;y1;color) |
| add_native_method("bar", Method::CT_DYNAMIC, _bar, 5, 5); | add_native_method("bar", Method::CT_DYNAMIC, _bar, 5, 5); |
| /// ^image.replace(color-source;color-dest)(x;y)... point coord pairs | // ^image.replace(color-source;color-dest)(x;y)... point coord pairs |
| add_native_method("replace", Method::CT_DYNAMIC, _replace, 2+3*2, 2+100*2); | add_native_method("replace", Method::CT_DYNAMIC, _replace, 2+3*2, 2+100*2); |
| /// ^image.polygon(color)(x;y)... point coord pairs | // ^image.polygon(color)(x;y)... point coord pairs |
| add_native_method("polygon", Method::CT_DYNAMIC, _polygon, 1+3*2, 1+100*2); | add_native_method("polygon", Method::CT_DYNAMIC, _polygon, 1+3*2, 1+100*2); |
| /// ^image.polybar(color)(x;y)... point coord pairs | // ^image.polybar(color)(x;y)... point coord pairs |
| add_native_method("polybar", Method::CT_DYNAMIC, _polybar, 1+3*2, 1+100*2); | add_native_method("polybar", Method::CT_DYNAMIC, _polybar, 1+3*2, 1+100*2); |
| /// ^image.font[alPHAbet;font-file-name.gif](height) | // ^image.font[alPHAbet;font-file-name.gif](height) |
| /// ^image.font[alPHAbet;font-file-name.gif](height;width) | // ^image.font[alPHAbet;font-file-name.gif](height;width) |
| add_native_method("font", Method::CT_DYNAMIC, _font, 3, 4); | add_native_method("font", Method::CT_DYNAMIC, _font, 3, 4); |
| /// ^image.text(x;y)[text] | // ^image.text(x;y)[text] |
| add_native_method("text", Method::CT_DYNAMIC, _text, 3, 3); | add_native_method("text", Method::CT_DYNAMIC, _text, 3, 3); |
| } | } |