LibreOffice Module vcl (master)  1
pdfwriter_impl.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  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #ifndef INCLUDED_VCL_SOURCE_GDI_PDFWRITER_IMPL_HXX
20 #define INCLUDED_VCL_SOURCE_GDI_PDFWRITER_IMPL_HXX
21 
22 #include <map>
23 #include <list>
24 #include <unordered_map>
25 #include <memory>
26 #include <vector>
27 
28 #include <com/sun/star/lang/Locale.hpp>
29 #include <com/sun/star/util/XURLTransformer.hpp>
30 #include <com/sun/star/uno/Sequence.h>
31 #include <osl/file.hxx>
32 #include <rtl/cipher.h>
33 #include <rtl/strbuf.hxx>
34 #include <rtl/ustring.hxx>
35 #include <tools/gen.hxx>
36 #include <vcl/bitmapex.hxx>
37 #include <vcl/gradient.hxx>
38 #include <vcl/graphictools.hxx>
39 #include <vcl/hatch.hxx>
40 #include <vcl/virdev.hxx>
41 #include <vcl/pdfwriter.hxx>
42 #include <vcl/wall.hxx>
43 #include <o3tl/typed_flags_set.hxx>
44 #include <comphelper/hash.hxx>
45 #include <tools/stream.hxx>
46 
47 #include <outdata.hxx>
48 #include "pdffontcache.hxx"
49 #include "pdfbuildin_fonts.hxx"
50 
51 class StyleSettings;
52 class FontSelectPattern;
53 class FontSubsetInfo;
54 class ZCodec;
55 class EncHashTransporter;
56 struct BitStreamState;
57 class PhysicalFontFace;
58 class SvStream;
59 class SvMemoryStream;
60 
61 // the maximum password length
62 #define ENCRYPTED_PWD_SIZE 32
63 #define MD5_DIGEST_SIZE 16
64 #define SECUR_40BIT_KEY 5
65 // security 128 bit
66 #define SECUR_128BIT_KEY 16
67 // maximum length of MD5 digest input, in step 2 of algorithm 3.1
68 // PDF spec ver. 1.4: see there for details
69 #define MAXIMUM_RC4_KEY_LENGTH (SECUR_128BIT_KEY+3+2)
70 
72  Font = 0x0001,
73  MapMode = 0x0002,
74  LineColor = 0x0004,
75  FillColor = 0x0008,
76  ClipRegion = 0x0040,
77  LayoutMode = 0x0100,
78  TransparentPercent = 0x0200,
79  DigitLanguage = 0x0400,
80  All = 0x077f
81 };
82 namespace o3tl {
83  template<> struct typed_flags<GraphicsStateUpdateFlags> : is_typed_flags<GraphicsStateUpdateFlags, 0x077f> {};
84 }
85 
86 namespace vcl
87 {
88 
89 class PDFStreamIf;
90 class Matrix3;
91 
92 namespace filter
93 {
94 class PDFObjectElement;
95 }
96 
98 {
99  friend class PDFStreamIf;
100 
101 public:
103  typedef std::map< OString, sal_Int32 > ResourceMap;
105  {
106  // note: handle fonts globally for performance
107  ResourceMap m_aXObjects;
108  ResourceMap m_aExtGStates;
109  ResourceMap m_aShadings;
110  ResourceMap m_aPatterns;
111 
112  void append( OStringBuffer&, sal_Int32 nFontDictObject );
113  };
114 
115  struct PDFPage
116  {
118  double const m_nPageWidth; // in inch/72
119  double const m_nPageHeight; // in inch/72
121  sal_Int32 m_nPageObject;
122  std::vector<sal_Int32> m_aStreamObjects;
124  sal_uInt64 m_nBeginStreamPos;
125  std::vector<sal_Int32> m_aAnnotations;
126  std::vector<sal_Int32> m_aMCIDParents;
128  sal_uInt32 m_nTransTime;
129 
130  PDFPage( PDFWriterImpl* pWriter, double nPageWidth, double nPageHeight, PDFWriter::Orientation eOrientation );
131  ~PDFPage();
132 
133  void beginStream();
134  void endStream();
135  bool emit( sal_Int32 nParentPage );
136 
137  // converts point from ref device coordinates to
138  // page coordinates and appends the point to the buffer
139  // if pOutPoint is set it will be updated to the emitted point
140  // (in PDF map mode, that is 10th of point)
141  void appendPoint( const Point& rPoint, OStringBuffer& rBuffer ) const;
142  // appends a B2DPoint without further transformation
143  void appendPixelPoint( const basegfx::B2DPoint& rPoint, OStringBuffer& rBuffer ) const;
144  // appends a rectangle
145  void appendRect( const tools::Rectangle& rRect, OStringBuffer& rBuffer ) const;
146  // converts a rectangle to 10th points page space
147  void convertRect( tools::Rectangle& rRect ) const;
148  // appends a polygon optionally closing it
149  void appendPolygon( const tools::Polygon& rPoly, OStringBuffer& rBuffer, bool bClose = true ) const;
150  // appends a polygon optionally closing it
151  void appendPolygon( const basegfx::B2DPolygon& rPoly, OStringBuffer& rBuffer ) const;
152  // appends a polypolygon optionally closing the subpaths
153  void appendPolyPolygon( const tools::PolyPolygon& rPolyPoly, OStringBuffer& rBuffer ) const;
154  // appends a polypolygon optionally closing the subpaths
155  void appendPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPoly, OStringBuffer& rBuffer ) const;
156  // converts a length (either vertical or horizontal; this
157  // can be important if the source MapMode is not
158  // symmetrical) to page length and appends it to the buffer
159  // if pOutLength is set it will be updated to the emitted length
160  // (in PDF map mode, that is 10th of point)
161  void appendMappedLength( sal_Int32 nLength, OStringBuffer& rBuffer, bool bVertical = true, sal_Int32* pOutLength = nullptr ) const;
162  // the same for double values
163  void appendMappedLength( double fLength, OStringBuffer& rBuffer, bool bVertical = true, sal_Int32 nPrecision = 5 ) const;
164  // appends LineInfo
165  // returns false if too many dash array entry were created for
166  // the implementation limits of some PDF readers
167  bool appendLineInfo( const LineInfo& rInfo, OStringBuffer& rBuffer ) const;
168  // appends a horizontal waveline with vertical offset (helper for drawWaveLine)
169  void appendWaveLine( sal_Int32 nLength, sal_Int32 nYOffset, sal_Int32 nDelta, OStringBuffer& rBuffer ) const;
170 
171  double getHeight() const { return m_nPageHeight ? m_nPageHeight : PDFWriterImpl::g_nInheritedPageHeight; }
172  };
173 
174  friend struct PDFPage;
175 
176  struct BitmapID
177  {
179  sal_Int32 m_nSize;
182 
183  BitmapID() : m_nSize( 0 ), m_nChecksum( 0 ), m_nMaskChecksum( 0 ) {}
184 
185  bool operator==( const BitmapID& rComp ) const
186  {
187  return (m_aPixelSize == rComp.m_aPixelSize &&
188  m_nSize == rComp.m_nSize &&
189  m_nChecksum == rComp.m_nChecksum &&
190  m_nMaskChecksum == rComp.m_nMaskChecksum );
191  }
192  };
193 
196  {
198  sal_Int32 m_nFormObject;
200  sal_Int32 m_nEmbeddedObject;
202  sal_Int32 m_nBitmapObject;
206  std::vector<sal_Int8> m_aPDFData;
207 
209  : m_nFormObject(0),
210  m_nEmbeddedObject(0),
211  m_nBitmapObject(0)
212  {
213  }
214 
216  sal_Int32 getObject() const;
217  };
218 
219  struct BitmapEmit
220  {
223  sal_Int32 m_nObject;
225 
227  : m_nObject(0)
228  {
229  }
230  };
231 
232  struct JPGEmit
233  {
235  std::unique_ptr<SvMemoryStream>
238  sal_Int32 m_nObject;
241 
243  : m_nObject(0)
244  , m_bTrueColor(false)
245  {
246  }
247  };
248 
250  {
253  sal_Int32 m_nObject;
254  };
255 
256  // for tilings (drawWallpaper, begin/endPattern)
257  struct TilingEmit
258  {
259  sal_Int32 m_nObject;
264  std::unique_ptr<SvMemoryStream> m_pTilingStream;
265 
267  : m_nObject( 0 )
268  {}
269  };
270 
271  // for transparency group XObjects
273  {
274  sal_Int32 m_nObject;
276  double m_fAlpha;
278  std::unique_ptr<SvMemoryStream> m_pContentStream;
279  std::unique_ptr<SvMemoryStream> m_pSoftMaskStream;
280 
282  : m_nObject( 0 ),
283  m_nExtGStateObject( -1 ),
284  m_fAlpha( 0.0 )
285  {}
286  };
287 
288  // font subsets
289  class GlyphEmit
290  {
291  // performance: actually this should probably a vector;
292  std::vector<sal_Ucs> m_CodeUnits;
294 
295  public:
296  GlyphEmit() : m_nSubsetGlyphID(0)
297  {
298  }
299 
300  void setGlyphId( sal_uInt8 i_nId ) { m_nSubsetGlyphID = i_nId; }
302 
303  void addCode( sal_Ucs i_cCode )
304  {
305  m_CodeUnits.push_back(i_cCode);
306  }
307  sal_Int32 countCodes() const { return m_CodeUnits.size(); }
308  const std::vector<sal_Ucs>& codes() const { return m_CodeUnits; }
309  sal_Ucs getCode( sal_Int32 i_nIndex ) const
310  {
311  sal_Ucs nRet = 0;
312  if (static_cast<size_t>(i_nIndex) < m_CodeUnits.size())
313  nRet = m_CodeUnits[i_nIndex];
314  return nRet;
315  }
316  };
317  typedef std::map< sal_GlyphId, GlyphEmit > FontEmitMapping;
318  struct FontEmit
319  {
320  sal_Int32 m_nFontID;
321  FontEmitMapping m_aMapping;
322 
323  explicit FontEmit( sal_Int32 nID ) : m_nFontID( nID ) {}
324  };
325  struct Glyph
326  {
327  sal_Int32 m_nFontID;
329  };
330  typedef std::map< sal_GlyphId, Glyph > FontMapping;
331  struct FontSubset
332  {
333  std::vector< FontEmit > m_aSubsets;
334  FontMapping m_aMapping;
335  };
336  typedef std::map< const PhysicalFontFace*, FontSubset > FontSubsetData;
337  struct EmbedFont
338  {
339  sal_Int32 m_nNormalFontID;
340 
341  EmbedFont() : m_nNormalFontID( 0 ) {}
342  };
343  typedef std::map< const PhysicalFontFace*, EmbedFont > FontEmbedData;
344 
345  struct PDFDest
346  {
347  sal_Int32 m_nPage;
350  };
351 
352 //--->i56629
354  {
355  OUString m_aDestName;
356  sal_Int32 m_nPage;
359  };
360 
362  {
363  sal_Int32 m_nObject;
364  sal_Int32 m_nParentObject;
365  sal_Int32 m_nNextObject;
366  sal_Int32 m_nPrevObject;
367  std::vector< sal_Int32 > m_aChildren;
368  OUString m_aTitle;
369  sal_Int32 m_nDestID;
370 
372  : m_nObject( 0 ),
373  m_nParentObject( 0 ),
374  m_nNextObject( 0 ),
375  m_nPrevObject( 0 ),
376  m_nDestID( -1 )
377  {}
378  };
379 
381  {
382  sal_Int32 m_nObject;
384  sal_Int32 m_nPage;
385 
387  : m_nObject( -1 ),
388  m_nPage( -1 )
389  {}
390  };
391 
392  struct PDFLink : public PDFAnnotation
393  {
394  sal_Int32 m_nDest; // set to -1 for URL, to a dest else
395  OUString m_aURL;
396  sal_Int32 m_nStructParent; // struct parent entry
397 
399  : m_nDest( -1 ),
400  m_nStructParent( -1 )
401  {}
402  };
403 
405  struct PDFScreen : public PDFAnnotation
406  {
408  OUString m_aURL;
410  OUString m_aTempFileURL;
412  sal_Int32 m_nTempFileObject;
413 
415  : m_nTempFileObject(0)
416  {
417  }
418  };
419 
422  {
424  sal_Int32 m_nObject;
426  std::shared_ptr<std::vector<sal_Int8>> m_pData;
427 
429  : m_nObject(0)
430  {
431  }
432  };
433 
434  struct PDFNoteEntry : public PDFAnnotation
435  {
437 
439  {}
440  };
441 
442  typedef std::unordered_map< OString, SvMemoryStream* > PDFAppearanceStreams;
443  typedef std::unordered_map< OString, PDFAppearanceStreams > PDFAppearanceMap;
444 
445  struct PDFWidget : public PDFAnnotation
446  {
448  OString m_aName;
449  OUString m_aDescription;
450  OUString m_aText;
452  OUString m_aValue;
453  OString m_aDAString;
454  OString m_aDRDict;
455  OString m_aMKDict;
456  OString m_aMKDictCAString; // i12626, added to be able to encrypt the /CA text string
457  // since the object number is not known at the moment
458  // of filling m_aMKDict, the string will be encrypted when emitted.
459  // the /CA string MUST BE the last added to m_aMKDict
460  // see code for details
461  sal_Int32 m_nFlags;
462  sal_Int32 m_nParent; // if not 0, parent's object number
463  std::vector<sal_Int32> m_aKids; // widget children, contains object numbers
464  std::vector<sal_Int32> m_aKidsIndex; // widget children, contains index to m_aWidgets
465  OUString m_aOnValue;
466  sal_Int32 m_nTabOrder; // lowest number gets first in tab order
467  sal_Int32 m_nRadioGroup;
468  sal_Int32 m_nMaxLen;
469  bool m_bSubmit;
471  sal_Int32 m_nDest;
472  std::vector<OUString> m_aListEntries;
473  std::vector<sal_Int32> m_aSelectedEntries;
474  PDFAppearanceMap m_aAppearances;
476  : m_eType( PDFWriter::PushButton ),
477  m_nTextStyle( DrawTextFlags::NONE ),
478  m_nFlags( 0 ),
479  m_nParent( 0 ),
480  m_nTabOrder( 0 ),
481  m_nRadioGroup( -1 ),
482  m_nMaxLen( 0 ),
483  m_bSubmit( false ),
484  m_bSubmitGet( false ),
485  m_nDest( -1 )
486  {}
487  };
488 
490  {
492  sal_Int32 nValue;
493 
495  : eValue( PDFWriter::Invalid ),
496  nValue( 0 )
497  {}
498 
500  : eValue( eVal ),
501  nValue( 0 )
502  {}
503 
504  explicit PDFStructureAttribute( sal_Int32 nVal )
505  : eValue( PDFWriter::Invalid ),
506  nValue( nVal )
507  {}
508  };
509 
510  struct PDFStructureElementKid // for Kids entries
511  {
512  sal_Int32 const nObject; // an object number if nMCID is -1,
513  // else the page object relevant to MCID
514  sal_Int32 const nMCID; // an MCID if >= 0
515 
516  explicit PDFStructureElementKid( sal_Int32 nObj ) : nObject( nObj ), nMCID( -1 ) {}
517  PDFStructureElementKid( sal_Int32 MCID, sal_Int32 nPage ) : nObject( nPage ), nMCID( MCID ) {}
518  };
519 
521  {
522  sal_Int32 m_nObject;
524  OString m_aAlias;
525  sal_Int32 m_nOwnElement; // index into structure vector
526  sal_Int32 m_nParentElement; // index into structure vector
529  std::list< sal_Int32 > m_aChildren; // indexes into structure vector
530  std::list< PDFStructureElementKid > m_aKids;
531  std::map<PDFWriter::StructAttribute, PDFStructureAttribute >
534  OUString m_aActualText;
535  OUString m_aAltText;
536  css::lang::Locale m_aLocale;
537 
538  // m_aContents contains the element's marked content sequence
539  // as pairs of (page nr, MCID)
540 
542  : m_nObject( 0 ),
543  m_eType( PDFWriter::NonStructElement ),
544  m_nOwnElement( -1 ),
545  m_nParentElement( -1 ),
546  m_nFirstPageObject( 0 ),
547  m_bOpenMCSeq( false )
548  {
549  }
550 
551  };
552 
554  {
555  OUString m_aMimeType;
557  sal_Int32 m_nStreamObject;
559 
560  PDFAddStream() : m_pStream( nullptr ), m_nStreamObject( 0 ), m_bCompress( true ) {}
561  };
562 
563  // helper structure for drawLayout and friends
564  struct PDFGlyph
565  {
566  Point const m_aPos;
568  sal_Int32 const m_nNativeWidth;
569  sal_Int32 const m_nMappedFontId;
571  int const m_nCharPos;
572 
573  PDFGlyph( const Point& rPos,
574  const GlyphItem* pGlyph,
575  sal_Int32 nNativeWidth,
576  sal_Int32 nFontId,
577  sal_uInt8 nMappedGlyphId,
578  int nCharPos )
579  : m_aPos( rPos ), m_pGlyph(pGlyph), m_nNativeWidth( nNativeWidth ),
580  m_nMappedFontId( nFontId ), m_nMappedGlyphId( nMappedGlyphId ),
581  m_nCharPos(nCharPos)
582  {}
583  };
584 
588 
589  // returns true if compression was done
590  // else false
591  static bool compressStream( SvMemoryStream* );
592 
593  static void convertLineInfoToExtLineInfo( const LineInfo& rIn, PDFWriter::ExtLineInfo& rOut );
594 
595 protected:
596  void ImplClearFontData(bool bNewFontLists) override;
597  void ImplRefreshFontData(bool bNewFontLists) override;
598  vcl::Region ClipToDeviceBounds(vcl::Region aRegion) const override;
599  void DrawHatchLine_DrawLine(const Point& rStartPoint, const Point& rEndPoint) override;
600 
601 private:
602  MapMode m_aMapMode; // PDFWriterImpl scaled units
603  std::vector< PDFPage > m_aPages;
604  /* maps object numbers to file offsets (needed for xref) */
605  std::vector< sal_uInt64 > m_aObjects;
606  /* contains Bitmaps until they are written to the
607  * file stream as XObjects*/
608  std::list< BitmapEmit > m_aBitmaps;
609  /* contains JPG streams until written to file */
610  std::vector<JPGEmit> m_aJPGs;
611  /*--->i56629 contains all named destinations ever set during the PDF creation,
612  destination id is always the destination's position in this vector
613  */
614  std::vector<PDFNamedDest> m_aNamedDests;
615  /* contains all dests ever set during the PDF creation,
616  dest id is always the dest's position in this vector
617  */
618  std::vector<PDFDest> m_aDests;
621  ::std::map< sal_Int32, sal_Int32 > m_aDestinationIdTranslation;
622  /* contains all links ever set during PDF creation,
623  link id is always the link's position in this vector
624  */
625  std::vector<PDFLink> m_aLinks;
627  std::vector<PDFScreen> m_aScreens;
629  std::vector<PDFEmbeddedFile> m_aEmbeddedFiles;
630  /* makes correctly encoded for export to PDF URLS
631  */
632  css::uno::Reference< css::util::XURLTransformer > m_xTrans;
633  /* maps arbitrary link ids for structure attributes to real link ids
634  (for setLinkPropertyId)
635  */
636  std::map<sal_Int32, sal_Int32> m_aLinkPropertyMap;
637  /* contains all outline items,
638  object 0 is the outline root
639  */
640  std::vector<PDFOutlineEntry> m_aOutline;
641  /* contains all notes set during PDF creation
642  */
643  std::vector<PDFNoteEntry> m_aNotes;
644  /* the root of the structure tree
645  */
646  std::vector<PDFStructureElement> m_aStructure;
647  /* current object in the structure hierarchy
648  */
650  /* structure parent tree */
651  std::vector< OString > m_aStructParentTree;
652  /* emit structure marks currently (aka. NonStructElement or not)
653  */
655  /* role map of struct tree root */
656  std::unordered_map< OString, OString >
658 
659  /* contains all widgets used in the PDF
660  */
661  std::vector<PDFWidget> m_aWidgets;
662  /* maps radio group id to index of radio group control in m_aWidgets */
663  std::map< sal_Int32, sal_Int32 > m_aRadioGroupWidgets;
664  /* unordered_map for field names, used to ensure unique field names */
665  std::unordered_map< OString, sal_Int32 > m_aFieldNameMap;
666 
667  /* contains Bitmaps for gradient functions until they are written
668  * to the file stream */
669  std::list< GradientEmit > m_aGradients;
670  /* contains bitmap tiling patterns */
671  std::vector< TilingEmit > m_aTilings;
672  std::list< TransparencyEmit > m_aTransparentObjects;
673  /* contains all font subsets in use */
674  FontSubsetData m_aSubsets;
675  FontEmbedData m_aSystemFonts;
676  sal_Int32 m_nNextFID;
678 
679  static constexpr sal_Int32 g_nInheritedPageWidth = 595; // default A4 in inch/72
680  static constexpr sal_Int32 g_nInheritedPageHeight = 842; // default A4 in inch/72
681  sal_Int32 m_nCurrentPage;
682 
683  sal_Int32 m_nCatalogObject;
684  // object number of the main signature dictionary
688  sal_Int32 m_nResourceDict;
690  sal_Int32 m_nFontDictObject;
691  std::map< sal_Int32, sal_Int32 > m_aBuildinFontToObjectMap;
692 
694  osl::File m_aFile;
695  bool m_bOpen;
696 
697  /* output redirection; e.g. to accumulate content streams for
698  XObjects
699  */
701  {
706  };
707  std::list< StreamRedirect > m_aOutputStreams;
708 
709  // graphics state
711  {
724 
726  m_aLineColor( COL_TRANSPARENT ),
727  m_aFillColor( COL_TRANSPARENT ),
728  m_aTextLineColor( COL_TRANSPARENT ),
729  m_aOverlineColor( COL_TRANSPARENT ),
730  m_bClipRegion( false ),
731  m_nLayoutMode( ComplexTextLayoutFlags::Default ),
732  m_aDigitLanguage( 0 ),
733  m_nFlags( PushFlags::ALL ),
734  m_nUpdateFlags( GraphicsStateUpdateFlags::All )
735  {}
736  };
737  std::list< GraphicsState > m_aGraphicsStack;
739 
740  std::unique_ptr<ZCodec> m_pCodec;
741  std::unique_ptr<SvMemoryStream> m_pMemStream;
742 
743  std::vector< PDFAddStream > m_aAdditionalStreams;
744  std::set< PDFWriter::ErrorCode > m_aErrors;
745 
747 
748 /*
749 variables for PDF security
750 i12626
751 */
752 /* used to cipher the stream data and for password management */
753  rtlCipher m_aCipher;
754  /* pad string used for password in Standard security handler */
756 
757  /* the encryption key, formed with the user password according to algorithm 3.2, maximum length is 16 bytes + 3 + 2
758  for 128 bit security */
759  sal_Int32 m_nKeyLength; // key length, 16 or 5
760  sal_Int32 m_nRC4KeyLength; // key length, 16 or 10, to be input to the algorithm 3.1
761 
762  /* set to true if the following stream must be encrypted, used inside writeBuffer() */
764 
765  /* the numerical value of the access permissions, according to PDF spec, must be signed */
767  /* string to hold the PDF creation date */
769  /* string to hold the PDF creation date, for PDF/A metadata */
771  /* the buffer where the data are encrypted, dynamically allocated */
772  std::vector<sal_uInt8> m_vEncryptionBuffer;
773 
774  /* this function implements part of the PDF spec algorithm 3.1 in encryption, the rest (the actual encryption) is in PDFWriterImpl::writeBuffer */
775  void checkAndEnableStreamEncryption( sal_Int32 nObject );
776 
777  void disableStreamEncryption() { m_bEncryptThisStream = false; };
778 
779  /* */
780  void enableStringEncryption( sal_Int32 nObject );
781 
782 // test if the encryption is active, if yes than encrypt the unicode string and add to the OStringBuffer parameter
783  void appendUnicodeTextStringEncrypt( const OUString& rInString, const sal_Int32 nInObjectNumber, OStringBuffer& rOutBuffer );
784 
785  void appendLiteralStringEncrypt( const OUString& rInString, const sal_Int32 nInObjectNumber, OStringBuffer& rOutBuffer, rtl_TextEncoding nEnc = RTL_TEXTENCODING_ASCII_US );
786  void appendLiteralStringEncrypt( const OString& rInString, const sal_Int32 nInObjectNumber, OStringBuffer& rOutBuffer );
787  void appendLiteralStringEncrypt( OStringBuffer const & rInString, const sal_Int32 nInObjectNumber, OStringBuffer& rOutBuffer );
788 
789  /* creates fonts and subsets that will be emitted later */
790  void registerGlyph(const GlyphItem* pGlyph, const PhysicalFontFace* pFont, const std::vector<sal_Ucs>& rCodeUnits, sal_uInt8& nMappedGlyph, sal_Int32& nMappedFontObject);
791 
792  /* emits a text object according to the passed layout */
793  /* TODO: remove rText as soon as SalLayout will change so that rText is not necessary anymore */
794  void drawVerticalGlyphs( const std::vector<PDFGlyph>& rGlyphs, OStringBuffer& rLine, const Point& rAlignOffset, const Matrix3& rRotScale, double fAngle, double fXScale, double fSkew, sal_Int32 nFontHeight );
795  void drawHorizontalGlyphs( const std::vector<PDFGlyph>& rGlyphs, OStringBuffer& rLine, const Point& rAlignOffset, bool bFirst, double fAngle, double fXScale, double fSkew, sal_Int32 nFontHeight, sal_Int32 nPixelFontHeight );
796  void drawLayout( SalLayout& rLayout, const OUString& rText, bool bTextLines );
797  void drawRelief( SalLayout& rLayout, const OUString& rText, bool bTextLines );
798  void drawShadow( SalLayout& rLayout, const OUString& rText, bool bTextLines );
799 
800  enum Mode { DEFAULT, NOWRITE };
801 
802  /* writes differences between graphics stack and current real PDF
803  * state to the file
804  */
805  void updateGraphicsState(Mode mode = DEFAULT);
806 
807  /* writes a transparency group object */
808  void writeTransparentObject( TransparencyEmit& rObject );
809 
810  /* writes an XObject of type image, may create
811  a second for the mask
812  */
813  bool writeBitmapObject( BitmapEmit& rObject, bool bMask = false );
814 
815  void writeJPG( JPGEmit& rEmit );
817  void writeReferenceXObject(ReferenceXObjectEmit& rEmit);
820  OString copyExternalResources(filter::PDFObjectElement& rPage, const OString& rKind, std::map<sal_Int32, sal_Int32>& rCopiedResources);
823  sal_Int32 copyExternalResource(SvMemoryStream& rDocBuffer, filter::PDFObjectElement& rObject, std::map<sal_Int32, sal_Int32>& rCopiedResources);
824 
825  /* tries to find the bitmap by its id and returns its emit data if exists,
826  else creates a new emit data block */
827  const BitmapEmit& createBitmapEmit( const BitmapEx& rBitmapEx, const Graphic& rGraphic );
828 
829  /* writes the Do operation inside the content stream */
830  void drawBitmap( const Point& rDestPt, const Size& rDestSize, const BitmapEmit& rBitmap, const Color& rFillColor );
831  /* write the function object for a Gradient */
832  bool writeGradientFunction( GradientEmit const & rObject );
833  /* creates a GradientEmit and returns its object number */
834  sal_Int32 createGradient( const Gradient& rGradient, const Size& rSize );
835 
836  /* writes all tilings */
837  bool emitTilings();
838  /* writes all gradient patterns */
839  bool emitGradients();
840  /* writes a builtin font object and returns its objectid (or 0 in case of failure ) */
841  sal_Int32 emitBuildinFont( const pdf::BuildinFontFace*, sal_Int32 nObject );
842  /* writes a type1 system font object and returns its mapping from font ids to object ids (or 0 in case of failure ) */
843  std::map< sal_Int32, sal_Int32 > emitSystemFont( const PhysicalFontFace*, EmbedFont const & );
844  /* writes a font descriptor and returns its object id (or 0) */
845  sal_Int32 emitFontDescriptor( const PhysicalFontFace*, FontSubsetInfo const &, sal_Int32 nSubsetID, sal_Int32 nStream );
846  /* writes a ToUnicode cmap, returns the corresponding stream object */
847  sal_Int32 createToUnicodeCMap( sal_uInt8 const * pEncoding, const sal_Ucs* pCodeUnits, const sal_Int32* pCodeUnitsPerGlyph,
848  const sal_Int32* pEncToUnicodeIndex, int nGlyphs );
849 
850  /* get resource dict object number */
851  sal_Int32 getResourceDictObj()
852  {
853  if( m_nResourceDict <= 0 )
854  m_nResourceDict = createObject();
855  return m_nResourceDict;
856  }
857  /* get the font dict object */
858  sal_Int32 getFontDictObject()
859  {
860  if( m_nFontDictObject <= 0 )
861  m_nFontDictObject = createObject();
862  return m_nFontDictObject;
863  }
864  /* push resource into current (redirected) resource dict */
865  void pushResource( ResourceKind eKind, const OString& rResource, sal_Int32 nObject );
866 
867  void appendBuildinFontsToDict( OStringBuffer& rDict ) const;
868  /* writes the font dictionary and emits all font objects
869  * returns object id of font directory (or 0 on error)
870  */
871  bool emitFonts();
872  /* writes the Resource dictionary;
873  * returns dict object id (or 0 on error)
874  */
875  sal_Int32 emitResources();
876  // appends a dest
877  bool appendDest( sal_Int32 nDestID, OStringBuffer& rBuffer );
878  // write all links
879  bool emitLinkAnnotations();
881  bool emitScreenAnnotations();
882  // write all notes
883  bool emitNoteAnnotations();
884  // write the appearance streams of a widget
885  bool emitAppearances( PDFWidget& rWidget, OStringBuffer& rAnnotDict );
886  // clean up radio button "On" values
888  // write all widgets
889  bool emitWidgetAnnotations();
890  // writes all annotation objects
891  bool emitAnnotations();
893  bool emitEmbeddedFiles();
894  //write the named destination stuff
895  sal_Int32 emitNamedDestinations();//i56629
896  // writes outline dict and tree
897  sal_Int32 emitOutline();
898  // puts the attribute objects of a structure element into the returned string,
899  // helper for emitStructure
900  OString emitStructureAttributes( PDFStructureElement& rEle );
901  //--->i94258
902  // the maximum array elements allowed for PDF array object
903  static const sal_uInt32 ncMaxPDFArraySize = 8191;
904  //check if internal dummy container are needed in the structure elements
906  //<---i94258
907  // writes document structure
908  sal_Int32 emitStructure( PDFStructureElement& rEle );
909  // writes structure parent tree
910  sal_Int32 emitStructParentTree( sal_Int32 nTreeObject );
911  // writes page tree and catalog
912  bool emitCatalog();
913  // writes signature dictionary object
914  bool emitSignature();
915  // creates a PKCS7 object using the ByteRange and overwrite /Contents
916  // of the signature dictionary
917  bool finalizeSignature();
918  // writes xref and trailer
919  bool emitTrailer();
920  // emit additional streams collected; also create there object numbers
921  bool emitAdditionalStreams();
922  // emits info dict (if applicable)
923  sal_Int32 emitInfoDict( );
924 
925  // acrobat reader 5 and 6 use the order of the annotations
926  // as their tab order; since PDF1.5 one can make the
927  // tab order explicit by using the structure tree
928  void sortWidgets();
929 
930  // updates the count numbers of outline items
931  sal_Int32 updateOutlineItemCount( std::vector< sal_Int32 >& rCounts,
932  sal_Int32 nItemLevel,
933  sal_Int32 nCurrentItemId );
934  // default appearances for widgets
935  sal_Int32 findRadioGroupWidget( const PDFWriter::RadioButtonWidget& rRadio );
936  Font replaceFont( const Font& rControlFont, const Font& rAppSetFont );
937  sal_Int32 getBestBuildinFont( const Font& rFont );
938  sal_Int32 getSystemFont( const Font& i_rFont );
939 
940  // used for edit and listbox
942 
948 
949  /* ensure proper escapement and uniqueness of field names */
950  void createWidgetFieldName( sal_Int32 i_nWidgetsIndex, const PDFWriter::AnyWidget& i_rInWidget );
951  /* adds an entry to m_aObjects and returns its index+1,
952  * sets the offset to ~0
953  */
954  sal_Int32 createObject();
955  /* sets the offset of object n to the current position of output file+1
956  */
957  bool updateObject( sal_Int32 n );
958 
959  bool writeBuffer( const void* pBuffer, sal_uInt64 nBytes );
960  void beginCompression();
961  void endCompression();
962  void beginRedirect( SvStream* pStream, const tools::Rectangle& );
964 
965  void endPage();
966 
977  bool checkEmitStructure();
978 
979  /* draws an emphasis mark */
980  void drawEmphasisMark( long nX, long nY, const tools::PolyPolygon& rPolyPoly, bool bPolyLine, const tools::Rectangle& rRect1, const tools::Rectangle& rRect2 );
981 
982  /* true if PDF/A-1a or PDF/A-1b is output */
984  /* true if PDF/A-2a is output */
987 
988  /*
989  i12626
990  methods for PDF security
991 
992  pad a password according algorithm 3.2, step 1 */
993  static void padPassword( const OUString& i_rPassword, sal_uInt8* o_pPaddedPW );
994  /* algorithm 3.2: compute an encryption key */
997  sal_Int32 i_nAccessPermissions
998  );
999  /* algorithm 3.3: computing the encryption dictionary'ss owner password value ( /O ) */
1000  static bool computeODictionaryValue( const sal_uInt8* i_pPaddedOwnerPassword, const sal_uInt8* i_pPaddedUserPassword,
1001  std::vector< sal_uInt8 >& io_rOValue,
1002  sal_Int32 i_nKeyLength
1003  );
1004  /* algorithm 3.4 or 3.5: computing the encryption dictionary's user password value ( /U ) revision 2 or 3 of the standard security handler */
1005  static bool computeUDictionaryValue( EncHashTransporter* i_pTransporter,
1007  sal_Int32 i_nKeyLength,
1008  sal_Int32 i_nAccessPermissions
1009  );
1010 
1011  static void computeDocumentIdentifier( std::vector< sal_uInt8 >& o_rIdentifier,
1012  const vcl::PDFWriter::PDFDocInfo& i_rDocInfo,
1013  const OString& i_rCString1,
1014  OString& o_rCString2
1015  );
1016  static sal_Int32 computeAccessPermissions( const vcl::PDFWriter::PDFEncryptionProperties& i_rProperties,
1017  sal_Int32& o_rKeyLength, sal_Int32& o_rRC4KeyLength );
1018  void setupDocInfo();
1019  bool prepareEncryption( const css::uno::Reference< css::beans::XMaterialHolder >& );
1020 
1021  // helper for playMetafile
1022  void implWriteGradient( const tools::PolyPolygon& rPolyPoly, const Gradient& rGradient,
1023  VirtualDevice* pDummyVDev, const vcl::PDFWriter::PlayMetafileContext& );
1024  void implWriteBitmapEx( const Point& rPoint, const Size& rSize, const BitmapEx& rBitmapEx, const Graphic& i_pGraphic,
1025  VirtualDevice const * pDummyVDev, const vcl::PDFWriter::PlayMetafileContext& );
1026 
1027  // helpers for CCITT 1bit bitmap stream
1028  void putG4Bits( sal_uInt32 i_nLength, sal_uInt32 i_nCode, BitStreamState& io_rState );
1029  void putG4Span( long i_nSpan, bool i_bWhitePixel, BitStreamState& io_rState );
1030  void writeG4Stream( BitmapReadAccess const * i_pBitmap );
1031 
1032  // color helper functions
1033  void appendStrokingColor( const Color& rColor, OStringBuffer& rBuffer );
1034  void appendNonStrokingColor( const Color& rColor, OStringBuffer& rBuffer );
1035 public:
1036  PDFWriterImpl( const PDFWriter::PDFWriterContext& rContext, const css::uno::Reference< css::beans::XMaterialHolder >&, PDFWriter& );
1037  ~PDFWriterImpl() override;
1038  void dispose() override;
1039 
1040  static css::uno::Reference< css::beans::XMaterialHolder >
1041  initEncryption( const OUString& i_rOwnerPassword,
1042  const OUString& i_rUserPassword );
1043 
1044  /* document structure */
1045  void newPage( double nPageWidth , double nPageHeight, PDFWriter::Orientation eOrientation );
1046  bool emit();
1047  const std::set< PDFWriter::ErrorCode > & getErrors() const { return m_aErrors;}
1048  void insertError( PDFWriter::ErrorCode eErr ) { m_aErrors.insert( eErr ); }
1050 
1052  {
1053  Size aSize;
1054  if( m_nCurrentPage >= 0 && m_nCurrentPage < static_cast<sal_Int32>(m_aPages.size()) )
1055  aSize = Size( m_aPages[ m_nCurrentPage ].m_nPageWidth, m_aPages[ m_nCurrentPage ].m_nPageHeight );
1056  return aSize;
1057  }
1058 
1059  PDFWriter::PDFVersion getVersion() const { return m_aContext.Version; }
1060 
1061  void setDocumentLocale( const css::lang::Locale& rLoc )
1062  { m_aContext.DocumentLocale = rLoc; }
1063 
1064  /* graphics state */
1065  void push( PushFlags nFlags );
1066  void pop();
1067 
1068  void setFont( const Font& rFont );
1069 
1070  void setMapMode( const MapMode& rMapMode );
1071 
1072  const MapMode& getMapMode() { return m_aGraphicsStack.front().m_aMapMode; }
1073 
1074  void setLineColor( const Color& rColor )
1075  {
1076  m_aGraphicsStack.front().m_aLineColor = ImplIsColorTransparent(rColor) ? COL_TRANSPARENT : rColor;
1077  m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsStateUpdateFlags::LineColor;
1078  }
1079 
1080  void setFillColor( const Color& rColor )
1081  {
1082  m_aGraphicsStack.front().m_aFillColor = ImplIsColorTransparent(rColor) ? COL_TRANSPARENT : rColor;
1083  m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsStateUpdateFlags::FillColor;
1084  }
1085 
1087  {
1088  m_aGraphicsStack.front().m_aTextLineColor = COL_TRANSPARENT;
1089  }
1090 
1091  void setTextLineColor( const Color& rColor )
1092  {
1093  m_aGraphicsStack.front().m_aTextLineColor = rColor;
1094  }
1095 
1097  {
1098  m_aGraphicsStack.front().m_aOverlineColor = COL_TRANSPARENT;
1099  }
1100 
1101  void setOverlineColor( const Color& rColor )
1102  {
1103  m_aGraphicsStack.front().m_aOverlineColor = rColor;
1104  }
1105 
1106  void setTextFillColor( const Color& rColor )
1107  {
1108  m_aGraphicsStack.front().m_aFont.SetFillColor( rColor );
1109  m_aGraphicsStack.front().m_aFont.SetTransparent( ImplIsColorTransparent( rColor ) );
1110  m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsStateUpdateFlags::Font;
1111  }
1113  {
1114  m_aGraphicsStack.front().m_aFont.SetFillColor( COL_TRANSPARENT );
1115  m_aGraphicsStack.front().m_aFont.SetTransparent( true );
1116  m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsStateUpdateFlags::Font;
1117  }
1118  void setTextColor( const Color& rColor )
1119  {
1120  m_aGraphicsStack.front().m_aFont.SetColor( rColor );
1121  m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsStateUpdateFlags::Font;
1122  }
1123 
1125  {
1126  m_aGraphicsStack.front().m_aClipRegion.clear();
1127  m_aGraphicsStack.front().m_bClipRegion = false;
1128  m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsStateUpdateFlags::ClipRegion;
1129  }
1130 
1131  void setClipRegion( const basegfx::B2DPolyPolygon& rRegion );
1132 
1133  void moveClipRegion( sal_Int32 nX, sal_Int32 nY );
1134 
1135  void intersectClipRegion( const tools::Rectangle& rRect );
1136 
1137  void intersectClipRegion( const basegfx::B2DPolyPolygon& rRegion );
1138 
1140  {
1141  m_aGraphicsStack.front().m_nLayoutMode = nLayoutMode;
1142  m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsStateUpdateFlags::LayoutMode;
1143  }
1144 
1146  {
1147  m_aGraphicsStack.front().m_aDigitLanguage = eLang;
1148  m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsStateUpdateFlags::DigitLanguage;
1149  }
1150 
1151  void setTextAlign( TextAlign eAlign )
1152  {
1153  m_aGraphicsStack.front().m_aFont.SetAlignment( eAlign );
1154  m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsStateUpdateFlags::Font;
1155  }
1156 
1157  /* actual drawing functions */
1158  void drawText( const Point& rPos, const OUString& rText, sal_Int32 nIndex, sal_Int32 nLen, bool bTextLines = true );
1159  void drawTextArray( const Point& rPos, const OUString& rText, const long* pDXArray, sal_Int32 nIndex, sal_Int32 nLen );
1160  void drawStretchText( const Point& rPos, sal_uLong nWidth, const OUString& rText,
1161  sal_Int32 nIndex, sal_Int32 nLen );
1162  void drawText( const tools::Rectangle& rRect, const OUString& rOrigStr, DrawTextFlags nStyle );
1163  void drawTextLine( const Point& rPos, long nWidth, FontStrikeout eStrikeout, FontLineStyle eUnderline, FontLineStyle eOverline, bool bUnderlineAbove );
1164  void drawWaveTextLine( OStringBuffer& aLine, long nWidth, FontLineStyle eTextLine, Color aColor, bool bIsAbove );
1165  void drawStraightTextLine( OStringBuffer& aLine, long nWidth, FontLineStyle eTextLine, Color aColor, bool bIsAbove );
1166  void drawStrikeoutLine( OStringBuffer& aLine, long nWidth, FontStrikeout eStrikeout, Color aColor );
1167  void drawStrikeoutChar( const Point& rPos, long nWidth, FontStrikeout eStrikeout );
1168 
1169  void drawLine( const Point& rStart, const Point& rStop );
1170  void drawLine( const Point& rStart, const Point& rStop, const LineInfo& rInfo );
1171  void drawPolygon( const tools::Polygon& rPoly );
1172  void drawPolyPolygon( const tools::PolyPolygon& rPolyPoly );
1173  void drawPolyLine( const tools::Polygon& rPoly );
1174  void drawPolyLine( const tools::Polygon& rPoly, const LineInfo& rInfo );
1175  void drawPolyLine( const tools::Polygon& rPoly, const PDFWriter::ExtLineInfo& rInfo );
1176 
1177  void drawPixel( const Point& rPt, const Color& rColor );
1178 
1179  void drawRectangle( const tools::Rectangle& rRect );
1180  void drawRectangle( const tools::Rectangle& rRect, sal_uInt32 nHorzRound, sal_uInt32 nVertRound );
1181  void drawEllipse( const tools::Rectangle& rRect );
1182  void drawArc( const tools::Rectangle& rRect, const Point& rStart, const Point& rStop, bool bWithPie, bool bWidthChord );
1183 
1184  void drawBitmap( const Point& rDestPoint, const Size& rDestSize, const Bitmap& rBitmap, const Graphic& rGraphic );
1185  void drawBitmap( const Point& rDestPoint, const Size& rDestSize, const BitmapEx& rBitmap );
1186  void drawJPGBitmap( SvStream& rDCTData, bool bIsTrueColor, const Size& rSizePixel, const tools::Rectangle& rTargetArea, const Bitmap& rMask, const Graphic& rGraphic );
1188  void createEmbeddedFile(const Graphic& rGraphic, ReferenceXObjectEmit& rEmit, sal_Int32 nBitmapObject);
1189 
1190  void drawGradient( const tools::Rectangle& rRect, const Gradient& rGradient );
1191  void drawHatch( const tools::PolyPolygon& rPolyPoly, const Hatch& rHatch );
1192  void drawWallpaper( const tools::Rectangle& rRect, const Wallpaper& rWall );
1193  void drawTransparent( const tools::PolyPolygon& rPolyPoly, sal_uInt32 nTransparentPercent );
1194  void beginTransparencyGroup();
1195  void endTransparencyGroup( const tools::Rectangle& rBoundingBox, sal_uInt32 nTransparentPercent );
1196 
1197  void emitComment( const char* pComment );
1198 
1199  //--->i56629 named destinations
1200  sal_Int32 createNamedDest( const OUString& sDestName, const tools::Rectangle& rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType );
1201 
1202  //--->i59651
1203  //emits output intent
1204  sal_Int32 emitOutputIntent();
1205 
1206  //emits the document metadata
1207  sal_Int32 emitDocumentMetadata();
1208 
1209  // links
1210  sal_Int32 createLink( const tools::Rectangle& rRect, sal_Int32 nPageNr );
1211  sal_Int32 createDest( const tools::Rectangle& rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType );
1212  sal_Int32 registerDestReference( sal_Int32 nDestId, const tools::Rectangle& rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType );
1213  void setLinkDest( sal_Int32 nLinkId, sal_Int32 nDestId );
1214  void setLinkURL( sal_Int32 nLinkId, const OUString& rURL );
1215  void setLinkPropertyId( sal_Int32 nLinkId, sal_Int32 nPropertyId );
1216 
1217  // screens
1218  sal_Int32 createScreen(const tools::Rectangle& rRect, sal_Int32 nPageNr);
1219  void setScreenURL(sal_Int32 nScreenId, const OUString& rURL);
1220  void setScreenStream(sal_Int32 nScreenId, const OUString& rURL);
1221 
1222  // outline
1223  sal_Int32 createOutlineItem( sal_Int32 nParent, const OUString& rText, sal_Int32 nDestID );
1224  void setOutlineItemParent( sal_Int32 nItem, sal_Int32 nNewParent );
1225  void setOutlineItemText( sal_Int32 nItem, const OUString& rText );
1226  void setOutlineItemDest( sal_Int32 nItem, sal_Int32 nDestID );
1227 
1228  // notes
1229  void createNote( const tools::Rectangle& rRect, const PDFNote& rNote, sal_Int32 nPageNr );
1230  // structure elements
1231  sal_Int32 beginStructureElement( PDFWriter::StructElement eType, const OUString& rAlias );
1232  void endStructureElement();
1233  bool setCurrentStructureElement( sal_Int32 nElement );
1235  bool setStructureAttributeNumerical( enum PDFWriter::StructAttribute eAttr, sal_Int32 nValue );
1236  void setStructureBoundingBox( const tools::Rectangle& rRect );
1237  void setActualText( const OUString& rText );
1238  void setAlternateText( const OUString& rText );
1239 
1240  // transitional effects
1241  void setPageTransition( PDFWriter::PageTransition eType, sal_uInt32 nMilliSec, sal_Int32 nPageNr );
1242 
1243  // controls
1244  sal_Int32 createControl( const PDFWriter::AnyWidget& rControl, sal_Int32 nPageNr = -1 );
1245 
1246  // additional streams
1247  void addStream( const OUString& rMimeType, PDFOutputStream* pStream );
1248 
1249  // helper: eventually begin marked content sequence and
1250  // emit a comment in debug case
1251  void MARK( const char* pString );
1252 };
1253 
1254 } // namespace vcl
1255 
1256 #endif //_VCL_PDFEXPORT_HXX
1257 
1258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 createGradient(const Gradient &rGradient, const Size &rSize)
sal_Int32 createNamedDest(const OUString &sDestName, const tools::Rectangle &rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType)
::std::map< sal_Int32, sal_Int32 > m_aDestinationIdTranslation
contains destinations accessible via a public Id, instead of being linked to by an ordinary link ...
static const sal_uInt8 s_nPadString[ENCRYPTED_PWD_SIZE]
void writeG4Stream(BitmapReadAccess const *i_pBitmap)
void drawHorizontalGlyphs(const std::vector< PDFGlyph > &rGlyphs, OStringBuffer &rLine, const Point &rAlignOffset, bool bFirst, double fAngle, double fXScale, double fSkew, sal_Int32 nFontHeight, sal_Int32 nPixelFontHeight)
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
std::list< BitmapEmit > m_aBitmaps
Definition: hatch.hxx:44
void pushResource(ResourceKind eKind, const OString &rResource, sal_Int32 nObject)
sal_Int32 getResourceDictObj()
std::unordered_map< OString, OString > m_aRoleMap
std::vector< sal_Int32 > m_aKids
A PDF Screen annotation.
void setLinkDest(sal_Int32 nLinkId, sal_Int32 nDestId)
void drawLayout(SalLayout &rLayout, const OUString &rText, bool bTextLines)
void setTextLineColor(const Color &rColor)
static constexpr sal_Int32 g_nInheritedPageWidth
sal_Int32 emitBuildinFont(const pdf::BuildinFontFace *, sal_Int32 nObject)
std::map< sal_Int32, sal_Int32 > emitSystemFont(const PhysicalFontFace *, EmbedFont const &)
void implWriteBitmapEx(const Point &rPoint, const Size &rSize, const BitmapEx &rBitmapEx, const Graphic &i_pGraphic, VirtualDevice const *pDummyVDev, const vcl::PDFWriter::PlayMetafileContext &)
bool emitScreenAnnotations()
Write all screen annotations.
sal_Int32 emitDocumentMetadata()
sal_Unicode sal_Ucs
Definition: salgdi.hxx:60
void createDefaultPushButtonAppearance(PDFWidget &, const PDFWriter::PushButtonWidget &rWidget)
void setAlternateText(const OUString &rText)
void implWriteGradient(const tools::PolyPolygon &rPolyPoly, const Gradient &rGradient, VirtualDevice *pDummyVDev, const vcl::PDFWriter::PlayMetafileContext &)
void createDefaultListBoxAppearance(PDFWidget &, const PDFWriter::ListBoxWidget &rWidget)
OUString m_aTempFileURL
Embedded video.
PDFFontCache m_aFontCache
std::map< PDFWriter::StructAttribute, PDFStructureAttribute > m_aAttributes
Size getCurPageSize() const
Font replaceFont(const Font &rControlFont, const Font &rAppSetFont)
void drawEllipse(const tools::Rectangle &rRect)
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: button.hxx:32
void setOverlineColor(const Color &rColor)
std::map< const PhysicalFontFace *, FontSubset > FontSubsetData
static bool computeUDictionaryValue(EncHashTransporter *i_pTransporter, vcl::PDFWriter::PDFEncryptionProperties &io_rProperties, sal_Int32 i_nKeyLength, sal_Int32 i_nAccessPermissions)
void drawPixel(const Point &rPt, const Color &rColor)
void setDigitLanguage(LanguageType eLang)
sal_uIntPtr sal_uLong
void drawRectangle(const tools::Rectangle &rRect)
sal_Ucs getCode(sal_Int32 i_nIndex) const
std::vector< PDFStructureElement > m_aStructure
sal_Int32 emitStructure(PDFStructureElement &rEle)
void drawPolyPolygon(const tools::PolyPolygon &rPolyPoly)
void drawPolygon(const tools::Polygon &rPoly)
void setClipRegion(const basegfx::B2DPolyPolygon &rRegion)
std::unique_ptr< SvMemoryStream > m_pTilingStream
vcl::Region ClipToDeviceBounds(vcl::Region aRegion) const override
Perform actual rect clip against outdev dimensions, to generate empty clips whenever one of the value...
std::unique_ptr< SvMemoryStream > m_pContentStream
sal_Int32 emitFontDescriptor(const PhysicalFontFace *, FontSubsetInfo const &, sal_Int32 nSubsetID, sal_Int32 nStream)
void setOutlineItemDest(sal_Int32 nItem, sal_Int32 nDestID)
PDFWriterImpl(const PDFWriter::PDFWriterContext &rContext, const css::uno::Reference< css::beans::XMaterialHolder > &, PDFWriter &)
std::list< GradientEmit > m_aGradients
sal_Int32 createToUnicodeCMap(sal_uInt8 const *pEncoding, const sal_Ucs *pCodeUnits, const sal_Int32 *pCodeUnitsPerGlyph, const sal_Int32 *pEncToUnicodeIndex, int nGlyphs)
sal_Int32 m_nFormObject
ID of the Form XObject, if any.
sal_Int64 m_nSignatureLastByteRangeNoOffset
std::vector< PDFWidget > m_aWidgets
void drawTextLine(const Point &rPos, long nWidth, FontStrikeout eStrikeout, FontLineStyle eUnderline, FontLineStyle eOverline, bool bUnderlineAbove)
GraphicsStateUpdateFlags m_nUpdateFlags
static const sal_Char * getAttributeValueTag(PDFWriter::StructAttributeValue eVal)
bool ImplIsColorTransparent(Color aColor)
Definition: outdata.hxx:25
FontEmbedData m_aSystemFonts
VclPtr< PDFWriterImpl > m_pWriter
basegfx::B2DPolyPolygon m_aClipRegion
std::unique_ptr< SvMemoryStream > m_pSoftMaskStream
std::map< sal_GlyphId, GlyphEmit > FontEmitMapping
void append(OStringBuffer &, sal_Int32 nFontDictObject)
void drawJPGBitmap(SvStream &rDCTData, bool bIsTrueColor, const Size &rSizePixel, const tools::Rectangle &rTargetArea, const Bitmap &rMask, const Graphic &rGraphic)
void drawWallpaper(const tools::Rectangle &rRect, const Wallpaper &rWall)
void appendPoint(const Point &rPoint, OStringBuffer &rBuffer) const
static const sal_uInt32 ncMaxPDFArraySize
static const sal_Char * getAttributeTag(PDFWriter::StructAttribute eAtr)
static bool computeODictionaryValue(const sal_uInt8 *i_pPaddedOwnerPassword, const sal_uInt8 *i_pPaddedUserPassword, std::vector< sal_uInt8 > &io_rOValue, sal_Int32 i_nKeyLength)
PDFWriter::DestAreaType m_eType
bool appendDest(sal_Int32 nDestID, OStringBuffer &rBuffer)
std::list< PDFStructureElementKid > m_aKids
void addCode(sal_Ucs i_cCode)
void drawStraightTextLine(OStringBuffer &aLine, long nWidth, FontLineStyle eTextLine, Color aColor, bool bIsAbove)
void writeTransparentObject(TransparencyEmit &rObject)
std::shared_ptr< std::vector< sal_Int8 > > m_pData
Contents of the file.
GraphicsState m_aCurrentPDFState
OUString m_aURL
Linked video.
void beginRedirect(SvStream *pStream, const tools::Rectangle &)
std::vector< PDFPage > m_aPages
sal_Int32 getBestBuildinFont(const Font &rFont)
SvStream * endRedirect()
void setFont(const Font &rFont)
void setLinkURL(sal_Int32 nLinkId, const OUString &rURL)
ComplexTextLayoutFlags m_nLayoutMode
std::vector< PDFScreen > m_aScreens
Contains all screen annotations.
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
void drawArc(const tools::Rectangle &rRect, const Point &rStart, const Point &rStop, bool bWithPie, bool bWidthChord)
void newPage(double nPageWidth, double nPageHeight, PDFWriter::Orientation eOrientation)
Play a metafile like an outputdevice would do.
Definition: pdfwriter.hxx:662
sal_Int32 createOutlineItem(sal_Int32 nParent, const OUString &rText, sal_Int32 nDestID)
std::vector< sal_Int32 > m_aAnnotations
std::vector< sal_Int32 > m_aStreamObjects
PDFWriter::Orientation const m_eOrientation
std::vector< TilingEmit > m_aTilings
char sal_Char
bool prepareEncryption(const css::uno::Reference< css::beans::XMaterialHolder > &)
sal_Int32 m_nSignatureObject
void setStructureBoundingBox(const tools::Rectangle &rRect)
std::vector< PDFEmbeddedFile > m_aEmbeddedFiles
Contains embedded files.
void drawWaveTextLine(OStringBuffer &aLine, long nWidth, FontLineStyle eTextLine, Color aColor, bool bIsAbove)
OString emitStructureAttributes(PDFStructureElement &rEle)
void appendPixelPoint(const basegfx::B2DPoint &rPoint, OStringBuffer &rBuffer) const
void appendBuildinFontsToDict(OStringBuffer &rDict) const
std::list< StreamRedirect > m_aOutputStreams
sal_Int32 m_nEmbeddedObject
ID of the vector/embedded object, if m_nFormObject is used.
bool appendLineInfo(const LineInfo &rInfo, OStringBuffer &rBuffer) const
PushFlags
Definition: outdevstate.hxx:38
PDFWriter::DestAreaType m_eType
static const sal_Char * getStructureTag(PDFWriter::StructElement)
sal_Int32 findRadioGroupWidget(const PDFWriter::RadioButtonWidget &rRadio)
GraphicsStateUpdateFlags
static bool computeEncryptionKey(EncHashTransporter *, vcl::PDFWriter::PDFEncryptionProperties &io_rProperties, sal_Int32 i_nAccessPermissions)
bool emit(sal_Int32 nParentPage)
Font drawFieldBorder(PDFWidget &, const PDFWriter::AnyWidget &, const StyleSettings &)
const std::vector< sal_Ucs > & codes() const
bool writeBuffer(const void *pBuffer, sal_uInt64 nBytes)
void appendPolygon(const tools::Polygon &rPoly, OStringBuffer &rBuffer, bool bClose=true) const
static sal_Int32 computeAccessPermissions(const vcl::PDFWriter::PDFEncryptionProperties &i_rProperties, sal_Int32 &o_rKeyLength, sal_Int32 &o_rRC4KeyLength)
void ImplClearFontData(bool bNewFontLists) override
Size m_aPixelSize
Size of the bitmap replacement, in pixels.
css::uno::Reference< css::util::XURLTransformer > m_xTrans
static void padPassword(const OUString &i_rPassword, sal_uInt8 *o_pPaddedPW)
void drawHatch(const tools::PolyPolygon &rPolyPoly, const Hatch &rHatch)
void registerGlyph(const GlyphItem *pGlyph, const PhysicalFontFace *pFont, const std::vector< sal_Ucs > &rCodeUnits, sal_uInt8 &nMappedGlyph, sal_Int32 &nMappedFontObject)
abstract base class for physical font faces
void createDefaultRadioButtonAppearance(PDFWidget &, const PDFWriter::RadioButtonWidget &rWidget)
void setDocumentLocale(const css::lang::Locale &rLoc)
std::vector< sal_uInt64 > m_aObjects
PDFStructureAttribute(PDFWriter::StructAttributeValue eVal)
sal_Int32 updateOutlineItemCount(std::vector< sal_Int32 > &rCounts, sal_Int32 nItemLevel, sal_Int32 nCurrentItemId)
void appendNonStrokingColor(const Color &rColor, OStringBuffer &rBuffer)
PDFGlyph(const Point &rPos, const GlyphItem *pGlyph, sal_Int32 nNativeWidth, sal_Int32 nFontId, sal_uInt8 nMappedGlyphId, int nCharPos)
NONE
#define ENCRYPTED_PWD_SIZE
std::list< GraphicsState > m_aGraphicsStack
void setPageTransition(PDFWriter::PageTransition eType, sal_uInt32 nMilliSec, sal_Int32 nPageNr)
void setLineColor(const Color &rColor)
std::vector< sal_Int32 > m_aMCIDParents
bool emitAppearances(PDFWidget &rWidget, OStringBuffer &rAnnotDict)
sal_Int32 registerDestReference(sal_Int32 nDestId, const tools::Rectangle &rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType)
void putG4Span(long i_nSpan, bool i_bWhitePixel, BitStreamState &io_rState)
std::unique_ptr< SvMemoryStream > m_pMemStream
void drawRelief(SalLayout &rLayout, const OUString &rText, bool bTextLines)
void addInternalStructureContainer(PDFStructureElement &rEle)
void setActualText(const OUString &rText)
bool updateObject(sal_Int32 n)
Indirect object: something with a unique ID.
Definition: pdfdocument.hxx:79
std::map< sal_Int32, sal_Int32 > m_aLinkPropertyMap
std::map< const PhysicalFontFace *, EmbedFont > FontEmbedData
sal_Int32 beginStructureElement(PDFWriter::StructElement eType, const OUString &rAlias)
std::unique_ptr< ZCodec > m_pCodec
ComplexTextLayoutFlags
Definition: outdevstate.hxx:66
FontSubsetData m_aSubsets
void endTransparencyGroup(const tools::Rectangle &rBoundingBox, sal_uInt32 nTransparentPercent)
PDFWriter::PDFWriterContext m_aContext
void drawStretchText(const Point &rPos, sal_uLong nWidth, const OUString &rText, sal_Int32 nIndex, sal_Int32 nLen)
std::map< OString, sal_Int32 > ResourceMap
void convertRect(tools::Rectangle &rRect) const
sal_Int32 m_nTempFileObject
ID of the EmbeddedFile object.
bool emitEmbeddedFiles()
Writes embedded files.
void createNote(const tools::Rectangle &rRect, const PDFNote &rNote, sal_Int32 nPageNr)
bool writeGradientFunction(GradientEmit const &rObject)
sal_Int32 getObject() const
Returns the ID one should use when referring to this bitmap.
PDFWriter::WidgetType m_eType
sal_Int32 m_nBitmapObject
ID of the bitmap object, if m_nFormObject is used.
ReferenceXObjectEmit m_aReferenceXObject
void createDefaultEditAppearance(PDFWidget &, const PDFWriter::EditWidget &rWidget)
ResourceDict m_aGlobalResourceDict
void emitComment(const char *pComment)
void createWidgetFieldName(sal_Int32 i_nWidgetsIndex, const PDFWriter::AnyWidget &i_rInWidget)
static void computeDocumentIdentifier(std::vector< sal_uInt8 > &o_rIdentifier, const vcl::PDFWriter::PDFDocInfo &i_rDocInfo, const OString &i_rCString1, OString &o_rCString2)
void createEmbeddedFile(const Graphic &rGraphic, ReferenceXObjectEmit &rEmit, sal_Int32 nBitmapObject)
Stores the original PDF data from rGraphic as an embedded file.
Contains information to emit a reference XObject.
PDFWriter & m_rOuterFace
void putG4Bits(sal_uInt32 i_nLength, sal_uInt32 i_nCode, BitStreamState &io_rState)
void drawTextArray(const Point &rPos, const OUString &rText, const long *pDXArray, sal_Int32 nIndex, sal_Int32 nLen)
DrawTextFlags
Definition: outdev.hxx:144
std::vector< PDFOutlineEntry > m_aOutline
static bool compressStream(SvMemoryStream *)
sal_Int32 createControl(const PDFWriter::AnyWidget &rControl, sal_Int32 nPageNr=-1)
sal_Int32 emitStructParentTree(sal_Int32 nTreeObject)
sal_Int32 emitOutputIntent()
std::unordered_map< OString, SvMemoryStream * > PDFAppearanceStreams
void drawEmphasisMark(long nX, long nY, const tools::PolyPolygon &rPolyPoly, bool bPolyLine, const tools::Rectangle &rRect1, const tools::Rectangle &rRect2)
void setTextAlign(TextAlign eAlign)
static void convertLineInfoToExtLineInfo(const LineInfo &rIn, PDFWriter::ExtLineInfo &rOut)
PDFWriter::StructAttributeValue eValue
std::vector< PDFNamedDest > m_aNamedDests
void intersectClipRegion(const tools::Rectangle &rRect)
void push(PushFlags nFlags)
PDFWriter::PageTransition m_eTransition
void setScreenStream(sal_Int32 nScreenId, const OUString &rURL)
std::unique_ptr< SvMemoryStream > m_pStream
const BitmapEmit & createBitmapEmit(const BitmapEx &rBitmapEx, const Graphic &rGraphic)
sal_Int32 copyExternalResource(SvMemoryStream &rDocBuffer, filter::PDFObjectElement &rObject, std::map< sal_Int32, sal_Int32 > &rCopiedResources)
Copies a single resource from an external document, returns the new object ID in our document...
std::unordered_map< OString, sal_Int32 > m_aFieldNameMap
void dispose() override
std::vector< OUString > m_aListEntries
void drawPolyLine(const tools::Polygon &rPoly)
void drawLine(const Point &rStart, const Point &rStop)
void setTextFillColor(const Color &rColor)
std::vector< PDFLink > m_aLinks
std::vector< FontEmit > m_aSubsets
void appendUnicodeTextStringEncrypt(const OUString &rInString, const sal_Int32 nInObjectNumber, OStringBuffer &rOutBuffer)
void ImplRefreshFontData(bool bNewFontLists) override
void appendRect(const tools::Rectangle &rRect, OStringBuffer &rBuffer) const
void setOutlineItemParent(sal_Int32 nItem, sal_Int32 nNewParent)
std::vector< sal_Int32 > m_aSelectedEntries
bool writeBitmapObject(BitmapEmit &rObject, bool bMask=false)
void appendMappedLength(sal_Int32 nLength, OStringBuffer &rBuffer, bool bVertical=true, sal_Int32 *pOutLength=nullptr) const
void drawShadow(SalLayout &rLayout, const OUString &rText, bool bTextLines)
void appendWaveLine(sal_Int32 nLength, sal_Int32 nYOffset, sal_Int32 nDelta, OStringBuffer &rBuffer) const
unsigned char sal_uInt8
std::map< sal_Int32, sal_Int32 > m_aRadioGroupWidgets
void writeReferenceXObject(ReferenceXObjectEmit &rEmit)
Writes the form XObject proxy for the image.
void setOutlineItemText(sal_Int32 nItem, const OUString &rText)
std::map< sal_GlyphId, Glyph > FontMapping
void addStream(const OUString &rMimeType, PDFOutputStream *pStream)
void drawGradient(const tools::Rectangle &rRect, const Gradient &rGradient)
void setTextColor(const Color &rColor)
sal_Int64 m_nSignatureContentOffset
static constexpr sal_Int32 g_nInheritedPageHeight
sal_Int32 createLink(const tools::Rectangle &rRect, sal_Int32 nPageNr)
void setMapMode(const MapMode &rMapMode)
void checkAndEnableStreamEncryption(sal_Int32 nObject)
bool setStructureAttribute(enum PDFWriter::StructAttribute eAttr, enum PDFWriter::StructAttributeValue eVal)
std::unordered_map< OString, PDFAppearanceStreams > PDFAppearanceMap
OString copyExternalResources(filter::PDFObjectElement &rPage, const OString &rKind, std::map< sal_Int32, sal_Int32 > &rCopiedResources)
Copies resources of a given kind from an external page to the output, returning what has to be includ...
std::vector< sal_Int8 > m_aPDFData
PDF data from the graphic object, if not writing a reference XObject.
void setLinkPropertyId(sal_Int32 nLinkId, sal_Int32 nPropertyId)
PDFStructureElementKid(sal_Int32 MCID, sal_Int32 nPage)
void setScreenURL(sal_Int32 nScreenId, const OUString &rURL)
std::vector< sal_Int32 > m_aChildren
void setGlyphId(sal_uInt8 i_nId)
void drawStrikeoutLine(OStringBuffer &aLine, long nWidth, FontStrikeout eStrikeout, Color aColor)
sal_Int32 m_nObject
ID of the file.
PDFPage(PDFWriterImpl *pWriter, double nPageWidth, double nPageHeight, PDFWriter::Orientation eOrientation)
void DrawHatchLine_DrawLine(const Point &rStartPoint, const Point &rEndPoint) override
void drawVerticalGlyphs(const std::vector< PDFGlyph > &rGlyphs, OStringBuffer &rLine, const Point &rAlignOffset, const Matrix3 &rRotScale, double fAngle, double fXScale, double fSkew, sal_Int32 nFontHeight)
std::vector< JPGEmit > m_aJPGs
PDFWriter::PDFVersion getVersion() const
void setLayoutMode(ComplexTextLayoutFlags nLayoutMode)
void appendLiteralStringEncrypt(const OUString &rInString, const sal_Int32 nInObjectNumber, OStringBuffer &rOutBuffer, rtl_TextEncoding nEnc=RTL_TEXTENCODING_ASCII_US)
void drawStrikeoutChar(const Point &rPos, long nWidth, FontStrikeout eStrikeout)
void setFillColor(const Color &rColor)
bool setCurrentStructureElement(sal_Int32 nElement)
bool setStructureAttributeNumerical(enum PDFWriter::StructAttribute eAttr, sal_Int32 nValue)
sal_Int32 m_nAccessPermissions
bool operator==(const BitmapID &rComp) const
std::set< PDFWriter::ErrorCode > m_aErrors
std::vector< PDFAddStream > m_aAdditionalStreams
std::vector< OString > m_aStructParentTree
ReferenceXObjectEmit m_aReferenceXObject
sal_Int32 m_nCurrentStructElement
SvtGraphicFill::Transform m_aTransform
void drawText(const Point &rPos, const OUString &rText, sal_Int32 nIndex, sal_Int32 nLen, bool bTextLines=true)
const std::set< PDFWriter::ErrorCode > & getErrors() const
void drawBitmap(const Point &rDestPt, const Size &rDestSize, const BitmapEmit &rBitmap, const Color &rFillColor)
std::vector< sal_uInt8 > m_vEncryptionBuffer
sal_Int32 getSystemFont(const Font &i_rFont)
void createDefaultCheckBoxAppearance(PDFWidget &, const PDFWriter::CheckBoxWidget &rWidget)
void drawTransparent(const tools::PolyPolygon &rPolyPoly, sal_uInt32 nTransparentPercent)
void moveClipRegion(sal_Int32 nX, sal_Int32 nY)
std::vector< PDFNoteEntry > m_aNotes
sal_Int32 emitNamedDestinations()
static css::uno::Reference< css::beans::XMaterialHolder > initEncryption(const OUString &i_rOwnerPassword, const OUString &i_rUserPassword)
FontLineStyle
std::vector< sal_Int32 > m_aKidsIndex
void insertError(PDFWriter::ErrorCode eErr)
sal_Int32 createScreen(const tools::Rectangle &rRect, sal_Int32 nPageNr)
bool checkEmitStructure()
checks whether a non struct element lies in the ancestor hierarchy of the current structure element ...
void appendStrokingColor(const Color &rColor, OStringBuffer &rBuffer)
std::vector< sal_Ucs > m_CodeUnits
void enableStringEncryption(sal_Int32 nObject)
void MARK(const char *pString)
const MapMode & getMapMode()
std::map< sal_Int32, sal_Int32 > m_aBuildinFontToObjectMap
css::lang::Locale DocumentLocale
Definition: pdfwriter.hxx:598
void updateGraphicsState(Mode mode=DEFAULT)
FontStrikeout
std::list< TransparencyEmit > m_aTransparentObjects
Homogeneous 2D transformation matrix.
void writeJPG(JPGEmit &rEmit)
TextAlign
::comphelper::Hash m_DocDigest
void appendPolyPolygon(const tools::PolyPolygon &rPolyPoly, OStringBuffer &rBuffer) const
std::vector< PDFDest > m_aDests
OString m_aCreationMetaDateString
sal_Int32 createDest(const tools::Rectangle &rRect, sal_Int32 nPageNr, PDFWriter::DestAreaType eType)
sal_Int32 getFontDictObject()
void playMetafile(const GDIMetaFile &, vcl::PDFExtOutDevData *, const vcl::PDFWriter::PlayMetafileContext &, VirtualDevice *pDummyDev=nullptr)