LibreOffice Module vcl (master) 1
ExternalPDFStreams.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#pragma once
11
12#include <sal/types.h>
13#include <sal/log.hxx>
14#include <vcl/dllapi.h>
15
16#include <map>
17#include <vector>
18#include <memory>
19
22
23namespace vcl
24{
25// A external PDF stream, which stores the PDF stream data as byte array.
26// This struct is also responsible to parsing the stream as a PDFDocument,
27// and store its instance for the life-cycle of the struct, so that it
28// reused to avoid unnecessary parsing.
30{
32 std::shared_ptr<filter::PDFDocument> mpPDFDocument;
33 std::map<sal_Int32, sal_Int32> maCopiedResources;
34
35 std::map<sal_Int32, sal_Int32>& getCopiedResources() { return maCopiedResources; }
36
37 std::shared_ptr<filter::PDFDocument>& getPDFDocument()
38 {
39 if (!mpPDFDocument)
40 {
41 SvMemoryStream aPDFStream;
42 aPDFStream.WriteBytes(maDataContainer.getData(), maDataContainer.getSize());
43 aPDFStream.Seek(0);
44 auto pPDFDocument = std::make_shared<filter::PDFDocument>();
45 if (!pPDFDocument->ReadWithPossibleFixup(aPDFStream))
46 {
47 SAL_WARN("vcl.pdfwriter",
48 "PDFWriterImpl::writeReferenceXObject: reading the PDF document failed");
49 }
50 else
51 {
52 mpPDFDocument = pPDFDocument;
53 }
54 }
55 return mpPDFDocument;
56 }
57};
58
59// Class to manage external PDF streams, for the de-duplication purpose.
61{
62private:
63 std::map<std::vector<sal_uInt8>, sal_Int32> maStreamIndexMap;
64 std::vector<ExternalPDFStream> maStreamList;
65
66public:
68
69 sal_Int32 store(BinaryDataContainer const& rDataContainer);
70
71 ExternalPDFStream& get(sal_uInt32 nIndex);
72};
73}
74
75/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Container for the binary data, whose responsibility is to manage the make it as simple as possible to...
const sal_uInt8 * getData() const
std::size_t WriteBytes(const void *pData, std::size_t nSize)
sal_uInt64 Seek(sal_uInt64 nPos)
ExternalPDFStream & get(sal_uInt32 nIndex)
std::vector< ExternalPDFStream > maStreamList
std::map< std::vector< sal_uInt8 >, sal_Int32 > maStreamIndexMap
sal_Int32 store(BinaryDataContainer const &rDataContainer)
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
#define SAL_WARN(area, stream)
std::map< sal_Int32, sal_Int32 > maCopiedResources
std::shared_ptr< filter::PDFDocument > mpPDFDocument
std::map< sal_Int32, sal_Int32 > & getCopiedResources()
std::shared_ptr< filter::PDFDocument > & getPDFDocument()
BinaryDataContainer maDataContainer