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);
31 get_font_name (const GdkFont * font)
38 g_print ("Extracting X font info\n");
41 font_atom = gdk_atom_intern ("FONT", FALSE);
43 if (font->type == GDK_FONT_FONTSET) {
44 XFontStruct **font_structs;
48 num_fonts = XFontsOfFontSet (XFontSet(GDK_FONT_XFONT (font)), &font_structs, &font_names);
50 g_print ("Fonts of fontset:\n");
51 for (i = 0; i < num_fonts; i++) g_print (" %s\n", font_names[i]);
53 status = XGetFontProperty (font_structs[0], font_atom, &atom);
55 status = XGetFontProperty ( (XFontStruct*)GDK_FONT_XFONT (font), font_atom, &atom);
59 return gdk_atom_name (atom);
65 #if USE_UNUSED_STUFF_FROM_E_FONT
67 * Splits full X font name into pieces, overwriting hyphens
71 split_name (gchar * c[], gchar * name)
79 for (i = 0; i < 12; i++) {
82 while (*p && (*p != '-')) p++;
83 /* Replace hyphen with '\0' */
91 * Find light and bold variants of a font, ideally using the provided
92 * weight for the light variant, and a weight 2 shades darker than it
93 * for the bold variant. If there isn't something 2 shades darker, use
94 * something 3 or more shades darker if it exists, or 1 shade darker
95 * if that's all there is. If there is nothing darker than the provided
96 * weight, but there are lighter fonts, then use the darker one for
97 * bold and a lighter one for light.
101 find_variants (gchar **namelist, gint length, gchar *weight,
102 gchar **lightname, gchar **boldname)
104 static GHashTable *wh = NULL;
105 /* Standard, Found, Bold, Light */
113 wh = g_hash_table_new (g_str_hash, g_str_equal);
114 g_hash_table_insert (wh, "light", GINT_TO_POINTER (1));
115 g_hash_table_insert (wh, "book", GINT_TO_POINTER (2));
116 g_hash_table_insert (wh, "regular", GINT_TO_POINTER (2));
117 g_hash_table_insert (wh, "medium", GINT_TO_POINTER (3));
118 g_hash_table_insert (wh, "demibold", GINT_TO_POINTER (5));
119 g_hash_table_insert (wh, "bold", GINT_TO_POINTER (6));
120 g_hash_table_insert (wh, "black", GINT_TO_POINTER (8));
123 g_snprintf (s, 32, weight);
125 sw = GPOINTER_TO_INT (g_hash_table_lookup (wh, s));
126 if (sw == 0) return FALSE;
128 fw = 0; lw = 0; bw = 32;
129 f = NULL; l = NULL; b = NULL;
130 *lightname = NULL; *boldname = NULL;
132 for (i = 0; i < length; i++) {
135 while (*p && (*p != '-')) p++;
137 while (*p && (*p != '-')) p++;
140 while (*p && (*p != '-')) p++;
143 fw = GPOINTER_TO_INT (g_hash_table_lookup (wh, f));
146 if ((fw - 2 == sw) ||
147 ((fw > bw) && (bw == sw + 1)) ||
148 ((fw < bw) && (fw - 2 > sw))) {
152 } else if (fw < sw) {
153 if ((fw + 2 == sw) ||
154 ((fw < lw) && (lw == sw - 1)) ||
155 ((fw > lw) && (fw + 2 < sw))) {
176 #ifdef E_FONT_VERBOSE
178 * Return newly allocated full name
182 e_font_print_gdk_font_name (const GdkFont * font)
184 Atom font_atom, atom;
187 font_atom = gdk_atom_intern ("FONT", FALSE);
189 g_print ("-------- start of font description --------\n");
192 g_print ("GdkFont is NULL\n");
193 } else if (font->type == GDK_FONT_FONTSET) {
194 XFontStruct **font_structs;
199 num_fonts = XFontsOfFontSet (GDK_FONT_XFONT (font), &font_structs, &font_names);
201 g_print ("Gdk Fontset, locale: %s\n", XLocaleOfFontSet (GDK_FONT_XFONT (font)));
202 for (i = 0; i < num_fonts; i++) {
203 g_print (" %s\n", font_names[i]);
207 status = XGetFontProperty (GDK_FONT_XFONT (font), font_atom, &atom);
208 name = gdk_atom_name (atom);
209 g_print ("GdkFont: %s\n", name);
210 if (name) g_free (name);
213 g_print ("-------- end of font description --------\n");