2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000 The LyX Team.
9 * ====================================================== */
13 #include <gdk--/font.h>
14 #include <gdk/gdktypes.h>
18 #include "gnome_helpers.h"
20 string get_font_name(Gdk_Font const & font)
22 gchar * name = get_font_name(font.gdkobj());
23 string name_str(name);
30 get_font_name (const GdkFont * font)
37 g_print ("Extracting X font info\n");
40 font_atom = gdk_atom_intern ("FONT", FALSE);
42 if (font->type == GDK_FONT_FONTSET) {
43 XFontStruct **font_structs;
47 num_fonts = XFontsOfFontSet (
48 static_cast<XFontSet>(GDK_FONT_XFONT (font))
49 , &font_structs, &font_names);
51 g_print ("Fonts of fontset:\n");
52 for (i = 0; i < num_fonts; i++) g_print (" %s\n", font_names[i]);
54 status = XGetFontProperty (font_structs[0], font_atom, &atom);
56 status = XGetFontProperty (
57 static_cast<XFontStruct*>(GDK_FONT_XFONT (font))
62 return gdk_atom_name (atom);
68 #if USE_UNUSED_STUFF_FROM_E_FONT
70 * Splits full X font name into pieces, overwriting hyphens
74 split_name (gchar * c[], gchar * name)
82 for (i = 0; i < 12; i++) {
85 while (*p && (*p != '-')) p++;
86 /* Replace hyphen with '\0' */
94 * Find light and bold variants of a font, ideally using the provided
95 * weight for the light variant, and a weight 2 shades darker than it
96 * for the bold variant. If there isn't something 2 shades darker, use
97 * something 3 or more shades darker if it exists, or 1 shade darker
98 * if that's all there is. If there is nothing darker than the provided
99 * weight, but there are lighter fonts, then use the darker one for
100 * bold and a lighter one for light.
104 find_variants (gchar **namelist, gint length, gchar *weight,
105 gchar **lightname, gchar **boldname)
107 static GHashTable *wh = NULL;
108 /* Standard, Found, Bold, Light */
116 wh = g_hash_table_new (g_str_hash, g_str_equal);
117 g_hash_table_insert (wh, "light", GINT_TO_POINTER (1));
118 g_hash_table_insert (wh, "book", GINT_TO_POINTER (2));
119 g_hash_table_insert (wh, "regular", GINT_TO_POINTER (2));
120 g_hash_table_insert (wh, "medium", GINT_TO_POINTER (3));
121 g_hash_table_insert (wh, "demibold", GINT_TO_POINTER (5));
122 g_hash_table_insert (wh, "bold", GINT_TO_POINTER (6));
123 g_hash_table_insert (wh, "black", GINT_TO_POINTER (8));
126 g_snprintf (s, 32, weight);
128 sw = GPOINTER_TO_INT (g_hash_table_lookup (wh, s));
129 if (sw == 0) return FALSE;
131 fw = 0; lw = 0; bw = 32;
132 f = NULL; l = NULL; b = NULL;
133 *lightname = NULL; *boldname = NULL;
135 for (i = 0; i < length; i++) {
138 while (*p && (*p != '-')) p++;
140 while (*p && (*p != '-')) p++;
143 while (*p && (*p != '-')) p++;
146 fw = GPOINTER_TO_INT (g_hash_table_lookup (wh, f));
149 if ((fw - 2 == sw) ||
150 ((fw > bw) && (bw == sw + 1)) ||
151 ((fw < bw) && (fw - 2 > sw))) {
155 } else if (fw < sw) {
156 if ((fw + 2 == sw) ||
157 ((fw < lw) && (lw == sw - 1)) ||
158 ((fw > lw) && (fw + 2 < sw))) {
179 #ifdef E_FONT_VERBOSE
181 * Return newly allocated full name
185 e_font_print_gdk_font_name (const GdkFont * font)
187 Atom font_atom, atom;
190 font_atom = gdk_atom_intern ("FONT", FALSE);
192 g_print ("-------- start of font description --------\n");
195 g_print ("GdkFont is NULL\n");
196 } else if (font->type == GDK_FONT_FONTSET) {
197 XFontStruct **font_structs;
202 num_fonts = XFontsOfFontSet (GDK_FONT_XFONT (font), &font_structs, &font_names);
204 g_print ("Gdk Fontset, locale: %s\n", XLocaleOfFontSet (GDK_FONT_XFONT (font)));
205 for (i = 0; i < num_fonts; i++) {
206 g_print (" %s\n", font_names[i]);
210 status = XGetFontProperty (GDK_FONT_XFONT (font), font_atom, &atom);
211 name = gdk_atom_name (atom);
212 g_print ("GdkFont: %s\n", name);
213 if (name) g_free (name);
216 g_print ("-------- end of font description --------\n");