Commit 3cb4d7c6 authored by bdash's avatar bdash
Browse files

2007-06-13 Alp Toker <alp.toker@collabora.co.uk>

        Reviewed by Rob.

        http://bugs.webkit.org/show_bug.cgi?id=14060
        Cairo SVG support

        * WebCore.pro: Add new files to the build.
        * platform/graphics/svg/SVGPaintServerPattern.h:
        * platform/graphics/svg/SVGPaintServerSolid.h:
        * platform/graphics/svg/cairo: Added.
        * platform/graphics/svg/cairo/RenderPathCairo.cpp: Added.
        (WebCore::RenderPath::strokeContains):
        (WebCore::RenderPath::strokeBBox):
        * platform/graphics/svg/cairo/SVGPaintServerCairo.cpp: Added.
        (WebCore::SVGPaintServer::draw):
        (WebCore::SVGPaintServer::teardown):
        (WebCore::SVGPaintServer::renderPath):
        * platform/graphics/svg/cairo/SVGPaintServerGradientCairo.cpp: Added.
        (WebCore::SVGPaintServerGradient::setup):
        * platform/graphics/svg/cairo/SVGPaintServerPatternCairo.cpp: Added.
        (WebCore::SVGPaintServerPattern::setup):
        * platform/graphics/svg/cairo/SVGPaintServerSolidCairo.cpp: Added.
        (WebCore::SVGPaintServerSolid::setup):
        * platform/graphics/svg/cairo/SVGResourceClipperCairo.cpp: Added.
        (WebCore::SVGResourceClipper::applyClip):
        * platform/graphics/svg/cairo/SVGResourceMaskerCairo.cpp: Added.
        (WebCore::SVGResourceMasker::applyMask):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@23507 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c14b0062
2007-06-13 Alp Toker <alp.toker@collabora.co.uk>
Reviewed by Rob.
http://bugs.webkit.org/show_bug.cgi?id=14060
Cairo SVG support
* WebCore.pro: Add new files to the build.
* platform/graphics/svg/SVGPaintServerPattern.h:
* platform/graphics/svg/SVGPaintServerSolid.h:
* platform/graphics/svg/cairo: Added.
* platform/graphics/svg/cairo/RenderPathCairo.cpp: Added.
(WebCore::RenderPath::strokeContains):
(WebCore::RenderPath::strokeBBox):
* platform/graphics/svg/cairo/SVGPaintServerCairo.cpp: Added.
(WebCore::SVGPaintServer::draw):
(WebCore::SVGPaintServer::teardown):
(WebCore::SVGPaintServer::renderPath):
* platform/graphics/svg/cairo/SVGPaintServerGradientCairo.cpp: Added.
(WebCore::SVGPaintServerGradient::setup):
* platform/graphics/svg/cairo/SVGPaintServerPatternCairo.cpp: Added.
(WebCore::SVGPaintServerPattern::setup):
* platform/graphics/svg/cairo/SVGPaintServerSolidCairo.cpp: Added.
(WebCore::SVGPaintServerSolid::setup):
* platform/graphics/svg/cairo/SVGResourceClipperCairo.cpp: Added.
(WebCore::SVGResourceClipper::applyClip):
* platform/graphics/svg/cairo/SVGResourceMaskerCairo.cpp: Added.
(WebCore::SVGResourceMasker::applyMask):
2007-06-13 Simon Hausmann <hausmann@kde.org>
 
Reviewed by Lars.
......@@ -40,6 +40,7 @@ DEFINES += ENABLE_XPATH=1
DEFINES += ENABLE_XSLT=1
#DEFINES += ENABLE_XBL=1
qt-port:DEFINES += ENABLE_SVG=1
gdk-port:DEFINES += ENABLE_SVG=1
DEFINES += WTF_CHANGES=1
......@@ -70,6 +71,7 @@ DEPENDPATH += editing/qt history/qt loader/qt page/qt \
}
gdk-port:INCLUDEPATH += \
$$PWD/platform/graphics/svg/cairo \
$$PWD/platform/image-decoders/bmp \
$$PWD/platform/image-decoders/gif \
$$PWD/platform/image-decoders/ico \
......@@ -920,6 +922,10 @@ contains(DEFINES, ENABLE_SVG=1) {
DEPENDPATH += platform/graphics/svg/qt
}
gdk-port {
DEPENDPATH += platform/graphics/svg/cairo
}
SVG_NAMES = $$PWD/ksvg2/svg/svgtags.in
XLINK_NAMES = $$PWD/ksvg2/misc/xlinkattrs.in
......@@ -1233,6 +1239,15 @@ qt-port:SOURCES += \
platform/graphics/svg/qt/SVGResourceFilterQt.cpp \
platform/graphics/svg/qt/SVGResourceMaskerQt.cpp
gdk-port:SOURCES += \
platform/graphics/svg/cairo/RenderPathCairo.cpp \
platform/graphics/svg/cairo/SVGPaintServerCairo.cpp \
platform/graphics/svg/cairo/SVGPaintServerGradientCairo.cpp \
platform/graphics/svg/cairo/SVGPaintServerPatternCairo.cpp \
platform/graphics/svg/cairo/SVGPaintServerSolidCairo.cpp \
platform/graphics/svg/cairo/SVGResourceClipperCairo.cpp \
platform/graphics/svg/cairo/SVGResourceMaskerCairo.cpp
# GENERATOR 5-C:
svgnames_a.output = tmp/SVGNames.cpp
svgnames_a.commands = perl $$PWD/ksvg2/scripts/make_names.pl --tags $$PWD/ksvg2/svg/svgtags.in --attrs $$PWD/ksvg2/svg/svgattrs.in --namespace SVG --cppNamespace WebCore --namespaceURI 'http://www.w3.org/2000/svg' --factory --attrsNullNamespace --output tmp
......
......@@ -64,7 +64,7 @@ namespace WebCore {
virtual void teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
#endif
#if PLATFORM(QT)
#if PLATFORM(QT) || PLATFORM(CAIRO)
virtual bool setup(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
#endif
......
......@@ -45,7 +45,7 @@ namespace WebCore {
virtual TextStream& externalRepresentation(TextStream&) const;
#if PLATFORM(CG) || PLATFORM(QT)
#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(CAIRO)
virtual bool setup(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
#endif
......
/*
* Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "RenderPath.h"
#include "CairoPath.h"
#include "KCanvasRenderingStyle.h"
namespace WebCore {
bool RenderPath::strokeContains(const FloatPoint& point, bool requiresStroke) const
{
if (requiresStroke && !KSVGPainterFactory::strokePaintServer(style(), this))
return false;
cairo_t* cr = path().platformPath()->m_cr;
// TODO: set stroke properties
return cairo_in_stroke(cr, point.x(), point.y());
}
FloatRect RenderPath::strokeBBox() const
{
// TODO: this implementation is naive
cairo_t* cr = path().platformPath()->m_cr;
double x0, x1, y0, y1;
cairo_stroke_extents(cr, &x0, &y0, &x1, &y1);
FloatRect bbox = FloatRect(x0, y0, x1 - x0, y1 - y0);
return bbox;
}
}
/*
* Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#if ENABLE(SVG)
#include "SVGPaintServer.h"
#include "GraphicsContext.h"
#include "KCanvasRenderingStyle.h"
#include "RenderPath.h"
#include <cairo.h>
namespace WebCore {
void SVGPaintServer::draw(GraphicsContext*& context, const RenderPath* path, SVGPaintTargetType type) const
{
if (!setup(context, path, type))
return;
renderPath(context, path, type);
teardown(context, path, type);
}
void SVGPaintServer::teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const
{
// no-op
}
void SVGPaintServer::renderPath(GraphicsContext*& context, const RenderPath* path, SVGPaintTargetType type) const
{
cairo_t* cr = context->platformContext();
const SVGRenderStyle* style = path->style()->svgStyle();
cairo_set_fill_rule(cr, style->fillRule() == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
if ((type & ApplyToFillTargetType) && style->hasFill())
cairo_fill_preserve(cr);
if ((type & ApplyToStrokeTargetType) && style->hasStroke())
cairo_stroke_preserve(cr);
cairo_new_path(cr);
}
} // namespace WebCore
#endif
/*
* Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#if ENABLE(SVG)
#include "SVGPaintServerGradient.h"
#include "SVGPaintServerLinearGradient.h"
#include "SVGPaintServerRadialGradient.h"
#include "GraphicsContext.h"
#include "RenderObject.h"
#include "RenderPath.h"
#include "RenderStyle.h"
#include "SVGGradientElement.h"
namespace WebCore {
bool SVGPaintServerGradient::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
{
m_ownerElement->buildGradient();
cairo_t* cr = context->platformContext();
cairo_pattern_t* pattern;
cairo_matrix_t matrix;
cairo_matrix_init_identity (&matrix);
const cairo_matrix_t gradient_matrix = gradientTransform();
// TODO: revise this code, it is known not to work in many cases
if (this->type() == LinearGradientPaintServer) {
const SVGPaintServerLinearGradient* linear = static_cast<const SVGPaintServerLinearGradient*>(this);
if (boundingBoxMode()) {
// TODO: use RenderPathCairo's strokeBBox?
double x1, y1, x2, y2;
cairo_fill_extents(cr, &x1, &y1, &x2, &y2);
cairo_matrix_translate(&matrix, x1, y1);
cairo_matrix_scale(&matrix, x2 - x1, y2 - y1);
cairo_matrix_multiply(&matrix, &matrix, &gradient_matrix);
cairo_matrix_invert(&matrix);
}
double x0, x1, y0, y1;
x0 = linear->gradientStart().x();
y0 = linear->gradientStart().y();
x1 = linear->gradientEnd().x();
y1 = linear->gradientEnd().y();
pattern = cairo_pattern_create_linear(x0, y0, x1, y1);
} else if (this->type() == RadialGradientPaintServer) {
const SVGPaintServerRadialGradient* radial = static_cast<const SVGPaintServerRadialGradient*>(this);
// TODO: pattern = cairo_pattern_create_radial();
return false;
} else {
return false;
}
cairo_pattern_set_filter(pattern, CAIRO_FILTER_BILINEAR);
switch (spreadMethod()) {
case SPREADMETHOD_PAD:
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_PAD);
break;
case SPREADMETHOD_REFLECT:
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REFLECT);
break;
case SPREADMETHOD_REPEAT:
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
break;
default:
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_NONE);
break;
}
cairo_pattern_set_matrix(pattern, &matrix);
const Vector<SVGGradientStop>& stops = gradientStops();
for (unsigned i = 0; i < stops.size(); ++i) {
float offset = stops[i].first;
Color color = stops[i].second;
cairo_pattern_add_color_stop_rgba(pattern, offset, color.red(), color.green(), color.blue(), color.alpha());
}
cairo_set_source(cr, pattern);
cairo_pattern_destroy(pattern);
return true;
}
} // namespace WebCore
#endif
/*
* Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#if ENABLE(SVG)
#include "NotImplemented.h"
#include "SVGPaintServerPattern.h"
namespace WebCore {
bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
{
notImplemented();
return true;
}
} // namespace WebCore
#endif
/*
* Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#if ENABLE(SVG)
#include "SVGPaintServerSolid.h"
#include "GraphicsContext.h"
#include "KCanvasRenderingStyle.h"
#include "RenderPath.h"
namespace WebCore {
bool SVGPaintServerSolid::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
{
// TODO: share this code with other PaintServers
cairo_t* cr = context->platformContext();
const SVGRenderStyle* style = object->style()->svgStyle();
float red, green, blue, alpha;
color().getRGBA(red, green, blue, alpha);
if ((type & ApplyToFillTargetType) && style->hasFill()) {
alpha = style->fillOpacity();
cairo_set_fill_rule(cr, style->fillRule() == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
}
if ((type & ApplyToStrokeTargetType) && style->hasStroke()) {
alpha = style->strokeOpacity();
cairo_set_line_width(cr, KSVGPainterFactory::cssPrimitiveToLength(object, style->strokeWidth(), 1.0));
context->setLineCap(style->capStyle());
context->setLineJoin(style->joinStyle());
if (style->joinStyle() == MiterJoin)
context->setMiterLimit(style->strokeMiterLimit());
const KCDashArray& dashes = KSVGPainterFactory::dashArrayFromRenderingStyle(object->style());
double* dsh = new double[dashes.size()];
for (int i = 0 ; i < dashes.size() ; i++)
dsh[i] = dashes[i];
double dashOffset = KSVGPainterFactory::cssPrimitiveToLength(object, style->strokeDashOffset(), 0.0);
cairo_set_dash(cr, dsh, dashes.size(), dashOffset);
delete[] dsh;
}
cairo_set_source_rgba(cr, red, green, blue, alpha);
return true;
}
} // namespace WebCore
#endif
/*
* Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#if ENABLE(SVG)
#include "SVGResourceClipper.h"
#include "AffineTransform.h"
#include "GraphicsContext.h"
#include <cairo.h>
namespace WebCore {
void SVGResourceClipper::applyClip(GraphicsContext* context, const FloatRect& boundingBox) const
{
Vector<ClipData> data = m_clipData.clipData();
unsigned int count = data.size();
if (!count)
return;
cairo_t* cr = context->platformContext();
cairo_reset_clip(cr);
for (unsigned int x = 0; x < count; x++) {
Path path = data[x].path;
if (path.isEmpty())
continue;
path.closeSubpath();
if (data[x].bboxUnits) {
// Make use of the clipping units
AffineTransform transform;
transform.translate(boundingBox.x(), boundingBox.y());
transform.scale(boundingBox.width(), boundingBox.height());
path.transform(transform);
}
cairo_set_fill_rule(cr, data[x].windRule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING);
// TODO: review this code, clipping may not be having the desired effect
context->clip(path);
}
}
} // namespace WebCore
#endif
/*
* Copyright (C) 2007 Alp Toker <alp.toker@collabora.co.uk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#if ENABLE(SVG)
#include "SVGResourceMasker.h"
#include "ImageBuffer.h"
#include "GraphicsContext.h"
#include <cairo.h>
namespace WebCore {
void SVGResourceMasker::applyMask(GraphicsContext* context, const FloatRect& boundingBox) const
{
cairo_t* cr = context->platformContext();
cairo_surface_t* surface = mask()->surface();
if (!surface)
return;
cairo_pattern_t* mask = cairo_pattern_create_for_surface(surface);
cairo_mask(cr, mask);
cairo_pattern_destroy(mask);
}
} // namespace WebCore
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment