summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/VSDXTheme.cpp179
-rw-r--r--src/lib/VSDXTheme.h10
2 files changed, 184 insertions, 5 deletions
diff --git a/src/lib/VSDXTheme.cpp b/src/lib/VSDXTheme.cpp
index a0388f0..97be35d 100644
--- a/src/lib/VSDXTheme.cpp
+++ b/src/lib/VSDXTheme.cpp
@@ -39,6 +39,12 @@ libvisio::VSDXTheme::~VSDXTheme()
{
}
+
+int libvisio::VSDXTheme::getElementToken(xmlTextReaderPtr reader)
+{
+ return VSDXMLTokenMap::getTokenId(xmlTextReaderConstName(reader));
+}
+
bool libvisio::VSDXTheme::parse(WPXInputStream *input)
{
if (!input)
@@ -53,8 +59,7 @@ bool libvisio::VSDXTheme::parse(WPXInputStream *input)
int ret = xmlTextReaderRead(reader);
while (1 == ret)
{
- int tokenId = VSDXMLTokenMap::getTokenId(xmlTextReaderConstName(reader));
- int tokenType = xmlTextReaderNodeType(reader);
+ int tokenId = getElementToken(reader);
switch (tokenId)
{
@@ -79,7 +84,7 @@ bool libvisio::VSDXTheme::parse(WPXInputStream *input)
boost::optional<libvisio::Colour> libvisio::VSDXTheme::readSrgbClr(xmlTextReaderPtr reader)
{
boost::optional<libvisio::Colour> retVal;
- if (XML_A_SRGBCLR == VSDXMLTokenMap::getTokenId(xmlTextReaderConstName(reader)))
+ if (XML_A_SRGBCLR == getElementToken(reader))
{
xmlChar *val = xmlTextReaderGetAttribute(reader, BAD_CAST("val"));
if (val)
@@ -100,7 +105,7 @@ boost::optional<libvisio::Colour> libvisio::VSDXTheme::readSrgbClr(xmlTextReader
boost::optional<libvisio::Colour> libvisio::VSDXTheme::readSysClr(xmlTextReaderPtr reader)
{
boost::optional<libvisio::Colour> retVal;
- if (XML_A_SYSCLR == VSDXMLTokenMap::getTokenId(xmlTextReaderConstName(reader)))
+ if (XML_A_SYSCLR == getElementToken(reader))
{
xmlChar *lastClr = xmlTextReaderGetAttribute(reader, BAD_CAST("lastClr"));
if (lastClr)
@@ -120,6 +125,172 @@ boost::optional<libvisio::Colour> libvisio::VSDXTheme::readSysClr(xmlTextReaderP
void libvisio::VSDXTheme::readClrScheme(xmlTextReaderPtr reader)
{
+ int ret = 1;
+ int tokenId = XML_TOKEN_INVALID;
+ int tokenType = -1;
+ m_clrScheme.m_variationClrSchemeLst.clear();
+ do
+ {
+ ret = xmlTextReaderRead(reader);
+ tokenId = getElementToken(reader);
+ if (XML_TOKEN_INVALID == tokenId)
+ {
+ VSD_DEBUG_MSG(("VSDXTheme::readClrScheme: unknown token %s\n", xmlTextReaderConstName(reader)));
+ }
+ tokenType = xmlTextReaderNodeType(reader);
+ switch (tokenId)
+ {
+ case XML_A_SRGBCLR:
+ readThemeColour(reader, tokenId, m_clrScheme.m_dk1);
+ break;
+ case XML_A_DK2:
+ readThemeColour(reader, tokenId, m_clrScheme.m_dk2);
+ break;
+ case XML_A_LT1:
+ readThemeColour(reader, tokenId, m_clrScheme.m_lt1);
+ break;
+ case XML_A_LT2:
+ readThemeColour(reader, tokenId, m_clrScheme.m_lt2);
+ break;
+ case XML_A_ACCENT1:
+ readThemeColour(reader, tokenId, m_clrScheme.m_accent1);
+ break;
+ case XML_A_ACCENT2:
+ readThemeColour(reader, tokenId, m_clrScheme.m_accent2);
+ break;
+ case XML_A_ACCENT3:
+ readThemeColour(reader, tokenId, m_clrScheme.m_accent3);
+ break;
+ case XML_A_ACCENT4:
+ readThemeColour(reader, tokenId, m_clrScheme.m_accent4);
+ break;
+ case XML_A_ACCENT5:
+ readThemeColour(reader, tokenId, m_clrScheme.m_accent5);
+ break;
+ case XML_A_ACCENT6:
+ readThemeColour(reader, tokenId, m_clrScheme.m_accent6);
+ break;
+ case XML_A_HLINK:
+ readThemeColour(reader, tokenId, m_clrScheme.m_hlink);
+ break;
+ case XML_A_FOLHLINK:
+ readThemeColour(reader, tokenId, m_clrScheme.m_folHlink);
+ break;
+ case XML_VT_VARIATIONCLRSCHEMELST:
+ readVariationClrSchemeLst(reader);
+ break;
+ default:
+ break;
+ }
+ }
+ while ((XML_A_CLRSCHEME != tokenId || XML_READER_TYPE_END_ELEMENT != tokenType) && 1 == ret);
+}
+
+void libvisio::VSDXTheme::readThemeColour(xmlTextReaderPtr reader, int idToken, Colour &clr)
+{
+ int ret = 1;
+ int tokenId = XML_TOKEN_INVALID;
+ int tokenType = -1;
+ boost::optional<libvisio::Colour> colour;
+ do
+ {
+ ret = xmlTextReaderRead(reader);
+ tokenId = getElementToken(reader);
+ if (XML_TOKEN_INVALID == tokenId)
+ {
+ VSD_DEBUG_MSG(("VSDXTheme::readThemeColour: unknown token %s\n", xmlTextReaderConstName(reader)));
+ }
+ tokenType = xmlTextReaderNodeType(reader);
+ switch (tokenId)
+ {
+ case XML_A_SRGBCLR:
+ colour = readSrgbClr(reader);
+ break;
+ case XML_A_SYSCLR:
+ colour = readSysClr(reader);
+ break;
+ default:
+ break;
+ }
+ }
+ while ((idToken != tokenId || XML_READER_TYPE_END_ELEMENT != tokenType) && 1 == ret);
+
+ if (colour)
+ clr = *colour;
+}
+
+void libvisio::VSDXTheme::readVariationClrSchemeLst(xmlTextReaderPtr reader)
+{
+ int ret = 1;
+ int tokenId = XML_TOKEN_INVALID;
+ int tokenType = -1;
+ do
+ {
+ ret = xmlTextReaderRead(reader);
+ tokenId = getElementToken(reader);
+ if (XML_TOKEN_INVALID == tokenId)
+ {
+ VSD_DEBUG_MSG(("VSDXTheme::readVariationClrSchemeLst: unknown token %s\n", xmlTextReaderConstName(reader)));
+ }
+ tokenType = xmlTextReaderNodeType(reader);
+ switch (tokenId)
+ {
+ case XML_VT_VARIATIONSTYLESCHEME:
+ {
+ VSDXVariationClrScheme varClrSch;
+ readVariationClrScheme(reader, varClrSch);
+ m_clrScheme.m_variationClrSchemeLst.push_back(varClrSch);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ while ((XML_VT_VARIATIONSTYLESCHEMELST != tokenId || XML_READER_TYPE_END_ELEMENT != tokenType) && 1 == ret);
+}
+
+void libvisio::VSDXTheme::readVariationClrScheme(xmlTextReaderPtr reader, VSDXVariationClrScheme &varClrSch)
+{
+ int ret = 1;
+ int tokenId = XML_TOKEN_INVALID;
+ int tokenType = -1;
+ do
+ {
+ ret = xmlTextReaderRead(reader);
+ tokenId = getElementToken(reader);
+ if (XML_TOKEN_INVALID == tokenId)
+ {
+ VSD_DEBUG_MSG(("VSDXTheme::readVariationClrScheme: unknown token %s\n", xmlTextReaderConstName(reader)));
+ }
+ tokenType = xmlTextReaderNodeType(reader);
+ switch (tokenId)
+ {
+ case XML_VT_VARCOLOR1:
+ readThemeColour(reader, tokenId, varClrSch.m_varColor1);
+ break;
+ case XML_VT_VARCOLOR2:
+ readThemeColour(reader, tokenId, varClrSch.m_varColor2);
+ break;
+ case XML_VT_VARCOLOR3:
+ readThemeColour(reader, tokenId, varClrSch.m_varColor3);
+ break;
+ case XML_VT_VARCOLOR4:
+ readThemeColour(reader, tokenId, varClrSch.m_varColor4);
+ break;
+ case XML_VT_VARCOLOR5:
+ readThemeColour(reader, tokenId, varClrSch.m_varColor5);
+ break;
+ case XML_VT_VARCOLOR6:
+ readThemeColour(reader, tokenId, varClrSch.m_varColor6);
+ break;
+ case XML_VT_VARCOLOR7:
+ readThemeColour(reader, tokenId, varClrSch.m_varColor7);
+ break;
+ default:
+ break;
+ }
+ }
+ while ((XML_VT_VARIATIONSTYLESCHEME != tokenId || XML_READER_TYPE_END_ELEMENT != tokenType) && 1 == ret);
}
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/lib/VSDXTheme.h b/src/lib/VSDXTheme.h
index 2e1101f..bb8b7e9 100644
--- a/src/lib/VSDXTheme.h
+++ b/src/lib/VSDXTheme.h
@@ -30,6 +30,7 @@
#ifndef __VSDXTHEME_H__
#define __VSDXTHEME_H__
+#include <vector>
#include <boost/optional.hpp>
#include <libwpd-stream/libwpd-stream.h>
#include "VSDXMLHelper.h"
@@ -64,7 +65,7 @@ struct VSDXClrScheme
Colour m_accent6;
Colour m_hlink;
Colour m_folHlink;
- std::vector<VSDXVariationClrScheme> variationClrSchemeLst;
+ std::vector<VSDXVariationClrScheme> m_variationClrSchemeLst;
};
class VSDXTheme
@@ -82,6 +83,13 @@ private:
boost::optional<Colour> readSysClr(xmlTextReaderPtr reader);
void readClrScheme(xmlTextReaderPtr reader);
+ void readThemeColour(xmlTextReaderPtr reader, int idToken, Colour &clr);
+ void readVariationClrSchemeLst(xmlTextReaderPtr reader);
+ void readVariationClrScheme(xmlTextReaderPtr reader, VSDXVariationClrScheme &varClrSch);
+
+ int getElementToken(xmlTextReaderPtr reader);
+
+ VSDXClrScheme m_clrScheme;
};
} // namespace libvisio