]> Pileus Git - ~andy/gtk/blob - gdk/gdkfont.c
Revert name change
[~andy/gtk] / gdk / gdkfont.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #undef GDK_DISABLE_DEPRECATED
28
29 #include "config.h"
30 #include "gdkdisplay.h"
31 #include "gdkfont.h"
32 #include "gdkinternals.h"
33 #include "gdkalias.h"
34
35 GType
36 gdk_font_get_type (void)
37 {
38   static GType our_type = 0;
39   
40   if (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);
44   return our_type;
45 }
46
47 /**
48  * gdk_font_ref:
49  * @font: a #GdkFont
50  * 
51  * Increases the reference count of a font by one.
52  * 
53  * Return value: @font
54  **/
55 GdkFont*
56 gdk_font_ref (GdkFont *font)
57 {
58   GdkFontPrivate *private;
59
60   g_return_val_if_fail (font != NULL, NULL);
61
62   private = (GdkFontPrivate*) font;
63   private->ref_count += 1;
64   return font;
65 }
66
67 /**
68  * gdk_font_unref:
69  * @font: a #GdkFont
70  * 
71  * Decreases the reference count of a font by one.
72  * If the result is zero, destroys the font.
73  **/
74 void
75 gdk_font_unref (GdkFont *font)
76 {
77   GdkFontPrivate *private;
78   private = (GdkFontPrivate*) font;
79
80   g_return_if_fail (font != NULL);
81   g_return_if_fail (private->ref_count > 0);
82
83   private->ref_count -= 1;
84   if (private->ref_count == 0)
85     _gdk_font_destroy (font);
86 }
87
88 /**
89  * gdk_string_width:
90  * @font:  a #GdkFont
91  * @string: the nul-terminated string to measure
92  * 
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
96  * should be drawn)
97  * 
98  * Return value: the width of the string in pixels.
99  **/
100 gint
101 gdk_string_width (GdkFont     *font,
102                   const gchar *string)
103 {
104   g_return_val_if_fail (font != NULL, -1);
105   g_return_val_if_fail (string != NULL, -1);
106
107   return gdk_text_width (font, string, _gdk_font_strlen (font, string));
108 }
109
110 /**
111  * gdk_char_width:
112  * @font: a #GdkFont
113  * @character: the character to measure.
114  * 
115  * Determines the width of a given character.
116  * 
117  * Return value: the width of the character in pixels.
118  *
119  * Deprecated: Use gdk_text_extents() instead.
120  **/
121 gint
122 gdk_char_width (GdkFont *font,
123                 gchar    character)
124 {
125   g_return_val_if_fail (font != NULL, -1);
126
127   return gdk_text_width (font, &character, 1);
128 }
129
130 /**
131  * gdk_char_width_wc:
132  * @font: a #GdkFont
133  * @character: the character to measure.
134  * 
135  * Determines the width of a given wide character. (Encoded
136  * in the wide-character encoding of the current locale).
137  * 
138  * Return value: the width of the character in pixels.
139  **/
140 gint
141 gdk_char_width_wc (GdkFont *font,
142                    GdkWChar character)
143 {
144   g_return_val_if_fail (font != NULL, -1);
145
146   return gdk_text_width_wc (font, &character, 1);
147 }
148
149 /**
150  * gdk_string_measure:
151  * @font: a #GdkFont
152  * @string: the nul-terminated string to measure.
153  * 
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().
159  * 
160  * Return value: the right bearing of the string in pixels.
161  **/
162 gint
163 gdk_string_measure (GdkFont     *font,
164                     const gchar *string)
165 {
166   g_return_val_if_fail (font != NULL, -1);
167   g_return_val_if_fail (string != NULL, -1);
168
169   return gdk_text_measure (font, string, _gdk_font_strlen (font, string));
170 }
171
172 /**
173  * gdk_string_extents:
174  * @font: a #GdkFont.
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.
181  * 
182  * Gets the metrics of a nul-terminated string.
183  **/
184 void
185 gdk_string_extents (GdkFont     *font,
186                     const gchar *string,
187                     gint        *lbearing,
188                     gint        *rbearing,
189                     gint        *width,
190                     gint        *ascent,
191                     gint        *descent)
192 {
193   g_return_if_fail (font != NULL);
194   g_return_if_fail (string != NULL);
195
196   gdk_text_extents (font, string, _gdk_font_strlen (font, string),
197                     lbearing, rbearing, width, ascent, descent);
198 }
199
200
201 /**
202  * gdk_text_measure:
203  * @font: a #GdkFont
204  * @text: the text to measure.
205  * @text_length: the length of the text in bytes.
206  * 
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().
212  * 
213  * Return value: the right bearing of the string in pixels.
214  **/
215 gint
216 gdk_text_measure (GdkFont     *font,
217                   const gchar *text,
218                   gint         text_length)
219 {
220   gint rbearing;
221
222   g_return_val_if_fail (font != NULL, -1);
223   g_return_val_if_fail (text != NULL, -1);
224
225   gdk_text_extents (font, text, text_length, NULL, &rbearing, NULL, NULL, NULL);
226   return rbearing;
227 }
228
229 /**
230  * gdk_char_measure:
231  * @font: a #GdkFont
232  * @character: the character to measure.
233  * 
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. 
238  * 
239  * Return value: the right bearing of the character in pixels.
240  **/
241 gint
242 gdk_char_measure (GdkFont *font,
243                   gchar    character)
244 {
245   g_return_val_if_fail (font != NULL, -1);
246
247   return gdk_text_measure (font, &character, 1);
248 }
249
250 /**
251  * gdk_string_height:
252  * @font: a #GdkFont
253  * @string: the nul-terminated string to measure.
254  * 
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().
259  * 
260  * Return value: the height of the string in pixels.
261  **/
262 gint
263 gdk_string_height (GdkFont     *font,
264                    const gchar *string)
265 {
266   g_return_val_if_fail (font != NULL, -1);
267   g_return_val_if_fail (string != NULL, -1);
268
269   return gdk_text_height (font, string, _gdk_font_strlen (font, string));
270 }
271
272 /**
273  * gdk_text_height:
274  * @font: a #GdkFont
275  * @text: the text to measure.
276  * @text_length: the length of the text in bytes.
277  * 
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().
282  * 
283  * Return value: the height of the string in pixels.
284  **/
285 gint
286 gdk_text_height (GdkFont     *font,
287                  const gchar *text,
288                  gint         text_length)
289 {
290   gint ascent, descent;
291
292   g_return_val_if_fail (font != NULL, -1);
293   g_return_val_if_fail (text != NULL, -1);
294
295   gdk_text_extents (font, text, text_length, NULL, NULL, NULL, &ascent, &descent);
296   return ascent + descent;
297 }
298
299 /**
300  * gdk_char_height:
301  * @font: a #GdkFont
302  * @character: the character to measure.
303  * 
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().
308  * 
309  * Return value: the height of the character in pixels.
310  *
311  * Deprecated: Use gdk_text_extents() instead.
312  **/
313 gint
314 gdk_char_height (GdkFont *font,
315                  gchar    character)
316 {
317   g_return_val_if_fail (font != NULL, -1);
318
319   return gdk_text_height (font, &character, 1);
320 }
321
322 /**
323  * gdk_font_from_description:
324  * @font_desc: a #PangoFontDescription.
325  * 
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.
331  * 
332  * Return value: the newly loaded font, or %NULL if the font
333  * cannot be loaded.
334  **/
335 GdkFont*
336 gdk_font_from_description (PangoFontDescription *font_desc)
337 {
338   return gdk_font_from_description_for_display (gdk_display_get_default (),font_desc);
339 }
340
341 /**
342  * gdk_font_load:
343  * @font_name: a XLFD describing the font to load.
344  * 
345  * Loads a font.
346  * 
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.
349  * 
350  * Return value: a #GdkFont, or %NULL if the font could not be loaded.
351  **/
352 GdkFont*
353 gdk_font_load (const gchar *font_name)
354 {  
355    return gdk_font_load_for_display (gdk_display_get_default(), font_name);
356 }
357
358 #define __GDK_FONT_C__
359 #include "gdkaliasdef.c"