--- parser3/src/classes/image.C 2001/09/01 14:39:25 1.36 +++ parser3/src/classes/image.C 2001/09/06 06:11:13 1.40 @@ -5,9 +5,9 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: image.C,v 1.36 2001/09/01 14:39:25 parser Exp $ + $Id: image.C,v 1.40 2001/09/06 06:11:13 parser Exp $ */ -static const char *RCSId="$Id: image.C,v 1.36 2001/09/01 14:39:25 parser Exp $"; +static const char *RCSId="$Id: image.C,v 1.40 2001/09/06 06:11:13 parser Exp $"; /* jpegsize: gets the width and height (in pixels) of a jpeg file @@ -219,11 +219,12 @@ void measure(Pool& pool, const String& f "can not determine image type - no file name extension"); } -/// used by image: _measure / read_mem +#ifndef DOXYGEN struct Read_mem_info { unsigned char *ptr; unsigned char *eof; }; +#endif static size_t read_mem(void*& buf, size_t limit, void *info) { Read_mem_info& rmi=*static_cast(info); buf=rmi.ptr; @@ -232,11 +233,12 @@ static size_t read_mem(void*& buf, size_ return read_size; } -/// used by image: _measure / read_disk +#ifndef DOXYGEN struct Read_disk_info { const String *file_spec; size_t offset; }; +#endif static size_t read_disk(void*& buf, size_t limit, void *info) { Read_disk_info& rdi=*static_cast(info); Pool& pool=rdi.file_spec->pool(); @@ -283,11 +285,12 @@ static void _measure(Request& r, const S static_cast(r.self)->set(file_name, width, height); } -/// used by image: _html / append_attrib_pair +#ifndef DOXYGEN struct Attrib_info { String *tag; ///< html tag being constructed Hash *skip; ///< tag attributes not to append to tag string [to skip] }; +#endif static void append_attrib_pair(const Hash::Key& key, Hash::Val *val, void *info) { Attrib_info& ai=*static_cast(info); @@ -309,14 +312,17 @@ static void _html(Request& r, const Stri const Hash& fields=static_cast(r.self)->fields(); Hash *attribs=0; - if(params->size()) - if(attribs=params->get(0).get_hash()) { - Attrib_info attrib_info={&tag, 0}; - attribs->for_each(append_attrib_pair, &attrib_info); - } else - PTHROW(0, 0, - &method_name, - "attributes must be must be hash"); + if(params->size()) { + Value &vattribs=params->get(0); + if(vattribs.is_defined()) // allow 'void' + if(Hash *attribs=vattribs.get_hash()) { + Attrib_info attrib_info={&tag, 0}; + attribs->for_each(append_attrib_pair, &attrib_info); + } else + PTHROW(0, 0, + &method_name, + "attributes must be hash"); + } Attrib_info attrib_info={&tag, attribs}; fields.for_each(append_attrib_pair, &attrib_info); @@ -544,7 +550,7 @@ static void _polybar(Request& r, const S class Font : public Pooled { public: - const static int kerning; + const static int letter_spacing; int height; ///< Font heigth int monospace; ///< Default char width int spacebarspace; ///< spacebar width @@ -598,26 +604,36 @@ public: if(cstr) for(; *cstr; cstr++) { int index=index_of(*cstr); index_display(image, x, y, index); - x+=kerning + (monospace ? monospace : index_width(index)); + x+=letter_spacing + (monospace ? monospace : index_width(index)); } } }; -const int Font::kerning=1; +const int Font::letter_spacing=1; static void _font(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - Value& valphabet=params->as_no_junction(0, "alphabet must not be code"); - Value& file_name=params->as_no_junction(1, "file_name must not be code"); + 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 monospace_width; + if(params->size()>3) { + monospace_width=params->as_int(3, r); + if(!monospace_width) + monospace_width=image.SX(); + } else + monospace_width=0; - int monospace_width=params->size()>3?params->as_int(3, r):0; - gdImage& image=*load(r, method_name, file_name.as_string()); + if(!alphabet.size()) + PTHROW(0, 0, + &method_name, + "alphabet must not be empty"); + static_cast(r.self)->font=new(pool) Font(pool, - valphabet.as_string(), + alphabet, image, - image.SY(), monospace_width, spacebar_width); + image.SY() / alphabet.size(), monospace_width, spacebar_width); } static void _text(Request& r, const String& method_name, MethodParams *params) {