WebCore/platform/graphics/qt/PathQt.cpp
changeset 2 303757a437d3
parent 0 4f2f89ce4247
--- a/WebCore/platform/graphics/qt/PathQt.cpp	Fri Sep 17 09:02:29 2010 +0300
+++ b/WebCore/platform/graphics/qt/PathQt.cpp	Mon Oct 04 01:32:07 2010 +0300
@@ -51,6 +51,7 @@
 namespace WebCore {
 
 Path::Path()
+    : m_lastMoveToIndex(0)
 {
 }
 
@@ -60,12 +61,14 @@
 
 Path::Path(const Path& other)
     : m_path(other.m_path)
+    , m_lastMoveToIndex(other.m_lastMoveToIndex)
 {
 }
 
 Path& Path::operator=(const Path& other)
 {
     m_path = other.m_path;
+    m_lastMoveToIndex = other.m_lastMoveToIndex;
     return *this;
 }
 
@@ -180,6 +183,7 @@
 
 void Path::moveTo(const FloatPoint& point)
 {
+    m_lastMoveToIndex = m_path.elementCount();
     m_path.moveTo(point);
 }
 
@@ -260,7 +264,26 @@
 
 void Path::closeSubpath()
 {
-    m_path.closeSubpath();
+    const int elementCount = m_path.elementCount();
+
+    if (!elementCount)
+        return;
+
+    QPointF lastMoveToPoint = m_path.elementAt(m_lastMoveToIndex);
+    int elementsInLastSubpath = 0;
+
+    for (int i = m_lastMoveToIndex; i < elementCount; ++i) {
+        QPainterPath::Element element = m_path.elementAt(i);
+        if (element.isLineTo() || element.isCurveTo()) {
+            // All we need to know is if there are 1 or more elements in the last subpath.
+            if (++elementsInLastSubpath == 2) {
+                m_path.lineTo(lastMoveToPoint);
+                return;
+            }
+        }
+    }
+
+    moveTo(lastMoveToPoint);
 }
 
 #define DEGREES(t) ((t) * 180.0 / M_PI)
@@ -440,7 +463,7 @@
     // QTransform.map doesn't handle the MoveTo element because of the isEmpty issue
     if (m_path.isEmpty() && m_path.elementCount()) {
         QPointF point = qTransform.map(m_path.currentPosition());
-        m_path.moveTo(point);
+        moveTo(point);
     } else 
 #endif
         m_path = qTransform.map(m_path);