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