Anti-Grain Geometry - AGG (libagg)  2.5
agg-2.5/include/agg_gsv_text.h
Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 // Anti-Grain Geometry (AGG) - Version 2.5
00003 // A high quality rendering engine for C++
00004 // Copyright (C) 2002-2006 Maxim Shemanarev
00005 // Contact: mcseem@antigrain.com
00006 //          mcseemagg@yahoo.com
00007 //          http://antigrain.com
00008 // 
00009 // AGG is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU General Public License
00011 // as published by the Free Software Foundation; either version 2
00012 // of the License, or (at your option) any later version.
00013 // 
00014 // AGG is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU General Public License
00020 // along with AGG; if not, write to the Free Software
00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00022 // MA 02110-1301, USA.
00023 //----------------------------------------------------------------------------
00024 
00025 #ifndef AGG_GSV_TEXT_INCLUDED
00026 #define AGG_GSV_TEXT_INCLUDED
00027 
00028 #include "agg_array.h"
00029 #include "agg_conv_stroke.h"
00030 #include "agg_conv_transform.h"
00031 
00032 namespace agg
00033 {
00034 
00035 
00036     //---------------------------------------------------------------gsv_text
00037     //
00038     // See Implementation agg_gsv_text.cpp 
00039     //
00040     class gsv_text
00041     {
00042         enum status
00043         {
00044             initial,
00045             next_char,
00046             start_glyph,
00047             glyph
00048         };
00049 
00050     public:
00051         gsv_text();
00052 
00053         void font(const void* font);
00054         void flip(bool flip_y) { m_flip = flip_y; }
00055         void load_font(const char* file);
00056         void size(double height, double width=0.0);
00057         void space(double space);
00058         void line_space(double line_space);
00059         void start_point(double x, double y);
00060         void text(const char* text);
00061         
00062         double text_width();
00063 
00064         void rewind(unsigned path_id);
00065         unsigned vertex(double* x, double* y);
00066 
00067     private:
00068         // not supposed to be copied
00069         gsv_text(const gsv_text&);
00070         const gsv_text& operator = (const gsv_text&);
00071 
00072         int16u value(const int8u* p) const
00073         {
00074             int16u v;
00075             if(m_big_endian)
00076             {
00077                  *(int8u*)&v      = p[1];
00078                 *((int8u*)&v + 1) = p[0];
00079             }
00080             else
00081             {
00082                  *(int8u*)&v      = p[0];
00083                 *((int8u*)&v + 1) = p[1];
00084             }
00085             return v;
00086         }
00087 
00088     private:
00089         double          m_x;
00090         double          m_y;
00091         double          m_start_x;
00092         double          m_width;
00093         double          m_height;
00094         double          m_space;
00095         double          m_line_space;
00096         char            m_chr[2];
00097         char*           m_text;
00098         pod_array<char> m_text_buf;
00099         char*           m_cur_chr;
00100         const void*     m_font;
00101         pod_array<char> m_loaded_font;
00102         status          m_status;
00103         bool            m_big_endian;
00104         bool            m_flip;
00105         int8u*          m_indices;
00106         int8*           m_glyphs;
00107         int8*           m_bglyph;
00108         int8*           m_eglyph;
00109         double          m_w;
00110         double          m_h;
00111     };
00112 
00113 
00114 
00115 
00116     //--------------------------------------------------------gsv_text_outline
00117     template<class Transformer = trans_affine> class gsv_text_outline
00118     {
00119     public:
00120         gsv_text_outline(gsv_text& text, const Transformer& trans) :
00121           m_polyline(text),
00122           m_trans(m_polyline, trans)
00123         {
00124         }
00125 
00126         void width(double w) 
00127         { 
00128             m_polyline.width(w); 
00129         }
00130 
00131         void transformer(const Transformer* trans) 
00132         {
00133             m_trans->transformer(trans);
00134         }
00135 
00136         void rewind(unsigned path_id) 
00137         { 
00138             m_trans.rewind(path_id); 
00139             m_polyline.line_join(round_join);
00140             m_polyline.line_cap(round_cap);
00141         }
00142 
00143         unsigned vertex(double* x, double* y)
00144         {
00145             return m_trans.vertex(x, y);
00146         }
00147 
00148     private:
00149         conv_stroke<gsv_text> m_polyline;
00150         conv_transform<conv_stroke<gsv_text>, Transformer> m_trans;
00151     };
00152 
00153 
00154 
00155 }
00156 
00157 
00158 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines