--- parser3/src/classes/image.C 2024/09/11 21:07:36 1.185 +++ parser3/src/classes/image.C 2025/05/26 00:52:15 1.196 @@ -1,7 +1,7 @@ /** @file Parser: @b image parser class. - Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com) Authors: Konstantin Morshnev , Alexandr Petrosian */ @@ -26,7 +26,7 @@ #include "pa_table.h" #include "pa_charsets.h" -volatile const char * IDENT_IMAGE_C="$Id: image.C,v 1.185 2024/09/11 21:07:36 moko Exp $"; +volatile const char * IDENT_IMAGE_C="$Id: image.C,v 1.196 2025/05/26 00:52:15 moko Exp $"; // defines @@ -189,7 +189,14 @@ public: EXIF_TAG(0xa434, LensModel); EXIF_TAG(0xa435, LensSerialNumber); } -} exif_tag_value2name; + + static EXIF_tag_value2name &instance(){ + static EXIF_tag_value2name *singleton=NULL; + if(!singleton) + singleton=new EXIF_tag_value2name; + return *singleton; + } +}; class EXIF_gps_tag_value2name: public Hash { public: @@ -226,7 +233,15 @@ public: EXIF_TAG(0x1D, GPSDateStamp); EXIF_TAG(0x1E, GPSDifferential); } -} exif_gps_tag_value2name; + + static EXIF_gps_tag_value2name &instance(){ + static EXIF_gps_tag_value2name *singleton=NULL; + if(!singleton) + singleton=new EXIF_gps_tag_value2name; + return *singleton; + } + +}; ///*********************************************** support functions @@ -438,7 +453,7 @@ static Value* parse_IFD_entry_formatted_ HashStringValue& hash=result->hash(); for(uint i=0; iwidth); @@ -960,7 +975,7 @@ static void measure(const String& file_n else throw Exception(IMAGE_FORMAT, &file_name, "unhandled file name extension '%s'", cext); } else - throw Exception(IMAGE_FORMAT, &file_name, "can not determine file type - no file name extension"); + throw Exception(IMAGE_FORMAT, &file_name, "cannot determine file type - no file name extension"); } // methods @@ -1075,13 +1090,13 @@ static gdImage* load(Request& r, const S throw Exception(IMAGE_FORMAT, &file_name, "is not in GIF format"); return image; } else { - throw Exception("file.missing", 0, "can not open '%s'", file_name_cstr); + throw Exception("file.missing", 0, "cannot open '%s'", file_name_cstr); } } static void _load(Request& r, MethodParams& params) { - const String& file_name=params.as_string(0, FILE_NAME_MUST_NOT_BE_CODE); + const String& file_name=params.as_file_name(0); gdImage* image=load(r, file_name); GET_SELF(r, VImage).set(&file_name, image->SX(), image->SY(), image); @@ -1332,12 +1347,12 @@ void Font::string_display(gdImage& image static void _font(Request& r, MethodParams& params) { - const String& alphabet=params.as_string(0, "alphabet must not be code"); + const String& alphabet=params.as_string(0, "alphabet must be string"); size_t alphabet_length=alphabet.length(r.charsets.source()); if(!alphabet_length) throw Exception(PARSER_RUNTIME, 0, "alphabet must not be empty"); - gdImage* image=load(r, params.as_string(1, FILE_NAME_MUST_NOT_BE_CODE)); + gdImage* image=load(r, params.as_file_name(1)); int spacebar_width=image->SX(); int monospace_width=0; // proportional @@ -1384,14 +1399,14 @@ static void _font(Request& r, MethodPara static void _text(Request& r, MethodParams& params) { 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"); + const String& s=params.as_string(2, "text must be string"); VImage& vimage=GET_SELF(r, VImage); vimage.font().string_display(vimage.image(), x, y, s); } static void _length(Request& r, MethodParams& params) { - const String& s=params.as_string(0, "text must not be code"); + const String& s=params.as_string(0, "text must be string"); VImage& vimage=GET_SELF(r, VImage); r.write(*new VInt(vimage.font().string_width(s))); @@ -1440,8 +1455,8 @@ static void _circle(Request& r, MethodPa gdImage& as_image(MethodParams& params, int index, const char* msg) { Value& value=params.as_no_junction(index, msg); - if(Value* vimage=value.as(VIMAGE_TYPE)) { - return static_cast(vimage)->image(); + if(VImage* vimage=dynamic_cast(&value)) { + return vimage->image(); } else throw Exception(PARSER_RUNTIME, 0, msg); }