WebCore/ChangeLog

 12008-11-15 Dirk Schulze <krit@webkit.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Make SVGPaintServerPattern platform independent.
 6
 7 * GNUmakefile.am:
 8 * WebCore.pro:
 9 * WebCore.vcproj/WebCore.vcproj:
 10 * WebCore.xcodeproj/project.pbxproj:
 11 * svg/graphics/SVGPaintServerPattern.cpp:
 12 (WebCore::SVGPaintServerPattern::SVGPaintServerPattern):
 13 (WebCore::SVGPaintServerPattern::~SVGPaintServerPattern):
 14 (WebCore::SVGPaintServerPattern::setup):
 15 (WebCore::SVGPaintServerPattern::renderPath):
 16 (WebCore::SVGPaintServerPattern::teardown):
 17 * svg/graphics/SVGPaintServerPattern.h:
 18 * svg/graphics/cairo/SVGPaintServerPatternCairo.cpp: Removed.
 19 * svg/graphics/cg/SVGPaintServerPatternCg.cpp: Removed.
 20 * svg/graphics/qt/SVGPaintServerPatternQt.cpp: Removed.
 21
1222008-11-14 Greg Bolsinga <bolsinga@apple.com>
223
324 Reviewed by Darin Adler.
38422

WebCore/GNUmakefile.am

@@webcoregtk_sources += \
27022702 WebCore/svg/graphics/cairo/RenderPathCairo.cpp \
27032703 WebCore/svg/graphics/cairo/SVGPaintServerCairo.cpp \
27042704 WebCore/svg/graphics/cairo/SVGPaintServerGradientCairo.cpp \
2705  WebCore/svg/graphics/cairo/SVGPaintServerPatternCairo.cpp \
27062705 WebCore/svg/graphics/cairo/SVGPaintServerSolidCairo.cpp \
27072706 WebCore/svg/graphics/cairo/SVGResourceClipperCairo.cpp \
27082707 WebCore/svg/graphics/cairo/SVGResourceFilterCairo.cpp \
38364

WebCore/WebCore.pro

@@SOURCES += \
16751675 svg/graphics/qt/RenderPathQt.cpp \
16761676 svg/graphics/qt/SVGPaintServerGradientQt.cpp \
16771677 svg/graphics/qt/SVGPaintServerLinearGradientQt.cpp \
1678  svg/graphics/qt/SVGPaintServerPatternQt.cpp \
16791678 svg/graphics/qt/SVGPaintServerQt.cpp \
16801679 svg/graphics/qt/SVGPaintServerRadialGradientQt.cpp \
16811680 svg/graphics/qt/SVGPaintServerSolidQt.cpp \
38364

WebCore/WebCore.vcproj/WebCore.vcproj

1528415284 </FileConfiguration>
1528515285 </File>
1528615286 <File
15287  RelativePath="..\svg\graphics\cg\SVGPaintServerPatternCg.cpp"
15288  >
15289  <FileConfiguration
15290  Name="Debug_Cairo|Win32"
15291  ExcludedFromBuild="true"
15292  >
15293  <Tool
15294  Name="VCCLCompilerTool"
15295  />
15296  </FileConfiguration>
15297  <FileConfiguration
15298  Name="Release_Cairo|Win32"
15299  ExcludedFromBuild="true"
15300  >
15301  <Tool
15302  Name="VCCLCompilerTool"
15303  />
15304  </FileConfiguration>
15305  </File>
15306  <File
1530715287 RelativePath="..\svg\graphics\cg\SVGPaintServerSolidCg.cpp"
1530815288 >
1530915289 <FileConfiguration

1565215632 </FileConfiguration>
1565315633 </File>
1565415634 <File
15655  RelativePath="..\svg\graphics\cairo\SVGPaintServerPatternCairo.cpp"
15656  >
15657  <FileConfiguration
15658  Name="Debug|Win32"
15659  ExcludedFromBuild="true"
15660  >
15661  <Tool
15662  Name="VCCLCompilerTool"
15663  />
15664  </FileConfiguration>
15665  <FileConfiguration
15666  Name="Release|Win32"
15667  ExcludedFromBuild="true"
15668  >
15669  <Tool
15670  Name="VCCLCompilerTool"
15671  />
15672  </FileConfiguration>
15673  <FileConfiguration
15674  Name="Debug_Internal|Win32"
15675  ExcludedFromBuild="true"
15676  >
15677  <Tool
15678  Name="VCCLCompilerTool"
15679  />
15680  </FileConfiguration>
15681  <FileConfiguration
15682  Name="Release_PGO|Win32"
15683  ExcludedFromBuild="true"
15684  >
15685  <Tool
15686  Name="VCCLCompilerTool"
15687  />
15688  </FileConfiguration>
15689  </File>
15690  <File
1569115635 RelativePath="..\svg\graphics\cairo\SVGPaintServerSolidCairo.cpp"
1569215636 >
1569315637 <FileConfiguration
38364

