ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/Deliantra-Client/pango-fontmap.c
Revision: 1.6
Committed: Sun Nov 18 00:52:22 2018 UTC (5 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +5 -8 lines
Log Message:
port to c++

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 fontmap = (PangoOpenGLFontMap *)g_object_new (PANGO_TYPE_OPENGL_FONT_MAP, NULL);
79
80 error = FT_Init_FreeType (&fontmap->library);
81 if (error != FT_Err_Ok)
82 g_critical ("pango_opengl_font_map_new: Could not initialize freetype");
83
84 return (PangoFontMap *)fontmap;
85 }
86
87 void
88 pango_opengl_font_map_set_default_substitute (PangoOpenGLFontMap *fontmap,
89 PangoOpenGLSubstituteFunc func,
90 gpointer data,
91 GDestroyNotify notify)
92 {
93 if (fontmap->substitute_destroy)
94 fontmap->substitute_destroy (fontmap->substitute_data);
95
96 fontmap->substitute_func = func;
97 fontmap->substitute_data = data;
98 fontmap->substitute_destroy = notify;
99
100 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
101 }
102
103 /**
104 * pango_opengl_font_map_substitute_changed:
105 * @fontmap: a #PangoOpenGLFontmap
106 *
107 * Call this function any time the results of the
108 * default substitution function set with
109 * pango_opengl_font_map_set_default_substitute() change.
110 * That is, if your subsitution function will return different
111 * results for the same input pattern, you must call this function.
112 *
113 * Since: 1.2
114 **/
115 void
116 pango_opengl_font_map_substitute_changed (PangoOpenGLFontMap *fontmap)
117 {
118 pango_fc_font_map_cache_clear (PANGO_FC_FONT_MAP (fontmap));
119 }
120
121 /**
122 * pango_opengl_font_map_create_context:
123 * @fontmap: a #PangoOpenGLFontmap
124 *
125 * Create a #PangoContext for the given fontmap.
126 *
127 * Return value: the newly created context; free with g_object_unref().
128 *
129 * Since: 1.2
130 **/
131 PangoContext *
132 pango_opengl_font_map_create_context (PangoOpenGLFontMap *fontmap)
133 {
134 g_return_val_if_fail (PANGO_OPENGL_IS_FONT_MAP (fontmap), NULL);
135
136 return pango_font_map_create_context (PANGO_FONT_MAP (fontmap));
137 }
138
139 FT_Library
140 _pango_opengl_font_map_get_library (PangoFontMap *fontmap_)
141 {
142 PangoOpenGLFontMap *fontmap = (PangoOpenGLFontMap *)fontmap_;
143
144 return fontmap->library;
145 }
146
147 /**
148 * _pango_opengl_font_map_get_renderer:
149 * @fontmap: a #PangoOpenGLFontmap
150 *
151 * Gets the singleton PangoOpenGLRenderer for this fontmap.
152 *
153 * Return value:
154 **/
155 PangoRenderer *
156 _pango_opengl_font_map_get_renderer (PangoOpenGLFontMap *fontmap)
157 {
158 if (!fontmap->renderer)
159 fontmap->renderer = (PangoRenderer *)g_object_new (PANGO_TYPE_OPENGL_RENDERER, NULL);
160
161 return fontmap->renderer;
162 }
163
164 static void
165 pango_opengl_font_map_default_substitute (PangoFcFontMap *fcfontmap,
166 FcPattern *pattern)
167 {
168 PangoOpenGLFontMap *fontmap = PANGO_OPENGL_FONT_MAP (fcfontmap);
169
170 FcConfigSubstitute (NULL, pattern, FcMatchPattern);
171
172 if (fontmap->substitute_func)
173 fontmap->substitute_func (pattern, fontmap->substitute_data);
174
175 FcDefaultSubstitute (pattern);
176 }
177
178 static PangoFcFont *
179 pango_opengl_font_map_new_font (PangoFcFontMap *fcfontmap,
180 FcPattern *pattern)
181 {
182 return (PangoFcFont *)_pango_opengl_font_new (PANGO_OPENGL_FONT_MAP (fcfontmap), pattern);
183 }
184
185 static void
186 pango_opengl_font_map_class_init (PangoOpenGLFontMapClass *klass)
187 {
188 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
189 PangoFcFontMapClass *fcfontmap_class = PANGO_FC_FONT_MAP_CLASS (klass);
190
191 gobject_class->finalize = pango_opengl_font_map_finalize;
192 fcfontmap_class->default_substitute = pango_opengl_font_map_default_substitute;
193 fcfontmap_class->new_font = pango_opengl_font_map_new_font;
194 }
195
196 static void
197 pango_opengl_font_map_init (PangoOpenGLFontMap *fontmap)
198 {
199 fontmap->library = NULL;
200 }
201