Title: [133682] trunk
Revision
133682
Author
commit-qu...@webkit.org
Date
2012-11-06 15:47:04 -0800 (Tue, 06 Nov 2012)

Log Message

[CSS Exclusions] Store ExclusionPolygonEdge vertices in clockwise order
https://bugs.webkit.org/show_bug.cgi?id=100763

Patch by Hans Muller <hmul...@adobe.com> on 2012-11-06
Reviewed by Darin Adler.

Source/WebCore:

The ExclusionPolygon's internal logic, notably getVertexIntersectionVertices(),
assumes that ExclusionPolygonEdge vertices are stored in clockwise order.
If this is not true, then we construct the polygon's edges in reverse.

To determine if the vertices are in clockwise order, we compare the slope
of the line between the top,left vertex and its previous vertex, with the
the slope of the line of vertices before and after the top,left vertex.
If the slope of the latter is greater, then top,left vertex is located
to its left, and the vertices are clockwise.

Test: fast/exclusions/shape-inside/shape-inside-counterclockwise-polygon.html

* rendering/ExclusionPolygon.cpp:
(WebCore::determinant): Used to decide if the min vertex is on the left side of the line that passes through its adjacent vertices.
(WebCore::ExclusionPolygon::ExclusionPolygon): If the polygon's vertices are specified in counterclockwise order, construct the edges in reverse.
(WebCore::appendIntervalX): Made this an inline since it was only defined as a function for the sake of clarity.

LayoutTests:

Verify that a shape-inside polygon whose vertices are specified in counterclockwise
order is handled correctly.

* fast/exclusions/shape-inside/shape-inside-counterclockwise-polygon-expected.html: Added.
* fast/exclusions/shape-inside/shape-inside-counterclockwise-polygon.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (133681 => 133682)


--- trunk/LayoutTests/ChangeLog	2012-11-06 23:44:28 UTC (rev 133681)
+++ trunk/LayoutTests/ChangeLog	2012-11-06 23:47:04 UTC (rev 133682)
@@ -1,3 +1,16 @@
+2012-11-06  Hans Muller  <hmul...@adobe.com>
+
+        [CSS Exclusions] Store ExclusionPolygonEdge vertices in clockwise order
+        https://bugs.webkit.org/show_bug.cgi?id=100763
+
+        Reviewed by Darin Adler.
+
+        Verify that a shape-inside polygon whose vertices are specified in counterclockwise
+        order is handled correctly.
+
+        * fast/exclusions/shape-inside/shape-inside-counterclockwise-polygon-expected.html: Added.
+        * fast/exclusions/shape-inside/shape-inside-counterclockwise-polygon.html: Added.
+
 2012-11-06  Dirk Pranke  <dpra...@chromium.org>
 
         Unreviewed, remove a couple of passing tests from chromium expectations.

Added: trunk/LayoutTests/fast/exclusions/shape-inside/shape-inside-counterclockwise-polygon-expected.html (0 => 133682)


--- trunk/LayoutTests/fast/exclusions/shape-inside/shape-inside-counterclockwise-polygon-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/exclusions/shape-inside/shape-inside-counterclockwise-polygon-expected.html	2012-11-06 23:47:04 UTC (rev 133682)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+    if (window.internals)
+        window.internals.settings.setCSSExclusionsEnabled(true);
+
+    // Rectilinear polygon with this shape (same as shape-inside-rectilinear-polygon-002.html).
+    // The vertices are specified in counter-clockwise order.
+    //   XXX
+    // XXXXXXX
+    // XXXXXXX
+    //   XXX
+    
+    var vertices = [{x:0, y:150}, {x:100, y:150}, {x:100, y:200}, {x:250, y:200}, {x:250, y:150}, {x:350, y:150}, {x:350, y:50}, {x:250, y:50}, {x:250, y:0}, {x:100, y:0}, {x:100, y:50}, {x:0, y:50}];
+    var lineHeight = 50;
+    var hasSubpixelSupport = false; // This test doesn't depend on subpixel layout.
+</script>
+
+<style id="stylesheet">
+    #polygon-shape-inside, #polygon-svg-shape {
+        position: absolute;
+        left: 0px;
+        top: 0px;
+    }
+</style>
+</head>
+
+<body id="body" _onload_="createPolygonShapeInsideTestCaseExpected(vertices)">
+    <svg id="polygon-svg-shape" xmlns="http://www.w3.org/2000/svg"></svg>
+    <div id="polygon-shape-inside"></div>
+    <p id="informative-text">
+        This test requires the Ahem font. It creates a polygonal shape-inside and a matching
+        filled SVG polygon. The content should just fill the shape, with alternating black and
+        empty rectangles on each line.</p>
+</body>
+
+</html>

