[Libreoffice-commits] libvisio.git: src/lib

Fridrich Štrba fridrich.strba at bluewin.ch
Fri Dec 11 10:05:13 PST 2015


 src/lib/VSD6Parser.cpp          |   17 +++++++++++++++++
 src/lib/VSD6Parser.h            |    1 +
 src/lib/VSDCollector.h          |    1 +
 src/lib/VSDContentCollector.cpp |   33 ++++++++++++++++++++++++++++++++-
 src/lib/VSDContentCollector.h   |    3 ++-
 src/lib/VSDParser.cpp           |   22 ++++++++++++++++++++++
 src/lib/VSDParser.h             |    1 +
 src/lib/VSDStencils.cpp         |    7 +++++--
 src/lib/VSDStencils.h           |    1 +
 src/lib/VSDStylesCollector.cpp  |    5 +++++
 src/lib/VSDStylesCollector.h    |    1 +
 11 files changed, 88 insertions(+), 4 deletions(-)

New commits:
commit 63841a8aa1798a0cb012fbaed3acae11f54f3485
Author: Fridrich Štrba <fridrich.strba at bluewin.ch>
Date:   Fri Dec 11 19:00:52 2015 +0100

    Parsing layer membership for binary parsers
    
    Change-Id: Ieaecf3764d4f0dc2cf33a3f69f5b89ba7874ae2c

diff --git a/src/lib/VSD6Parser.cpp b/src/lib/VSD6Parser.cpp
index 9e845eb..a9e91fa 100644
--- a/src/lib/VSD6Parser.cpp
+++ b/src/lib/VSD6Parser.cpp
@@ -82,6 +82,23 @@ void libvisio::VSD6Parser::readText(librevenge::RVNGInputStream *input)
   }
 }
 
+void libvisio::VSD6Parser::readLayerMem(librevenge::RVNGInputStream *input)
+{
+  input->seek(13, librevenge::RVNG_SEEK_CUR);
+  unsigned textLength = readU8(input);
+
+  librevenge::RVNGBinaryData  textStream;
+  unsigned long numBytesRead = 0;
+  const unsigned char *tmpBuffer = input->read(textLength, numBytesRead);
+  if (numBytesRead)
+  {
+    textStream.append(tmpBuffer, numBytesRead);
+    m_shape.m_layerMem.m_data = textStream;
+    m_shape.m_layerMem.m_format = libvisio::VSD_TEXT_ANSI;
+  }
+
+}
+
 void libvisio::VSD6Parser::readCharIX(librevenge::RVNGInputStream *input)
 {
   unsigned charCount = readU32(input);
diff --git a/src/lib/VSD6Parser.h b/src/lib/VSD6Parser.h
index 7750441..ea7d072 100644
--- a/src/lib/VSD6Parser.h
+++ b/src/lib/VSD6Parser.h
@@ -34,6 +34,7 @@ private:
   virtual void readName(librevenge::RVNGInputStream *input);
   virtual void readName2(librevenge::RVNGInputStream *input);
   virtual void readTextField(librevenge::RVNGInputStream *input);
+  virtual void readLayerMem(librevenge::RVNGInputStream *input);
 
   VSD6Parser();
   VSD6Parser(const VSDParser &);
diff --git a/src/lib/VSDCollector.h b/src/lib/VSDCollector.h
index f118d14..35034f9 100644
--- a/src/lib/VSDCollector.h
+++ b/src/lib/VSDCollector.h
@@ -103,6 +103,7 @@ public:
   virtual void collectPageSheet(unsigned id, unsigned level) = 0;
   virtual void collectMisc(unsigned level, const VSDMisc &misc) = 0;
   virtual void collectLayer(unsigned id, unsigned level, const VSDLayer &layer) = 0;
+  virtual void collectLayerMem(unsigned level, const VSDName &layerMem) = 0;
 
   // Style collectors
   virtual void collectStyleSheet(unsigned id, unsigned level,unsigned parentLineStyle, unsigned parentFillStyle, unsigned parentTextStyle) = 0;
diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp
index 79e884a..48d483f 100644
--- a/src/lib/VSDContentCollector.cpp
+++ b/src/lib/VSDContentCollector.cpp
@@ -60,7 +60,7 @@ libvisio::VSDContentCollector::VSDContentCollector(
   m_backgroundPageID(MINUS_ONE), m_currentPageID(0), m_currentPage(), m_pages(), m_layerList(),
   m_splineControlPoints(), m_splineKnotVector(), m_splineX(0.0), m_splineY(0.0),
   m_splineLastKnot(0.0), m_splineDegree(0), m_splineLevel(0), m_currentShapeLevel(0),
-  m_isBackgroundPage(false), m_currentLayerList()
+  m_isBackgroundPage(false), m_currentLayerList(), m_currentLayerMem()
 {
 }
 
@@ -2974,6 +2974,37 @@ void libvisio::VSDContentCollector::collectMisc(unsigned level, const VSDMisc &m
   m_misc = misc;
 }
 
+void libvisio::VSDContentCollector::collectLayerMem(unsigned level, const VSDName &layerMem)
+{
+  using namespace ::boost::spirit::classic;
+
+  _handleLevelChange(level);
+  librevenge::RVNGString text;
+  std::vector<unsigned char> tmpData(layerMem.m_data.size());
+  memcpy(&tmpData[0], layerMem.m_data.getDataBuffer(), layerMem.m_data.size());
+  appendCharacters(text, tmpData, layerMem.m_format);
+
+  m_currentLayerMem.clear();
+
+  bool bRes = parse(text.cstr(),
+                    //  Begin grammar
+                    (
+                      // parse comma-delimited list of doubles (have to use the
+                      // 'direct' variant, as otherwise spirit refactors our
+                      // parser to push both real num and comma to push_back_a)
+                      list_p.direct
+                      (
+                        int_p[push_back_a(m_currentLayerMem)],
+                        ';'
+                      )
+                    ) >> end_p,
+                    //  End grammar
+                    space_p).full;
+
+  if (!bRes)
+    m_currentLayerMem.clear();
+}
+
 void libvisio::VSDContentCollector::collectLayer(unsigned id, unsigned level, const VSDLayer &layer)
 {
   _handleLevelChange(level);
diff --git a/src/lib/VSDContentCollector.h b/src/lib/VSDContentCollector.h
index fc60a40..02304b2 100644
--- a/src/lib/VSDContentCollector.h
+++ b/src/lib/VSDContentCollector.h
@@ -123,7 +123,7 @@ public:
   void collectPageSheet(unsigned id, unsigned level);
   void collectMisc(unsigned level, const VSDMisc &misc);
   void collectLayer(unsigned id, unsigned level, const VSDLayer &layer);
-
+  void collectLayerMem(unsigned level, const VSDName &layerMem);
 
   // Style collectors
   void collectStyleSheet(unsigned id, unsigned level, unsigned parentLineStyle, unsigned parentFillStyle, unsigned parentTextStyle);
@@ -305,6 +305,7 @@ private:
   bool m_isBackgroundPage;
 
   VSDLayerList m_currentLayerList;
+  std::vector<unsigned> m_currentLayerMem;
 };
 
 } // namespace libvisio
diff --git a/src/lib/VSDParser.cpp b/src/lib/VSDParser.cpp
index cbb8192..4ecf8d4 100644
--- a/src/lib/VSDParser.cpp
+++ b/src/lib/VSDParser.cpp
@@ -596,6 +596,9 @@ void libvisio::VSDParser::handleChunk(librevenge::RVNGInputStream *input)
   case VSD_LAYER:
     readLayer(input);
     break;
+  case VSD_LAYER_MEMBERSHIP:
+    readLayerMem(input);
+    break;
   default:
     m_collector->collectUnhandledChunk(m_header.id, m_header.level);
   }
