Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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.

Canonical link: https://commits.webkit.org/193412@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222090 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
carlosgcampos committed Sep 15, 2017
1 parent ecabc1e commit 9d69ead
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
27 changes: 27 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,30 @@
2017-09-15 Carlos Garcia Campos <cgarcia@igalia.com>

[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.

2017-09-15 Carlos Garcia Campos <cgarcia@igalia.com>

[Harfbuzz] Fix incorrect font rendering when selecting texts in pages which specifies text-rendering: optimizeLegibility
Expand Down
39 changes: 37 additions & 2 deletions Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp
Expand Up @@ -359,6 +359,33 @@ FloatPoint HarfBuzzShaper::adjustStartPoint(const FloatPoint& point)
return point + m_startOffset;
}

static bool scriptsAreCompatibleForCharacters(UScriptCode script, UScriptCode previousScript, UChar32 character, UChar32 previousCharacter)
{
if (script == previousScript)
return true;

if (script == USCRIPT_INHERITED || previousScript == USCRIPT_COMMON)
return true;

if (script == USCRIPT_COMMON) {
// §5.1 Handling Characters with the Common Script Property.
// Programs must resolve any of the special Script property values, such as Common,
// based on the context of the surrounding characters. A simple heuristic uses the
// script of the preceding character, which works well in many cases.
// http://www.unicode.org/reports/tr24/#Common.
//
// FIXME: cover all other cases mentioned in the spec (ie. brackets or quotation marks).
// https://bugs.webkit.org/show_bug.cgi?id=177003.
//
// We use a slightly more conservative heuristic than the one proposed in the spec,
// using the script of the previous character only if both are ASCII.
if (isASCII(character) && isASCII(previousCharacter))
return true;
}

return uscript_hasScript(character, previousScript);
}

bool HarfBuzzShaper::collectHarfBuzzRuns()
{
const UChar* normalizedBufferEnd = m_normalizedBuffer.get() + m_normalizedBufferLength;
Expand All @@ -381,6 +408,7 @@ bool HarfBuzzShaper::collectHarfBuzzRuns()
if (!currentFontData)
currentFontData = &m_font->primaryFont();
UScriptCode currentScript = nextScript;
UChar32 previousCharacter = character;

for (iterator.advance(clusterLength); iterator.consume(character, clusterLength); iterator.advance(clusterLength)) {
if (FontCascade::treatAsZeroWidthSpace(character))
Expand Down Expand Up @@ -410,11 +438,18 @@ bool HarfBuzzShaper::collectHarfBuzzRuns()
nextScript = uscript_getScript(character, &errorCode);
if (U_FAILURE(errorCode))
return false;
if ((nextFontData != currentFontData) || ((currentScript != nextScript) && (nextScript != USCRIPT_INHERITED) && (!uscript_hasScript(character, currentScript))))

if (nextFontData != currentFontData)
break;

if (!scriptsAreCompatibleForCharacters(nextScript, currentScript, character, previousCharacter))
break;
if (nextScript == USCRIPT_INHERITED)

if (nextScript == USCRIPT_INHERITED || nextScript == USCRIPT_COMMON)
nextScript = currentScript;

currentCharacterPosition = iterator.characters();
previousCharacter = character;
}
unsigned numCharactersOfCurrentRun = iterator.currentIndex() - startIndexOfCurrentRun;
hb_script_t script = hb_icu_script_to_script(currentScript);
Expand Down

0 comments on commit 9d69ead

Please sign in to comment.