1 /* 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #include "config.h" 21 22 #if ENABLE(SVG) 23 #include "SVGPathByteStreamBuilder.h" 24 25 #include "SVGPathParser.h" 26 #include "SVGPathSeg.h" 27 #include "SVGPathStringSource.h" 28 #include <wtf/OwnPtr.h> 29 30 namespace WebCore { 31 32 SVGPathByteStreamBuilder::SVGPathByteStreamBuilder() 33 : m_byteStream(0) 34 { 35 } 36 37 void SVGPathByteStreamBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode) 38 { 39 ASSERT(m_byteStream); 40 writeSegmentType(mode == RelativeCoordinates ? PathSegMoveToRel : PathSegMoveToAbs); 41 writeFloatPoint(targetPoint); 42 } 43 44 void SVGPathByteStreamBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode) 45 { 46 ASSERT(m_byteStream); 47 writeSegmentType(mode == RelativeCoordinates ? PathSegLineToRel : PathSegLineToAbs); 48 writeFloatPoint(targetPoint); 49 } 50 51 void SVGPathByteStreamBuilder::lineToHorizontal(float x, PathCoordinateMode mode) 52 { 53 ASSERT(m_byteStream); 54 writeSegmentType(mode == RelativeCoordinates ? PathSegLineToHorizontalRel : PathSegLineToHorizontalAbs); 55 writeFloat(x); 56 } 57 58 void SVGPathByteStreamBuilder::lineToVertical(float y, PathCoordinateMode mode) 59 { 60 ASSERT(m_byteStream); 61 writeSegmentType(mode == RelativeCoordinates ? PathSegLineToVerticalRel : PathSegLineToVerticalAbs); 62 writeFloat(y); 63 } 64 65 void SVGPathByteStreamBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) 66 { 67 ASSERT(m_byteStream); 68 writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicRel : PathSegCurveToCubicAbs); 69 writeFloatPoint(point1); 70 writeFloatPoint(point2); 71 writeFloatPoint(targetPoint); 72 } 73 74 void SVGPathByteStreamBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) 75 { 76 ASSERT(m_byteStream); 77 writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicSmoothRel : PathSegCurveToCubicSmoothAbs); 78 writeFloatPoint(point2); 79 writeFloatPoint(targetPoint); 80 } 81 82 void SVGPathByteStreamBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode) 83 { 84 ASSERT(m_byteStream); 85 writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadraticRel : PathSegCurveToQuadraticAbs); 86 writeFloatPoint(point1); 87 writeFloatPoint(targetPoint); 88 } 89 90 void SVGPathByteStreamBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode) 91 { 92 ASSERT(m_byteStream); 93 writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadraticSmoothRel : PathSegCurveToQuadraticSmoothAbs); 94 writeFloatPoint(targetPoint); 95 } 96 97 void SVGPathByteStreamBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode) 98 { 99 ASSERT(m_byteStream); 100 writeSegmentType(mode == RelativeCoordinates ? PathSegArcRel : PathSegArcAbs); 101 writeFloat(r1); 102 writeFloat(r2); 103 writeFloat(angle); 104 writeFlag(largeArcFlag); 105 writeFlag(sweepFlag); 106 writeFloatPoint(targetPoint); 107 } 108 109 void SVGPathByteStreamBuilder::closePath() 110 { 111 ASSERT(m_byteStream); 112 writeSegmentType(PathSegClosePath); 113 } 114 115 } // namespace WebCore 116 117 #endif // ENABLE(SVG) 118