Changeset 190849 in webkit
- Timestamp:
- Oct 11, 2015 8:34:08 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r190845 r190849 1 2015-10-11 Simon Fraser <simon.fraser@apple.com> 2 3 Cleanup and simplification of SVG path-related classes 4 https://bugs.webkit.org/show_bug.cgi?id=150011 5 6 Reviewed by Zalan Bujtas. 7 8 Many SVG path-related subclasses were stateful, but only because code in 9 SVGPathUtilities kept global copies around for no reason. A microbenchmark 10 showed that there was no benefit to keeping global singletons of SVGPathBuilder, 11 SVGPathSegListBuilder, SVGPathByteStreamBuilder, SVGPathStringBuilder, 12 SVGPathTraversalStateBuilder, SVGPathParser and SVGPathBlender. 13 14 Making these classes not be re-usable makes the code much simpler, allowing 15 their SVGPathSources, SVGPathConsumers, SVGPathByteStream etc. to be stored 16 by reference, and eliminating the cleanup() function which created annoying 17 ordering issues. 18 19 Code that uses SVGPathParser and SVGPathBlender is further simplified by having 20 these classes expose only static functions, hiding any internal statefulness. 21 22 * svg/SVGPathBlender.cpp: Remove the m_progress member variable and instead 23 pass progress to the various blend functions, as we do for other blend functions. 24 Expose two only static functions. Pointers to references. 25 (WebCore::SVGPathBlender::addAnimatedPath): 26 (WebCore::SVGPathBlender::blendAnimatedPath): 27 (WebCore::SVGPathBlender::SVGPathBlender): 28 (WebCore::SVGPathBlender::blendAnimatedDimensonalFloat): 29 (WebCore::SVGPathBlender::blendAnimatedFloatPoint): 30 (WebCore::SVGPathBlender::blendMoveToSegment): 31 (WebCore::SVGPathBlender::blendLineToSegment): 32 (WebCore::SVGPathBlender::blendLineToHorizontalSegment): 33 (WebCore::SVGPathBlender::blendLineToVerticalSegment): 34 (WebCore::SVGPathBlender::blendCurveToCubicSegment): 35 (WebCore::SVGPathBlender::blendCurveToCubicSmoothSegment): 36 (WebCore::SVGPathBlender::blendCurveToQuadraticSegment): 37 (WebCore::SVGPathBlender::blendCurveToQuadraticSmoothSegment): 38 (WebCore::SVGPathBlender::blendArcToSegment): 39 (WebCore::SVGPathBlender::cleanup): Deleted. 40 * svg/SVGPathBlender.h: Make the constructor take a ref to the destination Path, 41 which is stored by reference. 42 * svg/SVGPathBuilder.cpp: 43 (WebCore::SVGPathBuilder::SVGPathBuilder): 44 (WebCore::SVGPathBuilder::moveTo): 45 (WebCore::SVGPathBuilder::lineTo): 46 (WebCore::SVGPathBuilder::curveToCubic): 47 (WebCore::SVGPathBuilder::closePath): 48 * svg/SVGPathBuilder.h: 49 (WebCore::SVGPathBuilder::setCurrentPath): Deleted. 50 * svg/SVGPathByteStreamBuilder.cpp: References, assertions removed. 51 (WebCore::SVGPathByteStreamBuilder::SVGPathByteStreamBuilder): 52 * svg/SVGPathByteStreamBuilder.h: 53 (WebCore::SVGPathByteStreamBuilder::writeType): 54 (WebCore::SVGPathByteStreamBuilder::setCurrentByteStream): Deleted. 55 * svg/SVGPathConsumer.h: 56 * svg/SVGPathElement.cpp: 57 * svg/SVGPathParser.cpp: Expose some static helper functions for parsing 58 to byte streams and strings. References. 59 (WebCore::SVGPathParser::parse): 60 (WebCore::SVGPathParser::parseToByteStream): 61 (WebCore::SVGPathParser::parseToString): 62 (WebCore::SVGPathParser::SVGPathParser): 63 (WebCore::SVGPathParser::parseClosePathSegment): 64 (WebCore::SVGPathParser::parseMoveToSegment): 65 (WebCore::SVGPathParser::parseLineToSegment): 66 (WebCore::SVGPathParser::parseLineToHorizontalSegment): 67 (WebCore::SVGPathParser::parseLineToVerticalSegment): 68 (WebCore::SVGPathParser::parseCurveToCubicSegment): 69 (WebCore::SVGPathParser::parseCurveToCubicSmoothSegment): 70 (WebCore::SVGPathParser::parseCurveToQuadraticSegment): 71 (WebCore::SVGPathParser::parseCurveToQuadraticSmoothSegment): 72 (WebCore::SVGPathParser::parseArcToSegment): 73 (WebCore::SVGPathParser::parsePathData): 74 (WebCore::SVGPathParser::decomposeArcToCubic): 75 (WebCore::SVGPathParser::parsePathDataFromSource): Deleted. 76 (WebCore::SVGPathParser::cleanup): Deleted. 77 * svg/SVGPathParser.h: 78 (WebCore::SVGPathParser::setCurrentConsumer): Deleted. 79 (WebCore::SVGPathParser::setCurrentSource): Deleted. 80 * svg/SVGPathSegListBuilder.cpp: 81 (WebCore::SVGPathSegListBuilder::SVGPathSegListBuilder): 82 (WebCore::SVGPathSegListBuilder::moveTo): 83 (WebCore::SVGPathSegListBuilder::lineTo): 84 (WebCore::SVGPathSegListBuilder::lineToHorizontal): 85 (WebCore::SVGPathSegListBuilder::lineToVertical): 86 (WebCore::SVGPathSegListBuilder::curveToCubic): 87 (WebCore::SVGPathSegListBuilder::curveToCubicSmooth): 88 (WebCore::SVGPathSegListBuilder::curveToQuadratic): 89 (WebCore::SVGPathSegListBuilder::curveToQuadraticSmooth): 90 (WebCore::SVGPathSegListBuilder::arcTo): 91 (WebCore::SVGPathSegListBuilder::closePath): 92 * svg/SVGPathSegListBuilder.h: 93 (WebCore::SVGPathSegListBuilder::setCurrentSVGPathElement): Deleted. 94 (WebCore::SVGPathSegListBuilder::setCurrentSVGPathSegList): Deleted. 95 (WebCore::SVGPathSegListBuilder::setCurrentSVGPathSegRole): Deleted. 96 * svg/SVGPathStringBuilder.cpp: 97 (WebCore::SVGPathStringBuilder::cleanup): Deleted. 98 * svg/SVGPathStringBuilder.h: 99 * svg/SVGPathTraversalStateBuilder.cpp: 100 (WebCore::SVGPathTraversalStateBuilder::SVGPathTraversalStateBuilder): 101 (WebCore::SVGPathTraversalStateBuilder::moveTo): 102 (WebCore::SVGPathTraversalStateBuilder::lineTo): 103 (WebCore::SVGPathTraversalStateBuilder::curveToCubic): 104 (WebCore::SVGPathTraversalStateBuilder::closePath): 105 (WebCore::SVGPathTraversalStateBuilder::continueConsuming): 106 (WebCore::SVGPathTraversalStateBuilder::totalLength): 107 (WebCore::SVGPathTraversalStateBuilder::currentPoint): 108 (WebCore::SVGPathTraversalStateBuilder::setDesiredLength): Deleted. 109 * svg/SVGPathTraversalStateBuilder.h: 110 (WebCore::SVGPathTraversalStateBuilder::pathSegmentIndex): 111 (WebCore::SVGPathTraversalStateBuilder::setCurrentTraversalState): Deleted. 112 * svg/SVGPathUtilities.cpp: Remove globals accessors, making things on the stack 113 instead. Use SVGPathParser helper functions where possible. 114 (WebCore::buildPathFromString): 115 (WebCore::buildSVGPathByteStreamFromSVGPathSegList): 116 (WebCore::appendSVGPathByteStreamFromSVGPathSeg): 117 (WebCore::buildPathFromByteStream): 118 (WebCore::buildSVGPathSegListFromByteStream): 119 (WebCore::buildStringFromByteStream): 120 (WebCore::buildStringFromSVGPathSegList): 121 (WebCore::buildSVGPathByteStreamFromString): 122 (WebCore::buildAnimatedSVGPathByteStream): 123 (WebCore::addToSVGPathByteStream): 124 (WebCore::getSVGPathSegAtLengthFromSVGPathByteStream): 125 (WebCore::getTotalLengthOfSVGPathByteStream): 126 (WebCore::getPointAtLengthOfSVGPathByteStream): 127 (WebCore::buildStringFromPath): 128 (WebCore::globalSVGPathBuilder): Deleted. 129 (WebCore::globalSVGPathSegListBuilder): Deleted. 130 (WebCore::globalSVGPathByteStreamBuilder): Deleted. 131 (WebCore::globalSVGPathStringBuilder): Deleted. 132 (WebCore::globalSVGPathTraversalStateBuilder): Deleted. 133 (WebCore::globalSVGPathParser): Deleted. 134 (WebCore::globalSVGPathBlender): Deleted. 135 * svg/SVGPathUtilities.h: 136 * svg/SVGToOTFFontConversion.cpp: CFFBuilder no longer inherits from SVGPathBuilder. 137 It did nothing with the Path, re-implemented all the functions, and only made use of 138 the m_current member var, so just make it inherit from SVGPathConsumer, and have 139 its own m_current. 140 (WebCore::SVGToOTFFontConverter::transcodeGlyphPaths): 141 1 142 2015-10-10 Antti Koivisto <antti@apple.com> 2 143 -
trunk/Source/WebCore/svg/SVGPathBlender.cpp
r184852 r190849 1 1 /* 2 2 * Copyright (C) Research In Motion Limited 2010, 2011. All rights reserved. 3 * Copyright (C) 2015 Apple Inc. All rights reserved. 3 4 * 4 5 * This library is free software; you can redistribute it and/or … … 28 29 namespace WebCore { 29 30 30 SVGPathBlender::SVGPathBlender() 31 : m_fromSource(nullptr) 32 , m_toSource(nullptr) 33 , m_consumer(nullptr) 34 , m_progress(0) 35 , m_addTypesCount(0) 36 , m_isInFirstHalfOfAnimation(false) 31 bool SVGPathBlender::addAnimatedPath(SVGPathSource& fromSource, SVGPathSource& toSource, SVGPathConsumer& consumer, unsigned repeatCount) 32 { 33 SVGPathBlender blender(fromSource, toSource, consumer); 34 return blender.addAnimatedPath(repeatCount); 35 } 36 37 bool SVGPathBlender::blendAnimatedPath(SVGPathSource& fromSource, SVGPathSource& toSource, SVGPathConsumer& consumer, float progress) 38 { 39 SVGPathBlender blender(fromSource, toSource, consumer); 40 return blender.blendAnimatedPath(progress); 41 } 42 43 SVGPathBlender::SVGPathBlender(SVGPathSource& fromSource, SVGPathSource& toSource, SVGPathConsumer& consumer) 44 : m_fromSource(fromSource) 45 , m_toSource(toSource) 46 , m_consumer(consumer) 37 47 { 38 48 } … … 44 54 } 45 55 46 float SVGPathBlender::blendAnimatedDimensonalFloat(float from, float to, FloatBlendMode blendMode )56 float SVGPathBlender::blendAnimatedDimensonalFloat(float from, float to, FloatBlendMode blendMode, float progress) 47 57 { 48 58 if (m_addTypesCount) { … … 52 62 53 63 if (m_fromMode == m_toMode) 54 return blend(from, to, m_progress);64 return blend(from, to, progress); 55 65 56 66 float fromValue = blendMode == BlendHorizontal ? m_fromCurrentPoint.x() : m_fromCurrentPoint.y(); … … 58 68 59 69 // Transform toY to the coordinate mode of fromY 60 float animValue = blend(from, m_fromMode == AbsoluteCoordinates ? to + toValue : to - toValue, m_progress);70 float animValue = blend(from, m_fromMode == AbsoluteCoordinates ? to + toValue : to - toValue, progress); 61 71 62 72 if (m_isInFirstHalfOfAnimation) … … 64 74 65 75 // Transform the animated point to the coordinate mode, needed for the current progress. 66 float currentValue = blend(fromValue, toValue, m_progress);76 float currentValue = blend(fromValue, toValue, progress); 67 77 return m_toMode == AbsoluteCoordinates ? animValue + currentValue : animValue - currentValue; 68 78 } 69 79 70 FloatPoint SVGPathBlender::blendAnimatedFloatPoint(const FloatPoint& fromPoint, const FloatPoint& toPoint )80 FloatPoint SVGPathBlender::blendAnimatedFloatPoint(const FloatPoint& fromPoint, const FloatPoint& toPoint, float progress) 71 81 { 72 82 if (m_addTypesCount) { … … 78 88 79 89 if (m_fromMode == m_toMode) 80 return blendFloatPoint(fromPoint, toPoint, m_progress);90 return blendFloatPoint(fromPoint, toPoint, progress); 81 91 82 92 // Transform toPoint to the coordinate mode of fromPoint … … 87 97 animatedPoint.move(-m_toCurrentPoint.x(), -m_toCurrentPoint.y()); 88 98 89 animatedPoint = blendFloatPoint(fromPoint, animatedPoint, m_progress);99 animatedPoint = blendFloatPoint(fromPoint, animatedPoint, progress); 90 100 91 101 if (m_isInFirstHalfOfAnimation) … … 93 103 94 104 // Transform the animated point to the coordinate mode, needed for the current progress. 95 FloatPoint currentPoint = blendFloatPoint(m_fromCurrentPoint, m_toCurrentPoint, m_progress);105 FloatPoint currentPoint = blendFloatPoint(m_fromCurrentPoint, m_toCurrentPoint, progress); 96 106 if (m_toMode == AbsoluteCoordinates) 97 107 return animatedPoint + currentPoint; … … 101 111 } 102 112 103 bool SVGPathBlender::blendMoveToSegment( )104 { 105 FloatPoint fromTargetPoint; 106 FloatPoint toTargetPoint; 107 if ((m_fromSource ->hasMoreData() && !m_fromSource->parseMoveToSegment(fromTargetPoint))108 || !m_toSource ->parseMoveToSegment(toTargetPoint))109 return false; 110 111 m_consumer ->moveTo(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint), false, m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);112 m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint; 113 m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint; 114 return true; 115 } 116 117 bool SVGPathBlender::blendLineToSegment( )118 { 119 FloatPoint fromTargetPoint; 120 FloatPoint toTargetPoint; 121 if ((m_fromSource ->hasMoreData() && !m_fromSource->parseLineToSegment(fromTargetPoint))122 || !m_toSource ->parseLineToSegment(toTargetPoint))123 return false; 124 125 m_consumer ->lineTo(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);126 m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint; 127 m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint; 128 return true; 129 } 130 131 bool SVGPathBlender::blendLineToHorizontalSegment( )113 bool SVGPathBlender::blendMoveToSegment(float progress) 114 { 115 FloatPoint fromTargetPoint; 116 FloatPoint toTargetPoint; 117 if ((m_fromSource.hasMoreData() && !m_fromSource.parseMoveToSegment(fromTargetPoint)) 118 || !m_toSource.parseMoveToSegment(toTargetPoint)) 119 return false; 120 121 m_consumer.moveTo(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress), false, m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode); 122 m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint; 123 m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint; 124 return true; 125 } 126 127 bool SVGPathBlender::blendLineToSegment(float progress) 128 { 129 FloatPoint fromTargetPoint; 130 FloatPoint toTargetPoint; 131 if ((m_fromSource.hasMoreData() && !m_fromSource.parseLineToSegment(fromTargetPoint)) 132 || !m_toSource.parseLineToSegment(toTargetPoint)) 133 return false; 134 135 m_consumer.lineTo(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode); 136 m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint; 137 m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint; 138 return true; 139 } 140 141 bool SVGPathBlender::blendLineToHorizontalSegment(float progress) 132 142 { 133 143 float fromX = 0; 134 144 float toX = 0; 135 if ((m_fromSource ->hasMoreData() && !m_fromSource->parseLineToHorizontalSegment(fromX))136 || !m_toSource ->parseLineToHorizontalSegment(toX))137 return false; 138 139 m_consumer ->lineToHorizontal(blendAnimatedDimensonalFloat(fromX, toX, BlendHorizontal), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);145 if ((m_fromSource.hasMoreData() && !m_fromSource.parseLineToHorizontalSegment(fromX)) 146 || !m_toSource.parseLineToHorizontalSegment(toX)) 147 return false; 148 149 m_consumer.lineToHorizontal(blendAnimatedDimensonalFloat(fromX, toX, BlendHorizontal, progress), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode); 140 150 m_fromCurrentPoint.setX(m_fromMode == AbsoluteCoordinates ? fromX : m_fromCurrentPoint.x() + fromX); 141 151 m_toCurrentPoint.setX(m_toMode == AbsoluteCoordinates ? toX : m_toCurrentPoint.x() + toX); … … 143 153 } 144 154 145 bool SVGPathBlender::blendLineToVerticalSegment( )155 bool SVGPathBlender::blendLineToVerticalSegment(float progress) 146 156 { 147 157 float fromY = 0; 148 158 float toY = 0; 149 if ((m_fromSource ->hasMoreData() && !m_fromSource->parseLineToVerticalSegment(fromY))150 || !m_toSource ->parseLineToVerticalSegment(toY))151 return false; 152 153 m_consumer ->lineToVertical(blendAnimatedDimensonalFloat(fromY, toY, BlendVertical), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);159 if ((m_fromSource.hasMoreData() && !m_fromSource.parseLineToVerticalSegment(fromY)) 160 || !m_toSource.parseLineToVerticalSegment(toY)) 161 return false; 162 163 m_consumer.lineToVertical(blendAnimatedDimensonalFloat(fromY, toY, BlendVertical, progress), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode); 154 164 m_fromCurrentPoint.setY(m_fromMode == AbsoluteCoordinates ? fromY : m_fromCurrentPoint.y() + fromY); 155 165 m_toCurrentPoint.setY(m_toMode == AbsoluteCoordinates ? toY : m_toCurrentPoint.y() + toY); … … 157 167 } 158 168 159 bool SVGPathBlender::blendCurveToCubicSegment( )169 bool SVGPathBlender::blendCurveToCubicSegment(float progress) 160 170 { 161 171 FloatPoint fromTargetPoint; … … 165 175 FloatPoint toPoint1; 166 176 FloatPoint toPoint2; 167 if ((m_fromSource ->hasMoreData() && !m_fromSource->parseCurveToCubicSegment(fromPoint1, fromPoint2, fromTargetPoint))168 || !m_toSource ->parseCurveToCubicSegment(toPoint1, toPoint2, toTargetPoint))169 return false; 170 171 m_consumer ->curveToCubic(blendAnimatedFloatPoint(fromPoint1, toPoint1),172 blendAnimatedFloatPoint(fromPoint2, toPoint2),173 blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint),174 175 m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint; 176 m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint; 177 return true; 178 } 179 180 bool SVGPathBlender::blendCurveToCubicSmoothSegment( )177 if ((m_fromSource.hasMoreData() && !m_fromSource.parseCurveToCubicSegment(fromPoint1, fromPoint2, fromTargetPoint)) 178 || !m_toSource.parseCurveToCubicSegment(toPoint1, toPoint2, toTargetPoint)) 179 return false; 180 181 m_consumer.curveToCubic(blendAnimatedFloatPoint(fromPoint1, toPoint1, progress), 182 blendAnimatedFloatPoint(fromPoint2, toPoint2, progress), 183 blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress), 184 m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode); 185 m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint; 186 m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint; 187 return true; 188 } 189 190 bool SVGPathBlender::blendCurveToCubicSmoothSegment(float progress) 181 191 { 182 192 FloatPoint fromTargetPoint; … … 184 194 FloatPoint toTargetPoint; 185 195 FloatPoint toPoint2; 186 if ((m_fromSource ->hasMoreData() && !m_fromSource->parseCurveToCubicSmoothSegment(fromPoint2, fromTargetPoint))187 || !m_toSource ->parseCurveToCubicSmoothSegment(toPoint2, toTargetPoint))188 return false; 189 190 m_consumer ->curveToCubicSmooth(blendAnimatedFloatPoint(fromPoint2, toPoint2),191 blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint),192 193 m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint; 194 m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint; 195 return true; 196 } 197 198 bool SVGPathBlender::blendCurveToQuadraticSegment( )196 if ((m_fromSource.hasMoreData() && !m_fromSource.parseCurveToCubicSmoothSegment(fromPoint2, fromTargetPoint)) 197 || !m_toSource.parseCurveToCubicSmoothSegment(toPoint2, toTargetPoint)) 198 return false; 199 200 m_consumer.curveToCubicSmooth(blendAnimatedFloatPoint(fromPoint2, toPoint2, progress), 201 blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress), 202 m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode); 203 m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint; 204 m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint; 205 return true; 206 } 207 208 bool SVGPathBlender::blendCurveToQuadraticSegment(float progress) 199 209 { 200 210 FloatPoint fromTargetPoint; … … 202 212 FloatPoint toTargetPoint; 203 213 FloatPoint toPoint1; 204 if ((m_fromSource ->hasMoreData() && !m_fromSource->parseCurveToQuadraticSegment(fromPoint1, fromTargetPoint))205 || !m_toSource ->parseCurveToQuadraticSegment(toPoint1, toTargetPoint))206 return false; 207 208 m_consumer ->curveToQuadratic(blendAnimatedFloatPoint(fromPoint1, toPoint1),209 blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint),210 211 m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint; 212 m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint; 213 return true; 214 } 215 216 bool SVGPathBlender::blendCurveToQuadraticSmoothSegment( )217 { 218 FloatPoint fromTargetPoint; 219 FloatPoint toTargetPoint; 220 if ((m_fromSource ->hasMoreData() && !m_fromSource->parseCurveToQuadraticSmoothSegment(fromTargetPoint))221 || !m_toSource ->parseCurveToQuadraticSmoothSegment(toTargetPoint))222 return false; 223 224 m_consumer ->curveToQuadraticSmooth(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);225 m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint; 226 m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint; 227 return true; 228 } 229 230 bool SVGPathBlender::blendArcToSegment( )214 if ((m_fromSource.hasMoreData() && !m_fromSource.parseCurveToQuadraticSegment(fromPoint1, fromTargetPoint)) 215 || !m_toSource.parseCurveToQuadraticSegment(toPoint1, toTargetPoint)) 216 return false; 217 218 m_consumer.curveToQuadratic(blendAnimatedFloatPoint(fromPoint1, toPoint1, progress), 219 blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress), 220 m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode); 221 m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint; 222 m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint; 223 return true; 224 } 225 226 bool SVGPathBlender::blendCurveToQuadraticSmoothSegment(float progress) 227 { 228 FloatPoint fromTargetPoint; 229 FloatPoint toTargetPoint; 230 if ((m_fromSource.hasMoreData() && !m_fromSource.parseCurveToQuadraticSmoothSegment(fromTargetPoint)) 231 || !m_toSource.parseCurveToQuadraticSmoothSegment(toTargetPoint)) 232 return false; 233 234 m_consumer.curveToQuadraticSmooth(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode); 235 m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint; 236 m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint; 237 return true; 238 } 239 240 bool SVGPathBlender::blendArcToSegment(float progress) 231 241 { 232 242 float fromRx = 0; … … 242 252 bool toSweep = false; 243 253 FloatPoint toTargetPoint; 244 if ((m_fromSource ->hasMoreData() && !m_fromSource->parseArcToSegment(fromRx, fromRy, fromAngle, fromLargeArc, fromSweep, fromTargetPoint))245 || !m_toSource ->parseArcToSegment(toRx, toRy, toAngle, toLargeArc, toSweep, toTargetPoint))254 if ((m_fromSource.hasMoreData() && !m_fromSource.parseArcToSegment(fromRx, fromRy, fromAngle, fromLargeArc, fromSweep, fromTargetPoint)) 255 || !m_toSource.parseArcToSegment(toRx, toRy, toAngle, toLargeArc, toSweep, toTargetPoint)) 246 256 return false; 247 257 … … 250 260 FloatPoint scaledToTargetPoint = toTargetPoint; 251 261 scaledToTargetPoint.scale(m_addTypesCount, m_addTypesCount); 252 m_consumer ->arcTo(fromRx + toRx * m_addTypesCount,253 254 255 256 257 258 262 m_consumer.arcTo(fromRx + toRx * m_addTypesCount, 263 fromRy + toRy * m_addTypesCount, 264 fromAngle + toAngle * m_addTypesCount, 265 fromLargeArc || toLargeArc, 266 fromSweep || toSweep, 267 fromTargetPoint + scaledToTargetPoint, 268 m_fromMode); 259 269 } else { 260 m_consumer ->arcTo(blend(fromRx, toRx, m_progress),261 blend(fromRy, toRy, m_progress),262 blend(fromAngle, toAngle, m_progress),263 264 265 blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint),266 270 m_consumer.arcTo(blend(fromRx, toRx, progress), 271 blend(fromRy, toRy, progress), 272 blend(fromAngle, toAngle, progress), 273 m_isInFirstHalfOfAnimation ? fromLargeArc : toLargeArc, 274 m_isInFirstHalfOfAnimation ? fromSweep : toSweep, 275 blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress), 276 m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode); 267 277 } 268 278 m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint; … … 297 307 } 298 308 299 bool SVGPathBlender::addAnimatedPath( SVGPathSource* fromSource, SVGPathSource* toSource, SVGPathConsumer* consumer,unsigned repeatCount)309 bool SVGPathBlender::addAnimatedPath(unsigned repeatCount) 300 310 { 301 311 TemporaryChange<unsigned> change(m_addTypesCount, repeatCount); 302 return blendAnimatedPath(0, fromSource, toSource, consumer); 303 } 304 305 bool SVGPathBlender::blendAnimatedPath(float progress, SVGPathSource* fromSource, SVGPathSource* toSource, SVGPathConsumer* consumer) 306 { 307 ASSERT(fromSource); 308 ASSERT(toSource); 309 ASSERT(consumer); 310 m_fromSource = fromSource; 311 m_toSource = toSource; 312 m_consumer = consumer; 312 return blendAnimatedPath(0); 313 } 314 315 bool SVGPathBlender::blendAnimatedPath(float progress) 316 { 313 317 m_isInFirstHalfOfAnimation = progress < 0.5f; 314 m_progress = progress; 315 316 bool fromSourceHadData = m_fromSource->hasMoreData(); 317 while (m_toSource->hasMoreData()) { 318 319 bool fromSourceHadData = m_fromSource.hasMoreData(); 320 while (m_toSource.hasMoreData()) { 318 321 SVGPathSegType fromCommand; 319 322 SVGPathSegType toCommand; 320 if ((fromSourceHadData && !m_fromSource ->parseSVGSegmentType(fromCommand)) || !m_toSource->parseSVGSegmentType(toCommand))323 if ((fromSourceHadData && !m_fromSource.parseSVGSegmentType(fromCommand)) || !m_toSource.parseSVGSegmentType(toCommand)) 321 324 return false; 322 325 … … 332 335 case PathSegMoveToRel: 333 336 case PathSegMoveToAbs: 334 if (!blendMoveToSegment( ))337 if (!blendMoveToSegment(progress)) 335 338 return false; 336 339 break; 337 340 case PathSegLineToRel: 338 341 case PathSegLineToAbs: 339 if (!blendLineToSegment( ))342 if (!blendLineToSegment(progress)) 340 343 return false; 341 344 break; 342 345 case PathSegLineToHorizontalRel: 343 346 case PathSegLineToHorizontalAbs: 344 if (!blendLineToHorizontalSegment( ))347 if (!blendLineToHorizontalSegment(progress)) 345 348 return false; 346 349 break; 347 350 case PathSegLineToVerticalRel: 348 351 case PathSegLineToVerticalAbs: 349 if (!blendLineToVerticalSegment( ))352 if (!blendLineToVerticalSegment(progress)) 350 353 return false; 351 354 break; 352 355 case PathSegClosePath: 353 m_consumer ->closePath();356 m_consumer.closePath(); 354 357 break; 355 358 case PathSegCurveToCubicRel: 356 359 case PathSegCurveToCubicAbs: 357 if (!blendCurveToCubicSegment( ))360 if (!blendCurveToCubicSegment(progress)) 358 361 return false; 359 362 break; 360 363 case PathSegCurveToCubicSmoothRel: 361 364 case PathSegCurveToCubicSmoothAbs: 362 if (!blendCurveToCubicSmoothSegment( ))365 if (!blendCurveToCubicSmoothSegment(progress)) 363 366 return false; 364 367 break; 365 368 case PathSegCurveToQuadraticRel: 366 369 case PathSegCurveToQuadraticAbs: 367 if (!blendCurveToQuadraticSegment( ))370 if (!blendCurveToQuadraticSegment(progress)) 368 371 return false; 369 372 break; 370 373 case PathSegCurveToQuadraticSmoothRel: 371 374 case PathSegCurveToQuadraticSmoothAbs: 372 if (!blendCurveToQuadraticSmoothSegment( ))375 if (!blendCurveToQuadraticSmoothSegment(progress)) 373 376 return false; 374 377 break; 375 378 case PathSegArcRel: 376 379 case PathSegArcAbs: 377 if (!blendArcToSegment( ))380 if (!blendArcToSegment(progress)) 378 381 return false; 379 382 break; … … 384 387 if (!fromSourceHadData) 385 388 continue; 386 if (m_fromSource ->hasMoreData() != m_toSource->hasMoreData())387 return false; 388 if (!m_fromSource ->hasMoreData() || !m_toSource->hasMoreData())389 if (m_fromSource.hasMoreData() != m_toSource.hasMoreData()) 390 return false; 391 if (!m_fromSource.hasMoreData() || !m_toSource.hasMoreData()) 389 392 return true; 390 393 } … … 393 396 } 394 397 395 void SVGPathBlender::cleanup() 396 { 397 ASSERT(m_toSource); 398 ASSERT(m_fromSource); 399 ASSERT(m_consumer); 400 401 m_consumer->cleanup(); 402 m_toSource = nullptr; 403 m_fromSource = nullptr; 404 m_consumer = nullptr; 405 m_fromCurrentPoint = FloatPoint(); 406 m_toCurrentPoint = FloatPoint(); 407 } 408 409 } 398 } -
trunk/Source/WebCore/svg/SVGPathBlender.h
r163440 r190849 1 1 /* 2 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 3 * Copyright (C) 2015 Apple Inc. All rights reserved. 3 4 * 4 5 * This library is free software; you can redistribute it and/or … … 35 36 WTF_MAKE_NONCOPYABLE(SVGPathBlender); WTF_MAKE_FAST_ALLOCATED; 36 37 public: 37 SVGPathBlender();38 38 39 bool addAnimatedPath(SVGPathSource*, SVGPathSource*, SVGPathConsumer*, unsigned repeatCount); 40 bool blendAnimatedPath(float, SVGPathSource*, SVGPathSource*, SVGPathConsumer*); 41 void cleanup(); 39 static bool addAnimatedPath(SVGPathSource& from, SVGPathSource& to, SVGPathConsumer&, unsigned repeatCount); 40 static bool blendAnimatedPath(SVGPathSource& from, SVGPathSource& to, SVGPathConsumer&, float); 42 41 43 42 private: 44 bool blendMoveToSegment(); 45 bool blendLineToSegment(); 46 bool blendLineToHorizontalSegment(); 47 bool blendLineToVerticalSegment(); 48 bool blendCurveToCubicSegment(); 49 bool blendCurveToCubicSmoothSegment(); 50 bool blendCurveToQuadraticSegment(); 51 bool blendCurveToQuadraticSmoothSegment(); 52 bool blendArcToSegment(); 43 SVGPathBlender(SVGPathSource&, SVGPathSource&, SVGPathConsumer&); 53 44 54 float blendAnimatedDimensonalFloat(float, float, FloatBlendMode);55 FloatPoint blendAnimatedFloatPoint(const FloatPoint& from, const FloatPoint& to);45 bool addAnimatedPath(unsigned repeatCount); 46 bool blendAnimatedPath(float progress); 56 47 57 SVGPathSource* m_fromSource; 58 SVGPathSource* m_toSource; 59 SVGPathConsumer* m_consumer; 48 bool blendMoveToSegment(float progress); 49 bool blendLineToSegment(float progress); 50 bool blendLineToHorizontalSegment(float progress); 51 bool blendLineToVerticalSegment(float progress); 52 bool blendCurveToCubicSegment(float progress); 53 bool blendCurveToCubicSmoothSegment(float progress); 54 bool blendCurveToQuadraticSegment(float progress); 55 bool blendCurveToQuadraticSmoothSegment(float progress); 56 bool blendArcToSegment(float progress); 57 58 float blendAnimatedDimensonalFloat(float from, float to, FloatBlendMode, float progress); 59 FloatPoint blendAnimatedFloatPoint(const FloatPoint& from, const FloatPoint& to, float progress); 60 61 SVGPathSource& m_fromSource; 62 SVGPathSource& m_toSource; 63 SVGPathConsumer& m_consumer; 60 64 61 65 FloatPoint m_fromCurrentPoint; 62 66 FloatPoint m_toCurrentPoint; 63 67 64 PathCoordinateMode m_fromMode; 65 PathCoordinateMode m_toMode; 66 float m_progress; 67 unsigned m_addTypesCount; 68 bool m_isInFirstHalfOfAnimation; 68 PathCoordinateMode m_fromMode { AbsoluteCoordinates }; 69 PathCoordinateMode m_toMode { AbsoluteCoordinates }; 70 unsigned m_addTypesCount { 0 }; 71 bool m_isInFirstHalfOfAnimation { false }; 69 72 }; 70 73 -
trunk/Source/WebCore/svg/SVGPathBuilder.cpp
r184852 r190849 3 3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> 4 4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> 5 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved. 6 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 7 7 * … … 29 29 namespace WebCore { 30 30 31 SVGPathBuilder::SVGPathBuilder( )32 : m_path( nullptr)31 SVGPathBuilder::SVGPathBuilder(Path& path) 32 : m_path(path) 33 33 { 34 34 } … … 36 36 void SVGPathBuilder::moveTo(const FloatPoint& targetPoint, bool closed, PathCoordinateMode mode) 37 37 { 38 ASSERT(m_path);39 38 m_current = mode == AbsoluteCoordinates ? targetPoint : m_current + targetPoint; 40 if (closed && !m_path ->isEmpty())41 m_path ->closeSubpath();42 m_path ->moveTo(m_current);39 if (closed && !m_path.isEmpty()) 40 m_path.closeSubpath(); 41 m_path.moveTo(m_current); 43 42 } 44 43 45 44 void SVGPathBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode) 46 45 { 47 ASSERT(m_path);48 46 m_current = mode == AbsoluteCoordinates ? targetPoint : m_current + targetPoint; 49 m_path ->addLineTo(m_current);47 m_path.addLineTo(m_current); 50 48 } 51 49 52 50 void SVGPathBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) 53 51 { 54 ASSERT(m_path);55 52 if (mode == RelativeCoordinates) { 56 m_path ->addBezierCurveTo(m_current + point1, m_current + point2, m_current + targetPoint);53 m_path.addBezierCurveTo(m_current + point1, m_current + point2, m_current + targetPoint); 57 54 m_current += targetPoint; 58 55 } else { 59 56 m_current = targetPoint; 60 m_path ->addBezierCurveTo(point1, point2, m_current);57 m_path.addBezierCurveTo(point1, point2, m_current); 61 58 } 62 59 } … … 64 61 void SVGPathBuilder::closePath() 65 62 { 66 ASSERT(m_path); 67 m_path->closeSubpath(); 63 m_path.closeSubpath(); 68 64 } 69 65 -
trunk/Source/WebCore/svg/SVGPathBuilder.h
r184852 r190849 3 3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> 4 4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> 5 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved. 6 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 7 7 * … … 34 34 class SVGPathBuilder : public SVGPathConsumer { 35 35 public: 36 SVGPathBuilder(); 37 38 void setCurrentPath(Path* path) { m_path = path; } 39 40 protected: 41 FloatPoint m_current; 36 SVGPathBuilder(Path&); 42 37 43 38 private: 44 39 virtual void incrementPathSegmentCount() override { } 45 40 virtual bool continueConsuming() override { return true; } 46 virtual void cleanup() override { m_path = nullptr; }47 41 48 42 // Used in UnalteredParsing/NormalizedParsing modes. … … 60 54 virtual void arcTo(float, float, float, bool, bool, const FloatPoint&, PathCoordinateMode) override { ASSERT_NOT_REACHED(); } 61 55 62 Path* m_path; 56 Path& m_path; 57 FloatPoint m_current; 63 58 }; 64 59 -
trunk/Source/WebCore/svg/SVGPathByteStreamBuilder.cpp
r184852 r190849 1 1 /* 2 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 3 * Copyright (C) 2015 Apple Inc. All rights reserved. 3 4 * 4 5 * This library is free software; you can redistribute it and/or … … 21 22 #include "SVGPathByteStreamBuilder.h" 22 23 23 #include "SVGPathParser.h"24 24 #include "SVGPathSeg.h" 25 25 #include "SVGPathStringSource.h" … … 27 27 namespace WebCore { 28 28 29 SVGPathByteStreamBuilder::SVGPathByteStreamBuilder( )30 : m_byteStream( nullptr)29 SVGPathByteStreamBuilder::SVGPathByteStreamBuilder(SVGPathByteStream& byteStream) 30 : m_byteStream(byteStream) 31 31 { 32 32 } … … 34 34 void SVGPathByteStreamBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode) 35 35 { 36 ASSERT(m_byteStream);37 36 writeSegmentType(mode == RelativeCoordinates ? PathSegMoveToRel : PathSegMoveToAbs); 38 37 writeFloatPoint(targetPoint); … … 41 40 void SVGPathByteStreamBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode) 42 41 { 43 ASSERT(m_byteStream);44 42 writeSegmentType(mode == RelativeCoordinates ? PathSegLineToRel : PathSegLineToAbs); 45 43 writeFloatPoint(targetPoint); … … 48 46 void SVGPathByteStreamBuilder::lineToHorizontal(float x, PathCoordinateMode mode) 49 47 { 50 ASSERT(m_byteStream);51 48 writeSegmentType(mode == RelativeCoordinates ? PathSegLineToHorizontalRel : PathSegLineToHorizontalAbs); 52 49 writeFloat(x); … … 55 52 void SVGPathByteStreamBuilder::lineToVertical(float y, PathCoordinateMode mode) 56 53 { 57 ASSERT(m_byteStream);58 54 writeSegmentType(mode == RelativeCoordinates ? PathSegLineToVerticalRel : PathSegLineToVerticalAbs); 59 55 writeFloat(y); … … 62 58 void SVGPathByteStreamBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) 63 59 { 64 ASSERT(m_byteStream);65 60 writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicRel : PathSegCurveToCubicAbs); 66 61 writeFloatPoint(point1); … … 71 66 void SVGPathByteStreamBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) 72 67 { 73 ASSERT(m_byteStream);74 68 writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicSmoothRel : PathSegCurveToCubicSmoothAbs); 75 69 writeFloatPoint(point2); … … 79 73 void SVGPathByteStreamBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode) 80 74 { 81 ASSERT(m_byteStream);82 75 writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadraticRel : PathSegCurveToQuadraticAbs); 83 76 writeFloatPoint(point1); … … 87 80 void SVGPathByteStreamBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode) 88 81 { 89 ASSERT(m_byteStream);90 82 writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadraticSmoothRel : PathSegCurveToQuadraticSmoothAbs); 91 83 writeFloatPoint(targetPoint); … … 94 86 void SVGPathByteStreamBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode) 95 87 { 96 ASSERT(m_byteStream);97 88 writeSegmentType(mode == RelativeCoordinates ? PathSegArcRel : PathSegArcAbs); 98 89 writeFloat(r1); … … 106 97 void SVGPathByteStreamBuilder::closePath() 107 98 { 108 ASSERT(m_byteStream);109 99 writeSegmentType(PathSegClosePath); 110 100 } -
trunk/Source/WebCore/svg/SVGPathByteStreamBuilder.h
r184852 r190849 1 1 /* 2 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 3 * Copyright (C) 2015 Apple Inc. All rights reserved. 3 4 * 4 5 * This library is free software; you can redistribute it and/or … … 30 31 class SVGPathByteStreamBuilder : public SVGPathConsumer { 31 32 public: 32 SVGPathByteStreamBuilder(); 33 34 void setCurrentByteStream(SVGPathByteStream* byteStream) { m_byteStream = byteStream; } 33 SVGPathByteStreamBuilder(SVGPathByteStream&); 35 34 36 35 private: 37 36 virtual void incrementPathSegmentCount() override { } 38 37 virtual bool continueConsuming() override { return true; } 39 virtual void cleanup() override { m_byteStream = nullptr; }40 38 41 39 // Used in UnalteredParsing/NormalizedParsing modes. … … 58 56 size_t typeSize = sizeof(ByteType); 59 57 for (size_t i = 0; i < typeSize; ++i) 60 m_byteStream ->append(type.bytes[i]);58 m_byteStream.append(type.bytes[i]); 61 59 } 62 60 … … 88 86 } 89 87 90 SVGPathByteStream *m_byteStream;88 SVGPathByteStream& m_byteStream; 91 89 }; 92 90 -
trunk/Source/WebCore/svg/SVGPathConsumer.h
r163440 r190849 3 3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> 4 4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> 5 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved. 6 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 7 7 * … … 47 47 virtual void incrementPathSegmentCount() = 0; 48 48 virtual bool continueConsuming() = 0; 49 virtual void cleanup() = 0;50 49 51 50 // Used in UnalteredParsing/NormalizedParsing modes. -
trunk/Source/WebCore/svg/SVGPathElement.cpp
r190844 r190849 44 44 #include "SVGPathSegLinetoVerticalRel.h" 45 45 #include "SVGPathSegList.h" 46 #include "SVGPathSegListBuilder.h"47 46 #include "SVGPathSegListPropertyTearOff.h" 48 47 #include "SVGPathSegMovetoAbs.h" -
trunk/Source/WebCore/svg/SVGPathParser.cpp
r184852 r190849 3 3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> 4 4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> 5 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved. 6 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 7 7 * … … 26 26 27 27 #include "AffineTransform.h" 28 #include "SVGPathByteStreamBuilder.h" 28 29 #include "SVGPathSource.h" 30 #include "SVGPathStringBuilder.h" 29 31 #include <wtf/MathExtras.h> 30 32 … … 33 35 namespace WebCore { 34 36 35 SVGPathParser::SVGPathParser() 36 : m_consumer(nullptr) 37 bool SVGPathParser::parse(SVGPathSource& source, SVGPathConsumer& consumer, PathParsingMode mode, bool checkForInitialMoveTo) 38 { 39 SVGPathParser parser(consumer, source, mode); 40 return parser.parsePathData(checkForInitialMoveTo); 41 } 42 43 bool SVGPathParser::parseToByteStream(SVGPathSource& source, SVGPathByteStream& byteStream, PathParsingMode mode, bool checkForInitialMoveTo) 44 { 45 SVGPathByteStreamBuilder builder(byteStream); 46 return parse(source, builder, mode, checkForInitialMoveTo); 47 } 48 49 bool SVGPathParser::parseToString(SVGPathSource& source, String& result, PathParsingMode mode, bool checkForInitialMoveTo) 50 { 51 SVGPathStringBuilder builder; 52 SVGPathParser parser(builder, source, mode); 53 bool ok = parser.parsePathData(checkForInitialMoveTo); 54 result = builder.result(); 55 return ok; 56 } 57 58 SVGPathParser::SVGPathParser(SVGPathConsumer& consumer, SVGPathSource& source, PathParsingMode parsingMode) 59 : m_source(source) 60 , m_consumer(consumer) 61 , m_pathParsingMode(parsingMode) 37 62 { 38 63 } … … 44 69 m_currentPoint = m_subPathPoint; 45 70 m_closePath = true; 46 m_consumer ->closePath();71 m_consumer.closePath(); 47 72 } 48 73 … … 50 75 { 51 76 FloatPoint targetPoint; 52 if (!m_source ->parseMoveToSegment(targetPoint))77 if (!m_source.parseMoveToSegment(targetPoint)) 53 78 return false; 54 79 … … 59 84 m_currentPoint = targetPoint; 60 85 m_subPathPoint = m_currentPoint; 61 m_consumer ->moveTo(m_currentPoint, m_closePath, AbsoluteCoordinates);62 } else 63 m_consumer ->moveTo(targetPoint, m_closePath, m_mode);86 m_consumer.moveTo(m_currentPoint, m_closePath, AbsoluteCoordinates); 87 } else 88 m_consumer.moveTo(targetPoint, m_closePath, m_mode); 64 89 m_closePath = false; 65 90 return true; … … 69 94 { 70 95 FloatPoint targetPoint; 71 if (!m_source ->parseLineToSegment(targetPoint))96 if (!m_source.parseLineToSegment(targetPoint)) 72 97 return false; 73 98 … … 77 102 else 78 103 m_currentPoint = targetPoint; 79 m_consumer ->lineTo(m_currentPoint, AbsoluteCoordinates);80 } else 81 m_consumer ->lineTo(targetPoint, m_mode);104 m_consumer.lineTo(m_currentPoint, AbsoluteCoordinates); 105 } else 106 m_consumer.lineTo(targetPoint, m_mode); 82 107 return true; 83 108 } … … 86 111 { 87 112 float toX; 88 if (!m_source ->parseLineToHorizontalSegment(toX))113 if (!m_source.parseLineToHorizontalSegment(toX)) 89 114 return false; 90 115 … … 94 119 else 95 120 m_currentPoint.setX(toX); 96 m_consumer ->lineTo(m_currentPoint, AbsoluteCoordinates);97 } else 98 m_consumer ->lineToHorizontal(toX, m_mode);121 m_consumer.lineTo(m_currentPoint, AbsoluteCoordinates); 122 } else 123 m_consumer.lineToHorizontal(toX, m_mode); 99 124 return true; 100 125 } … … 103 128 { 104 129 float toY; 105 if (!m_source ->parseLineToVerticalSegment(toY))130 if (!m_source.parseLineToVerticalSegment(toY)) 106 131 return false; 107 132 … … 111 136 else 112 137 m_currentPoint.setY(toY); 113 m_consumer ->lineTo(m_currentPoint, AbsoluteCoordinates);114 } else 115 m_consumer ->lineToVertical(toY, m_mode);138 m_consumer.lineTo(m_currentPoint, AbsoluteCoordinates); 139 } else 140 m_consumer.lineToVertical(toY, m_mode); 116 141 return true; 117 142 } … … 122 147 FloatPoint point2; 123 148 FloatPoint targetPoint; 124 if (!m_source ->parseCurveToCubicSegment(point1, point2, targetPoint))149 if (!m_source.parseCurveToCubicSegment(point1, point2, targetPoint)) 125 150 return false; 126 151 … … 131 156 targetPoint += m_currentPoint; 132 157 } 133 m_consumer ->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);158 m_consumer.curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); 134 159 135 160 m_controlPoint = point2; 136 161 m_currentPoint = targetPoint; 137 162 } else 138 m_consumer ->curveToCubic(point1, point2, targetPoint, m_mode);163 m_consumer.curveToCubic(point1, point2, targetPoint, m_mode); 139 164 return true; 140 165 } … … 144 169 FloatPoint point2; 145 170 FloatPoint targetPoint; 146 if (!m_source ->parseCurveToCubicSmoothSegment(point2, targetPoint))171 if (!m_source.parseCurveToCubicSmoothSegment(point2, targetPoint)) 147 172 return false; 148 173 … … 162 187 } 163 188 164 m_consumer ->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);189 m_consumer.curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); 165 190 166 191 m_controlPoint = point2; 167 192 m_currentPoint = targetPoint; 168 193 } else 169 m_consumer ->curveToCubicSmooth(point2, targetPoint, m_mode);194 m_consumer.curveToCubicSmooth(point2, targetPoint, m_mode); 170 195 return true; 171 196 } … … 175 200 FloatPoint point1; 176 201 FloatPoint targetPoint; 177 if (!m_source ->parseCurveToQuadraticSegment(point1, targetPoint))202 if (!m_source.parseCurveToQuadraticSegment(point1, targetPoint)) 178 203 return false; 179 204 … … 191 216 point2.scale(gOneOverThree, gOneOverThree); 192 217 193 m_consumer ->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);218 m_consumer.curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); 194 219 195 220 if (m_mode == RelativeCoordinates) … … 197 222 m_currentPoint = targetPoint; 198 223 } else 199 m_consumer ->curveToQuadratic(point1, targetPoint, m_mode);224 m_consumer.curveToQuadratic(point1, targetPoint, m_mode); 200 225 return true; 201 226 } … … 204 229 { 205 230 FloatPoint targetPoint; 206 if (!m_source ->parseCurveToQuadraticSmoothSegment(targetPoint))231 if (!m_source.parseCurveToQuadraticSmoothSegment(targetPoint)) 207 232 return false; 208 233 … … 226 251 point2.scale(gOneOverThree, gOneOverThree); 227 252 228 m_consumer ->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);253 m_consumer.curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates); 229 254 230 255 m_controlPoint = cubicPoint; 231 256 m_currentPoint = targetPoint; 232 257 } else 233 m_consumer ->curveToQuadraticSmooth(targetPoint, m_mode);258 m_consumer.curveToQuadraticSmooth(targetPoint, m_mode); 234 259 return true; 235 260 } … … 243 268 bool sweep; 244 269 FloatPoint targetPoint; 245 if (!m_source ->parseArcToSegment(rx, ry, angle, largeArc, sweep, targetPoint))270 if (!m_source.parseArcToSegment(rx, ry, angle, largeArc, sweep, targetPoint)) 246 271 return false; 247 272 … … 265 290 else 266 291 m_currentPoint = targetPoint; 267 m_consumer ->lineTo(m_currentPoint, AbsoluteCoordinates);292 m_consumer.lineTo(m_currentPoint, AbsoluteCoordinates); 268 293 } else 269 m_consumer ->lineTo(targetPoint, m_mode);294 m_consumer.lineTo(targetPoint, m_mode); 270 295 return true; 271 296 } … … 278 303 return decomposeArcToCubic(angle, rx, ry, point1, targetPoint, largeArc, sweep); 279 304 } 280 m_consumer->arcTo(rx, ry, angle, largeArc, sweep, targetPoint, m_mode); 281 return true; 282 } 283 284 bool SVGPathParser::parsePathDataFromSource(PathParsingMode pathParsingMode, bool checkForInitialMoveTo) 285 { 286 ASSERT(m_source); 287 ASSERT(m_consumer); 288 289 m_pathParsingMode = pathParsingMode; 290 291 m_controlPoint = FloatPoint(); 292 m_currentPoint = FloatPoint(); 293 m_subPathPoint = FloatPoint(); 294 m_closePath = true; 295 305 m_consumer.arcTo(rx, ry, angle, largeArc, sweep, targetPoint, m_mode); 306 return true; 307 } 308 309 bool SVGPathParser::parsePathData(bool checkForInitialMoveTo) 310 { 296 311 // Skip any leading spaces. 297 if (!m_source ->moveToNextToken())312 if (!m_source.moveToNextToken()) 298 313 return true; 299 314 300 315 SVGPathSegType command; 301 m_source->parseSVGSegmentType(command); 302 m_lastCommand = PathSegUnknown; 316 m_source.parseSVGSegmentType(command); 303 317 304 318 // Path must start with moveto. … … 308 322 while (true) { 309 323 // Skip spaces between command and first coordinate. 310 m_source ->moveToNextToken();324 m_source.moveToNextToken(); 311 325 m_mode = AbsoluteCoordinates; 312 326 switch (command) { … … 380 394 return false; 381 395 } 382 if (!m_consumer ->continueConsuming())396 if (!m_consumer.continueConsuming()) 383 397 return true; 384 398 385 399 m_lastCommand = command; 386 400 387 if (!m_source ->hasMoreData())401 if (!m_source.hasMoreData()) 388 402 return true; 389 403 390 command = m_source ->nextCommand(command);404 command = m_source.nextCommand(command); 391 405 392 406 if (m_lastCommand != PathSegCurveToCubicAbs … … 400 414 m_controlPoint = m_currentPoint; 401 415 402 m_consumer ->incrementPathSegmentCount();416 m_consumer.incrementPathSegmentCount(); 403 417 } 404 418 405 419 return false; 406 }407 408 void SVGPathParser::cleanup()409 {410 ASSERT(m_source);411 ASSERT(m_consumer);412 413 m_consumer->cleanup();414 m_source = nullptr;415 m_consumer = nullptr;416 420 } 417 421 … … 496 500 point2.move(t * sinEndTheta, -t * cosEndTheta); 497 501 498 m_consumer ->curveToCubic(pointTransform.mapPoint(point1), pointTransform.mapPoint(point2),502 m_consumer.curveToCubic(pointTransform.mapPoint(point1), pointTransform.mapPoint(point2), 499 503 pointTransform.mapPoint(targetPoint), AbsoluteCoordinates); 500 504 } -
trunk/Source/WebCore/svg/SVGPathParser.h
r163440 r190849 3 3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> 4 4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> 5 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved. 6 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 7 7 * … … 31 31 namespace WebCore { 32 32 33 class SVGPathByteStream; 33 34 class SVGPathSource; 34 35 35 36 class SVGPathParser { 36 WTF_MAKE_NONCOPYABLE(SVGPathParser); WTF_MAKE_FAST_ALLOCATED;37 37 public: 38 SVGPathParser();38 static bool parse(SVGPathSource&, SVGPathConsumer&, PathParsingMode = NormalizedParsing, bool checkForInitialMoveTo = true); 39 39 40 bool parsePathDataFromSource(PathParsingMode, bool checkForInitialMoveTo = true); 41 void setCurrentConsumer(SVGPathConsumer* consumer) { m_consumer = consumer; } 42 void setCurrentSource(SVGPathSource* source) { m_source = source; } 43 void cleanup(); 40 static bool parseToByteStream(SVGPathSource&, SVGPathByteStream&, PathParsingMode = NormalizedParsing, bool checkForInitialMoveTo = true); 41 static bool parseToString(SVGPathSource&, String& result, PathParsingMode = NormalizedParsing, bool checkForInitialMoveTo = true); 44 42 45 43 private: 46 bool decomposeArcToCubic(float, float, float, FloatPoint&, FloatPoint&, bool largeArcFlag, bool sweepFlag); 44 SVGPathParser(SVGPathConsumer&, SVGPathSource&, PathParsingMode); 45 bool parsePathData(bool checkForInitialMoveTo); 46 47 bool decomposeArcToCubic(float angle, float rx, float ry, FloatPoint&, FloatPoint&, bool largeArcFlag, bool sweepFlag); 47 48 void parseClosePathSegment(); 48 49 bool parseMoveToSegment(); … … 56 57 bool parseArcToSegment(); 57 58 58 SVGPathSource* m_source; 59 SVGPathConsumer* m_consumer; 60 PathCoordinateMode m_mode; 61 PathParsingMode m_pathParsingMode; 62 SVGPathSegType m_lastCommand; 63 bool m_closePath; 59 SVGPathSource& m_source; 60 SVGPathConsumer& m_consumer; 64 61 FloatPoint m_controlPoint; 65 62 FloatPoint m_currentPoint; 66 63 FloatPoint m_subPathPoint; 64 PathCoordinateMode m_mode { AbsoluteCoordinates }; 65 const PathParsingMode m_pathParsingMode { NormalizedParsing }; 66 SVGPathSegType m_lastCommand { PathSegUnknown }; 67 bool m_closePath { true }; 67 68 }; 68 69 -
trunk/Source/WebCore/svg/SVGPathSegListBuilder.cpp
r184852 r190849 3 3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> 4 4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> 5 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved. 6 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 7 7 * … … 25 25 #include "SVGPathSegListBuilder.h" 26 26 27 #include "ExceptionCode.h"28 27 #include "SVGPathElement.h" 29 28 #include "SVGPathSegArcAbs.h" … … 50 49 namespace WebCore { 51 50 52 SVGPathSegListBuilder::SVGPathSegListBuilder( )53 : m_pathElement( nullptr)54 , m_pathSegList( nullptr)55 , m_pathSegRole( PathSegUndefinedRole)51 SVGPathSegListBuilder::SVGPathSegListBuilder(SVGPathElement& pathElement, SVGPathSegList& pathSegList, SVGPathSegRole role) 52 : m_pathElement(pathElement) 53 , m_pathSegList(pathSegList) 54 , m_pathSegRole(role) 56 55 { 57 56 } … … 59 58 void SVGPathSegListBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode) 60 59 { 61 ASSERT(m_pathElement);62 ASSERT(m_pathSegList);63 60 if (mode == AbsoluteCoordinates) 64 m_pathSegList ->append(m_pathElement->createSVGPathSegMovetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));61 m_pathSegList.append(m_pathElement.createSVGPathSegMovetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole)); 65 62 else 66 m_pathSegList ->append(m_pathElement->createSVGPathSegMovetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));63 m_pathSegList.append(m_pathElement.createSVGPathSegMovetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole)); 67 64 } 68 65 69 66 void SVGPathSegListBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode) 70 67 { 71 ASSERT(m_pathElement);72 ASSERT(m_pathSegList);73 68 if (mode == AbsoluteCoordinates) 74 m_pathSegList ->append(m_pathElement->createSVGPathSegLinetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));69 m_pathSegList.append(m_pathElement.createSVGPathSegLinetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole)); 75 70 else 76 m_pathSegList ->append(m_pathElement->createSVGPathSegLinetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));71 m_pathSegList.append(m_pathElement.createSVGPathSegLinetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole)); 77 72 } 78 73 79 74 void SVGPathSegListBuilder::lineToHorizontal(float x, PathCoordinateMode mode) 80 75 { 81 ASSERT(m_pathElement);82 ASSERT(m_pathSegList);83 76 if (mode == AbsoluteCoordinates) 84 m_pathSegList ->append(m_pathElement->createSVGPathSegLinetoHorizontalAbs(x, m_pathSegRole));77 m_pathSegList.append(m_pathElement.createSVGPathSegLinetoHorizontalAbs(x, m_pathSegRole)); 85 78 else 86 m_pathSegList ->append(m_pathElement->createSVGPathSegLinetoHorizontalRel(x, m_pathSegRole));79 m_pathSegList.append(m_pathElement.createSVGPathSegLinetoHorizontalRel(x, m_pathSegRole)); 87 80 } 88 81 89 82 void SVGPathSegListBuilder::lineToVertical(float y, PathCoordinateMode mode) 90 83 { 91 ASSERT(m_pathElement);92 ASSERT(m_pathSegList);93 84 if (mode == AbsoluteCoordinates) 94 m_pathSegList ->append(m_pathElement->createSVGPathSegLinetoVerticalAbs(y, m_pathSegRole));85 m_pathSegList.append(m_pathElement.createSVGPathSegLinetoVerticalAbs(y, m_pathSegRole)); 95 86 else 96 m_pathSegList ->append(m_pathElement->createSVGPathSegLinetoVerticalRel(y, m_pathSegRole));87 m_pathSegList.append(m_pathElement.createSVGPathSegLinetoVerticalRel(y, m_pathSegRole)); 97 88 } 98 89 99 90 void SVGPathSegListBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) 100 91 { 101 ASSERT(m_pathElement);102 ASSERT(m_pathSegList);103 92 if (mode == AbsoluteCoordinates) 104 m_pathSegList ->append(m_pathElement->createSVGPathSegCurvetoCubicAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole));93 m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoCubicAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole)); 105 94 else 106 m_pathSegList ->append(m_pathElement->createSVGPathSegCurvetoCubicRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole));95 m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoCubicRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole)); 107 96 } 108 97 109 98 void SVGPathSegListBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) 110 99 { 111 ASSERT(m_pathElement);112 ASSERT(m_pathSegList);113 100 if (mode == AbsoluteCoordinates) 114 m_pathSegList ->append(m_pathElement->createSVGPathSegCurvetoCubicSmoothAbs(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole));101 m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoCubicSmoothAbs(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole)); 115 102 else 116 m_pathSegList ->append(m_pathElement->createSVGPathSegCurvetoCubicSmoothRel(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole));103 m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoCubicSmoothRel(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole)); 117 104 } 118 105 119 106 void SVGPathSegListBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode) 120 107 { 121 ASSERT(m_pathElement);122 ASSERT(m_pathSegList);123 108 if (mode == AbsoluteCoordinates) 124 m_pathSegList ->append(m_pathElement->createSVGPathSegCurvetoQuadraticAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole));109 m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoQuadraticAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole)); 125 110 else 126 m_pathSegList ->append(m_pathElement->createSVGPathSegCurvetoQuadraticRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole));111 m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoQuadraticRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole)); 127 112 } 128 113 129 114 void SVGPathSegListBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode) 130 115 { 131 ASSERT(m_pathElement);132 ASSERT(m_pathSegList);133 116 if (mode == AbsoluteCoordinates) 134 m_pathSegList ->append(m_pathElement->createSVGPathSegCurvetoQuadraticSmoothAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));117 m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoQuadraticSmoothAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole)); 135 118 else 136 m_pathSegList ->append(m_pathElement->createSVGPathSegCurvetoQuadraticSmoothRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));119 m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoQuadraticSmoothRel(targetPoint.x(), targetPoint.y(), m_pathSegRole)); 137 120 } 138 121 139 122 void SVGPathSegListBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode) 140 123 { 141 ASSERT(m_pathElement);142 ASSERT(m_pathSegList);143 124 if (mode == AbsoluteCoordinates) 144 m_pathSegList ->append(m_pathElement->createSVGPathSegArcAbs(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole));125 m_pathSegList.append(m_pathElement.createSVGPathSegArcAbs(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole)); 145 126 else 146 m_pathSegList ->append(m_pathElement->createSVGPathSegArcRel(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole));127 m_pathSegList.append(m_pathElement.createSVGPathSegArcRel(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole)); 147 128 } 148 129 149 130 void SVGPathSegListBuilder::closePath() 150 131 { 151 ASSERT(m_pathElement); 152 ASSERT(m_pathSegList); 153 m_pathSegList->append(m_pathElement->createSVGPathSegClosePath(m_pathSegRole)); 132 m_pathSegList.append(m_pathElement.createSVGPathSegClosePath(m_pathSegRole)); 154 133 } 155 134 -
trunk/Source/WebCore/svg/SVGPathSegListBuilder.h
r184852 r190849 3 3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> 4 4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> 5 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved. 6 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 7 7 * … … 35 35 class SVGPathSegListBuilder : public SVGPathConsumer { 36 36 public: 37 SVGPathSegListBuilder(); 38 39 void setCurrentSVGPathElement(SVGPathElement* pathElement) { m_pathElement = pathElement; } 40 void setCurrentSVGPathSegList(SVGPathSegList& pathSegList) { m_pathSegList = &pathSegList; } 41 void setCurrentSVGPathSegRole(SVGPathSegRole pathSegRole) { m_pathSegRole = pathSegRole; } 37 SVGPathSegListBuilder(SVGPathElement&, SVGPathSegList&, SVGPathSegRole); 42 38 43 39 private: 44 40 virtual void incrementPathSegmentCount() override { } 45 41 virtual bool continueConsuming() override { return true; } 46 virtual void cleanup() override47 {48 m_pathElement = nullptr;49 m_pathSegList = nullptr;50 m_pathSegRole = PathSegUndefinedRole;51 }52 42 53 43 // Used in UnalteredParsing/NormalizedParsing modes. … … 65 55 virtual void arcTo(float, float, float, bool largeArcFlag, bool sweepFlag, const FloatPoint&, PathCoordinateMode) override; 66 56 67 SVGPathElement *m_pathElement;68 SVGPathSegList *m_pathSegList;69 SVGPathSegRole m_pathSegRole ;57 SVGPathElement& m_pathElement; 58 SVGPathSegList& m_pathSegList; 59 SVGPathSegRole m_pathSegRole { PathSegUndefinedRole }; 70 60 }; 71 61 -
trunk/Source/WebCore/svg/SVGPathStringBuilder.cpp
r163440 r190849 1 1 /* 2 2 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 3 * Copyright (C) 2015 Apple Inc. All rights reserved. 3 4 * 4 5 * This library is free software; you can redistribute it and/or … … 42 43 m_stringBuilder.resize(size - 1); 43 44 return m_stringBuilder.toString(); 44 }45 46 void SVGPathStringBuilder::cleanup()47 {48 m_stringBuilder.clear();49 45 } 50 46 -
trunk/Source/WebCore/svg/SVGPathStringBuilder.h
r163440 r190849 1 1 /* 2 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 3 * Copyright (C) 2015 Apple Inc. All rights reserved. 3 4 * 4 5 * This library is free software; you can redistribute it and/or … … 34 35 35 36 private: 36 virtual void cleanup() override;37 37 virtual void incrementPathSegmentCount() override; 38 38 virtual bool continueConsuming() override; -
trunk/Source/WebCore/svg/SVGPathTraversalStateBuilder.cpp
r184852 r190849 3 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> 4 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> 5 * Copyright (C) 2015 Apple Inc. All rights reserved. 5 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 6 7 * … … 28 29 namespace WebCore { 29 30 30 SVGPathTraversalStateBuilder::SVGPathTraversalStateBuilder() 31 : m_traversalState(nullptr) 32 , m_segmentIndex(0) 31 SVGPathTraversalStateBuilder::SVGPathTraversalStateBuilder(PathTraversalState& state, float desiredLength) 32 : m_traversalState(state) 33 33 { 34 m_traversalState.setDesiredLength(desiredLength); 34 35 } 35 36 36 37 void SVGPathTraversalStateBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode) 37 38 { 38 ASSERT(m_traversalState); 39 m_traversalState->processPathElement(PathElementMoveToPoint, &targetPoint); 39 m_traversalState.processPathElement(PathElementMoveToPoint, &targetPoint); 40 40 } 41 41 42 42 void SVGPathTraversalStateBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode) 43 43 { 44 ASSERT(m_traversalState); 45 m_traversalState->processPathElement(PathElementAddLineToPoint, &targetPoint); 44 m_traversalState.processPathElement(PathElementAddLineToPoint, &targetPoint); 46 45 } 47 46 … … 49 48 { 50 49 FloatPoint points[] = { point1, point2, targetPoint }; 51 ASSERT(m_traversalState); 52 m_traversalState ->processPathElement(PathElementAddCurveToPoint, points);50 51 m_traversalState.processPathElement(PathElementAddCurveToPoint, points); 53 52 } 54 53 55 54 void SVGPathTraversalStateBuilder::closePath() 56 55 { 57 ASSERT(m_traversalState); 58 m_traversalState->processPathElement(PathElementCloseSubpath, nullptr); 59 } 60 61 void SVGPathTraversalStateBuilder::setDesiredLength(float desiredLength) 62 { 63 ASSERT(m_traversalState); 64 m_traversalState->setDesiredLength(desiredLength); 56 m_traversalState.processPathElement(PathElementCloseSubpath, nullptr); 65 57 } 66 58 67 59 bool SVGPathTraversalStateBuilder::continueConsuming() 68 60 { 69 ASSERT(m_traversalState); 70 return !m_traversalState->success(); 61 return !m_traversalState.success(); 71 62 } 72 63 73 float SVGPathTraversalStateBuilder::totalLength() 64 float SVGPathTraversalStateBuilder::totalLength() const 74 65 { 75 ASSERT(m_traversalState); 76 return m_traversalState->totalLength(); 66 return m_traversalState.totalLength(); 77 67 } 78 68 79 SVGPoint SVGPathTraversalStateBuilder::currentPoint() 69 SVGPoint SVGPathTraversalStateBuilder::currentPoint() const 80 70 { 81 ASSERT(m_traversalState); 82 return m_traversalState->current(); 71 return m_traversalState.current(); 83 72 } 84 73 -
trunk/Source/WebCore/svg/SVGPathTraversalStateBuilder.h
r182828 r190849 2 2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> 3 3 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 4 * Copyright (C) 2015 Apple Inc. All rights reserved. 4 5 * 5 6 * This library is free software; you can redistribute it and/or … … 31 32 class SVGPathTraversalStateBuilder : public SVGPathConsumer { 32 33 public: 33 SVGPathTraversalStateBuilder( );34 SVGPathTraversalStateBuilder(PathTraversalState&, float desiredLength = 0); 34 35 35 unsigned pathSegmentIndex() { return m_segmentIndex; }36 float totalLength() ;37 SVGPoint currentPoint() ;36 unsigned pathSegmentIndex() const { return m_segmentIndex; } 37 float totalLength() const; 38 SVGPoint currentPoint() const; 38 39 39 void setCurrentTraversalState(PathTraversalState* traversalState) { m_traversalState = traversalState; }40 void setDesiredLength(float);41 40 virtual void incrementPathSegmentCount() override { ++m_segmentIndex; } 42 41 virtual bool continueConsuming() override; 43 virtual void cleanup() override { m_traversalState = nullptr, m_segmentIndex = 0; }44 42 45 43 private: … … 59 57 virtual void arcTo(float, float, float, bool, bool, const FloatPoint&, PathCoordinateMode) override { ASSERT_NOT_REACHED(); } 60 58 61 PathTraversalState *m_traversalState;62 unsigned m_segmentIndex ;59 PathTraversalState& m_traversalState; 60 unsigned m_segmentIndex { 0 }; 63 61 }; 64 62 -
trunk/Source/WebCore/svg/SVGPathUtilities.cpp
r190844 r190849 1 1 /* 2 2 * Copyright (C) Research In Motion Limited 2010, 2012. All rights reserved. 3 * Copyright (C) 2015 Apple Inc. All rights reserved. 3 4 * 4 5 * This library is free software; you can redistribute it and/or … … 38 39 namespace WebCore { 39 40 40 // FIXME: are all these globals warranted? Why not just make them on the stack?41 static SVGPathBuilder& globalSVGPathBuilder(Path& result)42 {43 static NeverDestroyed<SVGPathBuilder> s_builder;44 s_builder.get().setCurrentPath(&result);45 return s_builder.get();46 }47 48 static SVGPathSegListBuilder& globalSVGPathSegListBuilder(SVGPathElement& element, SVGPathSegRole role, SVGPathSegList& result)49 {50 static NeverDestroyed<SVGPathSegListBuilder> s_builder;51 52 s_builder.get().setCurrentSVGPathElement(&element);53 s_builder.get().setCurrentSVGPathSegList(result);54 s_builder.get().setCurrentSVGPathSegRole(role);55 return s_builder.get();56 }57 58 static SVGPathByteStreamBuilder& globalSVGPathByteStreamBuilder(SVGPathByteStream& result)59 {60 static NeverDestroyed<SVGPathByteStreamBuilder> s_builder;61 s_builder.get().setCurrentByteStream(&result);62 return s_builder.get();63 }64 65 static SVGPathStringBuilder& globalSVGPathStringBuilder()66 {67 static NeverDestroyed<SVGPathStringBuilder> s_builder;68 return s_builder.get();69 }70 71 static SVGPathTraversalStateBuilder& globalSVGPathTraversalStateBuilder(PathTraversalState& traversalState, float length)72 {73 static NeverDestroyed<SVGPathTraversalStateBuilder> s_parser;74 75 s_parser.get().setCurrentTraversalState(&traversalState);76 s_parser.get().setDesiredLength(length);77 return s_parser.get();78 }79 80 // FIXME: why bother keeping a singleton around? Is it slow to allocate?81 static SVGPathParser& globalSVGPathParser(SVGPathSource& source, SVGPathConsumer& consumer)82 {83 static NeverDestroyed<SVGPathParser> s_parser;84 85 s_parser.get().setCurrentSource(&source);86 s_parser.get().setCurrentConsumer(&consumer);87 return s_parser.get();88 }89 90 static SVGPathBlender& globalSVGPathBlender()91 {92 static NeverDestroyed<SVGPathBlender> s_blender;93 return s_blender.get();94 }95 96 41 bool buildPathFromString(const String& d, Path& result) 97 42 { … … 99 44 return true; 100 45 101 SVGPathBuilder& builder = globalSVGPathBuilder(result); 102 46 SVGPathBuilder builder(result); 103 47 SVGPathStringSource source(d); 104 SVGPathParser& parser = globalSVGPathParser(source, builder); 105 bool ok = parser.parsePathDataFromSource(NormalizedParsing); 106 parser.cleanup(); 107 return ok; 48 return SVGPathParser::parse(source, builder); 108 49 } 109 50 … … 114 55 return true; 115 56 116 SVGPathByteStreamBuilder& builder = globalSVGPathByteStreamBuilder(result);117 118 57 SVGPathSegListSource source(list); 119 SVGPathParser& parser = globalSVGPathParser(source, builder); 120 bool ok = parser.parsePathDataFromSource(parsingMode); 121 parser.cleanup(); 122 return ok; 58 return SVGPathParser::parseToByteStream(source, result, parsingMode); 123 59 } 124 60 … … 132 68 133 69 SVGPathByteStream appendedByteStream; 134 SVGPathByteStreamBuilder& builder = globalSVGPathByteStreamBuilder(appendedByteStream);135 70 SVGPathSegListSource source(appendedItemList); 136 SVGPathParser& parser = globalSVGPathParser(source, builder); 137 bool ok = parser.parsePathDataFromSource(parsingMode, false); 138 parser.cleanup(); 71 bool ok = SVGPathParser::parseToByteStream(source, result, parsingMode, false); 139 72 140 73 if (ok) … … 149 82 return true; 150 83 151 SVGPathBuilder& builder = globalSVGPathBuilder(result); 152 153 SVGPathByteStreamSource source(stream); 154 SVGPathParser& parser = globalSVGPathParser(source, builder); 155 bool ok = parser.parsePathDataFromSource(NormalizedParsing); 156 parser.cleanup(); 157 return ok; 84 SVGPathBuilder builder(result); 85 SVGPathByteStreamSource source(stream); 86 return SVGPathParser::parse(source, builder); 158 87 } 159 88 … … 163 92 return true; 164 93 165 SVGPathSegListBuilder& builder = globalSVGPathSegListBuilder(element, parsingMode == NormalizedParsing ? PathSegNormalizedRole : PathSegUnalteredRole, result); 166 167 SVGPathByteStreamSource source(stream); 168 SVGPathParser& parser = globalSVGPathParser(source, builder); 169 bool ok = parser.parsePathDataFromSource(parsingMode); 170 parser.cleanup(); 171 return ok; 94 SVGPathSegListBuilder builder(element, result, parsingMode == NormalizedParsing ? PathSegNormalizedRole : PathSegUnalteredRole); 95 SVGPathByteStreamSource source(stream); 96 return SVGPathParser::parse(source, builder, parsingMode); 172 97 } 173 98 … … 177 102 return true; 178 103 179 SVGPathStringBuilder& builder = globalSVGPathStringBuilder(); 180 181 SVGPathByteStreamSource source(stream); 182 SVGPathParser& parser = globalSVGPathParser(source, builder); 183 bool ok = parser.parsePathDataFromSource(parsingMode); 184 result = builder.result(); 185 parser.cleanup(); 186 return ok; 104 SVGPathByteStreamSource source(stream); 105 return SVGPathParser::parseToString(source, result, parsingMode); 187 106 } 188 107 … … 193 112 return true; 194 113 195 SVGPathStringBuilder& builder = globalSVGPathStringBuilder();196 197 114 SVGPathSegListSource source(list); 198 SVGPathParser& parser = globalSVGPathParser(source, builder); 199 bool ok = parser.parsePathDataFromSource(parsingMode); 200 result = builder.result(); 201 parser.cleanup(); 202 return ok; 115 return SVGPathParser::parseToString(source, result, parsingMode); 203 116 } 204 117 … … 209 122 return true; 210 123 211 SVGPathByteStreamBuilder& builder = globalSVGPathByteStreamBuilder(result);212 213 124 SVGPathStringSource source(d); 214 SVGPathParser& parser = globalSVGPathParser(source, builder); 215 bool ok = parser.parsePathDataFromSource(parsingMode); 216 parser.cleanup(); 217 return ok; 125 return SVGPathParser::parseToByteStream(source, result, parsingMode); 218 126 } 219 127 … … 225 133 return true; 226 134 227 SVGPathByteStreamBuilder & builder = globalSVGPathByteStreamBuilder(result);135 SVGPathByteStreamBuilder builder(result); 228 136 229 137 SVGPathByteStreamSource fromSource(fromStream); 230 138 SVGPathByteStreamSource toSource(toStream); 231 SVGPathBlender& blender = globalSVGPathBlender(); 232 bool ok = blender.blendAnimatedPath(progress, &fromSource, &toSource, &builder); 233 blender.cleanup(); 234 return ok; 139 return SVGPathBlender::blendAnimatedPath(fromSource, toSource, builder, progress); 235 140 } 236 141 … … 242 147 243 148 // Is it OK to make the SVGPathByteStreamBuilder from a stream, and then clear that stream? 244 SVGPathByteStreamBuilder & builder = globalSVGPathByteStreamBuilder(streamToAppendTo);149 SVGPathByteStreamBuilder builder(streamToAppendTo); 245 150 246 151 SVGPathByteStream fromStreamCopy = streamToAppendTo; … … 249 154 SVGPathByteStreamSource fromSource(fromStreamCopy); 250 155 SVGPathByteStreamSource bySource(byStream); 251 SVGPathBlender& blender = globalSVGPathBlender(); 252 bool ok = blender.addAnimatedPath(&fromSource, &bySource, &builder, repeatCount); 253 blender.cleanup(); 254 return ok; 156 return SVGPathBlender::addAnimatedPath(fromSource, bySource, builder, repeatCount); 255 157 } 256 158 … … 261 163 262 164 PathTraversalState traversalState(PathTraversalState::Action::SegmentAtLength); 263 SVGPathTraversalStateBuilder& builder = globalSVGPathTraversalStateBuilder(traversalState, length); 264 265 SVGPathByteStreamSource source(stream); 266 SVGPathParser& parser = globalSVGPathParser(source, builder); 267 bool ok = parser.parsePathDataFromSource(NormalizedParsing); 165 SVGPathTraversalStateBuilder builder(traversalState, length); 166 167 SVGPathByteStreamSource source(stream); 168 bool ok = SVGPathParser::parse(source, builder); 268 169 pathSeg = builder.pathSegmentIndex(); 269 parser.cleanup();270 170 return ok; 271 171 } … … 277 177 278 178 PathTraversalState traversalState(PathTraversalState::Action::TotalLength); 279 SVGPathTraversalStateBuilder& builder = globalSVGPathTraversalStateBuilder(traversalState, 0); 280 281 SVGPathByteStreamSource source(stream); 282 SVGPath Parser& parser = globalSVGPathParser(source, builder);283 bool ok = parser.parsePathDataFromSource(NormalizedParsing);179 180 SVGPathTraversalStateBuilder builder(traversalState); 181 182 SVGPathByteStreamSource source(stream); 183 bool ok = SVGPathParser::parse(source, builder); 284 184 totalLength = builder.totalLength(); 285 parser.cleanup();286 185 return ok; 287 186 } … … 293 192 294 193 PathTraversalState traversalState(PathTraversalState::Action::VectorAtLength); 295 SVGPathTraversalStateBuilder& builder = globalSVGPathTraversalStateBuilder(traversalState, length); 296 297 SVGPathByteStreamSource source(stream); 298 SVGPath Parser& parser = globalSVGPathParser(source, builder);299 bool ok = parser.parsePathDataFromSource(NormalizedParsing);194 195 SVGPathTraversalStateBuilder builder(traversalState, length); 196 197 SVGPathByteStreamSource source(stream); 198 bool ok = SVGPathParser::parse(source, builder); 300 199 point = builder.currentPoint(); 301 parser.cleanup();302 200 return ok; 303 201 } … … 333 231 // a path, only apply a function to all path elements at once. 334 232 335 SVGPathStringBuilder & builder = globalSVGPathStringBuilder();233 SVGPathStringBuilder builder; 336 234 path.apply([&builder](const PathElement& pathElement) { 337 235 pathIteratorForBuildingString(builder, pathElement); 338 236 }); 339 237 string = builder.result(); 340 static_cast<SVGPathConsumer&>(builder).cleanup(); // Wat?341 238 342 239 return true; -
trunk/Source/WebCore/svg/SVGPathUtilities.h
r190844 r190849 1 1 /* 2 2 * Copyright (C) Research In Motion Limited 2010, 2012. All rights reserved. 3 * Copyright (C) 2015 Apple Inc. All rights reserved. 3 4 * 4 5 * This library is free software; you can redistribute it and/or -
trunk/Source/WebCore/svg/SVGToOTFFontConversion.cpp
r190841 r190849 1 1 /* 2 * Copyright (C) 2014 Apple Inc. All rights reserved.2 * Copyright (C) 2014-2015 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 34 34 #include "SVGHKernElement.h" 35 35 #include "SVGMissingGlyphElement.h" 36 #include "SVGPathBuilder.h"37 36 #include "SVGPathParser.h" 38 37 #include "SVGPathStringSource.h" … … 1127 1126 static const char rMoveTo = 0x15; 1128 1127 1129 class CFFBuilder : public SVGPath Builder {1128 class CFFBuilder : public SVGPathConsumer { 1130 1129 public: 1131 1130 CFFBuilder(Vector<char>& cffData, float width, FloatPoint origin) 1132 1131 : m_cffData(cffData) 1133 , m_hasBoundingBox(false)1134 1132 { 1135 1133 writeCFFEncodedNumber(m_cffData, width); … … 1210 1208 } 1211 1209 1210 virtual void incrementPathSegmentCount() override { } 1211 virtual bool continueConsuming() override { return true; } 1212 1213 virtual void lineToHorizontal(float, PathCoordinateMode) override { ASSERT_NOT_REACHED(); } 1214 virtual void lineToVertical(float, PathCoordinateMode) override { ASSERT_NOT_REACHED(); } 1215 virtual void curveToCubicSmooth(const FloatPoint&, const FloatPoint&, PathCoordinateMode) override { ASSERT_NOT_REACHED(); } 1216 virtual void curveToQuadratic(const FloatPoint&, const FloatPoint&, PathCoordinateMode) override { ASSERT_NOT_REACHED(); } 1217 virtual void curveToQuadraticSmooth(const FloatPoint&, PathCoordinateMode) override { ASSERT_NOT_REACHED(); } 1218 virtual void arcTo(float, float, float, bool, bool, const FloatPoint&, PathCoordinateMode) override { ASSERT_NOT_REACHED(); } 1219 1212 1220 Vector<char>& m_cffData; 1213 1221 FloatPoint m_startingPoint; 1222 FloatPoint m_current; 1214 1223 FloatRect m_boundingBox; 1215 bool m_hasBoundingBox ;1224 bool m_hasBoundingBox { false }; 1216 1225 }; 1217 1226 … … 1242 1251 SVGPathStringSource source(dAttribute); 1243 1252 1244 SVGPathParser parser; 1245 parser.setCurrentSource(&source); 1246 parser.setCurrentConsumer(&builder); 1247 1248 ok = parser.parsePathDataFromSource(NormalizedParsing); 1249 parser.cleanup(); 1250 1253 ok = SVGPathParser::parse(source, builder); 1251 1254 if (!ok) 1252 1255 result.clear();
Note: See TracChangeset
for help on using the changeset viewer.