diff options
-rw-r--r-- | writerperfect/qa/unit/EPUBExportTest.cxx | 7 | ||||
-rw-r--r-- | writerperfect/source/writer/EPUBExportFilter.cxx | 20 |
2 files changed, 21 insertions, 6 deletions
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); } } |