ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/pango-fontmap.c
Revision: 1.5
Committed: Sun Oct 7 17:54:24 2012 UTC (11 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.4: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 /* Pango
2 * OpenGL fonts handling
3 *
4 * Copyright (C) 2000 Red Hat Software
5 * Copyright (C) 2000 Tor Lillqvist
6 * Copyright (C) 2006 Marc Lehmann <pcg@goof.com>
7 *
8 * This file 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 file 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 #include <glib.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <errno.h>
28
29 #include <fontconfig/fontconfig.h>
30
31 #include "pangoopengl.h"
32
33 struct _PangoOpenGLFontMap
34 {
35 PangoFcFontMap parent_instance;
36
37 FT_Library library;
38
39 /* Function to call on prepared patterns to do final
40 * config tweaking.
41 */
42 PangoOpenGLSubstituteFunc substitute_func;
43 gpointer substitute_data;
44 GDestroyNotify substitute_destroy;
45
46 PangoRenderer *renderer;
47 };
48
49 struct _PangoOpenGLFontMapClass
50 {
51 PangoFcFontMapClass parent_class;
52 };
53
54 G_DEFINE_TYPE (PangoOpenGLFontMap, pango_opengl_font_map, PANGO_TYPE_FC_FONT_MAP)
55
56 static void
57 pango_opengl_font_map_finalize (GObject *object)
58 {
59 PangoOpenGLFontMap *fontmap = PANGO_OPENGL_FONT_MAP (object);
60
61 if (fontmap->renderer)
62 g_object_unref (fontmap->renderer);
63
64 if (fontmap->substitute_destroy)
65 fontmap->substitute_destroy (fontmap->substitute_data);
66
67 FT_Done_FreeType (fontmap->library);
68
69 G_OBJECT_CLASS (pango_opengl_font_map_parent_class)->finalize (object);
70 }
71
72 PangoFontMap *
73 pango_opengl_font_map_new (void)
74 {
75 PangoOpenGLFontMap *fontmap;
76 FT_Error error;
77
78 /* Make sure that the type system is initialized */
79 g_type_init ();
80
81 fontmap = g_object_new (PANGO_TYPE_OPENGL_FONT_MAP, NULL);
82
83 error = FT_Init_FreeType (&fontmap->library);
84 if (error != FT_Err_Ok)
85 g_critical ("pango_opengl_font_map_new: Could not initialize freetype");
86
87 return (PangoFontMap *)fontmap;
88 }
89
90 void
91 pango_opengl_font_map_set_default_substitute (PangoOpenGLFontMap *fontmap,
92 PangoOpenGLSubstituteFunc func,
93 gpointer data,
94 GDestroyNotify notify)
95 {
96 if (fontmap->substitute_destroy)
97 fontmap->substitute_destroy (fontmap->substitute_data);
98
99 fontmap->substitute_func = func;
100 fontmap->substitute_data = data;
101 fontmap->substitute_destroy = notify;
102
103 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
104 }
105
106 /**
107 * pango_opengl_font_map_substitute_changed:
108 * @fontmap: a #PangoOpenGLFontmap
109 *
110 * Call this function any time the results of the
111 * default substitution function set with
112 * pango_opengl_font_map_set_default_substitute() change.
113 * That is, if your subsitution function will return different
114 * results for the same input pattern, you must call this function.
115 *
116 * Since: 1.2
117 **/
118 void
119 pango_opengl_font_map_substitute_changed (PangoOpenGLFontMap *fontmap)
120 {
121 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
122 }
123
124 /**
125 * pango_opengl_font_map_create_context:
126 * @fontmap: a #PangoOpenGLFontmap
127 *
128 * Create a #PangoContext for the given fontmap.
129 *
130 * Return value: the newly created context; free with g_object_unref().
131 *
132 * Since: 1.2
133 **/
134 PangoContext *
135 pango_opengl_font_map_create_context (PangoOpenGLFontMap *fontmap)
136 {
137 g_return_val_if_fail (PANGO_OPENGL_IS_FONT_MAP (fontmap), NULL);
138
139 return pango_font_map_create_context (PANGO_FONT_MAP (fontmap));
140 }
141
142 FT_Library
143 _pango_opengl_font_map_get_library (PangoFontMap *fontmap_)
144 {
145 PangoOpenGLFontMap *fontmap = (PangoOpenGLFontMap *)fontmap_;
146
147 return fontmap->library;
148 }
149
150 /**
151 * _pango_opengl_font_map_get_renderer:
152 * @fontmap: a #PangoOpenGLFontmap
153 *
154 * Gets the singleton PangoOpenGLRenderer for this fontmap.
155 *
156 * Return value:
157 **/
158 PangoRenderer *
159 _pango_opengl_font_map_get_renderer (PangoOpenGLFontMap *fontmap)
160 {
161 if (!fontmap->renderer)
162 fontmap->renderer = g_object_new (PANGO_TYPE_OPENGL_RENDERER, NULL);
163
164 return fontmap->renderer;
165 }
166
167 static void
168 pango_opengl_font_map_default_substitute (PangoFcFontMap *fcfontmap,
169 FcPattern *pattern)
170 {
171 PangoOpenGLFontMap *fontmap = PANGO_OPENGL_FONT_MAP (fcfontmap);
172
173 FcConfigSubstitute (NULL, pattern, FcMatchPattern);
174
175 if (fontmap->substitute_func)
176 fontmap->substitute_func (pattern, fontmap->substitute_data);
177
178 FcDefaultSubstitute (pattern);
179 }
180
181 static PangoFcFont *
182 pango_opengl_font_map_new_font (PangoFcFontMap *fcfontmap,
183 FcPattern *pattern)
184 {
185 return (PangoFcFont *)_pango_opengl_font_new (PANGO_OPENGL_FONT_MAP (fcfontmap), pattern);
186 }
187
188 static void
189 pango_opengl_font_map_class_init (PangoOpenGLFontMapClass *class)
190 {
191 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
192 PangoFcFontMapClass *fcfontmap_class = PANGO_FC_FONT_MAP_CLASS (class);
193
194 gobject_class->finalize = pango_opengl_font_map_finalize;
195 fcfontmap_class->default_substitute = pango_opengl_font_map_default_substitute;
196 fcfontmap_class->new_font = pango_opengl_font_map_new_font;
197 }
198
199 static void
200 pango_opengl_font_map_init (PangoOpenGLFontMap *fontmap)
201 {
202 fontmap->library = NULL;
203 }
204