--- parser3/src/classes/image.C 2001/10/04 14:56:29 1.47 +++ parser3/src/classes/image.C 2001/10/09 07:06:00 1.52 @@ -4,7 +4,7 @@ Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: image.C,v 1.47 2001/10/04 14:56:29 parser Exp $ + $Id: image.C,v 1.52 2001/10/09 07:06:00 parser Exp $ */ /* @@ -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); @@ -312,9 +313,11 @@ static void _html(Request& r, const Stri Hash *attribs=0; if(params->size()) { - Value &vattribs=params->get(0); + Value &vattribs=r.process(params->get(0), + 0/*no name*/, + false/*don't intercept string*/); 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 @@ -366,11 +369,11 @@ static void _load(Request& r, const Stri static void _create(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - int width=params->as_int(0, r); - int height=params->as_int(1, r); + int width=params->as_int(0, "width must be int", r); + int height=params->as_int(1, "height must be int", r); int bgcolor_value=0xffFFff; if(params->size()>2) - bgcolor_value=params->as_int(2, r); + bgcolor_value=params->as_int(2, "color must be int", r); gdImage& image=*new(pool) gdImage(pool); image.Create(width, height); image.FilledRectangle(0, 0, width-1, height-1, image.Color(bgcolor_value)); @@ -408,11 +411,11 @@ static void _line(Request& r, const Stri "does not contain an image"); image->Line( - params->as_int(0, r), - params->as_int(1, r), - params->as_int(2, r), - params->as_int(3, r), - image->Color(params->as_int(4, r))); + params->as_int(0, "x0 must be int", r), + params->as_int(1, "y0 must be int", r), + params->as_int(2, "x1 must be int", r), + params->as_int(3, "y1 must be int", r), + image->Color(params->as_int(4, "color must be int", r))); } static void _fill(Request& r, const String& method_name, MethodParams *params) { @@ -425,9 +428,9 @@ static void _fill(Request& r, const Stri "does not contain an image"); image->Fill( - params->as_int(0, r), - params->as_int(1, r), - image->Color(params->as_int(2, r))); + params->as_int(0, "x must be int", r), + params->as_int(1, "y must be int", r), + image->Color(params->as_int(2, "color must be int", r))); } static void _rectangle(Request& r, const String& method_name, MethodParams *params) { @@ -440,11 +443,11 @@ static void _rectangle(Request& r, const "does not contain an image"); image->Rectangle( - params->as_int(0, r), - params->as_int(1, r), - params->as_int(2, r), - params->as_int(3, r), - image->Color(params->as_int(4, r))); + params->as_int(0, "x0 must be int", r), + params->as_int(1, "y0 must be int", r), + params->as_int(2, "x1 must be int", r), + params->as_int(3, "y1 must be int", r), + image->Color(params->as_int(4, "color must be int", r))); } static void _bar(Request& r, const String& method_name, MethodParams *params) { @@ -457,11 +460,11 @@ static void _bar(Request& r, const Strin "does not contain an image"); image->FilledRectangle( - params->as_int(0, r), - params->as_int(1, r), - params->as_int(2, r), - params->as_int(3, r), - image->Color(params->as_int(4, r))); + params->as_int(0, "x0 must be int", r), + params->as_int(1, "y0 must be int", r), + params->as_int(2, "x1 must be int", r), + params->as_int(3, "y1 must be int", r), + image->Color(params->as_int(4, "color must be int", r))); } #ifndef DOXYGEN @@ -493,8 +496,8 @@ static void _replace(Request& r, const S gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->FilledPolygonReplaceColor(all_p, table->size(), - image->Color(params->as_int(0, r)), // src color - image->Color(params->as_int(1, r)));// dest color + image->Color(params->as_int(0, "src color must be int", r)), + image->Color(params->as_int(1, "dest color must be int", r))); } static void _polyline(Request& r, const String& method_name, MethodParams *params) { @@ -516,7 +519,7 @@ static void _polyline(Request& r, const gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->Polygon(all_p, table->size(), - image->Color(params->as_int(0, r)), + image->Color(params->as_int(0, "color must be int", r)), false/*not closed*/); } @@ -539,7 +542,7 @@ static void _polygon(Request& r, const S gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->Polygon(all_p, table->size(), - image->Color(params->as_int(0, r))); + image->Color(params->as_int(0, "color must be int", r))); } static void _polybar(Request& r, const String& method_name, MethodParams *params) { @@ -561,7 +564,7 @@ static void _polybar(Request& r, const S gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->FilledPolygon(all_p, table->size(), - image->Color(params->as_int(0, r))); + image->Color(params->as_int(0, "color must be int", r))); } // font @@ -638,10 +641,10 @@ static void _font(Request& r, const Stri const String& alphabet=params->as_string(0, "alphabet must not be code"); gdImage& image=*load(r, method_name, params->as_string(1, "file_name must not be code")); - int spacebar_width=params->as_int(2, r); + int spacebar_width=params->as_int(2, "spacebar_width must be int", r); int monospace_width; if(params->size()>3) { - monospace_width=params->as_int(3, r); + monospace_width=params->as_int(3, "monospace_width must be int", r); if(!monospace_width) monospace_width=image.SX(); } else @@ -661,8 +664,8 @@ static void _font(Request& r, const Stri static void _text(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - int x=params->as_int(0, r); - int y=params->as_int(1, r); + int x=params->as_int(0, "x must be int", r); + int y=params->as_int(1, "y must be int", r); const String& s=params->as_string(2, "text must not be code"); VImage& vimage=*static_cast(r.self); @@ -700,6 +703,64 @@ static void _length(Request& r, const St "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, "center_x must be int", r), + params->as_int(1, "center_y must be int", r), + params->as_int(2, "width must be int", r), + params->as_int(3, "height must be int", r), + params->as_int(4, "start degrees must be int", r), + params->as_int(5, "end degrees must be int", r), + image->Color(params->as_int(6, "cx must be int", 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, "center_x must be int", r), + params->as_int(1, "center_y must be int", r), + params->as_int(2, "width must be int", r), + params->as_int(3, "height must be int", r), + params->as_int(4, "start degrees must be int", r), + params->as_int(5, "end degrees must be int", r), + image->Color(params->as_int(6, "color must be int", 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 size=params->as_int(2, "radius must be int", r)*2; + image->Arc( + params->as_int(0, "center_x must be int", r), + params->as_int(1, "center_y must be int", r), + size, //w + size, //h + 0, //s + 360, //e + image->Color(params->as_int(3, "color must be int", r))); +} + // constructor MImage::MImage(Pool& apool) : Methoded(apool) { @@ -757,6 +818,15 @@ MImage::MImage(Pool& apool) : Methoded(a // ^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