2 * pangocairo-fontmap.c: Cairo font handling
4 * Copyright (C) 2000-2005 Red Hat Software
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 #include "pangocairo.h"
25 #include "pangocairo-private.h"
26 #include "pango-impl-utils.h"
28 #if defined (HAVE_CAIRO_ATSUI)
29 # include "pangocairo-atsui.h"
31 #if defined (HAVE_CAIRO_WIN32)
32 # include "pangocairo-win32.h"
34 #if defined (HAVE_CAIRO_FREETYPE)
35 # include "pangocairo-fc.h"
39 pango_cairo_font_map_get_type (void)
41 static GType cairo_font_map_type = 0;
43 if (! cairo_font_map_type)
45 const GTypeInfo cairo_font_map_info =
47 sizeof (PangoCairoFontMapIface), /* class_size */
49 NULL, /* base_finalize */
51 NULL, /* class_finalize */
52 NULL, /* class_data */
60 g_type_register_static (G_TYPE_INTERFACE, I_("PangoCairoFontMap"),
61 &cairo_font_map_info, 0);
63 g_type_interface_add_prerequisite (cairo_font_map_type, PANGO_TYPE_FONT_MAP);
66 return cairo_font_map_type;
70 * pango_cairo_font_map_new:
72 * Creates a new #PangoCairoFontMap object; a fontmap is used
73 * to cache information about available fonts, and holds
74 * certain global parameters such as the resolution.
75 * In most cases, you can use pango_cairo_font_map_get_default()
78 * Note that the type of the returned object will depend
79 * on the particular font backend Cairo was compiled to use;
80 * You generally should only use the #PangoFontMap and
81 * #PangoCairoFontMap interfaces on the returned object.
83 * Return value: the newly allocated #PangoFontMap, which should
84 * be freed with g_object_unref().
89 pango_cairo_font_map_new (void)
91 /* Make sure that the type system is initialized */
94 #if defined(HAVE_CAIRO_ATSUI)
95 return g_object_new (PANGO_TYPE_CAIRO_ATSUI_FONT_MAP, NULL);
96 #elif defined(HAVE_CAIRO_WIN32)
97 return g_object_new (PANGO_TYPE_CAIRO_WIN32_FONT_MAP, NULL);
98 #elif defined(HAVE_CAIRO_FREETYPE)
99 return g_object_new (PANGO_TYPE_CAIRO_FC_FONT_MAP, NULL);
101 g_assert_not_reached ();
107 * pango_cairo_font_map_new_for_font_type:
108 * @fonttype: desired #cairo_font_type_t
110 * Creates a new #PangoCairoFontMap object of the type suitable
111 * to be used with cairo font backend of type @fonttype.
113 * In most cases one should simply use @pango_cairo_font_map_new(),
114 * or in fact in most of those cases, just use
115 * @pango_cairo_font_map_get_default().
117 * Return value: the newly allocated #PangoFontMap of suitable type
118 * which should be freed with g_object_unref(),
119 * or %NULL if the requested cairo font backend is
120 * not supported / compiled in.
125 pango_cairo_font_map_new_for_font_type (cairo_font_type_t fonttype)
127 /* Make sure that the type system is initialized */
130 switch ((int) fonttype)
132 #if defined(HAVE_CAIRO_ATSUI)
133 case CAIRO_FONT_TYPE_QUARTZ:
134 return g_object_new (PANGO_TYPE_CAIRO_ATSUI_FONT_MAP, NULL);
136 #if defined(HAVE_CAIRO_WIN32)
137 case CAIRO_FONT_TYPE_WIN32:
138 return g_object_new (PANGO_TYPE_CAIRO_WIN32_FONT_MAP, NULL);
140 #if defined(HAVE_CAIRO_FREETYPE)
141 case CAIRO_FONT_TYPE_FT:
142 return g_object_new (PANGO_TYPE_CAIRO_FC_FONT_MAP, NULL);
149 static PangoFontMap *default_font_map = NULL;
152 * pango_cairo_font_map_get_default:
154 * Gets a default #PangoCairoFontMap to use with Cairo.
156 * Note that the type of the returned object will depend
157 * on the particular font backend Cairo was compiled to use;
158 * You generally should only use the #PangoFontMap and
159 * #PangoCairoFontMap interfaces on the returned object.
161 * The default Cairo fontmap can be changed by using
162 * pango_cairo_font_map_set_default(). This can be used to
163 * change the Cairo font backend that the default fontmap
166 * Return value: the default Cairo fontmap for Pango. This
167 * object is owned by Pango and must not be freed.
172 pango_cairo_font_map_get_default (void)
174 if (G_UNLIKELY (!default_font_map))
175 default_font_map = pango_cairo_font_map_new ();
177 return default_font_map;
181 * pango_cairo_font_map_set_default:
182 * @fontmap: The new default font map, or %NULL
184 * Sets a default #PangoCairoFontMap to use with Cairo.
186 * This can be used to change the Cairo font backend that the
187 * default fontmap uses for example. The old default font map
188 * is unreffed and the new font map referenced.
190 * A value of %NULL for @fontmap will cause the current default
191 * font map to be released and a new default font
192 * map to be created on demand, using pango_cairo_font_map_new().
197 pango_cairo_font_map_set_default (PangoCairoFontMap *fontmap)
199 g_return_if_fail (fontmap == NULL || PANGO_IS_CAIRO_FONT_MAP (fontmap));
201 if ((PangoFontMap *) fontmap == default_font_map)
204 if (default_font_map)
205 g_object_unref (default_font_map);
208 g_object_ref (fontmap);
209 default_font_map = (PangoFontMap *) fontmap;
213 * pango_cairo_font_map_set_resolution:
214 * @fontmap: a #PangoCairoFontMap
215 * @dpi: the resolution in "dots per inch". (Physical inches aren't actually
216 * involved; the terminology is conventional.)
218 * Sets the resolution for the fontmap. This is a scale factor between
219 * points specified in a #PangoFontDescription and Cairo units. The
220 * default value is 96, meaning that a 10 point font will be 13
221 * units high. (10 * 96. / 72. = 13.3).
226 pango_cairo_font_map_set_resolution (PangoCairoFontMap *fontmap,
229 g_return_if_fail (PANGO_IS_CAIRO_FONT_MAP (fontmap));
231 (* PANGO_CAIRO_FONT_MAP_GET_IFACE (fontmap)->set_resolution) (fontmap, dpi);
235 * pango_cairo_font_map_get_resolution:
236 * @fontmap: a #PangoCairoFontMap
238 * Gets the resolution for the fontmap. See pango_cairo_font_map_set_resolution()
240 * Return value: the resolution in "dots per inch"
245 pango_cairo_font_map_get_resolution (PangoCairoFontMap *fontmap)
247 g_return_val_if_fail (PANGO_IS_CAIRO_FONT_MAP (fontmap), 96.);
249 return (* PANGO_CAIRO_FONT_MAP_GET_IFACE (fontmap)->get_resolution) (fontmap);
253 * pango_cairo_font_map_create_context:
254 * @fontmap: a #PangoCairoFontMap
256 * Create a #PangoContext for the given fontmap.
258 * Return value: the newly created context; free with g_object_unref().
262 * Deprecated: 1.22: Use pango_font_map_create_context() instead.
265 pango_cairo_font_map_create_context (PangoCairoFontMap *fontmap)
267 g_return_val_if_fail (PANGO_IS_CAIRO_FONT_MAP (fontmap), NULL);
269 return pango_font_map_create_context (PANGO_FONT_MAP (fontmap));
273 * pango_cairo_font_map_get_font_type:
274 * @fontmap: a #PangoCairoFontMap
276 * Gets the type of Cairo font backend that @fontmap uses.
278 * Return value: the #cairo_font_type_t cairo font backend type
283 pango_cairo_font_map_get_font_type (PangoCairoFontMap *fontmap)
285 g_return_val_if_fail (PANGO_IS_CAIRO_FONT_MAP (fontmap), CAIRO_FONT_TYPE_TOY);
287 return (* PANGO_CAIRO_FONT_MAP_GET_IFACE (fontmap)->get_font_type) (fontmap);