Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #include "config.h"
     21 
     22 #include "core/rendering/svg/RenderSVGResourceSolidColor.h"
     23 
     24 #include "core/frame/FrameView.h"
     25 #include "core/frame/LocalFrame.h"
     26 #include "core/rendering/style/RenderStyle.h"
     27 #include "core/rendering/svg/RenderSVGShape.h"
     28 #include "core/rendering/svg/SVGRenderSupport.h"
     29 #include "platform/graphics/GraphicsContext.h"
     30 
     31 namespace WebCore {
     32 
     33 const RenderSVGResourceType RenderSVGResourceSolidColor::s_resourceType = SolidColorResourceType;
     34 
     35 RenderSVGResourceSolidColor::RenderSVGResourceSolidColor()
     36 {
     37 }
     38 
     39 RenderSVGResourceSolidColor::~RenderSVGResourceSolidColor()
     40 {
     41 }
     42 
     43 bool RenderSVGResourceSolidColor::applyResource(RenderObject* object, RenderStyle* style, GraphicsContext*& context, unsigned short resourceMode)
     44 {
     45     // We are NOT allowed to ASSERT(object) here, unlike all other resources.
     46     // RenderSVGResourceSolidColor is the only resource which may be used from HTML, when rendering
     47     // SVG Fonts for a HTML document. This will be indicated by a null RenderObject pointer.
     48     ASSERT(context);
     49     ASSERT(resourceMode != ApplyToDefaultMode);
     50 
     51     const SVGRenderStyle* svgStyle = style ? style->svgStyle() : 0;
     52 
     53     bool isRenderingMask = false;
     54     if (object->frame() && object->frame()->view())
     55         isRenderingMask = object->frame()->view()->paintBehavior() & PaintBehaviorRenderingSVGMask;
     56 
     57     if (resourceMode & ApplyToFillMode) {
     58         if (!isRenderingMask && svgStyle)
     59             context->setAlphaAsFloat(svgStyle->fillOpacity());
     60         else
     61             context->setAlphaAsFloat(1);
     62         context->setFillColor(m_color);
     63         if (!isRenderingMask)
     64             context->setFillRule(svgStyle ? svgStyle->fillRule() : RULE_NONZERO);
     65 
     66         if (resourceMode & ApplyToTextMode)
     67             context->setTextDrawingMode(TextModeFill);
     68     } else if (resourceMode & ApplyToStrokeMode) {
     69         // When rendering the mask for a RenderSVGResourceClipper, the stroke code path is never hit.
     70         ASSERT(!isRenderingMask);
     71         context->setAlphaAsFloat(svgStyle ? svgStyle->strokeOpacity() : 1);
     72         context->setStrokeColor(m_color);
     73 
     74         if (style)
     75             SVGRenderSupport::applyStrokeStyleToContext(context, style, object);
     76 
     77         if (resourceMode & ApplyToTextMode)
     78             context->setTextDrawingMode(TextModeStroke);
     79     }
     80 
     81     return true;
     82 }
     83 
     84 void RenderSVGResourceSolidColor::postApplyResource(RenderObject*, GraphicsContext*& context, unsigned short resourceMode, const Path* path, const RenderSVGShape* shape)
     85 {
     86     ASSERT(context);
     87     ASSERT(resourceMode != ApplyToDefaultMode);
     88 
     89     if (resourceMode & ApplyToFillMode) {
     90         if (path)
     91             context->fillPath(*path);
     92         else if (shape)
     93             shape->fillShape(context);
     94     }
     95     if (resourceMode & ApplyToStrokeMode) {
     96         if (path)
     97             context->strokePath(*path);
     98         else if (shape)
     99             shape->strokeShape(context);
    100     }
    101 }
    102 
    103 }
    104