summaryrefslogtreecommitdiff
path: root/writerperfect
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-11-23 17:10:53 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-11-24 09:03:39 +0100
commitccd2888110a7074763e6a948f4c5da29f2196d40 (patch)
treebc2a419586b0235bd42f75be4f7bd4ee5e82d31a /writerperfect
parente8e5bd65d31a60712afcab17d2e5f77c3322f86f (diff)
EPUB export: implement character properties of links from named styles
ODF allows text properties on hyperlinks directly, librevenge wants an inner span instead. Change-Id: I903045a688bf318e7ac7f8cac83bb4d537259969 Reviewed-on: https://gerrit.libreoffice.org/45161 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'writerperfect')
-rw-r--r--writerperfect/qa/unit/EPUBExportTest.cxx34
-rw-r--r--writerperfect/qa/unit/data/writer/epubexport/link-namedcharformat.fodt13
-rw-r--r--writerperfect/source/writer/exp/txtparai.cxx13
3 files changed, 57 insertions, 3 deletions
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx
index 74edf831b84b..aba848ce9688 100644
--- a/writerperfect/qa/unit/EPUBExportTest.cxx
+++ b/writerperfect/qa/unit/EPUBExportTest.cxx
@@ -17,6 +17,7 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/propertysequence.hxx>
+#include <comphelper/string.hxx>
#include <cppuhelper/implbase.hxx>
#include <test/bootstrapfixture.hxx>
#include <test/xmltesttools.hxx>
@@ -53,6 +54,8 @@ public:
xmlDocPtr parseExport(const OUString &rName);
/// Loads a CSS representation of the stream named rName in the exported package into rTree.
void parseCssExport(const OUString &rName, std::map< OString, std::vector<OString> > &rTree);
+ /// Loads a CSS style string into a map.
+ void parseCssStyle(const OUString &rStyle, std::map<OUString, OUString> &rCss);
void testOutlineLevel();
void testMimetype();
void testEPUB2();
@@ -73,6 +76,7 @@ public:
void testTable();
void testLink();
void testLinkCharFormat();
+ void testLinkNamedCharFormat();
CPPUNIT_TEST_SUITE(EPUBExportTest);
CPPUNIT_TEST(testOutlineLevel);
@@ -95,6 +99,7 @@ public:
CPPUNIT_TEST(testTable);
CPPUNIT_TEST(testLink);
CPPUNIT_TEST(testLinkCharFormat);
+ CPPUNIT_TEST(testLinkNamedCharFormat);
CPPUNIT_TEST_SUITE_END();
};
@@ -179,6 +184,17 @@ void EPUBExportTest::parseCssExport(const OUString &rName, std::map< OString, st
}
}
+void EPUBExportTest::parseCssStyle(const OUString &rStyle, std::map<OUString, OUString> &rCss)
+{
+ for (const auto &rKeyValue : comphelper::string::split(rStyle, ';'))
+ {
+ OUString aKeyValue = rKeyValue.trim();
+ std::vector<OUString> aTokens = comphelper::string::split(aKeyValue, ':');
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aTokens.size());
+ rCss[aTokens[0].trim()] = aTokens[1].trim();
+ }
+}
+
void EPUBExportTest::testOutlineLevel()
{
createDoc("outline-level.fodt", {});
@@ -464,7 +480,7 @@ void EPUBExportTest::testLink()
createDoc("link.fodt", {});
mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml");
- assertXPathContent(mpXmlDoc, "//xhtml:p/xhtml:a", "https://libreoffice.org/");
+ assertXPathContent(mpXmlDoc, "//xhtml:p/xhtml:a/xhtml:span", "https://libreoffice.org/");
assertXPath(mpXmlDoc, "//xhtml:p/xhtml:a", "href", "https://libreoffice.org/");
}
@@ -478,6 +494,22 @@ void EPUBExportTest::testLinkCharFormat()
assertXPath(mpXmlDoc, "//xhtml:p/xhtml:a", "href", "https://libreoffice.org/");
}
+void EPUBExportTest::testLinkNamedCharFormat()
+{
+ // Character properties from named character style on hyperlink was lost.
+ createDoc("link-namedcharformat.fodt", {});
+
+ mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml");
+ // This failed, there was no span inside the hyperlink.
+ assertXPathContent(mpXmlDoc, "//xhtml:p/xhtml:a/xhtml:span", "http://libreoffice.org");
+ assertXPath(mpXmlDoc, "//xhtml:p/xhtml:a", "href", "http://libreoffice.org/");
+
+ OUString aStyle = getXPath(mpXmlDoc, "//xhtml:p/xhtml:a/xhtml:span", "style");
+ std::map<OUString, OUString> aCss;
+ parseCssStyle(aStyle, aCss);
+ CPPUNIT_ASSERT_EQUAL(OUString("#ff0000"), aCss["color"]);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest);
}
diff --git a/writerperfect/qa/unit/data/writer/epubexport/link-namedcharformat.fodt b/writerperfect/qa/unit/data/writer/epubexport/link-namedcharformat.fodt
new file mode 100644
index 000000000000..0e05c8d74d57
--- /dev/null
+++ b/writerperfect/qa/unit/data/writer/epubexport/link-namedcharformat.fodt
@@ -0,0 +1,13 @@
+<?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:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:styles>
+ <style:style style:name="Internet_20_link" style:display-name="Internet link" style:family="text">
+ <style:text-properties fo:color="#ff0000" fo:language="zxx" fo:country="none" style:text-underline-style="solid" style:text-underline-width="auto" style:text-underline-color="font-color" style:language-asian="zxx" style:country-asian="none" style:language-complex="zxx" style:country-complex="none"/>
+ </style:style>
+ </office:styles>
+ <office:body>
+ <office:text>
+ <text:p text:style-name="P1">A <text:a xlink:type="simple" xlink:href="http://libreoffice.org/" text:style-name="Internet_20_link" text:visited-style-name="Visited_20_Internet_20_Link">http://libreoffice.org</text:a> b – red via character style</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 c839b8b1bbed..9c649c1d25ec 100644
--- a/writerperfect/source/writer/exp/txtparai.cxx
+++ b/writerperfect/source/writer/exp/txtparai.cxx
@@ -245,10 +245,15 @@ void XMLHyperlinkContext::startElement(const OUString &/*rName*/, const css::uno
for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i)
{
const OUString &rAttributeName = xAttribs->getNameByIndex(i);
- if (rAttributeName == "xlink:href")
+ const OUString &rAttributeValue = xAttribs->getValueByIndex(i);
+ if (rAttributeName == "text:style-name")
+ // This affects the nested span's properties.
+ FillStyles(rAttributeValue, mrImport.GetAutomaticTextStyles(), mrImport.GetTextStyles(), m_aPropertyList);
+ else
{
+ // This affects the link's properties.
OString sName = OUStringToOString(rAttributeName, RTL_TEXTENCODING_UTF8);
- OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8);
+ OString sValue = OUStringToOString(rAttributeValue, RTL_TEXTENCODING_UTF8);
aPropertyList.insert(sName.getStr(), sValue.getStr());
}
}
@@ -263,8 +268,12 @@ void XMLHyperlinkContext::endElement(const OUString &/*rName*/)
void XMLHyperlinkContext::characters(const OUString &rChars)
{
+ mrImport.GetGenerator().openSpan(m_aPropertyList);
+
OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8);
mrImport.GetGenerator().insertText(librevenge::RVNGString(sCharU8.getStr()));
+
+ mrImport.GetGenerator().closeSpan();
}
XMLParaContext::XMLParaContext(XMLImport &rImport)