WebCore/WebCore.xcodeproj/project.pbxproj

30933093 B255992E0D00D8BA00BB825C /* RenderPathCg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B25598920D00D8B800BB825C /* RenderPathCg.cpp */; };
30943094 B255992F0D00D8BA00BB825C /* SVGPaintServerCg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B25598930D00D8B800BB825C /* SVGPaintServerCg.cpp */; };
30953095 B25599300D00D8BA00BB825C /* SVGPaintServerGradientCg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B25598940D00D8B800BB825C /* SVGPaintServerGradientCg.cpp */; };
3096  B25599310D00D8BA00BB825C /* SVGPaintServerPatternCg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B25598950D00D8B800BB825C /* SVGPaintServerPatternCg.cpp */; };
30973096 B25599320D00D8BA00BB825C /* SVGPaintServerSolidCg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B25598960D00D8B800BB825C /* SVGPaintServerSolidCg.cpp */; };
30983097 B25599330D00D8BA00BB825C /* SVGResourceClipperCg.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B25598970D00D8B800BB825C /* SVGResourceClipperCg.cpp */; };
30993098 B25599350D00D8BA00BB825C /* SVGResourceFilterCg.mm in Sources */ = {isa = PBXBuildFile; fileRef = B25598990D00D8B800BB825C /* SVGResourceFilterCg.mm */; };

76897688 B25598920D00D8B800BB825C /* RenderPathCg.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RenderPathCg.cpp; sourceTree = "<group>"; };
76907689 B25598930D00D8B800BB825C /* SVGPaintServerCg.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPaintServerCg.cpp; sourceTree = "<group>"; };
76917690 B25598940D00D8B800BB825C /* SVGPaintServerGradientCg.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPaintServerGradientCg.cpp; sourceTree = "<group>"; };
7692  B25598950D00D8B800BB825C /* SVGPaintServerPatternCg.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPaintServerPatternCg.cpp; sourceTree = "<group>"; };
76937691 B25598960D00D8B800BB825C /* SVGPaintServerSolidCg.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPaintServerSolidCg.cpp; sourceTree = "<group>"; };
76947692 B25598970D00D8B800BB825C /* SVGResourceClipperCg.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGResourceClipperCg.cpp; sourceTree = "<group>"; };
76957693 B25598990D00D8B800BB825C /* SVGResourceFilterCg.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = SVGResourceFilterCg.mm; sourceTree = "<group>"; };

1250412502 B25598920D00D8B800BB825C /* RenderPathCg.cpp */,
1250512503 B25598930D00D8B800BB825C /* SVGPaintServerCg.cpp */,
1250612504 B25598940D00D8B800BB825C /* SVGPaintServerGradientCg.cpp */,
12507  B25598950D00D8B800BB825C /* SVGPaintServerPatternCg.cpp */,
1250812505 B25598960D00D8B800BB825C /* SVGPaintServerSolidCg.cpp */,
1250912506 B25598970D00D8B800BB825C /* SVGResourceClipperCg.cpp */,
1251012507 B25598990D00D8B800BB825C /* SVGResourceFilterCg.mm */,

1759717594 B25599300D00D8BA00BB825C /* SVGPaintServerGradientCg.cpp in Sources */,
1759817595 B25599AA0D00D8BA00BB825C /* SVGPaintServerLinearGradient.cpp in Sources */,
1759917596 B25599AC0D00D8BA00BB825C /* SVGPaintServerPattern.cpp in Sources */,
17600  B25599310D00D8BA00BB825C /* SVGPaintServerPatternCg.cpp in Sources */,
1760117597 B25599AE0D00D8BA00BB825C /* SVGPaintServerRadialGradient.cpp in Sources */,
1760217598 B25599B00D00D8BA00BB825C /* SVGPaintServerSolid.cpp in Sources */,
1760317599 B25599320D00D8BA00BB825C /* SVGPaintServerSolidCg.cpp in Sources */,
38364

