Debian Codegraph @

font_win32_tt/agg_font_win32_tt.h

raw
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.4
3 // Copyright (C) 2002-2005 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: [email protected]
12 // [email protected]
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
15
16 #ifndef AGG_FONT_WIN32_TT_INCLUDED
17 #define AGG_FONT_WIN32_TT_INCLUDED
18
19 #include <windows.h>
20 #include "agg_scanline_storage_aa.h"
21 #include "agg_scanline_storage_bin.h"
22 #include "agg_scanline_u.h"
23 #include "agg_scanline_bin.h"
24 #include "agg_path_storage_integer.h"
25 #include "agg_rasterizer_scanline_aa.h"
26 #include "agg_conv_curve.h"
27 #include "agg_trans_affine.h"
28 #include "agg_font_cache_manager.h"
29
30 namespace agg
31 {
32
33 //-----------------------------------------------font_engine_win32_tt_base
34 class font_engine_win32_tt_base
35 {
36 enum { buf_size = 32768-32 };
37
38 public:
39 //--------------------------------------------------------------------
40 typedef serialized_scanlines_adaptor_aa<int8u> gray8_adaptor_type;
41 typedef serialized_scanlines_adaptor_bin mono_adaptor_type;
42 typedef scanline_storage_aa8 scanlines_aa_type;
43 typedef scanline_storage_bin scanlines_bin_type;
44
45 //--------------------------------------------------------------------
46 ~font_engine_win32_tt_base();
47 font_engine_win32_tt_base(bool flag32, HDC dc, unsigned max_fonts = 32);
48
49 // Set font parameters
50 //--------------------------------------------------------------------
51 void resolution(unsigned dpi) { m_resolution = unsigned(dpi); }
52 void height(double h) { m_height = unsigned(h); }
53 void width(double w) { m_width = unsigned(w); }
54 void weight(int w) { m_weight = w; }
55 void italic(bool it) { m_italic = it; }
56 void char_set(DWORD c) { m_char_set = c; }
57 void pitch_and_family(DWORD p){ m_pitch_and_family = p; }
58 void flip_y(bool flip) { m_flip_y = flip; }
59 void hinting(bool h) { m_hinting = h; }
60 bool create_font(const char* typeface_, glyph_rendering ren_type);
61
62 bool create_font(const char* typeface_,
63 glyph_rendering ren_type,
64 double height_,
65 double width_=0.0,
66 int weight_=FW_REGULAR,
67 bool italic_=false,
68 DWORD char_set_=ANSI_CHARSET,
69 DWORD pitch_and_family_=FF_DONTCARE);
70
71 // Set Gamma
72 //--------------------------------------------------------------------
73 template<class GammaF> void gamma(const GammaF& f)
74 {
75 m_rasterizer.gamma(f);
76 }
77
78 //--------------------------------------------------------------------
79 void transform(const agg::trans_affine& mtx)
80 {
81 m_affine = mtx;
82 }
83
84 // Accessors
85 //--------------------------------------------------------------------
86 unsigned resolution() const { return m_resolution; }
87 const char* typeface() const { return m_typeface; }
88 double height() const { return m_height; }
89 double width() const { return m_width; }
90 int weight() const { return m_weight; }
91 bool italic() const { return m_italic; }
92 DWORD char_set() const { return m_char_set; }
93 DWORD pitch_and_family() const { return m_pitch_and_family; }
94 bool hinting() const { return m_hinting; }
95 bool flip_y() const { return m_flip_y; }
96
97
98 // Interface mandatory to implement for font_cache_manager
99 //--------------------------------------------------------------------
100 const char* font_signature() const { return m_signature; }
101 int change_stamp() const { return m_change_stamp; }
102
103 bool prepare_glyph(unsigned glyph_code);
104 unsigned glyph_index() const { return m_glyph_index; }
105 unsigned data_size() const { return m_data_size; }
106 glyph_data_type data_type() const { return m_data_type; }
107 const rect_i& bounds() const { return m_bounds; }
108 double advance_x() const { return m_advance_x; }
109 double advance_y() const { return m_advance_y; }
110 void write_glyph_to(int8u* data) const;
111 bool add_kerning(unsigned first, unsigned second,
112 double* x, double* y);
113
114 private:
115 font_engine_win32_tt_base(const font_engine_win32_tt_base&);
116 const font_engine_win32_tt_base& operator = (const font_engine_win32_tt_base&);
117
118 void update_signature();
119 void load_kerning_pairs();
120 void sort_kerning_pairs();
121 int find_font(const char* name) const;
122
123 bool m_flag32;
124 HDC m_dc;
125 HFONT m_old_font;
126 HFONT* m_fonts;
127 unsigned m_num_fonts;
128 unsigned m_max_fonts;
129 char** m_font_names;
130 HFONT m_cur_font;
131
132 int m_change_stamp;
133 char* m_typeface;
134 unsigned m_typeface_len;
135 char* m_signature;
136 unsigned m_height;
137 unsigned m_width;
138 int m_weight;
139 bool m_italic;
140 DWORD m_char_set;
141 DWORD m_pitch_and_family;
142 bool m_hinting;
143 bool m_flip_y;
144
145 bool m_font_created;
146 unsigned m_resolution;
147 glyph_rendering m_glyph_rendering;
148 unsigned m_glyph_index;
149 unsigned m_data_size;
150 glyph_data_type m_data_type;
151 rect_i m_bounds;
152 double m_advance_x;
153 double m_advance_y;
154 MAT2 m_matrix;
155 char* m_gbuf;
156 KERNINGPAIR* m_kerning_pairs;
157 unsigned m_num_kerning_pairs;
158 unsigned m_max_kerning_pairs;
159 trans_affine m_affine;
160
161 path_storage_integer<int16, 6> m_path16;
162 path_storage_integer<int32, 6> m_path32;
163 conv_curve<path_storage_integer<int16, 6> > m_curves16;
164 conv_curve<path_storage_integer<int32, 6> > m_curves32;
165 scanline_u8 m_scanline_aa;
166 scanline_bin m_scanline_bin;
167 scanlines_aa_type m_scanlines_aa;
168 scanlines_bin_type m_scanlines_bin;
169 rasterizer_scanline_aa<> m_rasterizer;
170 };
171
172
173
174
175 //------------------------------------------------font_engine_win32_tt_int16
176 // This class uses values of type int16 (10.6 format) for the vector cache.
177 // The vector cache is compact, but when rendering glyphs of height
178 // more that 200 there integer overflow can occur.
179 //
180 class font_engine_win32_tt_int16 : public font_engine_win32_tt_base
181 {
182 public:
183 typedef serialized_integer_path_adaptor<int16, 6> path_adaptor_type;
184 typedef font_engine_win32_tt_base::gray8_adaptor_type gray8_adaptor_type;
185 typedef font_engine_win32_tt_base::mono_adaptor_type mono_adaptor_type;
186 typedef font_engine_win32_tt_base::scanlines_aa_type scanlines_aa_type;
187 typedef font_engine_win32_tt_base::scanlines_bin_type scanlines_bin_type;
188
189 font_engine_win32_tt_int16(HDC dc, unsigned max_fonts = 32) :
190 font_engine_win32_tt_base(false, dc, max_fonts) {}
191 };
192
193 //------------------------------------------------font_engine_win32_tt_int32
194 // This class uses values of type int32 (26.6 format) for the vector cache.
195 // The vector cache is twice larger than in font_engine_win32_tt_int16,
196 // but it allows you to render glyphs of very large sizes.
197 //
198 class font_engine_win32_tt_int32 : public font_engine_win32_tt_base
199 {
200 public:
201 typedef serialized_integer_path_adaptor<int32, 6> path_adaptor_type;
202 typedef font_engine_win32_tt_base::gray8_adaptor_type gray8_adaptor_type;
203 typedef font_engine_win32_tt_base::mono_adaptor_type mono_adaptor_type;
204 typedef font_engine_win32_tt_base::scanlines_aa_type scanlines_aa_type;
205 typedef font_engine_win32_tt_base::scanlines_bin_type scanlines_bin_type;
206
207 font_engine_win32_tt_int32(HDC dc, unsigned max_fonts = 32) :
208 font_engine_win32_tt_base(true, dc, max_fonts) {}
209 };
210
211
212 }
213
214 #endif