4 * An OpenGL based 'interactive canvas' library.
6 * Authored By Matthew Allum <mallum@openedhand.com>
8 * Copyright (C) 2008 OpenedHand
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
26 * @short_description: COGL-based text rendering using Pango
36 /* This is needed to get the Pango headers to export stuff needed to
38 #ifndef PANGO_ENABLE_BACKEND
39 #define PANGO_ENABLE_BACKEND 1
42 #include <pango/pango-fontmap.h>
43 #include <pango/pangocairo.h>
44 #include <pango/pango-renderer.h>
46 #include "cogl-pango.h"
47 #include "cogl-pango-private.h"
49 static GQuark cogl_pango_font_map_get_renderer_key (void) G_GNUC_CONST;
52 * cogl_pango_font_map_new:
54 * Creates a new font map.
56 * Return value: (transfer full): the newly created #PangoFontMap
61 cogl_pango_font_map_new (void)
63 return pango_cairo_font_map_new ();
67 * cogl_pango_font_map_create_context:
68 * @fm: a #CoglPangoFontMap
70 * Creates a new #PangoContext from the passed font map.
72 * Return value: (transfer full): the newly created #PangoContext
77 cogl_pango_font_map_create_context (CoglPangoFontMap *fm)
79 g_return_val_if_fail (COGL_PANGO_IS_FONT_MAP (fm), NULL);
81 /* We can just directly use the pango context from the Cairo font
83 return pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fm));
87 * cogl_pango_font_map_get_renderer:
88 * @fm: a #CoglPangoFontMap
90 * Retrieves the #CoglPangoRenderer for the passed font map.
92 * Return value: (transfer none): a #PangoRenderer
97 cogl_pango_font_map_get_renderer (CoglPangoFontMap *fm)
99 PangoRenderer *renderer;
101 g_return_val_if_fail (COGL_PANGO_IS_FONT_MAP (fm), NULL);
103 /* We want to keep a cached pointer to the renderer from the font
104 map instance but as we don't have a proper subclass we have to
105 store it in the object data instead */
107 renderer = g_object_get_qdata (G_OBJECT (fm),
108 cogl_pango_font_map_get_renderer_key ());
110 if (G_UNLIKELY (renderer == NULL))
112 renderer = g_object_new (COGL_PANGO_TYPE_RENDERER, NULL);
113 g_object_set_qdata_full (G_OBJECT (fm),
114 cogl_pango_font_map_get_renderer_key (),
123 * cogl_pango_font_map_set_resolution:
124 * @font_map: a #CoglPangoFontMap
127 * Sets the resolution to be used by @font_map at @dpi.
132 cogl_pango_font_map_set_resolution (CoglPangoFontMap *font_map,
135 g_return_if_fail (COGL_PANGO_IS_FONT_MAP (font_map));
137 pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (font_map), dpi);
141 * cogl_pango_font_map_clear_glyph_cache:
142 * @fm: a #CoglPangoFontMap
144 * Clears the glyph cache for @fm.
149 cogl_pango_font_map_clear_glyph_cache (CoglPangoFontMap *fm)
151 PangoRenderer *renderer;
153 renderer = cogl_pango_font_map_get_renderer (fm);
155 _cogl_pango_renderer_clear_glyph_cache (COGL_PANGO_RENDERER (renderer));
159 * cogl_pango_font_map_set_use_mipmapping:
160 * @fm: a #CoglPangoFontMap
161 * @value: %TRUE to enable the use of mipmapping
163 * Sets whether the renderer for the passed font map should use
164 * mipmapping when rendering a #PangoLayout.
169 cogl_pango_font_map_set_use_mipmapping (CoglPangoFontMap *fm,
172 CoglPangoRenderer *renderer;
174 renderer = COGL_PANGO_RENDERER (cogl_pango_font_map_get_renderer (fm));
176 _cogl_pango_renderer_set_use_mipmapping (renderer, value);
180 * cogl_pango_font_map_get_use_mipmapping:
181 * @fm: a #CoglPangoFontMap
183 * Retrieves whether the #CoglPangoRenderer used by @fm will
184 * use mipmapping when rendering the glyphs.
186 * Return value: %TRUE if mipmapping is used, %FALSE otherwise.
191 cogl_pango_font_map_get_use_mipmapping (CoglPangoFontMap *fm)
193 CoglPangoRenderer *renderer;
195 renderer = COGL_PANGO_RENDERER (cogl_pango_font_map_get_renderer (fm));
197 return _cogl_pango_renderer_get_use_mipmapping (renderer);
201 cogl_pango_font_map_get_renderer_key (void)
203 static GQuark renderer_key = 0;
205 if (G_UNLIKELY (renderer_key == 0))
206 renderer_key = g_quark_from_static_string ("CoglPangoFontMap");