⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 157960 in webkit


Ignore:
Timestamp:
Oct 24, 2013, 4:35:26 PM (13 years ago)
Author:
akling@apple.com
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.

Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r157959 r157960  
     12013-10-24  Andreas Kling  <akling@apple.com>
     2
     3        Uncomplicate some of SVGTextRunRenderingContext.
     4        <https://webkit.org/b/123294>
     5
     6        This class was weird about a few things, so I've taken these steps
     7        to clear things up:
     8
     9        - FINAL and OVERRIDE all the things.
     10        - Constructor now takes a RenderObject&.
     11        - renderer() now returns a RenderObject&.
     12        - drawSVGGlyphs() no longer takes a TextRun.
     13        - glyphDataForCharacter() no longer takes a TextRun.
     14
     15        To expand on the last two, there was also some awkward hoop-jumping
     16        where we'd go through the TextRun passed by argument to find its
     17        rendering context, which was really just |this| all along.
     18
     19        Reviewed by Antti Koivisto.
     20
    1212013-10-24  Roger Fong  <roger_fong@apple.com>
    222
  • trunk/Source/WebCore/platform/graphics/FontFastPath.cpp

    r154674 r157960  
    209209#if ENABLE(SVG_FONTS)
    210210            if (renderingContext && fontData->isSVGFont())
    211                 renderingContext->drawSVGGlyphs(context, run, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
     211                renderingContext->drawSVGGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
    212212            else
    213213#endif
    … …  
    227227#if ENABLE(SVG_FONTS)
    228228    if (renderingContext && fontData->isSVGFont())
    229         renderingContext->drawSVGGlyphs(context, run, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
     229        renderingContext->drawSVGGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
    230230    else
    231231#endif
  • trunk/Source/WebCore/platform/graphics/TextRun.h

    r157341 r157960  
    213213
    214214#if ENABLE(SVG_FONTS)
    215         virtual GlyphData glyphDataForCharacter(const Font&, const TextRun&, WidthIterator&, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength) = 0;
    216         virtual void drawSVGGlyphs(GraphicsContext*, const TextRun&, const SimpleFontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const = 0;
     215        virtual GlyphData glyphDataForCharacter(const Font&, WidthIterator&, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength) = 0;
     216        virtual void drawSVGGlyphs(GraphicsContext*, const SimpleFontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const = 0;
    217217        virtual float floatWidthUsingSVGFont(const Font&, const TextRun&, int& charsConsumed, String& glyphName) const = 0;
    218218        virtual bool applySVGKerning(const SimpleFontData*, WidthIterator&, GlyphBuffer*, int from) const = 0;
  • trunk/Source/WebCore/platform/graphics/WidthIterator.cpp

    r157330 r157960  
    7878#if ENABLE(SVG_FONTS)
    7979    if (TextRun::RenderingContext* renderingContext = m_run.renderingContext())
    80         return renderingContext->glyphDataForCharacter(*m_font, m_run, *this, character, mirror, currentCharacter, advanceLength);
     80        return renderingContext->glyphDataForCharacter(*m_font, *this, character, mirror, currentCharacter, advanceLength);
    8181#else
    8282    UNUSED_PARAM(currentCharacter);
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r157948 r157960  
    14881488    run.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
    14891489    if (textRunNeedsRenderingContext(font))
    1490         run.setRenderingContext(SVGTextRunRenderingContext::create(&renderer()));
     1490        run.setRenderingContext(SVGTextRunRenderingContext::create(renderer()));
    14911491
    14921492    // Propagate the maximum length of the characters buffer to the TextRun, even when we're only processing a substring.
  • trunk/Source/WebCore/rendering/RenderBlock.cpp

    r157950 r157960  
    54335433
    54345434    TextRun run(characters, length, 0, 0, expansion, textDirection, directionalOverride);
    5435     if (textRunNeedsRenderingContext(font))
    5436         run.setRenderingContext(SVGTextRunRenderingContext::create(context));
     5435    if (textRunNeedsRenderingContext(font)) {
     5436        ASSERT(context); // FIXME: Thread a RenderObject& to this point so we don't have to dereference anything.
     5437        run.setRenderingContext(SVGTextRunRenderingContext::create(*context));
     5438    }
    54375439
    54385440    return run;
    … …  
    54515453    }
    54525454    TextRun run(characters, length, 0, 0, expansion, textDirection, directionalOverride);
    5453     if (textRunNeedsRenderingContext(font))
    5454         run.setRenderingContext(SVGTextRunRenderingContext::create(context));
     5455    if (textRunNeedsRenderingContext(font)) {
     5456        ASSERT(context); // FIXME: Thread a RenderObject& to this point so we don't have to dereference anything.
     5457        run.setRenderingContext(SVGTextRunRenderingContext::create(*context));
     5458    }
    54555459
    54565460    return run;
  • trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp

    r157919 r157960  
    418418
    419419    if (textRunNeedsRenderingContext(style->font()))
    420         run.setRenderingContext(SVGTextRunRenderingContext::create(&renderer()));
     420        run.setRenderingContext(SVGTextRunRenderingContext::create(renderer()));
    421421
    422422    run.disableRoundingHacks();
  • trunk/Source/WebCore/rendering/svg/SVGTextMetrics.cpp

    r127801 r157960  
    7878
    7979    if (textRunNeedsRenderingContext(style->font()))
    80         run.setRenderingContext(SVGTextRunRenderingContext::create(text));
     80        run.setRenderingContext(SVGTextRunRenderingContext::create(*text));
    8181
    8282    run.disableRoundingHacks();
  • trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp

    r156393 r157960  
    5454}
    5555
    56 static inline RenderObject* firstParentRendererForNonTextNode(RenderObject* renderer)
    57 {
    58     ASSERT(renderer);
    59     return renderer->isText() ? renderer->parent() : renderer;
    60 }
    61 
    62 static inline RenderObject* renderObjectFromRun(const TextRun& run)
    63 {
    64     if (TextRun::RenderingContext* renderingContext = run.renderingContext())
    65         return static_cast<SVGTextRunRenderingContext*>(renderingContext)->renderer();
    66     return 0;
    67 }
    68 
    69 static inline RenderSVGResource* activePaintingResourceFromRun(const TextRun& run)
    70 {
    71     if (TextRun::RenderingContext* renderingContext = run.renderingContext())
    72         return static_cast<SVGTextRunRenderingContext*>(renderingContext)->activePaintingResource();
    73     return 0;
    74 }
    75 
    7656float SVGTextRunRenderingContext::floatWidthUsingSVGFont(const Font& font, const TextRun& run, int& charsConsumed, String& glyphName) const
    7757{
    … …  
    123103}
    124104
    125 void SVGTextRunRenderingContext::drawSVGGlyphs(GraphicsContext* context, const TextRun& run, const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const
     105void SVGTextRunRenderingContext::drawSVGGlyphs(GraphicsContext* context, const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const
    126106{
    127107    SVGFontElement* fontElement = 0;
    … …  
    132112        return;
    133113
    134     // We can only paint SVGFonts if a context is available.
    135     RenderSVGResource* activePaintingResource = activePaintingResourceFromRun(run);
    136     RenderObject* renderObject = renderObjectFromRun(run);
    137     RenderObject* parentRenderObject = firstParentRendererForNonTextNode(renderObject);
    138     RenderStyle* parentRenderObjectStyle = 0;
    139 
    140     ASSERT(renderObject);
     114    auto activePaintingResource = this->activePaintingResource();
    141115    if (!activePaintingResource) {
    142116        // TODO: We're only supporting simple filled HTML text so far.
    … …  
    145119        activePaintingResource = solidPaintingResource;
    146120    }
    147  
    148     bool isVerticalText = false;
    149     if (parentRenderObject) {
    150         parentRenderObjectStyle = parentRenderObject->style();
    151         ASSERT(parentRenderObjectStyle);
    152         isVerticalText = parentRenderObjectStyle->svgStyle()->isVerticalWritingMode();
    153     }
     121
     122    auto& elementRenderer = renderer().isRenderElement() ? toRenderElement(renderer()) : *renderer().parent();
     123    RenderStyle& style = *elementRenderer.style();
     124    bool isVerticalText = style.svgStyle()->isVerticalWritingMode();
    154125
    155126    float scale = scaleEmToUnits(fontData->platformData().size(), fontFaceElement->unitsPerEm());
    … …  
    195166        glyphPath.transform(glyphPathTransform);
    196167
    197         if (activePaintingResource->applyResource(parentRenderObject, parentRenderObjectStyle, context, resourceMode)) {
     168        if (activePaintingResource->applyResource(&elementRenderer, &style, context, resourceMode)) {
    198169            float strokeThickness = context->strokeThickness();
    199             if (renderObject && renderObject->isSVGInlineText())
    200                 context->setStrokeThickness(strokeThickness * toRenderSVGInlineText(renderObject)->scalingFactor());
    201             activePaintingResource->postApplyResource(parentRenderObject, context, resourceMode, &glyphPath, 0);
     170            if (renderer().isSVGInlineText())
     171                context->setStrokeThickness(strokeThickness * toRenderSVGInlineText(renderer()).scalingFactor());
     172            activePaintingResource->postApplyResource(&elementRenderer, context, resourceMode, &glyphPath, 0);
    202173            context->setStrokeThickness(strokeThickness);
    203174        }
    … …  
    210181}
    211182
    212 GlyphData SVGTextRunRenderingContext::glyphDataForCharacter(const Font& font, const TextRun& run, WidthIterator& iterator, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength)
     183GlyphData SVGTextRunRenderingContext::glyphDataForCharacter(const Font& font, WidthIterator& iterator, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength)
    213184{
    214185    const SimpleFontData* primaryFont = font.primaryFont();
    … …  
    234205    const SimpleFontData* originalFontData = glyphData.fontData;
    235206    if (glyphData.fontData && !glyphData.fontData->isSVGFont()) {
    236         if (TextRun::RenderingContext* renderingContext = run.renderingContext()) {
    237             RenderObject* renderObject = static_cast<SVGTextRunRenderingContext*>(renderingContext)->renderer();
    238             RenderObject* parentRenderObject = renderObject->isText() ? renderObject->parent() : renderObject;
    239             ASSERT(parentRenderObject);
    240             if (Element* parentRenderObjectElement = toElement(parentRenderObject->node())) {
    241                 if (parentRenderObjectElement->hasTagName(SVGNames::altGlyphTag))
    242                     glyphData.fontData = primaryFont;
    243             }
     207        auto& elementRenderer = renderer().isRenderElement() ? toRenderElement(renderer()) : *renderer().parent();
     208        if (Element* parentRendererElement = elementRenderer.element()) {
     209            if (parentRendererElement->hasTagName(SVGNames::altGlyphTag))
     210                glyphData.fontData = primaryFont;
    244211        }
    245212    }
  • trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.h

    r156393 r157960  
    3030class RenderSVGResource;
    3131
    32 class SVGTextRunRenderingContext : public TextRun::RenderingContext {
     32class SVGTextRunRenderingContext FINAL : public TextRun::RenderingContext {
    3333public:
    34     static PassRefPtr<SVGTextRunRenderingContext> create(RenderObject* renderer)
     34    static PassRef<SVGTextRunRenderingContext> create(RenderObject& renderer)
    3535    {
    36         return adoptRef(new SVGTextRunRenderingContext(renderer));
     36        return adoptRef(*new SVGTextRunRenderingContext(renderer));
    3737    }
    3838
    39     RenderObject* renderer() const { return m_renderer; }
     39    RenderObject& renderer() const { return m_renderer; }
    4040
    4141#if ENABLE(SVG_FONTS)
    … …  
    4343    void setActivePaintingResource(RenderSVGResource* object) { m_activePaintingResource = object; }
    4444
    45     virtual GlyphData glyphDataForCharacter(const Font&, const TextRun&, WidthIterator&, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength);
    46     virtual void drawSVGGlyphs(GraphicsContext*, const TextRun&, const SimpleFontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const;
    47     virtual float floatWidthUsingSVGFont(const Font&, const TextRun&, int& charsConsumed, String& glyphName) const;
    48     virtual bool applySVGKerning(const SimpleFontData*, WidthIterator&, GlyphBuffer*, int from) const;
     45    virtual GlyphData glyphDataForCharacter(const Font&, WidthIterator&, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength) OVERRIDE;
     46    virtual void drawSVGGlyphs(GraphicsContext*, const SimpleFontData*, const GlyphBuffer&, int from, int to, const FloatPoint&) const OVERRIDE;
     47    virtual float floatWidthUsingSVGFont(const Font&, const TextRun&, int& charsConsumed, String& glyphName) const OVERRIDE;
     48    virtual bool applySVGKerning(const SimpleFontData*, WidthIterator&, GlyphBuffer*, int from) const OVERRIDE;
    4949#endif
    5050
    5151private:
    52     SVGTextRunRenderingContext(RenderObject* renderer)
     52    SVGTextRunRenderingContext(RenderObject& renderer)
    5353        : m_renderer(renderer)
    5454#if ENABLE(SVG_FONTS)
    … …  
    6060    virtual ~SVGTextRunRenderingContext() { }
    6161
    62     RenderObject* m_renderer;
     62    RenderObject& m_renderer;
    6363
    6464#if ENABLE(SVG_FONTS)
  • trunk/Source/WebCore/svg/SVGFontData.cpp

    r157330 r157960  
    160160    RenderObject* renderObject = 0;
    161161    if (TextRun::RenderingContext* renderingContext = run.renderingContext())
    162         renderObject = static_cast<SVGTextRunRenderingContext*>(renderingContext)->renderer();
     162        renderObject = &static_cast<SVGTextRunRenderingContext*>(renderingContext)->renderer();
    163163
    164164    String language;
Note: See TracChangeset for help on using the changeset viewer.