Title: [157960] trunk/Source/WebCore
Revision
157960
Author
[email protected]
Date
2013-10-24 16:35:26 -0700 (Thu, 24 Oct 2013)

Log Message

Uncomplicate some of SVGTextRunRenderingContext.
<https://webkit.org/b/123294>

This class was weird about a few things, so I've taken these steps
to clear things up:

- FINAL and OVERRIDE all the things.
- Constructor now takes a RenderObject&.
- renderer() now returns a RenderObject&.
- drawSVGGlyphs() no longer takes a TextRun.
- glyphDataForCharacter() no longer takes a TextRun.

To expand on the last two, there was also some awkward hoop-jumping
where we'd go through the TextRun passed by argument to find its
rendering context, which was really just |this| all along.

Reviewed by Antti Koivisto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (157959 => 157960)


--- trunk/Source/WebCore/ChangeLog	2013-10-24 23:14:10 UTC (rev 157959)
+++ trunk/Source/WebCore/ChangeLog	2013-10-24 23:35:26 UTC (rev 157960)
@@ -1,3 +1,23 @@
+2013-10-24  Andreas Kling  <[email protected]>
+
+        Uncomplicate some of SVGTextRunRenderingContext.
+        <https://webkit.org/b/123294>
+
+        This class was weird about a few things, so I've taken these steps
+        to clear things up:
+
+        - FINAL and OVERRIDE all the things.
+        - Constructor now takes a RenderObject&.
+        - renderer() now returns a RenderObject&.
+        - drawSVGGlyphs() no longer takes a TextRun.
+        - glyphDataForCharacter() no longer takes a TextRun.
+
+        To expand on the last two, there was also some awkward hoop-jumping
+        where we'd go through the TextRun passed by argument to find its
+        rendering context, which was really just |this| all along.
+
+        Reviewed by Antti Koivisto.
+
 2013-10-24  Roger Fong  <[email protected]>
 
         Add texture level dependent size checks to textureImage2D calls.

Modified: trunk/Source/WebCore/platform/graphics/FontFastPath.cpp (157959 => 157960)