WebCore/svg/graphics/SVGPaintServerPattern.cpp

2828#if ENABLE(SVG)
2929#include "SVGPaintServerPattern.h"
3030
 31#include "AffineTransform.h"
 32#include "GraphicsContext.h"
 33#include "Image.h"
3134#include "ImageBuffer.h"
 35#include "Pattern.h"
 36#include "RenderObject.h"
3237#include "SVGPatternElement.h"
3338#include "SVGRenderTreeAsText.h"
3439

@@namespace WebCore {
3843
3944SVGPaintServerPattern::SVGPaintServerPattern(const SVGPatternElement* owner)
4045 : m_ownerElement(owner)
41 #if PLATFORM(CG)
42  , m_patternSpace(0)
4346 , m_pattern(0)
44 #endif
4547{
4648 ASSERT(owner);
4749}
4850
4951SVGPaintServerPattern::~SVGPaintServerPattern()
5052{
51 #if PLATFORM(CG)
52  CGPatternRelease(m_pattern);
53  CGColorSpaceRelease(m_patternSpace);
54 #endif
5553}
5654
5755FloatRect SVGPaintServerPattern::patternBoundaries() const

@@TextStream& SVGPaintServerPattern::exter
9694 return ts;
9795}
9896
 97bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
 98{
 99 FloatRect targetRect;
 100 if (isPaintingText) {
 101 IntRect textBoundary = const_cast<RenderObject*>(object)->absoluteBoundingBoxRect();
 102 targetRect = object->absoluteTransform().inverse().mapRect(textBoundary);
 103 } else
 104 targetRect = object->relativeBBox(false);
 105
 106 const SVGRenderStyle* style = object->style()->svgStyle();
 107
 108 m_ownerElement->buildPattern(targetRect);
 109 if (!tile())
 110 return false;
 111
 112 context->save();
 113 context->translate(patternBoundaries().x(), patternBoundaries().y());
 114 context->concatCTM(patternTransform());
 115
 116 ASSERT(!m_pattern);
 117
 118 IntRect tileRect = tile()->image()->rect();
 119 if (tileRect.width() > patternBoundaries().width() || tileRect.height() > patternBoundaries().height()) {
 120 // Draw the first cell of the pattern manually to support overflow="visible" on all platforms.
 121 int tileWidth = static_cast<int>(patternBoundaries().width() + 0.5f);
 122 int tileHeight = static_cast<int>(patternBoundaries().height() + 0.5f);
 123 std::auto_ptr<ImageBuffer> tileImage = ImageBuffer::create(IntSize(tileWidth, tileHeight), false);
 124
 125 GraphicsContext* tileImageContext = tileImage->context();
 126
 127 int numY = static_cast<int>(ceilf(tileRect.height() / tileHeight)) + 1;
 128 int numX = static_cast<int>(ceilf(tileRect.width() / tileWidth)) + 1;
 129
 130 tileImageContext->save();
 131 tileImageContext->translate(-patternBoundaries().width() * numX, -patternBoundaries().height() * numY);
 132 for (int i = numY; i > 0; i--) {
 133 tileImageContext->translate(0, patternBoundaries().height());
 134 for (int j = numX; j > 0; j--) {
 135 tileImageContext->translate(patternBoundaries().width(), 0);
 136 tileImageContext->drawImage(tile()->image(), tileRect, tileRect);
 137 }
 138 tileImageContext->translate(-patternBoundaries().width() * numX, 0);
 139 }
 140 tileImageContext->restore();
 141
 142 m_pattern = Pattern::create(tileImage->image(), true, true);
 143 }
 144 else
 145 m_pattern = Pattern::create(tile()->image(), true, true);
 146
 147 if ((type & ApplyToFillTargetType) && style->hasFill()) {
 148 context->setAlpha(style->fillOpacity());
 149 context->setFillPattern(m_pattern);
 150 context->setFillRule(style->fillRule());
 151
 152 if (isPaintingText)
 153 context->setTextDrawingMode(cTextFill);
 154 }
 155 if ((type & ApplyToStrokeTargetType) && style->hasStroke()) {
 156 context->setAlpha(style->strokeOpacity());
 157 context->setStrokePattern(m_pattern);
 158 applyStrokeStyleToContext(context, object->style(), object);
 159
 160 if (isPaintingText)
 161 context->setTextDrawingMode(cTextStroke);
 162 }
 163
 164 return true;
 165}
 166
 167void SVGPaintServerPattern::renderPath(GraphicsContext*& context, const RenderObject* path, SVGPaintTargetType type) const
 168{
 169 const SVGRenderStyle* style = path->style()->svgStyle();
 170
 171 if ((type & ApplyToFillTargetType) && style->hasFill())
 172 context->fillPath();
 173
 174 if ((type & ApplyToStrokeTargetType) && style->hasStroke())
 175 context->strokePath();
 176}
 177
 178void SVGPaintServerPattern::teardown(GraphicsContext*& context, const RenderObject*, SVGPaintTargetType, bool) const
 179{
 180 m_pattern = 0;
 181
 182 context->restore();
 183}
 184
