summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2017-02-17 12:45:47 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-02-17 14:54:13 +0000
commit5fd4c95affbad94f5630425e35bced434d18e3d8 (patch)
tree6f6d6f163013c2e34dfcefa15c72889f98091cf5 /vcl
parent19ac788547e27774884fa9b9287e36c50512a7a3 (diff)
tdf#106059 PDF export: include content of PDF images as an embedded file
Initial step to have vector output for PDF images in the PDF export result. Change-Id: I3d08403d3c83e11c63af69312f9af7474dcd2ead Reviewed-on: https://gerrit.libreoffice.org/34366 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/gdi/pdfextoutdevdata.cxx7
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx34
-rw-r--r--vcl/source/gdi/pdfwriter_impl.hxx19
-rw-r--r--vcl/source/gdi/pdfwriter_impl2.cxx7
4 files changed, 65 insertions, 2 deletions
diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx b/vcl/source/gdi/pdfextoutdevdata.cxx
index 89f570345e9d..10b5a31bd369 100644
--- a/vcl/source/gdi/pdfextoutdevdata.cxx
+++ b/vcl/source/gdi/pdfextoutdevdata.cxx
@@ -410,7 +410,7 @@ bool PageSyncData::PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAc
if ( !mbGroupIgnoreGDIMtfActions )
mCurrentGraphic = rGraphic;
}
- else if ( eType == GfxLinkType::NativePng && mParaRects.size() >= 2 )
+ else if ((eType == GfxLinkType::NativePng || eType == GfxLinkType::NativePdf) && mParaRects.size() >= 2)
{
if ( rOutDevData.HasAdequateCompression(rGraphic, mParaRects[0], mParaRects[1]) )
mCurrentGraphic = rGraphic;
@@ -815,7 +815,10 @@ bool PDFExtOutDevData::HasAdequateCompression( const Graphic &rGraphic,
{
bool bReduceResolution = false;
- assert( rGraphic.IsLink() && (rGraphic.GetLink().GetType() == GfxLinkType::NativeJpg || rGraphic.GetLink().GetType() == GfxLinkType::NativePng));
+ assert(rGraphic.IsLink() &&
+ (rGraphic.GetLink().GetType() == GfxLinkType::NativeJpg ||
+ rGraphic.GetLink().GetType() == GfxLinkType::NativePng ||
+ rGraphic.GetLink().GetType() == GfxLinkType::NativePdf));
// small items better off as PNG anyway
if ( rGraphic.GetSizePixel().Width() < 32 &&
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 13bd2fe561f9..9673087b237a 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -4967,6 +4967,39 @@ bool PDFWriterImpl::emitAnnotations()
return true;
}
+bool PDFWriterImpl::emitEmbeddedFiles()
+{
+ for (auto& rEmbeddedFile : m_aEmbeddedFiles)
+ {
+ if (!updateObject(rEmbeddedFile.m_nObject))
+ continue;
+
+ SvMemoryStream aUncompressed;
+ aUncompressed.WriteBytes(rEmbeddedFile.m_aData.getArray(), rEmbeddedFile.m_aData.getLength());
+ aUncompressed.Seek(0);
+ SvMemoryStream aCompressed;
+ ZCodec aZCodec;
+ aZCodec.BeginCompression();
+ aZCodec.Compress(aUncompressed, aCompressed);
+ aZCodec.EndCompression();
+
+ OStringBuffer aLine;
+ aLine.append(rEmbeddedFile.m_nObject);
+ aLine.append(" 0 obj\n");
+ aLine.append("<< /Type /EmbeddedFile /Filter /FlateDecode /Length ");
+ aLine.append(static_cast<sal_Int64>(aCompressed.GetSize()));
+ aLine.append(" >>\nstream\n");
+ CHECK_RETURN(writeBuffer(aLine.getStr(), aLine.getLength()));
+ aLine.setLength(0);
+
+ CHECK_RETURN(writeBuffer(aCompressed.GetData(), aCompressed.GetSize()));
+
+ aLine.append("\nendstream\nendobj\n\n");
+ CHECK_RETURN(writeBuffer(aLine.getStr(), aLine.getLength()));
+ }
+ return true;
+}
+
#undef CHECK_RETURN
#define CHECK_RETURN( x ) if( !x ) return false
@@ -5057,6 +5090,7 @@ bool PDFWriterImpl::emitCatalog()
// emit annotation objects
CHECK_RETURN( emitAnnotations() );
+ CHECK_RETURN( emitEmbeddedFiles() );
// emit Catalog
m_nCatalogObject = createObject();
diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx
index d2f985a8f696..da953ccea6c0 100644
--- a/vcl/source/gdi/pdfwriter_impl.hxx
+++ b/vcl/source/gdi/pdfwriter_impl.hxx
@@ -26,6 +26,7 @@
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/uno/Sequence.h>
#include <osl/file.hxx>
#include <rtl/cipher.h>
#include <rtl/digest.h>
@@ -416,6 +417,20 @@ public:
}
};
+ /// A PDF embedded file.
+ struct PDFEmbeddedFile
+ {
+ /// ID of the file.
+ sal_Int32 m_nObject;
+ /// Contents of the file.
+ css::uno::Sequence<sal_Int8> m_aData;
+
+ PDFEmbeddedFile()
+ : m_nObject(0)
+ {
+ }
+ };
+
struct PDFNoteEntry : public PDFAnnotation
{
PDFNote m_aContents;
@@ -608,6 +623,8 @@ private:
std::vector<PDFLink> m_aLinks;
/// Contains all screen annotations.
std::vector<PDFScreen> m_aScreens;
+ /// Contains embedded files.
+ std::vector<PDFEmbeddedFile> m_aEmbeddedFiles;
/* makes correctly encoded for export to PDF URLS
*/
css::uno::Reference< css::util::XURLTransformer > m_xTrans;
@@ -868,6 +885,8 @@ i12626
bool emitWidgetAnnotations();
// writes all annotation objects
bool emitAnnotations();
+ /// Writes embedded files.
+ bool emitEmbeddedFiles();
//write the named destination stuff
sal_Int32 emitNamedDestinations();//i56629
// writes outline dict and tree
diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx
index bc96f0b2cff0..bbfb7176f719 100644
--- a/vcl/source/gdi/pdfwriter_impl2.cxx
+++ b/vcl/source/gdi/pdfwriter_impl2.cxx
@@ -248,6 +248,13 @@ 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() );
+
+ if (i_Graphic.getPdfData().hasElements())
+ {
+ m_aEmbeddedFiles.push_back(PDFEmbeddedFile());
+ m_aEmbeddedFiles.back().m_nObject = createObject();
+ m_aEmbeddedFiles.back().m_aData = i_Graphic.getPdfData();
+ }
}
}
}