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