Diff for /parser3/src/classes/image.C between versions 1.151 and 1.155

version 1.151, 2016/03/31 21:46:19 version 1.155, 2016/10/26 19:10:31
Line 238  public: Line 238  public:
 };  };
   
 class Measure_file_reader: public Measure_reader {  class Measure_file_reader: public Measure_reader {
         const String& file_name; const char* fname;          const String& file_name;
         int f;          int f;
   
 public:  public:
         Measure_file_reader(int af, const String& afile_name, const char* afname):           Measure_file_reader(int af, const String& afile_name):
                 file_name(afile_name), fname(afname), f(af) {                  file_name(afile_name), f(af) {
         }          }
   
         override size_t read(const char* &abuf, size_t limit) {          override size_t read(const char* &abuf, size_t limit) {
Line 259  public: Line 259  public:
   
         override void seek(long value, int whence) {          override void seek(long value, int whence) {
                 if(lseek(f, value, whence)<0)                  if(lseek(f, value, whence)<0)
                         throw Exception(IMAGE_FORMAT,                          throw Exception(IMAGE_FORMAT, &file_name, "seek(value=%ld, whence=%d) failed: %s (%d)", value, whence, strerror(errno), errno);
                                 &file_name,   
                                 "seek(value=%ld, whence=%d) failed: %s (%d), actual filename '%s'",   
                                         value, whence, strerror(errno), errno, fname);  
         }          }
   
         override long tell() { return lseek(f, 0, SEEK_CUR); }          override long tell() { return lseek(f, 0, SEEK_CUR); }
Line 294  public: Line 291  public:
                 case SEEK_CUR: new_offset=offset+value; break;                  case SEEK_CUR: new_offset=offset+value; break;
                 case SEEK_SET: new_offset=(size_t)value; break;                  case SEEK_SET: new_offset=(size_t)value; break;
                 default:                   default: 
                         throw Exception(0,                           throw Exception(0, 0, "whence #%d not supported", 0, whence); 
                                 0,   
                                 "whence #%d not supported", 0, whence);   
                         break; // never                          break; // never
                 }                  }
                                   
                 if((ssize_t)new_offset<0 || new_offset>size)                  if((ssize_t)new_offset<0 || new_offset>size)
                         throw Exception(IMAGE_FORMAT,                          throw Exception(IMAGE_FORMAT, &file_name, "seek(value=%l, whence=%d) failed: out of buffer, new_offset>size (%l>%l) or new_offset<0", 
                                 &file_name,   
                                 "seek(value=%l, whence=%d) failed: out of buffer, new_offset>size (%l>%l) or new_offset<0",   
                                         value, whence, new_offset, size);                                          value, whence, new_offset, size);
                 offset=new_offset;                  offset=new_offset;
         }          }
