[Libreoffice-commits] core.git: vcl/source
Miklos Vajna
vmiklos at collabora.co.uk
Fri Feb 17 14:54:36 UTC 2017
vcl/source/gdi/pdfextoutdevdata.cxx | 7 +++++--
vcl/source/gdi/pdfwriter_impl.cxx | 34 ++++++++++++++++++++++++++++++++++
vcl/source/gdi/pdfwriter_impl.hxx | 19 +++++++++++++++++++
vcl/source/gdi/pdfwriter_impl2.cxx | 7 +++++++
4 files changed, 65 insertions(+), 2 deletions(-)
New commits:
commit 5fd4c95affbad94f5630425e35bced434d18e3d8
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Fri Feb 17 12:45:47 2017 +0100
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 at collabora.co.uk>
Tested-by: Jenkins <ci at libreoffice.org>
diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx b/vcl/source/gdi/pdfextoutdevdata.cxx
index 89f5703..10b5a31 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 13bd2fe..9673087 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 d2f985a..da953cc 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 bc96f0b..bbfb717 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();
+ }
}
}
}
More information about the Libreoffice-commits
mailing list