summaryrefslogtreecommitdiff
path: root/writerperfect/source/writer
diff options
context:
space:
mode:
authorMark Hung <marklh9@gmail.com>2018-04-24 21:26:49 +0800
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-04-26 17:16:53 +0200
commit4fb081704811b66194ea11e528ad792957b7ccfd (patch)
tree51d74a4fde41ad0887b124d02400d1b71479c65d /writerperfect/source/writer
parent7a30e0d63d37eeb7b5c1e30791de17a51ddd0652 (diff)
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 <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'writerperfect/source/writer')
-rw-r--r--writerperfect/source/writer/exp/txtparai.cxx85
1 files changed, 85 insertions, 0 deletions
diff --git a/writerperfect/source/writer/exp/txtparai.cxx b/writerperfect/source/writer/exp/txtparai.cxx
index f219cf711880..297c5824ccf8 100644
--- a/writerperfect/source/writer/exp/txtparai.cxx
+++ b/writerperfect/source/writer/exp/txtparai.cxx
@@ -148,6 +148,89 @@ void XMLSpanContext::characters(const OUString& rChars)
mrImport.GetGenerator().closeSpan();
}
+/// Handler for <text:ruby>.
+class XMLRubyContext : public XMLImportContext
+{
+public:
+ XMLRubyContext(XMLImport& rImport, const librevenge::RVNGPropertyList& rPropertyList);
+
+ rtl::Reference<XMLImportContext>
+ CreateChildContext(const OUString& rName,
+ const css::uno::Reference<css::xml::sax::XAttributeList>& xAttribs) override;
+
+ void SAL_CALL endElement(const OUString& rName) override;
+
+ OUString m_sRubyText;
+ OUString m_sRubyBase;
+
+private:
+ librevenge::RVNGPropertyList m_aPropertyList;
+};
+
+/// Handler for <text:ruby-text>.
+class XMLRubyTextContext : public XMLImportContext
+{
+public:
+ XMLRubyTextContext(XMLImport& rImport, XMLRubyContext& rParent)
+ : XMLImportContext(rImport)
+ , m_rParent(rParent)
+ {
+ }
+
+ void SAL_CALL characters(const OUString& rChars) override { m_rParent.m_sRubyText = rChars; }
+
+private:
+ XMLRubyContext& m_rParent;
+};
+
+/// Handler for <text:ruby-base>.
+class XMLRubyBaseContext : public XMLImportContext
+{
+public:
+ XMLRubyBaseContext(XMLImport& rImport, XMLRubyContext& rParent)
+ : XMLImportContext(rImport)
+ , m_rParent(rParent)
+ {
+ }
+
+ void SAL_CALL characters(const OUString& rChars) override { m_rParent.m_sRubyBase += rChars; }
+
+private:
+ XMLRubyContext& m_rParent;
+};
+
+XMLRubyContext::XMLRubyContext(XMLImport& rImport,
+ const librevenge::RVNGPropertyList& rPropertyList)
+ : XMLImportContext(rImport)
+ , m_sRubyText()
+{
+ // Inherit properties from parent.
+ librevenge::RVNGPropertyList::Iter itProp(rPropertyList);
+ for (itProp.rewind(); itProp.next();)
+ m_aPropertyList.insert(itProp.key(), itProp()->clone());
+}
+
+rtl::Reference<XMLImportContext> XMLRubyContext::CreateChildContext(
+ const OUString& rName, const css::uno::Reference<css::xml::sax::XAttributeList>& /*xAttribs*/)
+{
+ if (rName == "text:ruby-base")
+ return new XMLRubyBaseContext(mrImport, *this);
+ if (rName == "text:ruby-text")
+ return new XMLRubyTextContext(mrImport, *this);
+ return nullptr;
+}
+
+void XMLRubyContext::endElement(const OUString& /*rName*/)
+{
+ OString sRubyText = OUStringToOString(m_sRubyText, RTL_TEXTENCODING_UTF8);
+ OString sRubyBase = OUStringToOString(m_sRubyBase, RTL_TEXTENCODING_UTF8);
+ if (sRubyText.getLength())
+ m_aPropertyList.insert("text:ruby-text", sRubyText.getStr());
+ mrImport.GetGenerator().openSpan(m_aPropertyList);
+ mrImport.GetGenerator().insertText(sRubyBase.getStr());
+ mrImport.GetGenerator().closeSpan();
+}
+
/// Base class for contexts that represent a single character only.
class XMLCharContext : public XMLImportContext
{
@@ -426,6 +509,8 @@ rtl::Reference<XMLImportContext> XMLParaContext::CreateChildContext(
return new XMLHyperlinkContext(mrImport, m_aTextPropertyList);
if (rName == "draw:a")
return new XMLTextFrameHyperlinkContext(mrImport, m_aTextPropertyList);
+ if (rName == "text:ruby")
+ return new XMLRubyContext(mrImport, m_aTextPropertyList);
return CreateParagraphOrSpanChildContext(mrImport, rName, m_aTextPropertyList);
}