From 71632c96daa4ba15e13f4d9e7f2c121d0162614e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 22 Jan 2012 15:31:44 -0500 Subject: [PATCH] Fallback to Latin script if the font has no other usable scripts Patch and description from Jonathan Kew: It turns out that some legacy Thai fonts provide OpenType substitution features to implement mark positioning, but (incorrectly) put those features/lookups under the 'latn' script tag instead of using 'thai' (or possibly 'DFLT'). See https://bugzilla.mozilla.org/show_bug.cgi?id=719366 for an example and more detailed description. Although this is really a font bug, I suggest that we could improve the rendering of such fonts by looking for the 'latn' as a fallback if neither the requested script nor "default" is found in hb_ot_layout_table_choose_script. Suggested patch against harfbuzz master is attached. This does _not_ affect the other kind of legacy Thai font, where custom code to support vendor-specific PUA codepoints would be needed. I'm not keen to go down that path; IMO, such fonts should be ruthlessly stamped out in favour of standards-based solutions. :) JK --- src/hb-ot-layout.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index adf103f78..f3e07139a 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -281,6 +281,15 @@ hb_ot_layout_table_choose_script (hb_face_t *face, return FALSE; } + /* try with 'latn'; some old fonts put their features there even though + they're really trying to support Thai, for example :( */ +#define HB_OT_TAG_LATIN_SCRIPT HB_TAG ('l', 'a', 't', 'n') + if (g.find_script_index (HB_OT_TAG_LATIN_SCRIPT, script_index)) { + if (chosen_script) + *chosen_script = HB_OT_TAG_LATIN_SCRIPT; + return FALSE; + } + if (script_index) *script_index = HB_OT_LAYOUT_NO_SCRIPT_INDEX; if (chosen_script) *chosen_script = HB_OT_LAYOUT_NO_SCRIPT_INDEX;