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 "FontCache.h"
28 #include "GraphicsContext.h"
29 #include "HitTestResult.h"
30 #include "InlineFlowBox.h"
31 #include "PointerEventsHitRules.h"
32 #include "RenderBlock.h"
33 #include "RenderSVGInlineText.h"
34 #include "RenderSVGResource.h"
35 #include "RenderSVGResourceSolidColor.h"
36 #include "SVGImageBufferTools.h"
37 #include "SVGRootInlineBox.h"
38 #include "SVGTextRunRenderingContext.h"
44 SVGInlineTextBox::SVGInlineTextBox(RenderObject* object)
45 : InlineTextBox(object)
47 , m_paintingResourceMode(ApplyToDefaultMode)
48 , m_startsNewTextChunk(false)
49 , m_paintingResource(0)
53 int SVGInlineTextBox::offsetForPosition(float, bool) const
55 // SVG doesn't use the standard offset <-> position selection system, as it's not suitable for SVGs complex needs.
56 // vertical text selection, inline boxes spanning multiple lines (contrary to HTML, etc.)
61 int SVGInlineTextBox::offsetForPositionInFragment(const SVGTextFragment& fragment, float position, bool includePartialGlyphs) const
63 RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
66 float scalingFactor = textRenderer->scalingFactor();
67 ASSERT(scalingFactor);
69 RenderStyle* style = textRenderer->style();
72 TextRun textRun = constructTextRun(style, fragment);
74 // Eventually handle lengthAdjust="spacingAndGlyphs".
75 // FIXME: Handle vertical text.
76 AffineTransform fragmentTransform;
77 fragment.buildFragmentTransform(fragmentTransform);
78 if (!fragmentTransform.isIdentity())
79 textRun.setHorizontalGlyphStretch(narrowPrecisionToFloat(fragmentTransform.xScale()));
81 return fragment.characterOffset - start() + textRenderer->scaledFont().offsetForPosition(textRun, position * scalingFactor, includePartialGlyphs);
84 float SVGInlineTextBox::positionForOffset(int) const
86 // SVG doesn't use the offset <-> position selection system.
91 FloatRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment& fragment, int startPosition, int endPosition, RenderStyle* style)
93 ASSERT(startPosition < endPosition);
96 FontCachePurgePreventer fontCachePurgePreventer;
98 RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
101 float scalingFactor = textRenderer->scalingFactor();
102 ASSERT(scalingFactor);
104 const Font& scaledFont = textRenderer->scaledFont();
105 const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics();
106 FloatPoint textOrigin(fragment.x, fragment.y);
107 if (scalingFactor != 1)
108 textOrigin.scale(scalingFactor, scalingFactor);
110 textOrigin.move(0, -scaledFontMetrics.floatAscent());
112 FloatRect selectionRect = scaledFont.selectionRectForText(constructTextRun(style, fragment), textOrigin, fragment.height * scalingFactor, startPosition, endPosition);
113 if (scalingFactor == 1)
114 return selectionRect;
116 selectionRect.scale(1 / scalingFactor);
117 return selectionRect;
120 IntRect SVGInlineTextBox::localSelectionRect(int startPosition, int endPosition)
122 int boxStart = start();
123 startPosition = max(startPosition - boxStart, 0);
124 endPosition = min(endPosition - boxStart, static_cast<int>(len()));
125 if (startPosition >= endPosition)
128 RenderText* text = textRenderer();
131 RenderStyle* style = text->style();
134 AffineTransform fragmentTransform;
135 FloatRect selectionRect;
136 int fragmentStartPosition = 0;
137 int fragmentEndPosition = 0;
139 unsigned textFragmentsSize = m_textFragments.size();
140 for (unsigned i = 0; i < textFragmentsSize; ++i) {
141 const SVGTextFragment& fragment = m_textFragments.at(i);
143 fragmentStartPosition = startPosition;
144 fragmentEndPosition = endPosition;
145 if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
148 FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style);
149 fragment.buildFragmentTransform(fragmentTransform);
150 if (!fragmentTransform.isIdentity())
151 fragmentRect = fragmentTransform.mapRect(fragmentRect);
153 selectionRect.unite(fragmentRect);
156 return enclosingIntRect(selectionRect);
159 static inline bool textShouldBePainted(RenderSVGInlineText* textRenderer)
161 // Font::pixelSize(), returns FontDescription::computedPixelSize(), which returns "int(x + 0.5)".
162 // If the absolute font size on screen is below x=0.5, don't render anything.
163 return textRenderer->scaledFont().pixelSize();
166 void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo)
168 ASSERT(paintInfo.shouldPaintWithinRoot(renderer()));
169 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection);
170 ASSERT(truncation() == cNoTruncation);
172 if (renderer()->style()->visibility() != VISIBLE)
175 RenderObject* parentRenderer = parent()->renderer();
176 ASSERT(parentRenderer);
177 ASSERT(!parentRenderer->document()->printing());
179 // Determine whether or not we're selected.
180 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection;
181 bool hasSelection = selectionState() != RenderObject::SelectionNone;
182 if (!hasSelection || paintSelectedTextOnly)
185 Color backgroundColor = renderer()->selectionBackgroundColor();
186 if (!backgroundColor.isValid() || !backgroundColor.alpha())
189 RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
190 ASSERT(textRenderer);
191 if (!textShouldBePainted(textRenderer))
194 RenderStyle* style = parentRenderer->style();
197 const SVGRenderStyle* svgStyle = style->svgStyle();
200 bool hasFill = svgStyle->hasFill();
201 bool hasStroke = svgStyle->hasStroke();
203 RenderStyle* selectionStyle = style;
205 selectionStyle = parentRenderer->getCachedPseudoStyle(SELECTION);
206 if (selectionStyle) {
207 const SVGRenderStyle* svgSelectionStyle = selectionStyle->svgStyle();
208 ASSERT(svgSelectionStyle);
211 hasFill = svgSelectionStyle->hasFill();
213 hasStroke = svgSelectionStyle->hasStroke();
215 selectionStyle = style;
218 int startPosition, endPosition;
219 selectionStartEnd(startPosition, endPosition);
221 int fragmentStartPosition = 0;
222 int fragmentEndPosition = 0;
223 AffineTransform fragmentTransform;
224 unsigned textFragmentsSize = m_textFragments.size();
225 for (unsigned i = 0; i < textFragmentsSize; ++i) {
226 SVGTextFragment& fragment = m_textFragments.at(i);
227 ASSERT(!m_paintingResource);
229 fragmentStartPosition = startPosition;
230 fragmentEndPosition = endPosition;
231 if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
234 GraphicsContextStateSaver stateSaver(*paintInfo.context);
235 fragment.buildFragmentTransform(fragmentTransform);
236 if (!fragmentTransform.isIdentity())
237 paintInfo.context->concatCTM(fragmentTransform);
239 paintInfo.context->setFillColor(backgroundColor, style->colorSpace());
240 paintInfo.context->fillRect(selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColor, style->colorSpace());
242 m_paintingResourceMode = ApplyToDefaultMode;
245 ASSERT(!m_paintingResource);
248 void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint&, LayoutUnit, LayoutUnit)
250 ASSERT(paintInfo.shouldPaintWithinRoot(renderer()));
251 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection);
252 ASSERT(truncation() == cNoTruncation);
254 if (renderer()->style()->visibility() != VISIBLE)
257 // Note: We're explicitely not supporting composition & custom underlines and custom highlighters - unlike InlineTextBox.
258 // If we ever need that for SVG, it's very easy to refactor and reuse the code.
260 RenderObject* parentRenderer = parent()->renderer();
261 ASSERT(parentRenderer);
263 bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection;
264 bool hasSelection = !parentRenderer->document()->printing() && selectionState() != RenderObject::SelectionNone;
265 if (!hasSelection && paintSelectedTextOnly)
268 RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
269 ASSERT(textRenderer);
270 if (!textShouldBePainted(textRenderer))
273 RenderStyle* style = parentRenderer->style();
276 const SVGRenderStyle* svgStyle = style->svgStyle();
279 bool hasFill = svgStyle->hasFill();
280 bool hasStroke = svgStyle->hasStroke();
282 RenderStyle* selectionStyle = style;
284 selectionStyle = parentRenderer->getCachedPseudoStyle(SELECTION);
285 if (selectionStyle) {
286 const SVGRenderStyle* svgSelectionStyle = selectionStyle->svgStyle();
287 ASSERT(svgSelectionStyle);
290 hasFill = svgSelectionStyle->hasFill();
292 hasStroke = svgSelectionStyle->hasStroke();
294 selectionStyle = style;
297 AffineTransform fragmentTransform;
298 unsigned textFragmentsSize = m_textFragments.size();
299 for (unsigned i = 0; i < textFragmentsSize; ++i) {
300 SVGTextFragment& fragment = m_textFragments.at(i);
301 ASSERT(!m_paintingResource);
303 GraphicsContextStateSaver stateSaver(*paintInfo.context);
304 fragment.buildFragmentTransform(fragmentTransform);
305 if (!fragmentTransform.isIdentity())
306 paintInfo.context->concatCTM(fragmentTransform);
308 // 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.
309 int decorations = style->textDecorationsInEffect();
310 if (decorations & UNDERLINE)
311 paintDecoration(paintInfo.context, UNDERLINE, fragment);
312 if (decorations & OVERLINE)
313 paintDecoration(paintInfo.context, OVERLINE, fragment);
317 m_paintingResourceMode = ApplyToFillMode | ApplyToTextMode;
318 paintText(paintInfo.context, style, selectionStyle, fragment, hasSelection, paintSelectedTextOnly);
323 m_paintingResourceMode = ApplyToStrokeMode | ApplyToTextMode;
324 paintText(paintInfo.context, style, selectionStyle, fragment, hasSelection, paintSelectedTextOnly);
327 // Spec: Line-through should be drawn after the text is filled and stroked; thus, the line-through is rendered on top of the text.
328 if (decorations & LINE_THROUGH)
329 paintDecoration(paintInfo.context, LINE_THROUGH, fragment);
331 m_paintingResourceMode = ApplyToDefaultMode;
334 ASSERT(!m_paintingResource);
337 bool SVGInlineTextBox::acquirePaintingResource(GraphicsContext*& context, float scalingFactor, RenderObject* renderer, RenderStyle* style)
339 ASSERT(scalingFactor);
342 ASSERT(m_paintingResourceMode != ApplyToDefaultMode);
345 if (m_paintingResourceMode & ApplyToFillMode)
346 m_paintingResource = RenderSVGResource::fillPaintingResource(renderer, style, fallbackColor);
347 else if (m_paintingResourceMode & ApplyToStrokeMode)
348 m_paintingResource = RenderSVGResource::strokePaintingResource(renderer, style, fallbackColor);
350 // We're either called for stroking or filling.
351 ASSERT_NOT_REACHED();
354 if (!m_paintingResource)
357 if (!m_paintingResource->applyResource(renderer, style, context, m_paintingResourceMode)) {
358 if (fallbackColor.isValid()) {
359 RenderSVGResourceSolidColor* fallbackResource = RenderSVGResource::sharedSolidPaintingResource();
360 fallbackResource->setColor(fallbackColor);
362 m_paintingResource = fallbackResource;
363 m_paintingResource->applyResource(renderer, style, context, m_paintingResourceMode);
367 if (scalingFactor != 1 && m_paintingResourceMode & ApplyToStrokeMode)
368 context->setStrokeThickness(context->strokeThickness() * scalingFactor);
373 void SVGInlineTextBox::releasePaintingResource(GraphicsContext*& context, const Path* path)
375 ASSERT(m_paintingResource);
377 RenderObject* parentRenderer = parent()->renderer();
378 ASSERT(parentRenderer);
380 m_paintingResource->postApplyResource(parentRenderer, context, m_paintingResourceMode, path);
381 m_paintingResource = 0;
384 bool SVGInlineTextBox::prepareGraphicsContextForTextPainting(GraphicsContext*& context, float scalingFactor, TextRun& textRun, RenderStyle* style)
386 bool acquiredResource = acquirePaintingResource(context, scalingFactor, parent()->renderer(), style);
387 if (!acquiredResource)
390 #if ENABLE(SVG_FONTS)
391 // SVG Fonts need access to the painting resource used to draw the current text chunk.
392 TextRun::RenderingContext* renderingContext = textRun.renderingContext();
393 if (renderingContext)
394 static_cast<SVGTextRunRenderingContext*>(renderingContext)->setActivePaintingResource(m_paintingResource);
400 void SVGInlineTextBox::restoreGraphicsContextAfterTextPainting(GraphicsContext*& context, TextRun& textRun)
402 releasePaintingResource(context, /* path */0);
404 #if ENABLE(SVG_FONTS)
405 TextRun::RenderingContext* renderingContext = textRun.renderingContext();
406 if (renderingContext)
407 static_cast<SVGTextRunRenderingContext*>(renderingContext)->setActivePaintingResource(0);
409 UNUSED_PARAM(textRun);
413 TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFragment& fragment) const
416 ASSERT(textRenderer());
418 RenderText* text = textRenderer();
421 TextRun run(text->characters() + fragment.characterOffset
423 , false /* allowTabs */
424 , 0 /* xPos, only relevant with allowTabs=true */
425 , 0 /* padding, only relevant for justified text, not relevant for SVG */
426 , TextRun::AllowTrailingExpansion
428 , m_dirOverride || style->rtlOrdering() == VisualOrder /* directionalOverride */);
430 if (textRunNeedsRenderingContext(style->font()))
431 run.setRenderingContext(SVGTextRunRenderingContext::create(text));
433 run.disableRoundingHacks();
435 // We handle letter & word spacing ourselves.
436 run.disableSpacing();
438 // Propagate the maximum length of the characters buffer to the TextRun, even when we're only processing a substring.
439 run.setCharactersLength(text->textLength() - fragment.characterOffset);
440 ASSERT(run.charactersLength() >= run.length());
444 bool SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates(const SVGTextFragment& fragment, int& startPosition, int& endPosition) const
446 if (startPosition >= endPosition)
449 int offset = static_cast<int>(fragment.characterOffset) - start();
450 int length = static_cast<int>(fragment.length);
452 if (startPosition >= offset + length || endPosition <= offset)
455 if (startPosition < offset)
458 startPosition -= offset;
460 if (endPosition > offset + length)
461 endPosition = length;
463 ASSERT(endPosition >= offset);
464 endPosition -= offset;
467 ASSERT(startPosition < endPosition);
471 static inline float positionOffsetForDecoration(ETextDecoration decoration, const FontMetrics& fontMetrics, float thickness)
473 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-face> if specified.
474 // Compatible with Batik/Opera.
475 if (decoration == UNDERLINE)
476 return fontMetrics.floatAscent() + thickness * 1.5f;
477 if (decoration == OVERLINE)
479 if (decoration == LINE_THROUGH)
480 return fontMetrics.floatAscent() * 5 / 8.0f;
482 ASSERT_NOT_REACHED();
486 static inline float thicknessForDecoration(ETextDecoration, const Font& font)
488 // FIXME: For SVG Fonts we need to use the attributes defined in the <font-face> if specified.
489 // Compatible with Batik/Opera
490 return font.size() / 20.0f;
493 static inline RenderObject* findRenderObjectDefininingTextDecoration(InlineFlowBox* parentBox)
495 // Lookup first render object in parent hierarchy which has text-decoration set.
496 RenderObject* renderer = 0;
498 renderer = parentBox->renderer();
500 if (renderer->style() && renderer->style()->textDecoration() != TDNONE)
503 parentBox = parentBox->parent();
510 void SVGInlineTextBox::paintDecoration(GraphicsContext* context, ETextDecoration decoration, const SVGTextFragment& fragment)
512 if (textRenderer()->style()->textDecorationsInEffect() == TDNONE)
515 // Find out which render style defined the text-decoration, as its fill/stroke properties have to be used for drawing instead of ours.
516 RenderObject* decorationRenderer = findRenderObjectDefininingTextDecoration(parent());
517 RenderStyle* decorationStyle = decorationRenderer->style();
518 ASSERT(decorationStyle);
520 if (decorationStyle->visibility() == HIDDEN)
523 const SVGRenderStyle* svgDecorationStyle = decorationStyle->svgStyle();
524 ASSERT(svgDecorationStyle);
526 bool hasDecorationFill = svgDecorationStyle->hasFill();
527 bool hasDecorationStroke = svgDecorationStyle->hasStroke();
529 if (hasDecorationFill) {
530 m_paintingResourceMode = ApplyToFillMode;
531 paintDecorationWithStyle(context, decoration, fragment, decorationRenderer);
534 if (hasDecorationStroke) {
535 m_paintingResourceMode = ApplyToStrokeMode;
536 paintDecorationWithStyle(context, decoration, fragment, decorationRenderer);
540 static inline void normalizeTransform(AffineTransform& transform)
542 // Obtain consistent numerical results for the AffineTransform on both 32/64bit platforms.
543 // Tested with SnowLeopard on Core Duo vs. Core 2 Duo.
544 static const float s_floatEpsilon = std::numeric_limits<float>::epsilon();
546 if (fabs(transform.a() - 1) <= s_floatEpsilon)
548 else if (fabs(transform.a() + 1) <= s_floatEpsilon)
551 if (fabs(transform.d() - 1) <= s_floatEpsilon)
553 else if (fabs(transform.d() + 1) <= s_floatEpsilon)
556 if (fabs(transform.e()) <= s_floatEpsilon)
559 if (fabs(transform.f()) <= s_floatEpsilon)
563 void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, ETextDecoration decoration, const SVGTextFragment& fragment, RenderObject* decorationRenderer)
565 ASSERT(!m_paintingResource);
566 ASSERT(m_paintingResourceMode != ApplyToDefaultMode);
568 RenderStyle* decorationStyle = decorationRenderer->style();
569 ASSERT(decorationStyle);
571 float scalingFactor = 1;
573 RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decorationStyle, scalingFactor, scaledFont);
574 ASSERT(scalingFactor);
576 // The initial y value refers to overline position.
577 float thickness = thicknessForDecoration(decoration, scaledFont);
579 if (fragment.width <= 0 && thickness <= 0)
582 FloatPoint decorationOrigin(fragment.x, fragment.y);
583 float width = fragment.width;
584 const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics();
586 GraphicsContextStateSaver stateSaver(*context);
587 if (scalingFactor != 1) {
588 width *= scalingFactor;
589 decorationOrigin.scale(scalingFactor, scalingFactor);
591 AffineTransform newTransform = context->getCTM();
592 newTransform.scale(1 / scalingFactor);
593 normalizeTransform(newTransform);
595 context->setCTM(newTransform);
598 decorationOrigin.move(0, -scaledFontMetrics.floatAscent() + positionOffsetForDecoration(decoration, scaledFontMetrics, thickness));
601 path.addRect(FloatRect(decorationOrigin, FloatSize(width, thickness)));
603 if (acquirePaintingResource(context, scalingFactor, decorationRenderer, decorationStyle))
604 releasePaintingResource(context, &path);
607 void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyle* style, TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int endPosition)
609 RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
610 ASSERT(textRenderer);
612 float scalingFactor = textRenderer->scalingFactor();
613 ASSERT(scalingFactor);
615 const Font& scaledFont = textRenderer->scaledFont();
616 const ShadowData* shadow = style->textShadow();
618 FloatPoint textOrigin(fragment.x, fragment.y);
619 FloatSize textSize(fragment.width, fragment.height);
621 if (scalingFactor != 1) {
622 textOrigin.scale(scalingFactor, scalingFactor);
623 textSize.scale(scalingFactor);
626 FloatRect shadowRect(FloatPoint(textOrigin.x(), textOrigin.y() - scaledFont.fontMetrics().floatAscent()), textSize);
629 if (!prepareGraphicsContextForTextPainting(context, scalingFactor, textRun, style))
632 FloatSize extraOffset;
634 extraOffset = applyShadowToGraphicsContext(context, shadow, shadowRect, false /* stroked */, true /* opaque */, true /* horizontal */);
636 AffineTransform originalTransform;
637 if (scalingFactor != 1) {
638 originalTransform = context->getCTM();
640 AffineTransform newTransform = originalTransform;
641 newTransform.scale(1 / scalingFactor);
642 normalizeTransform(newTransform);
644 context->setCTM(newTransform);
647 scaledFont.drawText(context, textRun, textOrigin + extraOffset, startPosition, endPosition);
649 if (scalingFactor != 1)
650 context->setCTM(originalTransform);
652 restoreGraphicsContextAfterTextPainting(context, textRun);
660 context->clearShadow();
662 shadow = shadow->next();
666 void SVGInlineTextBox::paintText(GraphicsContext* context, RenderStyle* style, RenderStyle* selectionStyle, const SVGTextFragment& fragment, bool hasSelection, bool paintSelectedTextOnly)
669 ASSERT(selectionStyle);
671 int startPosition = 0;
674 selectionStartEnd(startPosition, endPosition);
675 hasSelection = mapStartEndPositionsIntoFragmentCoordinates(fragment, startPosition, endPosition);
678 // Fast path if there is no selection, just draw the whole chunk part using the regular style
679 TextRun textRun = constructTextRun(style, fragment);
680 if (!hasSelection || startPosition >= endPosition) {
681 paintTextWithShadows(context, style, textRun, fragment, 0, fragment.length);
685 // Eventually draw text using regular style until the start position of the selection
686 if (startPosition > 0 && !paintSelectedTextOnly)
687 paintTextWithShadows(context, style, textRun, fragment, 0, startPosition);
689 // Draw text using selection style from the start to the end position of the selection
690 if (style != selectionStyle)
691 SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, selectionStyle);
693 TextRun selectionTextRun = constructTextRun(selectionStyle, fragment);
694 paintTextWithShadows(context, selectionStyle, textRun, fragment, startPosition, endPosition);
696 if (style != selectionStyle)
697 SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, style);
699 // Eventually draw text using regular style from the end position of the selection to the end of the current chunk part
700 if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnly)
701 paintTextWithShadows(context, style, textRun, fragment, endPosition, fragment.length);
704 IntRect SVGInlineTextBox::calculateBoundaries() const
708 RenderSVGInlineText* textRenderer = toRenderSVGInlineText(this->textRenderer());
709 ASSERT(textRenderer);
711 float scalingFactor = textRenderer->scalingFactor();
712 ASSERT(scalingFactor);
714 float baseline = textRenderer->scaledFont().fontMetrics().floatAscent() / scalingFactor;
716 AffineTransform fragmentTransform;
717 unsigned textFragmentsSize = m_textFragments.size();
718 for (unsigned i = 0; i < textFragmentsSize; ++i) {
719 const SVGTextFragment& fragment = m_textFragments.at(i);
720 FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.width, fragment.height);
721 fragment.buildFragmentTransform(fragmentTransform);
722 if (!fragmentTransform.isIdentity())
723 fragmentRect = fragmentTransform.mapRect(fragmentRect);
725 textRect.unite(fragmentRect);
728 return enclosingIntRect(textRect);
731 bool SVGInlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit, LayoutUnit)
733 // FIXME: integrate with InlineTextBox::nodeAtPoint better.
734 ASSERT(!isLineBreak());
736 PointerEventsHitRules hitRules(PointerEventsHitRules::SVG_TEXT_HITTESTING, request, renderer()->style()->pointerEvents());
737 bool isVisible = renderer()->style()->visibility() == VISIBLE;
738 if (isVisible || !hitRules.requireVisible) {
739 if ((hitRules.canHitStroke && (renderer()->style()->svgStyle()->hasStroke() || !hitRules.requireStroke))
740 || (hitRules.canHitFill && (renderer()->style()->svgStyle()->hasFill() || !hitRules.requireFill))) {
741 FloatPoint boxOrigin(x(), y());
742 boxOrigin.moveBy(accumulatedOffset);
743 FloatRect rect(boxOrigin, size());
744 if (rect.intersects(result.rectForPoint(pointInContainer))) {
745 renderer()->updateHitTestResult(result, pointInContainer - toLayoutSize(accumulatedOffset));
746 if (!result.addNodeToRectBasedTestResult(renderer()->node(), pointInContainer, rect))
754 } // namespace WebCore