~ubuntu-branches/debian/sid/gtkglext/sid

« back to all changes in this revision

Viewing changes to gdk/x11/gdkglfont-x11.c

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2004-04-03 17:43:17 UTC
  • Revision ID: james.westby@ubuntu.com-20040403174317-d5gb2d2gftaligp8
Tags: upstream-1.0.6
ImportĀ upstreamĀ versionĀ 1.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GdkGLExt - OpenGL Extension to GDK
 
2
 * Copyright (C) 2002-2004  Naofumi Yasufuku
 
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.1 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 Free Software
 
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
 
17
 */
 
18
 
 
19
#include <string.h>
 
20
 
 
21
#include <pango/pangox.h>
 
22
 
 
23
#include "gdkglx.h"
 
24
#include "gdkglprivate-x11.h"
 
25
#include "gdkglfont.h"
 
26
 
 
27
#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
 
28
#include <gdk/gdkdisplay.h>
 
29
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */
 
30
 
 
31
/*
 
32
 * This code is ripped from gdk/x11/gdkfont-x11.c in GTK+.
 
33
 */
 
34
static char *
 
35
gdk_gl_font_charset_for_locale (void)
 
36
{
 
37
  static char *charset_map[][2] = {
 
38
    { "ANSI_X3.4-1968", "iso8859-1" },
 
39
    { "US-ASCII",   "iso8859-1" },
 
40
    { "ISO-8859-1", "iso8859-1" },
 
41
    { "ISO-8859-2", "iso8859-2" },
 
42
    { "ISO-8859-3", "iso8859-3" },
 
43
    { "ISO-8859-4", "iso8859-4" },
 
44
    { "ISO-8859-5", "iso8859-5" },
 
45
    { "ISO-8859-6", "iso8859-6" },
 
46
    { "ISO-8859-7", "iso8859-7" },
 
47
    { "ISO-8859-8", "iso8859-8" },
 
48
    { "ISO-8859-9", "iso8859-9" },
 
49
    { "UTF-8",      "iso8859-1" }
 
50
  };
 
51
 
 
52
  const char *codeset;
 
53
  char *result = NULL;
 
54
  gsize i;
 
55
 
 
56
  g_get_charset (&codeset);
 
57
  
 
58
  for (i = 0; i < G_N_ELEMENTS (charset_map); i++)
 
59
    if (strcmp (charset_map[i][0], codeset) == 0)
 
60
      {
 
61
        result = charset_map[i][1];
 
62
        break;
 
63
      }
 
64
 
 
65
  if (result != NULL)
 
66
    return g_strdup (result);
 
67
  else
 
68
    return g_strdup ("iso8859-1");
 
69
}
 
70
 
 
71
static PangoFont *
 
72
gdk_gl_font_use_pango_font_common (PangoFontMap               *font_map,
 
73
                                   const PangoFontDescription *font_desc,
 
74
                                   int                         first,
 
75
                                   int                         count,
 
76
                                   int                         list_base)
 
