diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-08-17 10:58:33 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-08-17 14:10:02 +0200 |
commit | 9480ff6a2b6057410940ff5c40828d5746898a0e (patch) | |
tree | a93ff38ea67d971765a04ea4afe9a7d19d8d5759 /writerperfect | |
parent | d21b119df35ca43d3a4edeab2a809c345e0f617c (diff) |
EPUB export: implement link support
Not only the link but the text of it was also unhandled, add code for
both.
Change-Id: Ic3a26db64a10d44f1f94b7358ed9103bb68bbe95
Reviewed-on: https://gerrit.libreoffice.org/41245
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'writerperfect')
-rw-r--r-- | writerperfect/source/writer/exp/txtparai.cxx | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/writerperfect/source/writer/exp/txtparai.cxx b/writerperfect/source/writer/exp/txtparai.cxx index 02e4f78c1ef5..72cc401ceb91 100644 --- a/writerperfect/source/writer/exp/txtparai.cxx +++ b/writerperfect/source/writer/exp/txtparai.cxx @@ -50,6 +50,50 @@ void XMLSpanContext::characters(const OUString &rChars) mrImport.GetGenerator().insertText(librevenge::RVNGString(sCharU8.getStr())); } +/// Handler for <text:a>. +class XMLHyperlinkContext : public XMLImportContext +{ +public: + XMLHyperlinkContext(XMLImport &rImport); + + void SAL_CALL startElement(const OUString &rName, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) override; + void SAL_CALL endElement(const OUString &rName) override; + void SAL_CALL characters(const OUString &rChars) override; +}; + +XMLHyperlinkContext::XMLHyperlinkContext(XMLImport &rImport) + : XMLImportContext(rImport) +{ +} + +void XMLHyperlinkContext::startElement(const OUString &/*rName*/, const css::uno::Reference<css::xml::sax::XAttributeList> &xAttribs) +{ + librevenge::RVNGPropertyList aPropertyList; + for (sal_Int16 i = 0; i < xAttribs->getLength(); ++i) + { + const OUString &rAttributeName = xAttribs->getNameByIndex(i); + if (rAttributeName == "xlink:href") + { + OString sName = OUStringToOString(rAttributeName, RTL_TEXTENCODING_UTF8); + OString sValue = OUStringToOString(xAttribs->getValueByIndex(i), RTL_TEXTENCODING_UTF8); + aPropertyList.insert(sName.getStr(), sValue.getStr()); + } + } + + mrImport.GetGenerator().openLink(aPropertyList); +} + +void XMLHyperlinkContext::endElement(const OUString &/*rName*/) +{ + mrImport.GetGenerator().closeLink(); +} + +void XMLHyperlinkContext::characters(const OUString &rChars) +{ + OString sCharU8 = OUStringToOString(rChars, RTL_TEXTENCODING_UTF8); + mrImport.GetGenerator().insertText(librevenge::RVNGString(sCharU8.getStr())); +} + XMLParaContext::XMLParaContext(XMLImport &rImport) : XMLImportContext(rImport) { @@ -59,6 +103,8 @@ XMLImportContext *XMLParaContext::CreateChildContext(const OUString &rName, cons { if (rName == "text:span") return new XMLSpanContext(mrImport); + if (rName == "text:a") + return new XMLHyperlinkContext(mrImport); return nullptr; } |