diff options
author | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2015-12-12 10:04:48 +0100 |
---|---|---|
committer | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2015-12-12 10:04:48 +0100 |
commit | 06df5223293979bee7e781e8c88d76b4c3fe134b (patch) | |
tree | 32cfefa132cf6add0133858ebcf82e0b0c7ff2d9 | |
parent | 0099751db287f87e6d5b1dee5d2ef2479040d188 (diff) |
Some improvements to the layer colours + make xml parsers work
Change-Id: I78bfed0ec539fc1c034123c90ad27a9e48693232
-rw-r--r-- | src/lib/VSDLayerList.cpp | 36 | ||||
-rw-r--r-- | src/lib/VSDLayerList.h | 5 | ||||
-rw-r--r-- | src/lib/VSDParser.cpp | 16 | ||||
-rw-r--r-- | src/lib/VSDTypes.h | 6 | ||||
-rw-r--r-- | src/lib/VSDXMLParserBase.cpp | 7 | ||||
-rw-r--r-- | src/lib/VSDXParser.cpp | 8 |
6 files changed, 22 insertions, 56 deletions
diff --git a/src/lib/VSDLayerList.cpp b/src/lib/VSDLayerList.cpp index ca638d4..6ebbbd6 100644 --- a/src/lib/VSDLayerList.cpp +++ b/src/lib/VSDLayerList.cpp @@ -9,11 +9,9 @@ #include "VSDLayerList.h" -libvisio::VSDLayer::VSDLayer() : - m_colourId(MINUS_ONE), m_colour() {} +libvisio::VSDLayer::VSDLayer() : m_colour() {} -libvisio::VSDLayer::VSDLayer(const VSDLayer &layer) : - m_colourId(layer.m_colourId), m_colour(layer.m_colour) {} +libvisio::VSDLayer::VSDLayer(const VSDLayer &layer) : m_colour(layer.m_colour) {} libvisio::VSDLayer::~VSDLayer() {} @@ -21,7 +19,6 @@ libvisio::VSDLayer &libvisio::VSDLayer::operator=(const libvisio::VSDLayer &laye { if (this != &layer) { - m_colourId = layer.m_colourId; m_colour = layer.m_colour; } return *this; @@ -67,48 +64,25 @@ void libvisio::VSDLayerList::addLayer(unsigned id, const libvisio::VSDLayer &lay m_elements[id] = layer; } -unsigned libvisio::VSDLayerList::getColourId(const std::vector<unsigned> &ids) -{ - unsigned colourId = MINUS_ONE; - for (std::vector<unsigned>::const_iterator iter = ids.begin(); iter != ids.end(); ++iter) - { - std::map<unsigned, libvisio::VSDLayer>::const_iterator iterMap = m_elements.find(*iter); - // It is enough that one layer does not override colour and the original colour is used - if (iterMap->second.m_colourId == MINUS_ONE) - return MINUS_ONE; - // This means we are reading the first layer and it overrides colour - else if (colourId == MINUS_ONE) - colourId = iterMap->second.m_colourId; - // If two layers override colour to two different values, the original colour is used - else if (colourId != iterMap->second.m_colourId) - return MINUS_ONE; - } - return colourId; -} - const libvisio::Colour *libvisio::VSDLayerList::getColour(const std::vector<unsigned> &ids) { - unsigned colourId = MINUS_ONE; std::map<unsigned, libvisio::VSDLayer>::const_iterator iterColour = m_elements.end(); for (std::vector<unsigned>::const_iterator iter = ids.begin(); iter != ids.end(); ++iter) { std::map<unsigned, libvisio::VSDLayer>::const_iterator iterMap = m_elements.find(*iter); // It is enough that one layer does not override colour and the original colour is used - if (iterMap->second.m_colourId == MINUS_ONE) + if (!iterMap->second.m_colour) return 0; // This means we are reading the first layer and it overrides colour else if (iterColour == m_elements.end()) - { - colourId = iterMap->second.m_colourId; iterColour = iterMap; - } // If two layers override colour to two different values, the original colour is used - else if (colourId != iterMap->second.m_colourId) + else if (!iterColour->second.m_colour || iterColour->second.m_colour.get() != iterMap->second.m_colour.get()) return 0; } if (iterColour == m_elements.end()) return 0; - return &(iterColour->second.m_colour); + return iterColour->second.m_colour.get_ptr(); } /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/VSDLayerList.h b/src/lib/VSDLayerList.h index aa45e14..c9cbb43 100644 --- a/src/lib/VSDLayerList.h +++ b/src/lib/VSDLayerList.h @@ -12,6 +12,7 @@ #include <map> #include <vector> +#include <boost/optional.hpp> #include "VSDTypes.h" namespace libvisio @@ -24,8 +25,7 @@ struct VSDLayer ~VSDLayer(); VSDLayer &operator=(const VSDLayer &layer); - unsigned m_colourId; - Colour m_colour; + boost::optional<Colour> m_colour; }; class VSDLayerList @@ -40,7 +40,6 @@ public: void addLayer(unsigned id, const VSDLayer &layer); - unsigned getColourId(const std::vector<unsigned> &ids); const Colour *getColour(const std::vector<unsigned> &ids); private: diff --git a/src/lib/VSDParser.cpp b/src/lib/VSDParser.cpp index 4ecf8d4..e3cd622 100644 --- a/src/lib/VSDParser.cpp +++ b/src/lib/VSDParser.cpp @@ -960,21 +960,19 @@ void libvisio::VSDParser::readLayerList(librevenge::RVNGInputStream *input) void libvisio::VSDParser::readLayer(librevenge::RVNGInputStream *input) { - VSDLayer layer; + libvisio::VSDLayer layer; input->seek(8, librevenge::RVNG_SEEK_CUR); unsigned char colourId = readU8(input); if (colourId == 0xff) - { - layer.m_colourId = MINUS_ONE; input->seek(4, librevenge::RVNG_SEEK_CUR); - } else { - layer.m_colourId = colourId; - layer.m_colour.r = readU8(input); - layer.m_colour.g = readU8(input); - layer.m_colour.b = readU8(input); - layer.m_colour.a = readU8(input); + libvisio::Colour colour; + colour.r = readU8(input); + colour.g = readU8(input); + colour.b = readU8(input); + colour.a = readU8(input); + layer.m_colour = colour; } m_collector->collectLayer(m_header.id, m_header.level, layer); diff --git a/src/lib/VSDTypes.h b/src/lib/VSDTypes.h index 5ac4593..9492844 100644 --- a/src/lib/VSDTypes.h +++ b/src/lib/VSDTypes.h @@ -74,15 +74,15 @@ struct Colour Colour(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha) : r(red), g(green), b(blue), a(alpha) {} Colour() : r(0), g(0), b(0), a(0) {} - inline bool operator==(const Colour &col) + inline bool operator==(const Colour &col) const { return ((r == col.r) && (g == col.g) && (b == col.b) && (a == col.a)); } - inline bool operator!=(const Colour &col) + inline bool operator!=(const Colour &col) const { return !operator==(col); } - inline bool operator!() + inline bool operator!() const { return (!r && !g && !b && !a); } diff --git a/src/lib/VSDXMLParserBase.cpp b/src/lib/VSDXMLParserBase.cpp index 2db6b39..5eb1fea 100644 --- a/src/lib/VSDXMLParserBase.cpp +++ b/src/lib/VSDXMLParserBase.cpp @@ -1369,13 +1369,8 @@ void libvisio::VSDXMLParserBase::readLayerIX(xmlTextReaderPtr reader) Colour colour; long idx; ret = readExtendedColourData(colour, idx, reader); - if (idx < 0 || idx >= 255) - layer.m_colourId = MINUS_ONE; - else - { - layer.m_colourId = idx; + if (idx != 255) layer.m_colour = colour; - } } break; default: diff --git a/src/lib/VSDXParser.cpp b/src/lib/VSDXParser.cpp index fe8497e..37351b9 100644 --- a/src/lib/VSDXParser.cpp +++ b/src/lib/VSDXParser.cpp @@ -649,6 +649,10 @@ void libvisio::VSDXParser::readPageSheetProperties(xmlTextReaderPtr reader) if (XML_READER_TYPE_ELEMENT == tokenType) ret = readDoubleData(drawingScale, reader); break; + case XML_LAYER: + if (XML_READER_TYPE_ELEMENT == tokenType) + readLayer(reader); + break; default: break; } @@ -845,10 +849,6 @@ void libvisio::VSDXParser::readStyleProperties(xmlTextReaderPtr reader) if (XML_READER_TYPE_ELEMENT == tokenType) ret = readByteData(textDirection, reader); break; - case XML_LAYER: - if (XML_READER_TYPE_ELEMENT == tokenType) - readLayer(reader); - break; case XML_PARAGRAPH: if (XML_READER_TYPE_ELEMENT == tokenType) readParagraph(reader); |