[sushi] font-widget: try C locale if we can't render the language sample string



commit a926939d0dd38a775386378008b529bb36629dd5
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue May 1 18:08:25 2012 -0400

    font-widget: try C locale if we can't render the language sample string
    
    If we're unable to render the language sample string, because the font
    doesn't have the required glyphs, fall back to the C locale first,
    before constructing a string of random glyphs.

 src/libsushi/sushi-font-widget.c |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)
---
diff --git a/src/libsushi/sushi-font-widget.c b/src/libsushi/sushi-font-widget.c
index 0653ea1..7cfd3b9 100644
--- a/src/libsushi/sushi-font-widget.c
+++ b/src/libsushi/sushi-font-widget.c
@@ -198,11 +198,33 @@ random_string_from_available_chars (FT_Face face,
   return g_string_free (retval, FALSE);
 }
 
-static void
-build_strings_for_face (SushiFontWidget *self)
+static gboolean
+set_pango_sample_string (SushiFontWidget *self)
 {
   const gchar *sample_string;
+  gboolean retval = FALSE;
+
+  sample_string = pango_language_get_sample_string (pango_language_from_string (NULL));
+  if (check_font_contain_text (self->priv->face, sample_string))
+    retval = TRUE;
+
+  if (!retval) {
+    sample_string = pango_language_get_sample_string (pango_language_from_string ("C"));
+    if (check_font_contain_text (self->priv->face, sample_string))
+      retval = TRUE;
+  }
+
+  if (retval) {
+    g_free (self->priv->sample_string);
+    self->priv->sample_string = g_strdup (sample_string);
+  }
 
+  return retval;
+}
+
+static void
+build_strings_for_face (SushiFontWidget *self)
+{
   /* if we don't have lowercase/uppercase/punctuation text in the face,
    * we omit it directly, and render a random text below.
    */
@@ -221,11 +243,7 @@ build_strings_for_face (SushiFontWidget *self)
   else
     self->priv->punctuation_text = NULL;
 
-  sample_string = pango_language_get_sample_string (NULL);
-
-  if (check_font_contain_text (self->priv->face, sample_string))
-    self->priv->sample_string = g_strdup (sample_string);
-  else
+  if (!set_pango_sample_string (self))
     self->priv->sample_string = random_string_from_available_chars (self->priv->face, 36);
 
   if (self->priv->face->family_name == NULL) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]