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 *
gdk_directfb_bogus_font(gint height)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 *
gdk_font_from_description_for_display(GdkDisplay * display,PangoFontDescription * font_desc)77 gdk_font_from_description_for_display (GdkDisplay *display,
78                                        PangoFontDescription *font_desc)
79 {
80   gint size;
81 
82   g_return_val_if_fail (font_desc, NULL);
83 
84   size = pango_font_description_get_size (font_desc);
85 
86   return gdk_directfb_bogus_font (PANGO_PIXELS (size));
87 }
88 
89 /* ********************* */
90 
91 GdkFont *
gdk_fontset_load(const gchar * fontset_name)92 gdk_fontset_load (const gchar *fontset_name)
93 {
94   return gdk_directfb_bogus_font (10);
95 }
96 
97 GdkFont *
gdk_fontset_load_for_display(GdkDisplay * display,const gchar * font_name)98 gdk_fontset_load_for_display (GdkDisplay *display,const gchar *font_name)
99 {
100   return gdk_directfb_bogus_font (10);
101 }
102 
103 GdkFont *
gdk_font_load_for_display(GdkDisplay * display,const gchar * font_name)104 gdk_font_load_for_display (GdkDisplay *display, const gchar *font_name)
105 {
106   return gdk_directfb_bogus_font (10);
107 }
108 
109 void
_gdk_font_destroy(GdkFont * font)110 _gdk_font_destroy (GdkFont *font)
111 {
112   switch (font->type)
113     {
114     case GDK_FONT_FONT:
115       break;
116     case GDK_FONT_FONTSET:
117       break;
118     default:
119       g_error ("unknown font type.");
120       break;
121     }
122 
123   g_free (font);
124 }
125 
126 gint
_gdk_font_strlen(GdkFont * font,const gchar * str)127 _gdk_font_strlen (GdkFont     *font,
128                   const gchar *str)
129 {
130   GdkFontDirectFB *font_private;
131   gint             length = 0;
132 
133   g_return_val_if_fail (font != NULL, -1);
134   g_return_val_if_fail (str != NULL, -1);
135 
136   font_private = (GdkFontDirectFB*) font;
137 
138   if (font->type == GDK_FONT_FONT)
139     {
140       guint16 *string_2b = (guint16 *)str;
141 
142       while (*(string_2b++))
143         length++;
144     }
145   else if (font->type == GDK_FONT_FONTSET)
146     {
147       length = strlen (str);
148     }
149   else
150     g_error("undefined font type\n");
151 
152   return length;
153 }
154 
155 gint
gdk_font_id(const GdkFont * font)156 gdk_font_id (const GdkFont *font)
157 {
158   const GdkFontDirectFB *font_private;
159 
160   g_return_val_if_fail (font != NULL, 0);
161 
162   font_private = (const GdkFontDirectFB*) font;
163 
164   if (font->type == GDK_FONT_FONT)
165     {
166       return -1;
167     }
168   else
169     {
170       return 0;
171     }
172 }
173 
174 gint
gdk_font_equal(const GdkFont * fonta,const GdkFont * fontb)175 gdk_font_equal (const GdkFont *fonta,
176                 const GdkFont *fontb)
177 {
178   const GdkFontDirectFB *privatea;
179   const GdkFontDirectFB *privateb;
180 
181   g_return_val_if_fail (fonta != NULL, FALSE);
182   g_return_val_if_fail (fontb != NULL, FALSE);
183 
184   privatea = (const GdkFontDirectFB*) fonta;
185   privateb = (const GdkFontDirectFB*) fontb;
186 
187   if (fonta == fontb)
188     return TRUE;
189 
190   return FALSE;
191 }
192 
193 gint
gdk_text_width(GdkFont * font,const gchar * text,gint text_length)194 gdk_text_width (GdkFont      *font,
195                 const gchar  *text,
196                 gint          text_length)
197 {
198   GdkFontDirectFB *private;
199 
200   private = (GdkFontDirectFB*) font;
201 
202   return (text_length * private->size) / 2;
203 }
204 
205 gint
gdk_text_width_wc(GdkFont * font,const GdkWChar * text,gint text_length)206 gdk_text_width_wc (GdkFont        *font,
207                    const GdkWChar *text,
208                    gint            text_length)
209 {
210   return 0;
211 }
212 
213 void
gdk_text_extents(GdkFont * font,const gchar * text,gint text_length,gint * lbearing,gint * rbearing,gint * width,gint * ascent,gint * descent)214 gdk_text_extents (GdkFont     *font,
215                   const gchar *text,
216                   gint         text_length,
217                   gint        *lbearing,
218                   gint        *rbearing,
219                   gint        *width,
220                   gint        *ascent,
221                   gint        *descent)
222 {
223   if (ascent)
224     *ascent = font->ascent;
225   if (descent)
226     *descent = font->descent;
227   if (width)
228     *width = gdk_text_width (font, text, text_length);
229   if (lbearing)
230     *lbearing = 0;
231   if (rbearing)
232     *rbearing = 0;
233 }
234 
235 void
gdk_text_extents_wc(GdkFont * font,const GdkWChar * text,gint text_length,gint * lbearing,gint * rbearing,gint * width,gint * ascent,gint * descent)236 gdk_text_extents_wc (GdkFont        *font,
237                      const GdkWChar *text,
238                      gint            text_length,
239                      gint           *lbearing,
240                      gint           *rbearing,
241                      gint           *width,
242                      gint           *ascent,
243                      gint           *descent)
244 {
245   char *realstr;
246   int i;
247 
248   realstr = alloca (text_length + 1);
249 
250   for(i = 0; i < text_length; i++)
251     realstr[i] = text[i];
252 
253   realstr[i] = '\0';
254 
255   return gdk_text_extents (font,
256                            realstr,
257                            text_length,
258                            lbearing,
259                            rbearing,
260                            width,
261                            ascent,
262                            descent);
263 }
264 
265 GdkFont *
gdk_font_lookup(GdkNativeWindow xid)266 gdk_font_lookup (GdkNativeWindow xid)
267 {
268   g_warning(" gdk_font_lookup unimplemented \n");
269   return NULL;
270 }
271 
272 GdkDisplay *
gdk_font_get_display(GdkFont * font)273 gdk_font_get_display (GdkFont* font)
274 {
275   g_warning(" gdk_font_get_display unimplemented \n");
276   return NULL;
277 }
278 
279 #define __GDK_FONT_X11_C__
280 #include "gdkaliasdef.c"
281