summaryrefslogtreecommitdiff
path: root/writerperfect
diff options
context:
space:
mode:
Diffstat (limited to 'writerperfect')
-rw-r--r--writerperfect/qa/unit/EPUBExportTest.cxx15
-rw-r--r--writerperfect/qa/unit/data/writer/epubexport/span-autostyle.fodt19
-rw-r--r--writerperfect/source/writer/exp/txtparai.cxx29
-rw-r--r--writerperfect/source/writer/exp/txtstyli.cxx30
4 files changed, 91 insertions, 2 deletions
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx
index cf602956c631..857f6ec85df3 100644
--- a/writerperfect/qa/unit/EPUBExportTest.cxx
+++ b/writerperfect/qa/unit/EPUBExportTest.cxx
@@ -51,12 +51,14 @@ public:
void testMimetype();
void testEPUB2();
void testPageBreakSplit();
+ void testSpanAutostyle();
CPPUNIT_TEST_SUITE(EPUBExportTest);
CPPUNIT_TEST(testOutlineLevel);
CPPUNIT_TEST(testMimetype);
CPPUNIT_TEST(testEPUB2);
CPPUNIT_TEST(testPageBreakSplit);
+ CPPUNIT_TEST(testSpanAutostyle);
CPPUNIT_TEST_SUITE_END();
};
@@ -85,6 +87,7 @@ void EPUBExportTest::tearDown()
void EPUBExportTest::registerNamespaces(xmlXPathContextPtr &pXmlXpathCtx)
{
xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("opf"), BAD_CAST("http://www.idpf.org/2007/opf"));
+ xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xhtml"), BAD_CAST("http://www.w3.org/1999/xhtml"));
}
void EPUBExportTest::createDoc(const OUString &rFile, const uno::Sequence<beans::PropertyValue> &rFilterData)
@@ -175,6 +178,18 @@ void EPUBExportTest::testPageBreakSplit()
CPPUNIT_ASSERT(!mxZipFile->hasByName("OEBPS/sections/section0003.xhtml"));
}
+void EPUBExportTest::testSpanAutostyle()
+{
+ createDoc("span-autostyle.fodt", {});
+
+ mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml");
+ assertXPath(mpXmlDoc, "//xhtml:p/xhtml:span[1]", "class", "span0");
+ // This failed, it was still span1, i.e. the bold and the italic formatting
+ // did not differ.
+ assertXPath(mpXmlDoc, "//xhtml:p/xhtml:span[2]", "class", "span1");
+ assertXPath(mpXmlDoc, "//xhtml:p/xhtml:span[3]", "class", "span2");
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest);
}
diff --git a/writerperfect/qa/unit/data/writer/epubexport/span-autostyle.fodt b/writerperfect/qa/unit/data/writer/epubexport/span-autostyle.fodt
new file mode 100644
index 000000000000..3122bef8dc46
--- /dev/null
+++ b/writerperfect/qa/unit/data/writer/epubexport/span-autostyle.fodt
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:automatic-styles>
+ <style:style style:name="T1" style:family="text">
+ <style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold"/>
+ </style:style>
+ <style:style style:name="T2" style:family="text">
+ <style:text-properties fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic"/>
+ </style:style>
+ <style:style style:name="T3" style:family="text">
+ <style:text-properties style:text-underline-style="solid" style:text-underline-width="auto" style:text-underline-color="font-color"/>
+ </style:style>
+ </office:automatic-styles>
+ <office:body>
+ <office:text>
+ <text:p text:style-name="Standard"><text:span text:style-name="T1">Hello</text:span> <text:span text:style-name="T2">world</text:span><text:span text:style-name="T3">!</text:span></text:p>
+ </office:text>
+ </office:body>
+</office:document>
diff --git a/writerperfect/source/writer/exp/txtparai.cxx b/writerperfect/source/writer/exp/txtparai.cxx
index e669cf89edf8..50ff36352ad5 100644
--- a/writerperfect/source/writer/exp/txtparai.cxx
+++ b/writerperfect/source/writer/exp/txtparai.cxx
@@ -44,9 +44,34 @@ XMLImportContext *XMLSpanContext::CreateChildContext(const OUString &rName, cons
return nullptr;
}
-void XMLSpanContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/)
+void XMLSpanContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs)
{
- mrImport.GetGenerator().openSpan(librevenge::RVNGPropertyList());
+ librevenge::RVNGPropertyList aPropertyList;
+ for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
+ {
+ const OUString &rAttributeName = xAttribs->getNameByIndex(i);
+ const OUString &rAttributeValue = xAttribs->getValueByIndex(i);
+ if (rAttributeName == "text:style-name")
+ {
+ // Reference to an automatic style, try to look it up.
+ auto itStyle = mrImport.GetAutomaticStyles().find(rAttributeValue);
+ if (itStyle == mrImport.GetAutomaticStyles().end())
+ continue;
+
+ // Apply properties directly, librevenge has no notion of automatic styles.
+ librevenge::RVNGPropertyList::Iter itProp(itStyle->second);
+ for (itProp.rewind(); itProp.next();)
+ aPropertyList.insert(itProp.key(), itProp()->clone());
+ }
+ else
+ {
+ OString sName = OUStringToOString(rAttributeName, RTL_TEXTENCODING_UTF8);
+ OString sValue = OUStringToOString(rAttributeValue, RTL_TEXTENCODING_UTF8);
+ aPropertyList.insert(sName.getStr(), sValue.getStr());
+ }
+ }
+
+ mrImport.GetGenerator().openSpan(aPropertyList);
}
void XMLSpanContext::endElement(const OUString &/*rName*/)
diff --git a/writerperfect/source/writer/exp/txtstyli.cxx b/writerperfect/source/writer/exp/txtstyli.cxx
index a7460a47c1b6..2d39816da4ef 100644
--- a/writerperfect/source/writer/exp/txtstyli.cxx
+++ b/writerperfect/source/writer/exp/txtstyli.cxx
@@ -46,6 +46,34 @@ void XMLParagraphPropertiesContext::startElement(const OUString &/*rName*/, cons
}
}
+/// Handler for <style:text-properties>.
+class XMLTextPropertiesContext : public XMLImportContext
+{
+public:
+ XMLTextPropertiesContext(XMLImport &rImport, XMLStyleContext &rStyle);
+
+ void SAL_CALL startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
+
+private:
+ XMLStyleContext &mrStyle;
+};
+
+XMLTextPropertiesContext::XMLTextPropertiesContext(XMLImport &rImport, XMLStyleContext &rStyle)
+ : XMLImportContext(rImport)
+ , mrStyle(rStyle)
+{
+}
+
+void XMLTextPropertiesContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs)
+{
+ for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
+ {
+ OString sName = OUStringToOString(xAttribs->getNameByIndex(i), RTL_TEXTENCODING_UTF8);
+ OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
+ mrStyle.GetPropertyList().insert(sName.getStr(), sValue.getStr());
+ }
+}
+
XMLStyleContext::XMLStyleContext(XMLImport &rImport)
: XMLImportContext(rImport)
{
@@ -55,6 +83,8 @@ XMLImportContext *XMLStyleContext::CreateChildContext(const OUString &rName, con
{
if (rName == "style:paragraph-properties")
return new XMLParagraphPropertiesContext(mrImport, *this);
+ if (rName == "style:text-properties")
+ return new XMLTextPropertiesContext(mrImport, *this);
return nullptr;
}