After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 154955 - Using different latin fonts in different locales
Using different latin fonts in different locales
Status: RESOLVED NOTGNOME
Product: pango
Classification: Platform
Component: general
1.4.x
Other Linux
: Normal normal
: Medium fix
Assigned To: pango-maint
pango-maint
Depends on:
Blocks:
 
 
Reported: 2004-10-09 04:27 UTC by federic zhang
Modified: 2006-07-08 03:27 UTC
See Also:
GNOME target: ---
GNOME version: 2.5/2.6


Attachments
it's the patch (4.67 KB, patch)
2004-10-09 04:29 UTC, federic zhang
none Details | Review
the correct one (4.69 KB, patch)
2004-10-09 04:39 UTC, federic zhang
rejected Details | Review

Description federic zhang 2004-10-09 04:27:47 UTC
See also http://bugzilla.gnome.org/show_bug.cgi?id=149438

Due to the matrix issue between multi-byte characters in CJK font and ASCII in
latin font, in some case user wants to config fonts.conf in following way to use
CJK font to render both ASCII and multi-byte characters in CJK locale.

<match target="pattern">
        <test name="family">
                <string>monospace</string>
        </test>
        <test name="lang" compare="contains">
                <string>ja</string>
        </test>
        <edit name="disable_pango_script">
                <bool>true</bool>
        </edit>
</match>

To enable the functionality, pango has to be patched.
Comment 1 federic zhang 2004-10-09 04:29:43 UTC
Created attachment 32419 [details] [review]
it's the patch
Comment 2 federic zhang 2004-10-09 04:34:32 UTC
Comment on attachment 32419 [details] [review]
it's the patch

