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

Fridrich Štrba fridrich.strba at bluewin.ch
Wed Jul 13 06:55:35 UTC 2016


 src/lib/CMXParser.cpp |   70 +++++++++++++++++++++++++++++++++++++++++++-------
 src/lib/CMXParser.h   |   26 +++++++++++++++---
 2 files changed, 83 insertions(+), 13 deletions(-)

New commits:
commit a9dc0718f68bac96144d15e2b6165fc1ae83d6d1
Author: Fridrich Štrba <fridrich.strba at bluewin.ch>
Date:   Wed Jul 13 08:55:08 2016 +0200

    Defines for sections
    
    Change-Id: Ib3ce9f075b726aaa0916f0caf720f031210a11da

diff --git a/src/lib/CMXParser.cpp b/src/lib/CMXParser.cpp
index 7d41e84..6483ba2 100644
--- a/src/lib/CMXParser.cpp
+++ b/src/lib/CMXParser.cpp
@@ -386,7 +386,6 @@ void libcdr::CMXParser::readIxmr(librevenge::RVNGInputStream *input)
     unsigned offset = readU32(input, m_bigEndian);
     offsets[indexRecordId] = offset;
   }
-
 }
 
 void libcdr::CMXParser::readPage(librevenge::RVNGInputStream *input, unsigned length)
diff --git a/src/lib/CMXParser.h b/src/lib/CMXParser.h
index 854b9e2..32c7ef5 100644
--- a/src/lib/CMXParser.h
+++ b/src/lib/CMXParser.h
@@ -18,6 +18,25 @@
 #include "CDRTypes.h"
 #include "CommonParser.h"
 
+#define CMX_MASTER_INDEX_TABLE 1
+#define CMX_PAGE_INDEX_TABLE 2
+#define CMX_MASTER_LAYER_TABLE 3
+#define CMX_PROCEDURE_INDEX_TABLE 4
+#define CMX_BITMAP_INDEX_TABLE 5
+#define CMX_ARROW_INDEX_TABLE 6
+#define CMX_FONT_INDEX_TABLE 7
+#define CMX_EMBEDDED_FILE_INDEX_TABLE 8
+#define CMX_THUMBNAIL_SECTION 10
+#define CMX_OUTLINE_DESCRIPTION_SECTION 15
+#define CMX_LINE_STYLE_DESCRIPTION_SECTION 16
+#define CMX_ARROWHEADS_DESCRIPTION_SECTION 17
+#define CMX_SCREEN_DESCRIPTION_SECTION 18
+#define CMX_PEN_DESCRIPTION_SECTION 19
+#define CMX_DOT_DASH_DESCRIPTION_SECTION 20
+#define CMX_COLOR_DESCRIPTION_SECTION 21
+#define CMX_COLOR_CORRECTION_SECTION 22
+#define CMX_PREVIEW_BOX_SECTION 23
+
 namespace libcdr
 {
 
commit f9a78854aba45c2dc6a5a29eea1d57a689e2ed5f
Author: Fridrich Štrba <fridrich.strba at bluewin.ch>
Date:   Wed Jul 13 08:42:51 2016 +0200

    Start the infrastructure for parsing from index section
    
    Change-Id: I9009d6d2f24a91dc8a56418c8b7cc7cd4165fefd

diff --git a/src/lib/CMXParser.cpp b/src/lib/CMXParser.cpp
index 8d8314c..7d41e84 100644
--- a/src/lib/CMXParser.cpp
+++ b/src/lib/CMXParser.cpp
@@ -36,7 +36,6 @@ libcdr::CMXParser::CMXParser(libcdr::CDRCollector *collector, CMXParserState &pa
   : 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_parserState(parserState),
     m_currentImageInfo(), m_currentPattern(0), m_currentBitmap(0) {}
 
@@ -197,9 +196,6 @@ void libcdr::CMXParser::readRecord(unsigned fourCC, unsigned &length, librevenge
   case CDR_FOURCC_cont:
     readCMXHeader(input);
     break;
-  case CDR_FOURCC_DISP:
-    readDisp(input, length);
-    break;
   case CDR_FOURCC_page:
     readPage(input, length);
     break;
@@ -284,19 +280,45 @@ void libcdr::CMXParser::readCMXHeader(librevenge::RVNGInputStream *input)
   m_scale = readDouble(input, m_bigEndian);
   CDR_DEBUG_MSG(("CMX Units Scale: %.9f\n", m_scale));
   input->seek(12, librevenge::RVNG_SEEK_CUR);
-  m_indexSectionOffset = readU32(input, m_bigEndian);
-  m_infoSectionOffset = readU32(input, m_bigEndian);
-  m_thumbnailOffset = readU32(input, m_bigEndian);
+  unsigned indexSectionOffset = readU32(input, m_bigEndian);
+#ifdef DEBUG
+  unsigned infoSectionOffset = readU32(input, m_bigEndian);
+#else
+  input->seek(4, librevenge::RVNG_SEEK_CUR);
+#endif
+  unsigned thumbnailOffset = readU32(input, m_bigEndian);
 #ifdef DEBUG
   CDRBox box = readBBox(input);
 #endif
   CDR_DEBUG_MSG(("CMX Offsets: index section 0x%.8x, info section: 0x%.8x, thumbnail: 0x%.8x\n",
-                 m_indexSectionOffset, m_infoSectionOffset, m_thumbnailOffset));
+                 indexSectionOffset, infoSectionOffset, thumbnailOffset));
   CDR_DEBUG_MSG(("CMX Bounding Box: x: %f, y: %f, w: %f, h: %f\n", box.m_x, box.m_y, box.m_w, box.m_h));
+  if (thumbnailOffset != (unsigned)-1)
+  {
+    long oldOffset = input->tell();
+    input->seek(thumbnailOffset, librevenge::RVNG_SEEK_SET);
+    readDisp(input);
+    input->seek(oldOffset, librevenge::RVNG_SEEK_SET);
+  }
+  if (indexSectionOffset != (unsigned)-1)
+  {
+    long oldOffset = input->tell();
+    input->seek(indexSectionOffset, librevenge::RVNG_SEEK_SET);
+    readIxmr(input);
+    input->seek(oldOffset, librevenge::RVNG_SEEK_SET);
+  }
 }
 
