diff options
author | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2013-02-22 11:24:18 +0100 |
---|---|---|
committer | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2013-02-22 11:24:18 +0100 |
commit | cb055a1b99ba51a6dc9aa407c18e7ea2ffc746f9 (patch) | |
tree | b648017c647a48de567a5eb014e7392be5f3f51d | |
parent | 9a4a8eb8e76755bd2aaa287f86a931f7f4030ccc (diff) |
Read and push to the api the names of the pages if they exist
-rw-r--r-- | src/lib/VSD5Parser.cpp | 2 | ||||
-rw-r--r-- | src/lib/VSD5Parser.h | 2 | ||||
-rw-r--r-- | src/lib/VSDCollector.h | 2 | ||||
-rw-r--r-- | src/lib/VSDContentCollector.cpp | 6 | ||||
-rw-r--r-- | src/lib/VSDContentCollector.h | 2 | ||||
-rw-r--r-- | src/lib/VSDDocumentStructure.h | 1 | ||||
-rw-r--r-- | src/lib/VSDPages.cpp | 4 | ||||
-rw-r--r-- | src/lib/VSDPages.h | 1 | ||||
-rw-r--r-- | src/lib/VSDParser.cpp | 54 | ||||
-rw-r--r-- | src/lib/VSDParser.h | 6 | ||||
-rw-r--r-- | src/lib/VSDStylesCollector.cpp | 2 | ||||
-rw-r--r-- | src/lib/VSDStylesCollector.h | 2 | ||||
-rw-r--r-- | src/lib/VSDTypes.h | 4 | ||||
-rw-r--r-- | src/lib/VSDXMLParserBase.cpp | 2 |
14 files changed, 77 insertions, 13 deletions
diff --git a/src/lib/VSD5Parser.cpp b/src/lib/VSD5Parser.cpp index 9d7c164..f49fafa 100644 --- a/src/lib/VSD5Parser.cpp +++ b/src/lib/VSD5Parser.cpp @@ -381,7 +381,7 @@ void libvisio::VSD5Parser::readShape(WPXInputStream *input) void libvisio::VSD5Parser::readPage(WPXInputStream *input) { unsigned backgroundPageID = getUInt(input); - m_collector->collectPage(m_header.id, m_header.level, backgroundPageID, m_isBackgroundPage, WPXString()); + m_collector->collectPage(m_header.id, m_header.level, backgroundPageID, m_isBackgroundPage, VSDName()); } void libvisio::VSD5Parser::readTextBlock(WPXInputStream *input) diff --git a/src/lib/VSD5Parser.h b/src/lib/VSD5Parser.h index 4430e1c..d6cf0ae 100644 --- a/src/lib/VSD5Parser.h +++ b/src/lib/VSD5Parser.h @@ -73,6 +73,8 @@ protected: virtual void readStyleSheet(WPXInputStream *input); + virtual void readNameIDX(WPXInputStream *) {} + virtual unsigned getUInt(WPXInputStream *input); virtual int getInt(WPXInputStream *input); diff --git a/src/lib/VSDCollector.h b/src/lib/VSDCollector.h index 1633726..f53545b 100644 --- a/src/lib/VSDCollector.h +++ b/src/lib/VSDCollector.h @@ -79,7 +79,7 @@ public: virtual void collectShapesOrder(unsigned id, unsigned level, const std::vector<unsigned> &shapeIds) = 0; virtual void collectForeignDataType(unsigned level, unsigned foreignType, unsigned foreignFormat, double offsetX, double offsetY, double width, double height) = 0; virtual void collectPageProps(unsigned id, unsigned level, double pageWidth, double pageHeight, double shadowOffsetX, double shadowOffsetY, double scale) = 0; - virtual void collectPage(unsigned id, unsigned level, unsigned backgroundPageID, bool isBackgroundPage, const WPXString &pageName) = 0; + virtual void collectPage(unsigned id, unsigned level, unsigned backgroundPageID, bool isBackgroundPage, const VSDName &pageName) = 0; virtual void collectShape(unsigned id, unsigned level, unsigned parent, unsigned masterPage, unsigned masterShape, unsigned lineStyle, unsigned fillStyle, unsigned textStyle) = 0; virtual void collectSplineStart(unsigned id, unsigned level, double x, double y, double secondKnot, double firstKnot, double lastKnot, unsigned degree) = 0; virtual void collectSplineKnot(unsigned id, unsigned level, double x, double y, double knot) = 0; diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp index 09b268b..8901fa1 100644 --- a/src/lib/VSDContentCollector.cpp +++ b/src/lib/VSDContentCollector.cpp @@ -1699,11 +1699,13 @@ void libvisio::VSDContentCollector::collectPageProps(unsigned /* id */, unsigned m_currentPage.m_pageHeight = m_scale*m_pageHeight; } -void libvisio::VSDContentCollector::collectPage(unsigned /* id */, unsigned level, unsigned backgroundPageID, bool isBackgroundPage, const WPXString &pageName) +void libvisio::VSDContentCollector::collectPage(unsigned /* id */, unsigned level, unsigned backgroundPageID, bool isBackgroundPage, const VSDName &pageName) { _handleLevelChange(level); m_currentPage.m_backgroundPageID = backgroundPageID; - m_currentPage.m_pageName = pageName; + m_currentPage.m_pageName.clear(); + if (!pageName.empty()) + _convertDataToString(m_currentPage.m_pageName, pageName.m_data, pageName.m_format); m_isBackgroundPage = isBackgroundPage; } diff --git a/src/lib/VSDContentCollector.h b/src/lib/VSDContentCollector.h index 0c273c2..25ec85b 100644 --- a/src/lib/VSDContentCollector.h +++ b/src/lib/VSDContentCollector.h @@ -100,7 +100,7 @@ public: void collectShapesOrder(unsigned id, unsigned level, const std::vector<unsigned> &shapeIds); void collectForeignDataType(unsigned level, unsigned foreignType, unsigned foreignFormat, double offsetX, double offsetY, double width, double height); void collectPageProps(unsigned id, unsigned level, double pageWidth, double pageHeight, double shadowOffsetX, double shadowOffsetY, double scale); - void collectPage(unsigned id, unsigned level, unsigned backgroundPageID, bool isBackgroundPage, const WPXString &pageName); + void collectPage(unsigned id, unsigned level, unsigned backgroundPageID, bool isBackgroundPage, const VSDName &pageName); void collectShape(unsigned id, unsigned level, unsigned parent, unsigned masterPage, unsigned masterShape, unsigned lineStyle, unsigned fillStyle, unsigned textStyle); void collectSplineStart(unsigned id, unsigned level, double x, double y, double secondKnot, double firstKnot, double lastKnot, unsigned degree); void collectSplineKnot(unsigned id, unsigned level, double x, double y, double knot); diff --git a/src/lib/VSDDocumentStructure.h b/src/lib/VSDDocumentStructure.h index ae0fd62..b6a2c98 100644 --- a/src/lib/VSDDocumentStructure.h +++ b/src/lib/VSDDocumentStructure.h @@ -140,6 +140,7 @@ #define VSD_ANNOTATION 0xc6 #define VSD_SMART_TAG_DEF 0xc7 #define VSD_PRINT_PROPS 0xc8 +#define VSD_NAMEIDX 0xc9 #define VSD_SHAPE_DATA 0xd1 #define VSD_FONTFACE 0xd7 diff --git a/src/lib/VSDPages.cpp b/src/lib/VSDPages.cpp index 81d2b84..de6c181 100644 --- a/src/lib/VSDPages.cpp +++ b/src/lib/VSDPages.cpp @@ -99,6 +99,8 @@ void libvisio::VSDPages::draw(libwpg::WPGPaintInterface *painter) WPXPropertyList pageProps; pageProps.insert("svg:width", m_pages[i].m_pageWidth); pageProps.insert("svg:height", m_pages[i].m_pageHeight); + if (m_pages[i].m_pageName.len()) + pageProps.insert("draw:name", m_pages[i].m_pageName); painter->startGraphics(pageProps); _drawWithBackground(painter, m_pages[i]); painter->endGraphics(); @@ -110,6 +112,8 @@ void libvisio::VSDPages::draw(libwpg::WPGPaintInterface *painter) WPXPropertyList pageProps; pageProps.insert("svg:width", iter->second.m_pageWidth); pageProps.insert("svg:height", iter->second.m_pageHeight); + if (iter->second.m_pageName.len()) + pageProps.insert("draw:name", iter->second.m_pageName); painter->startGraphics(pageProps); _drawWithBackground(painter, iter->second); painter->endGraphics(); diff --git a/src/lib/VSDPages.h b/src/lib/VSDPages.h index 98c0b5e..f1f1b30 100644 --- a/src/lib/VSDPages.h +++ b/src/lib/VSDPages.h @@ -32,6 +32,7 @@ #define __VSDPAGES_H__ #include "VSDOutputElementList.h" +#include "VSDTypes.h" namespace libvisio { diff --git a/src/lib/VSDParser.cpp b/src/lib/VSDParser.cpp index e5aca03..84c2124 100644 --- a/src/lib/VSDParser.cpp +++ b/src/lib/VSDParser.cpp @@ -46,13 +46,26 @@ libvisio::VSDParser::VSDParser(WPXInputStream *input, libwpg::WPGPaintInterface m_stencils(), m_currentStencil(0), m_shape(), m_isStencilStarted(false), m_isInStyles(false), m_currentShapeLevel(0), m_currentShapeID(MINUS_ONE), m_extractStencils(false), m_colours(), m_isBackgroundPage(false), m_isShapeStarted(false), m_shadowOffsetX(0.0), m_shadowOffsetY(0.0), - m_currentGeometryList(0), m_currentGeomListCount(0), m_fonts(), m_names() + m_currentGeometryList(0), m_currentGeomListCount(0), m_fonts(), m_names(), m_namesMapMap(), + m_currentPageName() {} libvisio::VSDParser::~VSDParser() { } +void libvisio::VSDParser::_nameFromId(VSDName &name, unsigned id, unsigned level) +{ + name = VSDName(); + std::map<unsigned, std::map<unsigned, VSDName> >::const_iterator iter1 = m_namesMapMap.find(level); + if (iter1 != m_namesMapMap.end()) + { + std::map<unsigned, VSDName>::const_iterator iter = iter1->second.find(id); + if (iter != iter1->second.end()) + name = iter->second; + } +} + bool libvisio::VSDParser::getChunkHeader(WPXInputStream *input) { unsigned char tmpChar = 0; @@ -197,6 +210,7 @@ void libvisio::VSDParser::handleStreams(WPXInputStream *input, unsigned ptrType, std::map<unsigned, libvisio::Pointer> PtrList; std::map<unsigned, libvisio::Pointer> FontFaces; std::map<unsigned, libvisio::Pointer> NameList; + std::map<unsigned, libvisio::Pointer> NameIDX; try { @@ -212,6 +226,8 @@ void libvisio::VSDParser::handleStreams(WPXInputStream *input, unsigned ptrType, FontFaces[i] = ptr; else if (ptr.Type == VSD_NAME_LIST2) NameList[i] = ptr; + else if (ptr.Type == VSD_NAMEIDX) + NameIDX[i] = ptr; else if (ptr.Type != 0) PtrList[i] = ptr; } @@ -229,10 +245,13 @@ void libvisio::VSDParser::handleStreams(WPXInputStream *input, unsigned ptrType, } std::map<unsigned, libvisio::Pointer>::iterator iter; - for (iter = FontFaces.begin(); iter != FontFaces.end(); ++iter) + for (iter = NameList.begin(); iter != NameList.end(); ++iter) handleStream(iter->second, iter->first, level+1); - for (iter = NameList.begin(); iter != NameList.end(); ++iter) + for (iter = NameIDX.begin(); iter != NameIDX.end(); ++iter) + handleStream(iter->second, iter->first, level+1); + + for (iter = FontFaces.begin(); iter != FontFaces.end(); ++iter) handleStream(iter->second, iter->first, level+1); if (!pointerOrder.empty()) @@ -281,6 +300,7 @@ void libvisio::VSDParser::handleStream(const Pointer &ptr, unsigned idx, unsigne m_isBackgroundPage = true; else m_isBackgroundPage = false; + _nameFromId(m_currentPageName, idx, level+1); m_collector->startPage(idx); break; case VSD_STENCILS: @@ -294,6 +314,7 @@ void libvisio::VSDParser::handleStream(const Pointer &ptr, unsigned idx, unsigne if (m_extractStencils) { m_isBackgroundPage = false; + _nameFromId(m_currentPageName, idx, level+1); m_collector->startPage(idx); } else @@ -480,6 +501,9 @@ void libvisio::VSDParser::handleChunk(WPXInputStream *input) case VSD_OLE_DATA: readOLEData(input); break; + case VSD_NAMEIDX: + readNameIDX(input); + break; case VSD_PAGE_PROPS: readPageProps(input); break; @@ -700,6 +724,27 @@ void libvisio::VSDParser::readOLEData(WPXInputStream *input) } +void libvisio::VSDParser::readNameIDX(WPXInputStream *input) +{ + std::map<unsigned, VSDName> names; + unsigned recordCount = readU32(input); + for (unsigned i = 0; i < recordCount; ++i) + { + unsigned nameId = readU32(input); + if (nameId != readU32(input)) + { + VSD_DEBUG_MSG(("VSDParser::readNameIDX --> mismatch of first two dwords\n")); + return; + } + unsigned elementId = readU32(input); + input->seek(1, WPX_SEEK_CUR); + std::map<unsigned, VSDName>::const_iterator iter = m_names.find(nameId); + if (iter != m_names.end()) + names[elementId] = iter->second; + } + m_namesMapMap[m_header.level] = names; +} + void libvisio::VSDParser::readEllipse(WPXInputStream *input) { input->seek(1, WPX_SEEK_CUR); @@ -833,7 +878,6 @@ void libvisio::VSDParser::readParaList(WPXInputStream *input) m_shape.m_paraList.setElementsOrder(paragraphOrder); } - } void libvisio::VSDParser::readPropList(WPXInputStream * /* input */) @@ -844,7 +888,7 @@ void libvisio::VSDParser::readPage(WPXInputStream *input) { input->seek(8, WPX_SEEK_CUR); //sub header length and children list length unsigned backgroundPageID = readU32(input); - m_collector->collectPage(m_header.id, m_header.level, backgroundPageID, m_isBackgroundPage, WPXString()); + m_collector->collectPage(m_header.id, m_header.level, backgroundPageID, m_isBackgroundPage, m_currentPageName); } void libvisio::VSDParser::readGeometry(WPXInputStream *input) diff --git a/src/lib/VSDParser.h b/src/lib/VSDParser.h index 13498e1..351b681 100644 --- a/src/lib/VSDParser.h +++ b/src/lib/VSDParser.h @@ -34,6 +34,7 @@ #include <stdio.h> #include <iostream> #include <vector> +#include <stack> #include <map> #include <libwpd/libwpd.h> #include <libwpd-stream/libwpd-stream.h> @@ -127,6 +128,8 @@ protected: void readOLEList(WPXInputStream *input); void readOLEData(WPXInputStream *input); + virtual void readNameIDX(WPXInputStream *input); + // parser of one pass bool parseDocument(WPXInputStream *input, unsigned shift); @@ -143,6 +146,7 @@ protected: void _handleLevelChange(unsigned level); Colour _colourFromIndex(unsigned idx); void _flushShape(); + void _nameFromId(VSDName &name, unsigned id, unsigned level); virtual unsigned getUInt(WPXInputStream *input); virtual int getInt(WPXInputStream *input); @@ -176,6 +180,8 @@ protected: std::map<unsigned, VSDName> m_fonts; std::map<unsigned, VSDName> m_names; + std::map<unsigned, std::map<unsigned, VSDName> > m_namesMapMap; + VSDName m_currentPageName; private: VSDParser(); diff --git a/src/lib/VSDStylesCollector.cpp b/src/lib/VSDStylesCollector.cpp index 452f8bd..be586ee 100644 --- a/src/lib/VSDStylesCollector.cpp +++ b/src/lib/VSDStylesCollector.cpp @@ -244,7 +244,7 @@ void libvisio::VSDStylesCollector::collectPageProps(unsigned /* id */, unsigned _handleLevelChange(level); } -void libvisio::VSDStylesCollector::collectPage(unsigned /* id */, unsigned level, unsigned /* backgroundPageID */, bool /* isBackgroundPage */, const WPXString & /* pageName */) +void libvisio::VSDStylesCollector::collectPage(unsigned /* id */, unsigned level, unsigned /* backgroundPageID */, bool /* isBackgroundPage */, const VSDName & /* pageName */) { _handleLevelChange(level); } diff --git a/src/lib/VSDStylesCollector.h b/src/lib/VSDStylesCollector.h index ce8d696..6cdf30b 100644 --- a/src/lib/VSDStylesCollector.h +++ b/src/lib/VSDStylesCollector.h @@ -91,7 +91,7 @@ public: void collectShapesOrder(unsigned id, unsigned level, const std::vector<unsigned> &shapeIds); void collectForeignDataType(unsigned level, unsigned foreignType, unsigned foreignFormat, double offsetX, double offsetY, double width, double height); void collectPageProps(unsigned id, unsigned level, double pageWidth, double pageHeight, double shadowOffsetX, double shadowOffsetY, double scale); - void collectPage(unsigned id, unsigned level, unsigned backgroundPageID, bool isBackgroundPage, const WPXString &pageName); + void collectPage(unsigned id, unsigned level, unsigned backgroundPageID, bool isBackgroundPage, const VSDName &pageName); void collectShape(unsigned id, unsigned level, unsigned parent, unsigned masterPage, unsigned masterShape, unsigned lineStyle, unsigned fillStyle, unsigned textStyle); void collectSplineStart(unsigned id, unsigned level, double x, double y, double secondKnot, double firstKnot, double lastKnot, unsigned degree); void collectSplineKnot(unsigned id, unsigned level, double x, double y, double knot); diff --git a/src/lib/VSDTypes.h b/src/lib/VSDTypes.h index ba90396..08e4e76 100644 --- a/src/lib/VSDTypes.h +++ b/src/lib/VSDTypes.h @@ -184,6 +184,10 @@ public: m_format(format) {} VSDName() : m_data(), m_format(VSD_TEXT_ANSI) {} VSDName(const VSDName &name) : m_data(name.m_data), m_format(name.m_format) {} + bool empty() const + { + return !m_data.size(); + } WPXBinaryData m_data; TextFormat m_format; }; diff --git a/src/lib/VSDXMLParserBase.cpp b/src/lib/VSDXMLParserBase.cpp index 2885f45..64e1e79 100644 --- a/src/lib/VSDXMLParserBase.cpp +++ b/src/lib/VSDXMLParserBase.cpp @@ -1105,7 +1105,7 @@ void libvisio::VSDXMLParserBase::readPage(xmlTextReaderPtr reader) bool isBackgroundPage = background ? xmlStringToBool(background) : false; m_isPageStarted = true; m_collector->startPage(nId); - m_collector->collectPage(nId, (unsigned)getElementDepth(reader), backgroundPageID, isBackgroundPage, pageName ? WPXString((const char *)pageName) : WPXString()); + m_collector->collectPage(nId, (unsigned)getElementDepth(reader), backgroundPageID, isBackgroundPage, pageName ? VSDName(WPXBinaryData(pageName, xmlStrlen(pageName)), VSD_TEXT_UTF8) : VSDName()); } if (id) xmlFree(id); |