[Libreoffice-commits] .: 2 commits - src/conv src/lib

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Mar 22 04:30:38 PDT 2013


 src/conv/raw/vsd2raw.cpp        |  183 ++++++++++++++++++++++++++++++++++------
 src/conv/raw/vss2raw.cpp        |  183 ++++++++++++++++++++++++++++++++++------
 src/lib/VSDContentCollector.cpp |   74 +++++++++-------
 src/lib/VSDContentCollector.h   |    1 
 4 files changed, 357 insertions(+), 84 deletions(-)

New commits:
commit 6b27d3cc5974edd2b65c33fd11c11a9a6ee692a3
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Fri Mar 22 12:30:13 2013 +0100

    Option to test the callback graph, in order to detect mismatched grouping

diff --git a/src/conv/raw/vsd2raw.cpp b/src/conv/raw/vsd2raw.cpp
index e79e343..dbc2ccc 100644
--- a/src/conv/raw/vsd2raw.cpp
+++ b/src/conv/raw/vsd2raw.cpp
@@ -29,16 +29,55 @@
  */
 
 #include <stdio.h>
+#include <stdarg.h>
 #include <string.h>
+#include <stack>
 
 #include "libvisio.h"
 #include <libwpd-stream/libwpd-stream.h>
 #include <libwpd/libwpd.h>
 
+enum PainterCallback
+{
+  PC_START_GRAPHICS = 0,
+  PC_START_LAYER,
+  PC_START_EMBEDDED_GRAPHICS,
+  PC_START_TEXT_OBJECT,
+  PC_START_TEXT_LINE,
+  PC_START_TEXT_SPAN
+};
+
+#ifdef _U
+#undef _U
+#endif
+
+#define _U(M, L) \
+	if (!m_printCallgraphScore) \
+			__iuprintf M; \
+	else \
+		m_callStack.push(L);
+
+#ifdef _D
+#undef _D
+#endif
+
+#define _D(M, L) \
+	if (!m_printCallgraphScore) \
+			__idprintf M; \
+	else \
+	{ \
+		PainterCallback lc = m_callStack.top(); \
+		if (lc != L) \
+			m_callbackMisses++; \
+		m_callStack.pop(); \
+	}
+
 class RawPainter : public libwpg::WPGPaintInterface
 {
 public:
-  RawPainter();
+  RawPainter(bool printCallgraphScore);
+
+  ~RawPainter();
 
   void startGraphics(const ::WPXPropertyList &propList);
   void endGraphics();
@@ -62,6 +101,25 @@ public:
   void startTextSpan(const ::WPXPropertyList &propList);
   void endTextSpan();
   void insertText(const ::WPXString &str);
+
+private:
+  int m_indent;
+  int m_callbackMisses;
+  bool m_printCallgraphScore;
+  std::stack<PainterCallback> m_callStack;
+
+  void __indentUp()
+  {
+    m_indent++;
+  }
+  void __indentDown()
+  {
+    if (m_indent > 0) m_indent--;
+  }
+
+  void __iprintf(const char *format, ...);
+  void __iuprintf(const char *format, ...);
+  void __idprintf(const char *format, ...);
 };
 
 WPXString getPropString(const WPXPropertyList &propList)
@@ -111,108 +169,177 @@ WPXString getPropString(const WPXPropertyListVector &itemList)
   return propString;
 }
 
