diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-08-28 18:10:59 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-08-29 09:03:42 +0200 |
commit | 6dfb01f15ce7a7287dcb705a592ede852ccf9cab (patch) | |
tree | 546fc0fdfdc81d95fe4c95a41280402d4ad5b251 | |
parent | 5bcf4e98769dbaf07e8b28a86edc2d3d648a571c (diff) |
EPUB export: write generator string
Should help with debugging when it's not clear the version creating the
output had a certain fix or not.
Change-Id: Ibd1b5153d3210d30f95eba8927c55e2e812d985c
Reviewed-on: https://gerrit.libreoffice.org/41652
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r-- | external/libepubgen/libepubgen-epub3.patch.1 | 59 | ||||
-rw-r--r-- | writerperfect/qa/unit/EPUBExportTest.cxx | 5 | ||||
-rw-r--r-- | writerperfect/source/writer/exp/xmlmetai.cxx | 24 |
3 files changed, 88 insertions, 0 deletions
diff --git a/external/libepubgen/libepubgen-epub3.patch.1 b/external/libepubgen/libepubgen-epub3.patch.1 index 52070425d7c0..d1d35c102022 100644 --- a/external/libepubgen/libepubgen-epub3.patch.1 +++ b/external/libepubgen/libepubgen-epub3.patch.1 @@ -1803,3 +1803,62 @@ index 019404f..aa09332 100644 -- 2.12.3 +From 143a470f190aaf2f420d2f84b5f08e9b01b40473 Mon Sep 17 00:00:00 2001 +From: Miklos Vajna <vmiklos@collabora.co.uk> +Date: Fri, 25 Aug 2017 17:44:38 +0200 +Subject: [PATCH] Export generator + +--- + src/lib/EPUBGenerator.cpp | 28 ++++++++++++++++++++++++++++ + src/test/EPUBTextGeneratorTest.cpp | 17 +++++++++++++++++ + 2 files changed, 45 insertions(+) + +diff --git a/src/lib/EPUBGenerator.cpp b/src/lib/EPUBGenerator.cpp +index 4ce2964..1661064 100644 +--- a/src/lib/EPUBGenerator.cpp ++++ b/src/lib/EPUBGenerator.cpp +@@ -7,6 +7,10 @@ + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + ++#ifdef HAVE_CONFIG_H ++#include "config.h" ++#endif ++ + #include <ctime> + #include <sstream> + +@@ -298,6 +302,30 @@ void EPUBGenerator::writeRoot() + sink.openElement("meta", metaAttrs); + sink.insertCharacters(date); + sink.closeElement("meta"); ++ ++#ifdef VERSION ++ const std::string version(VERSION); ++#else ++ const std::string version("unknown"); ++#endif ++ std::string generator; ++ if (m_metadata["meta:generator"]) ++ generator = m_metadata["meta:generator"]->getStr().cstr(); ++ ++ if (generator.empty()) ++ generator = "libepubgen/" + version; ++ else ++ { ++ generator += " ("; ++ generator += "libepubgen/" + version; ++ generator += ")"; ++ } ++ ++ metaAttrs.clear(); ++ metaAttrs.insert("name", "generator"); ++ metaAttrs.insert("content", generator.c_str()); ++ sink.openElement("meta", metaAttrs); ++ sink.closeElement("meta"); + } + + sink.closeElement("metadata"); +-- +2.12.3 + diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx index f6e0d756fd25..cf602956c631 100644 --- a/writerperfect/qa/unit/EPUBExportTest.cxx +++ b/writerperfect/qa/unit/EPUBExportTest.cxx @@ -19,6 +19,7 @@ #include <test/bootstrapfixture.hxx> #include <test/xmltesttools.hxx> #include <unotest/macros_test.hxx> +#include <unotools/docinfohelper.hxx> #include <unotools/mediadescriptor.hxx> #include <unotools/tempfile.hxx> #include <unotools/ucbstreamhelper.hxx> @@ -138,6 +139,10 @@ void EPUBExportTest::testMimetype() mpXmlDoc = parseExport("OEBPS/content.opf"); // Default is EPUB3. assertXPath(mpXmlDoc, "/opf:package", "version", "3.0"); + + // This was just "libepubgen/x.y.z", i.e. the LO version was missing. + OUString aGenerator = getXPath(mpXmlDoc, "/opf:package/opf:metadata/opf:meta[@name='generator']", "content"); + CPPUNIT_ASSERT(aGenerator.startsWith(utl::DocInfoHelper::GetGeneratorString())); } void EPUBExportTest::testEPUB2() diff --git a/writerperfect/source/writer/exp/xmlmetai.cxx b/writerperfect/source/writer/exp/xmlmetai.cxx index cc8b37f43a0a..6c01adeb8f11 100644 --- a/writerperfect/source/writer/exp/xmlmetai.cxx +++ b/writerperfect/source/writer/exp/xmlmetai.cxx @@ -84,6 +84,28 @@ void XMLDcDateContext::characters(const OUString &rChars) mrMeta.m_aPropertyList.insert("dc:date", librevenge::RVNGString(sCharU8.getStr())); } +/// Handler for <meta:generator>. +class XMLMetaGeneratorContext : public XMLImportContext +{ +public: + XMLMetaGeneratorContext(XMLImport &rImport, XMLMetaDocumentContext &rMeta); + + void SAL_CALL characters(const OUString &rChars) override; + + XMLMetaDocumentContext &mrMeta; +}; + +XMLMetaGeneratorContext::XMLMetaGeneratorContext(XMLImport &rImport, XMLMetaDocumentContext &rMeta) + : XMLImportContext(rImport), mrMeta(rMeta) +{ +} + +void XMLMetaGeneratorContext::characters(const OUString &rChars) +{ + OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); + mrMeta.m_aPropertyList.insert("meta:generator", librevenge::RVNGString(sCharU8.getStr())); +} + XMLMetaDocumentContext::XMLMetaDocumentContext(XMLImport &rImport) : XMLImportContext(rImport) { @@ -97,6 +119,8 @@ XMLImportContext *XMLMetaDocumentContext::CreateChildContext(const OUString &rNa return new XMLDcLanguageContext(mrImport, *this); if (rName == "dc:date") return new XMLDcDateContext(mrImport, *this); + if (rName == "meta:generator") + return new XMLMetaGeneratorContext(mrImport, *this); return nullptr; } |