Commit 529ec212 authored by davve@opera.com's avatar davve@opera.com

Unapply effectiveZoom during SVG layout

Text layout in SVG is assumed to happen in unzoomed coordinates.
Prior to this patch, there was a special SVG mode in the
StyleResolver that disregarded zoom when resolving lengths for
SVG elements. That broke down during inheritance though, so a
better way to handle the SVG zoom model is for the SVG module to
remove zoom from style values itself.

BUG=382366

Review URL: https://codereview.chromium.org/323053002

git-svn-id: svn://svn.chromium.org/blink/trunk@176051 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 578a32cf
<!doctype html>
<body style="zoom:2">
<p>The letter spacing should be identical:</p>
<div>
<svg style="letter-spacing: 10px" width="100" height="50"><text x="0" y="20">123</text></svg><br>
<svg style="letter-spacing: 10px" width="100" height="50"><text x="0" y="20">123</text></svg>
</div>
</body>
<!doctype html>
<body style="zoom:2">
<p>The letter spacing should be identical:</p>
<div style="letter-spacing: 10px">
<svg width="100" height="50"><text x="0" y="20">123</text></svg><br>
<svg style="letter-spacing: 10px" width="100" height="50"><text x="0" y="20">123</text></svg>
</div>
</body>
<!doctype html>
<body style="zoom:2">
<p>The word spacing should be identical:</p>
<div>
<svg style="word-spacing: 10px" width="200" height="50"><text x="0" y="20">one two three</text></svg><br>
<svg style="word-spacing: 10px" width="200" height="50"><text x="0" y="20">one two three</text></svg>
</div>
</body>
<!doctype html>
<body style="zoom:2">
<p>The word spacing should be identical:</p>
<div style="word-spacing: 10px">
<svg width="200" height="50"><text x="0" y="20">one two three</text></svg><br>
<svg style="word-spacing: 10px" width="200" height="50"><text x="0" y="20">one two three</text></svg>
</div>
</body>
......@@ -404,8 +404,6 @@ float StyleBuilderConverter::convertSpacing(StyleResolverState& state, CSSValue*
CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
if (primitiveValue->getValueID() == CSSValueNormal)
return 0;
if (state.useSVGZoomRules())
return primitiveValue->computeLength<float>(state.cssToLengthConversionData().copyWithAdjustedZoom(1));
return primitiveValue->computeLength<float>(state.cssToLengthConversionData());
}
......
......@@ -128,16 +128,6 @@ public:
void setWritingMode(WritingMode writingMode) { m_fontBuilder.didChangeFontParameters(m_style->setWritingMode(writingMode)); }
void setTextOrientation(TextOrientation textOrientation) { m_fontBuilder.didChangeFontParameters(m_style->setTextOrientation(textOrientation)); }
// SVG handles zooming in a different way compared to CSS. The whole document is scaled instead
// of each individual length value in the render style / tree. CSSPrimitiveValue::computeLength*()
// multiplies each resolved length with the zoom multiplier - so for SVG we need to disable that.
// Though all CSS values that can be applied to outermost <svg> elements (width/height/border/padding...)
// need to respect the scaling. RenderBox (the parent class of RenderSVGRoot) grabs values like
// width/height/border/padding/... from the RenderStyle -> for SVG these values would never scale,
// if we'd pass a 1.0 zoom factor everyhwere. So we only pass a zoom factor of 1.0 for specific
// properties that are NOT allowed to scale within a zoomed SVG document (letter/word-spacing/font-size).
bool useSVGZoomRules() const { return element() && element()->isSVGElement(); }
private:
ElementResolveContext m_elementContext;
Document& m_document;
......
......@@ -445,7 +445,7 @@ void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Rend
const Font& font = style->font();
SVGTextLayoutEngineSpacing spacingLayout(font);
SVGTextLayoutEngineSpacing spacingLayout(font, style->effectiveZoom());
SVGTextLayoutEngineBaseline baselineLayout(font);
bool didStartTextFragment = false;
......
......@@ -33,13 +33,15 @@
namespace WebCore {
SVGTextLayoutEngineSpacing::SVGTextLayoutEngineSpacing(const Font& font)
SVGTextLayoutEngineSpacing::SVGTextLayoutEngineSpacing(const Font& font, float effectiveZoom)
: m_font(font)
, m_lastCharacter(0)
, m_effectiveZoom(effectiveZoom)
#if ENABLE(SVG_FONTS)
, m_lastGlyph(0)
#endif
{
ASSERT(m_effectiveZoom);
}
float SVGTextLayoutEngineSpacing::calculateSVGKerning(bool isVerticalText, Glyph currentGlyph)
......@@ -96,6 +98,9 @@ float SVGTextLayoutEngineSpacing::calculateCSSSpacing(UChar currentCharacter)
spacing += m_font.fontDescription().wordSpacing();
}
if (m_effectiveZoom != 1)
spacing = spacing / m_effectiveZoom;
return spacing;
}
......
......@@ -32,7 +32,7 @@ class SVGElement;
class SVGTextLayoutEngineSpacing {
WTF_MAKE_NONCOPYABLE(SVGTextLayoutEngineSpacing);
public:
SVGTextLayoutEngineSpacing(const Font&);
SVGTextLayoutEngineSpacing(const Font&, float effectiveZoom);
float calculateSVGKerning(bool isVerticalText, Glyph currentGlyph);
float calculateCSSSpacing(UChar currentCharacter);
......@@ -40,6 +40,7 @@ public:
private:
const Font& m_font;
UChar m_lastCharacter;
float m_effectiveZoom;
#if ENABLE(SVG_FONTS)
Glyph m_lastGlyph;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment