summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2001-06-26 19:13:28 +0000
committerOwen Taylor <otaylor@src.gnome.org>2001-06-26 19:13:28 +0000
commit9c41176796502c33fec770dc5952bdcdc9db3783 (patch)
treee2c561525c5cdbe96aae959634e2cb3feceb3b8e
parentac5989fb0fec8273fd4955611b6efb0317d138c1 (diff)
downloadpango-9c41176796502c33fec770dc5952bdcdc9db3783.tar.gz
Couple of bug fixes for the last change.
Tue Jun 26 15:11:30 2001 Owen Taylor <otaylor@redhat.com> * pango/pango-context.c (font_set_get_font) pango/pango-context.c (add_engines): Couple of bug fixes for the last change. * configure.in: Abort out when AM_PATH_GLIB fails.
-rw-r--r--ChangeLog18
-rw-r--r--ChangeLog.pre-1-018
-rw-r--r--ChangeLog.pre-1-1018
-rw-r--r--ChangeLog.pre-1-218
-rw-r--r--ChangeLog.pre-1-418
-rw-r--r--ChangeLog.pre-1-618
-rw-r--r--ChangeLog.pre-1-818
-rw-r--r--configure.in8
-rw-r--r--pango/modules.c3
-rw-r--r--pango/pango-context.c218
-rw-r--r--pango/pango-context.h5
-rw-r--r--pango/pango-utils.c90
-rw-r--r--pango/pango-utils.h3
-rw-r--r--pango/pangoft2.c85
-rw-r--r--pango/pangowin32.c83
-rw-r--r--pango/pangox.c85
16 files changed, 404 insertions, 302 deletions
diff --git a/ChangeLog b/ChangeLog
index 130cfec8..847c0e96 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+Tue Jun 26 15:11:30 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-context.c (font_set_get_font)
+ pango/pango-context.c (add_engines): Couple of
+ bug fixes for the last change.
+
+ * configure.in: Abort out when AM_PATH_GLIB fails.
+
+Tue Jun 26 10:19:02 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.c (pango_language_matches): Handle
+ language == NULL as matching nothing but '*'.
+
+ * pango/pango-context.[ch] (pango_context_get_metrics): Add a
+ (slowish) function to get the metrics for a font description,
+ including fallbacks as with pango_itemize(), rather than a single
+ font.
+
Sat Jun 23 10:01:20 2001 Owen Taylor <otaylor@redhat.com>
* pango/pangowin32-fontmap.c (pango_win32_font_entry_get_coverage):
diff --git a/ChangeLog.pre-1-0 b/ChangeLog.pre-1-0
index 130cfec8..847c0e96 100644
--- a/ChangeLog.pre-1-0
+++ b/ChangeLog.pre-1-0
@@ -1,3 +1,21 @@
+Tue Jun 26 15:11:30 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-context.c (font_set_get_font)
+ pango/pango-context.c (add_engines): Couple of
+ bug fixes for the last change.
+
+ * configure.in: Abort out when AM_PATH_GLIB fails.
+
+Tue Jun 26 10:19:02 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.c (pango_language_matches): Handle
+ language == NULL as matching nothing but '*'.
+
+ * pango/pango-context.[ch] (pango_context_get_metrics): Add a
+ (slowish) function to get the metrics for a font description,
+ including fallbacks as with pango_itemize(), rather than a single
+ font.
+
Sat Jun 23 10:01:20 2001 Owen Taylor <otaylor@redhat.com>
* pango/pangowin32-fontmap.c (pango_win32_font_entry_get_coverage):
diff --git a/ChangeLog.pre-1-10 b/ChangeLog.pre-1-10
index 130cfec8..847c0e96 100644
--- a/ChangeLog.pre-1-10
+++ b/ChangeLog.pre-1-10
@@ -1,3 +1,21 @@
+Tue Jun 26 15:11:30 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-context.c (font_set_get_font)
+ pango/pango-context.c (add_engines): Couple of
+ bug fixes for the last change.
+
+ * configure.in: Abort out when AM_PATH_GLIB fails.
+
+Tue Jun 26 10:19:02 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.c (pango_language_matches): Handle
+ language == NULL as matching nothing but '*'.
+
+ * pango/pango-context.[ch] (pango_context_get_metrics): Add a
+ (slowish) function to get the metrics for a font description,
+ including fallbacks as with pango_itemize(), rather than a single
+ font.
+
Sat Jun 23 10:01:20 2001 Owen Taylor <otaylor@redhat.com>
* pango/pangowin32-fontmap.c (pango_win32_font_entry_get_coverage):
diff --git a/ChangeLog.pre-1-2 b/ChangeLog.pre-1-2
index 130cfec8..847c0e96 100644
--- a/ChangeLog.pre-1-2
+++ b/ChangeLog.pre-1-2
@@ -1,3 +1,21 @@
+Tue Jun 26 15:11:30 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-context.c (font_set_get_font)
+ pango/pango-context.c (add_engines): Couple of
+ bug fixes for the last change.
+
+ * configure.in: Abort out when AM_PATH_GLIB fails.
+
+Tue Jun 26 10:19:02 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.c (pango_language_matches): Handle
+ language == NULL as matching nothing but '*'.
+
+ * pango/pango-context.[ch] (pango_context_get_metrics): Add a
+ (slowish) function to get the metrics for a font description,
+ including fallbacks as with pango_itemize(), rather than a single
+ font.
+
Sat Jun 23 10:01:20 2001 Owen Taylor <otaylor@redhat.com>
* pango/pangowin32-fontmap.c (pango_win32_font_entry_get_coverage):
diff --git a/ChangeLog.pre-1-4 b/ChangeLog.pre-1-4
index 130cfec8..847c0e96 100644
--- a/ChangeLog.pre-1-4
+++ b/ChangeLog.pre-1-4
@@ -1,3 +1,21 @@
+Tue Jun 26 15:11:30 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-context.c (font_set_get_font)
+ pango/pango-context.c (add_engines): Couple of
+ bug fixes for the last change.
+
+ * configure.in: Abort out when AM_PATH_GLIB fails.
+
+Tue Jun 26 10:19:02 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.c (pango_language_matches): Handle
+ language == NULL as matching nothing but '*'.
+
+ * pango/pango-context.[ch] (pango_context_get_metrics): Add a
+ (slowish) function to get the metrics for a font description,
+ including fallbacks as with pango_itemize(), rather than a single
+ font.
+
Sat Jun 23 10:01:20 2001 Owen Taylor <otaylor@redhat.com>
* pango/pangowin32-fontmap.c (pango_win32_font_entry_get_coverage):
diff --git a/ChangeLog.pre-1-6 b/ChangeLog.pre-1-6
index 130cfec8..847c0e96 100644
--- a/ChangeLog.pre-1-6
+++ b/ChangeLog.pre-1-6
@@ -1,3 +1,21 @@
+Tue Jun 26 15:11:30 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-context.c (font_set_get_font)
+ pango/pango-context.c (add_engines): Couple of
+ bug fixes for the last change.
+
+ * configure.in: Abort out when AM_PATH_GLIB fails.
+
+Tue Jun 26 10:19:02 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.c (pango_language_matches): Handle
+ language == NULL as matching nothing but '*'.
+
+ * pango/pango-context.[ch] (pango_context_get_metrics): Add a
+ (slowish) function to get the metrics for a font description,
+ including fallbacks as with pango_itemize(), rather than a single
+ font.
+
Sat Jun 23 10:01:20 2001 Owen Taylor <otaylor@redhat.com>
* pango/pangowin32-fontmap.c (pango_win32_font_entry_get_coverage):
diff --git a/ChangeLog.pre-1-8 b/ChangeLog.pre-1-8
index 130cfec8..847c0e96 100644
--- a/ChangeLog.pre-1-8
+++ b/ChangeLog.pre-1-8
@@ -1,3 +1,21 @@
+Tue Jun 26 15:11:30 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-context.c (font_set_get_font)
+ pango/pango-context.c (add_engines): Couple of
+ bug fixes for the last change.
+
+ * configure.in: Abort out when AM_PATH_GLIB fails.
+
+Tue Jun 26 10:19:02 2001 Owen Taylor <otaylor@redhat.com>
+
+ * pango/pango-utils.c (pango_language_matches): Handle
+ language == NULL as matching nothing but '*'.
+
+ * pango/pango-context.[ch] (pango_context_get_metrics): Add a
+ (slowish) function to get the metrics for a font description,
+ including fallbacks as with pango_itemize(), rather than a single
+ font.
+
Sat Jun 23 10:01:20 2001 Owen Taylor <otaylor@redhat.com>
* pango/pangowin32-fontmap.c (pango_win32_font_entry_get_coverage):
diff --git a/configure.in b/configure.in
index 21a5005e..c701acd0 100644
--- a/configure.in
+++ b/configure.in
@@ -119,7 +119,13 @@ AM_CONDITIONAL(HAVE_XFT, $have_xft)
#
# Checks for GLib
#
-AM_PATH_GLIB_2_0(1.3.5,,,gobject gmodule)
+GLIB_REQUIRED_VERSION=1.3.6
+
+AM_PATH_GLIB_2_0($GLIB_REQUIRED_VERSION, :,
+ AC_MSG_ERROR([
+*** Glib $GLIB_REQUIRED_VERSION or better is required. The latest version of
+*** Glib is always available from ftp://ftp.gtk.org/.]),
+ gobject gmodule)
CFLAGS="$CFLAGS $GLIB_CFLAGS"
diff --git a/pango/modules.c b/pango/modules.c
index 4f235452..b4f15bec 100644
--- a/pango/modules.c
+++ b/pango/modules.c
@@ -127,7 +127,8 @@ pango_find_map (PangoLanguage *language,
{
/* Move the found map to the beginning of the list
* for speed next time around if we had to do
- * any failing strcmps.
+ * any failing comparison. (No longer so important,
+ * since we don't strcmp.)
*/
maps = g_list_remove_link(maps, tmp_list);
maps = g_list_prepend(maps, tmp_list->data);
diff --git a/pango/pango-context.c b/pango/pango-context.c
index b8ebf937..7e5bb3ac 100644
--- a/pango/pango-context.c
+++ b/pango/pango-context.c
@@ -697,74 +697,88 @@ static PangoEngineShape fallback_shaper = {
fallback_engine_get_coverage
};
-static PangoFont *
-get_font (PangoFont **fonts,
- PangoCoverage **coverages,
- int n_families,
- gunichar wc)
+/* FIXME: Remove this artificial limit */
+#define MAX_FAMILIES 16
+
+typedef struct _FontSet FontSet;
+
+struct _FontSet
+{
+ int n_families;
+ PangoFont *fonts[MAX_FAMILIES];
+ PangoCoverage *coverages[MAX_FAMILIES];
+};
+
+#define FONT_SET_INITIALIZER { 0, }
+
+static gint
+font_set_get_font (FontSet *font_set,
+ gunichar wc)
{
- PangoFont *result = NULL;
PangoCoverageLevel best_level = PANGO_COVERAGE_NONE;
+ int result = -1;
int i;
- for (i=0; i<n_families; i++)
+ for (i=0; i < font_set->n_families; i++)
{
- if (fonts[i])
+ if (font_set->fonts[i])
{
- PangoCoverageLevel level = pango_coverage_get (coverages[i], wc);
+ PangoCoverageLevel level = pango_coverage_get (font_set->coverages[i], wc);
- if (!result || level > best_level)
+ if (result == -1 || level > best_level)
{
- result = fonts[i];
+ result = i;
best_level = level;
}
}
}
- if (result)
- g_object_ref (result);
-
return result;
}
-/* FIXME: Remove this artificial limit */
-#define MAX_FAMILIES 16
-
static void
-load_font (PangoContext *context,
- PangoLanguage *language,
- PangoFontDescription *desc,
- PangoFont **current_fonts,
- PangoCoverage **current_coverages,
- int *n_families)
+font_set_free (FontSet *font_set)
{
- char **families;
- char *orig_family;
int j;
- for (j=0; j < *n_families; j++)
+ for (j=0; j < font_set->n_families; j++)
{
- if (current_fonts[j])
+ if (font_set->fonts[j])
{
- g_object_unref (current_fonts[j]);
- pango_coverage_unref (current_coverages[j]);
+ g_object_unref (font_set->fonts[j]);
+ pango_coverage_unref (font_set->coverages[j]);
}
}
+ font_set->n_families = 0;
+}
+
+static void
+font_set_load (FontSet *font_set,
+ PangoContext *context,
+ PangoLanguage *language,
+ PangoFontDescription *desc)
+{
+ char **families;
+ char *orig_family;
+ int j;
+
+ font_set_free (font_set);
+
orig_family = desc->family_name;
families = g_strsplit (orig_family, ",", -1);
- *n_families = 0;
- for (j=0; families[j] && *n_families < MAX_FAMILIES; j++)
+ font_set->n_families = 0;
+ for (j=0; families[j] && font_set->n_families < MAX_FAMILIES; j++)
{
desc->family_name = families[j];
- current_fonts[*n_families] = pango_context_load_font (context, desc);
+ font_set->fonts[font_set->n_families] = pango_context_load_font (context, desc);
- if (current_fonts[*n_families])
+ if (font_set->fonts[font_set->n_families])
{
- current_coverages[*n_families] = pango_font_get_coverage (current_fonts[*n_families], language);
- (*n_families)++;
+ font_set->coverages[font_set->n_families] = pango_font_get_coverage (font_set->fonts[font_set->n_families], language);
+ (font_set->n_families)++;
}
}
@@ -773,7 +787,7 @@ load_font (PangoContext *context,
/* The font description was completely unloadable, try with
* family == "Sans"
*/
- if (*n_families == 0)
+ if (font_set->n_families == 0)
{
char *ctmp1, *ctmp2;
@@ -789,17 +803,17 @@ load_font (PangoContext *context,
desc->family_name = "Sans";
- current_fonts[0] = pango_context_load_font (context, desc);
- if (current_fonts[0])
+ font_set->fonts[0] = pango_context_load_font (context, desc);
+ if (font_set->fonts[0])
{
- current_coverages[0] = pango_font_get_coverage (current_fonts[0], language);
- *n_families = 1;
+ font_set->coverages[0] = pango_font_get_coverage (font_set->fonts[0], language);
+ font_set->n_families = 1;
}
}
/* We couldn't try with Sans and the specified style. Try Sans Normal
*/
- if (*n_families == 0)
+ if (font_set->n_families == 0)
{
char *ctmp1, *ctmp2;
@@ -814,17 +828,17 @@ load_font (PangoContext *context,
g_free (ctmp1);
g_free (ctmp2);
- current_fonts[0] = pango_context_load_font (context, desc);
- if (current_fonts[0])
+ font_set->fonts[0] = pango_context_load_font (context, desc);
+ if (font_set->fonts[0])
{
- current_coverages[0] = pango_font_get_coverage (current_fonts[0], language);
- *n_families = 1;
+ font_set->coverages[0] = pango_font_get_coverage (font_set->fonts[0], language);
+ font_set->n_families = 1;
}
}
/* Everything failed, we are screwed, there is no way to continue
*/
- if (n_families == 0)
+ if (font_set->n_families == 0)
{
g_warning ("All font failbacks failed!!!!");
exit (1);
@@ -869,13 +883,12 @@ add_engines (PangoContext *context,
GSList *extra_attrs = NULL;
PangoMap *lang_map = NULL;
PangoFontDescription current_desc = { 0 };
- int n_families = 0;
- PangoFont *current_fonts[MAX_FAMILIES];
- PangoCoverage *current_coverages[MAX_FAMILIES];
+ FontSet current_fonts = FONT_SET_INITIALIZER;
PangoAttrIterator *iterator;
gboolean first_iteration = TRUE;
gunichar wc;
- int i = 0, j;
+ int i = 0;
+ int font_index;
if (cached_iter)
iterator = cached_iter;
@@ -935,8 +948,7 @@ add_engines (PangoContext *context,
{
current_desc = next_desc;
- load_font (context, language, &current_desc,
- current_fonts, current_coverages, &n_families);
+ font_set_load (&current_fonts, context, language, &current_desc);
}
}
@@ -944,7 +956,14 @@ add_engines (PangoContext *context,
pos = g_utf8_next_char (pos);
analysis->lang_engine = (PangoEngineLang *)pango_map_get_engine (lang_map, wc);
- analysis->font = get_font (current_fonts, current_coverages, n_families, wc);
+ font_index = font_set_get_font (&current_fonts, wc);
+ if (font_index != -1)
+ {
+ analysis->font = current_fonts.fonts[font_index];
+ g_object_ref (analysis->font);
+ }
+ else
+ analysis->font = NULL;
analysis->language = language;
/* FIXME: handle reference counting properly on the shapers */
@@ -960,17 +979,94 @@ add_engines (PangoContext *context,
}
g_assert (pos - text == start_index + length);
+
+ font_set_free (&current_fonts);
+
+ if (iterator != cached_iter)
+ pango_attr_iterator_destroy (iterator);
+}
+
+/**
+ * pango_context_get_metrics:
+ * @context: a #PangoContext
+ * @desc: a #PangoFontDescription structure
+ * @language: language tag used to determine which script to get the metrics
+ * for, or %NULL to indicate to get the metrics for the entire
+ * font.
+ * @metrics: Structure to fill in with the metrics of the font
+ *
+ * Get overall metric information for a font particular font
+ * description. Since the metrics may be substantially different for
+ * different scripts, a language tag can be provided to indicate that
+ * the metrics should be retrieved that correspond to the script(s)
+ * used by that language.
+ *
+ * The #PangoFontDescription is interpreted in the same way as
+ * by pango_itemize(), and the family name may be a comma separated
+ * list of figures. If characters from multiple of these families
+ * would be used to render the string, then the returned fonts would
+ * be a composite of the metrics for the fonts loaded for the
+ * individual families.
+ **/
+void
+pango_context_get_metrics (PangoContext *context,
+ const PangoFontDescription *desc,
+ PangoLanguage *language,
+ PangoFontMetrics *metrics)
+{
+ FontSet current_fonts = FONT_SET_INITIALIZER;
+ PangoFontMetrics raw_metrics[MAX_FAMILIES];
+ gboolean have_metrics[MAX_FAMILIES];
+ PangoFontDescription tmp_desc = *desc;
+ const char *sample_str;
+ const char *p;
+ int i;
+
+ g_return_if_fail (PANGO_IS_CONTEXT (context));
+ g_return_if_fail (desc != NULL);
+ g_return_if_fail (metrics != NULL);
+
+ sample_str = pango_language_get_sample_string (language);
+
+ font_set_load (&current_fonts, context, language, &tmp_desc);
+
+ for (i=0; i < MAX_FAMILIES; i++)
+ have_metrics[i] = FALSE;
- for (j=0; j<n_families; j++)
+ if (current_fonts.n_families == 1)
+ pango_font_get_metrics (current_fonts.fonts[0], language, metrics);
+ else
{
- if (current_fonts[j])
+ int count = 0;
+
+ p = sample_str;
+ while (*p)
{
- g_object_unref (current_fonts[j]);
- pango_coverage_unref (current_coverages[j]);
+ gunichar wc = g_utf8_get_char (p);
+ int index = font_set_get_font (&current_fonts, wc);
+ if (!have_metrics[index])
+ {
+ pango_font_get_metrics (current_fonts.fonts[index], language, &raw_metrics[index]);
+ have_metrics[index] = TRUE;
+ }
+
+ if (count == 0)
+ *metrics = raw_metrics[index];
+ else
+ {
+ metrics->ascent = MAX (metrics->ascent, raw_metrics[index].ascent);
+ metrics->descent = MAX (metrics->descent, raw_metrics[index].descent);
+ metrics->approximate_char_width += raw_metrics[index].approximate_char_width;
+ metrics->approximate_digit_width += raw_metrics[index].approximate_digit_width;
+ }
+
+ p = g_utf8_next_char (p);
+ count++;
}
- }
- if (iterator != cached_iter)
- pango_attr_iterator_destroy (iterator);
+ metrics->approximate_char_width /= count;
+ metrics->approximate_digit_width /= count;
+ }
+
+ font_set_free (&current_fonts);
}
-
diff --git a/pango/pango-context.h b/pango/pango-context.h
index 82ad982f..471328eb 100644
--- a/pango/pango-context.h
+++ b/pango/pango-context.h
@@ -61,6 +61,11 @@ void pango_context_list_families (PangoContext *context
int *n_families);
PangoFont * pango_context_load_font (PangoContext *context,
const PangoFontDescription *desc);
+void pango_context_get_metrics (PangoContext *context,
+ const PangoFontDescription *desc,
+ PangoLanguage *language,
+ PangoFontMetrics *metrics);
+
void pango_context_set_font_description (PangoContext *context,
const PangoFontDescription *desc);
diff --git a/pango/pango-utils.c b/pango/pango-utils.c
index b5c6c511..568434f2 100644
--- a/pango/pango-utils.c
+++ b/pango/pango-utils.c
@@ -984,7 +984,8 @@ pango_language_from_string (const char *language)
/**
* pango_language_matches:
- * @language: a language tag (see pango_language_from_string())
+ * @language: a language tag (see pango_language_from_string()),
+ * %NULL is allowed and matches nothing but '*'
* @range_list: a list of language ranges, separated by ';' characters.
* each element must either be '*', or a RFC 3066 language range
* canonicalized as by pango_lang_canonicalize().
@@ -1013,7 +1014,7 @@ pango_language_matches (PangoLanguage *language,
}
if (strncmp (p, "*", 1) == 0 ||
- (strncmp (lang_str, p, end - p) == 0 &&
+ (lang_str && strncmp (lang_str, p, end - p) == 0 &&
(lang_str[end - p] == '\0' || lang_str[end - p] == '-')))
return TRUE;
@@ -1023,6 +1024,91 @@ pango_language_matches (PangoLanguage *language,
return FALSE;
}
+typedef struct {
+ const char *lang;
+ const char *str;
+} LangInfo;
+
+int
+lang_info_compare (const void *key, const void *val)
+{
+ const LangInfo *lang_info = val;
+
+ return strncmp (key, lang_info->lang, 2);
+}
+
+/* The following array is supposed to contain enough text to tickle all necessary fonts for each
+ * of the languages in the following. Yes, it's pretty lame. Not all of the languages
+ * in the following have sufficient text to excercise all the accents for the language, and
+ * there are obviously many more languages to include as well.
+ */
+LangInfo lang_texts[] = {
+ { "ar", "Arabic السلام عليكم" },
+ { "cs", "Czech (česky) Dobrý den" },
+ { "da", "Danish (Dansk) Hej, Goddag" },
+ { "el", "Greek (Ελληνικά) Γειά σας" },
+ { "en", "English Hello" },
+ { "eo", "Esperanto Saluton" },
+ { "es", "Spanish (Español) ¡Hola!" },
+ { "et", "Estonian Tere, Tervist" },
+ { "fi", "Finnish (Suomi) Hei, Hyvää päivää" },
+ { "fr", "French (Français)" },
+ { "de", "German Grüß Gott" },
+ { "iw", "Hebrew שלום" },
+ { "il", "Italiano Ciao, Buon giorno" },
+ { "ja", "Japanese (日本語) こんにちは, コンニチハ" },
+ { "ko", "Korean (한글) 안녕하세요, 안녕하십니까" },
+ { "mt", "Maltese Ċaw, Saħħa" },
+ { "nl", "Nederlands, Vlaams Hallo, Dag" },
+ { "no", "Norwegian (Norsk) Hei, God dag" },
+ { "pl", "Polish Dzień dobry, Hej" },
+ { "ru", "Russian (Русский)" },
+ { "sk", "Slovak Dobrý deň" },
+ { "sv", "Swedish (Svenska) Hej på dej, Goddag" },
+ { "tr", "Turkish (Türkçe) Merhaba" },
+ { "zh", "Chinese (中文,普通话,汉语)" }
+};
+
+/**
+ * pango_language_get_sample_string:
+ * @language: a #PangoLanguage
+ *
+ * Get a string that is representative of the characters needed to
+ * render a particular language. This function is a bad hack for
+ * internal use by renderers and Pango.
+ *
+ * Return value: the sample string. This value is owned by Pango
+ * and must not be freed.
+ **/
+G_CONST_RETURN char *
+pango_language_get_sample_string (PangoLanguage *language)
+{
+ const char *result;
+
+ if (language)
+ {
+ const char *lang_str = pango_language_to_string (language);
+
+ LangInfo *lang_info = bsearch (lang_str, lang_texts,
+ G_N_ELEMENTS (lang_texts), sizeof (LangInfo),
+ lang_info_compare);
+
+ if (lang_info)
+ result = lang_info->str;
+ else
+ result = "French (Français)"; /* Assume iso-8859-1 */
+ }
+ else
+ {
+ /* Complete junk
+ */
+
+ result = "السلام عليكم česky Ελληνικά Français 日本語 한글 Русский 中文,普通话,汉语 Türkçe";
+ }
+
+ return result;
+}
+
#ifdef HAVE_FRIBIDI
void
diff --git a/pango/pango-utils.h b/pango/pango-utils.h
index 00c31a57..995f772b 100644
--- a/pango/pango-utils.h
+++ b/pango/pango-utils.h
@@ -83,3 +83,6 @@ gboolean pango_log2vis_get_embedding_levels (gunichar *str,
gboolean pango_get_mirror_char (gunichar ch,
gunichar *mirrored_ch);
+
+G_CONST_RETURN char *pango_language_get_sample_string (PangoLanguage *language);
+
diff --git a/pango/pangoft2.c b/pango/pangoft2.c
index 8cdf7fb1..99bd1376 100644
--- a/pango/pangoft2.c
+++ b/pango/pangoft2.c
@@ -48,7 +48,7 @@ typedef struct _PangoFT2ContextInfo PangoFT2ContextInfo;
struct _PangoFT2MetricsInfo
{
- PangoLanguage *language;
+ const char *sample_str;
PangoFontMetrics metrics;
};
@@ -622,52 +622,6 @@ get_font_metrics_from_string (PangoFont *font,
g_free (embedding_levels);
}
-typedef struct {
- const char *lang;
- const char *str;
-} LangInfo;
-
-int
-lang_info_compare (const void *key,
- const void *val)
-{
- const LangInfo *lang_info = val;
-
- return strncmp (key, lang_info->lang, 2);
-}
-
-/* The following array is supposed to contain enough text to tickle all necessary fonts for each
- * of the languages in the following. Yes, it's pretty lame. Not all of the languages
- * in the following have sufficient text to excercise all the accents for the language, and
- * there are obviously many more languages to include as well.
- */
-LangInfo lang_texts[] = {
- { "ar", "Arabic ا,DXXم عY(JY,CY(B" },
- { "cs", "Czech (česky) Dobrý den" },
- { "da", "Danish (Dansk) Hej, Goddag" },
- { "el", "Greek ($(GN;ληνικά(B) $(CN5ιά ,CNς(B" },
- { "en", "English Hello" },
- { "eo", "Esperanto Saluton" },
- { "es", "Spanish (Español) ¡Hola!" },
- { "et", "Estonian Tere, Tervist" },
- { "fi", "Finnish (Suomi) Hei, Hyvää päivää" },
- { "fr", "French (Français)" },
- { "de", "German Grüß Gott" },
- { "iw", "Hebrew שלום" },
- { "il", "Italiano Ciao, Buon giorno" },
- { "ja", "Japanese (日語) こん, コン,Foハ(B" },
- { "ko", "Korean (한글) ,Hk하,D8요(B, ,Hk하십j(B" },
- { "mt", "Maltese Ċaw, Saħħa" },
- { "nl", "Nederlands, Vlaams Hallo, Dag" },
- { "no", "Norwegian (Norsk) Hei, God dag" },
- { "pl", "Polish Dzień dobry, Hej" },
- { "ru", "Russian (Р,CQкий(B)" },
- { "sk", "Slovak Dobrý deň" },
- { "sv", "Swedish (Svenska) Hej på dej, Goddag" },
- { "tr", "Turkish (Türkçe) Merhaba" },
- { "zh", "Chinese (中文,$(1.i话(B,(Ih(B)" }
-};
-
static void
pango_ft2_font_get_metrics (PangoFont *font,
PangoLanguage *language,
@@ -677,43 +631,14 @@ pango_ft2_font_get_metrics (PangoFont *font,
PangoFT2Font *ft2font = (PangoFT2Font *)font;
GSList *tmp_list;
- PangoLanguage *lookup_lang;
- const char *str;
-
- if (language)
- {
- const char *lang_str = pango_language_to_string (language);
-
- LangInfo *lang_info = bsearch (lang_str, lang_texts,
- G_N_ELEMENTS (lang_texts), sizeof (LangInfo),
- lang_info_compare);
-
- if (lang_info)
- {
- lookup_lang = pango_language_from_string (lang_info->lang);
- str = lang_info->str;
- }
- else
- {
- lookup_lang = pango_language_from_string ("UNKNOWN");
- str = "French (Français)"; /* Assume iso-8859-1 */
- }
- }
- else
- {
- lookup_lang = pango_language_from_string ("NONE");
-
- /* Complete junk
- */
- str = "ا,DXXم عY(JY,CY č(Besky $(GN;ληνικά (BFrançais 日語 한글 Р,CQкий 中文(B,$(1.i话(B,(Ih (BTürkçe";
- }
+ const char *sample_str = pango_language_get_sample_string (language);
tmp_list = ft2font->metrics_by_lang;
while (tmp_list)
{
info = tmp_list->data;
- if (info->language == lookup_lang) /* We _don't_ need strcmp */
+ if (info->sample_str == sample_str) /* We _don't_ need strcmp */
break;
tmp_list = tmp_list->next;
@@ -722,11 +647,11 @@ pango_ft2_font_get_metrics (PangoFont *font,
if (!tmp_list)
{
info = g_new (PangoFT2MetricsInfo, 1);
- info->language = lookup_lang;
+ info->sample_str = sample_str;
ft2font->metrics_by_lang = g_slist_prepend (ft2font->metrics_by_lang, info);
- get_font_metrics_from_string (font, language, str, &info->metrics);
+ get_font_metrics_from_string (font, language, sample_str, &info->metrics);
}
*metrics = info->metrics;
diff --git a/pango/pangowin32.c b/pango/pangowin32.c
index cd6c8388..b7b885d4 100644
--- a/pango/pangowin32.c
+++ b/pango/pangowin32.c
@@ -753,51 +753,6 @@ get_font_metrics_from_string (PangoFont *font,
g_free (embedding_levels);
}
-typedef struct {
- const char *lang;
- const char *str;
-} LangInfo;
-
-int
-lang_info_compare (const void *key, const void *val)
-{
- const LangInfo *lang_info = val;
-
- return strncmp (key, lang_info->lang, 2);
-}
-
-/* The following array is supposed to contain enough text to tickle all necessary fonts for each
- * of the languages in the following. Yes, it's pretty lame. Not all of the languages
- * in the following have sufficient text to excercise all the accents for the language, and
- * there are obviously many more languages to include as well.
- */
-LangInfo lang_texts[] = {
- { "ar", "Arabic السلام عليكم" },
- { "cs", "Czech (česky) Dobrý den" },
- { "da", "Danish (Dansk) Hej, Goddag" },
- { "el", "Greek (Ελληνικά) Γειά σας" },
- { "en", "English Hello" },
- { "eo", "Esperanto Saluton" },
- { "es", "Spanish (Español) ¡Hola!" },
- { "et", "Estonian Tere, Tervist" },
- { "fi", "Finnish (Suomi) Hei, Hyvää päivää" },
- { "fr", "French (Français)" },
- { "de", "German Grüß Gott" },
- { "iw", "Hebrew שלום" },
- { "il", "Italiano Ciao, Buon giorno" },
- { "ja", "Japanese (日本語) こんにちは, コンニチハ" },
- { "ko", "Korean (한글) 안녕하세요, 안녕하십니까" },
- { "mt", "Maltese Ċaw, Saħħa" },
- { "nl", "Nederlands, Vlaams Hallo, Dag" },
- { "no", "Norwegian (Norsk) Hei, God dag" },
- { "pl", "Polish Dzień dobry, Hej" },
- { "ru", "Russian (Русский)" },
- { "sk", "Slovak Dobrý deň" },
- { "sv", "Swedish (Svenska) Hej på dej" },
- { "tr", "Turkish (Türkçe) Merhaba" },
- { "zh", "Chinese (中文,普通话,汉语)" }
-};
-
static void
pango_win32_font_get_metrics (PangoFont *font,
PangoLanguage *lang,
@@ -807,42 +762,14 @@ pango_win32_font_get_metrics (PangoFont *font,
PangoWin32Font *win32font = (PangoWin32Font *)font;
GSList *tmp_list;
- const char *lang_str = pango_language_to_string (lang);
- PangoLanguage *lookup_lang;
- const char *str;
+ const char *sample_str = pango_language_get_sample_string (language);
- if (lang)
- {
- LangInfo *lang_info = bsearch (lang_str, lang_texts,
- G_N_ELEMENTS (lang_texts), sizeof (LangInfo),
- lang_info_compare);
-
- if (lang_info)
- {
- lookup_lang = pango_language_from_string (lang_info->lang);
- str = lang_info->str;
- }
- else
- {
- lookup_lang = pango_language_to_string ("UNKNOWN");
- str = "French (Français)"; /* Assume iso-8859-1 */
- }
- }
- else
- {
- lookup_lang = pango_language_to_string ("NONE");
-
- /* Complete junk
- */
- str = "السلام عليكم česky Ελληνικά Français 日本語 한글 Русский 中文,普通话,汉语 Türkçe";
- }
-
tmp_list = win32font->metrics_by_lang;
while (tmp_list)
{
info = tmp_list->data;
- if (info->lang == lookup_lang) /* We _don't_ need strcmp */
+ if (info->sample_str == sample_str) /* We _don't_ need strcmp */
break;
tmp_list = tmp_list->next;
@@ -857,11 +784,11 @@ pango_win32_font_get_metrics (PangoFont *font,
win32font->metrics_by_lang = g_slist_prepend (win32font->metrics_by_lang, info);
info = g_new (PangoWin32MetricsInfo, 1);
- info->lang = lookup_lang;
+ info->sample_str = sample_str;
win32font->metrics_by_lang = g_slist_prepend (win32font->metrics_by_lang, info);
- get_font_metrics_from_string (font, lang, str, &info->metrics);
+ get_font_metrics_from_string (font, lang, sample_str, &info->metrics);
/* lovely copy&paste programming (from pangox.c) */
/* This is sort of a sledgehammer solution, but we cache this
@@ -869,7 +796,7 @@ pango_win32_font_get_metrics (PangoFont *font,
* chars in "0123456789"
*/
context = pango_win32_get_context ();
- pango_context_set_language (context, lookup_lang);
+ pango_context_set_language (context, lang);
layout = pango_layout_new (context);
pango_layout_set_text (layout, "0123456789", -1);
diff --git a/pango/pangox.c b/pango/pangox.c
index f7741d38..d4bb469f 100644
--- a/pango/pangox.c
+++ b/pango/pangox.c
@@ -116,7 +116,7 @@ struct _PangoXSubfontInfo
struct _PangoXMetricsInfo
{
- PangoLanguage *language;
+ const char *sample_str;
PangoFontMetrics metrics;
};
@@ -855,51 +855,6 @@ get_font_metrics_from_string (PangoFont *font,
g_free (embedding_levels);
}
-typedef struct {
- const char *lang;
- const char *str;
-} LangInfo;
-
-int
-lang_info_compare (const void *key, const void *val)
-{
- const LangInfo *lang_info = val;
-
- return strncmp (key, lang_info->lang, 2);
-}
-
-/* The following array is supposed to contain enough text to tickle all necessary fonts for each
- * of the languages in the following. Yes, it's pretty lame. Not all of the languages
- * in the following have sufficient text to excercise all the accents for the language, and
- * there are obviously many more languages to include as well.
- */
-LangInfo lang_texts[] = {
- { "ar", "Arabic السلام عليكم" },
- { "cs", "Czech (česky) Dobrý den" },
- { "da", "Danish (Dansk) Hej, Goddag" },
- { "el", "Greek (Ελληνικά) Γειά σας" },
- { "en", "English Hello" },
- { "eo", "Esperanto Saluton" },
- { "es", "Spanish (Español) ¡Hola!" },
- { "et", "Estonian Tere, Tervist" },
- { "fi", "Finnish (Suomi) Hei, Hyvää päivää" },
- { "fr", "French (Français)" },
- { "de", "German Grüß Gott" },
- { "iw", "Hebrew שלום" },
- { "il", "Italiano Ciao, Buon giorno" },
- { "ja", "Japanese (日本語) こんにちは, コンニチハ" },
- { "ko", "Korean (한글) 안녕하세요, 안녕하십니까" },
- { "mt", "Maltese Ċaw, Saħħa" },
- { "nl", "Nederlands, Vlaams Hallo, Dag" },
- { "no", "Norwegian (Norsk) Hei, God dag" },
- { "pl", "Polish Dzień dobry, Hej" },
- { "ru", "Russian (Русский)" },
- { "sk", "Slovak Dobrý deň" },
- { "sv", "Swedish (Svenska) Hej på dej, Goddag" },
- { "tr", "Turkish (Türkçe) Merhaba" },
- { "zh", "Chinese (中文,普通话,汉语)" }
-};
-
static void
pango_x_font_get_metrics (PangoFont *font,
PangoLanguage *language,
@@ -908,43 +863,15 @@ pango_x_font_get_metrics (PangoFont *font,
PangoXMetricsInfo *info = NULL; /* Quiet gcc */
PangoXFont *xfont = (PangoXFont *)font;
GSList *tmp_list;
- const char *lang_str = pango_language_to_string (language);
- PangoLanguage *lookup_lang;
- const char *str;
-
- if (language)
- {
- LangInfo *lang_info = bsearch (lang_str, lang_texts,
- G_N_ELEMENTS (lang_texts), sizeof (LangInfo),
- lang_info_compare);
-
- if (lang_info)
- {
- lookup_lang = pango_language_from_string (lang_info->lang);
- str = lang_info->str;
- }
- else
- {
- lookup_lang = pango_language_from_string ("UNKNOWN");
- str = "French (Français)"; /* Assume iso-8859-1 */
- }
- }
- else
- {
- lookup_lang = pango_language_from_string ("NONE");
-
- /* Complete junk
- */
- str = "السلام عليكم česky Ελληνικά Français 日本語 한글 Русский 中文,普通话,汉语 Türkçe";
- }
+ const char *sample_str = pango_language_get_sample_string (language);
tmp_list = xfont->metrics_by_lang;
while (tmp_list)
{
info = tmp_list->data;
- if (info->language == lookup_lang) /* We _don't_ need strcmp */
+ if (info->sample_str == sample_str) /* We _don't_ need strcmp */
break;
tmp_list = tmp_list->next;
@@ -957,18 +884,18 @@ pango_x_font_get_metrics (PangoFont *font,
PangoContext *context;
info = g_new (PangoXMetricsInfo, 1);
- info->language = lookup_lang;
+ info->sample_str = sample_str;
xfont->metrics_by_lang = g_slist_prepend (xfont->metrics_by_lang, info);
- get_font_metrics_from_string (font, lookup_lang, str, &info->metrics);
+ get_font_metrics_from_string (font, language, sample_str, &info->metrics);
/* This is sort of a sledgehammer solution, but we cache this
* stuff so not a huge deal hopefully. Get the avg. width of the
* chars in "0123456789"
*/
context = pango_x_get_context (pango_x_fontmap_get_display (xfont->fontmap));
- pango_context_set_language (context, lookup_lang);
+ pango_context_set_language (context, language);
layout = pango_layout_new (context);
pango_layout_set_text (layout, "0123456789", -1);