summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/rendering/svg/RenderSVGInlineText.cpp')
-rw-r--r--Source/WebCore/rendering/svg/RenderSVGInlineText.cpp47
1 files changed, 42 insertions, 5 deletions
diff --git a/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp b/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp
index 91ffb5c..a8aa0c8 100644
--- a/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp
+++ b/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp
@@ -26,11 +26,14 @@
#if ENABLE(SVG)
#include "RenderSVGInlineText.h"
+#include "CSSStyleSelector.h"
#include "FloatConversion.h"
#include "FloatQuad.h"
#include "RenderBlock.h"
#include "RenderSVGRoot.h"
#include "RenderSVGText.h"
+#include "Settings.h"
+#include "SVGImageBufferTools.h"
#include "SVGInlineTextBox.h"
#include "SVGRootInlineBox.h"
#include "VisiblePosition.h"
@@ -63,6 +66,7 @@ static PassRefPtr<StringImpl> applySVGWhitespaceRules(PassRefPtr<StringImpl> str
RenderSVGInlineText::RenderSVGInlineText(Node* n, PassRefPtr<StringImpl> string)
: RenderText(n, applySVGWhitespaceRules(string, false))
+ , m_scalingFactor(1)
{
}
@@ -74,6 +78,8 @@ void RenderSVGInlineText::styleDidChange(StyleDifference diff, const RenderStyle
// The text metrics may be influenced by style changes.
if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this))
textRenderer->setNeedsPositioningValuesUpdate();
+
+ updateScaledFont();
}
const RenderStyle* newStyle = style();
@@ -103,12 +109,12 @@ IntRect RenderSVGInlineText::localCaretRect(InlineBox* box, int caretOffset, int
// Use the edge of the selection rect to determine the caret rect.
if (static_cast<unsigned>(caretOffset) < textBox->start() + textBox->len()) {
IntRect rect = textBox->selectionRect(0, 0, caretOffset, caretOffset + 1);
- int x = box->isLeftToRightDirection() ? rect.x() : rect.right();
+ int x = box->isLeftToRightDirection() ? rect.x() : rect.maxX();
return IntRect(x, rect.y(), caretWidth, rect.height());
}
IntRect rect = textBox->selectionRect(0, 0, caretOffset - 1, caretOffset);
- int x = box->isLeftToRightDirection() ? rect.right() : rect.x();
+ int x = box->isLeftToRightDirection() ? rect.maxX() : rect.x();
return IntRect(x, rect.y(), caretWidth, rect.height());
}
@@ -159,9 +165,7 @@ VisiblePosition RenderSVGInlineText::positionForPoint(const IntPoint& point)
if (!firstTextBox() || !textLength())
return createVisiblePosition(0, DOWNSTREAM);
- RenderStyle* style = this->style();
- ASSERT(style);
- int baseline = style->font().ascent();
+ float baseline = m_scaledFont.fontMetrics().floatAscent();
RenderBlock* containingBlock = this->containingBlock();
ASSERT(containingBlock);
@@ -206,6 +210,39 @@ VisiblePosition RenderSVGInlineText::positionForPoint(const IntPoint& point)
return createVisiblePosition(offset + closestDistanceBox->start(), offset > 0 ? VP_UPSTREAM_IF_POSSIBLE : DOWNSTREAM);
}
+void RenderSVGInlineText::updateScaledFont()
+{
+ computeNewScaledFontForStyle(this, style(), m_scalingFactor, m_scaledFont);
+}
+
+void RenderSVGInlineText::computeNewScaledFontForStyle(RenderObject* renderer, const RenderStyle* style, float& scalingFactor, Font& scaledFont)
+{
+ ASSERT(style);
+ ASSERT(renderer);
+
+ Document* document = renderer->document();
+ ASSERT(document);
+
+ CSSStyleSelector* styleSelector = document->styleSelector();
+ ASSERT(styleSelector);
+
+ // Alter font-size to the right on-screen value, to avoid scaling the glyphs themselves.
+ AffineTransform ctm;
+ SVGImageBufferTools::calculateTransformationToOutermostSVGCoordinateSystem(renderer, ctm);
+ scalingFactor = narrowPrecisionToFloat(sqrt((pow(ctm.xScale(), 2) + pow(ctm.yScale(), 2)) / 2));
+ if (scalingFactor == 1 || !scalingFactor) {
+ scalingFactor = 1;
+ scaledFont = style->font();
+ return;
+ }
+
+ FontDescription fontDescription(style->fontDescription());
+ fontDescription.setComputedSize(fontDescription.computedSize() * scalingFactor);
+
+ scaledFont = Font(fontDescription, 0, 0);
+ scaledFont.update(styleSelector->fontSelector());
+}
+
}
#endif // ENABLE(SVG)