| OLD | NEW |
| 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 #include "core/svg/SVGPathByteStreamSource.h" | 21 #include "core/svg/SVGPathByteStreamSource.h" |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 | 24 |
| 25 bool SVGPathByteStreamSource::hasMoreData() const | 25 bool SVGPathByteStreamSource::hasMoreData() const |
| 26 { | 26 { |
| 27 return m_streamCurrent < m_streamEnd; | 27 return m_streamCurrent < m_streamEnd; |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool SVGPathByteStreamSource::parseSVGSegmentType(SVGPathSegType& pathSegType) | 30 SVGPathSegType SVGPathByteStreamSource::peekSegmentType() |
| 31 { | 31 { |
| 32 pathSegType = static_cast<SVGPathSegType>(readSVGSegmentType()); | 32 ASSERT(hasMoreData()); |
| 33 return true; | 33 ASSERT(m_streamCurrent + sizeof(unsigned short) <= m_streamEnd); |
| 34 unsigned short commandBytes; |
| 35 memcpy(&commandBytes, m_streamCurrent, sizeof(commandBytes)); |
| 36 return static_cast<SVGPathSegType>(commandBytes); |
| 34 } | 37 } |
| 35 | 38 |
| 36 SVGPathSegType SVGPathByteStreamSource::nextCommand(SVGPathSegType) | 39 PathSegmentData SVGPathByteStreamSource::parseSegment() |
| 37 { | 40 { |
| 38 return static_cast<SVGPathSegType>(readSVGSegmentType()); | 41 ASSERT(hasMoreData()); |
| 39 } | 42 PathSegmentData segment; |
| 43 segment.command = static_cast<SVGPathSegType>(readSVGSegmentType()); |
| 40 | 44 |
| 41 bool SVGPathByteStreamSource::parseMoveToSegment(FloatPoint& targetPoint) | 45 switch (segment.command) { |
| 42 { | 46 case PathSegCurveToCubicRel: |
| 43 targetPoint = readFloatPoint(); | 47 case PathSegCurveToCubicAbs: |
| 44 return true; | 48 segment.point1 = readFloatPoint(); |
| 45 } | 49 /* fall through */ |
| 46 | 50 case PathSegCurveToCubicSmoothRel: |
| 47 bool SVGPathByteStreamSource::parseLineToSegment(FloatPoint& targetPoint) | 51 case PathSegCurveToCubicSmoothAbs: |
| 48 { | 52 segment.point2 = readFloatPoint(); |
| 49 targetPoint = readFloatPoint(); | 53 /* fall through */ |
| 50 return true; | 54 case PathSegMoveToRel: |
| 51 } | 55 case PathSegMoveToAbs: |
| 52 | 56 case PathSegLineToRel: |
| 53 bool SVGPathByteStreamSource::parseLineToHorizontalSegment(float& x) | 57 case PathSegLineToAbs: |
| 54 { | 58 case PathSegCurveToQuadraticSmoothRel: |
| 55 x = readFloat(); | 59 case PathSegCurveToQuadraticSmoothAbs: |
| 56 return true; | 60 segment.targetPoint = readFloatPoint(); |
| 57 } | 61 break; |
| 58 | 62 case PathSegLineToHorizontalRel: |
| 59 bool SVGPathByteStreamSource::parseLineToVerticalSegment(float& y) | 63 case PathSegLineToHorizontalAbs: |
| 60 { | 64 segment.targetPoint.setX(readFloat()); |
| 61 y = readFloat(); | 65 break; |
| 62 return true; | 66 case PathSegLineToVerticalRel: |
| 63 } | 67 case PathSegLineToVerticalAbs: |
| 64 | 68 segment.targetPoint.setY(readFloat()); |
| 65 bool SVGPathByteStreamSource::parseCurveToCubicSegment(FloatPoint& point1, Float
Point& point2, FloatPoint& targetPoint) | 69 break; |
| 66 { | 70 case PathSegClosePath: |
| 67 point1 = readFloatPoint(); | 71 break; |
| 68 point2 = readFloatPoint(); | 72 case PathSegCurveToQuadraticRel: |
| 69 targetPoint = readFloatPoint(); | 73 case PathSegCurveToQuadraticAbs: |
| 70 return true; | 74 segment.point1 = readFloatPoint(); |
| 71 } | 75 segment.targetPoint = readFloatPoint(); |
| 72 | 76 break; |
| 73 bool SVGPathByteStreamSource::parseCurveToCubicSmoothSegment(FloatPoint& point2,
FloatPoint& targetPoint) | 77 case PathSegArcRel: |
| 74 { | 78 case PathSegArcAbs: { |
| 75 point2 = readFloatPoint(); | 79 segment.point1 = readFloatPoint(); // rx and ry |
| 76 targetPoint = readFloatPoint(); | 80 segment.point2.setX(readFloat()); // angle |
| 77 return true; | 81 segment.arcLarge = readFlag(); |
| 78 } | 82 segment.arcSweep = readFlag(); |
| 79 | 83 segment.targetPoint = readFloatPoint(); |
| 80 bool SVGPathByteStreamSource::parseCurveToQuadraticSegment(FloatPoint& point1, F
loatPoint& targetPoint) | 84 break; |
| 81 { | 85 } |
| 82 point1 = readFloatPoint(); | 86 default: |
| 83 targetPoint = readFloatPoint(); | 87 ASSERT_NOT_REACHED(); |
| 84 return true; | 88 } |
| 85 } | 89 return segment; |
| 86 | |
| 87 bool SVGPathByteStreamSource::parseCurveToQuadraticSmoothSegment(FloatPoint& tar
getPoint) | |
| 88 { | |
| 89 targetPoint = readFloatPoint(); | |
| 90 return true; | |
| 91 } | |
| 92 | |
| 93 bool SVGPathByteStreamSource::parseArcToSegment(float& rx, float& ry, float& ang
le, bool& largeArc, bool& sweep, FloatPoint& targetPoint) | |
| 94 { | |
| 95 rx = readFloat(); | |
| 96 ry = readFloat(); | |
| 97 angle = readFloat(); | |
| 98 largeArc = readFlag(); | |
| 99 sweep = readFlag(); | |
| 100 targetPoint = readFloatPoint(); | |
| 101 return true; | |
| 102 } | 90 } |
| 103 | 91 |
| 104 } | 92 } |
| OLD | NEW |