Added: trunk/LayoutTests/fast/exclusions/shape-inside/shape-inside-counterclockwise-polygon.html (0 => 133682)


--- trunk/LayoutTests/fast/exclusions/shape-inside/shape-inside-counterclockwise-polygon.html	                        (rev 0)
+++ trunk/LayoutTests/fast/exclusions/shape-inside/shape-inside-counterclockwise-polygon.html	2012-11-06 23:47:04 UTC (rev 133682)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+    if (window.internals)
+        window.internals.settings.setCSSExclusionsEnabled(true);
+
+    // Rectilinear polygon with this shape (same as shape-inside-rectilinear-polygon-002.html).
+    // The vertices are specified in counter-clockwise order.
+    //   XXX
+    // XXXXXXX
+    // XXXXXXX
+    //   XXX
+    
+    var vertices = [{x:0, y:150}, {x:100, y:150}, {x:100, y:200}, {x:250, y:200}, {x:250, y:150}, {x:350, y:150}, {x:350, y:50}, {x:250, y:50}, {x:250, y:0}, {x:100, y:0}, {x:100, y:50}, {x:0, y:50}];
+    var lineHeight = 50;
+    var hasSubpixelSupport = false; // This test doesn't depend on subpixel layout.
+</script>
+
+<style id="stylesheet">
+    #polygon-shape-inside, #polygon-svg-shape {
+        position: absolute;
+        left: 0px;
+        top: 0px;
+    }
+</style>
+</head>
+
+<body id="body" _onload_="createPolygonShapeInsideTestCase(vertices)">
+    <svg id="polygon-svg-shape" xmlns="http://www.w3.org/2000/svg"></svg>
+    <div id="polygon-shape-inside"></div>
+    <p id="informative-text">
+        This test requires the Ahem font. It creates a polygonal shape-inside and a matching
+        filled SVG polygon. The content should just fill the shape, with alternating black and
+        empty rectangles on each line.</p>
+</body>
+
+</html>

Modified: trunk/Source/WebCore/ChangeLog (133681 => 133682)


--- trunk/Source/WebCore/ChangeLog	2012-11-06 23:44:28 UTC (rev 133681)
+++ trunk/Source/WebCore/ChangeLog	2012-11-06 23:47:04 UTC (rev 133682)
@@ -1,3 +1,27 @@
+2012-11-06  Hans Muller  <hmul...@adobe.com>
+
+        [CSS Exclusions] Store ExclusionPolygonEdge vertices in clockwise order
+        https://bugs.webkit.org/show_bug.cgi?id=100763
+
+        Reviewed by Darin Adler.
+
+        The ExclusionPolygon's internal logic, notably getVertexIntersectionVertices(),
+        assumes that ExclusionPolygonEdge vertices are stored in clockwise order.
+        If this is not true, then we construct the polygon's edges in reverse.
+
+        To determine if the vertices are in clockwise order, we compare the slope
+        of the line between the top,left vertex and its previous vertex, with the
+        the slope of the line of vertices before and after the top,left vertex.
+        If the slope of the latter is greater, then top,left vertex is located
+        to its left, and the vertices are clockwise.
+
+        Test: fast/exclusions/shape-inside/shape-inside-counterclockwise-polygon.html
+
+        * rendering/ExclusionPolygon.cpp:
+        (WebCore::determinant): Used to decide if the min vertex is on the left side of the line that passes through its adjacent vertices.
+        (WebCore::ExclusionPolygon::ExclusionPolygon): If the polygon's vertices are specified in counterclockwise order, construct the edges in reverse.
+        (WebCore::appendIntervalX): Made this an inline since it was only defined as a function for the sake of clarity.
+
 2012-11-06  Tiancheng Jiang  <tiji...@rim.com>
 
         [BlackBerry] Update BB10 form theme.

