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

Miklos Vajna vmiklos at collabora.co.uk
Mon Sep 4 18:53:45 UTC 2017


 external/libepubgen/libepubgen-epub3.patch.1           |   44 +++++++++++++++++
 writerperfect/qa/unit/EPUBExportTest.cxx               |   13 +++++
 writerperfect/qa/unit/data/writer/epubexport/meta.fodt |   12 ++++
 writerperfect/source/writer/exp/xmlmetai.cxx           |   24 +++++++++
 4 files changed, 93 insertions(+)

New commits:
commit 41092fe0bb0d2f49948bf2a1f27acb53f21a84aa
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Sep 4 17:27:39 2017 +0200

    EPUB export: write author metadata
    
    <meta:initial-creator> is the author and <dc:creator> is the "last
    modified by" in ODF (it seems), so map the first to EPUB's <dc:creator>.
    
    Change-Id: Id701c8c38b0901ae14fbbc7b32d01b43d6d03f68
    Reviewed-on: https://gerrit.libreoffice.org/41903
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/external/libepubgen/libepubgen-epub3.patch.1 b/external/libepubgen/libepubgen-epub3.patch.1
index d1d35c102022..0415bf340e78 100644
--- a/external/libepubgen/libepubgen-epub3.patch.1
+++ b/external/libepubgen/libepubgen-epub3.patch.1
@@ -1862,3 +1862,47 @@ index 4ce2964..1661064 100644
 -- 
 2.12.3
 
+From 7e3b5186616326534b1ae95c6d2d188c5e522c7f Mon Sep 17 00:00:00 2001
+From: Miklos Vajna <vmiklos at collabora.co.uk>
+Date: Mon, 4 Sep 2017 17:18:49 +0200
+Subject: [PATCH] EPUBGenerator: always write author and title
+
+Some EPUB3 readers categorize books by author and then title, so if
+these are empty, then it's next to impossible to reach the export result
+there.
+---
+ src/lib/EPUBGenerator.cpp          | 11 ++++++++---
+ src/test/EPUBTextGeneratorTest.cpp | 11 +++++++++++
+ 2 files changed, 19 insertions(+), 3 deletions(-)
+
+diff --git a/src/lib/EPUBGenerator.cpp b/src/lib/EPUBGenerator.cpp
+index 1661064..3340643 100644
+--- a/src/lib/EPUBGenerator.cpp
++++ b/src/lib/EPUBGenerator.cpp
+@@ -260,15 +260,20 @@ void EPUBGenerator::writeRoot()
+   sink.insertCharacters(identifierCharactrs.c_str());
+   sink.closeElement("dc:identifier");
+ 
+-  // Zero-width space as it must be at least one character in length after
+-  // white space has been trimmed.
+-  RVNGString title("\u200b");
++  RVNGString title("Unknown Title");
+   if (m_metadata["dc:title"] && !m_metadata["dc:title"]->getStr().empty())
+     title = m_metadata["dc:title"]->getStr();
+   sink.openElement("dc:title");
+   sink.insertCharacters(title);
+   sink.closeElement("dc:title");
+ 
++  RVNGString creator("Unknown Author");
++  if (m_metadata["meta:initial-creator"] && !m_metadata["meta:initial-creator"]->getStr().empty())
++    creator = m_metadata["meta:initial-creator"]->getStr();
++  sink.openElement("dc:creator");
++  sink.insertCharacters(creator);
++  sink.closeElement("dc:creator");
++
+   RVNGString language("en");
+   if (m_metadata["dc:language"] && !m_metadata["dc:language"]->getStr().empty())
+     language = m_metadata["dc:language"]->getStr();
+-- 
+2.12.3
+
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx
index fef1cf19770c..61a6da2941f0 100644
--- a/writerperfect/qa/unit/EPUBExportTest.cxx
+++ b/writerperfect/qa/unit/EPUBExportTest.cxx
@@ -53,6 +53,7 @@ public:
     void testPageBreakSplit();
     void testSpanAutostyle();
     void testParaAutostyleCharProps();
+    void testMeta();
 
     CPPUNIT_TEST_SUITE(EPUBExportTest);
     CPPUNIT_TEST(testOutlineLevel);
@@ -61,6 +62,7 @@ public:
     CPPUNIT_TEST(testPageBreakSplit);
     CPPUNIT_TEST(testSpanAutostyle);
     CPPUNIT_TEST(testParaAutostyleCharProps);
+    CPPUNIT_TEST(testMeta);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -88,6 +90,7 @@ void EPUBExportTest::tearDown()
 
 void EPUBExportTest::registerNamespaces(xmlXPathContextPtr &pXmlXpathCtx)
 {
+    xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dc"), BAD_CAST("http://purl.org/dc/elements/1.1/"));
     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"));
 }
@@ -202,6 +205,16 @@ void EPUBExportTest::testParaAutostyleCharProps()
     assertXPath(mpXmlDoc, "//xhtml:p[2]/xhtml:span", "class", "span1");
 }
 
+void EPUBExportTest::testMeta()
+{
+    createDoc("meta.fodt", {});
+
+    mpXmlDoc = parseExport("OEBPS/content.opf");
+    // This was "Unknown Author", <meta:initial-creator> was not handled.
+    assertXPathContent(mpXmlDoc, "/opf:package/opf:metadata/dc:creator", "A U Thor");
+    assertXPathContent(mpXmlDoc, "/opf:package/opf:metadata/dc:title", "Title");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest);
 
 }
diff --git a/writerperfect/qa/unit/data/writer/epubexport/meta.fodt b/writerperfect/qa/unit/data/writer/epubexport/meta.fodt
new file mode 100644
index 000000000000..4e46fe79fcda
--- /dev/null
+++ b/writerperfect/qa/unit/data/writer/epubexport/meta.fodt
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document office:mimetype="application/vnd.oasis.opendocument.text" office:version="1.2" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
+  <office:meta>
+    <meta:initial-creator>A U Thor</meta:initial-creator>
+    <dc:title>Title</dc:title>
+  </office:meta>
+  <office:body>
+    <office:text>
+      <text:p><text:span>Hello world!</text:span></text:p>
+    </office:text>
+  </office:body>
+</office:document>
diff --git a/writerperfect/source/writer/exp/xmlmetai.cxx b/writerperfect/source/writer/exp/xmlmetai.cxx
index 6c01adeb8f11..8777f4fa0b6f 100644
--- a/writerperfect/source/writer/exp/xmlmetai.cxx
+++ b/writerperfect/source/writer/exp/xmlmetai.cxx
@@ -106,6 +106,28 @@ void XMLMetaGeneratorContext::characters(const OUString &rChars)
     mrMeta.m_aPropertyList.insert("meta:generator", librevenge::RVNGString(sCharU8.getStr()));
 }
 
+/// Handler for <meta:initial-creator>.
+class XMLMetaInitialCreatorContext : public XMLImportContext
+{
+public:
+    XMLMetaInitialCreatorContext(XMLImport &rImport, XMLMetaDocumentContext &rMeta);
+
+    void SAL_CALL characters(const OUString &rChars) override;
+
+    XMLMetaDocumentContext &mrMeta;
+};
+
+XMLMetaInitialCreatorContext::XMLMetaInitialCreatorContext(XMLImport &rImport, XMLMetaDocumentContext &rMeta)
+    : XMLImportContext(rImport), mrMeta(rMeta)
+{
+}
+
+void XMLMetaInitialCreatorContext::characters(const OUString &rChars)
+{
+    OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8);
+    mrMeta.m_aPropertyList.insert("meta:initial-creator", librevenge::RVNGString(sCharU8.getStr()));
+}
+
 XMLMetaDocumentContext::XMLMetaDocumentContext(XMLImport &rImport)
     : XMLImportContext(rImport)
 {
@@ -121,6 +143,8 @@ XMLImportContext *XMLMetaDocumentContext::CreateChildContext(const OUString &rNa
         return new XMLDcDateContext(mrImport, *this);
     if (rName == "meta:generator")
         return new XMLMetaGeneratorContext(mrImport, *this);
+    if (rName == "meta:initial-creator")
+        return new XMLMetaInitialCreatorContext(mrImport, *this);
     return nullptr;
 }
 


More information about the Libreoffice-commits mailing list