-void libcdr::CMXParser::readDisp(librevenge::RVNGInputStream *input, unsigned length)
+void libcdr::CMXParser::readDisp(librevenge::RVNGInputStream *input)
 {
+  unsigned fourCC = readU32(input, m_bigEndian);
+  if (CDR_FOURCC_DISP != fourCC)
+    return;
+  unsigned length = readU32(input, m_bigEndian);
+  const unsigned long maxLength = getRemainingLength(input);
+  if (length > maxLength)
+    length = maxLength;
+
   librevenge::RVNGBinaryData previewImage;
   previewImage.append((unsigned char)0x42);
   previewImage.append((unsigned char)0x4d);
@@ -336,6 +358,37 @@ void libcdr::CMXParser::readDisp(librevenge::RVNGInputStream *input, unsigned le
 #endif
 }
 
+const unsigned *libcdr::CMXParser::_getOffsetByType(unsigned short type, const std::map<unsigned short, unsigned> &offsets)
+{
+  std::map<unsigned short, unsigned>::const_iterator iter = offsets.find(type);
+  if (iter != offsets.end())
+    return &(iter->second);
+  return 0;
+}
+
+void libcdr::CMXParser::readIxmr(librevenge::RVNGInputStream *input)
+{
+  unsigned fourCC = readU32(input, m_bigEndian);
+  if (CDR_FOURCC_ixmr != fourCC)
+    return;
+  unsigned length = readU32(input, m_bigEndian);
+  const unsigned long maxLength = getRemainingLength(input);
+  if (length > maxLength)
+    length = maxLength;
+
+  readU16(input, m_bigEndian); // Master ID
+  readU16(input, m_bigEndian); // Size
+  unsigned short recordCount = readU16(input, m_bigEndian);
+  std::map<unsigned short, unsigned> offsets;
+  for (unsigned short i = 1; i <= recordCount; ++i)
+  {
+    unsigned short indexRecordId = readU16(input, m_bigEndian);
+    unsigned offset = readU32(input, m_bigEndian);
+    offsets[indexRecordId] = offset;
+  }
+
+}
+
 void libcdr::CMXParser::readPage(librevenge::RVNGInputStream *input, unsigned length)
 {
   long endPosition = length + input->tell();
diff --git a/src/lib/CMXParser.h b/src/lib/CMXParser.h
index 4192a9e..854b9e2 100644
--- a/src/lib/CMXParser.h
+++ b/src/lib/CMXParser.h
@@ -97,7 +97,7 @@ private:
   void parseImage(librevenge::RVNGInputStream *input);
 
   void readCMXHeader(librevenge::RVNGInputStream *input);
-  void readDisp(librevenge::RVNGInputStream *input, unsigned length);
+  void readDisp(librevenge::RVNGInputStream *input);
   void readPage(librevenge::RVNGInputStream *input, unsigned length);
   void readRclr(librevenge::RVNGInputStream *input);
   void readRotl(librevenge::RVNGInputStream *input);
@@ -106,6 +106,7 @@ private:
   void readRpen(librevenge::RVNGInputStream *input);
   void readIxtl(librevenge::RVNGInputStream *input);
   void readIxef(librevenge::RVNGInputStream *input);
+  void readIxmr(librevenge::RVNGInputStream *input);
   void readInfo(librevenge::RVNGInputStream *input);
   void readData(librevenge::RVNGInputStream *input);
 
@@ -133,6 +134,7 @@ private:
   CDRColor getPaletteColor(unsigned id);
   CDRColor readColor(librevenge::RVNGInputStream *input, unsigned char colorModel);
   CDRLineStyle getLineStyle(unsigned id);
+  const unsigned *_getOffsetByType(unsigned short type, const std::map<unsigned short, unsigned> &offsets);
 
   void _tryToSkipEmbedded(librevenge::RVNGInputStream *input);
 
@@ -140,9 +142,6 @@ private:
   unsigned short m_unit;
   double m_scale;
   double m_xmin, m_xmax, m_ymin, m_ymax;
-  unsigned m_indexSectionOffset;
-  unsigned m_infoSectionOffset;
-  unsigned m_thumbnailOffset;
   unsigned m_fillIndex;
   unsigned m_nextInstructionOffset;
   CMXParserState &m_parserState;


More information about the Libreoffice-commits mailing list