From fe652ec259f7ca9e79810553ce6c884688963102 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 22 Dec 2017 17:49:09 +0100 Subject: EPUB export: fix invalid XHTML output for text boxes
not allowed inside

. Also fix two more similar validation problems. Change-Id: I7c326743b5e89a5a32609bdf312cb8caa203692e Reviewed-on: https://gerrit.libreoffice.org/46983 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- external/libepubgen/UnpackedTarball_libepubgen.mk | 2 + external/libepubgen/libepubgen-epub3.patch.1 | 169 ++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 external/libepubgen/libepubgen-epub3.patch.1 diff --git a/external/libepubgen/UnpackedTarball_libepubgen.mk b/external/libepubgen/UnpackedTarball_libepubgen.mk index 14efadb337c0..47b21d7ee5d0 100644 --- a/external/libepubgen/UnpackedTarball_libepubgen.mk +++ b/external/libepubgen/UnpackedTarball_libepubgen.mk @@ -8,6 +8,8 @@ # epubgen_patches := +# Backport of . +epubgen_patches += libepubgen-epub3.patch.1 ifeq ($(COM_IS_CLANG),TRUE) ifneq ($(filter -fsanitize=%,$(CC)),) diff --git a/external/libepubgen/libepubgen-epub3.patch.1 b/external/libepubgen/libepubgen-epub3.patch.1 new file mode 100644 index 000000000000..7ea3a365737f --- /dev/null +++ b/external/libepubgen/libepubgen-epub3.patch.1 @@ -0,0 +1,169 @@ +From 006848cb62225647c418d5143d4e88a9d73829da Mon Sep 17 00:00:00 2001 +From: Miklos Vajna +Date: Fri, 22 Dec 2017 16:33:52 +0100 +Subject: [PATCH] EPUBHTMLGenerator: avoid

inside

