Skip to content

Commit

Permalink
Merge r220797 - [HarfBuzz] Decomposed Vietnamese characters are rende…
Browse files Browse the repository at this point in the history
…red incorrectly

https://bugs.webkit.org/show_bug.cgi?id=174418

Patch by Fujii Hironori <Hironori.Fujii@sony.com> on 2017-08-16
Reviewed by Michael Catanzaro.

Source/WebCore:

HarfBuzzShaper should normalize the input text before collecting
HarfBuzzRuns. Actually, HarfBuzzShaper::setNormalizedBuffer does
the task. But, this function hasn't been called from anywhere
since Bug 90951.

Test: fast/text/international/vietnamese-nfd.html
      imported/blink/fast/text/international/text-shaping-arabic-diffs.html

* platform/graphics/harfbuzz/HarfBuzzShaper.cpp:
(WebCore::HarfBuzzShaper::HarfBuzzShaper):
Call setNormalizedBuffer instead of normalizeCharacters.
(WebCore::normalizeCharacters): Deleted.
(WebCore::normalizeSpacesAndMirrorChars) Use
FontCascade::treatAsZeroWidthSpaceInComplexScript instead of
FontCascade::treatAsZeroWidthSpace to preserve ZWJ and ZWNJ.

LayoutTests:

* fast/text/international/vietnamese-nfd-expected.html: Added.
* fast/text/international/vietnamese-nfd.html: Added.
  • Loading branch information
fujii authored and carlosgcampos committed Aug 17, 2017
1 parent 17c8ea2 commit 8a7555d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 31 deletions.
10 changes: 10 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,13 @@
2017-08-16 Fujii Hironori <Hironori.Fujii@sony.com>

[HarfBuzz] Decomposed Vietnamese characters are rendered incorrectly
https://bugs.webkit.org/show_bug.cgi?id=174418

Reviewed by Michael Catanzaro.

* fast/text/international/vietnamese-nfd-expected.html: Added.
* fast/text/international/vietnamese-nfd.html: Added.

2017-08-15 Commit Queue <commit-queue@webkit.org>

Unreviewed, rolling out r219504.
Expand Down
15 changes: 15 additions & 0 deletions LayoutTests/fast/text/international/vietnamese-nfd-expected.html
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<style>
body {
font-size: 30px;
font-family: Helvetica, sans;
}
</style>
<body>
ã ẫ ẵ ẽ ễ ĩ õ ỗ ỡ ũ ữ ỹ<br>
ạ ậ ặ ẹ ệ ị ọ ộ ợ ụ ự ỵ<br>
ả ẩ ẳ ẻ ể ỉ ỏ ổ ở ủ ử ỷ<br>
</body>
</html>
15 changes: 15 additions & 0 deletions LayoutTests/fast/text/international/vietnamese-nfd.html
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<style>
body {
font-size: 30px;
font-family: Helvetica, sans;
}
</style>
<body>
ã ẫ ẵ ẽ ễ ĩ õ ỗ ỡ ũ ữ ỹ<br>
ạ ậ ặ ẹ ệ ị ọ ộ ợ ụ ự ỵ<br>
ả ẩ ẳ ẻ ể ỉ ỏ ổ ở ủ ử ỷ<br>
</body>
</html>
23 changes: 23 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,26 @@
2017-08-16 Fujii Hironori <Hironori.Fujii@sony.com>

[HarfBuzz] Decomposed Vietnamese characters are rendered incorrectly
https://bugs.webkit.org/show_bug.cgi?id=174418

Reviewed by Michael Catanzaro.

HarfBuzzShaper should normalize the input text before collecting
HarfBuzzRuns. Actually, HarfBuzzShaper::setNormalizedBuffer does
the task. But, this function hasn't been called from anywhere
since Bug 90951.

Test: fast/text/international/vietnamese-nfd.html
imported/blink/fast/text/international/text-shaping-arabic-diffs.html

* platform/graphics/harfbuzz/HarfBuzzShaper.cpp:
(WebCore::HarfBuzzShaper::HarfBuzzShaper):
Call setNormalizedBuffer instead of normalizeCharacters.
(WebCore::normalizeCharacters): Deleted.
(WebCore::normalizeSpacesAndMirrorChars) Use
FontCascade::treatAsZeroWidthSpaceInComplexScript instead of
FontCascade::treatAsZeroWidthSpace to preserve ZWJ and ZWNJ.

2017-08-15 Commit Queue <commit-queue@webkit.org>

Unreviewed, rolling out r219504.
Expand Down
33 changes: 2 additions & 31 deletions Source/WebCore/platform/graphics/harfbuzz/HarfBuzzShaper.cpp
Expand Up @@ -160,33 +160,6 @@ float HarfBuzzShaper::HarfBuzzRun::xPositionForOffset(unsigned offset)
return position;
}

static void normalizeCharacters(const TextRun& run, UChar* destination, unsigned length)
{
unsigned position = 0;
bool error = false;
const UChar* source;
String stringFor8BitRun;
if (run.is8Bit()) {
stringFor8BitRun = String::make16BitFrom8BitSource(run.characters8(), run.length());
source = stringFor8BitRun.characters16();
} else
source = run.characters16();

while (position < length) {
UChar32 character;
unsigned nextPosition = position;
U16_NEXT(source, nextPosition, length, character);
// Don't normalize tabs as they are not treated as spaces for word-end.
if (FontCascade::treatAsSpace(character) && character != '\t')
character = ' ';
else if (FontCascade::treatAsZeroWidthSpaceInComplexScript(character))
character = zeroWidthSpace;
U16_APPEND(destination, position, length, character, error);
ASSERT_UNUSED(error, !error);
position = nextPosition;
}
}

HarfBuzzShaper::HarfBuzzShaper(const FontCascade* font, const TextRun& run)
: m_font(font)
, m_normalizedBufferLength(0)
Expand All @@ -197,9 +170,7 @@ HarfBuzzShaper::HarfBuzzShaper(const FontCascade* font, const TextRun& run)
, m_padError(0)
, m_letterSpacing(font->letterSpacing())
{
m_normalizedBuffer = std::make_unique<UChar[]>(m_run.length() + 1);
m_normalizedBufferLength = m_run.length();
normalizeCharacters(m_run, m_normalizedBuffer.get(), m_normalizedBufferLength);
setNormalizedBuffer();
setPadding(m_run.expansion());
setFontFeatures();
}
Expand All @@ -220,7 +191,7 @@ static void normalizeSpacesAndMirrorChars(const UChar* source, UChar* destinatio
// Don't normalize tabs as they are not treated as spaces for word-end
if (FontCascade::treatAsSpace(character) && character != '\t')
character = ' ';
else if (FontCascade::treatAsZeroWidthSpace(character))
else if (FontCascade::treatAsZeroWidthSpaceInComplexScript(character))
character = zeroWidthSpace;
else if (normalizeMode == HarfBuzzShaper::NormalizeMirrorChars)
character = u_charMirror(character);
Expand Down

0 comments on commit 8a7555d

Please sign in to comment.