summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorRegina Henschel <rb.henschel@t-online.de>2023-01-03 20:13:12 +0100
committerRegina Henschel <rb.henschel@t-online.de>2023-01-05 09:13:37 +0000
commitf4a568fc0553603fbf05477e0942af4e8466fba0 (patch)
tree55cd3b8556c83bff6b4b7f1ea27fc910d253b4ec /oox
parentbb20dee2ef1b0804065e1cda2c834d257fdd90ed (diff)
tdf#152840 add ST_ThemeColor values to ClrScheme::getColor
... and Color::getSchemeColorIndex(). Without the fix it was not in all cases detected, that a theme color was used, so the FillColorTheme or the CharColorTheme property had got value '-1'. In case of WordArt in docx import, the color could not be determined and the text was black. Change-Id: I81cdb22d6b3c30bf9923b9069ba2e384ac5b3a1c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145021 Tested-by: Jenkins Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
Diffstat (limited to 'oox')
-rw-r--r--oox/qa/unit/data/tdf152840_WordArt_non_accent_color.docxbin0 -> 21925 bytes
-rw-r--r--oox/qa/unit/data/tdf152840_theme_color_non_accent.docxbin0 -> 22932 bytes
-rw-r--r--oox/qa/unit/shape.cxx59
-rw-r--r--oox/source/drawingml/clrscheme.cxx10
-rw-r--r--oox/source/drawingml/color.cxx6
5 files changed, 74 insertions, 1 deletions
diff --git a/oox/qa/unit/data/tdf152840_WordArt_non_accent_color.docx b/oox/qa/unit/data/tdf152840_WordArt_non_accent_color.docx
new file mode 100644
index 000000000000..877722037206
--- /dev/null
+++ b/oox/qa/unit/data/tdf152840_WordArt_non_accent_color.docx
Binary files differ
diff --git a/oox/qa/unit/data/tdf152840_theme_color_non_accent.docx b/oox/qa/unit/data/tdf152840_theme_color_non_accent.docx
new file mode 100644
index 000000000000..2bb4e1340e51
--- /dev/null
+++ b/oox/qa/unit/data/tdf152840_theme_color_non_accent.docx
Binary files differ
diff --git a/oox/qa/unit/shape.cxx b/oox/qa/unit/shape.cxx
index 094687ffe1df..3997494eb21c 100644
--- a/oox/qa/unit/shape.cxx
+++ b/oox/qa/unit/shape.cxx
@@ -500,6 +500,65 @@ CPPUNIT_TEST_FIXTURE(OoxShapeTest, testWriterFontwork3)
}
}
+CPPUNIT_TEST_FIXTURE(OoxShapeTest, testWriterFontworkNonAccentColor)
+{
+ loadFromURL(u"tdf152840_WordArt_non_accent_color.docx");
+ // The file contains WordArt which uses the theme colors "Background 1", "Text 1", "Background 2"
+ // and "Text 2".
+
+ uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+ uno::UNO_QUERY);
+
+ // The ID for the theme colors is not yet in API, but definied in enum PredefinedClrSchemeID
+ // in drawingml/clrscheme.hxx. Without fix the ID was -1 meaning no theme is used, and the color
+ // was Black (=0).
+
+ // background 1 = lt1 = ID 1
+ uno::Reference<beans::XPropertySet> xShape0Props(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(1)), xShape0Props->getPropertyValue(u"FillColorTheme"));
+ CPPUNIT_ASSERT_EQUAL(uno::Any(Color(255, 204, 153)),
+ xShape0Props->getPropertyValue(u"FillColor"));
+
+ // text 1 = dk1 = ID 0
+ uno::Reference<beans::XPropertySet> xShape1Props(xDrawPage->getByIndex(1), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(0)), xShape1Props->getPropertyValue(u"FillColorTheme"));
+ CPPUNIT_ASSERT_EQUAL(uno::Any(Color(255, 0, 0)), xShape1Props->getPropertyValue(u"FillColor"));
+
+ // background 2 = lt2 = ID 3
+ uno::Reference<beans::XPropertySet> xShape2Props(xDrawPage->getByIndex(2), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(3)), xShape2Props->getPropertyValue(u"FillColorTheme"));
+ CPPUNIT_ASSERT_EQUAL(uno::Any(Color(235, 221, 195)),
+ xShape2Props->getPropertyValue(u"FillColor"));
+
+ // text 2 = dk2 = ID 2
+ uno::Reference<beans::XPropertySet> xShape3Props(xDrawPage->getByIndex(3), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(2)), xShape3Props->getPropertyValue(u"FillColorTheme"));
+ CPPUNIT_ASSERT_EQUAL(uno::Any(Color(119, 95, 85)),
+ xShape3Props->getPropertyValue(u"FillColor"));
+}
+
+CPPUNIT_TEST_FIXTURE(OoxShapeTest, testWriterShapeFillNonAccentColor)
+{
+ loadFromURL(u"tdf152840_theme_color_non_accent.docx");
+ // The file contains shapes which uses the theme colors "bg2", "bg1", "tx1" and "tx2" in this
+ // order as fill color.
+
+ uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+ uno::UNO_QUERY);
+
+ // The ID for the theme colors is not yet in API, but definied in enum PredefinedClrSchemeID
+ // in drawingml/clrscheme.hxx. Without fix the ID was -1 meaning no theme is used.
+ uno::Reference<beans::XPropertySet> xShape0Props(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(3)), xShape0Props->getPropertyValue(u"FillColorTheme"));
+ uno::Reference<beans::XPropertySet> xShape1Props(xDrawPage->getByIndex(1), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(1)), xShape1Props->getPropertyValue(u"FillColorTheme"));
+ uno::Reference<beans::XPropertySet> xShape2Props(xDrawPage->getByIndex(2), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(0)), xShape2Props->getPropertyValue(u"FillColorTheme"));
+ uno::Reference<beans::XPropertySet> xShape3Props(xDrawPage->getByIndex(3), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(uno::Any(sal_Int16(2)), xShape3Props->getPropertyValue(u"FillColorTheme"));
+}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/drawingml/clrscheme.cxx b/oox/source/drawingml/clrscheme.cxx
index 225faf81eecf..5360ae423478 100644
--- a/oox/source/drawingml/clrscheme.cxx
+++ b/oox/source/drawingml/clrscheme.cxx
@@ -80,6 +80,16 @@ bool ClrScheme::getColor( sal_Int32 nSchemeClrToken, ::Color& rColor ) const
case XML_bg2 : nSchemeClrToken = XML_lt2; break;
case XML_tx1 : nSchemeClrToken = XML_dk1; break;
case XML_tx2 : nSchemeClrToken = XML_dk2; break;
+ case XML_background1 : nSchemeClrToken = XML_lt1; break;
+ case XML_background2 : nSchemeClrToken = XML_lt2; break;
+ case XML_text1 : nSchemeClrToken = XML_dk1; break;
+ case XML_text2 : nSchemeClrToken = XML_dk2; break;
+ case XML_light1 : nSchemeClrToken = XML_lt1; break;
+ case XML_light2 : nSchemeClrToken = XML_lt2; break;
+ case XML_dark1 : nSchemeClrToken = XML_dk1; break;
+ case XML_dark2 : nSchemeClrToken = XML_dk2; break;
+ case XML_hyperlink : nSchemeClrToken = XML_hlink; break;
+ case XML_followedHyperlink: nSchemeClrToken = XML_folHlink; break;
}
auto aIter = std::find_if(maClrScheme.begin(), maClrScheme.end(), find_by_token(nSchemeClrToken) );
diff --git a/oox/source/drawingml/color.cxx b/oox/source/drawingml/color.cxx
index f810deecf2bf..9e9218f285e8 100644
--- a/oox/source/drawingml/color.cxx
+++ b/oox/source/drawingml/color.cxx
@@ -715,7 +715,11 @@ sal_Int16 Color::getSchemeColorIndex() const
static std::map<OUString, sal_Int32> const aSchemeColorNameToIndex{
{ "dk1", 0 }, { "lt1", 1 }, { "dk2", 2 }, { "lt2", 3 },
{ "accent1", 4 }, { "accent2", 5 }, { "accent3", 6 }, { "accent4", 7 },
- { "accent5", 8 }, { "accent6", 9 }, { "hlink", 10 }, { "folHlink", 11 }
+ { "accent5", 8 }, { "accent6", 9 }, { "hlink", 10 }, { "folHlink", 11 },
+ { "tx1", 0 }, { "bg1", 1 }, { "tx2", 2 }, { "bg2", 3 },
+ { "dark1", 0}, { "light1", 1}, { "dark2", 2 }, { "light2", 3 },
+ { "text1", 0 }, { "background1", 1 }, { "text2", 2 }, { "background2", 3 },
+ { "hyperlink", 10 }, { "followedHyperlink", 11}
};
auto aIt = aSchemeColorNameToIndex.find(msSchemeName);