Mike FABIAN
2005-Nov-21 08:51 UTC
[Fontconfig] Patch to improve support for localized font family and style names
Reply-to: mfabian@suse.de X-Face: "'';oPz9V1+<,`}1ZuxRv~EiSusWq*{Yjr"Sdvbhq''?q=2R\\6Y9O/,SAE`{J|6I=|w/sQg< rW_N''E3IV6~f8?\l#Es`]S`mv'',PY(`8{$$R?+gLu}Qv/Mn>)?uladFjJ@yl!_p_Jh;5QxlD6zL:?r IXe4FfK$C^mWhh$o`yt;.r.FLZLQOWBt><!;-.DYZ)Nu&1?~*:\36\BGz]"L;nue;l\%sJ/]l{is5O Ew?0CF}dPS(ezG0xqUR)xa(L&&c;x{By"`oKvM&i!%+ From: Mike FABIAN <mfabian@suse.de> Date: Wed, 19 Oct 2005 16:12:05 +0200 Message-ID: <s3ty84p4mve.fsf@magellan.suse.de> User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.5 (cucumber, linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" --text follows this line-- --=-=- Here is a patch by Zhe Su <zsu@novell.com> to improve support for localized font family and style names. For details see: http://bugzilla.novell.com/show_bug.cgi?id=128930 --=-=-Content-Type: text/x-patch Content-Disposition: inline; filename=bugzilla-128930-support-localized-family-and-style-names.patch diff -ur fontconfig-2.3.91.20051007.old/src/fcdefault.c fontconfig-2.3.91.20051007/src/fcdefault.c --- fontconfig-2.3.91.20051007.old/src/fcdefault.c 2005-10-17 22:40:43.000000000 +0800 +++ fontconfig-2.3.91.20051007/src/fcdefault.c 2005-10-17 23:24:44.000000000 +0800 @@ -38,6 +38,67 @@ #define NUM_FC_BOOL_DEFAULTS (int) (sizeof FcBoolDefaults / sizeof FcBoolDefaults[0]) +FcChar8 * +FcGetDefaultLang (void) +{ + static char lang_local [128] = {0}; + char *ctype; + char *territory; + char *after; + int lang_len, territory_len; + + if (lang_local [0]) + return (FcChar8 *) lang_local; + + ctype = setlocale (LC_CTYPE, NULL); + + /* + * Check if setlocale (LC_ALL, "") has been called + */ + if (!ctype || !strcmp (ctype, "C")) + { + ctype = getenv ("LC_ALL"); + if (!ctype) + { + ctype = getenv ("LC_CTYPE"); + if (!ctype) + ctype = getenv ("LANG"); + } + } + + /* ignore missing or empty ctype */ + if (ctype && *ctype != ''\0'') + { + territory = strchr (ctype, ''_''); + if (territory) + { + lang_len = territory - ctype; + territory = territory + 1; + after = strchr (territory, ''.''); + if (!after) + { + after = strchr (territory, ''@''); + if (!after) + after = territory + strlen (territory); + } + territory_len = after - territory; + if (lang_len + 1 + territory_len + 1 <= (int) sizeof (lang_local)) + { + strncpy (lang_local, ctype, lang_len); + lang_local[lang_len] = ''-''; + strncpy (lang_local + lang_len + 1, territory, territory_len); + lang_local[lang_len + 1 + territory_len] = ''\0''; + } + } + } + + /* set default lang to en */ + if (!lang_local [0]) + strcpy (lang_local, "en"); + + return (FcChar8 *) lang_local; +} + void FcDefaultSubstitute (FcPattern *pattern) { @@ -92,55 +153,7 @@ if (FcPatternGet (pattern, FC_LANG, 0, &v) == FcResultNoMatch) { - char *lang; - char *territory; - char *after; - int lang_len, territory_len; - char lang_local[128]; - char *ctype = setlocale (LC_CTYPE, NULL); - - /* - * Check if setlocale (LC_ALL, "") has been called - */ - if (!ctype || !strcmp (ctype, "C")) - { - ctype = getenv ("LC_ALL"); - if (!ctype) - { - ctype = getenv ("LC_CTYPE"); - if (!ctype) - ctype = getenv ("LANG"); - } - } - /* ignore missing or empty ctype */ - if (ctype && *ctype != ''\0'') - { - lang = ctype; - territory = strchr (ctype, ''_''); - if (territory) - { - lang_len = territory - lang; - territory = territory + 1; - after = strchr (territory, ''.''); - if (!after) - { - after = strchr (territory, ''@''); - if (!after) - after = territory + strlen (territory); - } - territory_len = after - territory; - if (lang_len + 1 + territory_len + 1 <= (int) sizeof (lang_local)) - { - strncpy (lang_local, lang, lang_len); - lang_local[lang_len] = ''-''; - strncpy (lang_local + lang_len + 1, territory, territory_len); - lang_local[lang_len + 1 + territory_len] = ''\0''; - FcPatternAddString (pattern, FC_LANG, (FcChar8 *) lang_local); - } - } - else - FcPatternAddString (pattern, FC_LANG, (FcChar8 *) lang); - } + FcPatternAddString (pattern, FC_LANG, FcGetDefaultLang ()); } if (FcPatternGet (pattern, FC_FONTVERSION, 0, &v) == FcResultNoMatch) { diff -ur fontconfig-2.3.91.20051007.old/src/fcint.h fontconfig-2.3.91.20051007/src/fcint.h --- fontconfig-2.3.91.20051007.old/src/fcint.h 2005-10-07 19:00:55.000000000 +0800 +++ fontconfig-2.3.91.20051007/src/fcint.h 2005-10-18 09:57:14.000000000 +0800 @@ -571,6 +571,10 @@ int FcDebug (void); +/* fcdefault.c */ +FcChar8 * +FcGetDefaultLang (void); + /* fcdir.c */ FcBool diff -ur fontconfig-2.3.91.20051007.old/src/fclist.c fontconfig-2.3.91.20051007/src/fclist.c --- fontconfig-2.3.91.20051007.old/src/fclist.c 2005-10-07 19:00:55.000000000 +0800 +++ fontconfig-2.3.91.20051007/src/fclist.c 2005-10-18 12:43:54.000000000 +0800 @@ -337,6 +337,37 @@ table->entries = 0; } +static int +FcGetDefaultObjectLangIndex (FcPattern *font, const char *object) +{ + FcChar8 *lang = FcGetDefaultLang (); + FcPatternElt *e = FcPatternFindElt (font, object); + FcValueListPtr v; + FcValue value; + int idx = -1; + int i; + int langlen = strlen (lang); + + if (e) + { + for (v = e->values, i = 0; FcValueListPtrU(v); v = FcValueListPtrU(v)->next, ++i) + { + value = FcValueCanonicalize (&FcValueListPtrU (v)->value); + + if ((value.type & ~FC_STORAGE_STATIC) == FcTypeString) + { + FcLangResult res = FcLangCompare (value.u.s, lang); + if (res == FcLangEqual) + idx = i; + else if (res == FcLangDifferentCountry && strlen (value.u.s) < langlen && idx < 0) + idx = i; + } + } + } + + return (idx > 0) ? idx : 0; +} + static FcBool FcListAppend (FcListHashTable *table, FcPattern *font, @@ -347,6 +378,11 @@ FcValueListPtr v; FcChar32 hash; FcListBucket **prev, *bucket; + int familyidx = -1; + int fullnameidx = -1; + int styleidx = -1; + int defidx = 0; + int idx; hash = FcListPatternHash (font, os); for (prev = &table->buckets[hash % FC_LIST_HASH_SIZE]; @@ -368,15 +404,36 @@ for (o = 0; o < os->nobject; o++) { + if (!strcmp (os->objects[o], FC_FAMILY) || !strcmp (os->objects[o], FC_FAMILYLANG)) + { + if (familyidx < 0) + familyidx = FcGetDefaultObjectLangIndex (font, FC_FAMILYLANG); + defidx = familyidx; + } + else if (!strcmp (os->objects[o], FC_FULLNAME) || !strcmp (os->objects[o], FC_FULLNAMELANG)) + { + if (fullnameidx < 0) + fullnameidx = FcGetDefaultObjectLangIndex (font, FC_FULLNAMELANG); + defidx = fullnameidx; + } + else if (!strcmp (os->objects[o], FC_STYLE) || !strcmp (os->objects[o], FC_STYLELANG)) + { + if (styleidx < 0) + styleidx = FcGetDefaultObjectLangIndex (font, FC_STYLELANG); + defidx = styleidx; + } + else + defidx = 0; + e = FcPatternFindElt (font, os->objects[o]); if (e) { - for (v = e->values; FcValueListPtrU(v); - v = FcValueListPtrU(v)->next) + for (v = e->values, idx = 0; FcValueListPtrU(v); + v = FcValueListPtrU(v)->next, ++idx) { if (!FcPatternAdd (bucket->pattern, os->objects[o], - FcValueCanonicalize(&FcValueListPtrU(v)->value), FcTrue)) + FcValueCanonicalize(&FcValueListPtrU(v)->value), defidx != idx)) goto bail2; } } --=-=-Content-Type: text/plain; charset=iso-2022-jp -- Mike FABIAN <mfabian@suse.de> http://www.suse.de/~mfabian $B?gL2ITB-$O$$$$;E;v$NE($@!#(B --=-=-=--
Mike FABIAN
2005-Nov-21 08:51 UTC
[Fontconfig] Re: Patch to improve support for localized font family and style names
Keith Packard <keithp@keithp.com> ????????:> On Wed, 2005-10-19 at 16:12 +0200, Mike FABIAN wrote: > >> Here is a patch by Zhe Su <zsu@novell.com> to improve support >> for localized font family and style names. > > I didn''t do this initially because of my concern that applications won''t > correctly display non-ASCII font names. If Qt, Gtk+ and Mozilla all > manage nicely, then I''d say it''s time to switch to this behaviour.Most applications seem to work fine. Some legacy applications like "xfd" don''t. -- Mike FABIAN <mfabian@suse.de> http://www.suse.de/~mfabian ?????????????
Keith Packard
2005-Nov-21 08:51 UTC
[Fontconfig] Patch to improve support for localized font family and style names
On Wed, 2005-10-19 at 16:12 +0200, Mike FABIAN wrote:> Here is a patch by Zhe Su <zsu@novell.com> to improve support > for localized font family and style names.I didn''t do this initially because of my concern that applications won''t correctly display non-ASCII font names. If Qt, Gtk+ and Mozilla all manage nicely, then I''d say it''s time to switch to this behaviour. -keith -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://lists.freedesktop.org/archives/fontconfig/attachments/20051019/849c4b21/attachment.pgp
sunmoon1997
2005-Nov-21 08:51 UTC
[Fontconfig] Re: Patch to improve support for localized font family and style names
I can comfirm qt/gtk+ apps work fine and the recently vesion of mozilla/firefox works fine too. Keith Packard wrote:> On Wed, 2005-10-19 at 16:12 +0200, Mike FABIAN wrote: > > >>Here is a patch by Zhe Su <zsu@novell.com> to improve support >>for localized font family and style names. > > > I didn''t do this initially because of my concern that applications won''t > correctly display non-ASCII font names. If Qt, Gtk+ and Mozilla all > manage nicely, then I''d say it''s time to switch to this behaviour. > > -keith > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Fontconfig mailing list > Fontconfig@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/fontconfig
Mike FABIAN
2005-Nov-21 08:51 UTC
[Fontconfig] Re: Patch to improve support for localized font family and style names
Mike FABIAN <mfabian@suse.de> ????????:> Keith Packard <keithp@keithp.com> ????????: > >> On Wed, 2005-10-19 at 16:12 +0200, Mike FABIAN wrote: >> >>> Here is a patch by Zhe Su <zsu@novell.com> to improve support >>> for localized font family and style names.Zhe Su has updated his patch a little bit (new patch attached) because of the problem mentioned in comment #8 of http://bugzilla.novell.com/show_bug.cgi?id=128930> Comment #8 From Mike Fabian 2005-10-19 07:46 MST > [ ] Private > > Without the patch: > > mfabian@magellan:/var/tmp/abuild/x86_64$ LANG=zh_CN.UTF-8 fc-list : | grep -i > FZ > FZHeiTi,????:style=Regular > FZFangSong,????:style=Regular > FZKaiTi,????:style=Regular > FZSongTi,????:style=Regular > FZKaiTiB,????:style=Regular > FZMingTiB,????:style=Regular > mfabian@magellan:~$ > > With the patch: > > mfabian@magellan:~$ LANG=zh_CN.UTF-8 fc-list : | grep -i FZ > ????,FZHeiTi:style=Regular > ????,FZFangSong:style=Regular > ????,FZKaiTi:style=Regular > ????,FZSongTi:style=Regular > FZKaiTiB,????:style=Regular > FZMingTiB,????:style=Regular > mfabian@magellan:~$ > > I.e. when the locale is simplified Chinese, the traditional Chinese > font names will still be displayed in the ASCII versions. > > That''s funny, but probably OK, isn''t it?With Zhe Su''s new patch, the localized font names for traditional Chinese are also shown in simplified Chinese locales and vice versa. -------------- next part -------------- A non-text attachment was scrubbed... Name: bugzilla-128930-support-localized-family-and-style-names.patch Type: text/x-patch Size: 6481 bytes Desc: not available Url : http://lists.freedesktop.org/archives/fontconfig/attachments/20051020/64f71752/bugzilla-128930-support-localized-family-and-style-names.bin -------------- next part -------------- -- Mike FABIAN <mfabian@suse.de> http://www.suse.de/~mfabian ?????????????
Patrick Lam
2005-Nov-21 08:51 UTC
[Fontconfig] Re: Patch to improve support for localized font family and style names
Mike FABIAN wrote:> With Zhe Su''s new patch, the localized font names for traditional > Chinese are also shown in simplified Chinese locales and vice versa.Ill commit that patch as soon as cvs.freedesktop.org is no longer broken. Of course, that also might mean that the mailing list might be broken too... pat
sunmoon1997
2005-Nov-21 08:51 UTC
[Fontconfig] Re: Patch to improve support for localized font family and style names
Openoffice doesn''t work at non-utf8 locale, patch attached. Mike FABIAN wrote:> Patrick Lam <plam@MIT.EDU> ????????: > > >>Mike FABIAN wrote: >> >>>With Zhe Su''s new patch, the localized font names for traditional >>>Chinese are also shown in simplified Chinese locales and vice versa. >> >>Ill commit that patch as soon as cvs.freedesktop.org is no longer >>broken. Of course, that also might mean that the mailing list might be >>broken too... > > > Thank you. > > cvs.freedesktop.org appears to work OK today and I have updated the > SuSE packages for fontconfig to the latest CVS snapshot of the > fontconfig 1.4 branch. > > Packages for SuSE Linux 10.0 are in > > ftp://ftp.suse.com/pub/projects/m17n/10.0 >-------------- next part -------------- --- psprint/source/fontmanager/fontconfig.cxx.orig 2005-10-22 14:16:22.000000000 +0800 +++ psprint/source/fontmanager/fontconfig.cxx 2005-10-22 14:17:47.000000000 +0800 @@ -400,7 +400,7 @@ bool PrintFontManager::initFontconfig() if( aFonts.empty() ) continue; - int nFamilyName = m_pAtoms->getAtom( ATOM_FAMILYNAME, OStringToOUString( OString( (sal_Char*)family ), osl_getThreadTextEncoding() ), sal_True ); + int nFamilyName = m_pAtoms->getAtom( ATOM_FAMILYNAME, OStringToOUString( OString( (sal_Char*)family ), RTL_TEXTENCODING_UTF8 ), sal_True ); PrintFont* pUpdate = aFonts.front(); if( ++aFonts.begin() != aFonts.end() ) // more than one font {
Mike FABIAN
2005-Nov-21 08:51 UTC
[Fontconfig] Re: Patch to improve support for localized font family and style names
Patrick Lam <plam@MIT.EDU> ????????:> Mike FABIAN wrote: >> With Zhe Su''s new patch, the localized font names for traditional >> Chinese are also shown in simplified Chinese locales and vice versa. > > Ill commit that patch as soon as cvs.freedesktop.org is no longer > broken. Of course, that also might mean that the mailing list might be > broken too...Thank you. cvs.freedesktop.org appears to work OK today and I have updated the SuSE packages for fontconfig to the latest CVS snapshot of the fontconfig 1.4 branch. Packages for SuSE Linux 10.0 are in ftp://ftp.suse.com/pub/projects/m17n/10.0 -- Mike FABIAN <mfabian@suse.de> http://www.suse.de/~mfabian ?????????????