Git init
[external/pango1.0.git] / pango / pangowin32-private.h
1 /* Pango
2  * pangowin32-private.h:
3  *
4  * Copyright (C) 1999 Red Hat Software
5  * Copyright (C) 2000-2002 Tor Lillqvist
6  * Copyright (C) 2001 Alexander Larsson
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #ifndef __PANGOWIN32_PRIVATE_H__
25 #define __PANGOWIN32_PRIVATE_H__
26
27 /* Define if you want the possibility to get copious debugging output.
28  * (You still need to set the PANGO_WIN32_DEBUG environment variable
29  * to get it.)
30  */
31 #define PANGO_WIN32_DEBUGGING 1
32
33 #ifdef PANGO_WIN32_DEBUGGING
34 #ifdef __GNUC__
35 #define PING(printlist)                                 \
36 (_pango_win32_debug ?                                   \
37  (g_print ("%s:%d ", __PRETTY_FUNCTION__, __LINE__),    \
38   g_print printlist,                                    \
39   g_print ("\n"),                                       \
40   0) :                                                  \
41  0)
42 #else
43 #define PING(printlist)                                 \
44 (_pango_win32_debug ?                                   \
45  (g_print ("%s:%d ", __FILE__, __LINE__),               \
46   g_print printlist,                                    \
47   g_print ("\n"),                                       \
48   0) :                                                  \
49  0)
50 #endif
51 #else  /* !PANGO_WIN32_DEBUGGING */
52 #define PING(printlist)
53 #endif
54
55 #include <pango/pango-modules.h>
56 #include <pango/pangowin32.h>
57
58 typedef enum
59   {
60     PANGO_WIN32_COVERAGE_UNSPEC,
61     PANGO_WIN32_COVERAGE_ZH_TW,
62     PANGO_WIN32_COVERAGE_ZH_CN,
63     PANGO_WIN32_COVERAGE_JA,
64     PANGO_WIN32_COVERAGE_KO,
65     PANGO_WIN32_COVERAGE_VI,
66     PANGO_WIN32_N_COVERAGES
67   } PangoWin32CoverageLanguageClass;
68
69 #define PANGO_TYPE_WIN32_FONT_MAP             (_pango_win32_font_map_get_type ())
70 #define PANGO_WIN32_FONT_MAP(object)          (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_WIN32_FONT_MAP, PangoWin32FontMap))
71 #define PANGO_WIN32_IS_FONT_MAP(object)       (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_WIN32_FONT_MAP))
72 #define PANGO_WIN32_FONT_MAP_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_WIN32_FONT_MAP, PangoWin32FontMapClass))
73 #define PANGO_IS_WIN32_FONT_MAP_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_WIN32_FONT_MAP))
74 #define PANGO_WIN32_FONT_MAP_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_WIN32_FONT_MAP, PangoWin32FontMapClass))
75
76 #define PANGO_TYPE_WIN32_FONT            (_pango_win32_font_get_type ())
77 #define PANGO_WIN32_FONT(object)         (G_TYPE_CHECK_INSTANCE_CAST ((object), PANGO_TYPE_WIN32_FONT, PangoWin32Font))
78 #define PANGO_WIN32_FONT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), PANGO_TYPE_WIN32_FONT, PangoWin32FontClass))
79 #define PANGO_WIN32_IS_FONT(object)      (G_TYPE_CHECK_INSTANCE_TYPE ((object), PANGO_TYPE_WIN32_FONT))
80 #define PANGO_WIN32_IS_FONT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PANGO_TYPE_WIN32_FONT))
81 #define PANGO_WIN32_FONT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), PANGO_TYPE_WIN32_FONT, PangoWin32FontClass))
82
83 typedef struct _PangoWin32FontMap      PangoWin32FontMap;
84 typedef struct _PangoWin32FontMapClass PangoWin32FontMapClass;
85 typedef struct _PangoWin32Font         PangoWin32Font;
86 typedef struct _PangoWin32FontClass    PangoWin32FontClass;
87 typedef struct _PangoWin32Face         PangoWin32Face;
88 typedef struct _PangoWin32GlyphInfo    PangoWin32GlyphInfo;
89 typedef struct _PangoWin32MetricsInfo  PangoWin32MetricsInfo;
90
91 struct _PangoWin32FontMap
92 {
93   PangoFontMap parent_instance;
94
95   PangoWin32FontCache *font_cache;
96   GQueue *freed_fonts;
97
98   /* Map Pango family names to PangoWin32Family structs */
99   GHashTable *families;
100
101   /* Map LOGFONTWs (taking into account only the lfFaceName, lfItalic
102    * and lfWeight fields) to LOGFONTWs corresponding to actual fonts
103    * installed.
104    */
105   GHashTable *fonts;
106
107   double resolution;            /* (points / pixel) * PANGO_SCALE */
108 };
109
110 struct _PangoWin32FontMapClass
111 {
112   PangoFontMapClass parent_class;
113
114   PangoFont *(*find_font) (PangoWin32FontMap          *fontmap,
115                            PangoContext               *context,
116                            PangoWin32Face             *face,
117                            const PangoFontDescription *desc);
118
119 };
120
121 struct _PangoWin32Font
122 {
123   PangoFont font;
124
125   LOGFONTW logfontw;
126   int size;
127
128   GSList *metrics_by_lang;
129
130   PangoFontMap *fontmap;
131
132   /* Written by pango_win32_get_hfont: */
133   HFONT hfont;
134   gint tm_ascent;
135   gint tm_descent;
136   gint tm_overhang;
137
138   PangoWin32Face *win32face;
139
140   /* If TRUE, font is in cache of recently unused fonts and not otherwise
141    * in use.
142    */
143   gboolean in_cache;
144   GHashTable *glyph_info;
145 };
146
147 struct _PangoWin32FontClass
148 {
149   PangoFontClass parent_class;
150
151   gboolean (*select_font)        (PangoFont *font,
152                                   HDC        hdc);
153   void     (*done_font)          (PangoFont *font);
154   double   (*get_metrics_factor) (PangoFont *font);
155 };
156
157 struct _PangoWin32Face
158 {
159   PangoFontFace parent_instance;
160
161   LOGFONTW logfontw;
162   PangoFontDescription *description;
163   PangoCoverage *coverages[PANGO_WIN32_N_COVERAGES];
164   char *face_name;
165   gboolean is_synthetic;
166
167   gboolean has_cmap;
168   guint16 cmap_format;
169   gpointer cmap;
170
171   GSList *cached_fonts;
172 };
173
174 struct _PangoWin32GlyphInfo
175 {
176   PangoRectangle logical_rect;
177   PangoRectangle ink_rect;
178 };
179
180 struct _PangoWin32MetricsInfo
181 {
182   const char *sample_str;
183   PangoFontMetrics *metrics;
184 };
185
186 /* TrueType defines: */
187
188 #define MAKE_TT_TABLE_NAME(c1, c2, c3, c4) \
189    (((guint32)c4) << 24 | ((guint32)c3) << 16 | ((guint32)c2) << 8 | ((guint32)c1))
190
191 #define CMAP (MAKE_TT_TABLE_NAME('c','m','a','p'))
192 #define CMAP_HEADER_SIZE 4
193
194 #define NAME (MAKE_TT_TABLE_NAME('n','a','m','e'))
195 #define NAME_HEADER_SIZE 6
196
197 #define ENCODING_TABLE_SIZE 8
198
199 #define APPLE_UNICODE_PLATFORM_ID 0
200 #define MACINTOSH_PLATFORM_ID 1
201 #define ISO_PLATFORM_ID 2
202 #define MICROSOFT_PLATFORM_ID 3
203
204 #define SYMBOL_ENCODING_ID 0
205 #define UNICODE_ENCODING_ID 1
206 #define UCS4_ENCODING_ID 10
207
208 /* All the below structs must be packed! */
209
210 struct cmap_encoding_subtable
211 {
212   guint16 platform_id;
213   guint16 encoding_id;
214   guint32 offset;
215 };
216
217 struct format_4_cmap
218 {
219   guint16 format;
220   guint16 length;
221   guint16 language;
222   guint16 seg_count_x_2;
223   guint16 search_range;
224   guint16 entry_selector;
225   guint16 range_shift;
226
227   guint16 reserved;
228
229   guint16 arrays[1];
230 };
231
232 struct format_12_cmap
233 {
234   guint16 format;
235   guint16 reserved;
236   guint32 length;
237   guint32 language;
238   guint32 count;
239
240   guint32 groups[1];
241 };
242
243 struct name_header
244 {
245   guint16 format_selector;
246   guint16 num_records;
247   guint16 string_storage_offset;
248 };
249
250 struct name_record
251 {
252   guint16 platform_id;
253   guint16 encoding_id;
254   guint16 language_id;
255   guint16 name_id;
256   guint16 string_length;
257   guint16 string_offset;
258 };
259
260 GType           _pango_win32_font_get_type          (void) G_GNUC_CONST;
261
262 void            _pango_win32_make_matching_logfontw (PangoFontMap   *fontmap,
263                                                      const LOGFONTW *lfp,
264                                                      int             size,
265                                                      LOGFONTW       *out);
266
267 GType           _pango_win32_font_map_get_type      (void) G_GNUC_CONST;
268
269 void            _pango_win32_fontmap_cache_remove   (PangoFontMap   *fontmap,
270                                                      PangoWin32Font *xfont);
271
272 gboolean        _pango_win32_get_name_header        (HDC                 hdc,
273                                                      struct name_header *header);
274 gboolean        _pango_win32_get_name_record        (HDC                 hdc,
275                                                      gint                i,
276                                                      struct name_record *record);
277
278 extern HDC _pango_win32_hdc;
279 extern OSVERSIONINFO _pango_win32_os_version_info;
280 extern gboolean _pango_win32_debug;
281
282 #endif /* __PANGOWIN32_PRIVATE_H__ */