FloatRectWillBeLayoutRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment& fragment, int startPosition, int endPosition, RenderStyle* style) { ASSERT(startPosition < endPosition); ASSERT(style); RenderSVGInlineText& textRenderer = toRenderSVGInlineText(this->renderer()); FloatWillBeLayoutUnit scalingFactor = textRenderer.scalingFactor(); ASSERT(scalingFactor); const Font& scaledFont = textRenderer.scaledFont(); const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics(); FloatPointWillBeLayoutPoint textOrigin(fragment.x, fragment.y); if (scalingFactor != 1) textOrigin.scale(scalingFactor, scalingFactor); textOrigin.move(0, -scaledFontMetrics.floatAscent()); FloatRectWillBeLayoutRect selectionRect = scaledFont.selectionRectForText(constructTextRun(style, fragment), textOrigin, fragment.height * scalingFactor, startPosition, endPosition); if (scalingFactor == 1) return selectionRect; selectionRect.scale(1 / scalingFactor); return selectionRect; }
FloatRectWillBeLayoutRect SVGInlineTextBox::calculateBoundaries() const { FloatRectWillBeLayoutRect textRect; LayoutSVGInlineText& textLayoutObject = toLayoutSVGInlineText(this->layoutObject()); float scalingFactor = textLayoutObject.scalingFactor(); ASSERT(scalingFactor); FloatWillBeLayoutUnit baseline = textLayoutObject.scaledFont().fontMetrics().floatAscent() / scalingFactor; AffineTransform fragmentTransform; unsigned textFragmentsSize = m_textFragments.size(); for (unsigned i = 0; i < textFragmentsSize; ++i) { const SVGTextFragment& fragment = m_textFragments.at(i); FloatRectWillBeLayoutRect fragmentRect(fragment.x, fragment.y - baseline, fragment.width, fragment.height); fragment.buildFragmentTransform(fragmentTransform); fragmentRect = fragmentTransform.mapRect(fragmentRect.toFloatRect()); textRect.unite(fragmentRect); } return textRect; }
LayoutRect SVGInlineTextBox::localSelectionRect(int startPosition, int endPosition) { int boxStart = start(); startPosition = std::max(startPosition - boxStart, 0); endPosition = std::min(endPosition - boxStart, static_cast<int>(len())); if (startPosition >= endPosition) return LayoutRect(); RenderStyle* style = renderer().style(); ASSERT(style); AffineTransform fragmentTransform; FloatRectWillBeLayoutRect selectionRect; int fragmentStartPosition = 0; int fragmentEndPosition = 0; unsigned textFragmentsSize = m_textFragments.size(); for (unsigned i = 0; i < textFragmentsSize; ++i) { const SVGTextFragment& fragment = m_textFragments.at(i); fragmentStartPosition = startPosition; fragmentEndPosition = endPosition; if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition)) continue; FloatRectWillBeLayoutRect fragmentRect = selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style); fragment.buildFragmentTransform(fragmentTransform); fragmentRect = fragmentTransform.mapRect(fragmentRect); selectionRect.unite(fragmentRect); } // FIXME: the call to rawValue() below is temporary and should be removed once the transition // to LayoutUnit-based types is complete (crbug.com/321237) return enclosingIntRect(selectionRect.rawValue()); }