2 * Copyright (C) 2007 Rob Buis <buis@kde.org>
3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
4 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #include "SVGInlineTextBox.h"
26 #include "FloatConversion.h"
27 #include "GraphicsContext.h"
28 #include "InlineFlowBox.h"
29 #include "RenderBlock.h"
30 #include "RenderSVGInlineText.h"
31 #include "RenderSVGResource.h"
32 #include "RenderSVGResourceSolidColor.h"
33 #include "SVGImageBufferTools.h"
34 #include "SVGRootInlineBox.h"
41 SVGInlineTextBox::SVGInlineTextBox(RenderObject* object)
42 : InlineTextBox(object)
44 , m_paintingResourceMode(ApplyToDefaultMode)
45 , m_startsNewTextChunk(false)
46 , m_paintingResource(0)
50 int SVGInlineTextBox::offsetForPosition(float, bool) const
52 // SVG doesn't use the standard offset <-> position selection system, as it's not suitable for SVGs complex needs.
53 // vertical text selection, inline boxes spanning multiple lines (contrary to HTML, etc.)
58 int SVGInlineTextBox::offsetForPositionInFragment(const SVGTextFragment& fragment, float position, bool includePartialGlyphs) const
60 RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
63 float scalingFactor = textRenderer->scalingFactor();
64 ASSERT(scalingFactor);
66 RenderStyle* style = textRenderer->style();
69 TextRun textRun(constructTextRun(style, fragment));
71 // Eventually handle lengthAdjust="spacingAndGlyphs".
72 // FIXME: Handle vertical text.
73 AffineTransform fragmentTransform;
74 fragment.buildFragmentTransform(fragmentTransform);
75 if (!fragmentTransform.isIdentity())
76 textRun.setHorizontalGlyphStretch(narrowPrecisionToFloat(fragmentTransform.xScale()));
78 return fragment.characterOffset - start() + textRenderer->scaledFont().offsetForPosition(textRun, position * scalingFactor, includePartialGlyphs);
81 float SVGInlineTextBox::positionForOffset(int) const
83 // SVG doesn't use the offset <-> position selection system.
88 FloatRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment& fragment, int startPosition, int endPosition, RenderStyle* style)
90 ASSERT(startPosition < endPosition);
93 RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
96 float scalingFactor = textRenderer->scalingFactor();
97 ASSERT(scalingFactor);
99 const Font& scaledFont = textRenderer->scaledFont();
100 const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics();
101 FloatPoint textOrigin(fragment.x, fragment.y);
102 if (scalingFactor != 1)
103 textOrigin.scale(scalingFactor, scalingFactor);
105 textOrigin.move(0, -scaledFontMetrics.floatAscent());
107 FloatRect selectionRect = scaledFont.selectionRectForText(constructTextRun(style, fragment), textOrigin, fragment.height * scalingFactor, startPosition, endPosition);
108 if (scalingFactor == 1)
109 return selectionRect;
111 selectionRect.scale(1 / scalingFactor);
112 return selectionRect;
115 IntRect SVGInlineTextBox::selectionRect(int, int, int startPosition, int endPosition)
117 int boxStart = start();
118 startPosition = max(startPosition - boxStart, 0);
119 endPosition = min(endPosition - boxStart, static_cast<int>(len()));
120 if (startPosition >= endPosition)
123 RenderText* text = textRenderer();
126 RenderStyle* style = text->style();
129 AffineTransform fragmentTransform;
130 FloatRect selectionRect;
131 int fragmentStartPosition = 0;
132 int fragmentEndPosition = 0;
134 unsigned textFragmentsSize = m_textFragments.size();
135 for (unsigned i = 0; i < textFragmentsSize; ++i) {
136 const SVGTextFragment& fragment = m_textFragments.at(i);
138 fragmentStartPosition = startPosition;
139 fragmentEndPosition = endPosition;
140 if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
143 FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style);
144 fragment.buildFragmentTransform(fragmentTransform);
145 if (!fragmentTransform.isIdentity())
146 fragmentRect = fragmentTransform.mapRect(fragmentRect);
148 selectionRect.unite(fragmentRect);
151 return enclosingIntRect(selectionRect);
154 static inline bool textShouldBePainted(RenderSVGInlineText* textRenderer)
156 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which returns "int(x + 0.5)".
157 // If the absolute font size on screen is below x=0.5, don't render anything.
158 return textRenderer->scaledFont().pixelSize();
161 void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo)
163 ASSERT(paintInfo.shouldPaintWithinRoot(renderer()));
164 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection);
165 ASSERT(truncation() == cNoTruncation);
167 if (renderer()->style()->visibility() != VISIBLE)
170 RenderObject* parentRenderer = parent()->renderer();
171 ASSERT(parentRenderer);
172 ASSERT(!parentRenderer->document()->printing());
174 // Determine whether or not we're selected.
175 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection;
176 bool hasSelection = selectionState() != RenderObject::SelectionNone;
177 if (!hasSelection || paintSelectedTextOnly)
180 Color backgroundColor = renderer()->selectionBackgroundColor();
181 if (!backgroundColor.isValid() || !backgroundColor.alpha())
184 RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
185 ASSERT(textRenderer);
186 if (!textShouldBePainted(textRenderer))
189 RenderStyle* style = parentRenderer->style();
192 const SVGRenderStyle* svgStyle = style->svgStyle();
195 bool hasFill = svgStyle->hasFill();
196 bool hasStroke = svgStyle->hasStroke();
198 RenderStyle* selectionStyle = style;
200 selectionStyle = parentRenderer->getCachedPseudoStyle(SELECTION);
201 if (selectionStyle) {
202 const SVGRenderStyle* svgSelectionStyle = selectionStyle->svgStyle();
203 ASSERT(svgSelectionStyle);
206 hasFill = svgSelectionStyle->hasFill();
208 hasStroke = svgSelectionStyle->hasStroke();
210 selectionStyle = style;
213 int startPosition, endPosition;
214 selectionStartEnd(startPosition, endPosition);
216 int fragmentStartPosition = 0;
217 int fragmentEndPosition = 0;
218 AffineTransform fragmentTransform;
219 unsigned textFragmentsSize = m_textFragments.size();
220 for (unsigned i = 0; i < textFragmentsSize; ++i) {
221 SVGTextFragment& fragment = m_textFragments.at(i);
222 ASSERT(!m_paintingResource);
224 fragmentStartPosition = startPosition;
225 fragmentEndPosition = endPosition;
226 if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
229 paintInfo.context->save();
230 fragment.buildFragmentTransform(fragmentTransform);
231 if (!fragmentTransform.isIdentity())
232 paintInfo.context->concatCTM(fragmentTransform);
234 paintInfo.context->setFillColor(backgroundColor, style->colorSpace());
235 paintInfo.context->fillRect(selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColor, style->colorSpace());
237 m_paintingResourceMode = ApplyToDefaultMode;
238 paintInfo.context->restore();
241 ASSERT(!m_paintingResource);
244 void SVGInlineTextBox::paint(PaintInfo& paintInfo, int, int, int, int)
246 ASSERT(paintInfo.shouldPaintWithinRoot(renderer()));
247 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection);
248 ASSERT(truncation() == cNoTruncation);
250 if (renderer()->style()->visibility() != VISIBLE)
253 // Note: We're explicitely not supporting composition & custom underlines and custom highlighters - unlike InlineTextBox.
254 // If we ever need that for SVG, it's very easy to refactor and reuse the code.
256 RenderObject* parentRenderer = parent()->renderer();
257 ASSERT(parentRenderer);
259 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection;
260 bool hasSelection = !parentRenderer->document()->printing() && selectionState() != RenderObject::SelectionNone;
261 if (!hasSelection && paintSelectedTextOnly)
264 RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
265 ASSERT(textRenderer);
266 if (!textShouldBePainted(textRenderer))
269 RenderStyle* style = parentRenderer->style();
272 const SVGRenderStyle* svgStyle = style->svgStyle();
275 bool hasFill = svgStyle->hasFill();
276 bool hasStroke = svgStyle->hasStroke();
278 RenderStyle* selectionStyle = style;
280 selectionStyle = parentRenderer->getCachedPseudoStyle(SELECTION);
281 if (selectionStyle) {
282 const SVGRenderStyle* svgSelectionStyle = selectionStyle->svgStyle();
283 ASSERT(svgSelectionStyle);
286 hasFill = svgSelectionStyle->hasFill();
288 hasStroke = svgSelectionStyle->hasStroke();
290 selectionStyle = style;
293 AffineTransform fragmentTransform;
294 unsigned textFragmentsSize = m_textFragments.size();
295 for (unsigned i = 0; i < textFragmentsSize; ++i) {
296 SVGTextFragment& fragment = m_textFragments.at(i);
297 ASSERT(!m_paintingResource);
299 paintInfo.context->save();
300 fragment.buildFragmentTransform(fragmentTransform);
301 if (!fragmentTransform.isIdentity())
302 paintInfo.context->concatCTM(fragmentTransform);
304 // Spec: All text decorations except line-through should be drawn before the text is filled and stroked; thus, the text is rendered on top of these decorations.
305 int decorations = style->textDecorationsInEffect();
306 if (decorations & UNDERLINE)
307 paintDecoration(paintInfo.context, UNDERLINE, fragment);
308 if (decorations & OVERLINE)
309 paintDecoration(paintInfo.context, OVERLINE, fragment);
313 m_paintingResourceMode = ApplyToFillMode | ApplyToTextMode;
314 paintText(paintInfo.context, style, selectionStyle, fragment, hasSelection, paintSelectedTextOnly);
319 m_paintingResourceMode = ApplyToStrokeMode | ApplyToTextMode;
320 paintText(paintInfo.context, style, selectionStyle, fragment, hasSelection, paintSelectedTextOnly);
323 // Spec: Line-through should be drawn after the text is filled and stroked; thus, the line-through is rendered on top of the text.
324 if (decorations & LINE_THROUGH)
325 paintDecoration(paintInfo.context, LINE_THROUGH, fragment);
327 m_paintingResourceMode = ApplyToDefaultMode;
328 paintInfo.context->restore();
331 ASSERT(!m_paintingResource);
334 bool SVGInlineTextBox::acquirePaintingResource(GraphicsContext*& context, float scalingFactor, RenderObject* renderer, RenderStyle* style)
336 ASSERT(scalingFactor);
339 ASSERT(m_paintingResourceMode != ApplyToDefaultMode);
342 if (m_paintingResourceMode & ApplyToFillMode)
343 m_paintingResource = RenderSVGResource::fillPaintingResource(renderer, style, fallbackColor);
344 else if (m_paintingResourceMode & ApplyToStrokeMode)
345 m_paintingResource = RenderSVGResource::strokePaintingResource(renderer, style, fallbackColor);
347 // We're either called for stroking or filling.
348 ASSERT_NOT_REACHED();
351 if (!m_paintingResource)
354 if (!m_paintingResource->applyResource(renderer, style, context, m_paintingResourceMode)) {
355 if (fallbackColor.isValid()) {
356 RenderSVGResourceSolidColor* fallbackResource = RenderSVGResource::sharedSolidPaintingResource();
357 fallbackResource->setColor(fallbackColor);
359 m_paintingResource = fallbackResource;
360 m_paintingResource->applyResource(renderer, style, context, m_paintingResourceMode);
364 if (scalingFactor != 1 && m_paintingResourceMode & ApplyToStrokeMode)
365 context->setStrokeThickness(context->strokeThickness() * scalingFactor);
370 void SVGInlineTextBox::releasePaintingResource(GraphicsContext*& context, const Path* path)
372 ASSERT(m_paintingResource);
374 RenderObject* parentRenderer = parent()->renderer();
375 ASSERT(parentRenderer);
377 m_paintingResource->postApplyResource(parentRenderer, context, m_paintingResourceMode, path);
378 m_paintingResource = 0;
381 bool SVGInlineTextBox::prepareGraphicsContextForTextPainting(GraphicsContext*& context, float scalingFactor, TextRun& textRun, RenderStyle* style)
383 bool acquiredResource = acquirePaintingResource(context, scalingFactor, parent()->renderer(), style);
385 #if ENABLE(SVG_FONTS)
386 // SVG Fonts need access to the painting resource used to draw the current text chunk.
387 if (acquiredResource)
388 textRun.setActivePaintingResource(m_paintingResource);
391 return acquiredResource;
394 void SVGInlineTextBox::restoreGraphicsContextAfterTextPainting(GraphicsContext*& context, TextRun& textRun)
396 releasePaintingResource(context, /* path */0);
398 #if ENABLE(SVG_FONTS)
399 textRun.setActivePaintingResource(0);
403 TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFragment& fragment) const
406 ASSERT(textRenderer());
408 RenderText* text = textRenderer();
411 TextRun run(text->characters() + fragment.characterOffset
413 , false /* allowTabs */
414 , 0 /* xPos, only relevant with allowTabs=true */
415 , 0 /* padding, only relevant for justified text, not relevant for SVG */
416 , TextRun::AllowTrailingExpansion
418 , m_dirOverride || style->visuallyOrdered() /* directionalOverride */);
420 #if ENABLE(SVG_FONTS)
421 run.setReferencingRenderObject(text);
424 // We handle letter & word spacing ourselves.
425 run.disableSpacing();
429 bool SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates(const SVGTextFragment& fragment, int& startPosition, int& endPosition) const
431 if (startPosition >= endPosition)
434 int offset = static_cast<int>(fragment.characterOffset) - start();
435 int length = static_cast<int>(fragment.length);
437 if (startPosition >= offset + length || endPosition <= offset)
440 if (startPosition < offset)
443 startPosition -= offset;
445 if (endPosition > offset + length)
446 endPosition = length;
448 ASSERT(endPosition >= offset);
449 endPosition -= offset;
452 ASSERT(startPosition < endPosition);
456 static inline float positionOffsetForDecoration(ETextDecoration decoration, const FontMetrics& fontMetrics, float thickness)
458 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-face> if specified.
459 // Compatible with Batik/Opera.
460 if (decoration == UNDERLINE)
461 return fontMetrics.floatAscent() + thickness * 1.5f;
462 if (decoration == OVERLINE)
464 if (decoration == LINE_THROUGH)
465 return fontMetrics.floatAscent() * 5 / 8.0f;
467 ASSERT_NOT_REACHED();
471 static inline float thicknessForDecoration(ETextDecoration, const Font& font)
473 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-face> if specified.
474 // Compatible with Batik/Opera
475 return font.size() / 20.0f;
478 static inline RenderObject* findRenderObjectDefininingTextDecoration(InlineFlowBox* parentBox)
480 // Lookup first render object in parent hierarchy which has text-decoration set.
481 RenderObject* renderer = 0;
483 renderer = parentBox->renderer();
485 if (renderer->style() && renderer->style()->textDecoration() != TDNONE)
488 parentBox = parentBox->parent();
495 void SVGInlineTextBox::paintDecoration(GraphicsContext* context, ETextDecoration decoration, const SVGTextFragment& fragment)
497 if (textRenderer()->style()->textDecorationsInEffect() == TDNONE)
500 // Find out which render style defined the text-decoration, as its fill/stroke properties have to be used for drawing instead of ours.
501 RenderObject* decorationRenderer = findRenderObjectDefininingTextDecoration(parent());
502 RenderStyle* decorationStyle = decorationRenderer->style();
503 ASSERT(decorationStyle);
505 if (decorationStyle->visibility() == HIDDEN)
508 const SVGRenderStyle* svgDecorationStyle = decorationStyle->svgStyle();
509 ASSERT(svgDecorationStyle);
511 bool hasDecorationFill = svgDecorationStyle->hasFill();
512 bool hasDecorationStroke = svgDecorationStyle->hasStroke();
514 if (hasDecorationFill) {
515 m_paintingResourceMode = ApplyToFillMode;
516 paintDecorationWithStyle(context, decoration, fragment, decorationRenderer);
519 if (hasDecorationStroke) {
520 m_paintingResourceMode = ApplyToStrokeMode;
521 paintDecorationWithStyle(context, decoration, fragment, decorationRenderer);
525 static inline void normalizeTransform(AffineTransform& transform)
527 // Obtain consistent numerical results for the AffineTransform on both 32/64bit platforms.
528 // Tested with SnowLeopard on Core Duo vs. Core 2 Duo.
529 static const float s_floatEpsilon = std::numeric_limits<float>::epsilon();
531 if (fabs(transform.a() - 1) <= s_floatEpsilon)
533 else if (fabs(transform.a() + 1) <= s_floatEpsilon)
536 if (fabs(transform.d() - 1) <= s_floatEpsilon)
538 else if (fabs(transform.d() + 1) <= s_floatEpsilon)
541 if (fabs(transform.e()) <= s_floatEpsilon)
544 if (fabs(transform.f()) <= s_floatEpsilon)
548 void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, ETextDecoration decoration, const SVGTextFragment& fragment, RenderObject* decorationRenderer)
550 ASSERT(!m_paintingResource);
551 ASSERT(m_paintingResourceMode != ApplyToDefaultMode);
553 RenderStyle* decorationStyle = decorationRenderer->style();
554 ASSERT(decorationStyle);
556 float scalingFactor = 1;
558 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decorationStyle, scalingFactor, scaledFont);
559 ASSERT(scalingFactor);
561 // The initial y value refers to overline position.
562 float thickness = thicknessForDecoration(decoration, scaledFont);
564 if (fragment.width <= 0 && thickness <= 0)
567 FloatPoint decorationOrigin(fragment.x, fragment.y);
568 float width = fragment.width;
569 const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics();
572 if (scalingFactor != 1) {
573 width *= scalingFactor;
574 decorationOrigin.scale(scalingFactor, scalingFactor);
576 AffineTransform newTransform = context->getCTM();
577 newTransform.scale(1 / scalingFactor);
578 normalizeTransform(newTransform);
580 context->setCTM(newTransform);
583 decorationOrigin.move(0, -scaledFontMetrics.floatAscent() + positionOffsetForDecoration(decoration, scaledFontMetrics, thickness));
586 path.addRect(FloatRect(decorationOrigin, FloatSize(width, thickness)));
588 if (acquirePaintingResource(context, scalingFactor, decorationRenderer, decorationStyle))
589 releasePaintingResource(context, &path);
594 void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyle* style, TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int endPosition)
596 RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
597 ASSERT(textRenderer);
599 float scalingFactor = textRenderer->scalingFactor();
600 ASSERT(scalingFactor);
602 const Font& scaledFont = textRenderer->scaledFont();
603 const ShadowData* shadow = style->textShadow();
605 FloatPoint textOrigin(fragment.x, fragment.y);
606 FloatSize textSize(fragment.width, fragment.height);
608 if (scalingFactor != 1) {
609 textOrigin.scale(scalingFactor, scalingFactor);
610 textSize.scale(scalingFactor);
613 FloatRect shadowRect(FloatPoint(textOrigin.x(), textOrigin.y() - scaledFont.fontMetrics().floatAscent()), textSize);
616 if (!prepareGraphicsContextForTextPainting(context, scalingFactor, textRun, style))
619 FloatSize extraOffset;
621 extraOffset = applyShadowToGraphicsContext(context, shadow, shadowRect, false /* stroked */, true /* opaque */, true /* horizontal */);
623 AffineTransform originalTransform;
624 if (scalingFactor != 1) {
625 originalTransform = context->getCTM();
627 AffineTransform newTransform = originalTransform;
628 newTransform.scale(1 / scalingFactor);
629 normalizeTransform(newTransform);
631 context->setCTM(newTransform);
634 scaledFont.drawText(context, textRun, textOrigin + extraOffset, startPosition, endPosition);
636 if (scalingFactor != 1)
637 context->setCTM(originalTransform);
639 restoreGraphicsContextAfterTextPainting(context, textRun);
647 context->clearShadow();
649 shadow = shadow->next();
653 void SVGInlineTextBox::paintText(GraphicsContext* context, RenderStyle* style, RenderStyle* selectionStyle, const SVGTextFragment& fragment, bool hasSelection, bool paintSelectedTextOnly)
656 ASSERT(selectionStyle);
658 int startPosition = 0;
661 selectionStartEnd(startPosition, endPosition);
662 hasSelection = mapStartEndPositionsIntoFragmentCoordinates(fragment, startPosition, endPosition);
665 // Fast path if there is no selection, just draw the whole chunk part using the regular style
666 TextRun textRun(constructTextRun(style, fragment));
667 if (!hasSelection || startPosition >= endPosition) {
668 paintTextWithShadows(context, style, textRun, fragment, 0, fragment.length);
672 // Eventually draw text using regular style until the start position of the selection
673 if (startPosition > 0 && !paintSelectedTextOnly)
674 paintTextWithShadows(context, style, textRun, fragment, 0, startPosition);
676 // Draw text using selection style from the start to the end position of the selection
677 if (style != selectionStyle)
678 SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, selectionStyle);
680 TextRun selectionTextRun(constructTextRun(selectionStyle, fragment));
681 paintTextWithShadows(context, selectionStyle, textRun, fragment, startPosition, endPosition);
683 if (style != selectionStyle)
684 SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, style);
686 // Eventually draw text using regular style from the end position of the selection to the end of the current chunk part
687 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnly)
688 paintTextWithShadows(context, style, textRun, fragment, endPosition, fragment.length);
691 IntRect SVGInlineTextBox::calculateBoundaries() const
695 RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
696 ASSERT(textRenderer);
698 float scalingFactor = textRenderer->scalingFactor();
699 ASSERT(scalingFactor);
701 float baseline = textRenderer->scaledFont().fontMetrics().floatAscent() / scalingFactor;
703 AffineTransform fragmentTransform;
704 unsigned textFragmentsSize = m_textFragments.size();
705 for (unsigned i = 0; i < textFragmentsSize; ++i) {
706 const SVGTextFragment& fragment = m_textFragments.at(i);
707 FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.width, fragment.height);
708 fragment.buildFragmentTransform(fragmentTransform);
709 if (!fragmentTransform.isIdentity())
710 fragmentRect = fragmentTransform.mapRect(fragmentRect);
712 textRect.unite(fragmentRect);
715 return enclosingIntRect(textRect);
718 } // namespace WebCore