Line 400  inline uint endian_to_uint(bool is_big, Line 393  inline uint endian_to_uint(bool is_big,
                 x_endian_to_uint(b[0], b[1], b[2], b[3]);                  x_endian_to_uint(b[0], b[1], b[2], b[3]);
 }  }
   
 static void measure_gif(const String& origin_string,   static void measure_gif(const String& origin_string, Measure_reader& reader, ushort& width, ushort& height) {
                          Measure_reader& reader, ushort& width, ushort& height) {  
   
         const char* buf;          const char* buf;
         const size_t head_size=sizeof(GIF_Header);          const size_t head_size=sizeof(GIF_Header);
         if(reader.read(buf, head_size)<head_size)          if(reader.read(buf, head_size)<head_size)
                 throw Exception(IMAGE_FORMAT,                   throw Exception(IMAGE_FORMAT, &origin_string, "not GIF file - too small");
                         &origin_string,   
                         "not GIF file - too small");  
         GIF_Header *head=(GIF_Header *)buf;          GIF_Header *head=(GIF_Header *)buf;
   
         if(strncmp(head->signature, "GIF", 3)!=0)          if(strncmp(head->signature, "GIF", 3)!=0)
                 throw Exception(IMAGE_FORMAT,                   throw Exception(IMAGE_FORMAT, &origin_string, "not GIF file - wrong signature");
                         &origin_string,   
                         "not GIF file - wrong signature");        
   
         width=endian_to_ushort(false, head->width);          width=endian_to_ushort(false, head->width);
         height=endian_to_ushort(false, head->height);          height=endian_to_ushort(false, head->height);
 }  }
   
 static Value* parse_IFD_entry_formatted_one_value(  static Value* parse_IFD_entry_formatted_one_value(bool is_big, ushort format, size_t component_size, const uchar *value) {
                                                                                                   bool is_big,  
                                                                                                   ushort format,   
                                                                                                   size_t component_size,   
                                                                                                   const uchar *value) {  
         switch(format) {          switch(format) {
         case 1: // unsigned byte          case 1: // unsigned byte
                 return new VInt((uchar)value[0]);                  return new VInt((uchar)value[0]);
Line 469  static Value* parse_IFD_entry_formatted_ Line 453  static Value* parse_IFD_entry_formatted_
 // date.C  // date.C
 tm cstr_to_time_t(char *, const char **);  tm cstr_to_time_t(char *, const char **);
   
 static Value* parse_IFD_entry_formatted_value(bool is_big, ushort format,   static Value* parse_IFD_entry_formatted_value(bool is_big, ushort format, size_t component_size, uint components_count, const uchar *value) {
                                               size_t component_size, uint components_count,   
                                               const uchar *value) {  
         if(format==2) { // ascii string, exception: the only type with varying size          if(format==2) { // ascii string, exception: the only type with varying size
                 const char* cstr=(const char* )value;                  const char* cstr=(const char* )value;
                 size_t length=components_count;                  size_t length=components_count;
                 // Data format is "YYYY:MM:DD HH:MM:SS"+0x00, total 20bytes                  // Data format is "YYYY:MM:DD HH:MM:SS"+0x00, total 20bytes
                 if(length==JPEG_EXIF_DATE_CHARS                   if(length==JPEG_EXIF_DATE_CHARS && isdigit((unsigned char)cstr[0]) && cstr[length-1]==0) {
                         && isdigit((unsigned char)cstr[0])                          char cstr_writable[JPEG_EXIF_DATE_CHARS];
                         && cstr[length-1]==0) {  
                         char cstr_writable[JPEG_EXIF_DATE_CHARS];   
                         strcpy(cstr_writable, cstr);                          strcpy(cstr_writable, cstr);
   
                         try {                          try {
Line 506  static Value* parse_IFD_entry_formatted_ Line 486  static Value* parse_IFD_entry_formatted_
         return result;          return result;
 }  }
   
 static Value* parse_IFD_entry_value(  static Value* parse_IFD_entry_value(bool is_big, Measure_reader& reader, long tiff_base, JPG_Exif_IFD_entry& entry) {
                                                                         bool is_big, Measure_reader& reader, long tiff_base,  
                                                                         JPG_Exif_IFD_entry& entry) {  
         size_t format2component_size[]={          size_t format2component_size[]={
                 0, // undefined                  0, // undefined
                 1, // unsigned byte                  1, // unsigned byte
Line 543  static Value* parse_IFD_entry_value( Line 521  static Value* parse_IFD_entry_value(
         Value* result;          Value* result;
   
         if(value_size<=4)          if(value_size<=4)
                 result=parse_IFD_entry_formatted_value(                  result=parse_IFD_entry_formatted_value(is_big, format, component_size, components_count, entry.value_or_offset_to_it);
                         is_big, format,   
                         component_size, components_count,   
                         entry.value_or_offset_to_it);  
         else {          else {
                 long remembered=reader.tell();                  long remembered=reader.tell();
                 {                  {
Line 554  static Value* parse_IFD_entry_value( Line 529  static Value* parse_IFD_entry_value(
                         const char* value;                          const char* value;
                         if(reader.read(value, value_size)<sizeof(value_size))                          if(reader.read(value, value_size)<sizeof(value_size))
                                 return 0;                                  return 0;
                         result=parse_IFD_entry_formatted_value(                          result=parse_IFD_entry_formatted_value(is_big, format, component_size, components_count, (const uchar*)value);
                                 is_big, format,   
                                 component_size, components_count,   
                                 (const uchar*)value);  
                 }                  }
                 reader.seek(remembered, SEEK_SET);                  reader.seek(remembered, SEEK_SET);
         }          }
Line 565  static Value* parse_IFD_entry_value( Line 537  static Value* parse_IFD_entry_value(
         return result;          return result;
 }  }
   
 static void parse_IFD(HashStringValue& hash,  static void parse_IFD(HashStringValue& hash, bool is_big, Measure_reader& reader, long tiff_base, bool gps=false);
                       bool is_big, Measure_reader& reader, long tiff_base, bool gps=false);  
   
 static void parse_IFD_entry(HashStringValue& hash,  static void parse_IFD_entry(HashStringValue& hash, bool is_big, Measure_reader& reader, long tiff_base, JPG_Exif_IFD_entry& entry, bool gps=false) {
                             bool is_big, Measure_reader& reader, long tiff_base,  
                             JPG_Exif_IFD_entry& entry, bool gps=false) {  
         ushort tag=endian_to_ushort(is_big, entry.tag);          ushort tag=endian_to_ushort(is_big, entry.tag);
   
         if(tag==JPG_IFD_TAG_EXIF_OFFSET || tag==JPG_IFD_TAG_EXIF_GPS_OFFSET){          if(tag==JPG_IFD_TAG_EXIF_OFFSET || tag==JPG_IFD_TAG_EXIF_GPS_OFFSET){
Line 591  static void parse_IFD_entry(HashStringVa Line 560  static void parse_IFD_entry(HashStringVa
         }          }
 }  }
   
 static void parse_IFD(  static void parse_IFD(HashStringValue& hash, bool is_big, Measure_reader& reader, long tiff_base, bool gps) {
                       HashStringValue& hash,  
                       bool is_big, Measure_reader& reader, long tiff_base, bool gps) {  
         const char* buf;          const char* buf;
         if(reader.read(buf, sizeof(JPG_Exif_IFD_begin))<sizeof(JPG_Exif_IFD_begin))          if(reader.read(buf, sizeof(JPG_Exif_IFD_begin))<sizeof(JPG_Exif_IFD_begin))
                 return;                  return;
Line 612  static void parse_IFD( Line 579  static void parse_IFD(
 static Value* parse_exif(Measure_reader& reader, const String& origin_string) {  static Value* parse_exif(Measure_reader& reader, const String& origin_string) {
         const char* buf;          const char* buf;
         if(reader.read(buf, sizeof(JPG_Exif_segment_begin))<sizeof(JPG_Exif_segment_begin))          if(reader.read(buf, sizeof(JPG_Exif_segment_begin))<sizeof(JPG_Exif_segment_begin))
                 throw Exception(IMAGE_FORMAT,                   throw Exception(IMAGE_FORMAT, &origin_string, "not JPEG file - can not fully read Exif segment start");
                         &origin_string,   
                         "not JPEG file - can not fully read Exif segment start");  
   
         JPG_Exif_segment_begin *start=(JPG_Exif_segment_begin *)buf;          JPG_Exif_segment_begin *start=(JPG_Exif_segment_begin *)buf;
         if(memcmp(start->signature, "Exif\0\0", 4+2)!=0) //signature invalid?          if(memcmp(start->signature, "Exif\0\0", 4+2)!=0) //signature invalid?
Line 638  static Value* parse_exif(Measure_reader& Line 603  static Value* parse_exif(Measure_reader&
         return vhash;          return vhash;
 }  }
   
 static void measure_jpeg(const String& origin_string,   static void measure_jpeg(const String& origin_string, Measure_reader& reader, ushort& width, ushort& height, Value** exif) {
                          Measure_reader& reader, ushort& width, ushort& height, Value** exif) {  
         // JFIF format markers          // JFIF format markers
         const uchar MARKER=0xFF;          const uchar MARKER=0xFF;
         const uchar CODE_SIZE_A=0xC0;          const uchar CODE_SIZE_A=0xC0;
Line 651  static void measure_jpeg(const String& o Line 615  static void measure_jpeg(const String& o
         const char* buf;          const char* buf;
         const size_t prefix_size=2;          const size_t prefix_size=2;
         if(reader.read(buf, prefix_size)<prefix_size)          if(reader.read(buf, prefix_size)<prefix_size)
                 throw Exception(IMAGE_FORMAT,                   throw Exception(IMAGE_FORMAT, &origin_string, "not JPEG file - too small");
                         &origin_string,   
                         "not JPEG file - too small");  
         uchar *signature=(uchar *)buf;          uchar *signature=(uchar *)buf;
                   
         if(!(signature[0]==0xFF && signature[1]==0xD8))           if(!(signature[0]==0xFF && signature[1]==0xD8)) 
                 throw Exception(IMAGE_FORMAT,                   throw Exception(IMAGE_FORMAT, &origin_string, "not JPEG file - wrong signature");
                         &origin_string,   
                         "not JPEG file - wrong signature");  
   
         while(true) {          while(true) {
                 uint segment_base=reader.tell()+2/*marker,code*/;                  uint segment_base=reader.tell()+2/*marker,code*/;
Line 669  static void measure_jpeg(const String& o Line 629  static void measure_jpeg(const String& o
   
         // Verify that it's a valid segment.          // Verify that it's a valid segment.
                 if(head->marker!=MARKER)                  if(head->marker!=MARKER)
                         throw Exception(IMAGE_FORMAT,                           throw Exception(IMAGE_FORMAT, &origin_string, "not JPEG file - marker not found");
                                 &origin_string,   
                                 "not JPEG file - marker not found");  
   
                 switch(head->code) {                  switch(head->code) {
                 // http://park2.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html                  // http://park2.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html
Line 687  static void measure_jpeg(const String& o Line 645  static void measure_jpeg(const String& o
                         {                          {
                                 // Segments that contain size info                                  // Segments that contain size info
                                 if(reader.read(buf, sizeof(JPG_Size_segment_body))<sizeof(JPG_Size_segment_body))                                  if(reader.read(buf, sizeof(JPG_Size_segment_body))<sizeof(JPG_Size_segment_body))
                                         throw Exception(IMAGE_FORMAT,                                           throw Exception(IMAGE_FORMAT, &origin_string, "not JPEG file - can not fully read Size segment");
                                                 &origin_string,   
                                                 "not JPEG file - can not fully read Size segment");  
                                 JPG_Size_segment_body *body=(JPG_Size_segment_body *)buf;                                  JPG_Size_segment_body *body=(JPG_Size_segment_body *)buf;
                                                                   
                                 width=endian_to_ushort(true, body->width);                                  width=endian_to_ushort(true, body->width);
Line 701  static void measure_jpeg(const String& o Line 657  static void measure_jpeg(const String& o
                 reader.seek(segment_base+endian_to_ushort(true, head->length), SEEK_SET);                  reader.seek(segment_base+endian_to_ushort(true, head->length), SEEK_SET);
         }          }
   
         throw Exception(IMAGE_FORMAT,           throw Exception(IMAGE_FORMAT, &origin_string, "broken JPEG file - size frame not found");
                 &origin_string,   
                 "broken JPEG file - size frame not found");  
 }  }
   
 static void measure_png(const String& origin_string,   static void measure_png(const String& origin_string, Measure_reader& reader, ushort& width, ushort& height) {
                          Measure_reader& reader, ushort& width, ushort& height) {  
   
         const char* buf;          const char* buf;
         const size_t head_size=sizeof(PNG_Header);          const size_t head_size=sizeof(PNG_Header);
         if(reader.read(buf, head_size)<head_size)          if(reader.read(buf, head_size)<head_size)
                 throw Exception(IMAGE_FORMAT,                   throw Exception(IMAGE_FORMAT, &origin_string, "not PNG file - too small");
                         &origin_string,   
                         "not PNG file - too small");  
         PNG_Header *head=(PNG_Header *)buf;          PNG_Header *head=(PNG_Header *)buf;
   
         if(strncmp(head->signature, "IHDR", 4)!=0)          if(strncmp(head->signature, "IHDR", 4)!=0)
                 throw Exception(IMAGE_FORMAT,                   throw Exception(IMAGE_FORMAT, &origin_string, "not PNG file - wrong signature");
                         &origin_string,   
                         "not PNG file - wrong signature");        
   
         width=endian_to_ushort(true, head->width);          width=endian_to_ushort(true, head->width);
         height=endian_to_ushort(true, head->height);          height=endian_to_ushort(true, head->height);
Line 728  static void measure_png(const String& or Line 677  static void measure_png(const String& or
   
 // measure center  // measure center
   
 static void measure(const String& file_name,   static void measure(const String& file_name, Measure_reader& reader, ushort& width, ushort& height, Value** exif) {
                          Measure_reader& reader, ushort& width, ushort& height, Value** exif) {  
         const char* file_name_cstr=file_name.taint_cstr(String::L_FILE_SPEC);          const char* file_name_cstr=file_name.taint_cstr(String::L_FILE_SPEC);
         if(const char* cext=strrchr(file_name_cstr, '.')) {          if(const char* cext=strrchr(file_name_cstr, '.')) {
                 cext++;                  cext++;
Line 740  static void measure(const String& file_n Line 688  static void measure(const String& file_n
                 else if(strcasecmp(cext, "PNG")==0)                  else if(strcasecmp(cext, "PNG")==0)
                         measure_png(file_name, reader, width, height);                          measure_png(file_name, reader, width, height);
                 else                  else
                         throw Exception(IMAGE_FORMAT,                           throw Exception(IMAGE_FORMAT, &file_name, "unhandled image file name extension '%s'", cext);
                                 &file_name,   
                                 "unhandled image file name extension '%s'", cext);  
         } else          } else
                 throw Exception(IMAGE_FORMAT,                   throw Exception(IMAGE_FORMAT, &file_name, "can not determine image type - no file name extension");
                         &file_name,   
                         "can not determine image type - no file name extension");  
 }  }
   
 // methods  // methods
Line 756  struct File_measure_action_info { Line 700  struct File_measure_action_info {
         ushort* width;          ushort* width;
         ushort* height;          ushort* height;
         Value** exif;          Value** exif;
         const String* file_name;  
 };  };
 #endif  #endif
 static void file_measure_action(  static void file_measure_action(struct stat& /*finfo*/, int f, const String& file_spec, void *context) {
                                                                 struct stat& /*finfo*/, int f,   
                                                                 const String& /*file_spec*/, const char* fname, bool /*as_text*/,  
                                                                 void *context) {  
         File_measure_action_info& info=*static_cast<File_measure_action_info *>(context);          File_measure_action_info& info=*static_cast<File_measure_action_info *>(context);
   
         Measure_file_reader reader(f, *info.file_name, fname);          Measure_file_reader reader(f, file_spec);
         measure(*info.file_name, reader, *info.width, *info.height, info.exif);          measure(file_spec, reader, *info.width, *info.height, info.exif);
 }  }
   
 static void _measure(Request& r, MethodParams& params) {  static void _measure(Request& r, MethodParams& params) {
Line 779  static void _measure(Request& r, MethodP Line 719  static void _measure(Request& r, MethodP
         if((file_name=data.get_string())) {          if((file_name=data.get_string())) {
                 File_measure_action_info info={                  File_measure_action_info info={
                         &width, &height,                          &width, &height,
                         &exif,                          &exif
                         file_name  
                 };                  };
                 file_read_action_under_lock(r.absolute(*file_name),                   file_read_action_under_lock(r.absolute(*file_name), "measure", file_measure_action, &info);
                         "measure", file_measure_action, &info);  
         } else {          } else {
                 VFile* vfile=data.as_vfile(String::L_AS_IS);                  VFile* vfile=data.as_vfile(String::L_AS_IS);
                 file_name=&vfile->fields().get(name_name)->as_string();                  file_name=&vfile->fields().get(name_name)->as_string();
Line 804  struct Attrib_info { Line 742  struct Attrib_info {
         HashStringValue* skip; ///< tag attributes not to append to tag string [to skip]          HashStringValue* skip; ///< tag attributes not to append to tag string [to skip]
 };  };
 #endif  #endif
 static void append_attrib_pair(  static void append_attrib_pair(HashStringValue::key_type key, HashStringValue::value_type value, Attrib_info* info) {
                                 HashStringValue::key_type key,   
                                 HashStringValue::value_type value,   
                                 Attrib_info* info) {  
         // skip user-specified, internal(starting with "line-") attributes and border attribute with empty value          // skip user-specified, internal(starting with "line-") attributes and border attribute with empty value
         if(          if(
                 (info->skip && info->skip->get(key))                  (info->skip && info->skip->get(key))
Line 831  static void _html(Request& r, MethodPara Line 766  static void _html(Request& r, MethodPara
   
         if(params.count()) {          if(params.count()) {
                 // for backward compatibility: someday was ^html{}                  // for backward compatibility: someday was ^html{}
                 Value& vattribs=r.process_to_value(params[0], false/*don't intercept string*/);                  Value& vattribs=r.process(params[0]);
                 if(!vattribs.is_string()) { // allow empty                  if(!vattribs.is_string()) { // allow empty
                         if((attribs=vattribs.get_hash())) {                          if((attribs=vattribs.get_hash())) {
                                 Attrib_info info={&tag, 0};                                  Attrib_info info={&tag, 0};
                                 attribs->for_each<Attrib_info*>(append_attrib_pair, &info);                                  attribs->for_each<Attrib_info*>(append_attrib_pair, &info);
                         } else                          } else
                                 throw Exception(PARSER_RUNTIME,                                   throw Exception(PARSER_RUNTIME, 0, "attributes must be hash");
                                         0,   
                                         "attributes must be hash");  
                 }                  }
         }          }
   
Line 852  static void _html(Request& r, MethodPara Line 785  static void _html(Request& r, MethodPara
 }  }
   
 /// @test wrap FILE to auto-object  /// @test wrap FILE to auto-object
 static gdImage* load(Request& r,   static gdImage* load(Request& r, const String& file_name){
                                          const String& file_name){  
         const char* file_name_cstr=r.absolute(file_name).taint_cstr(String::L_FILE_SPEC);          const char* file_name_cstr=r.absolute(file_name).taint_cstr(String::L_FILE_SPEC);
         if(FILE *f=fopen(file_name_cstr, "rb")) {          if(FILE *f=fopen(file_name_cstr, "rb")) {
                 gdImage* image=new gdImage;                  gdImage* image=new gdImage;
                 bool ok=image->CreateFromGif(f);                  bool ok=image->CreateFromGif(f);
                 fclose(f);                  fclose(f);
                 if(!ok)                  if(!ok)
                         throw Exception(IMAGE_FORMAT,                           throw Exception(IMAGE_FORMAT, &file_name, "is not in GIF format");
                                 &file_name,  
                                 "is not in GIF format");  
                 return image;                  return image;
         } else {          } else {
                 throw Exception("file.missing",                   throw Exception("file.missing", 0, "can not open '%s'", file_name_cstr);
                         0,   
                         "can not open '%s'", file_name_cstr);  
         }          }
 }  }
   
Line 948  static void _bar(Request& r, MethodParam Line 876  static void _bar(Request& r, MethodParam
 }  }
   
 #ifndef DOXYGEN  #ifndef DOXYGEN
 static void add_point(Table::element_type row,   static void add_point(Table::element_type row, gdImage::Point **p) {
                                           gdImage::Point **p) {  
         if(row->count()!=2)          if(row->count()!=2)
                 throw Exception(0,                  throw Exception(0, 0, "coordinates table must contain two columns: x and y values");
                         0,  
                         "coordinates table must contain two columns: x and y values");  
         (**p).x=row->get(0)->as_int();          (**p).x=row->get(0)->as_int();
         (**p).y=row->get(1)->as_int();          (**p).y=row->get(1)->as_int();
         (*p)++;          (*p)++;
 }  }
 #endif  #endif
 #ifndef DOXYGEN  #ifndef DOXYGEN
 static void add_point(int x, int y,   static void add_point(int x, int y, gdImage::Point **p) {
                                           gdImage::Point **p) {  
         (**p).x=x;          (**p).x=x;
         (**p).y=y;          (**p).y=y;
         (*p)++;          (*p)++;
Line 1042  static void _polybar(Request& r, MethodP Line 966  static void _polybar(Request& r, MethodP
   
 // Font class  // Font class
   
 Font::Font(  Font::Font(Charset& asource_charset, const String& aalphabet, gdImage* aifont, int aheight, int amonospace, int aspacebarspace, int aletterspacing):
         Charset& asource_charset,   
         const String& aalphabet,   
         gdImage* aifont, int aheight, int amonospace, int aspacebarspace, int aletterspacing):  
         fsource_charset(asource_charset),          fsource_charset(asource_charset),
         height(aheight),          height(aheight),
         monospace(amonospace),          monospace(amonospace),
Line 1137  static void _font(Request& r, MethodPara Line 1058  static void _font(Request& r, MethodPara
         const String& alphabet=params.as_string(0, "alphabet must not be code");          const String& alphabet=params.as_string(0, "alphabet must not be code");
         size_t alphabet_length=alphabet.length(r.charsets.source());          size_t alphabet_length=alphabet.length(r.charsets.source());
         if(!alphabet_length)          if(!alphabet_length)
                 throw Exception(PARSER_RUNTIME,                  throw Exception(PARSER_RUNTIME, 0, "alphabet must not be empty");
                         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_string(1, FILE_NAME_MUST_NOT_BE_CODE));
   
Line 1154  static void _font(Request& r, MethodPara Line 1073  static void _font(Request& r, MethodPara
                         int valid_options=0;                          int valid_options=0;
                         if(Value* vspacebar_width=options->get(spacebar_width_name)){                          if(Value* vspacebar_width=options->get(spacebar_width_name)){
                                 valid_options++;                                  valid_options++;
                                 spacebar_width=r.process_to_value(*vspacebar_width).as_int();                                  spacebar_width=r.process(*vspacebar_width).as_int();
                         }                          }
                         if(Value* vmonospace_width=options->get(monospace_width_name)){                          if(Value* vmonospace_width=options->get(monospace_width_name)){
                                 valid_options++;                                  valid_options++;
                                 monospace_width=r.process_to_value(*vmonospace_width).as_int();                                  monospace_width=r.process(*vmonospace_width).as_int();
                                 if(!monospace_width)                                  if(!monospace_width)
                                         monospace_width=image->SX();                                          monospace_width=image->SX();
                         }                          }
                         if(Value* vletter_spacing=options->get(letter_spacing_name)){                          if(Value* vletter_spacing=options->get(letter_spacing_name)){
                                 valid_options++;                                  valid_options++;
                                 letter_spacing=r.process_to_value(*vletter_spacing).as_int();                                  letter_spacing=r.process(*vletter_spacing).as_int();
                         }                          }
                         if(valid_options!=options->count())                          if(valid_options!=options->count())
                                 throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION);                                  throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION);
Line 1180  static void _font(Request& r, MethodPara Line 1099  static void _font(Request& r, MethodPara
         }          }
   
         if(int remainder=image->SY() % alphabet_length)          if(int remainder=image->SY() % alphabet_length)
                 throw Exception(PARSER_RUNTIME,                  throw Exception(PARSER_RUNTIME, 0, "font-file height(%d) not divisable by alphabet size(%d), remainder=%d", image->SY(), alphabet_length, remainder);
                         0,  
                         "font-file height(%d) not divisable by alphabet size(%d), remainder=%d",  
                                 image->SY(), alphabet_length, remainder);  
                   
         GET_SELF(r, VImage).set_font(new Font(          GET_SELF(r, VImage).set_font(new Font(r.charsets.source(), alphabet, image, image->SY() / alphabet_length, monospace_width, spacebar_width, letter_spacing));
                 r.charsets.source(),  
                 alphabet,   
                 image,   
                 image->SY() / alphabet_length, monospace_width, spacebar_width, letter_spacing));  
 }  }
   
 static void _text(Request& r, MethodParams& params) {  static void _text(Request& r, MethodParams& params) {
Line 1254  gdImage& as_image(MethodParams& params, Line 1166  gdImage& as_image(MethodParams& params,
         if(Value* vimage=value.as(VIMAGE_TYPE)) {          if(Value* vimage=value.as(VIMAGE_TYPE)) {
                 return static_cast<VImage *>(vimage)->image();                  return static_cast<VImage *>(vimage)->image();
         } else          } else
                 throw Exception(PARSER_RUNTIME,                   throw Exception(PARSER_RUNTIME, 0, msg);
                         0,   
                         msg);  
 }  }
   
 static void _copy(Request& r, MethodParams& params) {  static void _copy(Request& r, MethodParams& params) {

Removed from v.1.151  
changed lines
  Added in v.1.155


E-mail: