Changeset 222090 in webkit


Ignore:
Timestamp:
Sep 15, 2017 8:37:02 AM (7 years ago)
Author:
Carlos Garcia Campos
Message:

[Harfbuzz] Material icons not rendered correctly when using the web font
https://bugs.webkit.org/show_bug.cgi?id=176995

Reviewed by Michael Catanzaro.

Only a few of them are correctly rendered and some others are wrong. We only render correctly the ones that
don't have an underscore in their name (or that start with a number like 3d_rotation). In the cases where the
name before the underscore is also an icon, we render that icon instead, that's why some of them are wrong. This
is happening because the underscore is causing the HarfbuffShaper to split the text in 3 runs, one for the word
before the underscore, another one for the underscore and another for the word after the underscore. So, we
end up trying to shape the 3 runs independently and we fail when the icon doesn't exist, or when it exists but
it's not the one we are looking for. The cause of this is that the underscore has a different script (Common)
than the rest of characters (Latin) which is a condition in HarfbuffShaper to create a different run. The
unicode spec says that characters with Common script should be handled differently, but we are just ignoring
it. The spec proposes to use an heuristic based on simply inheriting the script of the previous character, which
should work in most of the cases. We could take a more conservative approach and do that only if both characters
are ASCII. We should also consider handling other cases mentioned by the spec like brackets and quotation marks,
but that belongs to a different bug/commit.

  • platform/graphics/harfbuzz/HarfBuzzShaper.cpp:

(WebCore::scriptsAreCompatibleForCharacters): Helper function to check if the current and previous scripts are
compatible,
(WebCore::HarfBuzzShaper::collectHarfBuzzRuns): Use scriptsAreCompatibleForCharacters() to decided whether to
finish the current run or not. In case of Common script, inherit also the script from the previous character.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r222086 r222090  
     12017-09-15  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [Harfbuzz] Material icons not rendered correctly when using the web font
     4        https://bugs.webkit.org/show_bug.cgi?id=176995
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Only a few of them are correctly rendered and some others are wrong. We only render correctly the ones that
     9        don't have an underscore in their name (or that start with a number like 3d_rotation). In the cases where the
     10        name before the underscore is also an icon, we render that icon instead, that's why some of them are wrong. This
     11        is happening because the underscore is causing the HarfbuffShaper to split the text in 3 runs, one for the word
     12        before the underscore, another one for the underscore and another for the word after the underscore. So, we
     13        end up trying to shape the 3 runs independently and we fail when the icon doesn't exist, or when it exists but
     14        it's not the one we are looking for. The cause of this is that the underscore has a different script (Common)
     15        than the rest of characters (Latin) which is a condition in HarfbuffShaper to create a different run. The
     16        unicode spec says that characters with Common script should be handled differently, but we are just ignoring
     17        it. The spec proposes to use an heuristic based on simply inheriting the script of the previous character, which
     18        should work in most of the cases. We could take a more conservative approach and do that only if both characters
     19        are ASCII. We should also consider handling other cases mentioned by the spec like brackets and quotation marks,
     20        but that belongs to a different bug/commit.
     21
     22        * platform/graphics/harfbuzz/HarfBuzzShaper.cpp:
     23        (WebCore::scriptsAreCompatibleForCharacters): Helper function to check if the current and previous scripts are
     24        compatible,
     25        (WebCore::HarfBuzzShaper::collectHarfBuzzRuns): Use scriptsAreCompatibleForCharacters() to decided whether to
     26        finish the current run or not. In case of Common script, inherit also the script from the previous character.
     27
    1282017-09-15  Carlos Garcia Campos  <cgarcia@igalia.com>
    229
  • trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp

    r222086 r222090  
    360360}
    361361
     362static bool scriptsAreCompatibleForCharacters(UScriptCode script, UScriptCode previousScript, UChar32 character, UChar32 previousCharacter)
     363{
     364    if (script == previousScript)
     365        return true;
     366
     367    if (script == USCRIPT_INHERITED || previousScript == USCRIPT_COMMON)
     368        return true;
     369
     370    if (script == USCRIPT_COMMON) {
     371        // §5.1 Handling Characters with the Common Script Property.
     372        // Programs must resolve any of the special Script property values, such as Common,
     373        // based on the context of the surrounding characters. A simple heuristic uses the
     374        // script of the preceding character, which works well in many cases.
     375        // http://www.unicode.org/reports/tr24/#Common.
     376        //
     377        // FIXME: cover all other cases mentioned in the spec (ie. brackets or quotation marks).
     378        // https://bugs.webkit.org/show_bug.cgi?id=177003.
     379        //
     380        // We use a slightly more conservative heuristic than the one proposed in the spec,
     381        // using the script of the previous character only if both are ASCII.
     382        if (isASCII(character) && isASCII(previousCharacter))
     383            return true;
     384    }
     385
     386    return uscript_hasScript(character, previousScript);
     387}
     388
    362389bool HarfBuzzShaper::collectHarfBuzzRuns()
    363390{
     
    382409            currentFontData = &m_font->primaryFont();
    383410        UScriptCode currentScript = nextScript;
     411        UChar32 previousCharacter = character;
    384412
    385413        for (iterator.advance(clusterLength); iterator.consume(character, clusterLength); iterator.advance(clusterLength)) {
     
    411439            if (U_FAILURE(errorCode))
    412440                return false;
    413             if ((nextFontData != currentFontData) || ((currentScript != nextScript) && (nextScript != USCRIPT_INHERITED) && (!uscript_hasScript(character, currentScript))))
     441
     442            if (nextFontData != currentFontData)
    414443                break;
    415             if (nextScript == USCRIPT_INHERITED)
     444
     445            if (!scriptsAreCompatibleForCharacters(nextScript, currentScript, character, previousCharacter))
     446                break;
     447
     448            if (nextScript == USCRIPT_INHERITED || nextScript == USCRIPT_COMMON)
    416449                nextScript = currentScript;
     450
    417451            currentCharacterPosition = iterator.characters();
     452            previousCharacter = character;
    418453        }
    419454        unsigned numCharactersOfCurrentRun = iterator.currentIndex() - startIndexOfCurrentRun;
Note: See TracChangeset for help on using the changeset viewer.