[Libreoffice-commits] core.git: writerperfect/qa writerperfect/source
Miklos Vajna
vmiklos at collabora.co.uk
Fri Jan 19 08:12:00 UTC 2018
writerperfect/qa/unit/EPUBExportTest.cxx | 14 ++++++
writerperfect/qa/unit/data/writer/epubexport/popup-media.odt |binary
writerperfect/qa/unit/data/writer/epubexport/popup-media/libreoffice.png |binary
writerperfect/source/writer/exp/xmlimp.cxx | 22 ++++++++--
4 files changed, 32 insertions(+), 4 deletions(-)
New commits:
commit 9035ee7c90ed5ff78864145fd92241491033c074
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Thu Jan 18 15:53:54 2018 +0100
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
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
Binary files /dev/null and b/writerperfect/qa/unit/data/writer/epubexport/popup-media.odt 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
Binary files /dev/null and b/writerperfect/qa/unit/data/writer/epubexport/popup-media/libreoffice.png 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);
More information about the Libreoffice-commits
mailing list