From 296365202a94801885625350817522c2d6ef1587 Mon Sep 17 00:00:00 2001 From: Fridrich Štrba Date: Mon, 18 Jul 2016 11:43:54 +0200 Subject: If not line/fill is specified, thy the styles first Change-Id: I54a687cedf5c2a6b0a93ad578158762b317279ee --- src/lib/CDRCollector.h | 1 + src/lib/CDRContentCollector.cpp | 28 +++++++++++++++++++++++----- src/lib/CDRContentCollector.h | 3 ++- src/lib/CDRParser.cpp | 4 +++- src/lib/CDRStylesCollector.h | 1 + src/lib/CMXParser.cpp | 12 +++++------- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/lib/CDRCollector.h b/src/lib/CDRCollector.h index ead8d17..32d1c55 100644 --- a/src/lib/CDRCollector.h +++ b/src/lib/CDRCollector.h @@ -100,6 +100,7 @@ public: virtual void collectArtisticText(double x, double y) = 0; virtual void collectParagraphText(double x, double y, double width, double height) = 0; virtual void collectStld(unsigned id, const CDRStyle &style) = 0; + virtual void collectStyleId(unsigned id) = 0; }; } // namespace libcdr diff --git a/src/lib/CDRContentCollector.cpp b/src/lib/CDRContentCollector.cpp index e19a6f8..860bf30 100644 --- a/src/lib/CDRContentCollector.cpp +++ b/src/lib/CDRContentCollector.cpp @@ -61,7 +61,7 @@ libcdr::CDRContentCollector::CDRContentCollector(libcdr::CDRParserState &ps, lib : m_painter(painter), m_isDocumentStarted(false), m_isPageProperties(false), m_isPageStarted(false), m_ignorePage(false), m_page(ps.m_pages[0]), m_pageIndex(0), m_currentFillStyle(), m_currentLineStyle(), m_spnd(0), m_currentObjectLevel(0), m_currentGroupLevel(0), m_currentVectLevel(0), m_currentPageLevel(0), - m_currentImage(), m_currentText(0), m_currentBBox(), m_currentTextBox(), m_currentPath(), + m_currentStyleId(0), m_currentImage(), m_currentText(0), m_currentBBox(), m_currentTextBox(), m_currentPath(), m_currentTransforms(), m_fillTransforms(), m_polygon(0), m_isInPolygon(false), m_isInSpline(false), m_outputElementsStack(0), m_contentOutputElementsStack(), m_fillOutputElementsStack(), m_outputElementsQueue(0), m_contentOutputElementsQueue(), m_fillOutputElementsQueue(), @@ -150,6 +150,7 @@ void libcdr::CDRContentCollector::collectObject(unsigned level) m_currentObjectLevel = level; m_currentFillStyle = CDRFillStyle(); m_currentLineStyle = CDRLineStyle(); + m_currentStyleId = 0; m_currentBBox = CDRBox(); } @@ -681,6 +682,13 @@ void libcdr::CDRContentCollector::collectPolygonTransform(unsigned numAngles, un void libcdr::CDRContentCollector::_fillProperties(librevenge::RVNGPropertyList &propList) { + if (m_currentFillStyle.fillType == (unsigned short)-1 && m_currentStyleId) + { + CDRStyle tmpStyle; + m_ps.getRecursedStyle(tmpStyle, m_currentStyleId); + m_currentFillStyle = tmpStyle.m_fillStyle; + } + if (m_fillOpacity < 1.0) propList.insert("draw:opacity", m_fillOpacity, librevenge::RVNG_PERCENT); if (m_currentFillStyle.fillType == 0) @@ -994,12 +1002,17 @@ void libcdr::CDRContentCollector::_fillProperties(librevenge::RVNGPropertyList & void libcdr::CDRContentCollector::_lineProperties(librevenge::RVNGPropertyList &propList) { - if (m_currentLineStyle.lineType == (unsigned short)-1) + if (m_currentLineStyle.lineType == (unsigned short)-1 && m_currentStyleId) { - propList.insert("draw:stroke", "solid"); - propList.insert("svg:stroke-width", 0.0); - propList.insert("svg:stroke-color", "#000000"); + CDRStyle tmpStyle; + m_ps.getRecursedStyle(tmpStyle, m_currentStyleId); + m_currentLineStyle = tmpStyle.m_lineStyle; } + + if (m_currentLineStyle.lineType == (unsigned short)-1) + /* No line style specified and also no line style from the style id, + the shape has no outline then. */ + propList.insert("draw:stroke", "none"); else { if (m_currentLineStyle.lineType & 0x1) @@ -1315,4 +1328,9 @@ void libcdr::CDRContentCollector::collectParagraphText(double x, double y, doubl m_currentText = &(iter->second); } +void libcdr::CDRContentCollector::collectStyleId(unsigned styleId) +{ + m_currentStyleId = styleId; +} + /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/CDRContentCollector.h b/src/lib/CDRContentCollector.h index 517692a..2261454 100644 --- a/src/lib/CDRContentCollector.h +++ b/src/lib/CDRContentCollector.h @@ -66,6 +66,7 @@ public: void collectArtisticText(double x, double y); void collectParagraphText(double x, double y, double width, double height); void collectStld(unsigned, const CDRStyle &) {} + void collectStyleId(unsigned styleId); private: CDRContentCollector(const CDRContentCollector &); @@ -94,7 +95,7 @@ private: CDRFillStyle m_currentFillStyle; CDRLineStyle m_currentLineStyle; unsigned m_spnd; - unsigned m_currentObjectLevel, m_currentGroupLevel, m_currentVectLevel, m_currentPageLevel; + unsigned m_currentObjectLevel, m_currentGroupLevel, m_currentVectLevel, m_currentPageLevel, m_currentStyleId; CDRImage m_currentImage; const std::vector *m_currentText; CDRBox m_currentBBox; diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp index 76a8024..db463eb 100644 --- a/src/lib/CDRParser.cpp +++ b/src/lib/CDRParser.cpp @@ -2160,7 +2160,9 @@ void libcdr::CDRParser::readLoda(librevenge::RVNGInputStream *input, unsigned le } else if (argTypes[i] == 0xc8) { - // TODO: Handle styles + unsigned styleId = readUnsigned(input); + if (styleId) + m_collector->collectStyleId(styleId); } else if (argTypes[i] == 0x2af8) readPolygonTransform(input); diff --git a/src/lib/CDRStylesCollector.h b/src/lib/CDRStylesCollector.h index 2183376..8b1433d 100644 --- a/src/lib/CDRStylesCollector.h +++ b/src/lib/CDRStylesCollector.h @@ -65,6 +65,7 @@ public: void collectArtisticText(double, double) {} void collectParagraphText(double, double, double, double) {} void collectStld(unsigned id, const CDRStyle &style); + void collectStyleId(unsigned) {} private: CDRStylesCollector(const CDRStylesCollector &); diff --git a/src/lib/CMXParser.cpp b/src/lib/CMXParser.cpp index 324ca0c..bf3f818 100644 --- a/src/lib/CMXParser.cpp +++ b/src/lib/CMXParser.cpp @@ -1411,9 +1411,9 @@ bool libcdr::CMXParser::readRenderingAttributes(librevenge::RVNGInputStream *inp return false; } } - CDRLineStyle lineStyle; if (bitMask & 0x02) // outline { + CDRLineStyle lineStyle; if (m_precision == libcdr::PRECISION_32BIT) { do @@ -1444,13 +1444,11 @@ 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); } - else - lineStyle.lineType = 1; - m_collector->collectLineStyle(lineStyle.lineType, lineStyle.capsType, lineStyle.joinType, - lineStyle.lineWidth, lineStyle.stretch, lineStyle.angle, - lineStyle.color, lineStyle.dashArray, - lineStyle.startMarker, lineStyle.endMarker); if (bitMask & 0x04) // lens { if (m_precision == libcdr::PRECISION_32BIT) -- cgit v1.2.3