Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix text positioning with non-bmp characters.
https://bugs.webkit.org/show_bug.cgi?id=87681

Reviewed by Nikolas Zimmermann.

Source/WebCore:

Previously when constructing metrics for tspans with non-bmp characters,
each non-bmp character treated as a skipped character in the same way that
spaces are ignored.
This made sense because the initial SVGCharacterDataMap for <text> is
indexed by character index (not string length) so the high portion of a
non-bmp character was treated as a skipped space. Unfortunately, this
led to a bug because skipped spaces lead to an offset in the positioning
values list but non-bmp characters do not.

This change switches the code to use a new offset for non-bmp characters,
surrogatePairCharacters, which does not affect the positioning values list.

Tests: svg/text/non-bmp-tspans-expected.svg
       svg/text/non-bmp-tspans.svg

* rendering/svg/SVGTextMetricsBuilder.cpp:
(WebCore::SVGTextMetricsBuilder::measureTextRenderer):

LayoutTests:

* svg/text/non-bmp-tspans-expected.svg: Added.
* svg/text/non-bmp-tspans.svg: Added.


Canonical link: https://commits.webkit.org/108316@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@121756 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
progers committed Jul 3, 2012
1 parent 14c8732 commit a06ce5a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
10 changes: 10 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,13 @@
2012-07-03 Philip Rogers <pdr@google.com>

Fix text positioning with non-bmp characters.
https://bugs.webkit.org/show_bug.cgi?id=87681

Reviewed by Nikolas Zimmermann.

* svg/text/non-bmp-tspans-expected.svg: Added.
* svg/text/non-bmp-tspans.svg: Added.

2012-07-03 Gyuyoung Kim <gyuyoung.kim@samsung.com>

Improve test cases for network information APIs
Expand Down
14 changes: 14 additions & 0 deletions LayoutTests/svg/text/non-bmp-tspans-expected.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions LayoutTests/svg/text/non-bmp-tspans.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,28 @@
2012-07-03 Philip Rogers <pdr@google.com>

Fix text positioning with non-bmp characters.
https://bugs.webkit.org/show_bug.cgi?id=87681

Reviewed by Nikolas Zimmermann.

Previously when constructing metrics for tspans with non-bmp characters,
each non-bmp character treated as a skipped character in the same way that
spaces are ignored.
This made sense because the initial SVGCharacterDataMap for <text> is
indexed by character index (not string length) so the high portion of a
non-bmp character was treated as a skipped space. Unfortunately, this
led to a bug because skipped spaces lead to an offset in the positioning
values list but non-bmp characters do not.

This change switches the code to use a new offset for non-bmp characters,
surrogatePairCharacters, which does not affect the positioning values list.

Tests: svg/text/non-bmp-tspans-expected.svg
svg/text/non-bmp-tspans.svg

* rendering/svg/SVGTextMetricsBuilder.cpp:
(WebCore::SVGTextMetricsBuilder::measureTextRenderer):

2012-07-03 Gyuyoung Kim <gyuyoung.kim@samsung.com>

Improve test cases for network information APIs
Expand Down
5 changes: 3 additions & 2 deletions Source/WebCore/rendering/svg/SVGTextMetricsBuilder.cpp
Expand Up @@ -155,6 +155,7 @@ void SVGTextMetricsBuilder::measureTextRenderer(RenderSVGInlineText* text, Measu

initializeMeasurementWithTextRenderer(text);
bool preserveWhiteSpace = text->style()->whiteSpace() == PRE;
int surrogatePairCharacters = 0;

while (advance()) {
const UChar* currentCharacter = m_run.data(m_textPosition);
Expand All @@ -168,15 +169,15 @@ void SVGTextMetricsBuilder::measureTextRenderer(RenderSVGInlineText* text, Measu

if (data->processRenderer) {
if (data->allCharactersMap) {
const SVGCharacterDataMap::const_iterator it = data->allCharactersMap->find(data->valueListPosition + m_textPosition - data->skippedCharacters + 1);
const SVGCharacterDataMap::const_iterator it = data->allCharactersMap->find(data->valueListPosition + m_textPosition - data->skippedCharacters - surrogatePairCharacters + 1);
if (it != data->allCharactersMap->end())
attributes->characterDataMap().set(m_textPosition + 1, it->second);
}
textMetricsValues->append(m_currentMetrics);
}

if (data->allCharactersMap && currentCharacterStartsSurrogatePair())
data->skippedCharacters += m_currentMetrics.length() - 1;
surrogatePairCharacters++;

data->lastCharacter = currentCharacter;
}
Expand Down

0 comments on commit a06ce5a

Please sign in to comment.