xref: /haiku/headers/libs/agg/agg_gsv_text.h (revision abd00302375a7845543b09df3fc8cc984de984f8)
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.2
3 // Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
4 //
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
9 //
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 //          mcseemagg@yahoo.com
13 //          http://www.antigrain.com
14 //----------------------------------------------------------------------------
15 //
16 // Class gsv_text
17 //
18 //----------------------------------------------------------------------------
19 
20 #ifndef AGG_GSV_TEXT_INCLUDED
21 #define AGG_GSV_TEXT_INCLUDED
22 
23 #include "agg_basics.h"
24 #include "agg_conv_stroke.h"
25 #include "agg_conv_transform.h"
26 
27 namespace agg
28 {
29 
30 
31     //---------------------------------------------------------------gsv_text
32     //
33     // See Implementation agg_gsv_text.cpp
34     //
35     class gsv_text
36     {
37         enum status
38         {
39             initial,
40             next_char,
41             start_glyph,
42             glyph
43         };
44 
45     public:
46         ~gsv_text();
47         gsv_text();
48 
49         void font(const void* font);
50         void flip(bool flip_y) { m_flip = flip_y; }
51         void load_font(const char* file);
52         void size(double height, double width=0.0);
53         void space(double space);
54         void line_space(double line_space);
55         void start_point(double x, double y);
56         void text(const char* text);
57 
58         void rewind(unsigned id);
59         unsigned vertex(double* x, double* y);
60 
61     private:
62         // not supposed to be copied
63         gsv_text(const gsv_text&);
64         const gsv_text& operator = (const gsv_text&);
65 
66         int16u value(const int8u* p) const
67         {
68             int16u v;
69             if(m_big_endian)
70             {
71                  *(int8u*)&v      = p[1];
72                 *((int8u*)&v + 1) = p[0];
73             }
74             else
75             {
76                  *(int8u*)&v      = p[0];
77                 *((int8u*)&v + 1) = p[1];
78             }
79             return v;
80         }
81 
82     private:
83         double      m_x;
84         double      m_y;
85         double      m_start_x;
86         double      m_width;
87         double      m_height;
88         double      m_space;
89         double      m_line_space;
90         char        m_chr[2];
91         char*       m_text;
92         char*       m_text_buf;
93         unsigned    m_buf_size;
94         char*       m_cur_chr;
95         const void* m_font;
96         char*       m_loaded_font;
97         status      m_status;
98         bool        m_big_endian;
99         bool        m_flip;
100 
101         int8u*      m_indices;
102         int8*       m_glyphs;
103         int8*       m_bglyph;
104         int8*       m_eglyph;
105         double      m_w;
106         double      m_h;
107     };
108 
109 
110 
111 
112     //--------------------------------------------------------gsv_text_outline
113     template<class Transformer = trans_affine> class gsv_text_outline
114     {
115     public:
116         gsv_text_outline(gsv_text& text, const Transformer& trans) :
117           m_polyline(text),
118           m_trans(m_polyline, trans)
119         {
120         }
121 
122         void width(double w)
123         {
124             m_polyline.width(w);
125         }
126 
127         void transformer(const Transformer* trans)
128         {
129             m_trans->transformer(trans);
130         }
131 
132         void rewind(unsigned id)
133         {
134             m_trans.rewind(id);
135             m_polyline.line_join(round_join);
136             m_polyline.line_cap(round_cap);
137         }
138 
139         unsigned vertex(double* x, double* y)
140         {
141             return m_trans.vertex(x, y);
142         }
143 
144     private:
145         conv_stroke<gsv_text> m_polyline;
146         conv_transform<conv_stroke<gsv_text>, Transformer> m_trans;
147     };
148 
149 
150 
151 }
152 
153 
154 #endif
155