Merge pull request #10 from gunyarakun/fix-invalid-return
[cocotron.git] / O2Context_AntiGrain / agg_font_win32_tt.h
blob57ae94925f836f1aec0afe5d1acee880e11a4808
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: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 #ifndef AGG_FONT_WIN32_TT_INCLUDED
17 #define AGG_FONT_WIN32_TT_INCLUDED
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"
30 // Modified for O2Context_AntiGran to match default Cocotron GDI fonts default value
31 // and to get glyph by glyph index, and not ASCII code
33 namespace agg
36 //-----------------------------------------------font_engine_win32_tt_base
37 class font_engine_win32_tt_base
39 enum { buf_size = 32768-32 };
41 public:
42 //--------------------------------------------------------------------
43 typedef serialized_scanlines_adaptor_aa<int8u> gray8_adaptor_type;
44 typedef serialized_scanlines_adaptor_bin mono_adaptor_type;
45 typedef scanline_storage_aa8 scanlines_aa_type;
46 typedef scanline_storage_bin scanlines_bin_type;
48 //--------------------------------------------------------------------
49 ~font_engine_win32_tt_base();
50 font_engine_win32_tt_base(bool flag32, HDC dc, unsigned max_fonts = 32);
52 // Set font parameters
53 //--------------------------------------------------------------------
54 void resolution(unsigned dpi) { m_resolution = unsigned(dpi); }
55 void height(double h) { m_height = unsigned(h); }
56 void width(double w) { m_width = unsigned(w); }
57 void weight(int w) { m_weight = w; }
58 void italic(bool it) { m_italic = it; }
59 void char_set(DWORD c) { m_char_set = c; }
60 void pitch_and_family(DWORD p){ m_pitch_and_family = p; }
61 void flip_y(bool flip) { m_flip_y = flip; }
62 void hinting(bool h) { m_hinting = h; }
63 bool create_font(const char* typeface_, glyph_rendering ren_type);
65 bool create_font(const char* typeface_,
66 glyph_rendering ren_type,
67 double height_,
68 double width_=0.0,
69 int weight_=FW_REGULAR,
70 bool italic_=false,
71 DWORD char_set_=DEFAULT_CHARSET,
72 DWORD pitch_and_family_=DEFAULT_PITCH|FF_DONTCARE);
74 // Set Gamma
75 //--------------------------------------------------------------------
76 template<class GammaF> void gamma(const GammaF& f)
78 m_rasterizer.gamma(f);
81 //--------------------------------------------------------------------
82 void transform(const agg::trans_affine& mtx)
84 m_affine = mtx;
87 // Accessors
88 //--------------------------------------------------------------------
89 unsigned resolution() const { return m_resolution; }
90 const char* typeface() const { return m_typeface; }
91 double height() const { return m_height; }
92 double width() const { return m_width; }
93 int weight() const { return m_weight; }
94 bool italic() const { return m_italic; }
95 DWORD char_set() const { return m_char_set; }
96 DWORD pitch_and_family() const { return m_pitch_and_family; }
97 bool hinting() const { return m_hinting; }
98 bool flip_y() const { return m_flip_y; }
101 // Interface mandatory to implement for font_cache_manager
102 //--------------------------------------------------------------------
103 const char* font_signature() const { return m_signature; }
104 int change_stamp() const { return m_change_stamp; }
106 bool prepare_glyph(unsigned glyph_code);
107 unsigned glyph_index() const { return m_glyph_index; }
108 unsigned data_size() const { return m_data_size; }
109 glyph_data_type data_type() const { return m_data_type; }
110 const rect_i& bounds() const { return m_bounds; }
111 double advance_x() const { return m_advance_x; }
112 double advance_y() const { return m_advance_y; }
113 void write_glyph_to(int8u* data) const;
114 bool add_kerning(unsigned first, unsigned second,
115 double* x, double* y);
117 private:
118 font_engine_win32_tt_base(const font_engine_win32_tt_base&);
119 const font_engine_win32_tt_base& operator = (const font_engine_win32_tt_base&);
121 void update_signature();
122 void load_kerning_pairs();
123 void sort_kerning_pairs();
124 int find_font(const char* name) const;
126 bool m_flag32;
127 HDC m_dc;
128 HFONT m_old_font;
129 HFONT* m_fonts;
130 unsigned m_num_fonts;
131 unsigned m_max_fonts;
132 char** m_font_names;
133 HFONT m_cur_font;
135 int m_change_stamp;
136 char* m_typeface;
137 unsigned m_typeface_len;
138 char* m_signature;
139 unsigned m_height;
140 unsigned m_width;
141 int m_weight;
142 bool m_italic;
143 DWORD m_char_set;
144 DWORD m_pitch_and_family;
145 bool m_hinting;
146 bool m_flip_y;
148 bool m_font_created;
149 unsigned m_resolution;
150 glyph_rendering m_glyph_rendering;
151 unsigned m_glyph_index;
152 unsigned m_data_size;
153 glyph_data_type m_data_type;
154 rect_i m_bounds;
155 double m_advance_x;
156 double m_advance_y;
157 MAT2 m_matrix;
158 char* m_gbuf;
159 KERNINGPAIR* m_kerning_pairs;
160 unsigned m_num_kerning_pairs;
161 unsigned m_max_kerning_pairs;
162 trans_affine m_affine;
164 path_storage_integer<int16, 6> m_path16;
165 path_storage_integer<int32, 6> m_path32;
166 conv_curve<path_storage_integer<int16, 6> > m_curves16;
167 conv_curve<path_storage_integer<int32, 6> > m_curves32;
168 scanline_u8 m_scanline_aa;
169 scanline_bin m_scanline_bin;
170 scanlines_aa_type m_scanlines_aa;
171 scanlines_bin_type m_scanlines_bin;
172 rasterizer_scanline_aa<> m_rasterizer;
178 //------------------------------------------------font_engine_win32_tt_int16
179 // This class uses values of type int16 (10.6 format) for the vector cache.
180 // The vector cache is compact, but when rendering glyphs of height
181 // more that 200 there integer overflow can occur.
183 class font_engine_win32_tt_int16 : public font_engine_win32_tt_base
185 public:
186 typedef serialized_integer_path_adaptor<int16, 6> path_adaptor_type;
187 typedef font_engine_win32_tt_base::gray8_adaptor_type gray8_adaptor_type;
188 typedef font_engine_win32_tt_base::mono_adaptor_type mono_adaptor_type;
189 typedef font_engine_win32_tt_base::scanlines_aa_type scanlines_aa_type;
190 typedef font_engine_win32_tt_base::scanlines_bin_type scanlines_bin_type;
192 font_engine_win32_tt_int16(HDC dc, unsigned max_fonts = 32) :
193 font_engine_win32_tt_base(false, dc, max_fonts) {}
196 //------------------------------------------------font_engine_win32_tt_int32
197 // This class uses values of type int32 (26.6 format) for the vector cache.
198 // The vector cache is twice larger than in font_engine_win32_tt_int16,
199 // but it allows you to render glyphs of very large sizes.
201 class font_engine_win32_tt_int32 : public font_engine_win32_tt_base
203 public:
204 typedef serialized_integer_path_adaptor<int32, 6> path_adaptor_type;
205 typedef font_engine_win32_tt_base::gray8_adaptor_type gray8_adaptor_type;
206 typedef font_engine_win32_tt_base::mono_adaptor_type mono_adaptor_type;
207 typedef font_engine_win32_tt_base::scanlines_aa_type scanlines_aa_type;
208 typedef font_engine_win32_tt_base::scanlines_bin_type scanlines_bin_type;
210 font_engine_win32_tt_int32(HDC dc, unsigned max_fonts = 32) :
211 font_engine_win32_tt_base(true, dc, max_fonts) {}
217 #endif