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