@@ -612,6 +615,8 @@ void libvisio::VSDParser::_flushShape()
 
   m_collector->collectXFormData(m_currentShapeLevel+2, m_shape.m_xform);
 
+  m_collector->collectLayerMem(m_currentShapeLevel+2, m_shape.m_layerMem);
+
   m_collector->collectMisc(m_currentShapeLevel+2, m_shape.m_misc);
 
   if (m_shape.m_txtxform)
@@ -975,6 +980,23 @@ void libvisio::VSDParser::readLayer(librevenge::RVNGInputStream *input)
   m_collector->collectLayer(m_header.id, m_header.level, layer);
 }
 
+void libvisio::VSDParser::readLayerMem(librevenge::RVNGInputStream *input)
+{
+  input->seek(13, librevenge::RVNG_SEEK_CUR);
+  unsigned textLength = readU8(input);
+
+  librevenge::RVNGBinaryData  textStream;
+  unsigned long numBytesRead = 0;
+  const unsigned char *tmpBuffer = input->read(textLength*2, numBytesRead);
+  if (numBytesRead)
+  {
+    textStream.append(tmpBuffer, numBytesRead);
+    m_shape.m_layerMem.m_data = textStream;
+    m_shape.m_layerMem.m_format = libvisio::VSD_TEXT_UTF16;
+  }
+
+}
+
 void libvisio::VSDParser::readPage(librevenge::RVNGInputStream *input)
 {
   input->seek(8, librevenge::RVNG_SEEK_CUR); //sub header length and children list length
diff --git a/src/lib/VSDParser.h b/src/lib/VSDParser.h
index d43e52f..fbf167e 100644
--- a/src/lib/VSDParser.h
+++ b/src/lib/VSDParser.h
@@ -114,6 +114,7 @@ protected:
 
   virtual void readLayerList(librevenge::RVNGInputStream *input);
   virtual void readLayer(librevenge::RVNGInputStream *input);
+  virtual void readLayerMem(librevenge::RVNGInputStream *input);
 
   // parser of one pass
   bool parseDocument(librevenge::RVNGInputStream *input, unsigned shift);
diff --git a/src/lib/VSDStencils.cpp b/src/lib/VSDStencils.cpp
index 49a8300..099fcbf 100644
--- a/src/lib/VSDStencils.cpp
+++ b/src/lib/VSDStencils.cpp
@@ -16,7 +16,7 @@ libvisio::VSDShape::VSDShape()
     m_textStyleId(MINUS_ONE), m_lineStyle(), m_fillStyle(), m_textBlockStyle(), m_charStyle(),
     m_themeRef(), m_charList(), m_paraStyle(), m_paraList(), m_text(), m_names(),
     m_textFormat(libvisio::VSD_TEXT_UTF16), m_nurbsData(), m_polylineData(), m_xform(), m_txtxform(0),
-    m_xform1d(0), m_misc()
+    m_xform1d(0), m_misc(), m_layerMem()
 {
 }
 
@@ -30,7 +30,8 @@ libvisio::VSDShape::VSDShape(const libvisio::VSDShape &shape)
     m_paraStyle(shape.m_paraStyle), m_paraList(shape.m_paraList), m_text(shape.m_text), m_names(shape.m_names),
     m_textFormat(shape.m_textFormat), m_nurbsData(shape.m_nurbsData), m_polylineData(shape.m_polylineData),
     m_xform(shape.m_xform), m_txtxform(shape.m_txtxform ? new XForm(*(shape.m_txtxform)) : 0),
-    m_xform1d(shape.m_xform1d ? new XForm1D(*(shape.m_xform1d)) : 0), m_misc(shape.m_misc)
+    m_xform1d(shape.m_xform1d ? new XForm1D(*(shape.m_xform1d)) : 0), m_misc(shape.m_misc),
+    m_layerMem(shape.m_layerMem)
 {
 }
 
@@ -77,6 +78,7 @@ libvisio::VSDShape &libvisio::VSDShape::operator=(const libvisio::VSDShape &shap
       delete m_xform1d;
     m_xform1d = shape.m_xform1d ? new XForm1D(*(shape.m_xform1d)) : 0;
     m_misc = shape.m_misc;
+    m_layerMem = shape.m_layerMem;
   }
   return *this;
 }
