~noskcaj/ubuntu/trusty/cogl/1.16.2

« back to all changes in this revision

Viewing changes to cogl-pango/cogl-pango-fontmap.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha, Jeremy Bicha, Rico Tzschichholz
  • Date: 2013-02-26 16:43:25 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20130226164325-t4z9rylpa20v0p6q
Tags: 1.13.4-0ubuntu1
[ Jeremy Bicha ]
* New upstream release
  - soname bump
* debian/control.in:
  - Bump minimum glib to 2.32
  - Drop obsolete breaks/replaces
  - Bump libclutter-1.0-dev breaks for soname transition
* debian/libcogl-dev.install:
  - Add some missing files

[ Rico Tzschichholz ]
* debian/control.in:
  - Build-depend on libxrandr-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
#include "cogl-pango.h"
47
47
#include "cogl-pango-private.h"
48
 
 
49
 
static GQuark cogl_pango_font_map_get_renderer_key (void) G_GNUC_CONST;
50
 
 
51
 
/**
52
 
 * cogl_pango_font_map_new:
53
 
 *
54
 
 * Creates a new font map.
55
 
 *
56
 
 * Return value: (transfer full): the newly created #PangoFontMap
57
 
 *
58
 
 * Since: 1.0
59
 
 */
 
48
#include "cogl-util.h"
 
49
#include "cogl/cogl-context-private.h"
 
50
 
 
51
static GQuark cogl_pango_font_map_get_priv_key (void) G_GNUC_CONST;
 
52
 
 
53
typedef struct _CoglPangoFontMapPriv
 
54
{
 
55
  CoglContext *ctx;
 
56
  PangoRenderer *renderer;
 
57
} CoglPangoFontMapPriv;
 
58
 
 
59
static void
 
60
free_priv (gpointer data)
 
61
{
 
62
  CoglPangoFontMapPriv *priv = data;
 
63
 
 
64
  cogl_object_unref (priv->ctx);
 
65
  cogl_object_unref (priv->renderer);
 
66
 
 
67
  g_free (priv);
 
68
}
 
69
 
60
70
PangoFontMap *
61
71
cogl_pango_font_map_new (void)
62
72
{
63
 
  return pango_cairo_font_map_new ();
 
73
  PangoFontMap *fm = pango_cairo_font_map_new ();
 
74
  CoglPangoFontMapPriv *priv = g_new0 (CoglPangoFontMapPriv, 1);
 
75
 
 
76
  _COGL_GET_CONTEXT (context, NULL);
 
77
 
 
78
  priv->ctx = cogl_object_ref (context);
 
79
 
 
80
  /* XXX: The public pango api doesn't let us sub-class
 
81
   * PangoCairoFontMap so we attach our own private data using qdata
 
82
   * for now. */
 
83
  g_object_set_qdata_full (G_OBJECT (fm),
 
84
                           cogl_pango_font_map_get_priv_key (),
 
85
                           priv,
 
86
                           free_priv);
 
87
 
 
88
  return fm;
64
89
}
65
90
 
66
 
/**
67
 
 * cogl_pango_font_map_create_context:
68
 
 * @fm: a #CoglPangoFontMap
69
 
 *
70
 
 * Creates a new #PangoContext from the passed font map.
71
 
 *
72
 
 * Return value: (transfer full): the newly created #PangoContext
73
 
 *
74
 
 * Since: 1.0
75
 
 */
76
91
PangoContext *
77
92
cogl_pango_font_map_create_context (CoglPangoFontMap *fm)
78
93
{
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);
80
95
 
81
96
  /* We can just directly use the pango context from the Cairo font
82
97
     map */
83
98
  return pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fm));
84
99
}
85
100
 
86
 
/**
87
 
 * cogl_pango_font_map_get_renderer:
88
 
 * @fm: a #CoglPangoFontMap
89
 
 *
90
 
 * Retrieves the #CoglPangoRenderer for the passed font map.
91
 
 *
92
 
 * Return value: (transfer none): a #PangoRenderer
93
 
 *
94
 
 * Since: 1.0
95
 
 */
 
101
static CoglPangoFontMapPriv *
 
102
_cogl_pango_font_map_get_priv (CoglPangoFontMap *fm)
 
103
{
 
104
  return g_object_get_qdata (G_OBJECT (fm),
 
105
                             cogl_pango_font_map_get_priv_key ());
 
106
}
 
107
 
 
108
PangoRenderer *
 
109
_cogl_pango_font_map_get_renderer (CoglPangoFontMap *fm)
 
110
{
 
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;
 
115
}
 
116
 
96
117
PangoRenderer *
97
118
cogl_pango_font_map_get_renderer (CoglPangoFontMap *fm)
98
119
{
99
 
  PangoRenderer *renderer;
100
 
 
101
 
  g_return_val_if_fail (COGL_PANGO_IS_FONT_MAP (fm), NULL);
102
 
 
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 */
106
 
 
107
 
  renderer = g_object_get_qdata (G_OBJECT (fm),
108
 
                                 cogl_pango_font_map_get_renderer_key ());
109
 
 
110
 
  if (G_UNLIKELY (renderer == NULL))
111
 
    {
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 (),
115
 
                               renderer,
116
 
                               g_object_unref);
117
 
    }
