From e294c69cbb9f0790df38c8340d30794128c2d59e Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Thu, 29 Oct 2020 08:17:43 +0000 Subject: [PATCH] Bug 1673510 - Improve text-orientation run itemization to better match harfbuzz heuristics for handling vertical alternates. r=lsalzman (test is in the following patch in the stack) Differential Revision: https://phabricator.services.mozilla.com/D94981 --- gfx/thebes/gfxTextRun.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gfx/thebes/gfxTextRun.cpp b/gfx/thebes/gfxTextRun.cpp index 7958ab3a6c06..e3301e65d3d4 100644 --- a/gfx/thebes/gfxTextRun.cpp +++ b/gfx/thebes/gfxTextRun.cpp @@ -3460,10 +3460,22 @@ void gfxFontGroup::ComputeRanges(nsTArray& aRanges, const T* aString, // 'vert' feature is going to handle this character, and if the // presentation form is available then it will be used as // fallback if needed, so it's OK if the feature is missing. + // + // Because "common" CJK punctuation characters in isolation will be + // resolved to Bopomofo script (as the first script listed in their + // ScriptExtensions property), but this is not always well supported + // by fonts' OpenType tables, we also try Han script; harfbuzz will + // apply a 'vert' feature from any available script (see + // https://github.com/harfbuzz/harfbuzz/issues/63) when shaping, + // so this is OK. It's not quite as general as what harfbuzz does + // (it will find the feature in *any* script), but should be enough + // for likely real-world examples. uint32_t v = gfxHarfBuzzShaper::GetVerticalPresentationForm(ch); + const uint32_t kVert = HB_TAG('v', 'e', 'r', 't'); orient = (!font || (v && font->HasCharacter(v)) || - font->FeatureWillHandleChar(aRunScript, - HB_TAG('v', 'e', 'r', 't'), ch)) + font->FeatureWillHandleChar(aRunScript, kVert, ch) || + (aRunScript == Script::BOPOMOFO && + font->FeatureWillHandleChar(Script::HAN, kVert, ch))) ? ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT : ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT; break;