Kaydet (Commit) 7f0641de authored tarafından Miklos Vajna's avatar Miklos Vajna

EPUB export: allow setting custom media dir explicitly

The default is the same <base directory>/<base name>/ as before.

Change-Id: Idb500193a7f6bd901d861e857147832a3ada91d3
Reviewed-on: https://gerrit.libreoffice.org/45602Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 7dcb4fef
...@@ -90,6 +90,7 @@ public: ...@@ -90,6 +90,7 @@ public:
void testImageLink(); void testImageLink();
void testFootnote(); void testFootnote();
void testPopup(); void testPopup();
void testPopupAPI();
CPPUNIT_TEST_SUITE(EPUBExportTest); CPPUNIT_TEST_SUITE(EPUBExportTest);
CPPUNIT_TEST(testOutlineLevel); CPPUNIT_TEST(testOutlineLevel);
...@@ -128,6 +129,7 @@ public: ...@@ -128,6 +129,7 @@ public:
CPPUNIT_TEST(testImageLink); CPPUNIT_TEST(testImageLink);
CPPUNIT_TEST(testFootnote); CPPUNIT_TEST(testFootnote);
CPPUNIT_TEST(testPopup); CPPUNIT_TEST(testPopup);
CPPUNIT_TEST(testPopupAPI);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; };
...@@ -724,6 +726,27 @@ void EPUBExportTest::testPopup() ...@@ -724,6 +726,27 @@ void EPUBExportTest::testPopup()
assertXPath(mpXmlDoc, "//xhtml:body/xhtml:aside[2]/xhtml:img", 1); assertXPath(mpXmlDoc, "//xhtml:body/xhtml:aside[2]/xhtml:img", 1);
} }
void EPUBExportTest::testPopupAPI()
{
// Make sure that the popup works with data from a media directory.
OUString aMediaDir = m_directories.getURLFromSrc(DATA_DIRECTORY) + "popup";
uno::Sequence<beans::PropertyValue> aFilterData(comphelper::InitPropertySequence(
{
{"RVNGMediaDir", uno::makeAny(aMediaDir)}
}));
createDoc("popup-api.odt", aFilterData);
// We have a non-empty anchor image.
mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml");
OUString aAnchor = getXPath(mpXmlDoc, "//xhtml:body/xhtml:p[1]/xhtml:a/xhtml:img", "src");
CPPUNIT_ASSERT(!aAnchor.isEmpty());
// We have a non-empty popup image.
OUString aData = getXPath(mpXmlDoc, "//xhtml:body/xhtml:aside[1]/xhtml:img", "src");
CPPUNIT_ASSERT(!aData.isEmpty());
// The anchor is different from the popup image.
CPPUNIT_ASSERT(aAnchor != aData);
}
CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest); CPPUNIT_TEST_SUITE_REGISTRATION(EPUBExportTest);
} }
......
...@@ -113,6 +113,37 @@ OUString FindCoverImage(const OUString &rDocumentBaseURL, OUString &rMimeType, c ...@@ -113,6 +113,37 @@ OUString FindCoverImage(const OUString &rDocumentBaseURL, OUString &rMimeType, c
return aRet; 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. /// 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) void FindXMPMetadata(const uno::Reference<uno::XComponentContext> &xContext, const OUString &rDocumentBaseURL, const uno::Sequence<beans::PropertyValue> &rFilterData, librevenge::RVNGPropertyList &rMetaData)
{ {
...@@ -256,6 +287,8 @@ XMLImport::XMLImport(const uno::Reference<uno::XComponentContext> &xContext, lib ...@@ -256,6 +287,8 @@ XMLImport::XMLImport(const uno::Reference<uno::XComponentContext> &xContext, lib
} }
} }
maMediaDir = FindMediaDir(rURL, aFilterData);
OUString aMimeType; OUString aMimeType;
OUString aCoverImage = FindCoverImage(rURL, aMimeType, aFilterData); OUString aCoverImage = FindCoverImage(rURL, aMimeType, aFilterData);
if (!aCoverImage.isEmpty()) if (!aCoverImage.isEmpty())
...@@ -303,16 +336,7 @@ bool XMLImport::FillPopupData(const OUString &rURL, librevenge::RVNGPropertyList ...@@ -303,16 +336,7 @@ bool XMLImport::FillPopupData(const OUString &rURL, librevenge::RVNGPropertyList
if (!bRelative) if (!bRelative)
return false; return false;
OUString aAbs; OUString aAbs = maMediaDir + rURL;
INetURLObject aBaseURL(maDocumentBaseURL);
try
{
aAbs = rtl::Uri::convertRelToAbs(maDocumentBaseURL, aBaseURL.GetBase() + "/" + rURL);
}
catch (const rtl::MalformedUriException &rException)
{
SAL_WARN("writerperfect", "XMLImport::FillPopupData: convertRelToAbs() failed:" << rException.getMessage());
}
if (aAbs.isEmpty()) if (aAbs.isEmpty())
return false; return false;
......
...@@ -58,6 +58,7 @@ class XMLImport : public cppu::WeakImplHelper ...@@ -58,6 +58,7 @@ class XMLImport : public cppu::WeakImplHelper
const css::uno::Reference<css::uno::XComponentContext> &mxContext; const css::uno::Reference<css::uno::XComponentContext> &mxContext;
css::uno::Reference<css::uri::XUriReferenceFactory> mxUriReferenceFactory; css::uno::Reference<css::uri::XUriReferenceFactory> mxUriReferenceFactory;
OUString maDocumentBaseURL; OUString maDocumentBaseURL;
OUString maMediaDir;
public: public:
XMLImport(const css::uno::Reference<css::uno::XComponentContext> &xContext, librevenge::RVNGTextInterface &rGenerator, const OUString &rURL, const css::uno::Sequence<css::beans::PropertyValue> &rDescriptor); XMLImport(const css::uno::Reference<css::uno::XComponentContext> &xContext, librevenge::RVNGTextInterface &rGenerator, const OUString &rURL, const css::uno::Sequence<css::beans::PropertyValue> &rDescriptor);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment