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

Fridrich Štrba fridrich.strba at bluewin.ch
Mon Jul 18 10:55:46 UTC 2016


 src/lib/CDRCollector.cpp        |    3 ++-
 src/lib/CDRCollector.h          |   10 ++++++----
 src/lib/CDRContentCollector.cpp |   14 ++++++++------
 src/lib/CDRContentCollector.h   |    8 ++++----
 src/lib/CDRParser.cpp           |   23 +++++++++++------------
 src/lib/CDRParser.h             |    2 ++
 src/lib/CDRStylesCollector.cpp  |   10 ++++++++++
 src/lib/CDRStylesCollector.h    |    7 ++++---
 src/lib/CMXParser.cpp           |   21 +++++++++++----------
 9 files changed, 58 insertions(+), 40 deletions(-)

New commits:
commit 4c41d9c89edeaa96208c68e3d1b0c1849c7c1c42
Author: Fridrich Štrba <fridrich.strba at bluewin.ch>
Date:   Mon Jul 18 12:55:22 2016 +0200

    Assure that we know fill/line properties when parsing the full colour fill
    
    Change-Id: I6bf3f779a9e846d3aa476a91989046757aebe58b

diff --git a/src/lib/CDRCollector.cpp b/src/lib/CDRCollector.cpp
index 939eca4..7b52258 100644
--- a/src/lib/CDRCollector.cpp
+++ b/src/lib/CDRCollector.cpp
@@ -14,7 +14,8 @@
 #include "libcdr_utils.h"
 
 libcdr::CDRParserState::CDRParserState()
-  : m_bmps(), m_patterns(), m_vects(), m_pages(), m_documentPalette(), m_texts(), m_styles(),
+  : m_bmps(), m_patterns(), m_vects(), m_pages(), m_documentPalette(), m_texts(),
+    m_styles(), m_fillStyles(), m_lineStyles(),
     m_colorTransformCMYK2RGB(0), m_colorTransformLab2RGB(0), m_colorTransformRGB2RGB(0)
 {
   cmsHPROFILE tmpRGBProfile = cmsCreate_sRGBProfile();
diff --git a/src/lib/CDRCollector.h b/src/lib/CDRCollector.h
index 32d1c55..52c626a 100644
--- a/src/lib/CDRCollector.h
+++ b/src/lib/CDRCollector.h
@@ -41,6 +41,8 @@ public:
   std::map<unsigned, CDRColor> m_documentPalette;
   std::map<unsigned, std::vector<CDRTextLine> > m_texts;
   std::map<unsigned, CDRStyle> m_styles;
+  std::map<unsigned, CDRFillStyle> m_fillStyles;
+  std::map<unsigned, CDRLineStyle> m_lineStyles;
 
   unsigned _getRGBColor(const CDRColor &color);
   unsigned getBMPColor(const CDRColor &color);
@@ -73,10 +75,10 @@ public:
   virtual void collectPath(const CDRPath &path) = 0;
   virtual void collectLevel(unsigned level) = 0;
   virtual void collectTransform(const CDRTransforms &transforms, bool considerGroupTransform) = 0;
-  virtual void collectFillStyle(unsigned short fillType, const CDRColor &color1, const CDRColor &color2, const CDRGradient &gradient, const CDRImageFill &imageFill) = 0;
-  virtual void collectLineStyle(unsigned short lineType, unsigned short capsType, unsigned short joinType, double lineWidth,
-                                double stretch, double angle, const CDRColor &color, const std::vector<unsigned> &dashArray,
-                                const CDRPath &startMarker, const CDRPath &endMarker) = 0;
+  virtual void collectFillStyle(unsigned id, const CDRFillStyle &fillStyle) = 0;
+  virtual void collectFillStyleId(unsigned id) = 0;
+  virtual void collectLineStyle(unsigned id, const CDRLineStyle &lineStyle) = 0;
+  virtual void collectLineStyleId(unsigned id) = 0;
   virtual void collectRotate(double angle, double cx, double cy) = 0;
   virtual void collectFlags(unsigned flags, bool considerFlags) = 0;
   virtual void collectPageSize(double width, double height, double offsetX, double offsetY) = 0;
diff --git a/src/lib/CDRContentCollector.cpp b/src/lib/CDRContentCollector.cpp
index 860bf30..a703e6d 100644
--- a/src/lib/CDRContentCollector.cpp
+++ b/src/lib/CDRContentCollector.cpp
@@ -641,16 +641,18 @@ void libcdr::CDRContentCollector::collectLevel(unsigned level)
   }
 }
 
-void libcdr::CDRContentCollector::collectFillStyle(unsigned short fillType, const CDRColor &color1, const CDRColor &color2, const CDRGradient &gradient, const CDRImageFill &imageFill)
+void libcdr::CDRContentCollector::collectFillStyleId(unsigned id)
 {
-  m_currentFillStyle = CDRFillStyle(fillType, color1, color2, gradient, imageFill);
+  std::map<unsigned, CDRFillStyle>::const_iterator iter = m_ps.m_fillStyles.find(id);
+  if (iter != m_ps.m_fillStyles.end())
+    m_currentFillStyle = iter->second;
 }
 
-void libcdr::CDRContentCollector::collectLineStyle(unsigned short lineType, unsigned short capsType, unsigned short joinType, double lineWidth,
-                                                   double stretch, double angle, const CDRColor &color, const std::vector<unsigned> &dashArray,
-                                                   const CDRPath &startMarker, const CDRPath &endMarker)
+void libcdr::CDRContentCollector::collectLineStyleId(unsigned id)
 {
-  m_currentLineStyle = CDRLineStyle(lineType, capsType, joinType, lineWidth, stretch, angle, color, dashArray, startMarker, endMarker);
+  std::map<unsigned, CDRLineStyle>::const_iterator iter = m_ps.m_lineStyles.find(id);
+  if (iter != m_ps.m_lineStyles.end())
+    m_currentLineStyle = iter->second;
 }
 
 void libcdr::CDRContentCollector::collectRotate(double angle, double cx, double cy)
diff --git a/src/lib/CDRContentCollector.h b/src/lib/CDRContentCollector.h
index 2261454..30c1546 100644
--- a/src/lib/CDRContentCollector.h
+++ b/src/lib/CDRContentCollector.h
@@ -39,10 +39,10 @@ public:
   void collectPath(const CDRPath &path);
   void collectLevel(unsigned level);
   void collectTransform(const CDRTransforms &transforms, bool considerGroupTransform);
-  void collectFillStyle(unsigned short fillType, const CDRColor &color1, const CDRColor &color2, const CDRGradient &gradient, const CDRImageFill &imageFill);
-  void collectLineStyle(unsigned short lineType, unsigned short capsType, unsigned short joinType, double lineWidth,
-                        double stretch, double angle, const CDRColor &color, const std::vector<unsigned> &dashArray,
-                        const CDRPath &startMarker, const CDRPath &endMarker);
+  void collectFillStyle(unsigned,const CDRFillStyle &) {}
+  void collectFillStyleId(unsigned id);
+  void collectLineStyle(unsigned,const CDRLineStyle &) {}
+  void collectLineStyleId(unsigned id);
   void collectRotate(double angle, double cx, double cy);
   void collectFlags(unsigned flags, bool considerFlags);
   void collectPageSize(double, double, double, double) {}
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index db463eb..960df3e 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -155,7 +155,7 @@ static int parseColourString(const char *colourString, libcdr::CDRColor &colour,
 
 libcdr::CDRParser::CDRParser(const std::vector<librevenge::RVNGInputStream *> &externalStreams, libcdr::CDRCollector *collector)
   : CommonParser(collector), m_externalStreams(externalStreams),
-    m_fonts(), m_fillStyles(), m_lineStyles(), m_arrows(), m_version(0) {}
+    m_fonts(), m_fillStyles(), m_lineStyles(), m_arrows(), m_version(0), m_waldoOutlId(0), m_waldoFillId(0) {}
 
 libcdr::CDRParser::~CDRParser()
 {
@@ -1561,7 +1561,8 @@ void libcdr::CDRParser::readWaldoOutl(librevenge::RVNGInputStream *input)
   CDRPath endMarker;
   if (iter != m_arrows.end())
     endMarker = iter->second;
-  m_collector->collectLineStyle(lineType, capsType, joinType, lineWidth, stretch, angle, color, dashArray, startMarker, endMarker);
+  m_collector->collectLineStyle(++m_waldoOutlId, CDRLineStyle(lineType, capsType, joinType, lineWidth, stretch, angle, color, dashArray, startMarker, endMarker));
+  m_collector->collectLineStyleId(m_waldoOutlId);
 }
 
 void libcdr::CDRParser::readWaldoFill(librevenge::RVNGInputStream *input)
@@ -1654,7 +1655,8 @@ void libcdr::CDRParser::readWaldoFill(librevenge::RVNGInputStream *input)
   default:
     break;
   }
-  m_collector->collectFillStyle(fillType, color1, color2, gradient, imageFill);
+  m_collector->collectFillStyle(++m_waldoFillId, CDRFillStyle(fillType, color1, color2, gradient, imageFill));
+  m_collector->collectFillStyleId(m_waldoFillId);
 }
 
 void libcdr::CDRParser::readTrfd(librevenge::RVNGInputStream *input, unsigned length)
@@ -2014,6 +2016,7 @@ void libcdr::CDRParser::readFild(librevenge::RVNGInputStream *input, unsigned le
     break;
   }
   m_fillStyles[fillId] = CDRFillStyle(fillType, color1, color2, gradient, imageFill);
+  m_collector->collectFillStyle(fillId, CDRFillStyle(fillType, color1, color2, gradient, imageFill));
 }
 
 void libcdr::CDRParser::readOutl(librevenge::RVNGInputStream *input, unsigned length)
@@ -2074,6 +2077,7 @@ void libcdr::CDRParser::readOutl(librevenge::RVNGInputStream *input, unsigned le
   if (iter != m_arrows.end())
     endMarker = iter->second;
   m_lineStyles[lineId] = CDRLineStyle(lineType, capsType, joinType, lineWidth, stretch, angle, color, dashArray, startMarker, endMarker);
+  m_collector->collectLineStyle(lineId, CDRLineStyle(lineType, capsType, joinType, lineWidth, stretch, angle, color, dashArray, startMarker, endMarker));
 }
 
 void libcdr::CDRParser::readLoda(librevenge::RVNGInputStream *input, unsigned length)
@@ -2138,10 +2142,8 @@ void libcdr::CDRParser::readLoda(librevenge::RVNGInputStream *input, unsigned le
       else
       {
         unsigned fillId = readU32(input);
-        std::map<unsigned, CDRFillStyle>::const_iterator iter = m_fillStyles.find(fillId);
-        if (iter != m_fillStyles.end())
-          m_collector->collectFillStyle(iter->second.fillType, iter->second.color1, iter->second.color2,
-                                        iter->second.gradient, iter->second.imageFill);
+        if (fillId)
+          m_collector->collectFillStyleId(fillId);
       }
     }
     else if (argTypes[i] == 0x0a)
@@ -2151,11 +2153,8 @@ void libcdr::CDRParser::readLoda(librevenge::RVNGInputStream *input, unsigned le
       else
       {
         unsigned outlId = readU32(input);
-        std::map<unsigned, CDRLineStyle>::const_iterator iter = m_lineStyles.find(outlId);
-        if (iter != m_lineStyles.end())
-          m_collector->collectLineStyle(iter->second.lineType, iter->second.capsType, iter->second.joinType, iter->second.lineWidth,
-                                        iter->second.stretch, iter->second.angle, iter->second.color, iter->second.dashArray,
-                                        iter->second.startMarker, iter->second.endMarker);
+        if (outlId)
+          m_collector->collectLineStyleId(outlId);
       }
     }
     else if (argTypes[i] == 0xc8)
diff --git a/src/lib/CDRParser.h b/src/lib/CDRParser.h
index ca30d50..2521cd3 100644
--- a/src/lib/CDRParser.h
+++ b/src/lib/CDRParser.h
@@ -104,6 +104,8 @@ private:
   std::map<unsigned, CDRPath> m_arrows;
 
   unsigned m_version;
+  unsigned m_waldoOutlId;
+  unsigned m_waldoFillId;
 
 };
 
diff --git a/src/lib/CDRStylesCollector.cpp b/src/lib/CDRStylesCollector.cpp
index 3119cc2..093dad8 100644
--- a/src/lib/CDRStylesCollector.cpp
+++ b/src/lib/CDRStylesCollector.cpp
@@ -269,4 +269,14 @@ void libcdr::CDRStylesCollector::collectStld(unsigned id, const CDRStyle &style)
   m_ps.m_styles[id] = style;
 }
 
+void libcdr::CDRStylesCollector::collectFillStyle(unsigned id, const CDRFillStyle &fillStyle)
+{
+  m_ps.m_fillStyles[id] = fillStyle;
+}
+
+void libcdr::CDRStylesCollector::collectLineStyle(unsigned id, const CDRLineStyle &lineStyle)
+{
+  m_ps.m_lineStyles[id] = lineStyle;
+}
+
 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/lib/CDRStylesCollector.h b/src/lib/CDRStylesCollector.h
index 8b1433d..009692f 100644
--- a/src/lib/CDRStylesCollector.h
+++ b/src/lib/CDRStylesCollector.h
@@ -39,9 +39,10 @@ public:
   void collectPath(const CDRPath &) {}
   void collectLevel(unsigned) {}
   void collectTransform(const CDRTransforms &, bool) {}
-  void collectFillStyle(unsigned short, const CDRColor &, const CDRColor &, const CDRGradient &, const CDRImageFill &) {}
-  void collectLineStyle(unsigned short, unsigned short, unsigned short, double, double, double, const CDRColor &,
-                        const std::vector<unsigned> &, const CDRPath &, const CDRPath &) {}
+  void collectFillStyle(unsigned id, const CDRFillStyle &fillStyle);
+  void collectFillStyleId(unsigned) {}
+  void collectLineStyle(unsigned id, const CDRLineStyle &lineStyle);
+  void collectLineStyleId(unsigned) {}
   void collectRotate(double,double,double) {}
   void collectFlags(unsigned, bool) {}
   void collectPageSize(double width, double height, double offsetX, double offsetY);
diff --git a/src/lib/CMXParser.cpp b/src/lib/CMXParser.cpp
index bf3f818..f82f4f1 100644
--- a/src/lib/CMXParser.cpp
+++ b/src/lib/CMXParser.cpp
@@ -957,8 +957,9 @@ bool libcdr::CMXParser::readFill(librevenge::RVNGInputStream *input)
   libcdr::CDRColor color2;
   libcdr::CDRImageFill imageFill;
   libcdr::CDRGradient gradient;
-  unsigned fillIdentifier = readU16(input, m_bigEndian);
-  switch (fillIdentifier)
+  unsigned fillId = (unsigned)input->tell();
+  unsigned fillType = readU16(input, m_bigEndian);
+  switch (fillType)
   {
   case 1: // Uniform
     if (m_precision == libcdr::PRECISION_32BIT)
@@ -1103,11 +1104,11 @@ bool libcdr::CMXParser::readFill(librevenge::RVNGInputStream *input)
         tagId = readU8(input, m_bigEndian);
         if (tagId == CMX_Tag_EndTag)
         {
-          CDR_DEBUG_MSG(("    %s fill - tagId %i\n", fillIdentifier == 7 ? "Two-Color Pattern" : "Monochrome with transparent bitmap", tagId));
+          CDR_DEBUG_MSG(("    %s fill - tagId %i\n", fillType == 7 ? "Two-Color Pattern" : "Monochrome with transparent bitmap", tagId));
           break;
         }
         tagLength = readU16(input, m_bigEndian);
-        CDR_DEBUG_MSG(("    %s fill - tagId %i, tagLength %u\n", fillIdentifier == 7 ? "Two-Color Pattern" : "Monochrome with transparent bitmap", tagId, tagLength));
+        CDR_DEBUG_MSG(("    %s fill - tagId %i, tagLength %u\n", fillType == 7 ? "Two-Color Pattern" : "Monochrome with transparent bitmap", tagId, tagLength));
         switch (tagId)
         {
         case CMX_Tag_RenderAttr_FillSpec_MonoBM:
@@ -1145,7 +1146,7 @@ bool libcdr::CMXParser::readFill(librevenge::RVNGInputStream *input)
     }
     else if (m_precision == libcdr::PRECISION_16BIT)
     {
-      CDR_DEBUG_MSG(("    %s fill\n", fillIdentifier == 7 ? "Two-Color Pattern" : "Monochrome with transparent bitmap"));
+      CDR_DEBUG_MSG(("    %s fill\n", fillType == 7 ? "Two-Color Pattern" : "Monochrome with transparent bitmap"));
       unsigned short patternId = readU16(input, m_bigEndian);
       int tmpWidth = readU16(input, m_bigEndian);
       int tmpHeight = readU16(input, m_bigEndian);
@@ -1368,7 +1369,8 @@ bool libcdr::CMXParser::readFill(librevenge::RVNGInputStream *input)
       return false;
     break;
   }
-  m_collector->collectFillStyle(fillIdentifier, color1, color2, gradient, imageFill);
+  m_collector->collectFillStyle(fillId, CDRFillStyle(fillType, color1, color2, gradient, imageFill));
+  m_collector->collectFillStyleId(fillId);
   return true;
 }
 
@@ -1414,6 +1416,7 @@ bool libcdr::CMXParser::readRenderingAttributes(librevenge::RVNGInputStream *inp
   if (bitMask & 0x02) // outline
   {
     CDRLineStyle lineStyle;
+    unsigned lineStyleId = (unsigned)input->tell();
     if (m_precision == libcdr::PRECISION_32BIT)
     {
       do
@@ -1444,10 +1447,8 @@ bool libcdr::CMXParser::readRenderingAttributes(librevenge::RVNGInputStream *inp
       CDR_DEBUG_MSG(("  Outline specification\n"));
       lineStyle = getLineStyle(readU16(input, m_bigEndian));
     }
-    m_collector->collectLineStyle(lineStyle.lineType, lineStyle.capsType, lineStyle.joinType,
-                                  lineStyle.lineWidth, lineStyle.stretch, lineStyle.angle,
-                                  lineStyle.color, lineStyle.dashArray,
-                                  lineStyle.startMarker, lineStyle.endMarker);
+    m_collector->collectLineStyle(lineStyleId, lineStyle);
+    m_collector->collectLineStyleId(lineStyleId);
   }
   if (bitMask & 0x04) // lens
   {


More information about the Libreoffice-commits mailing list