|
|
| version 1.45, 2001/09/24 14:34:25 | version 1.48, 2001/10/08 15:14:07 |
|---|---|
| Line 2 | Line 2 |
| Parser: @b image parser class. | Parser: @b image parser class. |
| Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) | Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru>(http://design.ru/paf) | Author: Alexander Petrosyan <paf@design.ru>(http://design.ru/paf) |
| $Id$ | |
| */ | */ |
| static const char *RCSId="$Id$"; | |
| /* | /* |
| jpegsize: gets the width and height (in pixels) of a jpeg file | jpegsize: gets the width and height (in pixels) of a jpeg file |
| Line 612 public: | Line 612 public: |
| } | } |
| /* ******************************** string ********************************** */ | /* ******************************** string ********************************** */ |
| /* | |
| int string_width(const char *cstr){ | int string_width(const String& s){ |
| const char *cstr=s.cstr(String::UL_AS_IS); | |
| int result=0; | int result=0; |
| for(; *cstr; cstr++) | for(; *cstr; cstr++) |
| result+=index_width(index_of(*cstr)); | result+=index_width(index_of(*cstr)); |
| return result; | return result; |
| } | } |
| */ | |
| void string_display(gdImage& image, int x, int y, const String& s){ | void string_display(gdImage& image, int x, int y, const String& s){ |
| const char *cstr=s.cstr(String::UL_AS_IS); | const char *cstr=s.cstr(String::UL_AS_IS); |
| Line 679 static void _text(Request& r, const Stri | Line 679 static void _text(Request& r, const Stri |
| "does not contain an image"); | "does not contain an image"); |
| } | } |
| static void _length(Request& r, const String& method_name, MethodParams *params) { | |
| Pool& pool=r.pool(); | |
| const String& s=params->as_string(0, "text must not be code"); | |
| VImage& vimage=*static_cast<VImage *>(r.self); | |
| if(vimage.image) | |
| if(vimage.font) { | |
| VInt& result=*new(pool) VInt(pool, vimage.font->string_width(s)); | |
| result.set_name(method_name); | |
| r.write_assign_lang(result); | |
| } else | |
| PTHROW(0, 0, | |
| &method_name, | |
| "set the font first"); | |
| else | |
| PTHROW(0, 0, | |
| &method_name, | |
| "does not contain an image"); | |
| } | |
| static void _arc(Request& r, const String& method_name, MethodParams *params) { | |
| Pool& pool=r.pool(); | |
| gdImage *image=static_cast<VImage *>(r.self)->image; | |
| if(!image) | |
| PTHROW(0, 0, | |
| &method_name, | |
| "does not contain an image"); | |
| image->Arc( | |
| params->as_int(0, r), //cx | |
| params->as_int(1, r), //cy | |
| params->as_int(2, r), //w | |
| params->as_int(3, r), //h | |
| params->as_int(4, r), //s | |
| params->as_int(5, r), //e | |
| image->Color(params->as_int(6, r))); | |
| } | |
| static void _circle(Request& r, const String& method_name, MethodParams *params) { | |
| Pool& pool=r.pool(); | |
| gdImage *image=static_cast<VImage *>(r.self)->image; | |
| if(!image) | |
| PTHROW(0, 0, | |
| &method_name, | |
| "does not contain an image"); | |
| int radius=params->as_int(2, r); | |
| image->Arc( | |
| params->as_int(0, r), //cx | |
| params->as_int(1, r), //cy | |
| radius, //w | |
| radius, //h | |
| 0, //s | |
| 360, //e | |
| image->Color(params->as_int(3, r))); | |
| } | |
| // constructor | // constructor |
| MImage::MImage(Pool& apool) : Methoded(apool) { | MImage::MImage(Pool& apool) : Methoded(apool) { |
| Line 733 MImage::MImage(Pool& apool) : Methoded(a | Line 793 MImage::MImage(Pool& apool) : Methoded(a |
| // ^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); |
| // ^image.ngth[text] | |
| add_native_method("length", Method::CT_DYNAMIC, _length, 1, 1); | |
| // ^image.arc(center x;center y;width;height;start in degrees;end in degrees;color) | |
| add_native_method("arc", Method::CT_DYNAMIC, _arc, 7, 7); | |
| // ^image.circle(center x;center y;r;color) | |
| add_native_method("circle", Method::CT_DYNAMIC, _circle, 4, 4); | |
| } | } |
| // global variable | // global variable |