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.
118 gdk_char_width (GdkFont *font,
121 g_return_val_if_fail (font != NULL, -1);
123 return gdk_text_width (font, &character, 1);
129 * @character: the character to measure.
131 * Determines the width of a given wide character. (Encoded
132 * in the wide-character encoding of the current locale).
134 * Return value: the width of the character in pixels.
137 gdk_char_width_wc (GdkFont *font,
140 g_return_val_if_fail (font != NULL, -1);
142 return gdk_text_width_wc (font, &character, 1);
146 * gdk_string_measure:
148 * @string: the nul-terminated string to measure.
150 * Determines the distance from the origin to the rightmost
151 * portion of a nul-terminated string when drawn. This is not the
152 * correct value for determining the origin of the next
153 * portion when drawing text in multiple pieces.
154 * See gdk_string_width().
156 * Return value: the right bearing of the string in pixels.
159 gdk_string_measure (GdkFont *font,
162 g_return_val_if_fail (font != NULL, -1);
163 g_return_val_if_fail (string != NULL, -1);
165 return gdk_text_measure (font, string, _gdk_font_strlen (font, string));
169 * gdk_string_extents:
171 * @string: the nul-terminated string to measure.
172 * @lbearing: the left bearing of the string.
173 * @rbearing: the right bearing of the string.
174 * @width: the width of the string.
175 * @ascent: the ascent of the string.
176 * @descent: the descent of the string.
178 * Gets the metrics of a nul-terminated string.
181 gdk_string_extents (GdkFont *font,
189 g_return_if_fail (font != NULL);
190 g_return_if_fail (string != NULL);
192 gdk_text_extents (font, string, _gdk_font_strlen (font, string),
193 lbearing, rbearing, width, ascent, descent);
200 * @text: the text to measure.
201 * @text_length: the length of the text in bytes.
203 * Determines the distance from the origin to the rightmost
204 * portion of a string when drawn. This is not the
205 * correct value for determining the origin of the next
206 * portion when drawing text in multiple pieces.
207 * See gdk_text_width().
209 * Return value: the right bearing of the string in pixels.
212 gdk_text_measure (GdkFont *font,
218 g_return_val_if_fail (font != NULL, -1);
219 g_return_val_if_fail (text != NULL, -1);
221 gdk_text_extents (font, text, text_length, NULL, &rbearing, NULL, NULL, NULL);
228 * @character: the character to measure.
230 * Determines the distance from the origin to the rightmost
231 * portion of a character when drawn. This is not the
232 * correct value for determining the origin of the next
233 * portion when drawing text in multiple pieces.
235 * Return value: the right bearing of the character in pixels.
238 gdk_char_measure (GdkFont *font,
241 g_return_val_if_fail (font != NULL, -1);
243 return gdk_text_measure (font, &character, 1);
249 * @string: the nul-terminated string to measure.
251 * Determines the total height of a given nul-terminated
252 * string. This value is not generally useful, because you
253 * cannot determine how this total height will be drawn in
254 * relation to the baseline. See gdk_string_extents().
256 * Return value: the height of the string in pixels.
259 gdk_string_height (GdkFont *font,
262 g_return_val_if_fail (font != NULL, -1);
263 g_return_val_if_fail (string != NULL, -1);
265 return gdk_text_height (font, string, _gdk_font_strlen (font, string));
271 * @text: the text to measure.
272 * @text_length: the length of the text in bytes.
274 * Determines the total height of a given string.
275 * This value is not generally useful, because you cannot
276 * determine how this total height will be drawn in
277 * relation to the baseline. See gdk_text_extents().
279 * Return value: the height of the string in pixels.
282 gdk_text_height (GdkFont *font,
286 gint ascent, descent;
288 g_return_val_if_fail (font != NULL, -1);
289 g_return_val_if_fail (text != NULL, -1);
291 gdk_text_extents (font, text, text_length, NULL, NULL, NULL, &ascent, &descent);
292 return ascent + descent;
298 * @character: the character to measure.
300 * Determines the total height of a given character.
301 * This value is not generally useful, because you cannot
302 * determine how this total height will be drawn in
303 * relation to the baseline. See gdk_text_extents().
305 * Return value: the height of the character in pixels.
308 gdk_char_height (GdkFont *font,
311 g_return_val_if_fail (font != NULL, -1);
313 return gdk_text_height (font, &character, 1);
317 * gdk_font_from_description:
318 * @font_desc: a #PangoFontDescription.
320 * Load a #GdkFont based on a Pango font description. This font will
321 * only be an approximation of the Pango font, and
322 * internationalization will not be handled correctly. This function
323 * should only be used for legacy code that cannot be easily converted
324 * to use Pango. Using Pango directly will produce better results.
326 * Return value: the newly loaded font, or %NULL if the font
330 gdk_font_from_description (PangoFontDescription *font_desc)
332 return gdk_font_from_description_for_display (gdk_display_get_default (),font_desc);
337 * @font_name: a XLFD describing the font to load.
341 * The font may be newly loaded or looked up the font in a cache.
342 * You should make no assumptions about the initial reference count.
344 * Return value: a #GdkFont, or %NULL if the font could not be loaded.
347 gdk_font_load (const gchar *font_name)
349 return gdk_font_load_for_display (gdk_display_get_default(), font_name);