118
 
 
119
 
  return renderer;
120
 
}
121
 
 
122
 
/**
123
 
 * cogl_pango_font_map_set_resolution:
124
 
 * @font_map: a #CoglPangoFontMap
125
 
 * @dpi: DPI to set
126
 
 *
127
 
 * Sets the resolution to be used by @font_map at @dpi.
128
 
 *
129
 
 * Since: 1.0
130
 
 */
 
120
  return _cogl_pango_font_map_get_renderer (fm);
 
121
}
 
122
 
 
123
CoglContext *
 
124
_cogl_pango_font_map_get_cogl_context (CoglPangoFontMap *fm)
 
125
{
 
126
  CoglPangoFontMapPriv *priv = _cogl_pango_font_map_get_priv (fm);
 
127
  return priv->ctx;
 
128
}
 
129
 
131
130
void
132
131
cogl_pango_font_map_set_resolution (CoglPangoFontMap *font_map,
133
132
                                    double            dpi)
134
133
{
135
 
  g_return_if_fail (COGL_PANGO_IS_FONT_MAP (font_map));
 
134
  _COGL_RETURN_IF_FAIL (COGL_PANGO_IS_FONT_MAP (font_map));
136
135
 
137
136
  pango_cairo_font_map_set_resolution (PANGO_CAIRO_FONT_MAP (font_map), dpi);
138
137
}
139
138
 
140
 
/**
141
 
 * cogl_pango_font_map_clear_glyph_cache:
142
 
 * @fm: a #CoglPangoFontMap
143
 
 *
144
 
 * Clears the glyph cache for @fm.
145
 
 *
146
 
 * Since: 1.0
147
 
 */
148
139
void
149
140
cogl_pango_font_map_clear_glyph_cache (CoglPangoFontMap *fm)
150
141
{
151
 
  PangoRenderer *renderer;
152
 
 
153
 
  renderer = cogl_pango_font_map_get_renderer (fm);
 
142
  PangoRenderer *renderer = _cogl_pango_font_map_get_renderer (fm);
154
143
 
155
144
  _cogl_pango_renderer_clear_glyph_cache (COGL_PANGO_RENDERER (renderer));
156
145
}
157
146
 
158
 
/**
159
 
 * cogl_pango_font_map_set_use_mipmapping:
160
 
 * @fm: a #CoglPangoFontMap
161
 
 * @value: %TRUE to enable the use of mipmapping
162
 
 *
163
 
 * Sets whether the renderer for the passed font map should use
164
 
 * mipmapping when rendering a #PangoLayout.
165
 
 *
166
 
 * Since: 1.0
167
 
 */
168
147
void
169
148
cogl_pango_font_map_set_use_mipmapping (CoglPangoFontMap *fm,
170
149
                                        CoglBool          value)
171
150
{
172
 
  CoglPangoRenderer *renderer;
173
 
 
174
 
  renderer = COGL_PANGO_RENDERER (cogl_pango_font_map_get_renderer (fm));
175
 
 
176
 
  _cogl_pango_renderer_set_use_mipmapping (renderer, value);
 
151
  PangoRenderer *renderer = _cogl_pango_font_map_get_renderer (fm);
 
152
 
 
153
  _cogl_pango_renderer_set_use_mipmapping (COGL_PANGO_RENDERER (renderer),
 
154
                                           value);
177
155
}
178
156
 
179
 
/**
180
 
 * cogl_pango_font_map_get_use_mipmapping:
181
 
 * @fm: a #CoglPangoFontMap
182
 
 *
183
 
 * Retrieves whether the #CoglPangoRenderer used by @fm will
184
 
 * use mipmapping when rendering the glyphs.
185
 
 *
186
 
 * Return value: %TRUE if mipmapping is used, %FALSE otherwise.
187
 
 *
188
 
 * Since: 1.0
189
 
 */
190
157
CoglBool
191
158
cogl_pango_font_map_get_use_mipmapping (CoglPangoFontMap *fm)
192
159
{
193
 
  CoglPangoRenderer *renderer;
194
 
 
195
 
  renderer = COGL_PANGO_RENDERER (cogl_pango_font_map_get_renderer (fm));
196
 
 
197
 
  return _cogl_pango_renderer_get_use_mipmapping (renderer);
 
160
  PangoRenderer *renderer = _cogl_pango_font_map_get_renderer (fm);
 
161
 
 
162
  return
 
163
    _cogl_pango_renderer_get_use_mipmapping (COGL_PANGO_RENDERER (renderer));
198
164
}
199
165
 
200
166
static GQuark
201
 
cogl_pango_font_map_get_renderer_key (void)
 
167
cogl_pango_font_map_get_priv_key (void)
202
168
{
203
 
  static GQuark renderer_key = 0;
204
 
 
205
 
  if (G_UNLIKELY (renderer_key == 0))
206
 
      renderer_key = g_quark_from_static_string ("CoglPangoFontMap");
207
 
 
208
 
  return renderer_key;
 
169
  static GQuark priv_key = 0;
 
170
 
 
171
  if (G_UNLIKELY (priv_key == 0))
 
172
      priv_key = g_quark_from_static_string ("CoglPangoFontMap");
 
173
 
 
174
  return priv_key;
209
175
}