[Libreoffice-commits] core.git: vcl/source

Miklos Vajna vmiklos at collabora.co.uk
Wed Feb 22 16:29:53 UTC 2017


 vcl/source/gdi/pdfwriter_impl.cxx  |   20 +++++++++++++++++---
 vcl/source/gdi/pdfwriter_impl.hxx  |    5 ++++-
 vcl/source/gdi/pdfwriter_impl2.cxx |    7 -------
 3 files changed, 21 insertions(+), 11 deletions(-)

New commits:
commit 6db0f1feb1d9931d2726dd11a889c58815710ce0
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Feb 22 15:31:28 2017 +0100

    tdf#106059 PDF export: create a reference XObject for PDF images
    
    If a reader is capable of showing reference XObjects, then it can show
    the original/vector PDF image instead of the bitmap fallback.
    
    Change-Id: Iac8a460c43ff7467e3a5fd8ee4cbf2179084335b

diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index be69ad0..fd63cdd 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -11178,7 +11178,7 @@ bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask )
     }
 
     // Write the form XObject proxy for the image.
-    if (rObject.m_nFormObject > 0)
+    if (rObject.m_nFormObject > 0 && rObject.m_nEmbeddedObject > 0)
     {
         aLine.setLength(0);
         if (!updateObject(rObject.m_nFormObject))
@@ -11215,8 +11215,14 @@ bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask )
         aLine.append(aSize.Width());
         aLine.append(" ");
         aLine.append(aSize.Height());
-        aLine.append(" ]");
-        aLine.append(" /Length ");
+        aLine.append(" ]\n");
+
+        // Write the reference dictionary.
+        aLine.append("/Ref<< /F << /Type /Filespec /F (<embedded file>) /EF << /F ");
+        aLine.append(rObject.m_nEmbeddedObject);
+        aLine.append(" 0 R >> >> /Page 0 >>\n");
+
+        aLine.append("/Length ");
 
         OStringBuffer aStream;
         aStream.append("q ");
@@ -11400,7 +11406,15 @@ const PDFWriterImpl::BitmapEmit& PDFWriterImpl::createBitmapEmit( const BitmapEx
         m_aBitmaps.front().m_aBitmap    = aBitmap;
         m_aBitmaps.front().m_nObject    = createObject();
         if (rGraphic.getPdfData().hasElements())
+        {
+            // Store the original PDF data as an embedded file.
+            m_aEmbeddedFiles.push_back(PDFEmbeddedFile());
+            m_aEmbeddedFiles.back().m_nObject = createObject();
+            m_aEmbeddedFiles.back().m_aData = rGraphic.getPdfData();
+
             m_aBitmaps.front().m_nFormObject = createObject();
+            m_aBitmaps.front().m_nEmbeddedObject = m_aEmbeddedFiles.back().m_nObject;
+        }
         it = m_aBitmaps.begin();
     }
 
diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx
index 69338bd..022679f 100644
--- a/vcl/source/gdi/pdfwriter_impl.hxx
+++ b/vcl/source/gdi/pdfwriter_impl.hxx
@@ -215,10 +215,13 @@ public:
         sal_Int32   m_nObject;
         /// ID of the Form XObject, if any.
         sal_Int32 m_nFormObject;
+        /// ID of the embedded object, if m_nFormObject is used.
+        sal_Int32 m_nEmbeddedObject;
 
         BitmapEmit()
             : m_nObject(0),
-              m_nFormObject(0)
+              m_nFormObject(0),
+              m_nEmbeddedObject(0)
         {
         }
 
diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx
index f131a6d..6de2a88 100644
--- a/vcl/source/gdi/pdfwriter_impl2.cxx
+++ b/vcl/source/gdi/pdfwriter_impl2.cxx
@@ -248,13 +248,6 @@ void PDFWriterImpl::implWriteBitmapEx( const Point& i_rPoint, const Size& i_rSiz
                 m_rOuterFace.DrawBitmapEx( aPoint, aSize, aBitmapEx );
             else
                 m_rOuterFace.DrawBitmap( aPoint, aSize, aBitmapEx.GetBitmap(), i_Graphic );
-
-            if (i_Graphic.getPdfData().hasElements())
-            {
-                m_aEmbeddedFiles.push_back(PDFEmbeddedFile());
-                m_aEmbeddedFiles.back().m_nObject = createObject();
-                m_aEmbeddedFiles.back().m_aData = i_Graphic.getPdfData();
-            }
         }
     }
 }


More information about the Libreoffice-commits mailing list