diff options
Diffstat (limited to 'WebCore/svg/graphics/cairo')
8 files changed, 491 insertions, 0 deletions
diff --git a/WebCore/svg/graphics/cairo/RenderPathCairo.cpp b/WebCore/svg/graphics/cairo/RenderPathCairo.cpp new file mode 100644 index 0000000..72379b5 --- /dev/null +++ b/WebCore/svg/graphics/cairo/RenderPathCairo.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "RenderPath.h" + +#include "CairoPath.h" +#include "SVGPaintServer.h" + +namespace WebCore { + +bool RenderPath::strokeContains(const FloatPoint& point, bool requiresStroke) const +{ + if (requiresStroke && !SVGPaintServer::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; +} + +} diff --git a/WebCore/svg/graphics/cairo/SVGPaintServerCairo.cpp b/WebCore/svg/graphics/cairo/SVGPaintServerCairo.cpp new file mode 100644 index 0000000..37cab6f --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGPaintServerCairo.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServer.h" + +#include "GraphicsContext.h" +#include "SVGPaintServer.h" +#include "RenderPath.h" + +#include <cairo.h> + +namespace WebCore { + +void SVGPaintServer::draw(GraphicsContext*& context, const RenderObject* 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 RenderObject* 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 diff --git a/WebCore/svg/graphics/cairo/SVGPaintServerGradientCairo.cpp b/WebCore/svg/graphics/cairo/SVGPaintServerGradientCairo.cpp new file mode 100644 index 0000000..7b22f4f --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGPaintServerGradientCairo.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#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 diff --git a/WebCore/svg/graphics/cairo/SVGPaintServerPatternCairo.cpp b/WebCore/svg/graphics/cairo/SVGPaintServerPatternCairo.cpp new file mode 100644 index 0000000..6381277 --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGPaintServerPatternCairo.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#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 diff --git a/WebCore/svg/graphics/cairo/SVGPaintServerSolidCairo.cpp b/WebCore/svg/graphics/cairo/SVGPaintServerSolidCairo.cpp new file mode 100644 index 0000000..6acc9b2 --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGPaintServerSolidCairo.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServerSolid.h" + +#include "GraphicsContext.h" +#include "SVGPaintServer.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, SVGRenderStyle::cssPrimitiveToLength(object, style->strokeWidth(), 1.0)); + context->setLineCap(style->capStyle()); + context->setLineJoin(style->joinStyle()); + if (style->joinStyle() == MiterJoin) + context->setMiterLimit(style->strokeMiterLimit()); + + const DashArray& dashes = dashArrayFromRenderingStyle(object->style()); + double* dsh = new double[dashes.size()]; + for (unsigned i = 0 ; i < dashes.size() ; i++) + dsh[i] = dashes[i]; + double dashOffset = SVGRenderStyle::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 diff --git a/WebCore/svg/graphics/cairo/SVGResourceClipperCairo.cpp b/WebCore/svg/graphics/cairo/SVGResourceClipperCairo.cpp new file mode 100644 index 0000000..5900fcd --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGResourceClipperCairo.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#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 diff --git a/WebCore/svg/graphics/cairo/SVGResourceFilterCairo.cpp b/WebCore/svg/graphics/cairo/SVGResourceFilterCairo.cpp new file mode 100644 index 0000000..a27038a --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGResourceFilterCairo.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2008 Collabora Ltd. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#include "NotImplemented.h" +#include "SVGResourceFilter.h" + +namespace WebCore { + +SVGResourceFilterPlatformData* SVGResourceFilter::createPlatformData() +{ + notImplemented(); + return 0; +} + +void SVGResourceFilter::prepareFilter(GraphicsContext*&, const FloatRect&) +{ + notImplemented(); +} + +void SVGResourceFilter::applyFilter(GraphicsContext*&, const FloatRect&) +{ + notImplemented(); +} + +} // namespace WebCore + +#endif + diff --git a/WebCore/svg/graphics/cairo/SVGResourceMaskerCairo.cpp b/WebCore/svg/graphics/cairo/SVGResourceMaskerCairo.cpp new file mode 100644 index 0000000..78ea76b --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGResourceMaskerCairo.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#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) +{ + cairo_t* cr = context->platformContext(); + cairo_surface_t* surface = m_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 |