root/trunk/WebCore/svg/graphics/cairo/SVGPaintServerPatternCairo.cpp

Revision 36737, 2.8 KB (checked in by eric@webkit.org, 2 months ago)

2008-09-21 Dirk Schulze <vbs85@gmx.de>

Reviewed by eseidel. Landed by eseidel.

All platforms use the DashArray in the GraphicsContext.

  • svg/graphics/SVGPaintServer.h:
  • svg/graphics/cairo/SVGPaintServerGradientCairo.cpp: (WebCore::SVGPaintServerGradient::setup):
  • svg/graphics/cairo/SVGPaintServerPatternCairo.cpp: (WebCore::SVGPaintServerPattern::setup):
  • svg/graphics/cairo/SVGPaintServerSolidCairo.cpp: (WebCore::SVGPaintServerSolid::setup):
  • svg/graphics/qt/SVGPaintServerGradientQt.cpp: (WebCore::SVGPaintServerGradient::setup):
  • svg/graphics/qt/SVGPaintServerQt.cpp:
  • svg/graphics/qt/SVGPaintServerSolidQt.cpp: (WebCore::SVGPaintServerSolid::setup):
  • Property svn:eol-style set to native
Line 
1/*
2 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
3 * Copyright (C) 2008 Dirk Schulze <vbs85@gmx.de>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB.  If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#include "config.h"
22
23#if ENABLE(SVG)
24#include "SVGPaintServerPattern.h"
25
26#include "GraphicsContext.h"
27#include "Image.h"
28#include "ImageBuffer.h"
29#include "RenderObject.h"
30#include "SVGPatternElement.h"
31
32#include <wtf/OwnArrayPtr.h>
33
34namespace WebCore {
35
36bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
37{
38    FloatRect targetRect = object->relativeBBox(false);
39
40    const SVGRenderStyle* svgStyle = object->style()->svgStyle();
41    RenderStyle* style = object->style();
42
43    float strokeWidth = SVGRenderStyle::cssPrimitiveToLength(object, svgStyle->strokeWidth(), 1.0f);
44
45    if (targetRect.width() == 0)
46        targetRect = FloatRect(targetRect.x(), targetRect.y(), strokeWidth, targetRect.height());
47    if (targetRect.height() == 0)
48        targetRect = FloatRect(targetRect.x(), targetRect.y(), targetRect.width(), strokeWidth);
49
50    m_ownerElement->buildPattern(targetRect);
51
52    cairo_surface_t* image = tile()->image()->nativeImageForCurrentFrame();
53    if (!image)
54        return false;
55
56    cairo_t* cr = context->platformContext();
57
58    cairo_pattern_t* pattern = cairo_pattern_create_for_surface(image);
59    cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
60
61    cairo_pattern_set_filter(pattern, CAIRO_FILTER_BEST);
62    cairo_matrix_t pattern_matrix = patternTransform();
63    cairo_matrix_t matrix = {1, 0, 0, 1, patternBoundaries().x(), patternBoundaries().y()};
64    cairo_matrix_multiply(&matrix, &matrix, &pattern_matrix);
65    cairo_matrix_invert(&matrix);
66    cairo_pattern_set_matrix(pattern, &matrix);
67
68    if ((type & ApplyToFillTargetType) && svgStyle->hasFill())
69        context->setFillRule(svgStyle->fillRule());
70
71    if ((type & ApplyToStrokeTargetType) && svgStyle->hasStroke())
72        applyStrokeStyleToContext(context, style, object);
73
74    cairo_set_source(cr, pattern);
75    cairo_pattern_destroy(pattern);
76
77    return true;
78}
79
80} // namespace WebCore
81
82#endif
Note: See TracBrowser for help on using the browser.