summaryrefslogtreecommitdiff
path: root/external/libepubgen
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-08-17 10:15:34 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-08-17 11:27:49 +0200
commitec4034c4a4f23574401ba2a74b635d9ed4befbc8 (patch)
tree18e75f9a051282dd1fe4b135b88ef7c4a057de39 /external/libepubgen
parent6255575c475a25698a4c7145923abbb46f58313d (diff)
EPUB export: use real chapter names
Instead of "Seciton N" placeholders, by backporting the relevant libepubgen commit. Change-Id: I7073658597205927eeefc4e63ec23bd95cf4f30c Reviewed-on: https://gerrit.libreoffice.org/41241 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'external/libepubgen')
-rw-r--r--external/libepubgen/libepubgen-epub3.patch.1214
1 files changed, 214 insertions, 0 deletions
diff --git a/external/libepubgen/libepubgen-epub3.patch.1 b/external/libepubgen/libepubgen-epub3.patch.1
index 0da826609e23..32aa72d76a32 100644
--- a/external/libepubgen/libepubgen-epub3.patch.1
+++ b/external/libepubgen/libepubgen-epub3.patch.1
@@ -1192,3 +1192,217 @@ index cb557b2..aba8827 100644
--
2.12.3
+From 576c2472e384ea1a71739b15f42561cd34de5bba Mon Sep 17 00:00:00 2001
+From: Miklos Vajna <vmiklos@collabora.co.uk>
+Date: Wed, 16 Aug 2017 17:52:37 +0200
+Subject: [PATCH] EPUB_SPLIT_METHOD_HEADING: try to use real chapter names, not
+ Section N
+
+What users call "chapter title" is the text of a paragraph with an
+outline level set.
+
+To keep this simple just handle the text after opening such a paragraph,
+but no other paragraph is opened, i.e. assume that in:
+
+<para outline=y>A<para outline=n>B</para>C</para>
+
+only A is interesting, but not B, neither C. (Which could happen with an
+at-character anchored frame inside a heading text e.g.)
+---
+ src/lib/EPUBGenerator.cpp | 5 +++++
+ src/lib/EPUBGenerator.h | 2 ++
+ src/lib/EPUBHTMLManager.cpp | 26 ++++++++++++++++++++++++--
+ src/lib/EPUBHTMLManager.h | 3 +++
+ src/lib/EPUBPath.cpp | 11 +++++++++++
+ src/lib/EPUBPath.h | 4 ++++
+ src/lib/EPUBTextGenerator.cpp | 6 ++++++
+ 7 files changed, 55 insertions(+), 2 deletions(-)
+
+diff --git a/src/lib/EPUBGenerator.cpp b/src/lib/EPUBGenerator.cpp
+index 4bffb8b..4ce2964 100644
+--- a/src/lib/EPUBGenerator.cpp
++++ b/src/lib/EPUBGenerator.cpp
+@@ -106,6 +106,11 @@ const EPUBHTMLGeneratorPtr_t &EPUBGenerator::getHtml() const
+ return m_currentHtml;
+ }
+
++EPUBHTMLManager &EPUBGenerator::getHtmlManager()
++{
++ return m_htmlManager;
++}
++
+ const EPUBSplitGuard &EPUBGenerator::getSplitGuard() const
+ {
+ return m_splitGuard;
+diff --git a/src/lib/EPUBGenerator.h b/src/lib/EPUBGenerator.h
+index 1a67a88..f98c80f 100644
+--- a/src/lib/EPUBGenerator.h
++++ b/src/lib/EPUBGenerator.h
+@@ -45,6 +45,8 @@ public:
+
+ const EPUBHTMLGeneratorPtr_t &getHtml() const;
+
++ EPUBHTMLManager &getHtmlManager();
++
+ const EPUBSplitGuard &getSplitGuard() const;
+ EPUBSplitGuard &getSplitGuard();
+ int getVersion() const;
+diff --git a/src/lib/EPUBHTMLManager.cpp b/src/lib/EPUBHTMLManager.cpp
+index be56cc7..5141f31 100644
+--- a/src/lib/EPUBHTMLManager.cpp
++++ b/src/lib/EPUBHTMLManager.cpp
+@@ -18,6 +18,20 @@
+ namespace libepubgen
+ {
+
++namespace
++{
++
++/// Extracts a title string from a path and provides a fallback if it would be empty.
++void getPathTitle(std::ostringstream &label, const EPUBPath &path, std::vector<EPUBPath>::size_type index)
++{
++ if (path.getTitle().empty())
++ label << "Section " << (index + 1);
++ else
++ label << path.getTitle();
++}
++
++}
++
+ EPUBHTMLManager::EPUBHTMLManager(EPUBManifest &manifest)
+ : m_manifest(manifest)
+ , m_paths()
+@@ -78,7 +92,7 @@ void EPUBHTMLManager::writeTocTo(EPUBXMLSink &sink, const EPUBPath &tocPath, int
+ anchorAttrs.insert("href", m_paths[i].relativeTo(tocPath).str().c_str());
+ sink.openElement("a", anchorAttrs);
+ std::ostringstream label;
+- label << "Section " << (i + 1);
++ getPathTitle(label, m_paths[i], i);
+ sink.insertCharacters(label.str().c_str());
+ sink.closeElement("a");
+ sink.closeElement("li");
+@@ -101,7 +115,7 @@ void EPUBHTMLManager::writeTocTo(EPUBXMLSink &sink, const EPUBPath &tocPath, int
+ sink.openElement("navLabel");
+ sink.openElement("text");
+ std::ostringstream label;
+- label << "Section " << (i + 1);
++ getPathTitle(label, m_paths[i], i);
+ sink.insertCharacters(label.str().c_str());
+ sink.closeElement("text");
+ sink.closeElement("navLabel");
+@@ -112,6 +126,14 @@ void EPUBHTMLManager::writeTocTo(EPUBXMLSink &sink, const EPUBPath &tocPath, int
+ }
+ }
+
++void EPUBHTMLManager::insertHeadingText(const std::string &text)
++{
++ if (m_paths.empty())
++ return;
++
++ m_paths.back().appendTitle(text);
++}
++
+ }
+
+ /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
+diff --git a/src/lib/EPUBHTMLManager.h b/src/lib/EPUBHTMLManager.h
+index 2ec7bb7..6b480c4 100644
+--- a/src/lib/EPUBHTMLManager.h
++++ b/src/lib/EPUBHTMLManager.h
+@@ -48,6 +48,9 @@ public:
+ void writeSpineTo(EPUBXMLSink &sink);
+ void writeTocTo(EPUBXMLSink &sink, const EPUBPath &tocPath, int version);
+
++ /// Appends text to the title of the current heading.
++ void insertHeadingText(const std::string &text);
++
+ private:
+ EPUBManifest &m_manifest;
+ std::vector<EPUBPath> m_paths;
+diff --git a/src/lib/EPUBPath.cpp b/src/lib/EPUBPath.cpp
+index 9def6f6..e1c05ed 100644
+--- a/src/lib/EPUBPath.cpp
++++ b/src/lib/EPUBPath.cpp
+@@ -53,6 +53,7 @@ EPUBPath::Relative::Relative(const std::vector<std::string> &components)
+
+ EPUBPath::EPUBPath(const std::string &path)
+ : m_components()
++ , m_title()
+ {
+ const std::string trimmed(algorithm::trim_left_copy_if(path, algorithm::is_any_of("/")));
+ algorithm::split(m_components, trimmed, algorithm::is_any_of("/"), algorithm::token_compress_on);
+@@ -110,6 +111,16 @@ const EPUBPath::Relative EPUBPath::relativeTo(const EPUBPath &base) const
+ return Relative(components);
+ }
+
++void EPUBPath::appendTitle(const std::string &title)
++{
++ m_title += title;
++}
++
++std::string EPUBPath::getTitle() const
++{
++ return m_title;
++}
++
+ bool operator==(const EPUBPath &left, const EPUBPath &right)
+ {
+ return left.m_components == right.m_components;
+diff --git a/src/lib/EPUBPath.h b/src/lib/EPUBPath.h
+index 18bf058..12b8f25 100644
+--- a/src/lib/EPUBPath.h
++++ b/src/lib/EPUBPath.h
+@@ -48,8 +48,12 @@ public:
+
+ const Relative relativeTo(const EPUBPath &base) const;
+
++ void appendTitle(const std::string &title);
++ std::string getTitle() const;
++
+ private:
+ std::vector<std::string> m_components;
++ std::string m_title;
+ };
+
+ bool operator==(const EPUBPath &left, const EPUBPath &right);
+diff --git a/src/lib/EPUBTextGenerator.cpp b/src/lib/EPUBTextGenerator.cpp
+index aba8827..b1e33f8 100644
+--- a/src/lib/EPUBTextGenerator.cpp
++++ b/src/lib/EPUBTextGenerator.cpp
+@@ -67,6 +67,7 @@ public:
+ bool m_inPageSpan;
+ bool m_inHeader;
+ bool m_inFooter;
++ bool m_inHeading;
+
+ RVNGPropertyList m_pageSpanProps;
+ shared_ptr<EPUBTextElements> m_currentHeader;
+@@ -88,6 +89,7 @@ EPUBTextGenerator::Impl::Impl(EPUBPackage *const package, const EPUBSplitMethod
+ , m_inPageSpan(false)
+ , m_inHeader(false)
+ , m_inFooter(false)
++ , m_inHeading(false)
+ , m_pageSpanProps()
+ , m_currentHeader()
+ , m_currentFooter()
+@@ -260,6 +262,7 @@ void EPUBTextGenerator::openParagraph(const librevenge::RVNGPropertyList &propLi
+ const RVNGProperty *const outlineLevel = propList["text:outline-level"];
+ if (outlineLevel && m_impl->getSplitGuard().splitOnHeading(outlineLevel->getInt()))
+ m_impl->startNewHtmlFile();
++ m_impl->m_inHeading = outlineLevel != nullptr;
+
+ m_impl->getSplitGuard().openLevel();
+
+@@ -366,6 +369,9 @@ void EPUBTextGenerator::insertText(const librevenge::RVNGString &text)
+ if (m_impl->m_inHeader || m_impl->m_inFooter)
+ m_impl->m_currentHeaderOrFooter->addInsertText(text);
+
++ if (m_impl->m_inHeading)
++ m_impl->getHtmlManager().insertHeadingText(text.cstr());
++
+ m_impl->getSplitGuard().incrementSize(text.len());
+
+ m_impl->getHtml()->insertText(text);
+--
+2.12.3
+