summaryrefslogtreecommitdiff
path: root/writerperfect
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2018-01-18 15:53:54 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-01-19 09:11:12 +0100
commit9035ee7c90ed5ff78864145fd92241491033c074 (patch)
tree9bbdf4bf8f8c6c285f55d446118ed7cadc65da49 /writerperfect
parentd5d4166df8ad189761387146966c91d58c28076f (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')
-rw-r--r--writerperfect/qa/unit/EPUBExportTest.cxx14
-rw-r--r--writerperfect/qa/unit/data/writer/epubexport/popup-media.odtbin0 -> 10111 bytes
-rw-r--r--writerperfect/qa/unit/data/writer/epubexport/popup-media/libreoffice.pngbin0 -> 714 bytes
-rw-r--r--writerperfect/source/writer/exp/xmlimp.cxx22
4 files changed, 32 insertions, 4 deletions
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx
index 5a1c21c0e48f..176324b0dff7 100644
--- a/writerperfect/qa/unit/EPUBExportTest.cxx
+++ b/writerperfect/qa/unit/EPUBExportTest.cxx
@@ -94,6 +94,7 @@ public:
void testImageLink();
void testFootnote();
void testPopup();
+ void testPopupMedia();
void testPopupAPI();
void testPageSize();
void testSVG();
@@ -139,6 +140,7 @@ public:
CPPUNIT_TEST(testImageLink);
CPPUNIT_TEST(testFootnote);
CPPUNIT_TEST(testPopup);
+ CPPUNIT_TEST(testPopupMedia);
CPPUNIT_TEST(testPopupAPI);
CPPUNIT_TEST(testPageSize);
CPPUNIT_TEST(testSVG);
@@ -791,6 +793,18 @@ void EPUBExportTest::testPopup()
assertXPath(mpXmlDoc, "//xhtml:body/xhtml:aside[2]/xhtml:img", 1);
}
+void EPUBExportTest::testPopupMedia()
+{
+ // This is the same as testPopup(), but the links point to images in the
+ // default media directory, not in the document directory.
+ createDoc("popup-media.odt", {});
+
+ mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml");
+ // Test image popup anchor. This failed, number of XPath nodes was 0.
+ assertXPath(mpXmlDoc, "//xhtml:body/xhtml:p[1]/xhtml:a", "type", "noteref");
+ assertXPath(mpXmlDoc, "//xhtml:body/xhtml:p[1]/xhtml:a/xhtml:img", 1);
+}
+
void EPUBExportTest::testPopupAPI()
{
// Make sure that the popup works with data from a media directory.
diff --git a/writerperfect/qa/unit/data/writer/epubexport/popup-media.odt b/writerperfect/qa/unit/data/writer/epubexport/popup-media.odt
new file mode 100644
index 000000000000..5f45e7ce8aef
--- /dev/null
+++ b/writerperfect/qa/unit/data/writer/epubexport/popup-media.odt
Binary files differ
diff --git a/writerperfect/qa/unit/data/writer/epubexport/popup-media/libreoffice.png b/writerperfect/qa/unit/data/writer/epubexport/popup-media/libreoffice.png
new file mode 100644
index 000000000000..cc74f136fbdf
--- /dev/null
+++ b/writerperfect/qa/unit/data/writer/epubexport/popup-media/libreoffice.png
Binary files differ
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);