]> Pileus Git - ~andy/gtk/blob - gdk/directfb/gdkfont-directfb.c
Add a function to beep on a window. For X11, implement this with XkbBell.
[~andy/gtk] / gdk / directfb / gdkfont-directfb.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.
23  */
24
25 /*
26  * GTK+ DirectFB backend
27  * Copyright (C) 2001-2002  convergence integrated media GmbH
28  * Copyright (C) 2002-2004  convergence GmbH
29  * Written by Denis Oliver Kropp <dok@convergence.de> and
30  *            Sven Neumann <sven@convergence.de>
31  */
32
33 #undef GDK_DISABLE_DEPRECATED
34
35 #include <config.h>
36 #include "gdk.h"
37
38 #include <string.h>
39
40 #include "gdkdirectfb.h"
41 #include "gdkprivate-directfb.h"
42
43 #include "gdkinternals.h"
44
45 #include "gdkfont.h"
46 #include "gdkalias.h"
47
48
49 typedef struct _GdkFontDirectFB  GdkFontDirectFB;
50
51 struct _GdkFontDirectFB
52 {
53   GdkFontPrivate    base;
54   gint              size;
55   IDirectFBFont    *dfbfont;
56 };
57
58
59 static GdkFont *
60 gdk_directfb_bogus_font (gint height)
61 {
62   GdkFont         *font;
63   GdkFontDirectFB *private;
64
65   private = g_new0 (GdkFontDirectFB, 1);
66   font = (GdkFont *)private;
67
68   font->type = GDK_FONT_FONT;
69   font->ascent = height*3/4;
70   font->descent = height/4;
71   private->size = height;
72   private->base.ref_count = 1;
73   return font;
74 }
75
76 GdkFont*
77 gdk_font_from_description_for_display (GdkDisplay * display,PangoFontDescription *font_desc)
78 {
79   gint size;
80
81   g_return_val_if_fail (font_desc, NULL);
82
83   size = pango_font_description_get_size (font_desc);
84
85   return gdk_directfb_bogus_font (PANGO_PIXELS (size));
86 }
87
88 /* ********************* */
89
90 GdkFont*
91 gdk_fontset_load (const gchar *fontset_name)
92 {
93   return gdk_directfb_bogus_font (10);
94 }
95
96 GdkFont *
97 gdk_fontset_load_for_display (GdkDisplay *display,const gchar *font_name) {
98   return gdk_directfb_bogus_font (10);
99 }
100
101 GdkFont *
102 gdk_font_load_for_display (GdkDisplay *display,const gchar *font_name)
103 {
104   return gdk_directfb_bogus_font (10);
105 }
106
107 void
108 _gdk_font_destroy (GdkFont *font)
109 {
110   switch (font->type)
111     {
112     case GDK_FONT_FONT:
113       break;
114     case GDK_FONT_FONTSET:
115       break;
116     default:
117       g_error ("unknown font type.");
118       break;
119     }
120
121   g_free (font);
122 }
123
124 gint
125 _gdk_font_strlen (GdkFont     *font,
126                   const gchar *str)
127 {
128   GdkFontDirectFB *font_private;
129   gint length = 0;
130
131   g_return_val_if_fail (font != NULL, -1);
132   g_return_val_if_fail (str != NULL, -1);
133
134   font_private = (GdkFontDirectFB*) font;
135
136   if (font->type == GDK_FONT_FONT)
137     {
138       guint16 *string_2b = (guint16 *)str;
139
140       while (*(string_2b++))
141         length++;
142     }
143   else if (font->type == GDK_FONT_FONTSET)
144     {
145       length = strlen (str);
146     }
147   else
148     g_error("undefined font type\n");
149
150   return length;
151 }
152
153 gint
154 gdk_font_id (const GdkFont *font)
155 {
156   const GdkFontDirectFB *font_private;
157
158   g_return_val_if_fail (font != NULL, 0);
159
160   font_private = (const GdkFontDirectFB*) font;
161
162   if (font->type == GDK_FONT_FONT)
163     {
164       return -1;
165     }
166   else
167     {
168       return 0;
169     }
170 }
171
172 gint
173 gdk_font_equal (const GdkFont *fonta,
174                 const GdkFont *fontb)
175 {
176   const GdkFontDirectFB *privatea;
177   const GdkFontDirectFB *privateb;
178
179   g_return_val_if_fail (fonta != NULL, FALSE);
180   g_return_val_if_fail (fontb != NULL, FALSE);
181
182   privatea = (const GdkFontDirectFB*) fonta;
183   privateb = (const GdkFontDirectFB*) fontb;
184
185   if(fonta == fontb)
186     return TRUE;
187
188   return FALSE;
189 }
190
191 gint
192 gdk_text_width (GdkFont      *font,
193                 const gchar  *text,
194                 gint          text_length)
195 {
196   GdkFontDirectFB *private;
197
198   private = (GdkFontDirectFB*) font;
199
200   return (text_length * private->size) / 2;
201 }
202
203 gint
204 gdk_text_width_wc (GdkFont        *font,
205                    const GdkWChar *text,
206                    gint            text_length)
207 {
208   return 0;
209 }
210
211 void
212 gdk_text_extents (GdkFont     *font,
213                   const gchar *text,
214                   gint         text_length,
215                   gint        *lbearing,
216                   gint        *rbearing,
217                   gint        *width,
218                   gint        *ascent,
219                   gint        *descent)
220 {
221   if(ascent)
222     *ascent = font->ascent;
223   if(descent)
224     *descent = font->descent;
225   if(width)
226     *width = gdk_text_width(font, text, text_length);
227   if(lbearing)
228     *lbearing = 0;
229   if(rbearing)
230     *rbearing = 0;
231 }
232
233 void
234 gdk_text_extents_wc (GdkFont        *font,
235                      const GdkWChar *text,
236                      gint            text_length,
237                      gint           *lbearing,
238                      gint           *rbearing,
239                      gint           *width,
240                      gint           *ascent,
241                      gint           *descent)
242 {
243   char *realstr;
244   int i;
245
246   realstr = alloca (text_length + 1);
247
248   for(i = 0; i < text_length; i++)
249     realstr[i] = text[i];
250
251   realstr[i] = '\0';
252
253   return gdk_text_extents (font,
254                            realstr,
255                            text_length,
256                            lbearing,
257                            rbearing,
258                            width,
259                            ascent,
260                            descent);
261 }
262
263 GdkFont *
264 gdk_font_lookup (GdkNativeWindow xid)
265 {
266         g_warning(" gdk_font_lookup unimplemented \n");
267   return NULL;
268 }
269
270 GdkDisplay*
271 gdk_font_get_display (GdkFont* font)
272 {
273         g_warning(" gdk_font_get_display unimplemented \n");
274   return NULL;
275 }
276
277 #define __GDK_FONT_X11_C__
278 #include "gdkaliasdef.c"