Changeset 39427 in webkit
- Timestamp:
- Dec 21, 2008 3:44:16 PM (15 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 1 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r39424 r39427 1 2008-12-21 Dirk Schulze <krit@webkit.org> 2 3 Reviewed by Darin Adler, Nikolas Zimmermann. 4 5 Move the the platform dependent strokeBBox functionality out of RenderPath 6 into Path with strokeBoundingRect. 7 8 RenderPath clean-up for strokeBoundingBox 9 [https://bugs.webkit.org/show_bug.cgi?id=22902] 10 11 * GNUmakefile.am: 12 * WebCore.xcodeproj/project.pbxproj: 13 * platform/graphics/GraphicsContext.h: 14 * platform/graphics/Path.h: 15 * platform/graphics/StrokeStyleApplier.h: Added. 16 (WebCore::StrokeStyleApplier::~StrokeStyleApplier): 17 * platform/graphics/cairo/PathCairo.cpp: 18 (WebCore::Path::strokeBoundingRect): 19 * platform/graphics/cg/PathCG.cpp: 20 (WebCore::createScratchContext): 21 (WebCore::scratchContext): 22 (WebCore::Path::strokeBoundingRect): 23 * platform/graphics/qt/GraphicsContextQt.cpp: 24 (WebCore::GraphicsContext::pen): 25 * platform/graphics/qt/PathQt.cpp: 26 (WebCore::Path::strokeBoundingRect): 27 * rendering/RenderPath.cpp: 28 (WebCore::StrokeBoundingRectStyleApplier::StrokeBoundingRectStyleApplier): 29 (WebCore::StrokeBoundingRectStyleApplier::strokeStyle): 30 (WebCore::RenderPath::relativeBBox): 31 * rendering/RenderPath.h: 32 * svg/graphics/cairo/RenderPathCairo.cpp: 33 * svg/graphics/cg/RenderPathCg.cpp: 34 * svg/graphics/qt/RenderPathQt.cpp: 35 1 36 2008-12-20 David Kilzer <ddkilzer@apple.com> 2 37 -
trunk/WebCore/GNUmakefile.am
r39408 r39427 1327 1327 WebCore/platform/graphics/StringTruncator.cpp \ 1328 1328 WebCore/platform/graphics/StringTruncator.h \ 1329 WebCore/platform/graphics/StrokeStyleApplier.h \ 1329 1330 WebCore/platform/graphics/TextRun.h \ 1330 1331 WebCore/platform/graphics/UnitBezier.h \ -
trunk/WebCore/WebCore.xcodeproj/project.pbxproj
r39388 r39427 874 874 75793ED40D0CE85B007FC0AC /* DOMMessageEvent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 75793ED10D0CE85B007FC0AC /* DOMMessageEvent.mm */; }; 875 875 75793ED50D0CE85B007FC0AC /* DOMMessageEventInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 75793ED20D0CE85B007FC0AC /* DOMMessageEventInternal.h */; }; 876 849F77760EFEC6200090849D /* StrokeStyleApplier.h in Headers */ = {isa = PBXBuildFile; fileRef = 849F77750EFEC6200090849D /* StrokeStyleApplier.h */; }; 876 877 85004D940ACEEAEF00C438F6 /* DOMSVGDefsElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 85004D880ACEEAEF00C438F6 /* DOMSVGDefsElement.h */; }; 877 878 85004D950ACEEAEF00C438F6 /* DOMSVGDefsElement.mm in Sources */ = {isa = PBXBuildFile; fileRef = 85004D890ACEEAEF00C438F6 /* DOMSVGDefsElement.mm */; }; … … 5753 5754 75793ED10D0CE85B007FC0AC /* DOMMessageEvent.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMMessageEvent.mm; sourceTree = "<group>"; }; 5754 5755 75793ED20D0CE85B007FC0AC /* DOMMessageEventInternal.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMMessageEventInternal.h; sourceTree = "<group>"; }; 5756 849F77750EFEC6200090849D /* StrokeStyleApplier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StrokeStyleApplier.h; sourceTree = "<group>"; }; 5755 5757 84B2B1F7056BEF3A00D2B771 /* WebCoreKeyGenerator.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreKeyGenerator.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; }; 5756 5758 84B2B1F8056BEF3A00D2B771 /* WebCoreKeyGenerator.m */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = WebCoreKeyGenerator.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; }; … … 9575 9577 49E911BB0EF86D47009D0CAF /* ScaleTransformOperation.h */, 9576 9578 49E911BC0EF86D47009D0CAF /* SkewTransformOperation.cpp */, 9579 849F77750EFEC6200090849D /* StrokeStyleApplier.h */, 9577 9580 49E911BD0EF86D47009D0CAF /* SkewTransformOperation.h */, 9578 9581 49E911BE0EF86D47009D0CAF /* TransformOperation.h */, … … 16456 16459 49E912AD0EFAC906009D0CAF /* AnimationList.h in Headers */, 16457 16460 49E912AE0EFAC906009D0CAF /* TimingFunction.h in Headers */, 16461 849F77760EFEC6200090849D /* StrokeStyleApplier.h in Headers */, 16458 16462 ); 16459 16463 runOnlyForDeploymentPostprocessing = 0; -
trunk/WebCore/platform/graphics/GraphicsContext.h
r39105 r39427 313 313 bool inTransparencyLayer() const; 314 314 PlatformPath* currentPath(); 315 QPen pen(); 315 316 #endif 316 317 -
trunk/WebCore/platform/graphics/Path.h
r35966 r39427 57 57 class FloatSize; 58 58 class FloatRect; 59 class GraphicsContext; 59 60 class String; 61 class StrokeStyleApplier; 60 62 61 63 enum WindRule { … … 89 91 bool contains(const FloatPoint&, WindRule rule = RULE_NONZERO) const; 90 92 FloatRect boundingRect() const; 93 FloatRect strokeBoundingRect(StrokeStyleApplier* applier = 0); 91 94 92 95 float length(); -
trunk/WebCore/platform/graphics/cairo/PathCairo.cpp
r38794 r39427 28 28 #include "CairoPath.h" 29 29 #include "FloatRect.h" 30 #include "GraphicsContext.h" 30 31 #include "NotImplemented.h" 31 32 #include "PlatformString.h" 33 #include "StrokeStyleApplier.h" 32 34 33 35 #include <cairo.h> … … 189 191 } 190 192 193 FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) 194 { 195 cairo_t* cr = platformPath()->m_cr; 196 GraphicsContext gc(cr); 197 if (applier) 198 applier->strokeStyle(&gc); 199 200 double x0, x1, y0, y1; 201 cairo_stroke_extents(cr, &x0, &y0, &x1, &y1); 202 return FloatRect(x0, y0, x1 - x0, y1 - y0); 203 } 204 191 205 bool Path::contains(const FloatPoint& point, WindRule rule) const 192 206 { -
trunk/WebCore/platform/graphics/cg/PathCG.cpp
r38794 r39427 33 33 #include <ApplicationServices/ApplicationServices.h> 34 34 #include "FloatRect.h" 35 #include "GraphicsContext.h" 35 36 #include "IntRect.h" 36 37 #include "PlatformString.h" 38 #include "StrokeStyleApplier.h" 37 39 38 40 #include <wtf/MathExtras.h> … … 63 65 } 64 66 67 static CGContextRef createScratchContext() 68 { 69 CFMutableDataRef empty = CFDataCreateMutable(NULL, 0); 70 CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData(empty); 71 CGContextRef contextRef = CGPDFContextCreate(consumer, NULL, NULL); 72 CGDataConsumerRelease(consumer); 73 CFRelease(empty); 74 75 CGFloat black[4] = {0, 0, 0, 1}; 76 CGContextSetFillColor(contextRef, black); 77 CGContextSetStrokeColor(contextRef, black); 78 return contextRef; 79 } 80 81 static inline CGContextRef scratchContext() 82 { 83 static CGContextRef context = createScratchContext(); 84 return context; 85 } 65 86 66 87 static void copyClosingSubpathsApplierFunction(void* info, const CGPathElement* element) … … 122 143 { 123 144 return CGPathGetBoundingBox(m_path); 145 } 146 147 FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) 148 { 149 CGContextRef context = scratchContext(); 150 151 CGContextSaveGState(context); 152 CGContextBeginPath(context); 153 CGContextAddPath(context, platformPath()); 154 155 GraphicsContext gc(context); 156 if (applier) 157 applier->strokeStyle(&gc); 158 159 CGContextReplacePathWithStrokedPath(context); 160 if (CGContextIsPathEmpty(context)) { 161 CGContextRestoreGState(context); 162 return FloatRect(); 163 } 164 CGRect box = CGContextGetPathBoundingBox(context); 165 CGContextRestoreGState(context); 166 167 return box; 124 168 } 125 169 -
trunk/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
r38785 r39427 526 526 } 527 527 528 QPen GraphicsContext::pen() 529 { 530 if (paintingDisabled()) 531 return QPen(); 532 533 QPainter *p = m_data->p(); 534 return p->pen(); 535 } 536 528 537 void GraphicsContext::fillPath() 529 538 { -
trunk/WebCore/platform/graphics/qt/PathQt.cpp
r38618 r39427 30 30 #include "Path.h" 31 31 32 #include "AffineTransform.h" 32 33 #include "FloatRect.h" 34 #include "GraphicsContext.h" 35 #include "ImageBuffer.h" 33 36 #include "PlatformString.h" 34 #include " AffineTransform.h"37 #include "StrokeStyleApplier.h" 35 38 #include <QPainterPath> 36 39 #include <QMatrix> … … 92 95 { 93 96 return m_path->boundingRect(); 97 } 98 99 FloatRect Path::strokeBoundingRect(StrokeStyleApplier* applier) 100 { 101 // FIXME: We should try to use a 'shared Context' instead of creating a new ImageBuffer 102 // on each call. 103 std::auto_ptr<ImageBuffer> scratchImage = ImageBuffer::create(IntSize(1, 1), false); 104 GraphicsContext* gc = scratchImage->context(); 105 QPainterPathStroker stroke; 106 if (applier) { 107 applier->strokeStyle(gc); 108 109 QPen pen = gc->pen(); 110 stroke.setWidth(pen.widthF()); 111 stroke.setCapStyle(pen.capStyle()); 112 stroke.setJoinStyle(pen.joinStyle()); 113 stroke.setMiterLimit(pen.miterLimit()); 114 stroke.setDashPattern(pen.dashPattern()); 115 stroke.setDashOffset(pen.dashOffset()); 116 } 117 return (stroke.createStroke(*platformPath())).boundingRect(); 94 118 } 95 119 -
trunk/WebCore/rendering/RenderPath.cpp
r38353 r39427 33 33 #include "PointerEventsHitRules.h" 34 34 #include "RenderSVGContainer.h" 35 #include "StrokeStyleApplier.h" 35 36 #include "SVGPaintServer.h" 36 37 #include "SVGRenderSupport.h" … … 46 47 namespace WebCore { 47 48 49 class BoundingRectStrokeStyleApplier : public StrokeStyleApplier { 50 public: 51 BoundingRectStrokeStyleApplier(const RenderObject* object, RenderStyle* style) 52 : m_object(object) 53 , m_style(style) 54 { 55 ASSERT(style); 56 ASSERT(object); 57 } 58 59 void strokeStyle(GraphicsContext* gc) 60 { 61 applyStrokeStyleToContext(gc, m_style, m_object); 62 } 63 64 private: 65 const RenderObject* m_object; 66 RenderStyle* m_style; 67 }; 68 48 69 // RenderPath 49 70 RenderPath::RenderPath(RenderStyle* style, SVGStyledTransformableElement* node) … … 90 111 91 112 if (includeStroke) { 92 if (m_strokeBbox.isEmpty()) 93 m_strokeBbox = strokeBBox(); 113 if (m_strokeBbox.isEmpty()) { 114 if (style()->svgStyle()->hasStroke()) { 115 BoundingRectStrokeStyleApplier strokeStyle(this, style()); 116 m_strokeBbox = m_path.strokeBoundingRect(&strokeStyle); 117 } else { 118 if (m_fillBBox.isEmpty()) 119 m_fillBBox = m_path.boundingRect(); 120 121 m_strokeBbox = m_fillBBox; 122 } 123 } 94 124 95 125 return m_strokeBbox; -
trunk/WebCore/rendering/RenderPath.h
r38346 r39427 47 47 48 48 // Hit-detection seperated for the fill and the stroke 49 virtualbool fillContains(const FloatPoint&, bool requiresFill = true) const;50 virtualbool strokeContains(const FloatPoint&, bool requiresStroke = true) const;49 bool fillContains(const FloatPoint&, bool requiresFill = true) const; 50 bool strokeContains(const FloatPoint&, bool requiresStroke = true) const; 51 51 52 52 // Returns an unscaled bounding box (not even including localTransform()) for this vector path … … 76 76 77 77 FloatRect drawMarkersIfNeeded(GraphicsContext*, const FloatRect&, const Path&) const; 78 virtual FloatRect strokeBBox() const;79 78 80 79 private: -
trunk/WebCore/svg/graphics/cairo/RenderPathCairo.cpp
r29663 r39427 37 37 } 38 38 39 FloatRect RenderPath::strokeBBox() const40 {41 // TODO: this implementation is naive42 43 cairo_t* cr = path().platformPath()->m_cr;44 45 double x0, x1, y0, y1;46 cairo_stroke_extents(cr, &x0, &y0, &x1, &y1);47 FloatRect bbox = FloatRect(x0, y0, x1 - x0, y1 - y0);48 49 return bbox;50 39 } 51 52 } -
trunk/WebCore/svg/graphics/cg/RenderPathCg.cpp
r29216 r39427 41 41 namespace WebCore { 42 42 43 FloatRect RenderPath::strokeBBox() const44 {45 if (style()->svgStyle()->hasStroke())46 return strokeBoundingBox(path(), style(), this);47 48 return path().boundingRect();49 }50 51 52 43 bool RenderPath::strokeContains(const FloatPoint& point, bool requiresStroke) const 53 44 { -
trunk/WebCore/svg/graphics/qt/RenderPathQt.cpp
r29663 r39427 43 43 } 44 44 45 static QPainterPath getPathStroke(const QPainterPath &path, const RenderObject* object, const RenderStyle* style)46 {47 QPainterPathStroker s;48 s.setWidth(SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0));49 50 if (style->svgStyle()->capStyle() == ButtCap)51 s.setCapStyle(Qt::FlatCap);52 else if (style->svgStyle()->capStyle() == RoundCap)53 s.setCapStyle(Qt::RoundCap);54 55 if (style->svgStyle()->joinStyle() == MiterJoin) {56 s.setJoinStyle(Qt::MiterJoin);57 s.setMiterLimit((qreal) style->svgStyle()->strokeMiterLimit());58 } else if(style->svgStyle()->joinStyle() == RoundJoin)59 s.setJoinStyle(Qt::RoundJoin);60 61 const DashArray& dashes = WebCore::dashArrayFromRenderingStyle(style);62 double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0);63 64 unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0;65 if(dashLength) {66 QVector<qreal> pattern;67 unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2;68 69 for(unsigned int i = 0; i < count; i++)70 pattern.append(dashes[i % dashLength] / (float)s.width());71 72 s.setDashPattern(pattern);73 74 Q_UNUSED(dashOffset);75 // TODO: dash-offset, does/will qt4 API allow it? (Rob)76 }77 78 return s.createStroke(path);79 }80 81 FloatRect RenderPath::strokeBBox() const82 {83 QPainterPath outline = getPathStroke(*(path().platformPath()), this, style());84 return outline.boundingRect();85 }86 87 45 } 88 46
Note: See TracChangeset
for help on using the changeset viewer.