src/lib/VSDXTheme.cpp                             |    8 ++++-
 src/test/data/tdf154379-QuickStyleFillMatrix.vsdx |binary
 src/test/importtest.cpp                           |   32 +++++++++++++++++++---
 3 files changed, 35 insertions(+), 5 deletions(-)

New commits:
commit a63cf4a0aa11be22a6a6bb5de3d445d5147bc16f
Author:     Bartosz Kosiorek <[email protected]>
AuthorDate: Tue Oct 8 17:32:07 2024 +0200
Commit:     Bartosz Kosiorek <[email protected]>
CommitDate: Thu Oct 10 00:46:16 2024 +0200

    tdf#154379 Fix reading FillStyleLst
    
    With previous implementation readFillStyleLst method
    is saving all colours into first element: m_fillStyleLst[0]
    It was causing that only last colour was present.
    
    This commit is fixing that issue, by increasing iterator.
    
    Change-Id: Ib77463c582874967e255ef91c0380fd880b8418e
    Reviewed-on: https://gerrit.libreoffice.org/c/libvisio/+/174698
    Reviewed-by: Bartosz Kosiorek <[email protected]>
    Tested-by: Bartosz Kosiorek <[email protected]>

diff --git a/src/lib/VSDXTheme.cpp b/src/lib/VSDXTheme.cpp
index 537e2ad..06ba95c 100644
--- a/src/lib/VSDXTheme.cpp
+++ b/src/lib/VSDXTheme.cpp
@@ -555,7 +555,7 @@ void libvisio::VSDXTheme::readFillStyleLst(xmlTextReaderPtr 
reader)
     VSD_DEBUG_MSG(("VSDXTheme::readFillStyleLst: unknown token %s
", xmlTextReaderConstName(reader)));
   }
   int tokenType = xmlTextReaderNodeType(reader);
-  int i = 0;
+  std::size_t i = 0;
   while ((XML_A_FILLSTYLELST != tokenId || XML_READER_TYPE_END_ELEMENT != 
tokenType) && 1 == ret)
   {
     switch (tokenId)
@@ -565,7 +565,10 @@ void 
libvisio::VSDXTheme::readFillStyleLst(xmlTextReaderPtr reader)
       Colour colour;
       if (readThemeColour(reader, tokenId, colour))
       {
-        m_fillStyleLst[i] = colour;
+        if (i < m_fillStyleLst.size())
+          m_fillStyleLst[i] = colour;
+        else
+          VSD_DEBUG_MSG(("VSDXTheme::readFillStyleLst Error: Unable to add 
colour #%02x%02x%02x
", colour.r, colour.g, colour.b));
       }
       break;
     }
@@ -581,6 +584,7 @@ void libvisio::VSDXTheme::readFillStyleLst(xmlTextReaderPtr 
reader)
       VSD_DEBUG_MSG(("VSDXTheme::readFillStyleLst: unknown token %s
", xmlTextReaderConstName(reader)));
     }
     tokenType = xmlTextReaderNodeType(reader);
+    i++;
   }
 }
 
diff --git a/src/test/data/tdf154379-QuickStyleFillMatrix.vsdx 
b/src/test/data/tdf154379-QuickStyleFillMatrix.vsdx
new file mode 100644
index 0000000..b561b10
Binary files /dev/null and b/src/test/data/tdf154379-QuickStyleFillMatrix.vsdx 
differ
diff --git a/src/test/importtest.cpp b/src/test/importtest.cpp
index 1dc4945..a4380b1 100644
--- a/src/test/importtest.cpp
+++ b/src/test/importtest.cpp
@@ -219,7 +219,8 @@ class ImportTest : public CPPUNIT_NS::TestFixture
   CPPUNIT_TEST(testBmpFileHeader);
   CPPUNIT_TEST(testBmpFileHeader2);
   CPPUNIT_TEST(testVsdxImportDefaultFillColour);
-  CPPUNIT_TEST(testVsdxQickStyleFillStyle);
+  CPPUNIT_TEST(testVsdxQuickStyleFillMatrix);
+  CPPUNIT_TEST(testVsdxQuickStyleFillStyle);
   CPPUNIT_TEST_SUITE_END();
 
   void testVsdxMetadataTitle();
@@ -239,7 +240,8 @@ class ImportTest : public CPPUNIT_NS::TestFixture
   void testBmpFileHeader();
   void testBmpFileHeader2();
   void testVsdxImportDefaultFillColour();
-  void testVsdxQickStyleFillStyle();
+  void testVsdxQuickStyleFillMatrix();
+  void testVsdxQuickStyleFillStyle();
 
   xmlBufferPtr m_buffer;
   xmlDocPtr m_doc;
@@ -555,7 +557,31 @@ void ImportTest::testVsdxImportDefaultFillColour()
   assertXPath(m_doc, "/document/page/layer[1]//setStyle[2]", "fill-color", 
"#5b9bd5");
 }
 
-void ImportTest::testVsdxQickStyleFillStyle()
+void ImportTest::testVsdxQuickStyleFillMatrix()
+{
+  // Without the accompanying fix in place, this test would have failed with:
+  // equality assertion failed
+  // - Expected: #ffffff
+  // - Actual  : #5b9bd5
+  // - Attribute 'fill-color' of '/document/page/layer/layer/setStyle[1]': 
incorrect value.
+
+  m_doc = parse("tdf154379-QuickStyleFillMatrix.vsdx", m_buffer);
+  assertXPath(m_doc, "/document/page/layer/layer/setStyle[1]", "fill", 
"solid");
+  assertXPath(m_doc, "/document/page/layer/layer/setStyle[1]", "fill-color", 
"#ffffff");
+  assertXPath(m_doc, "/document/page/layer/layer/setStyle[1]", "stroke-color", 
"#5b9bd5");
+  assertXPath(m_doc, "/document/page/layer/layer/setStyle[2]", "fill", "none");
+  assertXPath(m_doc, "/document/page/layer/layer/setStyle[2]", "fill-color", 
"#ffffff");
+  assertXPath(m_doc, "/document/page/layer/layer/setStyle[2]", "stroke-color", 
"#5b9bd5");
+
+  assertXPath(m_doc, "/document/page/layer/textObject/paragraph[1]/span", 
"color", "#5b9bd5");
+  // TODO assertXPath(m_doc, 
"/document/page/layer/textObject/paragraph[1]/span", "background-color", 
"#ffffff");
+  assertXPathContent(m_doc, 
"/document/page/layer/textObject/paragraph[1]/span/insertText", " 
Kommissionierungs");
+  assertXPath(m_doc, "/document/page/layer/textObject/paragraph[1]/span", 
"color", "#5b9bd5");
+  // TODO assertXPath(m_doc, 
"/document/page/layer/textObject/paragraph[2]/span", "background-color", 
"#ffffff");
+  assertXPathContent(m_doc, 
"/document/page/layer/textObject/paragraph[2]/span/insertText", "Beleg ");
+}
+
+void ImportTest::testVsdxQuickStyleFillStyle()
 {
   // Without the accompanying fix in place, this test would have failed with:
   // equality assertion failed

Reply via email to