1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #undef GDK_DISABLE_DEPRECATED
29 #include "gdkdisplay.h"
31 #include "gdkinternals.h"
34 gdk_font_get_type (void)
36 static GType our_type = 0;
39 our_type = g_boxed_type_register_static ("GdkFont",
40 (GBoxedCopyFunc)gdk_font_ref,
41 (GBoxedFreeFunc)gdk_font_unref);
49 * Increases the reference count of a font by one.
54 gdk_font_ref (GdkFont *font)
56 GdkFontPrivate *private;
58 g_return_val_if_fail (font != NULL, NULL);
60 private = (GdkFontPrivate*) font;
61 private->ref_count += 1;
69 * Decreases the reference count of a font by one.
70 * If the result is zero, destroys the font.
73 gdk_font_unref (GdkFont *font)
75 GdkFontPrivate *private;
76 private = (GdkFontPrivate*) font;
78 g_return_if_fail (font != NULL);
79 g_return_if_fail (private->ref_count > 0);
81 private->ref_count -= 1;
82 if (private->ref_count == 0)
83 _gdk_font_destroy (font);
89 * @string: the nul-terminated string to measure
91 * Determines the width of a nul-terminated string.
92 * (The distance from the origin of the string to the
93 * point where the next string in a sequence of strings
96 * Return value: the width of the string in pixels.
99 gdk_string_width (GdkFont *font,
102 g_return_val_if_fail (font != NULL, -1);
103 g_return_val_if_fail (string != NULL, -1);
105 return gdk_text_width (font, string, _gdk_font_strlen (font, string));
111 * @character: the character to measure.
113 * Determines the width of a given character.
115 * Return value: the width of the character in pixels.
117 * Deprecated: Use gdk_text_extents() instead.
120 gdk_char_width (GdkFont *font,
123 g_return_val_if_fail (font != NULL, -1);
125 return gdk_text_width (font, &character, 1);
131 * @character: the character to measure.
133 * Determines the width of a given wide character. (Encoded
134 * in the wide-character encoding of the current locale).
136 * Return value: the width of the character in pixels.
139 gdk_char_width_wc (GdkFont *font,
142 g_return_val_if_fail (font != NULL, -1);
144 return gdk_text_width_wc (font, &character, 1);
148 * gdk_string_measure:
150 * @string: the nul-terminated string to measure.
152 * Determines the distance from the origin to the rightmost
153 * portion of a nul-terminated string when drawn. This is not the
154 * correct value for determining the origin of the next
155 * portion when drawing text in multiple pieces.
156 * See gdk_string_width().
158 * Return value: the right bearing of the string in pixels.
161 gdk_string_measure (GdkFont *font,
164 g_return_val_if_fail (font != NULL, -1);
165 g_return_val_if_fail (string != NULL, -1);
167 return gdk_text_measure (font, string, _gdk_font_strlen (font, string));
171 * gdk_string_extents:
173 * @string: the nul-terminated string to measure.
174 * @lbearing: the left bearing of the string.
175 * @rbearing: the right bearing of the string.
176 * @width: the width of the string.
177 * @ascent: the ascent of the string.
178 * @descent: the descent of the string.
180 * Gets the metrics of a nul-terminated string.
183 gdk_string_extents (GdkFont *font,
191 g_return_if_fail (font != NULL);
192 g_return_if_fail (string != NULL);
194 gdk_text_extents (font, string, _gdk_font_strlen (font, string),
195 lbearing, rbearing, width, ascent, descent);
202 * @text: the text to measure.
203 * @text_length: the length of the text in bytes.
205 * Determines the distance from the origin to the rightmost
206 * portion of a string when drawn. This is not the
207 * correct value for determining the origin of the next
208 * portion when drawing text in multiple pieces.
209 * See gdk_text_width().
211 * Return value: the right bearing of the string in pixels.
214 gdk_text_measure (GdkFont *font,
220 g_return_val_if_fail (font != NULL, -1);
221 g_return_val_if_fail (text != NULL, -1);
223 gdk_text_extents (font, text, text_length, NULL, &rbearing, NULL, NULL, NULL);
230 * @character: the character to measure.
232 * Determines the distance from the origin to the rightmost
233 * portion of a character when drawn. This is not the
234 * correct value for determining the origin of the next
235 * portion when drawing text in multiple pieces.
237 * Return value: the right bearing of the character in pixels.
240 gdk_char_measure (GdkFont *font,
243 g_return_val_if_fail (font != NULL, -1);
245 return gdk_text_measure (font, &character, 1);
251 * @string: the nul-terminated string to measure.
253 * Determines the total height of a given nul-terminated
254 * string. This value is not generally useful, because you
255 * cannot determine how this total height will be drawn in
256 * relation to the baseline. See gdk_string_extents().
258 * Return value: the height of the string in pixels.
261 gdk_string_height (GdkFont *font,
264 g_return_val_if_fail (font != NULL, -1);
265 g_return_val_if_fail (string != NULL, -1);
267 return gdk_text_height (font, string, _gdk_font_strlen (font, string));
273 * @text: the text to measure.
274 * @text_length: the length of the text in bytes.
276 * Determines the total height of a given string.
277 * This value is not generally useful, because you cannot
278 * determine how this total height will be drawn in
279 * relation to the baseline. See gdk_text_extents().
281 * Return value: the height of the string in pixels.
284 gdk_text_height (GdkFont *font,
288 gint ascent, descent;
290 g_return_val_if_fail (font != NULL, -1);
291 g_return_val_if_fail (text != NULL, -1);
293 gdk_text_extents (font, text, text_length, NULL, NULL, NULL, &ascent, &descent);
294 return ascent + descent;
300 * @character: the character to measure.
302 * Determines the total height of a given character.
303 * This value is not generally useful, because you cannot
304 * determine how this total height will be drawn in
305 * relation to the baseline. See gdk_text_extents().
307 * Return value: the height of the character in pixels.
309 * Deprecated: Use gdk_text_extents() instead.
312 gdk_char_height (GdkFont *font,
315 g_return_val_if_fail (font != NULL, -1);
317 return gdk_text_height (font, &character, 1);
321 * gdk_font_from_description:
322 * @font_desc: a #PangoFontDescription.
324 * Load a #GdkFont based on a Pango font description. This font will
325 * only be an approximation of the Pango font, and
326 * internationalization will not be handled correctly. This function
327 * should only be used for legacy code that cannot be easily converted
328 * to use Pango. Using Pango directly will produce better results.
330 * Return value: the newly loaded font, or %NULL if the font
334 gdk_font_from_description (PangoFontDescription *font_desc)
336 return gdk_font_from_description_for_display (gdk_display_get_default (),font_desc);
341 * @font_name: a XLFD describing the font to load.
345 * The font may be newly loaded or looked up the font in a cache.
346 * You should make no assumptions about the initial reference count.
348 * Return value: a #GdkFont, or %NULL if the font could not be loaded.
351 gdk_font_load (const gchar *font_name)
353 return gdk_font_load_for_display (gdk_display_get_default(), font_name);