[Libreoffice-commits] core.git: writerperfect/qa writerperfect/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Dec 19 08:06:44 UTC 2017


 writerperfect/qa/unit/EPUBExportTest.cxx         |    7 +++++++
 writerperfect/source/writer/EPUBExportFilter.cxx |   20 ++++++++++++++------
 2 files changed, 21 insertions(+), 6 deletions(-)

New commits:
commit fadd9d449719a97dc8d99d96b0ee663ae92759f8
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Dec 18 17:28:53 2017 +0100

    EPUB export, fixed layout: fix mm size of SVG pages
    
    The preferred map unit was pixel, but SVGExport::writeMtf() expects the
    map unit is always a logical one, given that it calls
    OutputDevice::LogicToLogic() for it.
    
    Change-Id: Id1f311eb14423a76a82886ca848c90ab48c6eb49
    Reviewed-on: https://gerrit.libreoffice.org/46733
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx
index 178041d9c0da..1cdd80040d2c 100644
--- a/writerperfect/qa/unit/EPUBExportTest.cxx
+++ b/writerperfect/qa/unit/EPUBExportTest.cxx
@@ -171,6 +171,7 @@ void EPUBExportTest::registerNamespaces(xmlXPathContextPtr &pXmlXpathCtx)
     xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dc"), BAD_CAST("http://purl.org/dc/elements/1.1/"));
     xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("opf"), BAD_CAST("http://www.idpf.org/2007/opf"));
     xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xhtml"), BAD_CAST("http://www.w3.org/1999/xhtml"));
+    xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("svg"), BAD_CAST("http://www.w3.org/2000/svg"));
 }
 
 void EPUBExportTest::createDoc(const OUString &rFile, const uno::Sequence<beans::PropertyValue> &rFilterData)
@@ -813,6 +814,12 @@ void EPUBExportTest::testPageSize()
     mpXmlDoc = parseExport("OEBPS/sections/section0001.xhtml");
     // 21,59cm x 27.94cm (letter).
     assertXPath(mpXmlDoc, "/xhtml:html/xhtml:head/xhtml:meta[@name='viewport']", "content", "width=816, height=1056");
+
+    xmlFreeDoc(mpXmlDoc);
+    mpXmlDoc = parseExport("OEBPS/images/image0001.svg");
+    // This was 288mm, logic->logic conversion input was a pixel value.
+    assertXPath(mpXmlDoc, "/svg:svg", "width", "216mm");
+    assertXPath(mpXmlDoc, "/svg:svg", "height", "279mm");
 }
 
 void EPUBExportTest::testSVG()
diff --git a/writerperfect/source/writer/EPUBExportFilter.cxx b/writerperfect/source/writer/EPUBExportFilter.cxx
index eb65c0ee5098..42652719684f 100644
--- a/writerperfect/source/writer/EPUBExportFilter.cxx
+++ b/writerperfect/source/writer/EPUBExportFilter.cxx
@@ -140,15 +140,23 @@ void EPUBExportFilter::CreateMetafiles(std::vector<std::pair<uno::Sequence<sal_I
     for (sal_Int16 nPage = 1; nPage <= nPages; ++nPage)
     {
         Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels(nPage);
-        Graphic aGraphic = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aDocumentSizePixel, COL_WHITE);
-        const GDIMetaFile &rGDIMetaFile = aGraphic.GetGDIMetaFile();
-        SvMemoryStream aMemoryStream;
-        const_cast<GDIMetaFile &>(rGDIMetaFile).Write(aMemoryStream);
-        uno::Sequence<sal_Int8> aSequence(static_cast<const sal_Int8 *>(aMemoryStream.GetData()), aMemoryStream.Tell());
-
         Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage);
         // Get the CSS pixel size of the page (mm100 -> pixel using 96 DPI, independent from system DPI).
         Size aCss(static_cast<double>(aLogic.getWidth()) / 26.4583, static_cast<double>(aLogic.getHeight()) / 26.4583);
+        Graphic aGraphic = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aCss, COL_WHITE);
+        GDIMetaFile &rGDIMetaFile = const_cast<GDIMetaFile &>(aGraphic.GetGDIMetaFile());
+
+        // Set preferred map unit and size on the metafile, so the SVG size
+        // will be correct in MM.
+        MapMode aMapMode;
+        aMapMode.SetMapUnit(MapUnit::Map100thMM);
+        rGDIMetaFile.SetPrefMapMode(aMapMode);
+        rGDIMetaFile.SetPrefSize(aLogic);
+
+        SvMemoryStream aMemoryStream;
+        rGDIMetaFile.Write(aMemoryStream);
+        uno::Sequence<sal_Int8> aSequence(static_cast<const sal_Int8 *>(aMemoryStream.GetData()), aMemoryStream.Tell());
+
         rPageMetafiles.emplace_back(aSequence, aCss);
     }
 }


More information about the Libreoffice-commits mailing list