From 81bc750723a18f21cd17d1b173cd2a4dda9cea6e Mon Sep 17 00:00:00 2001 From: Ben Murdoch Date: Tue, 24 May 2011 11:24:40 +0100 Subject: Merge WebKit at r80534: Intial merge by Git Change-Id: Ia7a83357124c9e1cdb1debf55d9661ec0bd09a61 --- Source/WebCore/rendering/svg/SVGInlineTextBox.cpp | 51 +++++++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) (limited to 'Source/WebCore/rendering/svg/SVGInlineTextBox.cpp') diff --git a/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp b/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp index 52976f2..05e1357 100644 --- a/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp +++ b/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp @@ -47,7 +47,7 @@ SVGInlineTextBox::SVGInlineTextBox(RenderObject* object) { } -int SVGInlineTextBox::offsetForPosition(int, bool) const +int SVGInlineTextBox::offsetForPosition(float, bool) const { // SVG doesn't use the standard offset <-> position selection system, as it's not suitable for SVGs complex needs. // vertical text selection, inline boxes spanning multiple lines (contrary to HTML, etc.) @@ -76,7 +76,7 @@ int SVGInlineTextBox::offsetForPositionInFragment(const SVGTextFragment& fragmen return fragment.positionListOffset - start() + textRenderer->scaledFont().offsetForPosition(textRun, position * scalingFactor, includePartialGlyphs); } -int SVGInlineTextBox::positionForOffset(int) const +float SVGInlineTextBox::positionForOffset(int) const { // SVG doesn't use the offset <-> position selection system. ASSERT_NOT_REACHED(); @@ -415,9 +415,6 @@ TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFrag run.setReferencingRenderObject(text); #endif - // Disable any word/character rounding. - run.disableRoundingHacks(); - // We handle letter & word spacing ourselves. run.disableSpacing(); return run; @@ -519,6 +516,29 @@ void SVGInlineTextBox::paintDecoration(GraphicsContext* context, ETextDecoration } } +static inline void normalizeTransform(AffineTransform& transform) +{ + // Obtain consistent numerical results for the AffineTransform on both 32/64bit platforms. + // Tested with SnowLeopard on Core Duo vs. Core 2 Duo. + static const float s_floatEpsilon = std::numeric_limits::epsilon(); + + if (fabs(transform.a() - 1) <= s_floatEpsilon) + transform.setA(1); + else if (fabs(transform.a() + 1) <= s_floatEpsilon) + transform.setA(-1); + + if (fabs(transform.d() - 1) <= s_floatEpsilon) + transform.setD(1); + else if (fabs(transform.d() + 1) <= s_floatEpsilon) + transform.setD(-1); + + if (fabs(transform.e()) <= s_floatEpsilon) + transform.setE(0); + + if (fabs(transform.f()) <= s_floatEpsilon) + transform.setF(0); +} + void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, ETextDecoration decoration, const SVGTextFragment& fragment, RenderObject* decorationRenderer) { ASSERT(!m_paintingResource); @@ -546,7 +566,12 @@ void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, ETextD if (scalingFactor != 1) { width *= scalingFactor; decorationOrigin.scale(scalingFactor, scalingFactor); - context->scale(FloatSize(1 / scalingFactor, 1 / scalingFactor)); + + AffineTransform newTransform = context->getCTM(); + newTransform.scale(1 / scalingFactor); + normalizeTransform(newTransform); + + context->setCTM(newTransform); } decorationOrigin.move(0, -scaledFontMetrics.floatAscent() + positionOffsetForDecoration(decoration, scaledFontMetrics, thickness)); @@ -589,13 +614,21 @@ void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyl if (shadow) extraOffset = applyShadowToGraphicsContext(context, shadow, shadowRect, false /* stroked */, true /* opaque */, true /* horizontal */); - if (scalingFactor != 1) - context->scale(FloatSize(1 / scalingFactor, 1 / scalingFactor)); + AffineTransform originalTransform; + if (scalingFactor != 1) { + originalTransform = context->getCTM(); + + AffineTransform newTransform = originalTransform; + newTransform.scale(1 / scalingFactor); + normalizeTransform(newTransform); + + context->setCTM(newTransform); + } scaledFont.drawText(context, textRun, textOrigin + extraOffset, startPosition, endPosition); if (scalingFactor != 1) - context->scale(FloatSize(scalingFactor, scalingFactor)); + context->setCTM(originalTransform); restoreGraphicsContextAfterTextPainting(context, textRun); -- cgit v1.1