--- trunk/Source/WebCore/platform/graphics/FontFastPath.cpp	2013-10-24 23:14:10 UTC (rev 157959)
+++ trunk/Source/WebCore/platform/graphics/FontFastPath.cpp	2013-10-24 23:35:26 UTC (rev 157960)
@@ -208,7 +208,7 @@
         if (nextFontData != fontData || nextOffset != offset) {
 #if ENABLE(SVG_FONTS)
             if (renderingContext && fontData->isSVGFont())
-                renderingContext->drawSVGGlyphs(context, run, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
+                renderingContext->drawSVGGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
             else
 #endif
                 drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
@@ -226,7 +226,7 @@
 
 #if ENABLE(SVG_FONTS)
     if (renderingContext && fontData->isSVGFont())
-        renderingContext->drawSVGGlyphs(context, run, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
+        renderingContext->drawSVGGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
     else
 #endif
         drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);

Modified: trunk/Source/WebCore/platform/graphics/TextRun.h (157959 => 157960)


--- trunk/Source/WebCore/platform/graphics/TextRun.h	2013-10-24 23:14:10 UTC (rev 157959)
+++ trunk/Source/WebCore/platform/graphics/TextRun.h	2013-10-24 23:35:26 UTC (rev 157960)
@@ -212,8 +212,8 @@
         virtual ~RenderingContext() { }
 
 #if ENABLE(SVG_FONTS)
-        virtual GlyphData glyphDataForCharacter(const Font&, const TextRun&, WidthIterator&, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength) = 0;
-        virtual void drawSVGGlyphs(GraphicsContext*, const TextRun&, const SimpleFontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const = 0;
+        virtual GlyphData glyphDataForCharacter(const Font&, WidthIterator&, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength) = 0;
+        virtual void drawSVGGlyphs(GraphicsContext*, const SimpleFontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const = 0;
         virtual float floatWidthUsingSVGFont(const Font&, const TextRun&, int& charsConsumed, String& glyphName) const = 0;
         virtual bool applySVGKerning(const SimpleFontData*, WidthIterator&, GlyphBuffer*, int from) const = 0;
 #endif

Modified: trunk/Source/WebCore/platform/graphics/WidthIterator.cpp (157959 => 157960)


--- trunk/Source/WebCore/platform/graphics/WidthIterator.cpp	2013-10-24 23:14:10 UTC (rev 157959)
+++ trunk/Source/WebCore/platform/graphics/WidthIterator.cpp	2013-10-24 23:35:26 UTC (rev 157960)
@@ -77,7 +77,7 @@
 
 #if ENABLE(SVG_FONTS)
     if (TextRun::RenderingContext* renderingContext = m_run.renderingContext())
-        return renderingContext->glyphDataForCharacter(*m_font, m_run, *this, character, mirror, currentCharacter, advanceLength);
+        return renderingContext->glyphDataForCharacter(*m_font, *this, character, mirror, currentCharacter, advanceLength);
 #else
     UNUSED_PARAM(currentCharacter);
     UNUSED_PARAM(advanceLength);

Modified: trunk/Source/WebCore/rendering/InlineTextBox.cpp (157959 => 157960)


--- trunk/Source/WebCore/rendering/InlineTextBox.cpp	2013-10-24 23:14:10 UTC (rev 157959)
+++ trunk/Source/WebCore/rendering/InlineTextBox.cpp	2013-10-24 23:35:26 UTC (rev 157960)
@@ -1487,7 +1487,7 @@
     TextRun run(string, textPos(), expansion(), expansionBehavior(), direction(), dirOverride() || style.rtlOrdering() == VisualOrder, !renderer().canUseSimpleFontCodePath());
     run.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
     if (textRunNeedsRenderingContext(font))
-        run.setRenderingContext(SVGTextRunRenderingContext::create(&renderer()));
+        run.setRenderingContext(SVGTextRunRenderingContext::create(renderer()));
 
     // Propagate the maximum length of the characters buffer to the TextRun, even when we're only processing a substring.
     run.setCharactersLength(maximumLength);

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (157959 => 157960)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2013-10-24 23:14:10 UTC (rev 157959)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2013-10-24 23:35:26 UTC (rev 157960)
@@ -5432,8 +5432,10 @@
     bool directionalOverride = style.rtlOrdering() == VisualOrder;
 
     TextRun run(characters, length, 0, 0, expansion, textDirection, directionalOverride);
-    if (textRunNeedsRenderingContext(font))
-        run.setRenderingContext(SVGTextRunRenderingContext::create(context));
+    if (textRunNeedsRenderingContext(font)) {
+        ASSERT(context); // FIXME: Thread a RenderObject& to this point so we don't have to dereference anything.
+        run.setRenderingContext(SVGTextRunRenderingContext::create(*context));
+    }
 
     return run;
 }
@@ -5450,8 +5452,10 @@
             directionalOverride |= isOverride(style.unicodeBidi());
     }
     TextRun run(characters, length, 0, 0, expansion, textDirection, directionalOverride);
-    if (textRunNeedsRenderingContext(font))
-        run.setRenderingContext(SVGTextRunRenderingContext::create(context));
+    if (textRunNeedsRenderingContext(font)) {
+        ASSERT(context); // FIXME: Thread a RenderObject& to this point so we don't have to dereference anything.
+        run.setRenderingContext(SVGTextRunRenderingContext::create(*context));
+    }
 
     return run;
 }

Modified: trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp (157959 => 157960)


--- trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp	2013-10-24 23:14:10 UTC (rev 157959)
+++ trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp	2013-10-24 23:35:26 UTC (rev 157960)
@@ -417,7 +417,7 @@
                 , dirOverride() || style->rtlOrdering() == VisualOrder /* directionalOverride */);
 
     if (textRunNeedsRenderingContext(style->font()))
-        run.setRenderingContext(SVGTextRunRenderingContext::create(&renderer()));
+        run.setRenderingContext(SVGTextRunRenderingContext::create(renderer()));
 
     run.disableRoundingHacks();
 

Modified: trunk/Source/WebCore/rendering/svg/SVGTextMetrics.cpp (157959 => 157960)


--- trunk/Source/WebCore/rendering/svg/SVGTextMetrics.cpp	2013-10-24 23:14:10 UTC (rev 157959)
+++ trunk/Source/WebCore/rendering/svg/SVGTextMetrics.cpp	2013-10-24 23:35:26 UTC (rev 157960)
@@ -77,7 +77,7 @@
                 , isOverride(style->unicodeBidi()) /* directionalOverride */);
 
     if (textRunNeedsRenderingContext(style->font()))
-        run.setRenderingContext(SVGTextRunRenderingContext::create(text));
+        run.setRenderingContext(SVGTextRunRenderingContext::create(*text));
 
     run.disableRoundingHacks();
 

Modified: trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp (157959 => 157960)


--- trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp	2013-10-24 23:14:10 UTC (rev 157959)
+++ trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp	2013-10-24 23:35:26 UTC (rev 157960)
@@ -53,26 +53,6 @@
     return svgFontData;
 }
 
