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

Fridrich Štrba fridrich.strba at bluewin.ch
Fri Jul 1 11:03:25 UTC 2016


 src/lib/CMXDocument.cpp |    6 +++---
 src/lib/CMXParser.cpp   |   12 ++++++------
 src/lib/CMXParser.h     |   10 ++++++++--
 3 files changed, 17 insertions(+), 11 deletions(-)

New commits:
commit 79cd1211c2bb118280c7da2d228a7f592df03295
Author: Fridrich Štrba <fridrich.strba at bluewin.ch>
Date:   Fri Jul 1 13:03:00 2016 +0200

    Extensible parser state for CMXParser
    
    Change-Id: I52706b557c449b8ef6850bf29b2943df83c43741

diff --git a/src/lib/CMXDocument.cpp b/src/lib/CMXDocument.cpp
index c92aae1..691fd61 100644
--- a/src/lib/CMXDocument.cpp
+++ b/src/lib/CMXDocument.cpp
@@ -66,8 +66,8 @@ CDRAPI bool libcdr::CMXDocument::parse(librevenge::RVNGInputStream *input, libre
   input->seek(0, librevenge::RVNG_SEEK_SET);
   CDRParserState ps;
   CDRStylesCollector stylesCollector(ps);
-  std::map<unsigned, libcdr::CDRColor> colorPalette;
-  CMXParser stylesParser(&stylesCollector, colorPalette);
+  CMXParserState parserState;
+  CMXParser stylesParser(&stylesCollector, parserState);
   bool retVal = stylesParser.parseRecords(input);
   if (ps.m_pages.empty())
     retVal = false;
@@ -75,7 +75,7 @@ CDRAPI bool libcdr::CMXDocument::parse(librevenge::RVNGInputStream *input, libre
   {
     input->seek(0, librevenge::RVNG_SEEK_SET);
     CDRContentCollector contentCollector(ps, painter);
-    CMXParser contentParser(&contentCollector, colorPalette);
+    CMXParser contentParser(&contentCollector, parserState);
     retVal = contentParser.parseRecords(input);
   }
   return retVal;
diff --git a/src/lib/CMXParser.cpp b/src/lib/CMXParser.cpp
index 3c51f87..9b2eec5 100644
--- a/src/lib/CMXParser.cpp
+++ b/src/lib/CMXParser.cpp
@@ -28,12 +28,12 @@
 #define M_PI 3.14159265358979323846
 #endif
 
-libcdr::CMXParser::CMXParser(libcdr::CDRCollector *collector, std::map<unsigned, libcdr::CDRColor> &colorPalette)
+libcdr::CMXParser::CMXParser(libcdr::CDRCollector *collector, CMXParserState &parserState)
   : CommonParser(collector),
     m_bigEndian(false), m_unit(0),
     m_scale(0.0), m_xmin(0.0), m_xmax(0.0), m_ymin(0.0), m_ymax(0.0),
     m_indexSectionOffset(0), m_infoSectionOffset(0), m_thumbnailOffset(0),
-    m_fillIndex(0), m_nextInstructionOffset(0), m_colorPalette(colorPalette) {}
+    m_fillIndex(0), m_nextInstructionOffset(0), m_parserState(parserState) {}
 
 libcdr::CMXParser::~CMXParser()
 {
@@ -1029,7 +1029,7 @@ void libcdr::CMXParser::readRclr(librevenge::RVNGInputStream *input, unsigned /*
           readU8(input, m_bigEndian);
           break;
         case CMX_Tag_DescrSection_Color_ColorDescr:
-          m_colorPalette[j] = readColor(input, colorModel);
+          m_parserState.m_colorPalette[j] = readColor(input, colorModel);
           break;
         default:
           break;
@@ -1042,7 +1042,7 @@ void libcdr::CMXParser::readRclr(librevenge::RVNGInputStream *input, unsigned /*
     {
       colorModel = readU8(input, m_bigEndian);
       readU8(input, m_bigEndian);
-      m_colorPalette[j] = readColor(input, colorModel);
+      m_parserState.m_colorPalette[j] = readColor(input, colorModel);
     }
     else
       return;
@@ -1051,8 +1051,8 @@ void libcdr::CMXParser::readRclr(librevenge::RVNGInputStream *input, unsigned /*
 
 libcdr::CDRColor libcdr::CMXParser::getPaletteColor(unsigned id)
 {
-  const std::map<unsigned, libcdr::CDRColor>::const_iterator iter = m_colorPalette.find(id);
-  if (iter != m_colorPalette.end())
+  const std::map<unsigned, libcdr::CDRColor>::const_iterator iter = m_parserState.m_colorPalette.find(id);
+  if (iter != m_parserState.m_colorPalette.end())
     return iter->second;
   return libcdr::CDRColor();
 }
diff --git a/src/lib/CMXParser.h b/src/lib/CMXParser.h
index 612479b..f050f88 100644
--- a/src/lib/CMXParser.h
+++ b/src/lib/CMXParser.h
@@ -23,10 +23,16 @@ namespace libcdr
 
 class CDRCollector;
 
+struct CMXParserState
+{
+  CMXParserState() : m_colorPalette() {}
+  std::map<unsigned, CDRColor> m_colorPalette;
+};
+
 class CMXParser : protected CommonParser
 {
 public:
-  explicit CMXParser(CDRCollector *collector, std::map<unsigned, CDRColor> &colorPalette);
+  explicit CMXParser(CDRCollector *collector, CMXParserState &parserState);
   virtual ~CMXParser();
   bool parseRecords(librevenge::RVNGInputStream *input, long size = -1, unsigned level = 0);
 
@@ -73,7 +79,7 @@ private:
   unsigned m_thumbnailOffset;
   unsigned m_fillIndex;
   unsigned m_nextInstructionOffset;
-  std::map<unsigned, CDRColor> &m_colorPalette;
+  CMXParserState &m_parserState;
 };
 
 } // namespace libcdr


More information about the Libreoffice-commits mailing list