Bugzilla – Attachment 140714 Details for
Bug 115623
EPUB: support vertical writing mode (tb)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for libepubgen to support writing-mode
writing-mode.patch.1 (text/plain), 11.26 KB, created by
Mark Hung
on 2018-03-19 15:10:42 UTC
(
hide
)
Description:
Patch for libepubgen to support writing-mode
Filename:
MIME Type:
Creator:
Mark Hung
Created:
2018-03-19 15:10:42 UTC
Size:
11.26 KB
patch
obsolete
>From 196f3642f0196250843bea7d7ca7e7b3eb0a9e27 Mon Sep 17 00:00:00 2001 >From: Mark Hung <marklh9@gmail.com> >Date: Mon, 19 Mar 2018 20:36:11 +0800 >Subject: [PATCH] writing-mode support of reflowable layout method. > >1. Convert style:writing-mode in page properties to css >properites and put them in body style or class. The >classes for body elements are body#. openPageSpan >must be invoked with reflowable layout method. > >2. Always keep the page properties for splitted pages: >For whatever reasons ( size, title, etc. ) it splits >the page before closePageSpan, it should keep the original page >properties. >--- > src/lib/EPUBGenerator.cpp | 8 ++++--- > src/lib/EPUBHTMLGenerator.cpp | 18 +++++++++++++-- > src/lib/EPUBSpanStyleManager.cpp | 45 ++++++++++++++++++++++++++++++++------ > src/lib/EPUBSpanStyleManager.h | 14 ++++++++---- > src/test/EPUBTextGeneratorTest.cpp | 41 ++++++++++++++++++++++++++++++++++ > 5 files changed, 110 insertions(+), 16 deletions(-) > >diff --git a/src/lib/EPUBGenerator.cpp b/src/lib/EPUBGenerator.cpp >index 83f3f40..3ec8883 100644 >--- a/src/lib/EPUBGenerator.cpp >+++ b/src/lib/EPUBGenerator.cpp >@@ -119,11 +119,13 @@ void EPUBGenerator::startNewHtmlFile() > m_splitGuard.onSplit(); > > librevenge::RVNGPropertyList pageProperties; >- if (m_layoutMethod == EPUB_LAYOUT_METHOD_FIXED && m_currentHtml) >+ if (m_currentHtml) > m_currentHtml->getPageProperties(pageProperties); > m_currentHtml = m_htmlManager.create(m_imageManager, m_fontManager, m_listStyleManager, m_paragraphStyleManager, m_spanStyleManager, m_tableStyleManager, m_stylesheetPath, m_stylesMethod, m_layoutMethod, m_version); >- if (m_layoutMethod == EPUB_LAYOUT_METHOD_FIXED) >- m_currentHtml->setPageProperties(pageProperties); >+ >+ // The splitted page should keep the old page properties. >+ // Only openPageSpan can update the page properties. >+ m_currentHtml->setPageProperties(pageProperties); > > // restore state in the new file > m_currentHtml->startDocument(m_documentProps); >diff --git a/src/lib/EPUBHTMLGenerator.cpp b/src/lib/EPUBHTMLGenerator.cpp >index 342213e..d5cc0d2 100644 >--- a/src/lib/EPUBHTMLGenerator.cpp >+++ b/src/lib/EPUBHTMLGenerator.cpp >@@ -600,6 +600,20 @@ void EPUBHTMLGenerator::endDocument() > RVNGPropertyList bodyAttrs; > if (m_impl->m_version >= 30) > bodyAttrs.insert("xmlns:epub", "http://www.idpf.org/2007/ops"); >+ >+ if (m_impl->m_actualPageProperties["style:writing-mode"]) >+ { >+ switch (m_impl->m_stylesMethod) >+ { >+ case EPUB_STYLES_METHOD_CSS: >+ bodyAttrs.insert("class", m_impl->m_spanManager.getClass(m_impl->m_actualPageProperties, true).c_str()); >+ break; >+ case EPUB_STYLES_METHOD_INLINE: >+ bodyAttrs.insert("style", m_impl->m_spanManager.getStyle(m_impl->m_actualPageProperties, true).c_str()); >+ break; >+ } >+ } >+ > m_impl->m_document.openElement("body", bodyAttrs); > m_impl->flushUnsent(m_impl->m_document); > m_impl->m_document.closeElement("body"); >@@ -710,10 +724,10 @@ void EPUBHTMLGenerator::openSpan(const RVNGPropertyList &propList) > switch (m_impl->m_stylesMethod) > { > case EPUB_STYLES_METHOD_CSS: >- attrs.insert("class", m_impl->m_spanManager.getClass(propList).c_str()); >+ attrs.insert("class", m_impl->m_spanManager.getClass(propList, false).c_str()); > break; > case EPUB_STYLES_METHOD_INLINE: >- attrs.insert("style", m_impl->m_spanManager.getStyle(propList).c_str()); >+ attrs.insert("style", m_impl->m_spanManager.getStyle(propList, false).c_str()); > break; > } > m_impl->output(false).openElement("span", attrs); >diff --git a/src/lib/EPUBSpanStyleManager.cpp b/src/lib/EPUBSpanStyleManager.cpp >index e25fa26..25eea26 100644 >--- a/src/lib/EPUBSpanStyleManager.cpp >+++ b/src/lib/EPUBSpanStyleManager.cpp >@@ -21,7 +21,7 @@ namespace libepubgen > > using librevenge::RVNGPropertyList; > >-std::string EPUBSpanStyleManager::getClass(RVNGPropertyList const &pList) >+std::string EPUBSpanStyleManager::getClass(RVNGPropertyList const &pList, bool bIsBody) > { > if (pList["librevenge:span-id"]) > { >@@ -31,20 +31,31 @@ std::string EPUBSpanStyleManager::getClass(RVNGPropertyList const &pList) > } > > EPUBCSSProperties content; >- extractProperties(pList, content); >+ if (bIsBody) >+ extractBodyProperties(pList, content); >+ else >+ extractSpanProperties(pList, content); >+ > ContentNameMap_t::const_iterator it = m_contentNameMap.find(content); > if (it != m_contentNameMap.end()) > return it->second; > std::stringstream s; >- s << "span" << m_contentNameMap.size(); >+ if (bIsBody) >+ s << "body" << (m_numberBody.next() - 1); >+ else >+ s << "span" << (m_numberSpan.next() - 1); >+ > m_contentNameMap[content]=s.str(); > return s.str(); > } > >-std::string EPUBSpanStyleManager::getStyle(RVNGPropertyList const &pList) >+std::string EPUBSpanStyleManager::getStyle(RVNGPropertyList const &pList, bool bIsBody) > { > EPUBCSSProperties content; >- extractProperties(pList, content); >+ if (bIsBody) >+ extractBodyProperties(pList, content); >+ else >+ extractSpanProperties(pList, content); > > std::stringstream s; > for (const auto &property : content) >@@ -62,7 +73,7 @@ void EPUBSpanStyleManager::defineSpan(RVNGPropertyList const &propList) > int id=propList["librevenge:span-id"]->getInt(); > RVNGPropertyList pList(propList); > pList.remove("librevenge:span-id"); >- m_idNameMap[id]=getClass(pList); >+ m_idNameMap[id]=getClass(pList, false); > } > > void EPUBSpanStyleManager::send(EPUBCSSSink &out) >@@ -75,7 +86,7 @@ void EPUBSpanStyleManager::send(EPUBCSSSink &out) > } > } > >-void EPUBSpanStyleManager::extractProperties(RVNGPropertyList const &pList, EPUBCSSProperties &cssProps) const >+void EPUBSpanStyleManager::extractSpanProperties(RVNGPropertyList const &pList, EPUBCSSProperties &cssProps) const > { > if (pList["fo:background-color"]) > cssProps["background-color"] = pList["fo:background-color"]->getStr().cstr(); >@@ -227,6 +238,26 @@ void EPUBSpanStyleManager::extractTextPosition(char const *value, EPUBCSSPropert > } > } > >+void EPUBSpanStyleManager::extractBodyProperties(RVNGPropertyList const &pList, EPUBCSSProperties &cssProps) const >+{ >+ if (pList["style:writing-mode"]) >+ { >+ std::string mode = pList["style:writing-mode"]->getStr().cstr(); >+ if (mode == "tb-rl") >+ mode = "vertical-rl"; >+ else if (mode == "tb-lr") >+ mode = "vertical-lr"; >+ else >+ { >+ mode = "horizontal-tb"; >+ cssProps["direction"] = (mode == "rl-tb" || mode == "rl")?"rtl":"ltr"; >+ } >+ >+ cssProps["-epub-writing-mode"] = mode; >+ cssProps["-webkit-writing-mode"] = mode; >+ cssProps["writing-mode"] = mode; >+ } >+} > } > > /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ >diff --git a/src/lib/EPUBSpanStyleManager.h b/src/lib/EPUBSpanStyleManager.h >index ec9d0e5..6c18392 100644 >--- a/src/lib/EPUBSpanStyleManager.h >+++ b/src/lib/EPUBSpanStyleManager.h >@@ -19,6 +19,7 @@ > #include <librevenge/librevenge.h> > > #include "EPUBCSSProperties.h" >+#include "EPUBCounter.h" > > namespace libepubgen > { >@@ -32,7 +33,7 @@ class EPUBSpanStyleManager > > public: > //! constructor >- EPUBSpanStyleManager() : m_contentNameMap(), m_idNameMap() >+ EPUBSpanStyleManager() : m_contentNameMap(), m_idNameMap(), m_numberSpan(), m_numberBody() > { > } > //! destructor >@@ -42,14 +43,16 @@ public: > //! define a span style > void defineSpan(librevenge::RVNGPropertyList const &pList); > //! returns the class name corresponding to a propertylist >- std::string getClass(librevenge::RVNGPropertyList const &pList); >+ std::string getClass(librevenge::RVNGPropertyList const &pList, bool bIsBody); > //! returns the style string corresponding to a propertylist >- std::string getStyle(librevenge::RVNGPropertyList const &pList); >+ std::string getStyle(librevenge::RVNGPropertyList const &pList, bool bIsBody); > //! send the data to the sink > void send(EPUBCSSSink &out); > protected: > //! convert a property list into a CSS property map >- void extractProperties(librevenge::RVNGPropertyList const &pList, EPUBCSSProperties &cssProps) const; >+ void extractSpanProperties(librevenge::RVNGPropertyList const &pList, EPUBCSSProperties &cssProps) const; >+ //! Extract body styles from a property list into a CSS property map >+ void extractBodyProperties(librevenge::RVNGPropertyList const &pList, EPUBCSSProperties &cssProps) const; > //! add data corresponding to a text position into the map > void extractTextPosition(char const *value, EPUBCSSProperties &cssProps) const; > //! add data corresponding to the line decoration into the map >@@ -59,6 +62,9 @@ protected: > //! a map id -> name > std::map<int, std::string> m_idNameMap; > >+ EPUBCounter m_numberSpan; >+ EPUBCounter m_numberBody; >+ > private: > EPUBSpanStyleManager(EPUBSpanStyleManager const &orig); > EPUBSpanStyleManager operator=(EPUBSpanStyleManager const &orig); >diff --git a/src/test/EPUBTextGeneratorTest.cpp b/src/test/EPUBTextGeneratorTest.cpp >index ddf0c90..5bc1cb9 100644 >--- a/src/test/EPUBTextGeneratorTest.cpp >+++ b/src/test/EPUBTextGeneratorTest.cpp >@@ -235,6 +235,7 @@ private: > CPPUNIT_TEST(testFixedLayoutSpine); > CPPUNIT_TEST(testPageBreak); > CPPUNIT_TEST(testPageBreakImage); >+ CPPUNIT_TEST(testWritingMode); > CPPUNIT_TEST_SUITE_END(); > > private: >@@ -274,6 +275,7 @@ private: > void testFixedLayoutSpine(); > void testPageBreak(); > void testPageBreakImage(); >+ void testWritingMode(); > > /// Asserts that exactly one xpath exists in buffer, and its content equals content. > void assertXPathContent(xmlBufferPtr buffer, const std::string &xpath, const std::string &content); >@@ -1350,6 +1352,45 @@ void EPUBTextGeneratorTest::testPageBreakImage() > CPPUNIT_ASSERT(package.m_streams.find("OEBPS/sections/section0002.xhtml") != package.m_streams.end()); > } > >+void EPUBTextGeneratorTest::testWritingMode() >+{ >+ librevenge::RVNGPropertyList page; >+ page.insert("style:writing-mode", "tb-rl"); >+ >+ StringEPUBPackage package; >+ libepubgen::EPUBTextGenerator generator(&package); >+ generator.setOption(libepubgen::EPUB_GENERATOR_OPTION_SPLIT, libepubgen::EPUB_SPLIT_METHOD_HEADING); >+ generator.startDocument(librevenge::RVNGPropertyList()); >+ generator.openPageSpan(page); >+ >+ { >+ librevenge::RVNGPropertyList propertyList; >+ propertyList.insert("text:outline-level", "1"); >+ generator.openParagraph(propertyList); >+ generator.insertText("Chapter 1"); >+ generator.closeParagraph(); >+ } >+ { >+ librevenge::RVNGPropertyList propertyList; >+ propertyList.insert("text:outline-level", "1"); >+ generator.openParagraph(propertyList); >+ generator.insertText("Chapter 2"); >+ generator.closeParagraph(); >+ } >+ >+ generator.closePageSpan(); >+ generator.endDocument(); >+ >+ // Make sure that the content was split to two sections. >+ CPPUNIT_ASSERT(package.m_streams.find("OEBPS/sections/section0001.xhtml") != package.m_streams.end()); >+ CPPUNIT_ASSERT(package.m_streams.find("OEBPS/sections/section0002.xhtml") != package.m_streams.end()); >+ CPPUNIT_ASSERT(package.m_streams.find("OEBPS/sections/section0003.xhtml") == package.m_streams.end()); >+ >+ assertCss(package.m_cssStreams["OEBPS/styles/stylesheet.css"], ".body0", "-epub-writing-mode: vertical-rl", false); >+ assertCss(package.m_cssStreams["OEBPS/styles/stylesheet.css"], ".body0", "-webkit-writing-mode: vertical-rl", false); >+ assertCss(package.m_cssStreams["OEBPS/styles/stylesheet.css"], ".body0", "writing-mode: vertical-rl", false); >+} >+ > CPPUNIT_TEST_SUITE_REGISTRATION(EPUBTextGeneratorTest); > > } >-- >2.14.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 115623
:
139833
|
140714
|
140871