diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-09-18 18:28:57 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-09-19 09:13:44 +0200 |
commit | 10b49dfb3996f99dec8dd0d2ffae2aef4022f395 (patch) | |
tree | fb0a9d2ebe131343e1c2bf6b0a9ec1c1b934159c /writerperfect | |
parent | fa9dc42ec1b0a61d7c49ecf9a4eb804bac8835fa (diff) |
EPUB export: write styles inline to please poor readers
And add a filter option to disable the new behavior, if wanted.
Change-Id: Ib70f60fc38d02c959452882bf593cd498b642fba
Reviewed-on: https://gerrit.libreoffice.org/42433
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.cxx | 49 | ||||
-rw-r--r-- | writerperfect/source/writer/EPUBExportFilter.cxx | 11 | ||||
-rw-r--r-- | writerperfect/source/writer/EPUBExportFilter.hxx | 2 |
3 files changed, 55 insertions, 7 deletions
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx index 12f3c9d65f66..f86f6c395d22 100644 --- a/writerperfect/qa/unit/EPUBExportTest.cxx +++ b/writerperfect/qa/unit/EPUBExportTest.cxx @@ -236,7 +236,12 @@ void EPUBExportTest::testPageBreakSplit() void EPUBExportTest::testSpanAutostyle() { - createDoc("span-autostyle.fodt", {}); + uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence( + { + // Explicitly request in-CSS styles. + {"EPUBStylesMethod", uno::makeAny(static_cast<sal_Int32>(0))} + })); + createDoc("span-autostyle.fodt", aFilterData); mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml"); assertXPath(mpXmlDoc, "//xhtml:p/xhtml:span[1]", "class", "span0"); @@ -248,7 +253,12 @@ void EPUBExportTest::testSpanAutostyle() void EPUBExportTest::testParaAutostyleCharProps() { - createDoc("para-autostyle-char-props.fodt", {}); + uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence( + { + // Explicitly request in-CSS styles. + {"EPUBStylesMethod", uno::makeAny(static_cast<sal_Int32>(0))} + })); + createDoc("para-autostyle-char-props.fodt", aFilterData); mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml"); // This failed, para-level char props were not exported. @@ -268,7 +278,12 @@ void EPUBExportTest::testMeta() void EPUBExportTest::testParaNamedstyle() { - createDoc("para-namedstyle.fodt", {}); + uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence( + { + // Explicitly request in-CSS styles. + {"EPUBStylesMethod", uno::makeAny(static_cast<sal_Int32>(0))} + })); + createDoc("para-namedstyle.fodt", aFilterData); mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml"); assertXPath(mpXmlDoc, "//xhtml:p[1]", "class", "para0"); @@ -283,7 +298,12 @@ void EPUBExportTest::testParaNamedstyle() void EPUBExportTest::testCharNamedstyle() { - createDoc("char-namedstyle.fodt", {}); + uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence( + { + // Explicitly request in-CSS styles. + {"EPUBStylesMethod", uno::makeAny(static_cast<sal_Int32>(0))} + })); + createDoc("char-namedstyle.fodt", aFilterData); mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml"); @@ -295,7 +315,12 @@ void EPUBExportTest::testCharNamedstyle() void EPUBExportTest::testNamedStyleInheritance() { - createDoc("named-style-inheritance.fodt", {}); + uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence( + { + // Explicitly request in-CSS styles. + {"EPUBStylesMethod", uno::makeAny(static_cast<sal_Int32>(0))} + })); + createDoc("named-style-inheritance.fodt", aFilterData); // Find the CSS rule for the blue text. mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml"); @@ -311,7 +336,12 @@ void EPUBExportTest::testNamedStyleInheritance() void EPUBExportTest::testNestedSpan() { - createDoc("nested-span.fodt", {}); + uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence( + { + // Explicitly request in-CSS styles. + {"EPUBStylesMethod", uno::makeAny(static_cast<sal_Int32>(0))} + })); + createDoc("nested-span.fodt", aFilterData); // Check textural content of nested span. mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml"); @@ -353,7 +383,12 @@ void EPUBExportTest::testEscape() void EPUBExportTest::testParaCharProps() { - createDoc("para-char-props.fodt", {}); + uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence( + { + // Explicitly request in-CSS styles. + {"EPUBStylesMethod", uno::makeAny(static_cast<sal_Int32>(0))} + })); + createDoc("para-char-props.fodt", aFilterData); mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml"); // Check formatting of the middle span. diff --git a/writerperfect/source/writer/EPUBExportFilter.cxx b/writerperfect/source/writer/EPUBExportFilter.cxx index ef2ba333e55b..f30f18bb6735 100644 --- a/writerperfect/source/writer/EPUBExportFilter.cxx +++ b/writerperfect/source/writer/EPUBExportFilter.cxx @@ -43,10 +43,16 @@ sal_Int32 EPUBExportFilter::GetDefaultSplitMethod() return libepubgen::EPUB_SPLIT_METHOD_HEADING; } +sal_Int32 EPUBExportFilter::GetDefaultStylesMethod() +{ + return libepubgen::EPUB_STYLES_METHOD_INLINE; +} + sal_Bool EPUBExportFilter::filter(const uno::Sequence<beans::PropertyValue> &rDescriptor) { sal_Int32 nVersion = EPUBExportFilter::GetDefaultVersion(); sal_Int32 nSplitMethod = EPUBExportFilter::GetDefaultSplitMethod(); + sal_Int32 nStylesMethod = EPUBExportFilter::GetDefaultStylesMethod(); uno::Sequence<beans::PropertyValue> aFilterData; for (sal_Int32 i = 0; i < rDescriptor.getLength(); ++i) { @@ -63,6 +69,8 @@ sal_Bool EPUBExportFilter::filter(const uno::Sequence<beans::PropertyValue> &rDe aFilterData[i].Value >>= nVersion; else if (aFilterData[i].Name == "EPUBSplitMethod") aFilterData[i].Value >>= nSplitMethod; + else if (aFilterData[i].Name == "EPUBStylesMethod") + aFilterData[i].Value >>= nStylesMethod; } // Build the export filter chain: the package has direct access to the ZIP @@ -74,6 +82,9 @@ sal_Bool EPUBExportFilter::filter(const uno::Sequence<beans::PropertyValue> &rDe , nVersion #endif ); +#if LIBEPUBGEN_VERSION_SUPPORT + aGenerator.setStylesMethod(static_cast<libepubgen::EPUBStylesMethod>(nStylesMethod)); +#endif uno::Reference<xml::sax::XDocumentHandler> xExportHandler(new exp::XMLImport(aGenerator)); uno::Reference<lang::XInitialization> xInitialization(mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.comp.Writer.XMLOasisExporter", mxContext), uno::UNO_QUERY); diff --git a/writerperfect/source/writer/EPUBExportFilter.hxx b/writerperfect/source/writer/EPUBExportFilter.hxx index b423f96175e7..25bf0df81171 100644 --- a/writerperfect/source/writer/EPUBExportFilter.hxx +++ b/writerperfect/source/writer/EPUBExportFilter.hxx @@ -50,6 +50,8 @@ public: static sal_Int32 GetDefaultVersion(); /// Gives the default split method. static sal_Int32 GetDefaultSplitMethod(); + /// Gives the default styles method. + static sal_Int32 GetDefaultStylesMethod(); }; } // namespace writerperfect |