Modified: trunk/Source/WebCore/rendering/ExclusionPolygon.cpp (133681 => 133682)


--- trunk/Source/WebCore/rendering/ExclusionPolygon.cpp	2012-11-06 23:44:28 UTC (rev 133681)
+++ trunk/Source/WebCore/rendering/ExclusionPolygon.cpp	2012-11-06 23:47:04 UTC (rev 133682)
@@ -71,12 +71,11 @@
 {
     unsigned nVertices = numberOfVertices();
     unsigned vertexIndex2 = nextVertexIndex(vertexIndex1, nVertices, clockwise);
-    unsigned lastVertexIndex = (clockwise) ? 0 : nVertices - 1;
 
-    while (vertexIndex2 != lastVertexIndex && areCoincidentPoints(vertexAt(vertexIndex1), vertexAt(vertexIndex2)))
+    while (vertexIndex2 && areCoincidentPoints(vertexAt(vertexIndex1), vertexAt(vertexIndex2)))
         vertexIndex2 = nextVertexIndex(vertexIndex2, nVertices, clockwise);
 
-    while (vertexIndex2 != lastVertexIndex) {
+    while (vertexIndex2) {
         unsigned vertexIndex3 = nextVertexIndex(vertexIndex2, nVertices, clockwise);
         if (!areCollinearPoints(vertexAt(vertexIndex1), vertexAt(vertexIndex2), vertexAt(vertexIndex3)))
             break;
@@ -101,11 +100,21 @@
     if (m_empty)
         return;
 
+    unsigned minVertexIndex = 0;
+    for (unsigned i = 1; i < nVertices; ++i) {
+        const FloatPoint& vertex = vertexAt(i);
+        if (vertex.y() < vertexAt(minVertexIndex).y() || (vertex.y() == vertexAt(minVertexIndex).y() && vertex.x() < vertexAt(minVertexIndex).x()))
+            minVertexIndex = i;
+    }
+    FloatPoint nextVertex = vertexAt((minVertexIndex + 1) % nVertices);
+    FloatPoint prevVertex = vertexAt((minVertexIndex + nVertices - 1) % nVertices);
+    bool clockwise = determinant(vertexAt(minVertexIndex) - prevVertex, nextVertex - prevVertex) > 0;
+
     unsigned edgeIndex = 0;
     unsigned vertexIndex1 = 0;
     do {
         m_boundingBox.extend(vertexAt(vertexIndex1));
-        unsigned vertexIndex2 = findNextEdgeVertexIndex(vertexIndex1, true);
+        unsigned vertexIndex2 = findNextEdgeVertexIndex(vertexIndex1, clockwise);
         m_edges[edgeIndex].polygon = this;
         m_edges[edgeIndex].vertexIndex1 = vertexIndex1;
         m_edges[edgeIndex].vertexIndex2 = vertexIndex2;
@@ -133,7 +142,6 @@
         ExclusionPolygonEdge* edge = &m_edges[i];
         m_edgeTree.add(EdgeInterval(edge->minY(), edge->maxY(), edge));
     }
-
 }
 
 static bool computeXIntersection(const ExclusionPolygonEdge* edgePointer, float y, EdgeIntersection& result)
@@ -194,7 +202,7 @@
     return true;
 }
 
-static bool appendIntervalX(float x, bool inside, Vector<ExclusionInterval>& result)
+static inline bool appendIntervalX(float x, bool inside, Vector<ExclusionInterval>& result)
 {
     if (!inside)
         result.append(ExclusionInterval(x));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to