--- parser3/src/classes/image.C 2003/07/24 11:31:20 1.91 +++ parser3/src/classes/image.C 2004/02/03 16:45:24 1.104 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_IMAGE_C="$Date: 2003/07/24 11:31:20 $"; +static const char * const IDENT_IMAGE_C="$Date: 2004/02/03 16:45:24 $"; /* jpegsize: gets the width and height (in pixels) of a jpeg file @@ -33,7 +33,7 @@ static const char* IDENT_IMAGE_C="$Date: class MImage: public Methoded { public: // VStateless_class - Value* create_new_value() { return new VImage(); } + Value* create_new_value(Pool&) { return new VImage(); } public: MImage(); @@ -161,8 +161,6 @@ public: }; class Measure_file_reader: public Measure_reader { - - ; const String& file_name; const char* fname; int f; @@ -180,7 +178,7 @@ public: if(ssize_t(read_size)<0 || read_size>limit) throw Exception(0, &file_name, - "measure failed: actually read %lu bytes count not in [0..%lu] valid range", + "measure failed: actually read %u bytes count not in [0..%u] valid range", read_size, limit); return read_size; @@ -331,7 +329,7 @@ static void measure_gif(const String& or Measure_reader& reader, ushort& width, ushort& height) { const char* buf; - const int head_size=sizeof(GIF_Header); + const size_t head_size=sizeof(GIF_Header); if(reader.read(buf, head_size)=0) return new VDate(t); } @@ -427,7 +425,7 @@ static Value* parse_IFD_entry_formatted_ HashStringValue& hash=result->hash(); for(uint i=0; i(context); @@ -703,12 +701,12 @@ static void _measure(Request& r, MethodP ushort height=0; Value* exif=0; const String* file_name; - if(file_name=data.get_string()) { - File_measure_action_info info={0}; - info.width=&width; - info.height=&height; - info.exif=&exif; - info.file_name=file_name; + if((file_name=data.get_string())) { + File_measure_action_info info={ + &width, &height, + &exif, + file_name + }; file_read_action_under_lock(r.absolute(*file_name), "measure", file_measure_action, &info); } else { @@ -755,11 +753,10 @@ static void _html(Request& r, MethodPara if(params.count()) { // for backward compatibility: someday was ^html{} Value& vattribs=r.process_to_value(params[0], - /*0/*no name* /,*/ false/*don't intercept string*/); if(!vattribs.is_string()) // allow empty - if(attribs=vattribs.get_hash()) { - Attrib_info info={&tag}; + if((attribs=vattribs.get_hash())) { + Attrib_info info={&tag, 0}; attribs->for_each(append_attrib_pair, &info); } else throw Exception("parser.runtime", @@ -792,7 +789,6 @@ static gdImage* load(Request& r, throw Exception("file.missing", 0, "can not open '%s'", file_name_cstr); - return 0; } } @@ -805,7 +801,6 @@ static void _load(Request& r, MethodPara } static void _create(Request& r, MethodParams& params) { - 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; @@ -818,27 +813,29 @@ static void _create(Request& r, MethodPa } static void _gif(Request& r, MethodParams& params) { - gdImage* image=GET_SELF(r, VImage).image; if(!image) throw Exception(0, 0, "does not contain an image"); - // could _ but don't thing it's wise to use $image.src for vfile.name + const String *file_name=0; + if(params.count()>0) + file_name=¶ms.as_string(0, "file name must be string"); gdBuf buf=image->Gif(); VFile& vfile=*new VFile; Value* content_type=new VString(*new String("image/gif")); vfile.set(false/*not tainted*/, - (const char*)buf.ptr, buf.size, 0, content_type); + (const char*)buf.ptr, buf.size, + file_name? file_name->cstr(String::L_FILE_SPEC): 0, + content_type); r.write_no_lang(vfile); } static void _line(Request& r, MethodParams& params) { - gdImage* image=GET_SELF(r, VImage).image; if(!image) throw Exception(0, @@ -854,7 +851,6 @@ static void _line(Request& r, MethodPara } static void _fill(Request& r, MethodParams& params) { - gdImage* image=GET_SELF(r, VImage).image; if(!image) throw Exception(0, @@ -868,7 +864,6 @@ static void _fill(Request& r, MethodPara } static void _rectangle(Request& r, MethodParams& params) { - gdImage* image=GET_SELF(r, VImage).image; if(!image) throw Exception(0, @@ -884,7 +879,6 @@ static void _rectangle(Request& r, Metho } static void _bar(Request& r, MethodParams& params) { - gdImage* image=GET_SELF(r, VImage).image; if(!image) throw Exception(0, @@ -908,7 +902,6 @@ static void add_point(Table::element_typ } #endif static void _replace(Request& r, MethodParams& params) { - gdImage* image=GET_SELF(r, VImage).image; if(!image) throw Exception(0, @@ -921,7 +914,7 @@ static void _replace(Request& r, MethodP 0, "coordinates must be table"); - gdImage::Point *all_p=new gdImage::Point[table->count()]; + gdImage::Point *all_p=new(PointerFreeGC) gdImage::Point[table->count()]; gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->FilledPolygonReplaceColor(all_p, table->count(), @@ -930,7 +923,6 @@ static void _replace(Request& r, MethodP } static void _polyline(Request& r, MethodParams& params) { - gdImage* image=GET_SELF(r, VImage).image; if(!image) throw Exception(0, @@ -943,7 +935,7 @@ static void _polyline(Request& r, Method 0, "coordinates must be table"); - gdImage::Point* all_p=new gdImage::Point[table->count()]; + gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->Polygon(all_p, table->count(), @@ -952,7 +944,6 @@ static void _polyline(Request& r, Method } static void _polygon(Request& r, MethodParams& params) { - gdImage* image=GET_SELF(r, VImage).image; if(!image) throw Exception(0, @@ -965,7 +956,7 @@ static void _polygon(Request& r, MethodP 0, "coordinates must be table"); - gdImage::Point* all_p=new gdImage::Point[table->count()]; + gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->Polygon(all_p, table->count(), @@ -973,7 +964,6 @@ static void _polygon(Request& r, MethodP } static void _polybar(Request& r, MethodParams& params) { - gdImage* image=GET_SELF(r, VImage).image; if(!image) throw Exception(0, @@ -986,7 +976,7 @@ static void _polybar(Request& r, MethodP 0, "coordinates must be table"); - gdImage::Point* all_p=new gdImage::Point[table->count()]; + gdImage::Point* all_p=new(PointerFreeGC) gdImage::Point[table->count()]; gdImage::Point *add_p=all_p; table->for_each(add_point, &add_p); image->FilledPolygon(all_p, table->count(), @@ -1004,9 +994,9 @@ const int Font::letter_spacing=1; Font::Font(//, const String& aalphabet, gdImage* aifont, int aheight, int amonospace, int aspacebarspace): - alphabet(aalphabet), height(aheight), monospace(amonospace), spacebarspace(aspacebarspace), - ifont(aifont) { + ifont(aifont), + alphabet(aalphabet) { } /* ******************************** char ********************************** */ @@ -1242,7 +1232,7 @@ MImage::MImage(): Methoded("image") { add_native_method("create", Method::CT_DYNAMIC, _create, 2, 3); // ^image.gif[] - add_native_method("gif", Method::CT_DYNAMIC, _gif, 0, 0); + add_native_method("gif", Method::CT_DYNAMIC, _gif, 0, 1); // ^image.line(x0;y0;x1;y1;color) add_native_method("line", Method::CT_DYNAMIC, _line, 5, 5);