diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-11-30 16:36:03 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-12-01 09:18:01 +0100 |
commit | 1a0a026a5770ca2e8ca66e1e8daed101301c7e30 (patch) | |
tree | 4639fc9ac509e0f7abe5d0f6092f8eacb0bd36e0 /writerperfect | |
parent | 3ed60d22c3c2a43d0460520485c3b6ecca00e239 (diff) |
EPUB export: handle custom media dir in cover image / XMP metadata
By changing the default to <media dir>/cover.<extension> and <media
dir>/<basename>.xmp.
Change-Id: I736aefafba5aa5208917d9ed40119ca7721cdde3
Reviewed-on: https://gerrit.libreoffice.org/45604
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'writerperfect')
-rw-r--r-- | writerperfect/qa/unit/data/writer/epubexport/meta-xmp/meta-xmp.xmp (renamed from writerperfect/qa/unit/data/writer/epubexport/meta-xmp.xmp) | 0 | ||||
-rw-r--r-- | writerperfect/qa/unit/data/writer/epubexport/meta/cover.png (renamed from writerperfect/qa/unit/data/writer/epubexport/meta.cover-image.png) | bin | 766 -> 766 bytes | |||
-rw-r--r-- | writerperfect/source/writer/exp/xmlimp.cxx | 88 |
3 files changed, 35 insertions, 53 deletions
diff --git a/writerperfect/qa/unit/data/writer/epubexport/meta-xmp.xmp b/writerperfect/qa/unit/data/writer/epubexport/meta-xmp/meta-xmp.xmp index aa578159cb89..aa578159cb89 100644 --- a/writerperfect/qa/unit/data/writer/epubexport/meta-xmp.xmp +++ b/writerperfect/qa/unit/data/writer/epubexport/meta-xmp/meta-xmp.xmp diff --git a/writerperfect/qa/unit/data/writer/epubexport/meta.cover-image.png b/writerperfect/qa/unit/data/writer/epubexport/meta/cover.png Binary files differindex fdad35484e7c..fdad35484e7c 100644 --- a/writerperfect/qa/unit/data/writer/epubexport/meta.cover-image.png +++ b/writerperfect/qa/unit/data/writer/epubexport/meta/cover.png diff --git a/writerperfect/source/writer/exp/xmlimp.cxx b/writerperfect/source/writer/exp/xmlimp.cxx index f933487a59b8..ad4928f17a65 100644 --- a/writerperfect/source/writer/exp/xmlimp.cxx +++ b/writerperfect/source/writer/exp/xmlimp.cxx @@ -49,6 +49,37 @@ OUString GetMimeType(const OUString &rExtension) return it == vMimeTypes.end() ? OUString() : it->second; } +/// Determines the base directory for cover images, XMP metadata, popup images. +OUString FindMediaDir(const OUString &rDocumentBaseURL, const uno::Sequence<beans::PropertyValue> &rFilterData) +{ + OUString aMediaDir; + + // See if filter data contains a media directory explicitly. + for (sal_Int32 i = 0; i < rFilterData.getLength(); ++i) + { + if (rFilterData[i].Name == "RVNGMediaDir") + { + rFilterData[i].Value >>= aMediaDir; + break; + } + } + + if (!aMediaDir.isEmpty()) + return aMediaDir + "/"; + + // Not set explicitly, try to pick it up from the base directory. + INetURLObject aURL(rDocumentBaseURL); + try + { + aMediaDir = rtl::Uri::convertRelToAbs(rDocumentBaseURL, aURL.GetBase()) + "/"; + } + catch (const rtl::MalformedUriException &rException) + { + SAL_WARN("writerperfect", "FindMediaDir: convertRelToAbs() failed:" << rException.getMessage()); + } + return aMediaDir; +} + /// Picks up a cover image from the base directory. OUString FindCoverImage(const OUString &rDocumentBaseURL, OUString &rMimeType, const uno::Sequence<beans::PropertyValue> &rFilterData) { @@ -75,8 +106,6 @@ OUString FindCoverImage(const OUString &rDocumentBaseURL, OUString &rMimeType, c if (rDocumentBaseURL.isEmpty()) return aRet; - INetURLObject aDocumentBaseURL(rDocumentBaseURL); - static const std::initializer_list<OUStringLiteral> vExtensions = { "gif", @@ -85,17 +114,10 @@ OUString FindCoverImage(const OUString &rDocumentBaseURL, OUString &rMimeType, c "svg" }; + OUString aMediaDir = FindMediaDir(rDocumentBaseURL, rFilterData); for (const auto &rExtension : vExtensions) { - try - { - aRet = rtl::Uri::convertRelToAbs(rDocumentBaseURL, aDocumentBaseURL.GetBase() + ".cover-image." + rExtension); - } - catch (const rtl::MalformedUriException &rException) - { - SAL_WARN("writerperfect", "FindCoverImage: convertRelToAbs() failed:" << rException.getMessage()); - } - + aRet = aMediaDir + "cover." + rExtension; if (!aRet.isEmpty()) { SvFileStream aStream(aRet, StreamMode::READ); @@ -113,37 +135,6 @@ OUString FindCoverImage(const OUString &rDocumentBaseURL, OUString &rMimeType, c return aRet; } -/// Determines the base directory for cover images, XMP metadata, popup images. -OUString FindMediaDir(const OUString &rDocumentBaseURL, const uno::Sequence<beans::PropertyValue> &rFilterData) -{ - OUString aMediaDir; - - // See if filter data contains a media directory explicitly. - for (sal_Int32 i = 0; i < rFilterData.getLength(); ++i) - { - if (rFilterData[i].Name == "RVNGMediaDir") - { - rFilterData[i].Value >>= aMediaDir; - break; - } - } - - if (!aMediaDir.isEmpty()) - return aMediaDir + "/"; - - // Not set explicitly, try to pick it up from the base directory. - INetURLObject aURL(rDocumentBaseURL); - try - { - aMediaDir = rtl::Uri::convertRelToAbs(rDocumentBaseURL, aURL.GetBase()) + "/"; - } - catch (const rtl::MalformedUriException &rException) - { - SAL_WARN("writerperfect", "FindMediaDir: convertRelToAbs() failed:" << rException.getMessage()); - } - return aMediaDir; -} - /// Picks up XMP metadata from the base directory. void FindXMPMetadata(const uno::Reference<uno::XComponentContext> &xContext, const OUString &rDocumentBaseURL, const uno::Sequence<beans::PropertyValue> &rFilterData, librevenge::RVNGPropertyList &rMetaData) { @@ -187,18 +178,9 @@ void FindXMPMetadata(const uno::Reference<uno::XComponentContext> &xContext, con if (rDocumentBaseURL.isEmpty()) return; + OUString aMediaDir = FindMediaDir(rDocumentBaseURL, rFilterData); INetURLObject aDocumentBaseURL(rDocumentBaseURL); - OUString aURL; - try - { - aURL = rtl::Uri::convertRelToAbs(rDocumentBaseURL, aDocumentBaseURL.GetBase() + ".xmp"); - } - catch (const rtl::MalformedUriException &rException) - { - SAL_WARN("writerperfect", "FindXMPMetadata: convertRelToAbs() failed:" << rException.getMessage()); - return; - } - + OUString aURL = aMediaDir + aDocumentBaseURL.GetBase() + ".xmp"; SvFileStream aStream(aURL, StreamMode::READ); if (!aStream.IsOpen()) return; |