diff options
Diffstat (limited to 'Source/WebCore/rendering/svg/RenderSVGInlineText.cpp')
-rw-r--r-- | Source/WebCore/rendering/svg/RenderSVGInlineText.cpp | 77 |
1 files changed, 37 insertions, 40 deletions
diff --git a/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp b/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp index 0667e8479..5aebea8ab 100644 --- a/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp +++ b/Source/WebCore/rendering/svg/RenderSVGInlineText.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz> - * Copyright (C) 2006 Apple Computer Inc. + * Copyright (C) 2006 Apple Inc. * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> * Copyright (C) 2008 Rob Buis <buis@kde.org> * Copyright (C) Research In Motion Limited 2010. All rights reserved. @@ -22,8 +22,6 @@ */ #include "config.h" - -#if ENABLE(SVG) #include "RenderSVGInlineText.h" #include "CSSFontSelector.h" @@ -32,7 +30,6 @@ #include "RenderBlock.h" #include "RenderSVGRoot.h" #include "RenderSVGText.h" -#include "Settings.h" #include "SVGInlineTextBox.h" #include "SVGRenderingContext.h" #include "SVGRootInlineBox.h" @@ -79,11 +76,11 @@ String RenderSVGInlineText::originalText() const return textNode().data(); } -void RenderSVGInlineText::setTextInternal(const String& text) +void RenderSVGInlineText::setRenderedText(const String& text) { - RenderText::setTextInternal(text); - if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this)) - textRenderer->subtreeTextDidChange(this); + RenderText::setRenderedText(text); + if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this)) + textAncestor->subtreeTextDidChange(this); } void RenderSVGInlineText::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) @@ -107,35 +104,35 @@ void RenderSVGInlineText::styleDidChange(StyleDifference diff, const RenderStyle return; // The text metrics may be influenced by style changes. - if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(this)) - textRenderer->subtreeStyleDidChange(this); + if (auto* textAncestor = RenderSVGText::locateRenderSVGTextAncestor(*this)) + textAncestor->subtreeStyleDidChange(this); } std::unique_ptr<InlineTextBox> RenderSVGInlineText::createTextBox() { auto box = std::make_unique<SVGInlineTextBox>(*this); box->setHasVirtualLogicalHeight(); - return std::move(box); + return WTFMove(box); } -LayoutRect RenderSVGInlineText::localCaretRect(InlineBox* box, int caretOffset, LayoutUnit*) +LayoutRect RenderSVGInlineText::localCaretRect(InlineBox* box, unsigned caretOffset, LayoutUnit*) { - if (!box || !box->isInlineTextBox()) + if (!is<InlineTextBox>(box)) return LayoutRect(); - InlineTextBox* textBox = toInlineTextBox(box); - if (static_cast<unsigned>(caretOffset) < textBox->start() || static_cast<unsigned>(caretOffset) > textBox->start() + textBox->len()) + auto& textBox = downcast<InlineTextBox>(*box); + if (caretOffset < textBox.start() || caretOffset > textBox.start() + textBox.len()) return LayoutRect(); // Use the edge of the selection rect to determine the caret rect. - if (static_cast<unsigned>(caretOffset) < textBox->start() + textBox->len()) { - LayoutRect rect = textBox->localSelectionRect(caretOffset, caretOffset + 1); - LayoutUnit x = box->isLeftToRightDirection() ? rect.x() : rect.maxX(); + if (caretOffset < textBox.start() + textBox.len()) { + LayoutRect rect = textBox.localSelectionRect(caretOffset, caretOffset + 1); + LayoutUnit x = textBox.isLeftToRightDirection() ? rect.x() : rect.maxX(); return LayoutRect(x, rect.y(), caretWidth, rect.height()); } - LayoutRect rect = textBox->localSelectionRect(caretOffset - 1, caretOffset); - LayoutUnit x = box->isLeftToRightDirection() ? rect.maxX() : rect.x(); + LayoutRect rect = textBox.localSelectionRect(caretOffset - 1, caretOffset); + LayoutUnit x = textBox.isLeftToRightDirection() ? rect.maxX() : rect.x(); return LayoutRect(x, rect.y(), caretWidth, rect.height()); } @@ -168,7 +165,7 @@ bool RenderSVGInlineText::characterStartsNewTextChunk(int position) const return it->value.x != SVGTextLayoutAttributes::emptyValue() || it->value.y != SVGTextLayoutAttributes::emptyValue(); } -VisiblePosition RenderSVGInlineText::positionForPoint(const LayoutPoint& point) +VisiblePosition RenderSVGInlineText::positionForPoint(const LayoutPoint& point, const RenderRegion*) { if (!firstTextBox() || !textLength()) return createVisiblePosition(0, DOWNSTREAM); @@ -184,16 +181,16 @@ VisiblePosition RenderSVGInlineText::positionForPoint(const LayoutPoint& point) float closestDistance = std::numeric_limits<float>::max(); float closestDistancePosition = 0; - const SVGTextFragment* closestDistanceFragment = 0; - SVGInlineTextBox* closestDistanceBox = 0; + const SVGTextFragment* closestDistanceFragment = nullptr; + SVGInlineTextBox* closestDistanceBox = nullptr; AffineTransform fragmentTransform; for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) { - if (!box->isSVGInlineTextBox()) + if (!is<SVGInlineTextBox>(*box)) continue; - SVGInlineTextBox* textBox = toSVGInlineTextBox(box); - Vector<SVGTextFragment>& fragments = textBox->textFragments(); + auto& textBox = downcast<SVGInlineTextBox>(*box); + Vector<SVGTextFragment>& fragments = textBox.textFragments(); unsigned textFragmentsSize = fragments.size(); for (unsigned i = 0; i < textFragmentsSize; ++i) { @@ -208,7 +205,7 @@ VisiblePosition RenderSVGInlineText::positionForPoint(const LayoutPoint& point) if (distance < closestDistance) { closestDistance = distance; - closestDistanceBox = textBox; + closestDistanceBox = &textBox; closestDistanceFragment = &fragment; closestDistancePosition = fragmentRect.x(); } @@ -224,31 +221,31 @@ VisiblePosition RenderSVGInlineText::positionForPoint(const LayoutPoint& point) void RenderSVGInlineText::updateScaledFont() { - computeNewScaledFontForStyle(this, &style(), m_scalingFactor, m_scaledFont); + computeNewScaledFontForStyle(*this, style(), m_scalingFactor, m_scaledFont); } -void RenderSVGInlineText::computeNewScaledFontForStyle(RenderObject* renderer, const RenderStyle* style, float& scalingFactor, Font& scaledFont) +void RenderSVGInlineText::computeNewScaledFontForStyle(const RenderObject& renderer, const RenderStyle& style, float& scalingFactor, FontCascade& scaledFont) { - ASSERT(style); - ASSERT(renderer); - // Alter font-size to the right on-screen value to avoid scaling the glyphs themselves, except when GeometricPrecision is specified scalingFactor = SVGRenderingContext::calculateScreenFontSizeScalingFactor(renderer); - if (scalingFactor == 1 || !scalingFactor || style->fontDescription().textRenderingMode() == GeometricPrecision) { + if (!scalingFactor || style.fontDescription().textRenderingMode() == GeometricPrecision) { scalingFactor = 1; - scaledFont = style->font(); + scaledFont = style.fontCascade(); return; } - FontDescription fontDescription(style->fontDescription()); + auto fontDescription = style.fontDescription(); // FIXME: We need to better handle the case when we compute very small fonts below (below 1pt). - fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSizeForSVGInlineText(fontDescription.computedSize(), fontDescription.isAbsoluteSize(), scalingFactor, renderer->document())); + fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSizeForSVGInlineText(fontDescription.computedSize(), fontDescription.isAbsoluteSize(), scalingFactor, renderer.document())); - scaledFont = Font(fontDescription, 0, 0); - scaledFont.update(renderer->document().ensureStyleResolver().fontSelector()); -} + // SVG controls its own glyph orientation, so don't allow writing-mode + // to affect it. + if (fontDescription.orientation() != FontOrientation::Horizontal) + fontDescription.setOrientation(FontOrientation::Horizontal); + scaledFont = FontCascade(fontDescription, 0, 0); + scaledFont.update(&renderer.document().fontSelector()); } -#endif // ENABLE(SVG) +} |