-RawPainter::RawPainter(): libwpg::WPGPaintInterface()
+RawPainter::RawPainter(bool printCallgraphScore):
+  libwpg::WPGPaintInterface(),
+  m_indent(0),
+  m_callbackMisses(0),
+  m_printCallgraphScore(printCallgraphScore),
+  m_callStack()
+{
+}
+
+RawPainter::~RawPainter()
+{
+  if (m_printCallgraphScore)
+    printf("%d\n", (int)(m_callStack.size() + m_callbackMisses));
+}
+
+void RawPainter::__iprintf(const char *format, ...)
 {
+  if (m_printCallgraphScore) return;
+
+  va_list args;
+  va_start(args, format);
+  for (int i=0; i<m_indent; i++)
+    printf("  ");
+  vprintf(format, args);
+  va_end(args);
+}
+
+void RawPainter::__iuprintf(const char *format, ...)
+{
+  va_list args;
+  va_start(args, format);
+  for (int i=0; i<m_indent; i++)
+    printf("  ");
+  vprintf(format, args);
+  __indentUp();
+  va_end(args);
+}
+
+void RawPainter::__idprintf(const char *format, ...)
+{
+  va_list args;
+  va_start(args, format);
+  __indentDown();
+  for (int i=0; i<m_indent; i++)
+    printf("  ");
+  vprintf(format, args);
+  va_end(args);
 }
 
 void RawPainter::startGraphics(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::startGraphics(%s)\n", getPropString(propList).cstr());
+  _U(("RawPainter::startGraphics(%s)\n", getPropString(propList).cstr()), PC_START_GRAPHICS);
 }
 
 void RawPainter::endGraphics()
 {
-  printf("RawPainter::endGraphics\n");
+  _D(("RawPainter::endGraphics\n"), PC_START_GRAPHICS);
 }
 
 void RawPainter::startLayer(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::startLayer (%s)\n", getPropString(propList).cstr());
+  _U(("RawPainter::startLayer (%s)\n", getPropString(propList).cstr()), PC_START_LAYER);
 }
 
 void RawPainter::endLayer()
 {
-  printf("RawPainter::endLayer\n");
+  _D(("RawPainter::endLayer\n"), PC_START_LAYER);
 }
 
 void RawPainter::startEmbeddedGraphics(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::startEmbeddedGraphics (%s)\n", getPropString(propList).cstr());
+  _U(("RawPainter::startEmbeddedGraphics (%s)\n", getPropString(propList).cstr()), PC_START_EMBEDDED_GRAPHICS);
 }
 
 void RawPainter::endEmbeddedGraphics()
 {
-  printf("RawPainter::endEmbeddedGraphics \n");
+  _D(("RawPainter::endEmbeddedGraphics \n"), PC_START_EMBEDDED_GRAPHICS);
 }
 
 void RawPainter::setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &gradient)
 {
-  printf("RawPainter::setStyle(%s, gradient: (%s))\n", getPropString(propList).cstr(), getPropString(gradient).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::setStyle(%s, gradient: (%s))\n", getPropString(propList).cstr(), getPropString(gradient).cstr());
 }
 
 void RawPainter::drawRectangle(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::drawRectangle (%s)\n", getPropString(propList).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::drawRectangle (%s)\n", getPropString(propList).cstr());
 }
 
 void RawPainter::drawEllipse(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::drawEllipse (%s)\n", getPropString(propList).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::drawEllipse (%s)\n", getPropString(propList).cstr());
 }
 
 void RawPainter::drawPolyline(const ::WPXPropertyListVector &vertices)
 {
-  printf("RawPainter::drawPolyline (%s)\n", getPropString(vertices).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::drawPolyline (%s)\n", getPropString(vertices).cstr());
 }
 
 void RawPainter::drawPolygon(const ::WPXPropertyListVector &vertices)
 {
-  printf("RawPainter::drawPolygon (%s)\n", getPropString(vertices).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::drawPolygon (%s)\n", getPropString(vertices).cstr());
 }
 
 void RawPainter::drawPath(const ::WPXPropertyListVector &path)
 {
-  printf("RawPainter::drawPath (%s)\n", getPropString(path).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::drawPath (%s)\n", getPropString(path).cstr());
 }
 
 void RawPainter::drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData & /*binaryData*/)
 {
-  printf("RawPainter::drawGraphicObject (%s)\n", getPropString(propList).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::drawGraphicObject (%s)\n", getPropString(propList).cstr());
 }
 
 void RawPainter::startTextObject(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &path)
 {
-  printf("RawPainter::startTextObject (%s, path: (%s))\n", getPropString(propList).cstr(), getPropString(path).cstr());
+  _U(("RawPainter::startTextObject (%s, path: (%s))\n", getPropString(propList).cstr(), getPropString(path).cstr()), PC_START_TEXT_OBJECT);
 }
 
 void RawPainter::endTextObject()
 {
-  printf("RawPainter::endTextObject\n");
+  _D(("RawPainter::endTextObject\n"), PC_START_TEXT_OBJECT);
 }
 
 void RawPainter::startTextLine(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::startTextLine (%s)\n", getPropString(propList).cstr());
+  _U(("RawPainter::startTextLine (%s)\n", getPropString(propList).cstr()), PC_START_TEXT_LINE);
 }
 
 void RawPainter::endTextLine()
 {
-  printf("RawPainter::endTextLine\n");
+  _D(("RawPainter::endTextLine\n"), PC_START_TEXT_LINE);
 }
 
 void RawPainter::startTextSpan(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::startTextSpan (%s)\n", getPropString(propList).cstr());
+  _U(("RawPainter::startTextSpan (%s)\n", getPropString(propList).cstr()), PC_START_TEXT_SPAN);
 }
 
 void RawPainter::endTextSpan()
 {
-  printf("RawPainter::endTextSpan\n");
+  _D(("RawPainter::endTextSpan\n"), PC_START_TEXT_SPAN);
 }
 
 void RawPainter::insertText(const ::WPXString &str)
 {
-  printf("RawPainter::insertText (%s)\n", str.cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::insertText (%s)\n", str.cstr());
 }
 
 
@@ -224,6 +351,7 @@ int printUsage()
   printf("Usage: vsd2raw [OPTION] <Visio Document File>\n");
   printf("\n");
   printf("Options:\n");
+  printf("--callgraph           Display the call graph nesting level\n");
   printf("--help                Shows this help message\n");
   return -1;
 }
@@ -232,14 +360,17 @@ int printUsage()
 
 int main(int argc, char *argv[])
 {
+  bool printIndentLevel = false;
+  char *file = 0;
+
   if (argc < 2)
     return printUsage();
 
-  char *file = 0;
-
   for (int i = 1; i < argc; i++)
   {
-    if (!file && strncmp(argv[i], "--", 2))
+    if (!strcmp(argv[i], "--callgraph"))
+      printIndentLevel = true;
+    else if (!file && strncmp(argv[i], "--", 2))
       file = argv[i];
     else
       return printUsage();
@@ -256,7 +387,7 @@ int main(int argc, char *argv[])
     return 1;
   }
 
-  RawPainter painter;
+  RawPainter painter(printIndentLevel);
   if (!libvisio::VisioDocument::parse(&input, &painter))
   {
     fprintf(stderr, "ERROR: Parsing of document failed!\n");
diff --git a/src/conv/raw/vss2raw.cpp b/src/conv/raw/vss2raw.cpp
index 34f3a5a..58a7597 100644
--- a/src/conv/raw/vss2raw.cpp
+++ b/src/conv/raw/vss2raw.cpp
@@ -29,16 +29,55 @@
  */
 
 #include <stdio.h>
+#include <stdarg.h>
 #include <string.h>
+#include <stack>
 
 #include "libvisio.h"
 #include <libwpd-stream/libwpd-stream.h>
 #include <libwpd/libwpd.h>
 
+enum PainterCallback
+{
+  PC_START_GRAPHICS = 0,
+  PC_START_LAYER,
+  PC_START_EMBEDDED_GRAPHICS,
+  PC_START_TEXT_OBJECT,
+  PC_START_TEXT_LINE,
+  PC_START_TEXT_SPAN
+};
+
+#ifdef _U
+#undef _U
+#endif
+
+#define _U(M, L) \
+	if (!m_printCallgraphScore) \
+			__iuprintf M; \
+	else \
+		m_callStack.push(L);
+
+#ifdef _D
+#undef _D
+#endif
+
+#define _D(M, L) \
+	if (!m_printCallgraphScore) \
+			__idprintf M; \
+	else \
+	{ \
+		PainterCallback lc = m_callStack.top(); \
+		if (lc != L) \
+			m_callbackMisses++; \
+		m_callStack.pop(); \
+	}
+
 class RawPainter : public libwpg::WPGPaintInterface
 {
 public:
-  RawPainter();
+  RawPainter(bool printCallgraphScore);
+
+  ~RawPainter();
 
   void startGraphics(const ::WPXPropertyList &propList);
   void endGraphics();
@@ -62,6 +101,25 @@ public:
   void startTextSpan(const ::WPXPropertyList &propList);
   void endTextSpan();
   void insertText(const ::WPXString &str);
+
+private:
+  int m_indent;
+  int m_callbackMisses;
+  bool m_printCallgraphScore;
+  std::stack<PainterCallback> m_callStack;
+
+  void __indentUp()
+  {
+    m_indent++;
+  }
+  void __indentDown()
+  {
+    if (m_indent > 0) m_indent--;
+  }
+
+  void __iprintf(const char *format, ...);
+  void __iuprintf(const char *format, ...);
+  void __idprintf(const char *format, ...);
 };
 
 WPXString getPropString(const WPXPropertyList &propList)
@@ -111,108 +169,177 @@ WPXString getPropString(const WPXPropertyListVector &itemList)
   return propString;
 }
 
-RawPainter::RawPainter(): libwpg::WPGPaintInterface()
+RawPainter::RawPainter(bool printCallgraphScore):
+  libwpg::WPGPaintInterface(),
+  m_indent(0),
+  m_callbackMisses(0),
+  m_printCallgraphScore(printCallgraphScore),
+  m_callStack()
+{
+}
+
+RawPainter::~RawPainter()
+{
+  if (m_printCallgraphScore)
+    printf("%d\n", (int)(m_callStack.size() + m_callbackMisses));
+}
+
+void RawPainter::__iprintf(const char *format, ...)
 {
+  if (m_printCallgraphScore) return;
+
+  va_list args;
+  va_start(args, format);
+  for (int i=0; i<m_indent; i++)
+    printf("  ");
+  vprintf(format, args);
+  va_end(args);
+}
+
+void RawPainter::__iuprintf(const char *format, ...)
+{
+  va_list args;
+  va_start(args, format);
+  for (int i=0; i<m_indent; i++)
+    printf("  ");
+  vprintf(format, args);
+  __indentUp();
+  va_end(args);
+}
+
+void RawPainter::__idprintf(const char *format, ...)
+{
+  va_list args;
+  va_start(args, format);
+  __indentDown();
+  for (int i=0; i<m_indent; i++)
+    printf("  ");
+  vprintf(format, args);
+  va_end(args);
 }
 
 void RawPainter::startGraphics(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::startGraphics(%s)\n", getPropString(propList).cstr());
+  _U(("RawPainter::startGraphics(%s)\n", getPropString(propList).cstr()), PC_START_GRAPHICS);
 }
 
 void RawPainter::endGraphics()
 {
-  printf("RawPainter::endGraphics\n");
+  _D(("RawPainter::endGraphics\n"), PC_START_GRAPHICS);
 }
 
 void RawPainter::startLayer(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::startLayer (%s)\n", getPropString(propList).cstr());
+  _U(("RawPainter::startLayer (%s)\n", getPropString(propList).cstr()), PC_START_LAYER);
 }
 
 void RawPainter::endLayer()
 {
-  printf("RawPainter::endLayer\n");
+  _D(("RawPainter::endLayer\n"), PC_START_LAYER);
 }
 
 void RawPainter::startEmbeddedGraphics(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::startEmbeddedGraphics (%s)\n", getPropString(propList).cstr());
+  _U(("RawPainter::startEmbeddedGraphics (%s)\n", getPropString(propList).cstr()), PC_START_EMBEDDED_GRAPHICS);
 }
 
 void RawPainter::endEmbeddedGraphics()
 {
-  printf("RawPainter::endEmbeddedGraphics \n");
+  _D(("RawPainter::endEmbeddedGraphics \n"), PC_START_EMBEDDED_GRAPHICS);
 }
 
 void RawPainter::setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &gradient)
 {
-  printf("RawPainter::setStyle(%s, gradient: (%s))\n", getPropString(propList).cstr(), getPropString(gradient).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::setStyle(%s, gradient: (%s))\n", getPropString(propList).cstr(), getPropString(gradient).cstr());
 }
 
 void RawPainter::drawRectangle(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::drawRectangle (%s)\n", getPropString(propList).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::drawRectangle (%s)\n", getPropString(propList).cstr());
 }
 
 void RawPainter::drawEllipse(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::drawEllipse (%s)\n", getPropString(propList).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::drawEllipse (%s)\n", getPropString(propList).cstr());
 }
 
 void RawPainter::drawPolyline(const ::WPXPropertyListVector &vertices)
 {
-  printf("RawPainter::drawPolyline (%s)\n", getPropString(vertices).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::drawPolyline (%s)\n", getPropString(vertices).cstr());
 }
 
 void RawPainter::drawPolygon(const ::WPXPropertyListVector &vertices)
 {
-  printf("RawPainter::drawPolygon (%s)\n", getPropString(vertices).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::drawPolygon (%s)\n", getPropString(vertices).cstr());
 }
 
 void RawPainter::drawPath(const ::WPXPropertyListVector &path)
 {
-  printf("RawPainter::drawPath (%s)\n", getPropString(path).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::drawPath (%s)\n", getPropString(path).cstr());
 }
 
 void RawPainter::drawGraphicObject(const ::WPXPropertyList &propList, const ::WPXBinaryData & /*binaryData*/)
 {
-  printf("RawPainter::drawGraphicObject (%s)\n", getPropString(propList).cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::drawGraphicObject (%s)\n", getPropString(propList).cstr());
 }
 
 void RawPainter::startTextObject(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &path)
 {
-  printf("RawPainter::startTextObject (%s, path: (%s))\n", getPropString(propList).cstr(), getPropString(path).cstr());
+  _U(("RawPainter::startTextObject (%s, path: (%s))\n", getPropString(propList).cstr(), getPropString(path).cstr()), PC_START_TEXT_OBJECT);
 }
 
 void RawPainter::endTextObject()
 {
-  printf("RawPainter::endTextObject\n");
+  _D(("RawPainter::endTextObject\n"), PC_START_TEXT_OBJECT);
 }
 
 void RawPainter::startTextLine(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::startTextLine (%s)\n", getPropString(propList).cstr());
+  _U(("RawPainter::startTextLine (%s)\n", getPropString(propList).cstr()), PC_START_TEXT_LINE);
 }
 
 void RawPainter::endTextLine()
 {
-  printf("RawPainter::endTextLine\n");
+  _D(("RawPainter::endTextLine\n"), PC_START_TEXT_LINE);
 }
 
 void RawPainter::startTextSpan(const ::WPXPropertyList &propList)
 {
-  printf("RawPainter::startTextSpan (%s)\n", getPropString(propList).cstr());
+  _U(("RawPainter::startTextSpan (%s)\n", getPropString(propList).cstr()), PC_START_TEXT_SPAN);
 }
 
 void RawPainter::endTextSpan()
 {
-  printf("RawPainter::endTextSpan\n");
+  _D(("RawPainter::endTextSpan\n"), PC_START_TEXT_SPAN);
 }
 
 void RawPainter::insertText(const ::WPXString &str)
 {
-  printf("RawPainter::insertText (%s)\n", str.cstr());
+  if (m_printCallgraphScore)
+    return;
+
+  __iprintf("RawPainter::insertText (%s)\n", str.cstr());
 }
 
 
@@ -224,6 +351,7 @@ int printUsage()
   printf("Usage: vsd2raw [OPTION] <Visio Stencils File>\n");
   printf("\n");
   printf("Options:\n");
+  printf("--callgraph           Display the call graph nesting level\n");
   printf("--help                Shows this help message\n");
   return -1;
 }
@@ -232,14 +360,17 @@ int printUsage()
 
 int main(int argc, char *argv[])
 {
+  bool printIndentLevel = false;
+  char *file = 0;
+
   if (argc < 2)
     return printUsage();
 
-  char *file = 0;
-
   for (int i = 1; i < argc; i++)
   {
-    if (!file && strncmp(argv[i], "--", 2))
+    if (!strcmp(argv[i], "--callgraph"))
+      printIndentLevel = true;
+    else if (!file && strncmp(argv[i], "--", 2))
       file = argv[i];
     else
       return printUsage();
@@ -256,7 +387,7 @@ int main(int argc, char *argv[])
     return 1;
   }
 
-  RawPainter painter;
+  RawPainter painter(printIndentLevel);
   if (!libvisio::VisioDocument::parseStencils(&input, &painter))
   {
     fprintf(stderr, "ERROR: Parsing of document failed!\n");
commit 5e1f929695e31733bfcda766effc1a92168c447b
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Fri Mar 22 12:29:20 2013 +0100

    Group shape elements if they are more then one

diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp
index 14bc55d..82ca61f 100644
--- a/src/lib/VSDContentCollector.cpp
+++ b/src/lib/VSDContentCollector.cpp
@@ -239,6 +239,42 @@ double libvisio::VSDContentCollector::_linePropertiesMarkerScale(unsigned marker
   }
 }
 
+void libvisio::VSDContentCollector::_flushShape()
+{
+  unsigned numPathElements = 0;
+  unsigned numForeignElements = 0;
+  unsigned numTextElements = 0;
+  if (m_fillStyle.pattern && !m_currentFillGeometry.empty())
+    numPathElements++;
+  if (m_lineStyle.pattern && !m_currentLineGeometry.empty())
+    numPathElements++;
+  if (m_currentForeignData.size() && m_currentForeignProps["libwpg:mime-type"] && m_foreignWidth != 0.0 && m_foreignHeight != 0.0)
+    numForeignElements++;
+  if (m_textStream.size())
+    numTextElements++;
+
+  if (numPathElements+numForeignElements+numTextElements > 1)
+    m_shapeOutputDrawing->addStartLayer(WPXPropertyList());
+
+  if (numPathElements > 1 && (numForeignElements || numTextElements))
+    m_shapeOutputDrawing->addStartLayer(WPXPropertyList());
+  _flushCurrentPath();
+  if (numPathElements > 1 && (numForeignElements || numTextElements))
+    m_shapeOutputDrawing->addEndLayer();
+  _flushCurrentForeignData();
+  _flushText();
+
+  if (numPathElements+numForeignElements+numTextElements > 1)
+  {
+    if (numTextElements)
+      m_shapeOutputText->addEndLayer();
+    else
+      m_shapeOutputDrawing->addEndLayer();
+  }
+
+  m_isShapeStarted = false;
+}
+
 void libvisio::VSDContentCollector::_flushCurrentPath()
 {
   WPXPropertyList styleProps;
@@ -248,22 +284,9 @@ void libvisio::VSDContentCollector::_flushCurrentPath()
   fillPathProps.insert("draw:stroke", "none");
   WPXPropertyList linePathProps(styleProps);
   linePathProps.insert("draw:fill", "none");
-  bool needsGroup = true;
-
-  if (!m_fillStyle.pattern)
-    needsGroup = false;
-  if (m_currentFillGeometry.empty())
-    needsGroup = false;
-  if (!m_lineStyle.pattern)
-    needsGroup = false;
-  if (m_currentLineGeometry.empty())
-    needsGroup = false;
-
-  if (needsGroup)
-    m_shapeOutputDrawing->addStartLayer(WPXPropertyList());
 
   std::vector<WPXPropertyList> tmpPath;
-  if (m_fillStyle.pattern)
+  if (m_fillStyle.pattern && !m_currentFillGeometry.empty())
   {
     bool firstPoint = true;
     bool wasMove = false;
@@ -324,7 +347,7 @@ void libvisio::VSDContentCollector::_flushCurrentPath()
   m_currentFillGeometry.clear();
   tmpPath.clear();
 
-  if (m_lineStyle.pattern)
+  if (m_lineStyle.pattern && !m_currentLineGeometry.empty())
   {
     bool firstPoint = true;
     bool wasMove = false;
@@ -403,9 +426,6 @@ void libvisio::VSDContentCollector::_flushCurrentPath()
     }
   }
   m_currentLineGeometry.clear();
-
-  if (needsGroup)
-    m_shapeOutputDrawing->addEndLayer();
 }
 
 void libvisio::VSDContentCollector::_flushText()
@@ -668,6 +688,7 @@ void libvisio::VSDContentCollector::_flushText()
   }
 
   m_shapeOutputText->addEndTextObject();
+  m_textStream.clear();
 }
 
 void libvisio::VSDContentCollector::_flushCurrentForeignData()
@@ -2492,7 +2513,7 @@ void libvisio::VSDContentCollector::_handleLevelChange(unsigned level)
   {
     if (m_isShapeStarted)
     {
-      if (m_stencilShape != 0 && !m_isStencilStarted)
+      if (m_stencilShape && !m_isStencilStarted)
       {
         m_isStencilStarted = true;
         m_NURBSData = m_stencilShape->m_nurbsData;
@@ -2510,12 +2531,7 @@ void libvisio::VSDContentCollector::_handleLevelChange(unsigned level)
         }
         m_isStencilStarted = false;
       }
-
-      _flushCurrentPath();
-      _flushCurrentForeignData();
-      if (m_textStream.size())
-        _flushText();
-      m_isShapeStarted = false;
+      _flushShape();
     }
     m_originalX = 0.0;
     m_originalY = 0.0;
@@ -2535,13 +2551,7 @@ void libvisio::VSDContentCollector::_handleLevelChange(unsigned level)
 void libvisio::VSDContentCollector::startPage(unsigned pageId)
 {
   if (m_isShapeStarted)
-  {
-    _flushCurrentPath();
-    _flushCurrentForeignData();
-    m_isShapeStarted = false;
-    if (m_textStream.size())
-      _flushText();
-  }
+    _flushShape();
   m_originalX = 0.0;
   m_originalY = 0.0;
   if (m_txtxform)
diff --git a/src/lib/VSDContentCollector.h b/src/lib/VSDContentCollector.h
index 25ec85b..6fead68 100644
--- a/src/lib/VSDContentCollector.h
+++ b/src/lib/VSDContentCollector.h
@@ -195,6 +195,7 @@ private:
 
   double _NURBSBasis(unsigned knot, unsigned degree, double point, const std::vector<double> &knotVector);
 
+  void _flushShape();
   void _flushCurrentPath();
   void _flushText();
   void _flushCurrentForeignData();


More information about the Libreoffice-commits mailing list