| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. | 2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above | 8 * 1. Redistributions of source code must retain the above |
| 9 * copyright notice, this list of conditions and the following | 9 * copyright notice, this list of conditions and the following |
| 10 * disclaimer. | 10 * disclaimer. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 27 * OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #include "config.h" | 30 #include "config.h" |
| 31 #include "ExclusionPolygon.h" | 31 #include "ExclusionPolygon.h" |
| 32 #include "LayoutPoint.h" |
| 32 | 33 |
| 33 #include <wtf/MathExtras.h> | 34 #include <wtf/MathExtras.h> |
| 34 | 35 |
| 35 namespace WebCore { | 36 namespace WebCore { |
| 36 | 37 |
| 37 enum EdgeIntersectionType { | 38 enum EdgeIntersectionType { |
| 38 Normal, | 39 Normal, |
| 39 VertexMinY, | 40 VertexMinY, |
| 40 VertexMaxY, | 41 VertexMaxY, |
| 41 VertexYBoth | 42 VertexYBoth |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 float angle5 = ((padding) ? -angle : twoPI - angle) / arcSegmentCount; | 123 float angle5 = ((padding) ? -angle : twoPI - angle) / arcSegmentCount; |
| 123 | 124 |
| 124 vertices.append(startArcVertex); | 125 vertices.append(startArcVertex); |
| 125 for (unsigned i = 1; i < arcSegmentCount; ++i) { | 126 for (unsigned i = 1; i < arcSegmentCount; ++i) { |
| 126 float angle = startAngle + angle5 * i; | 127 float angle = startAngle + angle5 * i; |
| 127 vertices.append(arcCenter + FloatPoint(cos(angle) * arcRadius, sin(angle
) * arcRadius)); | 128 vertices.append(arcCenter + FloatPoint(cos(angle) * arcRadius, sin(angle
) * arcRadius)); |
| 128 } | 129 } |
| 129 vertices.append(endArcVertex); | 130 vertices.append(endArcVertex); |
| 130 } | 131 } |
| 131 | 132 |
| 133 static inline void snapVerticesToLayoutUnitGrid(Vector<FloatPoint>& vertices) |
| 134 { |
| 135 for (unsigned i = 0; i < vertices.size(); ++i) |
| 136 vertices[i] = flooredLayoutPoint(vertices[i]); |
| 137 } |
| 138 |
| 132 static inline FloatPolygon* computeShapePaddingBounds(const FloatPolygon& polygo
n, float padding, WindRule fillRule) | 139 static inline FloatPolygon* computeShapePaddingBounds(const FloatPolygon& polygo
n, float padding, WindRule fillRule) |
| 133 { | 140 { |
| 134 Vector<FloatPoint>* paddedVertices = new Vector<FloatPoint>(); | 141 Vector<FloatPoint>* paddedVertices = new Vector<FloatPoint>(); |
| 135 FloatPoint intersection; | 142 FloatPoint intersection; |
| 136 | 143 |
| 137 for (unsigned i = 0; i < polygon.numberOfEdges(); ++i) { | 144 for (unsigned i = 0; i < polygon.numberOfEdges(); ++i) { |
| 138 const FloatPolygonEdge& thisEdge = polygon.edgeAt(i); | 145 const FloatPolygonEdge& thisEdge = polygon.edgeAt(i); |
| 139 const FloatPolygonEdge& prevEdge = thisEdge.previousEdge(); | 146 const FloatPolygonEdge& prevEdge = thisEdge.previousEdge(); |
| 140 OffsetPolygonEdge thisOffsetEdge(thisEdge, inwardEdgeNormal(thisEdge) *
padding); | 147 OffsetPolygonEdge thisOffsetEdge(thisEdge, inwardEdgeNormal(thisEdge) *
padding); |
| 141 OffsetPolygonEdge prevOffsetEdge(prevEdge, inwardEdgeNormal(prevEdge) *
padding); | 148 OffsetPolygonEdge prevOffsetEdge(prevEdge, inwardEdgeNormal(prevEdge) *
padding); |
| 142 | 149 |
| 143 if (prevOffsetEdge.intersection(thisOffsetEdge, intersection)) | 150 if (prevOffsetEdge.intersection(thisOffsetEdge, intersection)) |
| 144 paddedVertices->append(intersection); | 151 paddedVertices->append(intersection); |
| 145 else if (isReflexVertex(prevEdge.vertex1(), thisEdge.vertex1(), thisEdge
.vertex2())) | 152 else if (isReflexVertex(prevEdge.vertex1(), thisEdge.vertex1(), thisEdge
.vertex2())) |
| 146 appendArc(*paddedVertices, thisEdge.vertex1(), padding, prevOffsetEd
ge.vertex2(), thisOffsetEdge.vertex1(), true); | 153 appendArc(*paddedVertices, thisEdge.vertex1(), padding, prevOffsetEd
ge.vertex2(), thisOffsetEdge.vertex1(), true); |
| 147 } | 154 } |
| 148 | 155 |
| 156 snapVerticesToLayoutUnitGrid(*paddedVertices); |
| 149 return new FloatPolygon(adoptPtr(paddedVertices), fillRule); | 157 return new FloatPolygon(adoptPtr(paddedVertices), fillRule); |
| 150 } | 158 } |
| 151 | 159 |
| 152 static inline FloatPolygon* computeShapeMarginBounds(const FloatPolygon& polygon
, float margin, WindRule fillRule) | 160 static inline FloatPolygon* computeShapeMarginBounds(const FloatPolygon& polygon
, float margin, WindRule fillRule) |
| 153 { | 161 { |
| 154 Vector<FloatPoint>* marginVertices = new Vector<FloatPoint>(); | 162 Vector<FloatPoint>* marginVertices = new Vector<FloatPoint>(); |
| 155 FloatPoint intersection; | 163 FloatPoint intersection; |
| 156 | 164 |
| 157 for (unsigned i = 0; i < polygon.numberOfEdges(); ++i) { | 165 for (unsigned i = 0; i < polygon.numberOfEdges(); ++i) { |
| 158 const FloatPolygonEdge& thisEdge = polygon.edgeAt(i); | 166 const FloatPolygonEdge& thisEdge = polygon.edgeAt(i); |
| 159 const FloatPolygonEdge& prevEdge = thisEdge.previousEdge(); | 167 const FloatPolygonEdge& prevEdge = thisEdge.previousEdge(); |
| 160 OffsetPolygonEdge thisOffsetEdge(thisEdge, outwardEdgeNormal(thisEdge) *
margin); | 168 OffsetPolygonEdge thisOffsetEdge(thisEdge, outwardEdgeNormal(thisEdge) *
margin); |
| 161 OffsetPolygonEdge prevOffsetEdge(prevEdge, outwardEdgeNormal(prevEdge) *
margin); | 169 OffsetPolygonEdge prevOffsetEdge(prevEdge, outwardEdgeNormal(prevEdge) *
margin); |
| 162 | 170 |
| 163 if (prevOffsetEdge.intersection(thisOffsetEdge, intersection)) | 171 if (prevOffsetEdge.intersection(thisOffsetEdge, intersection)) |
| 164 marginVertices->append(intersection); | 172 marginVertices->append(intersection); |
| 165 else | 173 else |
| 166 appendArc(*marginVertices, thisEdge.vertex1(), margin, prevOffsetEdg
e.vertex2(), thisOffsetEdge.vertex1(), false); | 174 appendArc(*marginVertices, thisEdge.vertex1(), margin, prevOffsetEdg
e.vertex2(), thisOffsetEdge.vertex1(), false); |
| 167 } | 175 } |
| 168 | 176 |
| 177 snapVerticesToLayoutUnitGrid(*marginVertices); |
| 169 return new FloatPolygon(adoptPtr(marginVertices), fillRule); | 178 return new FloatPolygon(adoptPtr(marginVertices), fillRule); |
| 170 } | 179 } |
| 171 | 180 |
| 172 const FloatPolygon& ExclusionPolygon::shapePaddingBounds() const | 181 const FloatPolygon& ExclusionPolygon::shapePaddingBounds() const |
| 173 { | 182 { |
| 174 ASSERT(shapePadding() >= 0); | 183 ASSERT(shapePadding() >= 0); |
| 175 if (!shapePadding()) | 184 if (!shapePadding()) |
| 176 return m_polygon; | 185 return m_polygon; |
| 177 | 186 |
| 178 if (!m_paddingBounds) | 187 if (!m_paddingBounds) |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 } | 498 } |
| 490 } | 499 } |
| 491 } | 500 } |
| 492 | 501 |
| 493 if (firstFitFound) | 502 if (firstFitFound) |
| 494 result = firstFitRect.y(); | 503 result = firstFitRect.y(); |
| 495 return firstFitFound; | 504 return firstFitFound; |
| 496 } | 505 } |
| 497 | 506 |
| 498 } // namespace WebCore | 507 } // namespace WebCore |
| OLD | NEW |