--- parser3/src/classes/image.C 2001/09/18 16:05:42 1.44 +++ parser3/src/classes/image.C 2001/10/08 15:50:22 1.49 @@ -2,10 +2,10 @@ Parser: @b image parser class. Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + + $Id: image.C,v 1.49 2001/10/08 15:50:22 parser Exp $ */ -static const char *RCSId="$Id: image.C,v 1.44 2001/09/18 16:05:42 parser Exp $"; /* jpegsize: gets the width and height (in pixels) of a jpeg file @@ -48,7 +48,7 @@ public: // Methoded #ifndef DOXYGEN class Measure_reader { public: - enum { READ_CHUNK_SIZE=0x400*10 };// 10K + enum { READ_CHUNK_SIZE=0x400*20 };// 20K typedef size_t(*Func)(void *& buf, size_t limit, void *info); Measure_reader(Func afunc, void *ainfo) : @@ -293,7 +293,8 @@ struct Attrib_info { static void append_attrib_pair(const Hash::Key& key, Hash::Val *val, void *info) { Attrib_info& ai=*static_cast(info); - if(ai.skip && ai.skip->get(key)) + // skip user-specified and internal(starting with "line-") attributes + if(ai.skip && ai.skip->get(key) || key.pos("line-")==0) return; Value& value=*static_cast(val); @@ -314,7 +315,7 @@ static void _html(Request& r, const Stri if(params->size()) { Value &vattribs=params->get(0); if(vattribs.is_defined()) // allow 'void' - if(Hash *attribs=vattribs.get_hash()) { + if(attribs=vattribs.get_hash()) { Attrib_info attrib_info={&tag, 0}; attribs->for_each(append_attrib_pair, &attrib_info); } else @@ -612,14 +613,14 @@ public: } /* ******************************** 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; for(; *cstr; cstr++) result+=index_width(index_of(*cstr)); return result; } - */ void string_display(gdImage& image, int x, int y, const String& s){ const char *cstr=s.cstr(String::UL_AS_IS); @@ -679,6 +680,85 @@ static void _text(Request& r, const Stri "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(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(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 _sector(Request& r, const String& method_name, MethodParams *params) { + Pool& pool=r.pool(); + + gdImage *image=static_cast(r.self)->image; + if(!image) + PTHROW(0, 0, + &method_name, + "does not contain an image"); + + image->Sector( + 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(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 MImage::MImage(Pool& apool) : Methoded(apool) { @@ -733,6 +813,18 @@ MImage::MImage(Pool& apool) : Methoded(a // ^image.text(x;y)[text] 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.sector(center x;center y;width;height;start in degrees;end in degrees;color) + add_native_method("sector", Method::CT_DYNAMIC, _sector, 7, 7); + + // ^image.circle(center x;center y;r;color) + add_native_method("circle", Method::CT_DYNAMIC, _circle, 4, 4); + } // global variable