and/or + +This is not allowed in XHTML, but we wrote that markup when a text frame +was inside a span or a paragraph. The closest allowed markup in XHTML +seems to be closing the span/paragraph before opening the text box and +doing the opposite after the text box is closed. +--- + src/lib/EPUBHTMLGenerator.cpp | 33 +++++++++++++++++++++++++++++++++ + src/test/EPUBTextGeneratorTest.cpp | 4 +++- + 2 files changed, 36 insertions(+), 1 deletion(-) + +diff --git a/src/lib/EPUBHTMLGenerator.cpp b/src/lib/EPUBHTMLGenerator.cpp +index 342213e..bc9c1b7 100644 +--- a/src/lib/EPUBHTMLGenerator.cpp ++++ b/src/lib/EPUBHTMLGenerator.cpp +@@ -395,6 +395,8 @@ struct EPUBHTMLGeneratorImpl + , m_frameAnchorTypes() + , m_framePropertiesStack() + , m_linkPropertiesStack() ++ , m_paragraphAttributesStack() ++ , m_spanAttributesStack() + , m_stylesMethod(stylesMethod) + , m_layoutMethod(layoutMethod) + , m_actualSink() +@@ -495,6 +497,8 @@ struct EPUBHTMLGeneratorImpl + std::stack m_framePropertiesStack; + /// This is used for links which don't have a href. + std::stack m_linkPropertiesStack; ++ std::stack m_paragraphAttributesStack; ++ std::stack m_spanAttributesStack; + + EPUBStylesMethod m_stylesMethod; + EPUBLayoutMethod m_layoutMethod; +@@ -683,6 +687,12 @@ void EPUBHTMLGenerator::openParagraph(const RVNGPropertyList &propList) + } + m_impl->output(false).openElement("p", attrs); + m_impl->m_hasText = false; ++ ++ librevenge::RVNGPropertyList::Iter i(attrs); ++ RVNGPropertyList paragraphAttributes; ++ for (i.rewind(); i.next();) ++ paragraphAttributes.insert(i.key(), i()->clone()); ++ m_impl->m_paragraphAttributesStack.push(paragraphAttributes); + } + + void EPUBHTMLGenerator::closeParagraph() +@@ -690,6 +700,9 @@ void EPUBHTMLGenerator::closeParagraph() + if (m_impl->m_ignore) + return; + ++ if (!m_impl->m_paragraphAttributesStack.empty()) ++ m_impl->m_paragraphAttributesStack.pop(); ++ + if (!m_impl->m_hasText) + insertSpace(); + +@@ -717,12 +730,22 @@ void EPUBHTMLGenerator::openSpan(const RVNGPropertyList &propList) + break; + } + m_impl->output(false).openElement("span", attrs); ++ ++ librevenge::RVNGPropertyList::Iter i(attrs); ++ RVNGPropertyList spanAttributes; ++ for (i.rewind(); i.next();) ++ spanAttributes.insert(i.key(), i()->clone()); ++ m_impl->m_spanAttributesStack.push(spanAttributes); + } + + void EPUBHTMLGenerator::closeSpan() + { + if (m_impl->m_ignore) + return; ++ ++ if (!m_impl->m_spanAttributesStack.empty()) ++ m_impl->m_spanAttributesStack.pop(); ++ + m_impl->output().closeElement("span"); + } + +@@ -931,6 +954,11 @@ void EPUBHTMLGenerator::openTextBox(const RVNGPropertyList & /*propList*/) + if (m_impl->m_ignore) + return; + ++ if (!m_impl->m_spanAttributesStack.empty()) ++ m_impl->output().closeElement("span"); ++ if (!m_impl->m_paragraphAttributesStack.empty()) ++ m_impl->output().closeElement("p"); ++ + RVNGPropertyList attrs; + + if (!m_impl->m_framePropertiesStack.empty()) +@@ -968,6 +996,11 @@ void EPUBHTMLGenerator::closeTextBox() + m_impl->output().insertEmptyElement("br", attrs); + } + } ++ ++ if (!m_impl->m_paragraphAttributesStack.empty()) ++ m_impl->output(false).openElement("p", m_impl->m_paragraphAttributesStack.top()); ++ if (!m_impl->m_spanAttributesStack.empty()) ++ m_impl->output(false).openElement("span", m_impl->m_spanAttributesStack.top()); + } + + void EPUBHTMLGenerator::openTable(const RVNGPropertyList &propList) +-- +2.13.6 + +From a97e7f40bddba8e5d572b29811a19f34536190dc Mon Sep 17 00:00:00 2001 +From: Miklos Vajna +Date: Fri, 22 Dec 2017 17:16:23 +0100 +Subject: [PATCH] EPUBTableStyleManager: avoid vertical-align key without value + +ERROR(CSS-008): test.epub/OEBPS/styles/stylesheet.css(1625,19): An error occurred while parsing the CSS: Token ';' not allowed here, expecting a property value. +--- + src/lib/EPUBTableStyleManager.cpp | 5 +++-- + src/test/EPUBTextGeneratorTest.cpp | 6 +++++- + 2 files changed, 8 insertions(+), 3 deletions(-) + +diff --git a/src/lib/EPUBTableStyleManager.cpp b/src/lib/EPUBTableStyleManager.cpp +index a1ce33e..cf08737 100644 +--- a/src/lib/EPUBTableStyleManager.cpp ++++ b/src/lib/EPUBTableStyleManager.cpp +@@ -255,8 +255,9 @@ void EPUBTableStyleManager::extractCellProperties(RVNGPropertyList const &pList, + else + cssProps["text-align"] = pList["fo:text-align"]->getStr().cstr(); + } +- if (pList["style:vertical-align"]) +- cssProps["vertical-align"] = pList["style:vertical-align"]->getStr().cstr(); ++ const librevenge::RVNGProperty *verticalAlign = pList["style:vertical-align"]; ++ if (verticalAlign && !verticalAlign->getStr().empty()) ++ cssProps["vertical-align"] = verticalAlign->getStr().cstr(); + else + cssProps["vertical-align"] = "top"; + if (pList["fo:background-color"]) +-- +2.13.6 + +From 60baa7fb597cde57c3489d8b5066937e7edb779f Mon Sep 17 00:00:00 2001 +From: Miklos Vajna +Date: Fri, 22 Dec 2017 17:39:31 +0100 +Subject: [PATCH] EPUBHTMLGenerator: fix invalid XHTML with links at footnote + start + +ERROR(RSC-005): test3.epub/OEBPS/sections/section0001.xhtml(2,568): Error while parsing file: The a element must not appear inside a elements. +--- + src/lib/EPUBHTMLGenerator.cpp | 4 +++- + src/test/EPUBTextGeneratorTest.cpp | 9 +++++++++ + 2 files changed, 12 insertions(+), 1 deletion(-) + +diff --git a/src/lib/EPUBHTMLGenerator.cpp b/src/lib/EPUBHTMLGenerator.cpp +index bc9c1b7..59ded90 100644 +--- a/src/lib/EPUBHTMLGenerator.cpp ++++ b/src/lib/EPUBHTMLGenerator.cpp +@@ -781,7 +781,9 @@ void EPUBHTMLGenerator::openLink(const RVNGPropertyList &propList) + m_impl->m_linkPropertiesStack.push(linkProperties); + } + else +- m_impl->output(false).openElement("a", attrs); ++ // Implicit sendDelayed=true, so that in case the link is at the start of a ++ // footnote, links are not nested. ++ m_impl->output().openElement("a", attrs); + } + + void EPUBHTMLGenerator::closeLink() +-- +2.13.6 + -- cgit