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 #if ENABLE(SVG)
     23 #include "RenderSVGResourceSolidColor.h"
     24 
     25 #include "GraphicsContext.h"
     26 #include "RenderStyle.h"
     27 #include "SVGRenderSupport.h"
     28 
     29 #if USE(SKIA) && !PLATFORM(ANDROID)
     30 #include "PlatformContextSkia.h"
     31 #endif
     32 
     33 namespace WebCore {
     34 
     35 RenderSVGResourceType RenderSVGResourceSolidColor::s_resourceType = SolidColorResourceType;
     36 
     37 RenderSVGResourceSolidColor::RenderSVGResourceSolidColor()
     38 {
     39 }
     40 
     41 RenderSVGResourceSolidColor::~RenderSVGResourceSolidColor()
     42 {
     43 }
     44 
     45 bool RenderSVGResourceSolidColor::applyResource(RenderObject* object, RenderStyle* style, GraphicsContext*& context, unsigned short resourceMode)
     46 {
     47     // We are NOT allowed to ASSERT(object) here, unlike all other resources.
     48     // RenderSVGResourceSolidColor is the only resource which may be used from HTML, when rendering
     49     // SVG Fonts for a HTML document. This will be indicated by a null RenderObject pointer.
     50     ASSERT(context);
     51     ASSERT(resourceMode != ApplyToDefaultMode);
     52 
     53     const SVGRenderStyle* svgStyle = style ? style->svgStyle() : 0;
     54     ColorSpace colorSpace = style ? style->colorSpace() : ColorSpaceDeviceRGB;
     55 
     56     if (resourceMode & ApplyToFillMode) {
     57         context->setAlpha(svgStyle ? svgStyle->fillOpacity() : 1.0f);
     58         context->setFillColor(m_color, colorSpace);
     59         context->setFillRule(svgStyle ? svgStyle->fillRule() : RULE_NONZERO);
     60 
     61         if (resourceMode & ApplyToTextMode)
     62             context->setTextDrawingMode(TextModeFill);
     63     } else if (resourceMode & ApplyToStrokeMode) {
     64         context->setAlpha(svgStyle ? svgStyle->strokeOpacity() : 1.0f);
     65         context->setStrokeColor(m_color, colorSpace);
     66 
     67         if (style)
     68             SVGRenderSupport::applyStrokeStyleToContext(context, style, object);
     69 
     70         if (resourceMode & ApplyToTextMode)
     71             context->setTextDrawingMode(TextModeStroke);
     72     }
     73 
     74     return true;
     75 }
     76 
     77 void RenderSVGResourceSolidColor::postApplyResource(RenderObject*, GraphicsContext*& context, unsigned short resourceMode, const Path* path)
     78 {
     79     ASSERT(context);
     80     ASSERT(resourceMode != ApplyToDefaultMode);
     81 
     82     if (path && !(resourceMode & ApplyToTextMode)) {
     83         if (resourceMode & ApplyToFillMode)
     84             context->fillPath(*path);
     85         else if (resourceMode & ApplyToStrokeMode)
     86             context->strokePath(*path);
     87     }
     88 }
     89 
     90 }
     91 
     92 #endif
     93