summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-12-09 08:43:27 +0100
committerMiklos Vajna <vmiklos@collabora.com>2021-12-09 09:34:39 +0100
commit91f649a119d4b7ece26f9737a38663664953a57a (patch)
treeb2d3d85cd532ed21a1b1f86b942659b4a2407ada /xmloff
parent27487243c3ee31927e17a0859614ffa0df7881d7 (diff)
ODP import/export: refer to theme from shape text color
Refer to the 12 pre-defined colors by name + don't write the attribute for the case when there is no theme. Change-Id: Ib6ab5b7b34d896a36e04309bf0cb410998acce01 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126566 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/qa/unit/data/refer-to-theme.odpbin0 -> 14488 bytes
-rw-r--r--xmloff/qa/unit/draw.cxx24
-rw-r--r--xmloff/source/core/xmltoken.cxx13
-rw-r--r--xmloff/source/draw/sdxmlexp.cxx30
-rw-r--r--xmloff/source/text/txtprhdl.cxx20
-rw-r--r--xmloff/source/text/txtprmap.cxx2
-rw-r--r--xmloff/source/token/tokens.txt13
7 files changed, 87 insertions, 15 deletions
diff --git a/xmloff/qa/unit/data/refer-to-theme.odp b/xmloff/qa/unit/data/refer-to-theme.odp
new file mode 100644
index 000000000000..83bad49b5f56
--- /dev/null
+++ b/xmloff/qa/unit/data/refer-to-theme.odp
Binary files differ
diff --git a/xmloff/qa/unit/draw.cxx b/xmloff/qa/unit/draw.cxx
index cd991e691d7c..a61ef6de2717 100644
--- a/xmloff/qa/unit/draw.cxx
+++ b/xmloff/qa/unit/draw.cxx
@@ -177,6 +177,30 @@ CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeImport)
CPPUNIT_ASSERT_EQUAL(static_cast<util::Color>(0x954F72), aColorScheme[11]);
}
+CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testReferToTheme)
+{
+ // Given a document that refers to a theme color:
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "refer-to-theme.odp";
+
+ // When loading and saving that document:
+ getComponent() = loadFromDesktop(aURL);
+ utl::TempFile aTempFile;
+ save("impress8", aTempFile);
+
+ // Make sure the export result has the theme reference:
+ std::unique_ptr<SvStream> pStream = parseExportStream(aTempFile, "content.xml");
+ xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get());
+ // Without the accompanying fix in place, this test would have failed with:
+ // - XPath '//style:style[@style:name='T1']/style:text-properties' no attribute 'theme-color' exist
+ // i.e. only the direct color was written, but not the theme reference.
+ assertXPath(pXmlDoc, "//style:style[@style:name='T1']/style:text-properties", "theme-color",
+ "accent1");
+ assertXPath(pXmlDoc, "//style:style[@style:name='T2']/style:text-properties", "theme-color",
+ "accent1");
+ assertXPath(pXmlDoc, "//style:style[@style:name='T3']/style:text-properties", "theme-color",
+ "accent1");
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx
index caf15a395e03..fd486a313aae 100644
--- a/xmloff/source/core/xmltoken.cxx
+++ b/xmloff/source/core/xmltoken.cxx
@@ -3444,6 +3444,19 @@ namespace xmloff::token {
TOKEN("linked-style-name", XML_LINKED_STYLE_NAME ),
TOKEN("theme", XML_THEME ),
+ TOKEN("theme-color", XML_THEME_COLOR ),
+ TOKEN("dk1", XML_DK1 ),
+ TOKEN("lt1", XML_LT1 ),
+ TOKEN("dk2", XML_DK2 ),
+ TOKEN("lt2", XML_LT2 ),
+ TOKEN("accent1", XML_ACCENT1 ),
+ TOKEN("accent2", XML_ACCENT2 ),
+ TOKEN("accent3", XML_ACCENT3 ),
+ TOKEN("accent4", XML_ACCENT4 ),
+ TOKEN("accent5", XML_ACCENT5 ),
+ TOKEN("accent6", XML_ACCENT6 ),
+ TOKEN("hlink", XML_HLINK ),
+ TOKEN("folHlink", XML_FOLHLINK ),
#if OSL_DEBUG_LEVEL > 0
diff --git a/xmloff/source/draw/sdxmlexp.cxx b/xmloff/source/draw/sdxmlexp.cxx
index 9388cedb25e4..b789f7342d90 100644
--- a/xmloff/source/draw/sdxmlexp.cxx
+++ b/xmloff/source/draw/sdxmlexp.cxx
@@ -2410,26 +2410,26 @@ void SdXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& x
}
SvXMLElementExport aColorTable(*this, XML_NAMESPACE_LO_EXT, XML_COLOR_TABLE, true, true);
- static const std::u16string_view aColorNames[] = {
- u"dk1", // Background 1
- u"lt1", // Text 1
- u"dk2", // Background 2
- u"lt2", // Text 2
- u"accent1", // Accent 1
- u"accent2", // Accent 2
- u"accent3", // Accent 3
- u"accent4", // Accent 4
- u"accent5", // Accent 5
- u"accent6", // Accent 6
- u"hlink", // Hyperlink
- u"folHlink", // Followed hyperlink
+ static const XMLTokenEnum aColorTokens[] = {
+ XML_DK1, // Background 1
+ XML_LT1, // Text 1
+ XML_DK2, // Background 2
+ XML_LT2, // Text 2
+ XML_ACCENT1,
+ XML_ACCENT2,
+ XML_ACCENT3,
+ XML_ACCENT4,
+ XML_ACCENT5,
+ XML_ACCENT6,
+ XML_HLINK, // Hyperlink
+ XML_FOLHLINK, // Followed hyperlink
};
for (size_t nColor = 0; nColor < aColors.size(); ++nColor)
{
// Import goes via svx::Theme::FromAny(), which sanitizes user input.
- assert(nColor < SAL_N_ELEMENTS(aColorNames));
+ assert(nColor < SAL_N_ELEMENTS(aColorTokens));
- AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, OUString(aColorNames[nColor]));
+ AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, GetXMLToken(aColorTokens[nColor]));
OUStringBuffer sValue;
sax::Converter::convertColor(sValue, aColors[nColor]);
diff --git a/xmloff/source/text/txtprhdl.cxx b/xmloff/source/text/txtprhdl.cxx
index 2068c9b934a6..22fbe4174dd6 100644
--- a/xmloff/source/text/txtprhdl.cxx
+++ b/xmloff/source/text/txtprhdl.cxx
@@ -249,6 +249,23 @@ SvXMLEnumMapEntry<drawing::TextVerticalAdjust> const pXML_VerticalAlign_Enum[] =
{ XML_TOKEN_INVALID, drawing::TextVerticalAdjust(0) }
};
+SvXMLEnumMapEntry<sal_uInt16> const pXML_ThemeColor_Enum[] =
+{
+ { XML_DK1, 0 },
+ { XML_LT1, 1 },
+ { XML_DK2, 2 },
+ { XML_LT2, 3 },
+ { XML_ACCENT1, 4 },
+ { XML_ACCENT2, 5 },
+ { XML_ACCENT3, 6 },
+ { XML_ACCENT4, 7 },
+ { XML_ACCENT5, 8 },
+ { XML_ACCENT6, 9 },
+ { XML_HLINK, 10 },
+ { XML_FOLHLINK, 11 },
+ { XML_TOKEN_INVALID, 0 }
+};
+
namespace {
class XMLDropCapPropHdl_Impl : public XMLPropertyHandler
@@ -1412,6 +1429,9 @@ static const XMLPropertyHandler *GetPropertyHandler
case XML_TYPE_GRAPHIC:
pHdl = new XMLGraphicPropertyHandler;
break;
+ case XML_TYPE_THEME_COLOR:
+ pHdl = new XMLConstantsPropertyHandler(pXML_ThemeColor_Enum, XML_TOKEN_INVALID);
+ break;
default:
{
OSL_ENSURE(false, "XMLPropertyHandler missing (!)");
diff --git a/xmloff/source/text/txtprmap.cxx b/xmloff/source/text/txtprmap.cxx
index 2e8297d7947e..f51db1aa2ab6 100644
--- a/xmloff/source/text/txtprmap.cxx
+++ b/xmloff/source/text/txtprmap.cxx
@@ -138,6 +138,7 @@ XMLPropertyMapEntry const aXMLParaPropMap[] =
MT_ED( "CharColor", STYLE, USE_WINDOW_FONT_COLOR, XML_TYPE_ISAUTOCOLOR|MID_FLAG_MERGE_PROPERTY, 0 ),
MAP_EXT_I("CharTransparence", XML_NAMESPACE_DRAW, XML_OPACITY, XML_TYPE_NEG_PERCENT16 | XML_TYPE_PROP_TEXT, 0),
MAP_EXT("CharTransparence", XML_NAMESPACE_LO_EXT, XML_OPACITY, XML_TYPE_NEG_PERCENT16 | XML_TYPE_PROP_TEXT, 0),
+ MAP_EXT("CharColorTheme", XML_NAMESPACE_LO_EXT, XML_THEME_COLOR, XML_TYPE_THEME_COLOR, 0),
// RES_CHRATR_CONTOUR
MT_E( "CharContoured", STYLE, TEXT_OUTLINE, XML_TYPE_BOOL, 0 ),
// RES_CHRATR_CROSSEDOUT
@@ -481,6 +482,7 @@ XMLPropertyMapEntry const aXMLTextPropMap[] =
MT_ED( "CharColor", STYLE, USE_WINDOW_FONT_COLOR, XML_TYPE_ISAUTOCOLOR|MID_FLAG_MERGE_PROPERTY, 0 ),
MAP_EXT_I("CharTransparence", XML_NAMESPACE_DRAW, XML_OPACITY, XML_TYPE_NEG_PERCENT16 | XML_TYPE_PROP_TEXT, 0),
MAP_EXT("CharTransparence", XML_NAMESPACE_LO_EXT, XML_OPACITY, XML_TYPE_NEG_PERCENT16 | XML_TYPE_PROP_TEXT, 0),
+ MAP_EXT("CharColorTheme", XML_NAMESPACE_LO_EXT, XML_THEME_COLOR, XML_TYPE_THEME_COLOR | XML_TYPE_PROP_TEXT, 0),
// RES_CHRATR_CONTOUR
MT_E( "CharContoured", STYLE, TEXT_OUTLINE, XML_TYPE_BOOL, 0 ),
// RES_CHRATR_CROSSEDOUT
diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt
index abc66bd73034..12de9d78a22d 100644
--- a/xmloff/source/token/tokens.txt
+++ b/xmloff/source/token/tokens.txt
@@ -3188,4 +3188,17 @@ rtl
symmetric
linked-style-name
theme
+theme-color
+dk1
+lt1
+dk2
+lt2
+accent1
+accent2
+accent3
+accent4
+accent5
+accent6
+hlink
+folHlink
TOKEN_END_DUMMY