Skip to content

Commit

Permalink
Merge r174466 - Text drawn with an SVG font has no spaces when word-r…
Browse files Browse the repository at this point in the history
…ounding hacks are enabled

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

Reviewed by Darin Adler.

Source/WebCore:

When rounding hacks are enabled, we use the "adjusted space width" instead of the
regular space width. However, the SVG-font-specific implementation of the
SimpleFontData constructor doesn't initialize this value, so it was getting set
to an undefined value (which happened to be close to 0 in my tests).

Test: svg/text/svg-font-word-rounding-hacks-spaces.html

* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::getFontData):
(WebCore::CSSFontFaceSource::ensureFontData):
* loader/cache/CachedFont.cpp:
(WebCore::CachedFont::ensureCustomFontData):
(WebCore::CachedFont::getSVGFontById):
* platform/graphics/SimpleFontData.h:
* svg/SVGFontData.cpp:
(WebCore::SVGFontData::initializeFontData):

LayoutTests:

Make sure that spaces are present.

* svg/text/svg-font-word-rounding-hacks-spaces.html:
* svg/text/svg-font-word-rounding-hacks-spaces-expected.html:

Canonical link: https://commits.webkit.org/154760.113@webkitgtk/2.6
git-svn-id: https://svn.webkit.org/repository/webkit/releases/WebKitGTK/webkit-2.6@174965 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
litherum authored and carlosgcampos committed Oct 21, 2014
1 parent b4bdd8e commit 879e935
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 6 deletions.
12 changes: 12 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
2014-10-08 Myles C. Maxfield <mmaxfield@apple.com>

Text drawn with an SVG font has no spaces when word-rounding hacks are enabled
https://bugs.webkit.org/show_bug.cgi?id=137463

Reviewed by Darin Adler.

Make sure that spaces are present.

* svg/text/svg-font-word-rounding-hacks-spaces.html:
* svg/text/svg-font-word-rounding-hacks-spaces-expected.html:

2014-10-06 David Hyatt <hyatt@apple.com>

REGRESSION (Simple Line Layout): Inline block baselines computed incorrectly
Expand Down
8 changes: 5 additions & 3 deletions LayoutTests/svg/text/resources/Litherum.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<style>
.blackbox {
display: inline-block;
width: 14px;
height: 21px;
background: black;
}
.whitebox {
display: inline-block;
width: 14px;
height: 21px;
background: white;
}
</style>
</head>
<body>
This test makes sure that text drawn with an SVG font with word-wrapping hacks has spaces.
The test is successful if the space between the two boxes below is the same as the width of each of the boxes.
<div><div class="blackbox"></div><div class="whitebox"></div><div class="blackbox"></div></div>
</body>
</html>
20 changes: 20 additions & 0 deletions LayoutTests/svg/text/svg-font-word-rounding-hacks-spaces.html
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<style>
@font-face {
font-family: 'Litherum';
src: url("resources/Litherum.svg") format(svg)
}
</style>
<script>
if (window.internals)
window.internals.allowRoundingHacks();
</script>
</head>
<body>
This test makes sure that text drawn with an SVG font with word-wrapping hacks has spaces.
The test is successful if the space between the two boxes below is the same as the width of each of the boxes.
<div style="font: 14px Litherum;">a a</div>
</body>
</html>
24 changes: 24 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,27 @@
2014-10-08 Myles C. Maxfield <mmaxfield@apple.com>

Text drawn with an SVG font has no spaces when word-rounding hacks are enabled
https://bugs.webkit.org/show_bug.cgi?id=137463

Reviewed by Darin Adler.

When rounding hacks are enabled, we use the "adjusted space width" instead of the
regular space width. However, the SVG-font-specific implementation of the
SimpleFontData constructor doesn't initialize this value, so it was getting set
to an undefined value (which happened to be close to 0 in my tests).

Test: svg/text/svg-font-word-rounding-hacks-spaces.html

* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::getFontData):
(WebCore::CSSFontFaceSource::ensureFontData):
* loader/cache/CachedFont.cpp:
(WebCore::CachedFont::ensureCustomFontData):
(WebCore::CachedFont::getSVGFontById):
* platform/graphics/SimpleFontData.h:
* svg/SVGFontData.cpp:
(WebCore::SVGFontData::initializeFontData):

2014-10-08 Darin Adler <darin@apple.com>

ASSERTION FAILED: underlyingStringIsValid()
Expand Down
6 changes: 5 additions & 1 deletion Source/WebCore/platform/graphics/SimpleFontData.h
Expand Up @@ -159,7 +159,11 @@ class SimpleFontData final : public FontData {

float spaceWidth() const { return m_spaceWidth; }
float adjustedSpaceWidth() const { return m_adjustedSpaceWidth; }
void setSpaceWidth(float spaceWidth) { m_spaceWidth = spaceWidth; }
void setSpaceWidths(float spaceWidth)
{
m_spaceWidth = spaceWidth;
m_adjustedSpaceWidth = spaceWidth;
}

#if USE(CG) || USE(CAIRO)
float syntheticBoldOffset() const { return m_syntheticBoldOffset; }
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/svg/SVGFontData.cpp
Expand Up @@ -98,7 +98,7 @@ void SVGFontData::initializeFontData(SimpleFontData* fontData, float fontSize)

if (!glyphPageZero) {
fontData->setSpaceGlyph(0);
fontData->setSpaceWidth(0);
fontData->setSpaceWidths(0);
fontData->setAvgCharWidth(0);
fontData->setMaxCharWidth(ascent);
return;
Expand All @@ -107,7 +107,7 @@ void SVGFontData::initializeFontData(SimpleFontData* fontData, float fontSize)
// Calculate space width.
Glyph spaceGlyph = glyphPageZero->glyphDataForCharacter(' ').glyph;
fontData->setSpaceGlyph(spaceGlyph);
fontData->setSpaceWidth(fontData->widthForGlyph(spaceGlyph));
fontData->setSpaceWidths(fontData->widthForGlyph(spaceGlyph));

// Estimate average character width.
Glyph numeralZeroGlyph = glyphPageZero->glyphDataForCharacter('0').glyph;
Expand Down

0 comments on commit 879e935

Please sign in to comment.