From 4fb081704811b66194ea11e528ad792957b7ccfd Mon Sep 17 00:00:00 2001 From: Mark Hung Date: Tue, 24 Apr 2018 21:26:49 +0800 Subject: tdf#116822 export ruby text and base text to epub. Backport aa254c9e6f2d1ecfa2512111746a77c05ba9717f from libepubgen, implement XMLRubyContext, XMLRubyTextContext, XMLRubyBaseContext. Character formats of ruby text, ruby alignment, and ruby position are not implemented yet. Change-Id: I6c3708e6bc8e9e36a68171a037fd393f45d8d34f Reviewed-on: https://gerrit.libreoffice.org/53408 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- ...span-with-ruby-if-text-ruby-text-is-set.patch.1 | 117 +++++++++++++++++++++ external/libepubgen/UnpackedTarball_libepubgen.mk | 2 + 2 files changed, 119 insertions(+) create mode 100644 external/libepubgen/0001-Enclose-span-with-ruby-if-text-ruby-text-is-set.patch.1 (limited to 'external') diff --git a/external/libepubgen/0001-Enclose-span-with-ruby-if-text-ruby-text-is-set.patch.1 b/external/libepubgen/0001-Enclose-span-with-ruby-if-text-ruby-text-is-set.patch.1 new file mode 100644 index 000000000000..99c8523a9dc9 --- /dev/null +++ b/external/libepubgen/0001-Enclose-span-with-ruby-if-text-ruby-text-is-set.patch.1 @@ -0,0 +1,117 @@ +From 16c4e93af6d5eb9d021a671c54af664edc120df9 Mon Sep 17 00:00:00 2001 +From: Mark Hung +Date: Mon, 23 Apr 2018 01:24:48 +0800 +Subject: [PATCH] Enclose with if text:ruby-text is set. + +--- + src/lib/EPUBHTMLGenerator.cpp | 22 ++++++++++++++++++++++ + src/test/EPUBTextGeneratorTest.cpp | 25 +++++++++++++++++++++++++ + 2 files changed, 47 insertions(+) + +diff --git a/src/lib/EPUBHTMLGenerator.cpp b/src/lib/EPUBHTMLGenerator.cpp +index 0080816..a4467a9 100644 +--- a/src/lib/EPUBHTMLGenerator.cpp ++++ b/src/lib/EPUBHTMLGenerator.cpp +@@ -397,6 +397,7 @@ struct EPUBHTMLGeneratorImpl + , m_linkPropertiesStack() + , m_paragraphAttributesStack() + , m_spanAttributesStack() ++ , m_rubyText() + , m_stylesMethod(stylesMethod) + , m_layoutMethod(layoutMethod) + , m_actualSink() +@@ -500,6 +501,9 @@ struct EPUBHTMLGeneratorImpl + std::stack m_paragraphAttributesStack; + std::stack m_spanAttributesStack; + ++ /// This is set when the span has ruby text and should be wrapped in . ++ std::string m_rubyText; ++ + EPUBStylesMethod m_stylesMethod; + EPUBLayoutMethod m_layoutMethod; + +@@ -743,6 +747,14 @@ void EPUBHTMLGenerator::openSpan(const RVNGPropertyList &propList) + attrs.insert("style", m_impl->m_spanManager.getStyle(propList, false).c_str()); + break; + } ++ ++ const librevenge::RVNGProperty *rubyText = propList["text:ruby-text"]; ++ if (rubyText) ++ { ++ m_impl->m_rubyText = rubyText->getStr().cstr(); ++ m_impl->output(false).openElement("ruby", attrs); ++ } ++ + m_impl->output(false).openElement("span", attrs); + + librevenge::RVNGPropertyList::Iter i(attrs); +@@ -761,6 +773,16 @@ void EPUBHTMLGenerator::closeSpan() + m_impl->m_spanAttributesStack.pop(); + + m_impl->output().closeElement("span"); ++ ++ if (m_impl->m_rubyText.length()) ++ { ++ m_impl->output().openElement("rt"); ++ m_impl->output().insertCharacters(m_impl->m_rubyText.c_str()); ++ m_impl->output().closeElement("rt"); ++ m_impl->output().closeElement("ruby"); ++ m_impl->m_hasText = true; ++ m_impl->m_rubyText.clear(); ++ } + } + + void EPUBHTMLGenerator::openLink(const RVNGPropertyList &propList) +diff --git a/src/test/EPUBTextGeneratorTest.cpp b/src/test/EPUBTextGeneratorTest.cpp +index f03824f..61c7cac 100644 +--- a/src/test/EPUBTextGeneratorTest.cpp ++++ b/src/test/EPUBTextGeneratorTest.cpp +@@ -240,6 +240,7 @@ private: + CPPUNIT_TEST(testSplitOnHeadingInPageSpan); + CPPUNIT_TEST(testSplitOnSizeInPageSpan); + CPPUNIT_TEST(testManyWritingModes); ++ CPPUNIT_TEST(testRubyElements); + CPPUNIT_TEST_SUITE_END(); + + private: +@@ -284,6 +285,7 @@ private: + void testSplitOnHeadingInPageSpan(); + void testSplitOnSizeInPageSpan(); + void testManyWritingModes(); ++ void testRubyElements(); + + /// 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); +@@ -1507,6 +1509,29 @@ void EPUBTextGeneratorTest::testManyWritingModes() + assertXPath(package.m_streams["OEBPS/sections/section0002.xhtml"], "//xhtml:body", "class", "body1"); + } + ++void EPUBTextGeneratorTest::testRubyElements() ++{ ++ StringEPUBPackage package; ++ libepubgen::EPUBTextGenerator generator(&package); ++ generator.startDocument(librevenge::RVNGPropertyList()); ++ generator.openParagraph(librevenge::RVNGPropertyList()); ++ { ++ librevenge::RVNGPropertyList span; ++ span.insert("text:ruby-text", "ruby text"); ++ generator.openSpan(span); ++ generator.insertText("base text"); ++ generator.closeSpan(); ++ } ++ generator.closeParagraph(); ++ generator.endDocument(); ++ ++ // Expects: base textruby text ++ CPPUNIT_ASSERT_XPATH(package.m_streams["OEBPS/sections/section0001.xhtml"], "//xhtml:ruby", 1); ++ CPPUNIT_ASSERT_XPATH_CONTENT(package.m_streams["OEBPS/sections/section0001.xhtml"], "//xhtml:ruby/xhtml:rt", "ruby text"); ++ CPPUNIT_ASSERT_XPATH_CONTENT(package.m_streams["OEBPS/sections/section0001.xhtml"], "//xhtml:ruby/xhtml:span", "base text"); ++} ++ ++ + CPPUNIT_TEST_SUITE_REGISTRATION(EPUBTextGeneratorTest); + + } +-- +2.14.1 + diff --git a/external/libepubgen/UnpackedTarball_libepubgen.mk b/external/libepubgen/UnpackedTarball_libepubgen.mk index a6b2020f5f07..d7159f7e7bb5 100644 --- a/external/libepubgen/UnpackedTarball_libepubgen.mk +++ b/external/libepubgen/UnpackedTarball_libepubgen.mk @@ -16,6 +16,8 @@ epubgen_patches += 0001-Support-writing-mode-for-reflowable-layout-method.patch. epubgen_patches += 0002-Always-keep-page-properties-when-splitting-the-HTML-.patch.1 # Backport of . epubgen_patches += 0003-Ensure-page-properties-in-the-page-span-works.patch.1 +# Backport of +epubgen_patches += 0001-Enclose-span-with-ruby-if-text-ruby-text-is-set.patch.1 ifeq ($(COM_IS_CLANG),TRUE) ifneq ($(filter -fsanitize=%,$(CC)),) -- cgit v1.2.3