]> Pileus Git - ~andy/gtk/blob - gdk/gdkfont.c
applied patch from Andreas Persenius <ndap@swipnet.se> that updates the
[~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 #include "gdkfont.h"
28 #include "gdkinternals.h"
29
30 GdkFont*
31 gdk_font_ref (GdkFont *font)
32 {
33   GdkFontPrivate *private;
34
35   g_return_val_if_fail (font != NULL, NULL);
36
37   private = (GdkFontPrivate*) font;
38   private->ref_count += 1;
39   return font;
40 }
41
42 void
43 gdk_font_unref (GdkFont *font)
44 {
45   GdkFontPrivate *private;
46   private = (GdkFontPrivate*) font;
47
48   g_return_if_fail (font != NULL);
49   g_return_if_fail (private->ref_count > 0);
50
51   private->ref_count -= 1;
52   if (private->ref_count == 0)
53     _gdk_font_destroy (font);
54 }
55
56 gint
57 gdk_string_width (GdkFont     *font,
58                   const gchar *string)
59 {
60   g_return_val_if_fail (font != NULL, -1);
61   g_return_val_if_fail (string != NULL, -1);
62
63   return gdk_text_width (font, string, _gdk_font_strlen (font, string));
64 }
65
66 gint
67 gdk_char_width (GdkFont *font,
68                 gchar    character)
69 {
70   g_return_val_if_fail (font != NULL, -1);
71
72   return gdk_text_width (font, &character, 1);
73 }
74
75 gint
76 gdk_char_width_wc (GdkFont *font,
77                    GdkWChar character)
78 {
79   g_return_val_if_fail (font != NULL, -1);
80
81   return gdk_text_width_wc (font, &character, 1);
82 }
83
84 gint
85 gdk_string_measure (GdkFont     *font,
86                     const gchar *string)
87 {
88   g_return_val_if_fail (font != NULL, -1);
89   g_return_val_if_fail (string != NULL, -1);
90
91   return gdk_text_measure (font, string, _gdk_font_strlen (font, string));
92 }
93
94 void
95 gdk_string_extents (GdkFont     *font,
96                     const gchar *string,
97                     gint        *lbearing,
98                     gint        *rbearing,
99                     gint        *width,
100                     gint        *ascent,
101                     gint        *descent)
102 {
103   g_return_if_fail (font != NULL);
104   g_return_if_fail (string != NULL);
105
106   gdk_text_extents (font, string, _gdk_font_strlen (font, string),
107                     lbearing, rbearing, width, ascent, descent);
108 }
109
110
111 gint
112 gdk_text_measure (GdkFont     *font,
113                   const gchar *text,
114                   gint         text_length)
115 {
116   gint rbearing;
117
118   g_return_val_if_fail (font != NULL, -1);
119   g_return_val_if_fail (text != NULL, -1);
120
121   gdk_text_extents (font, text, text_length, NULL, &rbearing, NULL, NULL, NULL);
122   return rbearing;
123 }
124 gint
125 gdk_char_measure (GdkFont *font,
126                   gchar    character)
127 {
128   g_return_val_if_fail (font != NULL, -1);
129
130   return gdk_text_measure (font, &character, 1);
131 }
132
133 gint
134 gdk_string_height (GdkFont     *font,
135                    const gchar *string)
136 {
137   g_return_val_if_fail (font != NULL, -1);
138   g_return_val_if_fail (string != NULL, -1);
139
140   return gdk_text_height (font, string, _gdk_font_strlen (font, string));
141 }
142
143 gint
144 gdk_text_height (GdkFont     *font,
145                  const gchar *text,
146                  gint         text_length)
147 {
148   gint ascent, descent;
149
150   g_return_val_if_fail (font != NULL, -1);
151   g_return_val_if_fail (text != NULL, -1);
152
153   gdk_text_extents (font, text, text_length, NULL, NULL, NULL, &ascent, &descent);
154   return ascent + descent;
155 }
156
157 gint
158 gdk_char_height (GdkFont *font,
159                  gchar    character)
160 {
161   g_return_val_if_fail (font != NULL, -1);
162
163   return gdk_text_height (font, &character, 1);
164 }