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 (GDK_FONT_XFONT (font), &font_structs, &font_names);
49 g_print ("Fonts of fontset:\n");
50 for (i = 0; i < num_fonts; i++) g_print (" %s\n", font_names[i]);
52 status = XGetFontProperty (font_structs[0], font_atom, &atom);
54 status = XGetFontProperty (GDK_FONT_XFONT (font), font_atom, &atom);
58 return gdk_atom_name (atom);
64 #if USE_UNUSED_STUFF_FROM_E_FONT
66 * Splits full X font name into pieces, overwriting hyphens
70 split_name (gchar * c[], gchar * name)
78 for (i = 0; i < 12; i++) {
81 while (*p && (*p != '-')) p++;
82 /* Replace hyphen with '\0' */
90 * Find light and bold variants of a font, ideally using the provided
91 * weight for the light variant, and a weight 2 shades darker than it
92 * for the bold variant. If there isn't something 2 shades darker, use
93 * something 3 or more shades darker if it exists, or 1 shade darker
94 * if that's all there is. If there is nothing darker than the provided
95 * weight, but there are lighter fonts, then use the darker one for
96 * bold and a lighter one for light.
100 find_variants (gchar **namelist, gint length, gchar *weight,
101 gchar **lightname, gchar **boldname)
103 static GHashTable *wh = NULL;
104 /* Standard, Found, Bold, Light */
112 wh = g_hash_table_new (g_str_hash, g_str_equal);
113 g_hash_table_insert (wh, "light", GINT_TO_POINTER (1));
114 g_hash_table_insert (wh, "book", GINT_TO_POINTER (2));
115 g_hash_table_insert (wh, "regular", GINT_TO_POINTER (2));
116 g_hash_table_insert (wh, "medium", GINT_TO_POINTER (3));
117 g_hash_table_insert (wh, "demibold", GINT_TO_POINTER (5));
118 g_hash_table_insert (wh, "bold", GINT_TO_POINTER (6));
119 g_hash_table_insert (wh, "black", GINT_TO_POINTER (8));
122 g_snprintf (s, 32, weight);
124 sw = GPOINTER_TO_INT (g_hash_table_lookup (wh, s));
125 if (sw == 0) return FALSE;
127 fw = 0; lw = 0; bw = 32;
128 f = NULL; l = NULL; b = NULL;
129 *lightname = NULL; *boldname = NULL;
131 for (i = 0; i < length; i++) {
134 while (*p && (*p != '-')) p++;
136 while (*p && (*p != '-')) p++;
139 while (*p && (*p != '-')) p++;
142 fw = GPOINTER_TO_INT (g_hash_table_lookup (wh, f));
145 if ((fw - 2 == sw) ||
146 ((fw > bw) && (bw == sw + 1)) ||
147 ((fw < bw) && (fw - 2 > sw))) {
151 } else if (fw < sw) {
152 if ((fw + 2 == sw) ||
153 ((fw < lw) && (lw == sw - 1)) ||
154 ((fw > lw) && (fw + 2 < sw))) {
175 #ifdef E_FONT_VERBOSE
177 * Return newly allocated full name
181 e_font_print_gdk_font_name (const GdkFont * font)
183 Atom font_atom, atom;
186 font_atom = gdk_atom_intern ("FONT", FALSE);
188 g_print ("-------- start of font description --------\n");
191 g_print ("GdkFont is NULL\n");
192 } else if (font->type == GDK_FONT_FONTSET) {
193 XFontStruct **font_structs;
198 num_fonts = XFontsOfFontSet (GDK_FONT_XFONT (font), &font_structs, &font_names);
200 g_print ("Gdk Fontset, locale: %s\n", XLocaleOfFontSet (GDK_FONT_XFONT (font)));
201 for (i = 0; i < num_fonts; i++) {
202 g_print (" %s\n", font_names[i]);
206 status = XGetFontProperty (GDK_FONT_XFONT (font), font_atom, &atom);
207 name = gdk_atom_name (atom);
208 g_print ("GdkFont: %s\n", name);
209 if (name) g_free (name);
212 g_print ("-------- end of font description --------\n");