diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-01-18 15:53:54 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-01-19 09:11:12 +0100 |
commit | 9035ee7c90ed5ff78864145fd92241491033c074 (patch) | |
tree | 9bbdf4bf8f8c6c285f55d446118ed7cadc65da49 /writerperfect/source | |
parent | d5d4166df8ad189761387146966c91d58c28076f (diff) |
EPUB export: accept relative links for image popup from default media dir
Previously:
- the user had to copy the linked image to the same dir as the doc
- set a relative link on the image (in ODF, it resulted in "../foo.png")
- copy the image to the media dir ("test" by default for "test.odt")
- export to EPUB to have the image popup
Now, additionally:
- relative link may point to the default media dir (in ODF, it results
in "../test/foo.png")
- no need to copy the image
- export to EPUB creates the popup
So one less step is necessary. The downside is that this way the
relative URL contain the base name of the document, so renaming the
document breaks these relative links.
Change-Id: I93894a28393d36a33dcec7bfe7c4a54fd83768da
Diffstat (limited to 'writerperfect/source')
-rw-r--r-- | writerperfect/source/writer/exp/xmlimp.cxx | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/writerperfect/source/writer/exp/xmlimp.cxx b/writerperfect/source/writer/exp/xmlimp.cxx index f600840be1d7..f001bd667e5a 100644 --- a/writerperfect/source/writer/exp/xmlimp.cxx +++ b/writerperfect/source/writer/exp/xmlimp.cxx @@ -367,6 +367,16 @@ const librevenge::RVNGPropertyList &XMLImport::GetMetaData() return maMetaData; } +namespace +{ +/// Finds out if a file URL exists. +bool FileURLExists(const OUString& rURL) +{ + SvFileStream aStream(rURL, StreamMode::READ); + return aStream.IsOpen(); +} +} + PopupState XMLImport::FillPopupData(const OUString &rURL, librevenge::RVNGPropertyList &rPropList) { uno::Reference<uri::XUriReference> xUriRef; @@ -384,16 +394,20 @@ PopupState XMLImport::FillPopupData(const OUString &rURL, librevenge::RVNGProper if (bAbsolute) return PopupState::NotConsumed; + // Default case: relative URL, popup data was in the same directory as the + // document at insertion time. OUString aAbs = maMediaDir + rURL; - if (aAbs.isEmpty()) - return PopupState::NotConsumed; + if (!FileURLExists(aAbs)) + // Fallback case: relative URL, popup data was in the default media + // directory at insertion time. + aAbs = maMediaDir + "../" + rURL; - SvFileStream aStream(aAbs, StreamMode::READ); - if (!aStream.IsOpen()) + if (!FileURLExists(aAbs)) // Relative link, but points to non-existing file: don't emit that to // librevenge, since it will be invalid anyway. return PopupState::Ignore; + SvFileStream aStream(aAbs, StreamMode::READ); librevenge::RVNGBinaryData aBinaryData; SvMemoryStream aMemoryStream; aMemoryStream.WriteStream(aStream); |