Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: Source/core/svg/SVGPathByteStreamBuilder.cpp

Issue 1037463002: Rework the SVGPathConsumer interface (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase; FIXME -> TODO. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/svg/SVGPathByteStreamBuilder.h ('k') | Source/core/svg/SVGPathConsumer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 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 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, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 */ 18 */
19 19
20 #include "config.h" 20 #include "config.h"
21
22 #include "core/svg/SVGPathByteStreamBuilder.h" 21 #include "core/svg/SVGPathByteStreamBuilder.h"
23 22
23 #include "core/svg/SVGPathByteStream.h"
24 #include "core/svg/SVGPathSeg.h" 24 #include "core/svg/SVGPathSeg.h"
25 #include "wtf/OwnPtr.h" 25 #include "platform/geometry/FloatPoint.h"
26 26
27 namespace blink { 27 namespace blink {
28 28
29 // Helper class that coalesces writes to a SVGPathByteStream to a local buffer. 29 // Helper class that coalesces writes to a SVGPathByteStream to a local buffer.
30 class CoalescingBuffer { 30 class CoalescingBuffer {
31 public: 31 public:
32 CoalescingBuffer(SVGPathByteStream& byteStream) 32 CoalescingBuffer(SVGPathByteStream& byteStream)
33 : m_currentOffset(0) 33 : m_currentOffset(0)
34 , m_byteStream(byteStream) 34 , m_byteStream(byteStream)
35 { 35 {
(...skipping 30 matching lines...) Expand all
66 size_t m_currentOffset; 66 size_t m_currentOffset;
67 unsigned char m_bytes[sizeof(unsigned short) + sizeof(FloatPoint) * 3]; 67 unsigned char m_bytes[sizeof(unsigned short) + sizeof(FloatPoint) * 3];
68 SVGPathByteStream& m_byteStream; 68 SVGPathByteStream& m_byteStream;
69 }; 69 };
70 70
71 SVGPathByteStreamBuilder::SVGPathByteStreamBuilder(SVGPathByteStream& byteStream ) 71 SVGPathByteStreamBuilder::SVGPathByteStreamBuilder(SVGPathByteStream& byteStream )
72 : m_byteStream(byteStream) 72 : m_byteStream(byteStream)
73 { 73 {
74 } 74 }
75 75
76 void SVGPathByteStreamBuilder::moveTo(const FloatPoint& targetPoint, PathCoordin ateMode mode) 76 void SVGPathByteStreamBuilder::emitSegment(const PathSegmentData& segment)
77 { 77 {
78 CoalescingBuffer buffer(m_byteStream); 78 CoalescingBuffer buffer(m_byteStream);
79 buffer.writeSegmentType(mode == RelativeCoordinates ? PathSegMoveToRel : Pa thSegMoveToAbs); 79 buffer.writeSegmentType(segment.command);
80 buffer.writeFloatPoint(targetPoint);
81 }
82 80
83 void SVGPathByteStreamBuilder::lineTo(const FloatPoint& targetPoint, PathCoordin ateMode mode) 81 switch (segment.command) {
84 { 82 case PathSegMoveToRel:
85 CoalescingBuffer buffer(m_byteStream); 83 case PathSegMoveToAbs:
86 buffer.writeSegmentType(mode == RelativeCoordinates ? PathSegLineToRel : Pat hSegLineToAbs); 84 case PathSegLineToRel:
87 buffer.writeFloatPoint(targetPoint); 85 case PathSegLineToAbs:
88 } 86 case PathSegCurveToQuadraticSmoothRel:
89 87 case PathSegCurveToQuadraticSmoothAbs:
90 void SVGPathByteStreamBuilder::lineToHorizontal(float x, PathCoordinateMode mode ) 88 buffer.writeFloatPoint(segment.targetPoint);
91 { 89 break;
92 CoalescingBuffer buffer(m_byteStream); 90 case PathSegLineToHorizontalRel:
93 buffer.writeSegmentType(mode == RelativeCoordinates ? PathSegLineToHorizonta lRel : PathSegLineToHorizontalAbs); 91 case PathSegLineToHorizontalAbs:
94 buffer.writeFloat(x); 92 buffer.writeFloat(segment.targetPoint.x());
95 } 93 break;
96 94 case PathSegLineToVerticalRel:
97 void SVGPathByteStreamBuilder::lineToVertical(float y, PathCoordinateMode mode) 95 case PathSegLineToVerticalAbs:
98 { 96 buffer.writeFloat(segment.targetPoint.y());
99 CoalescingBuffer buffer(m_byteStream); 97 break;
100 buffer.writeSegmentType(mode == RelativeCoordinates ? PathSegLineToVerticalR el : PathSegLineToVerticalAbs); 98 case PathSegClosePath:
101 buffer.writeFloat(y); 99 break;
102 } 100 case PathSegCurveToCubicRel:
103 101 case PathSegCurveToCubicAbs:
104 void SVGPathByteStreamBuilder::curveToCubic(const FloatPoint& point1, const Floa tPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) 102 buffer.writeFloatPoint(segment.point1);
105 { 103 buffer.writeFloatPoint(segment.point2);
106 CoalescingBuffer buffer(m_byteStream); 104 buffer.writeFloatPoint(segment.targetPoint);
107 buffer.writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicRel : PathSegCurveToCubicAbs); 105 break;
108 buffer.writeFloatPoint(point1); 106 case PathSegCurveToCubicSmoothRel:
109 buffer.writeFloatPoint(point2); 107 case PathSegCurveToCubicSmoothAbs:
110 buffer.writeFloatPoint(targetPoint); 108 buffer.writeFloatPoint(segment.point2);
111 } 109 buffer.writeFloatPoint(segment.targetPoint);
112 110 break;
113 void SVGPathByteStreamBuilder::curveToCubicSmooth(const FloatPoint& point2, cons t FloatPoint& targetPoint, PathCoordinateMode mode) 111 case PathSegCurveToQuadraticRel:
114 { 112 case PathSegCurveToQuadraticAbs:
115 CoalescingBuffer buffer(m_byteStream); 113 buffer.writeFloatPoint(segment.point1);
116 buffer.writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicSmo othRel : PathSegCurveToCubicSmoothAbs); 114 buffer.writeFloatPoint(segment.targetPoint);
117 buffer.writeFloatPoint(point2); 115 break;
118 buffer.writeFloatPoint(targetPoint); 116 case PathSegArcRel:
119 } 117 case PathSegArcAbs:
120 118 buffer.writeFloatPoint(segment.point1);
121 void SVGPathByteStreamBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode) 119 buffer.writeFloat(segment.point2.x());
122 { 120 buffer.writeFlag(segment.arcLarge);
123 CoalescingBuffer buffer(m_byteStream); 121 buffer.writeFlag(segment.arcSweep);
124 buffer.writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadrati cRel : PathSegCurveToQuadraticAbs); 122 buffer.writeFloatPoint(segment.targetPoint);
125 buffer.writeFloatPoint(point1); 123 break;
126 buffer.writeFloatPoint(targetPoint); 124 default:
127 } 125 ASSERT_NOT_REACHED();
128 126 }
129 void SVGPathByteStreamBuilder::curveToQuadraticSmooth(const FloatPoint& targetPo int, PathCoordinateMode mode)
130 {
131 CoalescingBuffer buffer(m_byteStream);
132 buffer.writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadrati cSmoothRel : PathSegCurveToQuadraticSmoothAbs);
133 buffer.writeFloatPoint(targetPoint);
134 }
135
136 void SVGPathByteStreamBuilder::arcTo(float r1, float r2, float angle, bool large ArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode)
137 {
138 CoalescingBuffer buffer(m_byteStream);
139 buffer.writeSegmentType(mode == RelativeCoordinates ? PathSegArcRel : PathSe gArcAbs);
140 buffer.writeFloat(r1);
141 buffer.writeFloat(r2);
142 buffer.writeFloat(angle);
143 buffer.writeFlag(largeArcFlag);
144 buffer.writeFlag(sweepFlag);
145 buffer.writeFloatPoint(targetPoint);
146 }
147
148 void SVGPathByteStreamBuilder::closePath()
149 {
150 CoalescingBuffer buffer(m_byteStream);
151 buffer.writeSegmentType(PathSegClosePath);
152 } 127 }
153 128
154 } // namespace blink 129 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/svg/SVGPathByteStreamBuilder.h ('k') | Source/core/svg/SVGPathConsumer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698