ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/pango-fontmap.c
Revision: 1.1
Committed: Tue Jul 4 23:23:32 2006 UTC (17 years, 10 months ago) by root
Content type: text/plain
Branch: MAIN
Log Message:
Get rid of cairo completely (yay!) and of ft2 factually (still need the
library as it included pangofc), by introducing a custom pango opengl
renderer.

Text rendering now no longer requires the distinction between rgba and
grayscale modes, requires much less texture space and memory, and is
faster on accelerated hardware (and possibly with software rendering, too).

All at the cost of only 1200 lines or so.

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_fc_font_map_create_context (PANGO_FC_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 /**
152 * _pango_opengl_font_map_get_renderer:
153 * @fontmap: a #PangoOpenGLFontmap
154 *
155 * Gets the singleton PangoOpenGLRenderer for this fontmap.
156 *
157 * Return value:
158 **/
159 PangoRenderer *
160 _pango_opengl_font_map_get_renderer (PangoOpenGLFontMap *fontmap)
161 {
162 if (!fontmap->renderer)
163 fontmap->renderer = g_object_new (PANGO_TYPE_OPENGL_RENDERER, NULL);
164
165 return fontmap->renderer;
166 }
167
168 static void
169 pango_opengl_font_map_default_substitute (PangoFcFontMap *fcfontmap,
170 FcPattern *pattern)
171 {
172 PangoOpenGLFontMap *fontmap = PANGO_OPENGL_FONT_MAP (fcfontmap);
173 FcValue v;
174
175 FcConfigSubstitute (NULL, pattern, FcMatchPattern);
176
177 if (fontmap->substitute_func)
178 fontmap->substitute_func (pattern, fontmap->substitute_data);
179
180 #if 0
181 if (FcPatternGet (pattern, FC_DPI, 0, &v) == FcResultNoMatch)
182 FcPatternAddDouble (pattern, FC_DPI, fontmap->dpi_y);
183 #endif
184 FcDefaultSubstitute (pattern);
185 }
186
187 static PangoFcFont *
188 pango_opengl_font_map_new_font (PangoFcFontMap *fcfontmap,
189 FcPattern *pattern)
190 {
191 return (PangoFcFont *)_pango_opengl_font_new (PANGO_OPENGL_FONT_MAP (fcfontmap), pattern);
192 }
193
194 static void
195 pango_opengl_font_map_class_init (PangoOpenGLFontMapClass *class)
196 {
197 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
198 PangoFcFontMapClass *fcfontmap_class = PANGO_FC_FONT_MAP_CLASS (class);
199
200 gobject_class->finalize = pango_opengl_font_map_finalize;
201 fcfontmap_class->default_substitute = pango_opengl_font_map_default_substitute;
202 fcfontmap_class->new_font = pango_opengl_font_map_new_font;
203 }
204
205 static void
206 pango_opengl_font_map_init (PangoOpenGLFontMap *fontmap)
207 {
208 fontmap->library = NULL;
209 }
210