diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/rendering/svg/SVGInlineTextBox.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/rendering/svg/SVGInlineTextBox.cpp')
-rw-r--r-- | Source/WebCore/rendering/svg/SVGInlineTextBox.cpp | 309 |
1 files changed, 150 insertions, 159 deletions
diff --git a/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp b/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp index f55976e95..e70f0903a 100644 --- a/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp +++ b/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp @@ -22,8 +22,6 @@ #include "config.h" #include "SVGInlineTextBox.h" -#if ENABLE(SVG) -#include "FontCache.h" #include "Frame.h" #include "FrameView.h" #include "GraphicsContext.h" @@ -31,12 +29,13 @@ #include "InlineFlowBox.h" #include "PointerEventsHitRules.h" #include "RenderBlock.h" +#include "RenderInline.h" #include "RenderSVGResourceSolidColor.h" #include "RenderView.h" #include "SVGRenderingContext.h" #include "SVGResourcesCache.h" #include "SVGRootInlineBox.h" -#include "SVGTextRunRenderingContext.h" +#include "TextPainter.h" namespace WebCore { @@ -54,7 +53,7 @@ SVGInlineTextBox::SVGInlineTextBox(RenderSVGInlineText& renderer) , m_logicalHeight(0) , m_paintingResourceMode(ApplyToDefaultMode) , m_startsNewTextChunk(false) - , m_paintingResource(0) + , m_paintingResource(nullptr) { } @@ -89,7 +88,7 @@ int SVGInlineTextBox::offsetForPositionInFragment(const SVGTextFragment& fragmen float scalingFactor = renderer().scalingFactor(); ASSERT(scalingFactor); - TextRun textRun = constructTextRun(&renderer().style(), fragment); + TextRun textRun = constructTextRun(renderer().style(), fragment); // Eventually handle lengthAdjust="spacingAndGlyphs". // FIXME: Handle vertical text. @@ -101,53 +100,52 @@ int SVGInlineTextBox::offsetForPositionInFragment(const SVGTextFragment& fragmen return fragment.characterOffset - start() + renderer().scaledFont().offsetForPosition(textRun, position * scalingFactor, includePartialGlyphs); } -float SVGInlineTextBox::positionForOffset(int) const +float SVGInlineTextBox::positionForOffset(unsigned) const { // SVG doesn't use the offset <-> position selection system. ASSERT_NOT_REACHED(); return 0; } -FloatRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment& fragment, int startPosition, int endPosition, RenderStyle* style) const +FloatRect SVGInlineTextBox::selectionRectForTextFragment(const SVGTextFragment& fragment, unsigned startPosition, unsigned endPosition, const RenderStyle& style) const { ASSERT_WITH_SECURITY_IMPLICATION(startPosition < endPosition); - ASSERT(style); - - FontCachePurgePreventer fontCachePurgePreventer; float scalingFactor = renderer().scalingFactor(); ASSERT(scalingFactor); - const Font& scaledFont = renderer().scaledFont(); + const FontCascade& scaledFont = renderer().scaledFont(); const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics(); FloatPoint textOrigin(fragment.x, fragment.y); if (scalingFactor != 1) - textOrigin.scale(scalingFactor, scalingFactor); + textOrigin.scale(scalingFactor); textOrigin.move(0, -scaledFontMetrics.floatAscent()); - FloatRect selectionRect = scaledFont.selectionRectForText(constructTextRun(style, fragment), textOrigin, fragment.height * scalingFactor, startPosition, endPosition); + LayoutRect selectionRect = LayoutRect(textOrigin, LayoutSize(0, fragment.height * scalingFactor)); + TextRun run = constructTextRun(style, fragment); + scaledFont.adjustSelectionRectForText(run, selectionRect, startPosition, endPosition); + FloatRect snappedSelectionRect = snapRectToDevicePixelsWithWritingDirection(selectionRect, renderer().document().deviceScaleFactor(), run.ltr()); if (scalingFactor == 1) - return selectionRect; + return snappedSelectionRect; - selectionRect.scale(1 / scalingFactor); - return selectionRect; + snappedSelectionRect.scale(1 / scalingFactor); + return snappedSelectionRect; } -LayoutRect SVGInlineTextBox::localSelectionRect(int startPosition, int endPosition) const +LayoutRect SVGInlineTextBox::localSelectionRect(unsigned startPosition, unsigned endPosition) const { - int boxStart = start(); - startPosition = std::max(startPosition - boxStart, 0); - endPosition = std::min(endPosition - boxStart, static_cast<int>(len())); + startPosition = clampedOffset(startPosition); + endPosition = clampedOffset(endPosition); if (startPosition >= endPosition) return LayoutRect(); - RenderStyle& style = renderer().style(); + auto& style = renderer().style(); AffineTransform fragmentTransform; FloatRect selectionRect; - int fragmentStartPosition = 0; - int fragmentEndPosition = 0; + unsigned fragmentStartPosition = 0; + unsigned fragmentEndPosition = 0; unsigned textFragmentsSize = m_textFragments.size(); for (unsigned i = 0; i < textFragmentsSize; ++i) { @@ -158,7 +156,7 @@ LayoutRect SVGInlineTextBox::localSelectionRect(int startPosition, int endPositi if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition)) continue; - FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, &style); + FloatRect fragmentRect = selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style); fragment.buildFragmentTransform(fragmentTransform); if (!fragmentTransform.isIdentity()) fragmentRect = fragmentTransform.mapRect(fragmentRect); @@ -171,7 +169,7 @@ LayoutRect SVGInlineTextBox::localSelectionRect(int startPosition, int endPositi static inline bool textShouldBePainted(const RenderSVGInlineText& textRenderer) { - // Font::pixelSize(), returns FontDescription::computedPixelSize(), which returns "int(x + 0.5)". + // FontCascade::pixelSize(), returns FontDescription::computedPixelSize(), which returns "int(x + 0.5)". // If the absolute font size on screen is below x=0.5, don't render anything. return textRenderer.scaledFont().pixelSize(); } @@ -185,7 +183,7 @@ void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo) if (renderer().style().visibility() != VISIBLE) return; - RenderObject& parentRenderer = parent()->renderer(); + auto& parentRenderer = parent()->renderer(); ASSERT(!parentRenderer.document().printing()); // Determine whether or not we're selected. @@ -195,26 +193,20 @@ void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo) return; Color backgroundColor = renderer().selectionBackgroundColor(); - if (!backgroundColor.isValid() || !backgroundColor.alpha()) + if (!backgroundColor.isVisible()) return; if (!textShouldBePainted(renderer())) return; - RenderStyle& style = parentRenderer.style(); + auto& style = parentRenderer.style(); - RenderStyle* selectionStyle = &style; - if (hasSelection) { - selectionStyle = parentRenderer.getCachedPseudoStyle(SELECTION); - if (!selectionStyle) - selectionStyle = &style; - } - - int startPosition, endPosition; - selectionStartEnd(startPosition, endPosition); + unsigned startPosition; + unsigned endPosition; + std::tie(startPosition, endPosition) = selectionStartEnd(); - int fragmentStartPosition = 0; - int fragmentEndPosition = 0; + unsigned fragmentStartPosition = 0; + unsigned fragmentEndPosition = 0; AffineTransform fragmentTransform; unsigned textFragmentsSize = m_textFragments.size(); for (unsigned i = 0; i < textFragmentsSize; ++i) { @@ -226,13 +218,13 @@ void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo) if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition)) continue; - GraphicsContextStateSaver stateSaver(*paintInfo.context); + GraphicsContextStateSaver stateSaver(paintInfo.context()); fragment.buildFragmentTransform(fragmentTransform); if (!fragmentTransform.isIdentity()) - paintInfo.context->concatCTM(fragmentTransform); + paintInfo.context().concatCTM(fragmentTransform); - paintInfo.context->setFillColor(backgroundColor, style.colorSpace()); - paintInfo.context->fillRect(selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, &style), backgroundColor, style.colorSpace()); + paintInfo.context().setFillColor(backgroundColor); + paintInfo.context().fillRect(selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColor); m_paintingResourceMode = ApplyToDefaultMode; } @@ -240,7 +232,7 @@ void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo) ASSERT(!m_paintingResource); } -void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint&, LayoutUnit, LayoutUnit) +void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit, LayoutUnit) { ASSERT(paintInfo.shouldPaintWithinRoot(renderer())); ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection); @@ -252,9 +244,10 @@ void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint&, LayoutUni // Note: We're explicitely not supporting composition & custom underlines and custom highlighters - unlike InlineTextBox. // If we ever need that for SVG, it's very easy to refactor and reuse the code. - RenderObject& parentRenderer = parent()->renderer(); + auto& parentRenderer = parent()->renderer(); bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection; + bool shouldPaintSelectionHighlight = !(paintInfo.paintBehavior & PaintBehaviorSkipSelectionHighlight); bool hasSelection = !parentRenderer.document().printing() && selectionState() != RenderObject::SelectionNone; if (!hasSelection && paintSelectedTextOnly) return; @@ -262,15 +255,15 @@ void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint&, LayoutUni if (!textShouldBePainted(renderer())) return; - RenderStyle& style = parentRenderer.style(); + auto& style = parentRenderer.style(); const SVGRenderStyle& svgStyle = style.svgStyle(); bool hasFill = svgStyle.hasFill(); - bool hasVisibleStroke = svgStyle.hasVisibleStroke(); + bool hasVisibleStroke = style.hasVisibleStroke(); - RenderStyle* selectionStyle = &style; - if (hasSelection) { + const RenderStyle* selectionStyle = &style; + if (hasSelection && shouldPaintSelectionHighlight) { selectionStyle = parentRenderer.getCachedPseudoStyle(SELECTION); if (selectionStyle) { const SVGRenderStyle& svgSelectionStyle = selectionStyle->svgStyle(); @@ -278,7 +271,7 @@ void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint&, LayoutUni if (!hasFill) hasFill = svgSelectionStyle.hasFill(); if (!hasVisibleStroke) - hasVisibleStroke = svgSelectionStyle.hasVisibleStroke(); + hasVisibleStroke = selectionStyle->hasVisibleStroke(); } else selectionStyle = &style; } @@ -294,51 +287,64 @@ void SVGInlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint&, LayoutUni SVGTextFragment& fragment = m_textFragments.at(i); ASSERT(!m_paintingResource); - GraphicsContextStateSaver stateSaver(*paintInfo.context); + GraphicsContextStateSaver stateSaver(paintInfo.context()); fragment.buildFragmentTransform(fragmentTransform); if (!fragmentTransform.isIdentity()) - paintInfo.context->concatCTM(fragmentTransform); + paintInfo.context().concatCTM(fragmentTransform); // 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. int decorations = style.textDecorationsInEffect(); if (decorations & TextDecorationUnderline) - paintDecoration(paintInfo.context, TextDecorationUnderline, fragment); + paintDecoration(paintInfo.context(), TextDecorationUnderline, fragment); if (decorations & TextDecorationOverline) - paintDecoration(paintInfo.context, TextDecorationOverline, fragment); - - // Fill text - if (hasFill) { - m_paintingResourceMode = ApplyToFillMode | ApplyToTextMode; - paintText(paintInfo.context, &style, selectionStyle, fragment, hasSelection, paintSelectedTextOnly); - } - - // Stroke text - if (hasVisibleStroke) { - m_paintingResourceMode = ApplyToStrokeMode | ApplyToTextMode; - paintText(paintInfo.context, &style, selectionStyle, fragment, hasSelection, paintSelectedTextOnly); + paintDecoration(paintInfo.context(), TextDecorationOverline, fragment); + + auto paintOrder = style.paintTypesForPaintOrder(); + for (unsigned i = 0; i < paintOrder.size(); ++i) { + switch (paintOrder.at(i)) { + case PaintTypeFill: + if (!hasFill) + continue; + m_paintingResourceMode = ApplyToFillMode | ApplyToTextMode; + ASSERT(selectionStyle); + paintText(paintInfo.context(), style, *selectionStyle, fragment, hasSelection, paintSelectedTextOnly); + break; + case PaintTypeStroke: + if (!hasVisibleStroke) + continue; + m_paintingResourceMode = ApplyToStrokeMode | ApplyToTextMode; + ASSERT(selectionStyle); + paintText(paintInfo.context(), style, *selectionStyle, fragment, hasSelection, paintSelectedTextOnly); + break; + case PaintTypeMarkers: + continue; + } } // Spec: Line-through should be drawn after the text is filled and stroked; thus, the line-through is rendered on top of the text. if (decorations & TextDecorationLineThrough) - paintDecoration(paintInfo.context, TextDecorationLineThrough, fragment); + paintDecoration(paintInfo.context(), TextDecorationLineThrough, fragment); m_paintingResourceMode = ApplyToDefaultMode; } + // Finally, paint the outline if any. + if (renderer().style().hasOutline() && is<RenderInline>(parentRenderer)) + downcast<RenderInline>(parentRenderer).paintOutline(paintInfo, paintOffset); + ASSERT(!m_paintingResource); } -bool SVGInlineTextBox::acquirePaintingResource(GraphicsContext*& context, float scalingFactor, RenderBoxModelObject& renderer, RenderStyle* style) +bool SVGInlineTextBox::acquirePaintingResource(GraphicsContext*& context, float scalingFactor, RenderBoxModelObject& renderer, const RenderStyle& style) { ASSERT(scalingFactor); - ASSERT(style); ASSERT(m_paintingResourceMode != ApplyToDefaultMode); Color fallbackColor; if (m_paintingResourceMode & ApplyToFillMode) - m_paintingResource = RenderSVGResource::fillPaintingResource(renderer, *style, fallbackColor); + m_paintingResource = RenderSVGResource::fillPaintingResource(renderer, style, fallbackColor); else if (m_paintingResourceMode & ApplyToStrokeMode) - m_paintingResource = RenderSVGResource::strokePaintingResource(renderer, *style, fallbackColor); + m_paintingResource = RenderSVGResource::strokePaintingResource(renderer, style, fallbackColor); else { // We're either called for stroking or filling. ASSERT_NOT_REACHED(); @@ -347,13 +353,13 @@ bool SVGInlineTextBox::acquirePaintingResource(GraphicsContext*& context, float if (!m_paintingResource) return false; - if (!m_paintingResource->applyResource(renderer, *style, context, m_paintingResourceMode)) { + if (!m_paintingResource->applyResource(renderer, style, context, m_paintingResourceMode)) { if (fallbackColor.isValid()) { RenderSVGResourceSolidColor* fallbackResource = RenderSVGResource::sharedSolidPaintingResource(); fallbackResource->setColor(fallbackColor); m_paintingResource = fallbackResource; - m_paintingResource->applyResource(renderer, *style, context, m_paintingResourceMode); + m_paintingResource->applyResource(renderer, style, context, m_paintingResourceMode); } } @@ -367,55 +373,28 @@ void SVGInlineTextBox::releasePaintingResource(GraphicsContext*& context, const { ASSERT(m_paintingResource); - m_paintingResource->postApplyResource(parent()->renderer(), context, m_paintingResourceMode, path, /*RenderSVGShape*/ 0); + m_paintingResource->postApplyResource(parent()->renderer(), context, m_paintingResourceMode, path, /*RenderSVGShape*/ nullptr); m_paintingResource = nullptr; } -bool SVGInlineTextBox::prepareGraphicsContextForTextPainting(GraphicsContext*& context, float scalingFactor, TextRun& textRun, RenderStyle* style) +bool SVGInlineTextBox::prepareGraphicsContextForTextPainting(GraphicsContext*& context, float scalingFactor, const RenderStyle& style) { - bool acquiredResource = acquirePaintingResource(context, scalingFactor, parent()->renderer(), style); - if (!acquiredResource) - return false; - -#if ENABLE(SVG_FONTS) - // SVG Fonts need access to the painting resource used to draw the current text chunk. - TextRun::RenderingContext* renderingContext = textRun.renderingContext(); - if (renderingContext) - static_cast<SVGTextRunRenderingContext*>(renderingContext)->setActivePaintingResource(m_paintingResource); -#endif - - return true; + return acquirePaintingResource(context, scalingFactor, parent()->renderer(), style); } -void SVGInlineTextBox::restoreGraphicsContextAfterTextPainting(GraphicsContext*& context, TextRun& textRun) +void SVGInlineTextBox::restoreGraphicsContextAfterTextPainting(GraphicsContext*& context) { - releasePaintingResource(context, /* path */0); - -#if ENABLE(SVG_FONTS) - TextRun::RenderingContext* renderingContext = textRun.renderingContext(); - if (renderingContext) - static_cast<SVGTextRunRenderingContext*>(renderingContext)->setActivePaintingResource(0); -#else - UNUSED_PARAM(textRun); -#endif + releasePaintingResource(context, /* path */nullptr); } -TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFragment& fragment) const +TextRun SVGInlineTextBox::constructTextRun(const RenderStyle& style, const SVGTextFragment& fragment) const { - ASSERT(style); - - TextRun run(renderer().deprecatedCharacters() + fragment.characterOffset - , fragment.length + TextRun run(StringView(renderer().text()).substring(fragment.characterOffset, fragment.length) , 0 /* xPos, only relevant with allowTabs=true */ , 0 /* padding, only relevant for justified text, not relevant for SVG */ - , TextRun::AllowTrailingExpansion + , AllowTrailingExpansion , direction() - , dirOverride() || style->rtlOrdering() == VisualOrder /* directionalOverride */); - - if (style->font().isSVGFont()) - run.setRenderingContext(SVGTextRunRenderingContext::create(renderer())); - - run.disableRoundingHacks(); + , dirOverride() || style.rtlOrdering() == VisualOrder /* directionalOverride */); // We handle letter & word spacing ourselves. run.disableSpacing(); @@ -426,21 +405,24 @@ TextRun SVGInlineTextBox::constructTextRun(RenderStyle* style, const SVGTextFrag return run; } -bool SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates(const SVGTextFragment& fragment, int& startPosition, int& endPosition) const +bool SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates(const SVGTextFragment& fragment, unsigned& startPosition, unsigned& endPosition) const { if (startPosition >= endPosition) return false; - int offset = static_cast<int>(fragment.characterOffset) - start(); - int length = static_cast<int>(fragment.length); + ASSERT(fragment.characterOffset >= start()); + unsigned offset = fragment.characterOffset - start(); + unsigned length = fragment.length; if (startPosition >= offset + length || endPosition <= offset) return false; if (startPosition < offset) startPosition = 0; - else + else { + ASSERT(startPosition >= offset); startPosition -= offset; + } if (endPosition > offset + length) endPosition = length; @@ -468,7 +450,7 @@ static inline float positionOffsetForDecoration(TextDecoration decoration, const return 0.0f; } -static inline float thicknessForDecoration(TextDecoration, const Font& font) +static inline float thicknessForDecoration(TextDecoration, const FontCascade& font) { // FIXME: For SVG Fonts we need to use the attributes defined in the <font-face> if specified. // Compatible with Batik/Opera @@ -492,7 +474,7 @@ static inline RenderBoxModelObject& findRendererDefininingTextDecoration(InlineF return *renderer; } -void SVGInlineTextBox::paintDecoration(GraphicsContext* context, TextDecoration decoration, const SVGTextFragment& fragment) +void SVGInlineTextBox::paintDecoration(GraphicsContext& context, TextDecoration decoration, const SVGTextFragment& fragment) { if (renderer().style().textDecorationsInEffect() == TextDecorationNone) return; @@ -507,7 +489,7 @@ void SVGInlineTextBox::paintDecoration(GraphicsContext* context, TextDecoration const SVGRenderStyle& svgDecorationStyle = decorationStyle.svgStyle(); bool hasDecorationFill = svgDecorationStyle.hasFill(); - bool hasVisibleDecorationStroke = svgDecorationStyle.hasVisibleStroke(); + bool hasVisibleDecorationStroke = decorationStyle.hasVisibleStroke(); if (hasDecorationFill) { m_paintingResourceMode = ApplyToFillMode; @@ -520,16 +502,16 @@ void SVGInlineTextBox::paintDecoration(GraphicsContext* context, TextDecoration } } -void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, TextDecoration decoration, const SVGTextFragment& fragment, RenderBoxModelObject& decorationRenderer) +void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext& context, TextDecoration decoration, const SVGTextFragment& fragment, RenderBoxModelObject& decorationRenderer) { ASSERT(!m_paintingResource); ASSERT(m_paintingResourceMode != ApplyToDefaultMode); - RenderStyle& decorationStyle = decorationRenderer.style(); + auto& decorationStyle = decorationRenderer.style(); float scalingFactor = 1; - Font scaledFont; - RenderSVGInlineText::computeNewScaledFontForStyle(&decorationRenderer, &decorationStyle, scalingFactor, scaledFont); + FontCascade scaledFont; + RenderSVGInlineText::computeNewScaledFontForStyle(decorationRenderer, decorationStyle, scalingFactor, scaledFont); ASSERT(scalingFactor); // The initial y value refers to overline position. @@ -542,11 +524,11 @@ void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, TextDe float width = fragment.width; const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics(); - GraphicsContextStateSaver stateSaver(*context); + GraphicsContextStateSaver stateSaver(context); if (scalingFactor != 1) { width *= scalingFactor; - decorationOrigin.scale(scalingFactor, scalingFactor); - context->scale(FloatSize(1 / scalingFactor, 1 / scalingFactor)); + decorationOrigin.scale(scalingFactor); + context.scale(1 / scalingFactor); } decorationOrigin.move(0, -scaledFontMetrics.floatAscent() + positionOffsetForDecoration(decoration, scaledFontMetrics, thickness)); @@ -554,66 +536,62 @@ void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, TextDe Path path; path.addRect(FloatRect(decorationOrigin, FloatSize(width, thickness))); - if (acquirePaintingResource(context, scalingFactor, decorationRenderer, &decorationStyle)) - releasePaintingResource(context, &path); + GraphicsContext* contextPtr = &context; + if (acquirePaintingResource(contextPtr, scalingFactor, decorationRenderer, decorationStyle)) + releasePaintingResource(contextPtr, &path); } -void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyle* style, TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int endPosition) +void SVGInlineTextBox::paintTextWithShadows(GraphicsContext& context, const RenderStyle& style, TextRun& textRun, const SVGTextFragment& fragment, unsigned startPosition, unsigned endPosition) { float scalingFactor = renderer().scalingFactor(); ASSERT(scalingFactor); - const Font& scaledFont = renderer().scaledFont(); - const ShadowData* shadow = style->textShadow(); + const FontCascade& scaledFont = renderer().scaledFont(); + const ShadowData* shadow = style.textShadow(); FloatPoint textOrigin(fragment.x, fragment.y); FloatSize textSize(fragment.width, fragment.height); if (scalingFactor != 1) { - textOrigin.scale(scalingFactor, scalingFactor); + textOrigin.scale(scalingFactor); textSize.scale(scalingFactor); } FloatRect shadowRect(FloatPoint(textOrigin.x(), textOrigin.y() - scaledFont.fontMetrics().floatAscent()), textSize); + GraphicsContext* usedContext = &context; do { - if (!prepareGraphicsContextForTextPainting(context, scalingFactor, textRun, style)) + if (!prepareGraphicsContextForTextPainting(usedContext, scalingFactor, style)) break; - FloatSize extraOffset; - if (shadow) - extraOffset = applyShadowToGraphicsContext(context, shadow, shadowRect, false /* stroked */, true /* opaque */, true /* horizontal */); + { + ShadowApplier shadowApplier(*usedContext, shadow, shadowRect); - context->save(); - context->scale(FloatSize(1 / scalingFactor, 1 / scalingFactor)); + if (!shadowApplier.didSaveContext()) + usedContext->save(); + usedContext->scale(1 / scalingFactor); - scaledFont.drawText(context, textRun, textOrigin + extraOffset, startPosition, endPosition); + scaledFont.drawText(*usedContext, textRun, textOrigin + shadowApplier.extraOffset(), startPosition, endPosition); - context->restore(); + if (!shadowApplier.didSaveContext()) + usedContext->restore(); + } - restoreGraphicsContextAfterTextPainting(context, textRun); + restoreGraphicsContextAfterTextPainting(usedContext); if (!shadow) break; - if (shadow->next()) - context->restore(); - else - context->clearShadow(); - shadow = shadow->next(); } while (shadow); } -void SVGInlineTextBox::paintText(GraphicsContext* context, RenderStyle* style, RenderStyle* selectionStyle, const SVGTextFragment& fragment, bool hasSelection, bool paintSelectedTextOnly) +void SVGInlineTextBox::paintText(GraphicsContext& context, const RenderStyle& style, const RenderStyle& selectionStyle, const SVGTextFragment& fragment, bool hasSelection, bool paintSelectedTextOnly) { - ASSERT(style); - ASSERT(selectionStyle); - - int startPosition = 0; - int endPosition = 0; + unsigned startPosition = 0; + unsigned endPosition = 0; if (hasSelection) { - selectionStartEnd(startPosition, endPosition); + std::tie(startPosition, endPosition) = selectionStartEnd(); hasSelection = mapStartEndPositionsIntoFragmentCoordinates(fragment, startPosition, endPosition); } @@ -630,16 +608,15 @@ void SVGInlineTextBox::paintText(GraphicsContext* context, RenderStyle* style, R // Draw text using selection style from the start to the end position of the selection if (style != selectionStyle) - SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, *selectionStyle); + SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, selectionStyle); - TextRun selectionTextRun = constructTextRun(selectionStyle, fragment); paintTextWithShadows(context, selectionStyle, textRun, fragment, startPosition, endPosition); if (style != selectionStyle) - SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, *style); + SVGResourcesCache::clientStyleChanged(parent()->renderer(), StyleDifferenceRepaint, style); // Eventually draw text using regular style from the end position of the selection to the end of the current chunk part - if (endPosition < static_cast<int>(fragment.length) && !paintSelectedTextOnly) + if (endPosition < fragment.length && !paintSelectedTextOnly) paintTextWithShadows(context, style, textRun, fragment, endPosition, fragment.length); } @@ -667,7 +644,7 @@ FloatRect SVGInlineTextBox::calculateBoundaries() const return textRect; } -bool SVGInlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit, LayoutUnit) +bool SVGInlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit, LayoutUnit, HitTestAction) { // FIXME: integrate with InlineTextBox::nodeAtPoint better. ASSERT(!isLineBreak()); @@ -681,9 +658,25 @@ bool SVGInlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& boxOrigin.moveBy(accumulatedOffset); FloatRect rect(boxOrigin, size()); if (locationInContainer.intersects(rect)) { - renderer().updateHitTestResult(result, locationInContainer.point() - toLayoutSize(accumulatedOffset)); - if (!result.addNodeToRectBasedTestResult(&renderer().textNode(), request, locationInContainer, rect)) - return true; + + float scalingFactor = renderer().scalingFactor(); + ASSERT(scalingFactor); + + float baseline = renderer().scaledFont().fontMetrics().floatAscent() / scalingFactor; + + AffineTransform fragmentTransform; + for (auto& fragment : m_textFragments) { + FloatQuad fragmentQuad(FloatRect(fragment.x, fragment.y - baseline, fragment.width, fragment.height)); + fragment.buildFragmentTransform(fragmentTransform); + if (!fragmentTransform.isIdentity()) + fragmentQuad = fragmentTransform.mapQuad(fragmentQuad); + + if (fragmentQuad.containsPoint(locationInContainer.point())) { + renderer().updateHitTestResult(result, locationInContainer.point() - toLayoutSize(accumulatedOffset)); + if (!result.addNodeToRectBasedTestResult(&renderer().textNode(), request, locationInContainer, rect)) + return true; + } + } } } } @@ -691,5 +684,3 @@ bool SVGInlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& } } // namespace WebCore - -#endif |