Chromium Code Reviews| Index: Source/core/layout/svg/SVGTextLayoutEngineBaseline.cpp |
| diff --git a/Source/core/layout/svg/SVGTextLayoutEngineBaseline.cpp b/Source/core/layout/svg/SVGTextLayoutEngineBaseline.cpp |
| index 0a873559e9ff298c5fff15bec8dd81110d138fa0..b51b6469f5221222f5bcd3ebc16cbfa53290eaa9 100644 |
| --- a/Source/core/layout/svg/SVGTextLayoutEngineBaseline.cpp |
| +++ b/Source/core/layout/svg/SVGTextLayoutEngineBaseline.cpp |
| @@ -29,9 +29,11 @@ |
| namespace blink { |
| -SVGTextLayoutEngineBaseline::SVGTextLayoutEngineBaseline(const Font& font) |
| +SVGTextLayoutEngineBaseline::SVGTextLayoutEngineBaseline(const Font& font, float effectiveZoom) |
| : m_font(font) |
| + , m_effectiveZoom(effectiveZoom) |
| { |
| + ASSERT(m_effectiveZoom); |
| } |
| float SVGTextLayoutEngineBaseline::calculateBaselineShift(const ComputedStyle& style) const |
| @@ -40,11 +42,11 @@ float SVGTextLayoutEngineBaseline::calculateBaselineShift(const ComputedStyle& s |
| switch (svgStyle.baselineShift()) { |
| case BS_LENGTH: |
| - return SVGLengthContext::valueForLength(svgStyle.baselineShiftValue(), style, m_font.fontDescription().computedPixelSize()); |
| + return SVGLengthContext::valueForLength(svgStyle.baselineShiftValue(), style, m_font.fontDescription().computedPixelSize() / m_effectiveZoom); |
| case BS_SUB: |
| - return -m_font.fontMetrics().floatHeight() / 2; |
| + return -m_font.fontMetrics().floatHeight() / 2 / m_effectiveZoom; |
| case BS_SUPER: |
| - return m_font.fontMetrics().floatHeight() / 2; |
| + return m_font.fontMetrics().floatHeight() / 2 / m_effectiveZoom; |
| default: |
| ASSERT_NOT_REACHED(); |
| return 0; |
| @@ -115,30 +117,43 @@ float SVGTextLayoutEngineBaseline::calculateAlignmentBaselineShift(bool isVertic |
| const FontMetrics& fontMetrics = m_font.fontMetrics(); |
| + float alignementBaselineShift = 0; |
|
Erik Dahlström (inactive)
2015/04/14 09:13:08
s/alignement/alignment/
|
| + |
| // Note: http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling |
| switch (baseline) { |
| case AB_BEFORE_EDGE: |
| case AB_TEXT_BEFORE_EDGE: |
| - return fontMetrics.floatAscent(); |
| + alignementBaselineShift = fontMetrics.floatAscent(); |
| + break; |
| case AB_MIDDLE: |
| - return fontMetrics.xHeight() / 2; |
| + alignementBaselineShift = fontMetrics.xHeight() / 2; |
| + break; |
| case AB_CENTRAL: |
| - return (fontMetrics.floatAscent() - fontMetrics.floatDescent()) / 2; |
| + alignementBaselineShift = (fontMetrics.floatAscent() - fontMetrics.floatDescent()) / 2; |
| + break; |
| case AB_AFTER_EDGE: |
| case AB_TEXT_AFTER_EDGE: |
| case AB_IDEOGRAPHIC: |
| - return -fontMetrics.floatDescent(); |
| + alignementBaselineShift = -fontMetrics.floatDescent(); |
| + break; |
| case AB_ALPHABETIC: |
| - return 0; |
| + alignementBaselineShift = 0; |
| + break; |
| case AB_HANGING: |
| - return fontMetrics.floatAscent() * 8 / 10.f; |
| + alignementBaselineShift = fontMetrics.floatAscent() * 8 / 10.f; |
| + break; |
| case AB_MATHEMATICAL: |
| - return fontMetrics.floatAscent() / 2; |
| + alignementBaselineShift = fontMetrics.floatAscent() / 2; |
| + break; |
| case AB_BASELINE: |
| default: |
| ASSERT_NOT_REACHED(); |
| - return 0; |
| } |
| + |
| + if (m_effectiveZoom != 1) |
| + alignementBaselineShift = alignementBaselineShift / m_effectiveZoom; |
|
fs
2015/04/14 09:21:21
Since we have a nit in effect already... I'd prefe
|
| + |
| + return alignementBaselineShift; |
| } |
| float SVGTextLayoutEngineBaseline::calculateGlyphOrientationAngle(bool isVerticalText, const SVGComputedStyle& style, const UChar& character) const |
| @@ -184,12 +199,16 @@ float SVGTextLayoutEngineBaseline::calculateGlyphAdvanceAndOrientation(bool isVe |
| const FontMetrics& fontMetrics = m_font.fontMetrics(); |
| + float ascent = fontMetrics.floatAscent() / m_effectiveZoom; |
| + float descent = fontMetrics.floatDescent() / m_effectiveZoom; |
| + |
| // Vertical orientation handling. |
| if (isVerticalText) { |
| - float ascentMinusDescent = fontMetrics.floatAscent() - fontMetrics.floatDescent(); |
| + float ascentMinusDescent = ascent - descent; |
| + |
| if (!angle) { |
| xOrientationShift = (ascentMinusDescent - metrics.width()) / 2; |
| - yOrientationShift = fontMetrics.floatAscent(); |
| + yOrientationShift = ascent; |
| } else if (angle == 180) { |
| xOrientationShift = (ascentMinusDescent + metrics.width()) / 2; |
| } else if (angle == 270) { |
| @@ -209,7 +228,7 @@ float SVGTextLayoutEngineBaseline::calculateGlyphAdvanceAndOrientation(bool isVe |
| yOrientationShift = -metrics.width(); |
| } else if (angle == 180) { |
| xOrientationShift = metrics.width(); |
| - yOrientationShift = -fontMetrics.floatAscent(); |
| + yOrientationShift = -ascent; |
| } else if (angle == 270) { |
| xOrientationShift = metrics.width(); |
| } |