77
{
 
78
  PangoFont *font = NULL;
 
79
  gchar *charset = NULL;
 
80
  PangoXSubfont subfont_id;
 
81
  gchar *xlfd = NULL;
 
82
  PangoXFontCache *font_cache;
 
83
  XFontStruct *fs;
 
84
 
 
85
  GDK_GL_NOTE_FUNC_PRIVATE ();
 
86
 
 
87
  font = pango_font_map_load_font (font_map, NULL, font_desc);
 
88
  if (font == NULL)
 
89
    {
 
90
      g_warning ("cannot load PangoFont");
 
91
      goto FAIL;
 
92
    }
 
93
 
 
94
  charset = gdk_gl_font_charset_for_locale ();
 
95
  if (!pango_x_find_first_subfont (font, &charset, 1, &subfont_id))
 
96
    {
 
97
      g_warning ("cannot find PangoXSubfont");
 
98
      font = NULL;
 
99
      goto FAIL;
 
100
    }
 
101
 
 
102
  xlfd = pango_x_font_subfont_xlfd (font, subfont_id);
 
103
  if (xlfd == NULL)
 
104
    {
 
105
      g_warning ("cannot get XLFD");
 
106
      font = NULL;
 
107
      goto FAIL;
 
108
    }
 
109
 
 
110
  font_cache = pango_x_font_map_get_font_cache (font_map);
 
111
 
 
112
  fs = pango_x_font_cache_load (font_cache, xlfd);
 
113
 
 
114
  glXUseXFont (fs->fid, first, count, list_base);
 
115
 
 
116
  pango_x_font_cache_unload (font_cache, fs);
 
117
 
 
118
 FAIL:
 
119
 
 
120
  if (charset != NULL)
 
121
    g_free (charset);
 
122
 
 
123
  if (xlfd != NULL)
 
124
    g_free (xlfd);
 
125
 
 
126
  return font;
 
127
}
 
128
 
 
129
/**
 
130
 * gdk_gl_font_use_pango_font:
 
131
 * @font_desc: a #PangoFontDescription describing the font to use.
 
132
 * @first: the index of the first glyph to be taken.
 
133
 * @count: the number of glyphs to be taken.
 
134
 * @list_base: the index of the first display list to be generated.
 
135
 *
 
136
 * Creates bitmap display lists from a #PangoFont.
 
137
 *
 
138
 * Return value: the #PangoFont used, or NULL if no font matched.
 
139
 **/
 
140
PangoFont *
 
141
gdk_gl_font_use_pango_font (const PangoFontDescription *font_desc,
 
142
                            int                         first,
 
143
                            int                         count,
 
144
                            int                         list_base)
 
145
{
 
146
  PangoFontMap *font_map;
 
147
 
 
148
  g_return_val_if_fail (font_desc != NULL, NULL);
 
149
 
 
150
  GDK_GL_NOTE_FUNC ();
 
151
 
 
152
#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
 
153
  font_map = pango_x_font_map_for_display (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
 
154
#else  /* GDKGLEXT_MULTIHEAD_SUPPORT */
 
155
  font_map = pango_x_font_map_for_display (gdk_x11_get_default_xdisplay ());
 
156
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */
 
157
 
 
158
  return gdk_gl_font_use_pango_font_common (font_map, font_desc,
 
159
                                            first, count, list_base);
 
160
}
 
161
 
 
162
#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
 
163
 
 
164
/**
 
165
 * gdk_gl_font_use_pango_font_for_display:
 
166
 * @display: a #GdkDisplay.
 
167
 * @font_desc: a #PangoFontDescription describing the font to use.
 
168
 * @first: the index of the first glyph to be taken.
 
169
 * @count: the number of glyphs to be taken.
 
170
 * @list_base: the index of the first display list to be generated.
 
171
 *
 
172
 * Creates bitmap display lists from a #PangoFont.
 
173
 *
 
174
 * Return value: the #PangoFont used, or NULL if no font matched.
 
175
 **/
 
176
PangoFont *
 
177
gdk_gl_font_use_pango_font_for_display (GdkDisplay                 *display,
 
178
                                        const PangoFontDescription *font_desc,
 
179
                                        int                         first,
 
180
                                        int                         count,
 
181
                                        int                         list_base)
 
182
{
 
183
  PangoFontMap *font_map;
 
184
 
 
185
  g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
 
186
  g_return_val_if_fail (font_desc != NULL, NULL);
 
187
 
 
188
  GDK_GL_NOTE_FUNC ();
 
189
 
 
190
  font_map = pango_x_font_map_for_display (GDK_DISPLAY_XDISPLAY (display));
 
191
 
 
192
  return gdk_gl_font_use_pango_font_common (font_map, font_desc,
 
193
                                            first, count, list_base);
 
194
}
 
195
 
 
196
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */