Kaydet (Commit) 10b49dfb authored tarafından Miklos Vajna's avatar Miklos Vajna

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/42433Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst fa9dc42e
......@@ -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.
......
......@@ -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);
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment