webengine/osswebengine/WebCore/platform/graphics/svg/cg/SVGPaintServerSolidCg.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2     Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org>
       
     3 
       
     4     This file is part of the KDE project
       
     5 
       
     6     This library is free software; you can redistribute it and/or
       
     7     modify it under the terms of the GNU Library General Public
       
     8     License as published by the Free Software Foundation; either
       
     9     version 2 of the License, or (at your option) any later version.
       
    10 
       
    11     This library is distributed in the hope that it will be useful,
       
    12     but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    14     Library General Public License for more details.
       
    15 
       
    16     You should have received a copy of the GNU Library General Public License
       
    17     aint with this library; see the file COPYING.LIB.  If not, write to
       
    18     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    19     Boston, MA 02110-1301, USA.
       
    20 */
       
    21 
       
    22 #include "config.h"
       
    23 
       
    24 #if ENABLE(SVG)
       
    25 #include "SVGPaintServerSolid.h"
       
    26 
       
    27 #include "GraphicsContext.h"
       
    28 #include "RenderObject.h"
       
    29 #include "CgSupport.h"
       
    30 
       
    31 namespace WebCore {
       
    32 
       
    33 bool SVGPaintServerSolid::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
       
    34 {
       
    35     CGContextRef contextRef = context->platformContext();
       
    36     RenderStyle* style = object->style();
       
    37 
       
    38     CGContextSetAlpha(contextRef, style->opacity());
       
    39 
       
    40     static CGColorSpaceRef deviceRGBColorSpace = CGColorSpaceCreateDeviceRGB(); // This should be shared from GraphicsContext, or some other central location
       
    41 
       
    42     if ((type & ApplyToFillTargetType) && style->svgStyle()->hasFill()) {
       
    43         CGFloat colorComponents[4];
       
    44         color().getRGBA(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]);
       
    45         ASSERT(!color().hasAlpha());
       
    46         colorComponents[3] = style->svgStyle()->fillOpacity(); // SVG/CSS colors are not specified w/o alpha
       
    47         CGContextSetFillColorSpace(contextRef, deviceRGBColorSpace);
       
    48         CGContextSetFillColor(contextRef, colorComponents);
       
    49         if (isPaintingText) {
       
    50             const_cast<RenderObject*>(object)->style()->setColor(color());
       
    51             context->setTextDrawingMode(cTextFill);
       
    52         }
       
    53     }
       
    54 
       
    55     if ((type & ApplyToStrokeTargetType) && style->svgStyle()->hasStroke()) {
       
    56         CGFloat colorComponents[4];
       
    57         color().getRGBA(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]);
       
    58         ASSERT(!color().hasAlpha());
       
    59         colorComponents[3] = style->svgStyle()->strokeOpacity(); // SVG/CSS colors are not specified w/o alpha
       
    60         CGContextSetStrokeColorSpace(contextRef, deviceRGBColorSpace);
       
    61         CGContextSetStrokeColor(contextRef, colorComponents);
       
    62         applyStrokeStyleToContext(contextRef, style, object);
       
    63         if (isPaintingText) {
       
    64             const_cast<RenderObject*>(object)->style()->setColor(color());
       
    65             context->setTextDrawingMode(cTextStroke);
       
    66         }
       
    67     }
       
    68 
       
    69     return true;
       
    70 }
       
    71 
       
    72 } // namespace WebCore
       
    73 
       
    74 #endif
       
    75 
       
    76 // vim:ts=4:noet