summaryrefslogtreecommitdiff
path: root/external/libepubgen/libepubgen-epub3.patch.1
blob: 7ea3a365737f4e11095dee3af1a8d246e2c9f1dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
From 006848cb62225647c418d5143d4e88a9d73829da Mon Sep 17 00:00:00 2001
From: Miklos Vajna <vmiklos@collabora.co.uk>
Date: Fri, 22 Dec 2017 16:33:52 +0100
Subject: [PATCH] EPUBHTMLGenerator: avoid <div> inside <p> and/or <span>

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<RVNGPropertyList> m_framePropertiesStack;
   /// This is used for links which don't have a href.
   std::stack<RVNGPropertyList> m_linkPropertiesStack;
+  std::stack<RVNGPropertyList> m_paragraphAttributesStack;
+  std::stack<RVNGPropertyList> 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 <vmiklos@collabora.co.uk>
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 <vmiklos@collabora.co.uk>
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