-static inline RenderObject* firstParentRendererForNonTextNode(RenderObject* renderer)
-{
-    ASSERT(renderer);
-    return renderer->isText() ? renderer->parent() : renderer;
-}
-
-static inline RenderObject* renderObjectFromRun(const TextRun& run)
-{
-    if (TextRun::RenderingContext* renderingContext = run.renderingContext())
-        return static_cast<SVGTextRunRenderingContext*>(renderingContext)->renderer();
-    return 0;
-}
-
-static inline RenderSVGResource* activePaintingResourceFromRun(const TextRun& run)
-{
-    if (TextRun::RenderingContext* renderingContext = run.renderingContext())
-        return static_cast<SVGTextRunRenderingContext*>(renderingContext)->activePaintingResource();
-    return 0;
-}
-
 float SVGTextRunRenderingContext::floatWidthUsingSVGFont(const Font& font, const TextRun& run, int& charsConsumed, String& glyphName) const
 {
     WidthIterator it(&font, run);
@@ -122,7 +102,7 @@
     return true;
 }
 
-void SVGTextRunRenderingContext::drawSVGGlyphs(GraphicsContext* context, const TextRun& run, const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const
+void SVGTextRunRenderingContext::drawSVGGlyphs(GraphicsContext* context, const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const
 {
     SVGFontElement* fontElement = 0;
     SVGFontFaceElement* fontFaceElement = 0;
@@ -131,27 +111,18 @@
     if (!fontElement || !fontFaceElement)
         return;
 
-    // We can only paint SVGFonts if a context is available.
-    RenderSVGResource* activePaintingResource = activePaintingResourceFromRun(run);
-    RenderObject* renderObject = renderObjectFromRun(run);
-    RenderObject* parentRenderObject = firstParentRendererForNonTextNode(renderObject);
-    RenderStyle* parentRenderObjectStyle = 0;
-
-    ASSERT(renderObject);
+    auto activePaintingResource = this->activePaintingResource();
     if (!activePaintingResource) {
         // TODO: We're only supporting simple filled HTML text so far.
         RenderSVGResourceSolidColor* solidPaintingResource = RenderSVGResource::sharedSolidPaintingResource();
         solidPaintingResource->setColor(context->fillColor());
         activePaintingResource = solidPaintingResource;
     }
- 
-    bool isVerticalText = false;
-    if (parentRenderObject) {
-        parentRenderObjectStyle = parentRenderObject->style();
-        ASSERT(parentRenderObjectStyle);
-        isVerticalText = parentRenderObjectStyle->svgStyle()->isVerticalWritingMode();
-    }
 
+    auto& elementRenderer = renderer().isRenderElement() ? toRenderElement(renderer()) : *renderer().parent();
+    RenderStyle& style = *elementRenderer.style();
+    bool isVerticalText = style.svgStyle()->isVerticalWritingMode();
+
     float scale = scaleEmToUnits(fontData->platformData().size(), fontFaceElement->unitsPerEm());
     ASSERT(activePaintingResource);
 
@@ -194,11 +165,11 @@
         Path glyphPath = svgGlyph.pathData;
         glyphPath.transform(glyphPathTransform);
 
-        if (activePaintingResource->applyResource(parentRenderObject, parentRenderObjectStyle, context, resourceMode)) {
+        if (activePaintingResource->applyResource(&elementRenderer, &style, context, resourceMode)) {
             float strokeThickness = context->strokeThickness();
-            if (renderObject && renderObject->isSVGInlineText())
-                context->setStrokeThickness(strokeThickness * toRenderSVGInlineText(renderObject)->scalingFactor());
-            activePaintingResource->postApplyResource(parentRenderObject, context, resourceMode, &glyphPath, 0);
+            if (renderer().isSVGInlineText())
+                context->setStrokeThickness(strokeThickness * toRenderSVGInlineText(renderer()).scalingFactor());
+            activePaintingResource->postApplyResource(&elementRenderer, context, resourceMode, &glyphPath, 0);
             context->setStrokeThickness(strokeThickness);
         }
 
@@ -209,7 +180,7 @@
     }
 }
 
-GlyphData SVGTextRunRenderingContext::glyphDataForCharacter(const Font& font, const TextRun& run, WidthIterator& iterator, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength)
+GlyphData SVGTextRunRenderingContext::glyphDataForCharacter(const Font& font, WidthIterator& iterator, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength)
 {
     const SimpleFontData* primaryFont = font.primaryFont();
     ASSERT(primaryFont);
@@ -233,14 +204,10 @@
     // Characters enclosed by an <altGlyph> element, may not be registered in the GlyphPage.
     const SimpleFontData* originalFontData = glyphData.fontData;
     if (glyphData.fontData && !glyphData.fontData->isSVGFont()) {
-        if (TextRun::RenderingContext* renderingContext = run.renderingContext()) {
-            RenderObject* renderObject = static_cast<SVGTextRunRenderingContext*>(renderingContext)->renderer();
-            RenderObject* parentRenderObject = renderObject->isText() ? renderObject->parent() : renderObject;
-            ASSERT(parentRenderObject);
-            if (Element* parentRenderObjectElement = toElement(parentRenderObject->node())) {
-                if (parentRenderObjectElement->hasTagName(SVGNames::altGlyphTag))
-                    glyphData.fontData = primaryFont;
-            }
+        auto& elementRenderer = renderer().isRenderElement() ? toRenderElement(renderer()) : *renderer().parent();
+        if (Element* parentRendererElement = elementRenderer.element()) {
+            if (parentRendererElement->hasTagName(SVGNames::altGlyphTag))
+                glyphData.fontData = primaryFont;
         }
     }
 

Modified: trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.h (157959 => 157960)


--- trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.h	2013-10-24 23:14:10 UTC (rev 157959)
+++ trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.h	2013-10-24 23:35:26 UTC (rev 157960)
@@ -29,27 +29,27 @@
 class RenderObject;
 class RenderSVGResource;
 
-class SVGTextRunRenderingContext : public TextRun::RenderingContext {
+class SVGTextRunRenderingContext FINAL : public TextRun::RenderingContext {
 public:
-    static PassRefPtr<SVGTextRunRenderingContext> create(RenderObject* renderer)
+    static PassRef<SVGTextRunRenderingContext> create(RenderObject& renderer)
     {
-        return adoptRef(new SVGTextRunRenderingContext(renderer));
+        return adoptRef(*new SVGTextRunRenderingContext(renderer));
     }
 
-    RenderObject* renderer() const { return m_renderer; }
+    RenderObject& renderer() const { return m_renderer; }
 
 #if ENABLE(SVG_FONTS)
     RenderSVGResource* activePaintingResource() const { return m_activePaintingResource; }
     void setActivePaintingResource(RenderSVGResource* object) { m_activePaintingResource = object; }
 
-    virtual GlyphData glyphDataForCharacter(const Font&, const TextRun&, WidthIterator&, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength);
-    virtual void drawSVGGlyphs(GraphicsContext*, const TextRun&, const SimpleFontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const;
-    virtual float floatWidthUsingSVGFont(const Font&, const TextRun&, int& charsConsumed, String& glyphName) const;
-    virtual bool applySVGKerning(const SimpleFontData*, WidthIterator&, GlyphBuffer*, int from) const;
+    virtual GlyphData glyphDataForCharacter(const Font&, WidthIterator&, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength) OVERRIDE;
+    virtual void drawSVGGlyphs(GraphicsContext*, const SimpleFontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const OVERRIDE;
+    virtual float floatWidthUsingSVGFont(const Font&, const TextRun&, int& charsConsumed, String& glyphName) const OVERRIDE;
+    virtual bool applySVGKerning(const SimpleFontData*, WidthIterator&, GlyphBuffer*, int from) const OVERRIDE;
 #endif
 
 private:
-    SVGTextRunRenderingContext(RenderObject* renderer)
+    SVGTextRunRenderingContext(RenderObject& renderer)
         : m_renderer(renderer)
 #if ENABLE(SVG_FONTS)
         , m_activePaintingResource(0)
@@ -59,7 +59,7 @@
 
     virtual ~SVGTextRunRenderingContext() { }
 
-    RenderObject* m_renderer;
+    RenderObject& m_renderer;
 
 #if ENABLE(SVG_FONTS)
     RenderSVGResource* m_activePaintingResource;

Modified: trunk/Source/WebCore/svg/SVGFontData.cpp (157959 => 157960)


--- trunk/Source/WebCore/svg/SVGFontData.cpp	2013-10-24 23:14:10 UTC (rev 157959)
+++ trunk/Source/WebCore/svg/SVGFontData.cpp	2013-10-24 23:35:26 UTC (rev 157960)
@@ -159,7 +159,7 @@
 
     RenderObject* renderObject = 0;
     if (TextRun::RenderingContext* renderingContext = run.renderingContext())
-        renderObject = static_cast<SVGTextRunRenderingContext*>(renderingContext)->renderer();
+        renderObject = &static_cast<SVGTextRunRenderingContext*>(renderingContext)->renderer();
 
     String language;
     bool isVerticalText = false;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to