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
30 #include "gdkdisplay.h"
32 #include "gdkinternals.h"
36 gdk_font_get_type (void)
38 static GType our_type = 0;
41 our_type = g_boxed_type_register_static (g_intern_static_string ("GdkFont"),
42 (GBoxedCopyFunc)gdk_font_ref,
43 (GBoxedFreeFunc)gdk_font_unref);
51 * Increases the reference count of a font by one.
56 gdk_font_ref (GdkFont *font)
58 GdkFontPrivate *private;
60 g_return_val_if_fail (font != NULL, NULL);
62 private = (GdkFontPrivate*) font;
63 private->ref_count += 1;
71 * Decreases the reference count of a font by one.
72 * If the result is zero, destroys the font.
75 gdk_font_unref (GdkFont *font)
77 GdkFontPrivate *private;
78 private = (GdkFontPrivate*) font;
80 g_return_if_fail (font != NULL);
81 g_return_if_fail (private->ref_count > 0);
83 private->ref_count -= 1;
84 if (private->ref_count == 0)
85 _gdk_font_destroy (font);
91 * @string: the nul-terminated string to measure
93 * Determines the width of a nul-terminated string.
94 * (The distance from the origin of the string to the
95 * point where the next string in a sequence of strings
98 * Return value: the width of the string in pixels.
101 gdk_string_width (GdkFont *font,
104 g_return_val_if_fail (font != NULL, -1);
105 g_return_val_if_fail (string != NULL, -1);
107 return gdk_text_width (font, string, _gdk_font_strlen (font, string));
113 * @character: the character to measure.
115 * Determines the width of a given character.
117 * Return value: the width of the character in pixels.
119 * Deprecated: Use gdk_text_extents() instead.
122 gdk_char_width (GdkFont *font,
125 g_return_val_if_fail (font != NULL, -1);
127 return gdk_text_width (font, &character, 1);
133 * @character: the character to measure.
135 * Determines the width of a given wide character. (Encoded
136 * in the wide-character encoding of the current locale).
138 * Return value: the width of the character in pixels.
141 gdk_char_width_wc (GdkFont *font,
144 g_return_val_if_fail (font != NULL, -1);
146 return gdk_text_width_wc (font, &character, 1);
150 * gdk_string_measure:
152 * @string: the nul-terminated string to measure.
154 * Determines the distance from the origin to the rightmost
155 * portion of a nul-terminated string when drawn. This is not the
156 * correct value for determining the origin of the next
157 * portion when drawing text in multiple pieces.
158 * See gdk_string_width().
160 * Return value: the right bearing of the string in pixels.
163 gdk_string_measure (GdkFont *font,
166 g_return_val_if_fail (font != NULL, -1);
167 g_return_val_if_fail (string != NULL, -1);
169 return gdk_text_measure (font, string, _gdk_font_strlen (font, string));
173 * gdk_string_extents:
175 * @string: the nul-terminated string to measure.
176 * @lbearing: the left bearing of the string.
177 * @rbearing: the right bearing of the string.
178 * @width: the width of the string.
179 * @ascent: the ascent of the string.
180 * @descent: the descent of the string.
182 * Gets the metrics of a nul-terminated string.
185 gdk_string_extents (GdkFont *font,
193 g_return_if_fail (font != NULL);
194 g_return_if_fail (string != NULL);
196 gdk_text_extents (font, string, _gdk_font_strlen (font, string),
197 lbearing, rbearing, width, ascent, descent);
204 * @text: the text to measure.
205 * @text_length: the length of the text in bytes.
207 * Determines the distance from the origin to the rightmost
208 * portion of a string when drawn. This is not the
209 * correct value for determining the origin of the next
210 * portion when drawing text in multiple pieces.
211 * See gdk_text_width().
213 * Return value: the right bearing of the string in pixels.
216 gdk_text_measure (GdkFont *font,
222 g_return_val_if_fail (font != NULL, -1);
223 g_return_val_if_fail (text != NULL, -1);
225 gdk_text_extents (font, text, text_length, NULL, &rbearing, NULL, NULL, NULL);
232 * @character: the character to measure.
234 * Determines the distance from the origin to the rightmost
235 * portion of a character when drawn. This is not the
236 * correct value for determining the origin of the next
237 * portion when drawing text in multiple pieces.
239 * Return value: the right bearing of the character in pixels.
242 gdk_char_measure (GdkFont *font,
245 g_return_val_if_fail (font != NULL, -1);
247 return gdk_text_measure (font, &character, 1);
253 * @string: the nul-terminated string to measure.
255 * Determines the total height of a given nul-terminated
256 * string. This value is not generally useful, because you
257 * cannot determine how this total height will be drawn in
258 * relation to the baseline. See gdk_string_extents().
260 * Return value: the height of the string in pixels.
263 gdk_string_height (GdkFont *font,
266 g_return_val_if_fail (font != NULL, -1);
267 g_return_val_if_fail (string != NULL, -1);
269 return gdk_text_height (font, string, _gdk_font_strlen (font, string));
275 * @text: the text to measure.
276 * @text_length: the length of the text in bytes.
278 * Determines the total height of a given string.
279 * This value is not generally useful, because you cannot
280 * determine how this total height will be drawn in
281 * relation to the baseline. See gdk_text_extents().
283 * Return value: the height of the string in pixels.
286 gdk_text_height (GdkFont *font,
290 gint ascent, descent;
292 g_return_val_if_fail (font != NULL, -1);
293 g_return_val_if_fail (text != NULL, -1);
295 gdk_text_extents (font, text, text_length, NULL, NULL, NULL, &ascent, &descent);
296 return ascent + descent;
302 * @character: the character to measure.
304 * Determines the total height of a given character.
305 * This value is not generally useful, because you cannot
306 * determine how this total height will be drawn in
307 * relation to the baseline. See gdk_text_extents().
309 * Return value: the height of the character in pixels.
311 * Deprecated: Use gdk_text_extents() instead.
314 gdk_char_height (GdkFont *font,
317 g_return_val_if_fail (font != NULL, -1);
319 return gdk_text_height (font, &character, 1);
323 * gdk_font_from_description:
324 * @font_desc: a #PangoFontDescription.
326 * Load a #GdkFont based on a Pango font description. This font will
327 * only be an approximation of the Pango font, and
328 * internationalization will not be handled correctly. This function
329 * should only be used for legacy code that cannot be easily converted
330 * to use Pango. Using Pango directly will produce better results.
332 * Return value: the newly loaded font, or %NULL if the font
336 gdk_font_from_description (PangoFontDescription *font_desc)
338 return gdk_font_from_description_for_display (gdk_display_get_default (),font_desc);
343 * @font_name: a XLFD describing the font to load.
347 * The font may be newly loaded or looked up the font in a cache.
348 * You should make no assumptions about the initial reference count.
350 * Return value: a #GdkFont, or %NULL if the font could not be loaded.
353 gdk_font_load (const gchar *font_name)
355 return gdk_font_load_for_display (gdk_display_get_default(), font_name);
358 #define __GDK_FONT_C__
359 #include "gdkaliasdef.c"