99185} // namespace WebCore
100186
101187#endif
38364

WebCore/svg/graphics/SVGPaintServerPattern.h

3030
3131#include "AffineTransform.h"
3232#include "FloatRect.h"
 33#include "Pattern.h"
3334#include "SVGPaintServer.h"
3435
3536#include <memory>

@@namespace WebCore {
6364 virtual TextStream& externalRepresentation(TextStream&) const;
6465
6566 virtual bool setup(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
66 #if PLATFORM(CG) || PLATFORM(QT)
 67 virtual void renderPath(GraphicsContext*&, const RenderObject*, SVGPaintTargetType) const;
6768 virtual void teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
68 #endif
6969
7070 private:
7171 SVGPaintServerPattern(const SVGPatternElement*);

@@namespace WebCore {
7575 AffineTransform m_patternTransform;
7676 FloatRect m_patternBoundaries;
7777
78 #if PLATFORM(CG)
79  mutable CGColorSpaceRef m_patternSpace;
80  mutable CGPatternRef m_pattern;
81 #endif
 78 mutable RefPtr<Pattern> m_pattern;
8279 };
8380
8481} // namespace WebCore
38364

WebCore/svg/graphics/cairo/SVGPaintServerPatternCairo.cpp

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 
34 namespace WebCore {
35 
36 bool 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
38364

WebCore/svg/graphics/cg/SVGPaintServerPatternCg.cpp

1 /*
2  Copyright (C) 2006, 2007 Nikolas Zimmermann <zimmermann@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 "SVGPaintServerPattern.h"
26 
27 #include "CgSupport.h"
28 #include "GraphicsContext.h"
29 #include "ImageBuffer.h"
30 #include "RenderObject.h"
31 #include "SVGPatternElement.h"
32 
33 namespace WebCore {
34 
35 static void patternCallback(void* info, CGContextRef context)
36 {
37  ImageBuffer* patternImage = reinterpret_cast<ImageBuffer*>(info);
38  CGContextSaveGState(context);
39  CGContextTranslateCTM(context, 0, patternImage->size().height());
40  CGContextScaleCTM(context, 1.0f, -1.0f);
41  CGContextDrawImage(context, CGRect(FloatRect(FloatPoint(), patternImage->size())), patternImage->image()->getCGImageRef());
42  CGContextRestoreGState(context);
43 }
44 
45 bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
46 {
47  CGContextRef contextRef = context->platformContext();
48 
49  // Build pattern tile, passing destination object bounding box
50  FloatRect targetRect;
51  if (isPaintingText) {
52  IntRect textBoundary = const_cast<RenderObject*>(object)->absoluteBoundingBoxRect();
53  targetRect = object->absoluteTransform().inverse().mapRect(textBoundary);
54  } else
55  targetRect = object->relativeBBox(false);
56 
57  m_ownerElement->buildPattern(targetRect);
58 
59  if (!tile())
60  return false;
61 
62  context->save();
63 
64  // Respect local pattern transformation
65  context->concatCTM(patternTransform());
66 
67  // Apply pattern space transformation
68  context->translate(patternBoundaries().x(), patternBoundaries().y());
69 
70  // Crude hack to support overflow="visible".
71  // When the patternBoundaries() size is smaller than the actual tile() size, we run into a problem:
72  // Our tile contains content which is larger than the pattern cell size. We just draw the pattern
73  // "out of" cell boundaries, to draw the overflown content, instead of clipping it away. The uppermost
74  // cell doesn't include the overflown content of the cell right above it though -> that's why we're moving
75  // down the phase by a very small amount, so we're sure the "cell right above"'s overflown content gets drawn.
76  CGContextSetPatternPhase(contextRef, CGSizeMake(0.0f, -0.01f));
77 
78  RenderStyle* style = object->style();
79  CGContextSetAlpha(contextRef, style->opacity());
80 
81  CGPatternCallbacks callbacks = {0, patternCallback, 0};
82 
83  ASSERT(!m_pattern);
84  m_pattern = CGPatternCreate(tile(),
85  CGRect(FloatRect(FloatPoint(), tile()->size())),
86  CGContextGetCTM(contextRef),
87  patternBoundaries().width(),
88  patternBoundaries().height(),
89  kCGPatternTilingConstantSpacing,
90  true, // has color
91  &callbacks);
92 
93  if (!m_patternSpace)
94  m_patternSpace = CGColorSpaceCreatePattern(0);
95 
96  if ((type & ApplyToFillTargetType) && style->svgStyle()->hasFill()) {
97  CGFloat alpha = style->svgStyle()->fillOpacity();
98  CGContextSetFillColorSpace(contextRef, m_patternSpace);
99  CGContextSetFillPattern(contextRef, m_pattern, &alpha);
100 
101  if (isPaintingText)
102  context->setTextDrawingMode(cTextFill);
103  }
104 
105  if ((type & ApplyToStrokeTargetType) && style->svgStyle()->hasStroke()) {
106  CGFloat alpha = style->svgStyle()->strokeOpacity();
107  CGContextSetStrokeColorSpace(contextRef, m_patternSpace);
108  CGContextSetStrokePattern(contextRef, m_pattern, &alpha);
109  applyStrokeStyleToContext(context, style, object);
110 
111  if (isPaintingText)
112  context->setTextDrawingMode(cTextStroke);
113  }
114 
115  return true;
116 }
117 
118 void SVGPaintServerPattern::teardown(GraphicsContext*& context, const RenderObject*, SVGPaintTargetType, bool) const
119 {
120  CGPatternRelease(m_pattern);
121  m_pattern = 0;
122 
123  context->restore();
124 }
125 
126 } // namespace WebCore
127 
128 #endif
129 
130 // vim:ts=4:noet
38364

WebCore/svg/graphics/qt/SVGPaintServerPatternQt.cpp

1 /*
2  Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org>
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  aint 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 "AffineTransform.h"
27 #include "GraphicsContext.h"
28 #include "ImageBuffer.h"
29 #include "Pattern.h"
30 #include "RenderObject.h"
31 #include "SVGPatternElement.h"
32 
33 #include <QPainter>
34 #include <QPainterPath>
35 
36 namespace WebCore {
37 
38 bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const
39 {
40  Q_ASSERT(context);
41  Q_ASSERT(object);
42 
43  FloatRect targetRect = object->relativeBBox(false);
44  m_ownerElement->buildPattern(targetRect);
45 
46  if (!tile())
47  return false;
48 
49  QPainter* painter = context->platformContext();
50  QPainterPath* path = context->currentPath();
51 
52  RenderStyle* style = object->style();
53  const SVGRenderStyle* svgStyle = object->style()->svgStyle();
54 
55  RefPtr<Pattern> pattern = Pattern::create(tile()->image(), true, true);
56 
57  context->save();
58  painter->setPen(Qt::NoPen);
59  painter->setBrush(Qt::NoBrush);
60 
61  AffineTransform affine;
62  affine.translate(patternBoundaries().x(), patternBoundaries().y());
63  affine.multiply(patternTransform());
64 
65  QBrush brush(pattern->createPlatformPattern(affine));
66  if ((type & ApplyToFillTargetType) && svgStyle->hasFill()) {
67  painter->setBrush(brush);
68  context->setFillRule(svgStyle->fillRule());
69  }
70 
71  if ((type & ApplyToStrokeTargetType) && svgStyle->hasStroke()) {
72  QPen pen;
73  pen.setBrush(brush);
74  painter->setPen(pen);
75  applyStrokeStyleToContext(context, style, object);
76  }
77 
78  return true;
79 }
80 
81 void SVGPaintServerPattern::teardown(GraphicsContext*& context, const RenderObject*, SVGPaintTargetType, bool) const
82 {
83  context->restore();
84 }
85 
86 } // namespace WebCore
87 
88 #endif
89 
90 // vim:ts=4:noet
38364