summaryrefslogtreecommitdiff
path: root/gdk/x11/gdkfont-x11.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdk/x11/gdkfont-x11.c')
-rw-r--r--gdk/x11/gdkfont-x11.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/gdk/x11/gdkfont-x11.c b/gdk/x11/gdkfont-x11.c
index 4195a1f67..a0fc46aeb 100644
--- a/gdk/x11/gdkfont-x11.c
+++ b/gdk/x11/gdkfont-x11.c
@@ -26,6 +26,9 @@
#include <X11/Xlib.h>
#include <X11/Xos.h>
+
+#include <pango/pangox.h>
+
#include "gdkfont.h"
#include "gdkprivate-x11.h"
@@ -133,6 +136,93 @@ gdk_font_load (const gchar *font_name)
return font;
}
+static char *
+gdk_font_charset_for_locale ()
+{
+ static char *charset_map[][2] = {
+ { "ANSI_X3.4-1968", "iso8859-1" },
+ { "ISO-8859-1", "iso8859-1" },
+ { "ISO-8859-2", "iso8859-2" },
+ { "ISO-8859-3", "iso8859-3" },
+ { "ISO-8859-4", "iso8859-4" },
+ { "ISO-8859-5", "iso8859-5" },
+ { "ISO-8859-6", "iso8859-6" },
+ { "ISO-8859-7", "iso8859-7" },
+ { "ISO-8859-8", "iso8859-8" },
+ { "ISO-8859-9", "iso8859-9" },
+ };
+
+ char *codeset = g_get_codeset ();
+ char *result = NULL;
+ int i;
+
+ for (i=0; i < G_N_ELEMENTS (charset_map); i++)
+ if (strcmp (charset_map[i][0], codeset) == 0)
+ {
+ result = charset_map[i][1];
+ break;
+ }
+
+ g_free (codeset);
+
+ if (result)
+ return g_strdup (result);
+ else
+ return g_strdup ("iso-8859-1");
+};
+
+/**
+ * gdk_font_from_description:
+ * @font_desc: a #PangoFontDescription.
+ *
+ * Load a #GdkFont based on a Pango font description. This font will
+ * only be an approximation of the Pango font, and
+ * internationalization will not be handled correctly. This function
+ * should only be used for legacy code that cannot be easily converted
+ * to use Pango. Using Pango directly will produce better results.
+ *
+ * Return value: the newly loaded font, or %NULL if the font
+ * cannot be loaded.
+ **/
+GdkFont*
+gdk_font_from_description (PangoFontDescription *font_desc)
+{
+ PangoFontMap *font_map;
+ PangoFont *font;
+ GdkFont *result = NULL;
+
+ g_return_val_if_fail (font_desc != NULL, NULL);
+
+ font_map = pango_x_font_map_for_display (GDK_DISPLAY ());
+ font = pango_font_map_load_font (font_map, font_desc);
+
+ if (font)
+ {
+ gchar *charset = gdk_font_charset_for_locale ();
+ gint n_subfonts;
+ PangoXSubfont *subfont_ids;
+ gint *subfont_charsets;
+
+ n_subfonts = pango_x_list_subfonts (font, &charset, 1,
+ &subfont_ids, &subfont_charsets);
+ if (n_subfonts > 0)
+ {
+ gchar *xlfd = pango_x_font_subfont_xlfd (font, subfont_ids[0]);
+ result = gdk_font_load (xlfd);
+
+ g_free (xlfd);
+ }
+
+ g_free (subfont_ids);
+ g_free (subfont_charsets);
+
+ g_free (charset);
+ g_object_unref (G_OBJECT (font));
+ }
+
+ return result;
+}
+
GdkFont*
gdk_fontset_load (const gchar *fontset_name)
{