[gnome-font-viewer] font-widget: do not hardcode unicode charmap
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-font-viewer] font-widget: do not hardcode unicode charmap
- Date: Fri, 5 Jul 2019 18:55:04 +0000 (UTC)
commit 00366e95d482b902fcb72728375dbb84e8beaba9
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Fri Jul 5 11:29:47 2019 -0700
font-widget: do not hardcode unicode charmap
Instead, select the first charmap that yields characters. This
allows us to increase compatibility with fonts that do not support
unicode, while keeping the complexity of the code under control.
https://bugzilla.gnome.org/show_bug.cgi?id=769247
src/sushi-font-widget.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/src/sushi-font-widget.c b/src/sushi-font-widget.c
index e0ba634..8b8e062 100644
--- a/src/sushi-font-widget.c
+++ b/src/sushi-font-widget.c
@@ -241,9 +241,6 @@ check_font_contain_text (FT_Face face,
gboolean retval = TRUE;
string = g_utf8_to_ucs4_fast (text, -1, &len);
-
- FT_Select_Charmap (face, FT_ENCODING_UNICODE);
-
for (idx = 0; idx < len; idx++) {
gunichar c = string[idx];
@@ -337,9 +334,32 @@ set_pango_sample_string (SushiFontWidget *self)
return retval;
}
+static void
+select_best_charmap (SushiFontWidget *self)
+{
+ gchar *chars;
+ gint idx, n_chars;
+
+ if (FT_Select_Charmap (self->face, FT_ENCODING_UNICODE) == 0)
+ return;
+
+ for (idx = 0; idx < self->face->num_charmaps; idx++) {
+ if (FT_Set_Charmap (self->face, self->face->charmaps[idx]) != 0)
+ continue;
+
+ chars = build_charlist_for_face (self->face, &n_chars);
+ g_free (chars);
+
+ if (n_chars > 0)
+ break;
+ }
+}
+
static void
build_strings_for_face (SushiFontWidget *self)
{
+ select_best_charmap (self);
+
/* if we don't have lowercase/uppercase/punctuation text in the face,
* we omit it directly, and render a random text below.
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]