diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-02-22 14:51:16 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-02-22 14:29:18 +0000 |
commit | 57c5ad79609134e0ff0013a002cc80a570e81c20 (patch) | |
tree | d485ece00d7221e1cfb367fd8923196c47cacc65 | |
parent | e1190058b5d4d3cec9959dfa1e9fa87818f710e8 (diff) |
tdf#106059 PDF export: set matrix and bbox for PDF images
We still unconditionally refer to the bitmap, but now the correct
/Matrix and /BBox is set along with the necessary scaling inside the
stream, so that when there will be a vector image reference, it'll
appear at the correct position / size.
Change-Id: I9c13c11fe76995b3b3d31a135eeaa895ee0abb0d
Reviewed-on: https://gerrit.libreoffice.org/34543
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index b18f4fcc3ed1..be69ad0bba9c 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -11184,6 +11184,19 @@ bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask ) if (!updateObject(rObject.m_nFormObject)) return false; + // Count /Matrix and /BBox. + // vcl::ImportPDF() works with 96 DPI so use the same values here, too. + sal_Int32 nOldDPIX = getReferenceDevice()->GetDPIX(); + getReferenceDevice()->SetDPIX(96); + sal_Int32 nOldDPIY = getReferenceDevice()->GetDPIY(); + getReferenceDevice()->SetDPIY(96); + Size aSize = getReferenceDevice()->PixelToLogic(rObject.m_aBitmap.GetPrefSize(), MapMode(m_aMapMode.GetMapUnit())); + getReferenceDevice()->SetDPIX(nOldDPIX); + getReferenceDevice()->SetDPIY(nOldDPIY); + double fScaleX = 1.0 / aSize.Width(); + double fScaleY = 1.0 / aSize.Height(); + + // Now have all the info to write the form XObject. aLine.append(rObject.m_nFormObject); aLine.append(" 0 obj\n"); aLine.append("<< /Type /XObject"); @@ -11193,13 +11206,28 @@ bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask ) aLine.append(" "); aLine.append(rObject.m_nObject); aLine.append(" 0 R>> >>"); - aLine.append(" /BBox [ 0 0 1 1 ]"); + aLine.append(" /Matrix [ "); + appendDouble(fScaleX, aLine); + aLine.append(" 0 0 "); + appendDouble(fScaleY, aLine); + aLine.append(" 0 0 ]"); + aLine.append(" /BBox [ 0 0 "); + aLine.append(aSize.Width()); + aLine.append(" "); + aLine.append(aSize.Height()); + aLine.append(" ]"); aLine.append(" /Length "); OStringBuffer aStream; + aStream.append("q "); + aStream.append(aSize.Width()); + aStream.append(" 0 0 "); + aStream.append(aSize.Height()); + aStream.append(" 0 0 cm\n"); aStream.append("/Im"); aStream.append(rObject.m_nObject); - aStream.append(" Do"); + aStream.append(" Do\n"); + aStream.append("Q"); aLine.append(aStream.getLength()); aLine.append(">>\nstream\n"); |