@@ -118,6 +120,7 @@ void libvisio::VSDShape::clear()
   m_textStyleId = MINUS_ONE;
   m_textFormat = libvisio::VSD_TEXT_UTF16;
   m_misc = VSDMisc();
+  m_layerMem = VSDName();
 }
 
 libvisio::VSDStencil::VSDStencil()
diff --git a/src/lib/VSDStencils.h b/src/lib/VSDStencils.h
index 3d9a14c..c3596d5 100644
--- a/src/lib/VSDStencils.h
+++ b/src/lib/VSDStencils.h
@@ -55,6 +55,7 @@ public:
   XForm *m_txtxform;
   XForm1D *m_xform1d;
   VSDMisc m_misc;
+  VSDName m_layerMem;
 };
 
 class VSDStencil
diff --git a/src/lib/VSDStylesCollector.cpp b/src/lib/VSDStylesCollector.cpp
index f2bddc0..25f4029 100644
--- a/src/lib/VSDStylesCollector.cpp
+++ b/src/lib/VSDStylesCollector.cpp
@@ -249,6 +249,11 @@ void libvisio::VSDStylesCollector::collectMisc(unsigned level, const VSDMisc & /
   _handleLevelChange(level);
 }
 
+void libvisio::VSDStylesCollector::collectLayerMem(unsigned level, const VSDName & /* layerMem */)
+{
+  _handleLevelChange(level);
+}
+
 void libvisio::VSDStylesCollector::collectLayer(unsigned /* id */, unsigned level, const VSDLayer & /* layer */)
 {
   _handleLevelChange(level);
diff --git a/src/lib/VSDStylesCollector.h b/src/lib/VSDStylesCollector.h
index f8b83c2..caa6eb7 100644
--- a/src/lib/VSDStylesCollector.h
+++ b/src/lib/VSDStylesCollector.h
@@ -116,6 +116,7 @@ public:
   void collectPageSheet(unsigned id, unsigned level);
   void collectMisc(unsigned level, const VSDMisc &misc);
   void collectLayer(unsigned id, unsigned level, const VSDLayer &layer);
+  void collectLayerMem(unsigned level, const VSDName &layerMem);
 
   // Style collectors
   void collectStyleSheet(unsigned id, unsigned level,unsigned parentLineStyle, unsigned parentFillStyle, unsigned parentTextStyle);


More information about the Libreoffice-commits mailing list