[Libreoffice-commits] core.git: writerperfect/qa writerperfect/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Oct 17 16:04:32 UTC 2017


 writerperfect/qa/unit/EPUBExportTest.cxx                          |   12 ++++++
 writerperfect/qa/unit/data/writer/epubexport/link-charformat.fodt |   13 ++++++
 writerperfect/source/writer/exp/txtparai.cxx                      |   19 ++++++++--
 3 files changed, 41 insertions(+), 3 deletions(-)

New commits:
commit f61acf7ebb2365d29209310b56c371ccf63f153d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Oct 17 16:33:06 2017 +0200

    EPUB export: handle char format of hyperlinks
    
    <text:a> child elements were not handled.
    
    Change-Id: I7db9c005869934456ffbe5c36347b01cc76645b6
    Reviewed-on: https://gerrit.libreoffice.org/43462
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx
index 374d9f730c23..850228c0a276 100644
--- a/writerperfect/qa/unit/EPUBExportTest.cxx
+++ b/writerperfect/qa/unit/EPUBExportTest.cxx
@@ -72,6 +72,7 @@ public:
     void testImage();
     void testTable();
     void testLink();
+    void testLinkCharFormat();
 
     CPPUNIT_TEST_SUITE(EPUBExportTest);
     CPPUNIT_TEST(testOutlineLevel);
@@ -93,6 +94,7 @@ public:
     CPPUNIT_TEST(testImage);
     CPPUNIT_TEST(testTable);
     CPPUNIT_TEST(testLink);
+    CPPUNIT_TEST(testLinkCharFormat);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -466,6 +468,16 @@ void EPUBExportTest::testLink()
     assertXPath(mpXmlDoc, "//xhtml:p/xhtml:a", "href", "https://libreoffice.org/");
 }
 
+void EPUBExportTest::testLinkCharFormat()
+{
+    createDoc("link-charformat.fodt", {});
+
+    mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml");
+    // <span> was lost, link text having a char format was missing.
+    assertXPathContent(mpXmlDoc, "//xhtml:p/xhtml:a/xhtml:span", "https://libreoffice.org/");
+    assertXPath(mpXmlDoc, "//xhtml:p/xhtml:a", "href", "https://libreoffice.org/");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest);
 
 }
diff --git a/writerperfect/qa/unit/data/writer/epubexport/link-charformat.fodt b/writerperfect/qa/unit/data/writer/epubexport/link-charformat.fodt
new file mode 100644
index 000000000000..b158ce3dbb82
--- /dev/null
+++ b/writerperfect/qa/unit/data/writer/epubexport/link-charformat.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:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" 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>
+  </office:automatic-styles>
+  <office:body>
+    <office:text>
+      <text:p>Before <text:a xlink:type="simple" xlink:href="https://libreoffice.org/"><text:span text:style-name="T1">https://libreoffice.org/</text:span></text:a> after.</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 fa6f91f0bd7b..c839b8b1bbed 100644
--- a/writerperfect/source/writer/exp/txtparai.cxx
+++ b/writerperfect/source/writer/exp/txtparai.cxx
@@ -214,16 +214,29 @@ void XMLTabContext::startElement(const OUString &/*rName*/, const css::uno::Refe
 class XMLHyperlinkContext : public XMLImportContext
 {
 public:
-    XMLHyperlinkContext(XMLImport &rImport);
+    XMLHyperlinkContext(XMLImport &rImport, const librevenge::RVNGPropertyList &rPropertyList);
+    rtl::Reference<XMLImportContext> CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
 
     void SAL_CALL startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override;
     void SAL_CALL endElement(const OUString &rName) override;
     void SAL_CALL characters(const OUString &rChars) override;
+
+private:
+    librevenge::RVNGPropertyList m_aPropertyList;
 };
 
-XMLHyperlinkContext::XMLHyperlinkContext(XMLImport &rImport)
+XMLHyperlinkContext::XMLHyperlinkContext(XMLImport &rImport, const librevenge::RVNGPropertyList &rPropertyList)
     : XMLImportContext(rImport)
 {
+    // Inherit properties from parent.
+    librevenge::RVNGPropertyList::Iter itProp(rPropertyList);
+    for (itProp.rewind(); itProp.next();)
+        m_aPropertyList.insert(itProp.key(), itProp()->clone());
+}
+
+rtl::Reference<XMLImportContext> XMLHyperlinkContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/)
+{
+    return CreateParagraphOrSpanChildContext(mrImport, rName, m_aPropertyList);
 }
 
 void XMLHyperlinkContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs)
@@ -262,7 +275,7 @@ XMLParaContext::XMLParaContext(XMLImport &rImport)
 rtl::Reference<XMLImportContext> XMLParaContext::CreateChildContext(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &/*xAttribs*/)
 {
     if (rName == "text:a")
-        return new XMLHyperlinkContext(mrImport);
+        return new XMLHyperlinkContext(mrImport, m_aTextPropertyList);
     return CreateParagraphOrSpanChildContext(mrImport, rName, m_aTextPropertyList);
 }
 


More information about the Libreoffice-commits mailing list