>diff -urN pango-1.4.1.orig/pango/fonts.c pango-1.4.1/pango/fonts.c
>--- pango-1.4.1.orig/pango/fonts.c	2004-09-24 07:51:43.000000000 +0000
>+++ pango-1.4.1/pango/fonts.c	2004-09-27 07:36:09.000000000 +0000
>@@ -1137,6 +1137,14 @@
>   return PANGO_FONT_GET_CLASS (font)->get_metrics (font, language);
> }
> 
>+gboolean
>+pango_font_disable_script (PangoFont *font)
>+{
>+  g_return_val_if_fail (font != NULL, NULL);
>+
>+  return PANGO_FONT_GET_CLASS (font)->disable_script (font);
>+}
>+
> GType
> pango_font_metrics_get_type (void)
> {
>diff -urN pango-1.4.1.orig/pango/pango-context.c pango-1.4.1/pango/pango-context.c
>--- pango-1.4.1.orig/pango/pango-context.c	2004-09-24 07:51:43.000000000 +0000
>+++ pango-1.4.1/pango/pango-context.c	2004-10-09 03:01:44.000000000 +0000
>@@ -501,6 +501,7 @@
>   const char *attr_end;
>   PangoFontDescription *font_desc;
>   PangoLanguage *lang;
>+  gboolean disable_pango_script;
>   GSList *extra_attrs;
>   gboolean copy_extra_attrs;
> 
>@@ -603,6 +604,7 @@
> {
>   gunichar *text_ucs4;
>   long n_chars;
>+  PangoFont *tmp_font = NULL;
> 
>   state->context = context;
>   state->text = text;
>@@ -658,8 +660,14 @@
>   state->current_fonts = NULL;
>   state->cache = NULL;
>   state->exact_engines = NULL;
>-  state->fallback_engines = NULL;
>   state->base_font = NULL;
>+  state->fallback_engines = NULL;
>+
>+  tmp_font = pango_font_map_load_font (state->context->font_map,
>+                                       state->context,
>+                                       state->font_desc);
>+  state->disable_pango_script = pango_font_disable_script (tmp_font);
>+  if (tmp_font) g_object_unref (tmp_font);
>   
>   state->changed = EMBEDDING_CHANGED | SCRIPT_CHANGED | LANG_CHANGED | FONT_CHANGED;
> }
>@@ -959,7 +967,10 @@
>   if (state->changed & (SCRIPT_CHANGED | LANG_CHANGED))
>     {
>       PangoLanguage *old_derived_lang = state->derived_lang;
>-      state->derived_lang = compute_derived_language (state->lang, state->script);
>+      if (state->disable_pango_script && state->lang)
>+         state->derived_lang = state->lang;
>+      else
>+         state->derived_lang = compute_derived_language (state->lang, state->script);
>       if (old_derived_lang != state->derived_lang)
> 	state->changed |= DERIVED_LANG_CHANGED;
>     }
>diff -urN pango-1.4.1.orig/pango/pangofc-font.c pango-1.4.1/pango/pangofc-font.c
>--- pango-1.4.1.orig/pango/pangofc-font.c	2004-09-24 07:51:43.000000000 +0000
>+++ pango-1.4.1/pango/pangofc-font.c	2004-09-27 07:38:15.000000000 +0000
>@@ -57,6 +57,7 @@
> 							 guint32           ch);
> static PangoCoverage *       pango_fc_font_get_coverage (PangoFont        *font,
> 							 PangoLanguage    *language);
>+static gboolean              pango_fc_font_disable_script (PangoFont      *font);
> static PangoFontMetrics *    pango_fc_font_get_metrics  (PangoFont        *font,
> 							 PangoLanguage    *language);
> static PangoFontDescription *pango_fc_font_describe     (PangoFont        *font);
>@@ -105,6 +106,7 @@
>   font_class->describe = pango_fc_font_describe;
>   font_class->find_shaper = pango_fc_font_find_shaper;
>   font_class->get_coverage = pango_fc_font_get_coverage;
>+  font_class->disable_script = pango_fc_font_disable_script;
>   font_class->get_metrics = pango_fc_font_get_metrics;
>   
>   g_object_class_install_property (object_class, PROP_PATTERN,
>@@ -209,6 +211,18 @@
> 					  fcfont->font_pattern);
> }
> 
>+static gboolean
>+pango_fc_font_disable_script (PangoFont *font)
>+{
>+  gboolean disable_script = FALSE;
>+  PangoFcFont *fcfont = (PangoFcFont *)font;
>+
>+  if (FcPatternGetBool (fcfont->font_pattern, "disable_script", 0, &disable_script) != FcResultMatch)
>+    disable_script = FALSE;
>+
>+    return disable_script;
>+}
>+
> /* For Xft, it would be slightly more efficient to simply to
>  * call Xft, and also more robust against changes in Xft.
>  * But for now, we simply use the same code for all backends.
>diff -urN pango-1.4.1.orig/pango/pango-font.h pango-1.4.1/pango/pango-font.h
>--- pango-1.4.1.orig/pango/pango-font.h	2004-09-24 07:51:43.000000000 +0000
>+++ pango-1.4.1/pango/pango-font.h	2004-09-27 07:37:06.000000000 +0000
>@@ -299,6 +299,7 @@
> 						    guint32           ch);
> PangoFontMetrics *    pango_font_get_metrics       (PangoFont        *font,
> 						    PangoLanguage    *language);
>+gboolean              pango_font_disable_script    (PangoFont         *font);
> void                  pango_font_get_glyph_extents (PangoFont        *font,
> 						    PangoGlyph        glyph,
> 						    PangoRectangle   *ink_rect,
>@@ -335,6 +336,7 @@
> 					       PangoRectangle *logical_rect);
>   PangoFontMetrics *    (*get_metrics)        (PangoFont      *font,
> 					       PangoLanguage  *language);
>+  gboolean              (*disable_script)     (PangoFont      *font);
>   /*< private >*/
> 
>   /* Padding for future expansion */
Comment 3 federic zhang 2004-10-09 04:39:26 UTC
Created attachment 32420 [details] [review]
the correct one
Comment 4 federic zhang 2004-10-09 04:40:39 UTC
Sorry, wrong action is made, please ignore the above comment. Typo exists in the
first patch, the 'disable_script' variable in pango_fc_font_disable_script
should be replaced with 'disable_pango_script'.
Comment 5 Owen Taylor 2004-12-16 03:37:38 UTC
I don't really think fonts.conf is the right place for this type
of configuration; what you are objecting is the language tag passes
to fontconfig.

Possible directions here:

 - Simply back out language tag refinement entirely. fontconfig-2.3 is going
   to do a better job of selecting fonts, so it will be much less
   necessary. 

 - Figure out how to do actual per-locale font preferences at the
   fontconfig level. The fact that you can order Sans as 
   "English, Arabic, Chinese, Japanese" is counting on the fact the
   fonts are mutually exclusive. If your English font has crappy Japanese
   and your Japanese font crappy English it's not going to work.

I'm inclined to the first, though it might require somet thinking about
how to hide bad glyphs in a font for configurations where you want to
always, say, use Latin glyphs from the preferrred latin font.
Comment 6 federic zhang 2004-12-16 04:10:41 UTC
IMHO, the language tag refinement is good enough, we just need to tweak it a bit
for some special requirement.

You are right, the fonts are mutually exclusive, it is the *fact*. Suppose we
have one Unicode font that includes all scripts, of course it wouldn't work, but
i will have concern on its quality if it does exist. I believe the linux distro
wouldn't bundle it, so their default setting would be ok for naive user. Another
solution is to make them mutually exclusive in fontconfig, which makes CJK font
exclusive according to their code page information in OS/2 table. In this case,
for the English font that has crappy Japanese, the 'ja' tag wouldn't be
contained in its lang set.

Agreed it would be best solution if fontconfig can provide better font selection
algorithm that Qt/Pango can leverage directly.
Comment 7 Behdad Esfahbod 2006-07-08 03:27:05 UTC
Closing, as there's nothing to fix in pango here, and we already have a lot of other bugs about language tagging improvements.