46
46
#include "cogl-pango.h"
47
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
48
#include "cogl-util.h"
49
#include "cogl/cogl-context-private.h"
51
static GQuark cogl_pango_font_map_get_priv_key (void) G_GNUC_CONST;
53
typedef struct _CoglPangoFontMapPriv
56
PangoRenderer *renderer;
57
} CoglPangoFontMapPriv;
60
free_priv (gpointer data)
62
CoglPangoFontMapPriv *priv = data;
64
cogl_object_unref (priv->ctx);
65
cogl_object_unref (priv->renderer);
61
71
cogl_pango_font_map_new (void)
63
return pango_cairo_font_map_new ();
73
PangoFontMap *fm = pango_cairo_font_map_new ();
74
CoglPangoFontMapPriv *priv = g_new0 (CoglPangoFontMapPriv, 1);
76
_COGL_GET_CONTEXT (context, NULL);
78
priv->ctx = cogl_object_ref (context);
80
/* XXX: The public pango api doesn't let us sub-class
81
* PangoCairoFontMap so we attach our own private data using qdata
83
g_object_set_qdata_full (G_OBJECT (fm),
84
cogl_pango_font_map_get_priv_key (),
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
92
cogl_pango_font_map_create_context (CoglPangoFontMap *fm)
79
g_return_val_if_fail (COGL_PANGO_IS_FONT_MAP (fm), NULL);
94
_COGL_RETURN_VAL_IF_FAIL (COGL_PANGO_IS_FONT_MAP (fm), NULL);
81
96
/* We can just directly use the pango context from the Cairo font
83
98
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
101
static CoglPangoFontMapPriv *
102
_cogl_pango_font_map_get_priv (CoglPangoFontMap *fm)
104
return g_object_get_qdata (G_OBJECT (fm),
105
cogl_pango_font_map_get_priv_key ());
109
_cogl_pango_font_map_get_renderer (CoglPangoFontMap *fm)
111
CoglPangoFontMapPriv *priv = _cogl_pango_font_map_get_priv (fm);
112
if (G_UNLIKELY (!priv->renderer))
113
priv->renderer = _cogl_pango_renderer_new (priv->ctx);
114
return priv->renderer;
97
118
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.
120
return _cogl_pango_font_map_get_renderer (fm);
124
_cogl_pango_font_map_get_cogl_context (CoglPangoFontMap *fm)
126
CoglPangoFontMapPriv *priv = _cogl_pango_font_map_get_priv (fm);
132
131
cogl_pango_font_map_set_resolution (CoglPangoFontMap *font_map,
135
g_return_if_fail (COGL_PANGO_IS_FONT_MAP (font_map));
134
_COGL_RETURN_IF_FAIL (COGL_PANGO_IS_FONT_MAP (font_map));
137
136
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
140
cogl_pango_font_map_clear_glyph_cache (CoglPangoFontMap *fm)
151
PangoRenderer *renderer;
153
renderer = cogl_pango_font_map_get_renderer (fm);
142
PangoRenderer *renderer = _cogl_pango_font_map_get_renderer (fm);
155
144
_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
148
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);
151
PangoRenderer *renderer = _cogl_pango_font_map_get_renderer (fm);
153
_cogl_pango_renderer_set_use_mipmapping (COGL_PANGO_RENDERER (renderer),
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
158
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);
160
PangoRenderer *renderer = _cogl_pango_font_map_get_renderer (fm);
163
_cogl_pango_renderer_get_use_mipmapping (COGL_PANGO_RENDERER (renderer));
201
cogl_pango_font_map_get_renderer_key (void)
167
cogl_pango_font_map_get_priv_key (void)
203
static GQuark renderer_key = 0;
205
if (G_UNLIKELY (renderer_key == 0))
206
renderer_key = g_quark_from_static_string ("CoglPangoFontMap");
169
static GQuark priv_key = 0;
171
if (G_UNLIKELY (priv_key == 0))
172
priv_key = g_quark_from_static_string ("CoglPangoFontMap");