| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 #if ENABLE(SVG) | 23 #if ENABLE(SVG) |
| 24 #include "FloatConversion.h" | 24 #include "FloatConversion.h" |
| 25 #include "Path.h" | 25 #include "Path.h" |
| 26 #include <wtf/MathExtras.h> | 26 #include <wtf/MathExtras.h> |
| 27 | 27 |
| 28 namespace WebCore { | 28 namespace WebCore { |
| 29 | 29 |
| 30 class RenderSVGResourceMarker; | 30 class RenderSVGResourceMarker; |
| 31 | 31 |
| 32 class SVGMarkerData { | 32 enum SVGMarkerType { |
| 33 public: | 33 StartMarker, |
| 34 enum Type { | 34 MidMarker, |
| 35 Unknown = 0, | 35 EndMarker |
| 36 Start, | 36 }; |
| 37 Mid, | |
| 38 End | |
| 39 }; | |
| 40 | 37 |
| 41 SVGMarkerData(const Type& type = Unknown, RenderSVGResourceMarker* marker =
0) | 38 struct MarkerPosition { |
| 42 : m_type(type) | 39 MarkerPosition(SVGMarkerType useType, const FloatPoint& useOrigin, float use
Angle) |
| 43 , m_marker(marker) | 40 : type(useType) |
| 41 , origin(useOrigin) |
| 42 , angle(useAngle) |
| 44 { | 43 { |
| 45 } | 44 } |
| 46 | 45 |
| 47 FloatPoint origin() const { return m_origin; } | 46 SVGMarkerType type; |
| 48 RenderSVGResourceMarker* marker() const { return m_marker; } | 47 FloatPoint origin; |
| 48 float angle; |
| 49 }; |
| 49 | 50 |
| 50 float currentAngle() const | 51 class SVGMarkerData { |
| 52 public: |
| 53 SVGMarkerData(Vector<MarkerPosition>& positions) |
| 54 : m_positions(positions) |
| 55 , m_elementIndex(0) |
| 56 { |
| 57 } |
| 58 |
| 59 static void updateFromPathElement(void* info, const PathElement* element) |
| 60 { |
| 61 SVGMarkerData* markerData = static_cast<SVGMarkerData*>(info); |
| 62 |
| 63 // First update the outslope for the previous element. |
| 64 markerData->updateOutslope(element->points[0]); |
| 65 |
| 66 // Record the marker for the previous element. |
| 67 if (markerData->m_elementIndex > 0) { |
| 68 SVGMarkerType markerType = markerData->m_elementIndex == 1 ? StartMa
rker : MidMarker; |
| 69 markerData->m_positions.append(MarkerPosition(markerType, markerData
->m_origin, markerData->currentAngle(markerType))); |
| 70 } |
| 71 |
| 72 // Update our marker data for this element. |
| 73 markerData->updateMarkerDataForPathElement(element); |
| 74 ++markerData->m_elementIndex; |
| 75 } |
| 76 |
| 77 void pathIsDone() |
| 78 { |
| 79 m_positions.append(MarkerPosition(EndMarker, m_origin, currentAngle(EndM
arker))); |
| 80 } |
| 81 |
| 82 private: |
| 83 float currentAngle(SVGMarkerType type) const |
| 51 { | 84 { |
| 52 FloatSize inslopeChange = m_inslopePoints[1] - m_inslopePoints[0]; | 85 FloatSize inslopeChange = m_inslopePoints[1] - m_inslopePoints[0]; |
| 53 FloatSize outslopeChange = m_outslopePoints[1] - m_outslopePoints[0]; | 86 FloatSize outslopeChange = m_outslopePoints[1] - m_outslopePoints[0]; |
| 54 | 87 |
| 55 double inslope = rad2deg(atan2(inslopeChange.height(), inslopeChange.wid
th())); | 88 double inslope = rad2deg(atan2(inslopeChange.height(), inslopeChange.wid
th())); |
| 56 double outslope = rad2deg(atan2(outslopeChange.height(), outslopeChange.
width())); | 89 double outslope = rad2deg(atan2(outslopeChange.height(), outslopeChange.
width())); |
| 57 | 90 |
| 58 double angle = 0; | 91 switch (type) { |
| 59 switch (m_type) { | 92 case StartMarker: |
| 60 case Start: | 93 return narrowPrecisionToFloat(outslope); |
| 61 angle = outslope; | 94 case MidMarker: |
| 62 break; | 95 return narrowPrecisionToFloat((inslope + outslope) / 2); |
| 63 case Mid: | 96 case EndMarker: |
| 64 angle = (inslope + outslope) / 2; | 97 return narrowPrecisionToFloat(inslope); |
| 65 break; | |
| 66 case End: | |
| 67 angle = inslope; | |
| 68 break; | |
| 69 default: | |
| 70 ASSERT_NOT_REACHED(); | |
| 71 break; | |
| 72 } | 98 } |
| 73 | 99 |
| 74 return narrowPrecisionToFloat(angle); | 100 ASSERT_NOT_REACHED(); |
| 75 } | 101 return 0; |
| 76 | |
| 77 void updateTypeAndMarker(const Type& type, RenderSVGResourceMarker* marker) | |
| 78 { | |
| 79 m_type = type; | |
| 80 m_marker = marker; | |
| 81 } | 102 } |
| 82 | 103 |
| 83 void updateOutslope(const FloatPoint& point) | 104 void updateOutslope(const FloatPoint& point) |
| 84 { | 105 { |
| 85 m_outslopePoints[0] = m_origin; | 106 m_outslopePoints[0] = m_origin; |
| 86 m_outslopePoints[1] = point; | 107 m_outslopePoints[1] = point; |
| 87 } | 108 } |
| 88 | 109 |
| 89 void updateMarkerDataForPathElement(const PathElement* element) | 110 void updateMarkerDataForPathElement(const PathElement* element) |
| 90 { | 111 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 106 updateInslope(points[0]); | 127 updateInslope(points[0]); |
| 107 m_origin = points[0]; | 128 m_origin = points[0]; |
| 108 break; | 129 break; |
| 109 case PathElementCloseSubpath: | 130 case PathElementCloseSubpath: |
| 110 updateInslope(points[0]); | 131 updateInslope(points[0]); |
| 111 m_origin = m_subpathStart; | 132 m_origin = m_subpathStart; |
| 112 m_subpathStart = FloatPoint(); | 133 m_subpathStart = FloatPoint(); |
| 113 } | 134 } |
| 114 } | 135 } |
| 115 | 136 |
| 116 private: | |
| 117 void updateInslope(const FloatPoint& point) | 137 void updateInslope(const FloatPoint& point) |
| 118 { | 138 { |
| 119 m_inslopePoints[0] = m_origin; | 139 m_inslopePoints[0] = m_origin; |
| 120 m_inslopePoints[1] = point; | 140 m_inslopePoints[1] = point; |
| 121 } | 141 } |
| 122 | 142 |
| 123 Type m_type; | 143 Vector<MarkerPosition>& m_positions; |
| 124 RenderSVGResourceMarker* m_marker; | 144 unsigned m_elementIndex; |
| 125 FloatPoint m_origin; | 145 FloatPoint m_origin; |
| 126 FloatPoint m_subpathStart; | 146 FloatPoint m_subpathStart; |
| 127 FloatPoint m_inslopePoints[2]; | 147 FloatPoint m_inslopePoints[2]; |
| 128 FloatPoint m_outslopePoints[2]; | 148 FloatPoint m_outslopePoints[2]; |
| 129 }; | 149 }; |
| 130 | 150 |
| 131 } | 151 } |
| 132 | 152 |
| 133 #endif // ENABLE(SVG) | 153 #endif // ENABLE(SVG) |
| 134 #endif // SVGMarkerData_h | 154 #endif // SVGMarkerData_h |
| OLD | NEW |