Annotation of parser3/src/types/pa_vimage.h, revision 1.62

1.9       paf         1: /** @file
1.1       paf         2:        Parser: @b image parser type decl.
                      3: 
1.62    ! moko        4:        Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com)
        !             5:        Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1       paf         6: */
                      7: 
                      8: #ifndef PA_VIMAGE_H
                      9: #define PA_VIMAGE_H
1.26      paf        10: 
1.62    ! moko       11: #define IDENT_PA_VIMAGE_H "$Id: pa_vimage.h,v 1.61 2020/12/15 17:10:41 moko Exp $"
1.1       paf        12: 
1.12      paf        13: #include "classes.h"
1.1       paf        14: #include "pa_common.h"
                     15: #include "pa_vstateless_object.h"
1.51      misha      16: #include "pa_charset.h"
1.1       paf        17: 
1.20      parser     18: // defines
                     19: 
                     20: #define VIMAGE_TYPE "image"
                     21: 
                     22: // forwards
                     23: 
1.35      paf        24: class gdImage;
                     25: 
                     26: /// simple gdImage-based font storage & text output 
                     27: class Font: public PA_Object {
                     28: public:
                     29:        
1.49      misha      30:        int letterspacing;
1.58      moko       31:        int height;             ///< Font heigth
1.49      misha      32:        int monospace;          ///< Default char width
                     33:        int spacebarspace;      ///< spacebar width
1.35      paf        34:        gdImage* ifont;
                     35:        const String& alphabet;
                     36:        
1.38      paf        37:        Font(
1.51      misha      38:                Charset& acharset, const String& aalphabet, 
1.49      misha      39:                gdImage* aifont, int aheight, int amonospace, int aspacebarspace, int aletterspacing);
1.35      paf        40: 
1.58      moko       41:        //@{******************************** char **********************************
1.35      paf        42:        size_t index_of(char ch);
1.52      misha      43:        size_t index_of(XMLCh ch);
1.35      paf        44:        int index_width(size_t index);
1.40      paf        45:        void index_display(gdImage& image, int x, int y, size_t index);
1.35      paf        46:        //@}
                     47:        //@{******************************* string *********************************
                     48:        int step_width(int index);
                     49:        //@}
                     50:        /// counts trailing letter_spacing, consider this OK. useful for contiuations
                     51:        int string_width(const String& s);
1.58      moko       52:        void string_display(gdImage& image, int x, int y, const String& s);
1.51      misha      53: 
                     54: private:
                     55:        Charset& fsource_charset;
                     56:        Hash<XMLCh, size_t> fletter2index;
1.35      paf        57: };
1.10      paf        58: 
1.20      parser     59: // externs
                     60: 
1.35      paf        61: extern Methoded* image_class;
1.7       paf        62: 
1.8       paf        63: /** holds img attributes 
1.1       paf        64:        and [image itself]
                     65: */
1.35      paf        66: class VImage: public VStateless_object {
1.1       paf        67: public: // Value
                     68:        
1.35      paf        69:        override const char* type() const { return VIMAGE_TYPE; }
                     70:        override VStateless_class *get_class() { return image_class; }
1.1       paf        71: 
                     72:        /// VImage: true
1.35      paf        73:        override bool as_bool() const { return true; }
1.19      parser     74: 
1.58      moko       75:        /// VImage: true
1.54      moko       76:        override Value& as_expr_result();
1.47      misha      77: 
1.1       paf        78:        /// VImage: method,field
1.50      misha      79:        override Value* get_element(const String& aname);
1.15      parser     80: 
                     81:        /// VImage: field
1.55      moko       82:        override const VJunction* put_element(const String& name, Value* value);
1.1       paf        83: 
1.59      moko       84:        /// VImage: fields
                     85:        HashStringValue *get_hash() { return &ffields; }
                     86: 
1.1       paf        87: public: // usage
                     88: 
1.59      moko       89:        void set(const String* src, int width, int height, gdImage* aimage, Value* aexif=0, Value* axmp=0);
1.1       paf        90: 
1.35      paf        91:        HashStringValue& fields() { return ffields; }
1.3       paf        92: 
                     93: public:
                     94: 
1.60      moko       95:        gdImage& image() {
1.40      paf        96:                if(!fimage)
1.60      moko       97:                        throw Exception(PARSER_RUNTIME, 0, "using uninitialized image object");
1.40      paf        98:                return *fimage;
                     99:        }
                    100: 
                    101:        void set_font(Font* afont) { ffont=afont; }
1.58      moko      102: 
1.40      paf       103:        Font& font() {
                    104:                if(!ffont)
1.58      moko      105:                        throw Exception(PARSER_RUNTIME, 0, "set the font first");
1.40      paf       106:                return *ffont;
                    107:        }
1.1       paf       108: 
                    109: private:
                    110: 
1.59      moko      111:        gdImage* fimage;
1.40      paf       112:        Font* ffont;
1.35      paf       113:        HashStringValue ffields;
1.1       paf       114: 
                    115: };
                    116: 
                    117: #endif

E-mail: