merge the formfield patch from ooo-build
[ooovba.git] / vcl / source / gdi / pdfwriter_impl.hxx
blob2b179e8816886e93ae1fe66397b50e9b58e1e1b3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 #ifndef _VCL_PDFWRITER_IMPL_HXX
28 #define _VCL_PDFWRITER_IMPL_HXX
30 #include "vcl/pdfwriter.hxx"
31 #include "rtl/ustring.hxx"
32 #include "osl/file.h"
33 #include "tools/gen.hxx"
34 #include "tools/stream.hxx"
35 #include "vcl/outdev.hxx"
36 #include "vcl/bitmapex.hxx"
37 #include "vcl/gradient.hxx"
38 #include "vcl/hatch.hxx"
39 #include "vcl/wall.hxx"
40 #include "vcl/outdata.hxx"
41 #include "rtl/strbuf.hxx"
42 #include "rtl/cipher.h"
43 #include "rtl/digest.h"
44 #include "com/sun/star/util/XURLTransformer.hpp"
45 #include "com/sun/star/lang/Locale.hpp"
47 #include <vcl/sallayout.hxx>
48 #include "pdffontcache.hxx"
50 #include <vector>
51 #include <map>
52 #include <hash_map>
53 #include <list>
55 class ImplFontSelectData;
56 class ImplFontMetricData;
57 class FontSubsetInfo;
58 class ZCodec;
60 // the maximum password length
61 #define ENCRYPTED_PWD_SIZE 32
62 #define MD5_DIGEST_SIZE 16
63 #define SECUR_40BIT_KEY 5
64 // security 128 bit
65 #define SECUR_128BIT_KEY 16
66 // maximum length of MD5 digest input, in step 2 of algorithm 3.1
67 // PDF spec ver. 1.4: see there for details
68 #define MAXIMUM_RC4_KEY_LENGTH (SECUR_128BIT_KEY+3+2)
70 namespace vcl
73 class PDFSalLayout;
74 class PDFStreamIf;
75 class Matrix3;
77 class PDFWriterImpl
79 friend class PDFSalLayout;
80 friend class PDFStreamIf;
81 public:
82 // definition of structs
83 struct BuiltinFont
85 const char * m_pName; // Name
86 const char * m_pStyleName; // StyleName
87 const char * m_pPSName; // PSName
88 int m_nAscent;
89 int m_nDescent;
90 FontFamily m_eFamily; // Family
91 CharSet m_eCharSet; // CharSet
92 FontPitch m_ePitch; // Pitch
93 FontWidth m_eWidthType; // WidthType
94 FontWeight m_eWeight; // Weight
95 FontItalic m_eItalic; // Italic
96 int m_aWidths[256]; // character metrics
98 rtl::OString getNameObject() const;
102 enum ResourceKind { ResXObject, ResExtGState, ResShading, ResPattern };
103 typedef std::map< rtl::OString, sal_Int32 > ResourceMap;
104 struct ResourceDict
106 // note: handle fonts globally for performance
107 ResourceMap m_aXObjects;
108 ResourceMap m_aExtGStates;
109 ResourceMap m_aShadings;
110 ResourceMap m_aPatterns;
112 void append( rtl::OStringBuffer&, sal_Int32 nFontDictObject );
115 struct PDFPage
117 PDFWriterImpl* m_pWriter;
118 sal_Int32 m_nPageWidth; // in inch/72
119 sal_Int32 m_nPageHeight; // in inch/72
120 PDFWriter::Orientation m_eOrientation;
121 sal_Int32 m_nPageObject;
122 sal_Int32 m_nPageIndex;
123 std::vector<sal_Int32> m_aStreamObjects;
124 sal_Int32 m_nStreamLengthObject;
125 sal_uInt64 m_nBeginStreamPos;
126 std::vector<sal_Int32> m_aAnnotations;
127 std::vector<sal_Int32> m_aMCIDParents;
128 PDFWriter::PageTransition m_eTransition;
129 sal_uInt32 m_nTransTime;
130 sal_uInt32 m_nDuration;
131 bool m_bHasWidgets;
133 PDFPage( PDFWriterImpl* pWriter, sal_Int32 nPageWidth, sal_Int32 nPageHeight, PDFWriter::Orientation eOrientation );
134 ~PDFPage();
136 void beginStream();
137 void endStream();
138 bool emit( sal_Int32 nParentPage );
140 // converts point from ref device coordinates to
141 // page coordinates and appends the point to the buffer
142 // if bNeg is true, the coordinates are inverted AFTER transformation
143 // to page (useful for transformation matrices
144 // if pOutPoint is set it will be updated to the emitted point
145 // (in PDF map mode, that is 10th of point)
146 void appendPoint( const Point& rPoint, rtl::OStringBuffer& rBuffer, bool bNeg = false, Point* pOutPoint = NULL ) const;
147 // appends a rectangle
148 void appendRect( const Rectangle& rRect, rtl::OStringBuffer& rBuffer ) const;
149 // converts a rectangle to 10th points page space
150 void convertRect( Rectangle& rRect ) const;
151 // appends a polygon optionally closing it
152 void appendPolygon( const Polygon& rPoly, rtl::OStringBuffer& rBuffer, bool bClose = true ) const;
153 // appends a polypolygon optionally closing the subpaths
154 void appendPolyPolygon( const PolyPolygon& rPolyPoly, rtl::OStringBuffer& rBuffer, bool bClose = true ) const;
155 // converts a length (either vertical or horizontal; this
156 // can be important if the source MapMode is not
157 // symmetrical) to page length and appends it to the buffer
158 // if pOutLength is set it will be updated to the emitted length
159 // (in PDF map mode, that is 10th of point)
160 void appendMappedLength( sal_Int32 nLength, rtl::OStringBuffer& rBuffer, bool bVertical = true, sal_Int32* pOutLength = NULL ) const;
161 // the same for double values
162 void appendMappedLength( double fLength, rtl::OStringBuffer& rBuffer, bool bVertical = true, sal_Int32* pOutLength = NULL ) const;
163 // appends LineInfo
164 // returns false if too many dash array entry were created for
165 // the implementation limits of some PDF readers
166 bool appendLineInfo( const LineInfo& rInfo, rtl::OStringBuffer& rBuffer ) const;
167 // appends a horizontal waveline with vertical offset (helper for drawWaveLine)
168 void appendWaveLine( sal_Int32 nLength, sal_Int32 nYOffset, sal_Int32 nDelta, rtl::OStringBuffer& rBuffer ) const;
170 sal_Int32 getWidth() const { return m_nPageWidth ? m_nPageWidth : m_pWriter->m_nInheritedPageWidth; }
171 sal_Int32 getHeight() const { return m_nPageHeight ? m_nPageHeight : m_pWriter->m_nInheritedPageHeight; }
174 friend struct PDFPage;
176 struct BitmapID
178 Size m_aPixelSize;
179 sal_Int32 m_nSize;
180 sal_Int32 m_nChecksum;
181 sal_Int32 m_nMaskChecksum;
183 BitmapID() : m_nSize( 0 ), m_nChecksum( 0 ), m_nMaskChecksum( 0 ) {}
185 BitmapID& operator=( const BitmapID& rCopy )
187 m_aPixelSize = rCopy.m_aPixelSize;
188 m_nSize = rCopy.m_nSize;
189 m_nChecksum = rCopy.m_nChecksum;
190 m_nMaskChecksum = rCopy.m_nMaskChecksum;
191 return *this;
194 bool operator==( const BitmapID& rComp )
196 return (m_aPixelSize == rComp.m_aPixelSize &&
197 m_nSize == rComp.m_nSize &&
198 m_nChecksum == rComp.m_nChecksum &&
199 m_nMaskChecksum == rComp.m_nMaskChecksum );
203 struct BitmapEmit
205 BitmapID m_aID;
206 BitmapEx m_aBitmap;
207 sal_Int32 m_nObject;
208 bool m_bDrawMask;
210 BitmapEmit() : m_bDrawMask( false ) {}
213 struct JPGEmit
215 BitmapID m_aID;
216 SvMemoryStream* m_pStream;
217 Bitmap m_aMask;
218 sal_Int32 m_nObject;
219 bool m_bTrueColor;
221 JPGEmit() : m_pStream( NULL ) {}
222 ~JPGEmit() { delete m_pStream; }
225 struct GradientEmit
227 Gradient m_aGradient;
228 Size m_aSize;
229 sal_Int32 m_nObject;
232 // for tilings (drawWallpaper, begin/endPattern)
233 struct TilingEmit
235 sal_Int32 m_nObject;
236 Rectangle m_aRectangle;
237 Size m_aCellSize;
238 SvtGraphicFill::Transform m_aTransform;
239 ResourceDict m_aResources;
240 SvMemoryStream* m_pTilingStream;
242 TilingEmit()
243 : m_nObject( 0 ),
244 m_pTilingStream( NULL )
248 // for transparency group XObjects
249 struct TransparencyEmit
251 sal_Int32 m_nObject;
252 sal_Int32 m_nExtGStateObject;
253 double m_fAlpha;
254 Rectangle m_aBoundRect;
255 SvMemoryStream* m_pContentStream;
256 SvMemoryStream* m_pSoftMaskStream;
258 TransparencyEmit()
259 : m_nObject( 0 ),
260 m_nExtGStateObject( -1 ),
261 m_fAlpha( 0.0 ),
262 m_pContentStream( NULL ),
263 m_pSoftMaskStream( NULL )
265 ~TransparencyEmit()
267 delete m_pContentStream;
268 delete m_pSoftMaskStream;
272 // font subsets
273 struct GlyphEmit
275 sal_Ucs m_aUnicode;
276 sal_uInt8 m_nSubsetGlyphID;
278 typedef std::map< sal_GlyphId, GlyphEmit > FontEmitMapping;
279 struct FontEmit
281 sal_Int32 m_nFontID;
282 FontEmitMapping m_aMapping;
284 FontEmit( sal_Int32 nID ) : m_nFontID( nID ) {}
286 typedef std::list< FontEmit > FontEmitList;
287 struct Glyph
289 sal_Int32 m_nFontID;
290 sal_uInt8 m_nSubsetGlyphID;
292 typedef std::map< sal_GlyphId, Glyph > FontMapping;
293 struct FontSubset
295 FontEmitList m_aSubsets;
296 FontMapping m_aMapping;
298 typedef std::map< const ImplFontData*, FontSubset > FontSubsetData;
299 struct EmbedCode
301 sal_Ucs m_aUnicode;
302 rtl::OString m_aName;
304 struct EmbedEncoding
306 sal_Int32 m_nFontID;
307 std::vector< EmbedCode > m_aEncVector;
308 std::map< sal_Ucs, sal_Int8 > m_aCMap;
310 struct EmbedFont
312 sal_Int32 m_nNormalFontID;
313 std::list< EmbedEncoding > m_aExtendedEncodings;
315 typedef std::map< const ImplFontData*, EmbedFont > FontEmbedData;
317 struct PDFDest
319 sal_Int32 m_nPage;
320 PDFWriter::DestAreaType m_eType;
321 Rectangle m_aRect;
324 //--->i56629
325 struct PDFNamedDest
327 rtl::OUString m_aDestName;
328 sal_Int32 m_nPage;
329 PDFWriter::DestAreaType m_eType;
330 Rectangle m_aRect;
332 //<---
334 struct PDFOutlineEntry
336 sal_Int32 m_nParentID;
337 sal_Int32 m_nObject;
338 sal_Int32 m_nParentObject;
339 sal_Int32 m_nNextObject;
340 sal_Int32 m_nPrevObject;
341 std::vector< sal_Int32 > m_aChildren;
342 rtl::OUString m_aTitle;
343 sal_Int32 m_nDestID;
345 PDFOutlineEntry()
346 : m_nParentID( -1 ),
347 m_nObject( 0 ),
348 m_nParentObject( 0 ),
349 m_nNextObject( 0 ),
350 m_nPrevObject( 0 ),
351 m_nDestID( -1 )
355 struct PDFAnnotation
357 sal_Int32 m_nObject;
358 Rectangle m_aRect;
359 sal_Int32 m_nPage;
361 PDFAnnotation()
362 : m_nObject( -1 ),
363 m_nPage( -1 )
367 struct PDFLink : public PDFAnnotation
369 sal_Int32 m_nDest; // set to -1 for URL, to a dest else
370 rtl::OUString m_aURL;
371 sal_Int32 m_nStructParent; // struct parent entry
373 PDFLink()
374 : m_nDest( -1 ),
375 m_nStructParent( -1 )
379 struct PDFNoteEntry : public PDFAnnotation
381 PDFNote m_aContents;
383 PDFNoteEntry()
387 typedef std::hash_map< rtl::OString, SvMemoryStream*, rtl::OStringHash > PDFAppearanceStreams;
388 typedef std::hash_map< rtl::OString, PDFAppearanceStreams, rtl::OStringHash > PDFAppearanceMap;
390 struct PDFWidget : public PDFAnnotation
392 PDFWriter::WidgetType m_eType;
393 rtl::OString m_aName;
394 rtl::OUString m_aDescription;
395 rtl::OUString m_aText;
396 USHORT m_nTextStyle;
397 rtl::OUString m_aValue;
398 rtl::OString m_aDAString;
399 rtl::OString m_aMKDict;
400 rtl::OString m_aMKDictCAString; // i12626, added to be able to encrypt the /CA text string
401 // since the object number is not known at the moment
402 // of filling m_aMKDict, the string will be encrypted when emitted.
403 // the /CA string MUST BE the last added to m_aMKDict
404 // see code for details
405 sal_Int32 m_nFlags;
406 sal_Int32 m_nParent; // if not 0, parent's object number
407 std::vector<sal_Int32> m_aKids; // widget children, contains object numbers
408 std::vector<sal_Int32> m_aKidsIndex; // widget children, contains index to m_aWidgets
409 rtl::OUString m_aOnValue;
410 sal_Int32 m_nTabOrder; // lowest number gets first in tab order
411 sal_Int32 m_nRadioGroup;
412 sal_Int32 m_nMaxLen;
413 bool m_bSubmit;
414 bool m_bSubmitGet;
415 sal_Int32 m_nDest;
416 std::vector<rtl::OUString> m_aListEntries;
417 std::vector<sal_Int32> m_aSelectedEntries;
418 PDFAppearanceMap m_aAppearances;
419 PDFWidget()
420 : m_eType( PDFWriter::PushButton ),
421 m_nTextStyle( 0 ),
422 m_nFlags( 0 ),
423 m_nParent( 0 ),
424 m_nRadioGroup( -1 ),
425 m_nMaxLen( 0 ),
426 m_bSubmit( false ),
427 m_bSubmitGet( false ),
428 m_nDest( -1 )
432 struct PDFStructureAttribute
434 PDFWriter::StructAttributeValue eValue;
435 sal_Int32 nValue;
437 PDFStructureAttribute()
438 : eValue( PDFWriter::Invalid ),
439 nValue( 0 )
442 PDFStructureAttribute( PDFWriter::StructAttributeValue eVal )
443 : eValue( eVal ),
444 nValue( 0 )
447 PDFStructureAttribute( sal_Int32 nVal )
448 : eValue( PDFWriter::Invalid ),
449 nValue( nVal )
453 typedef std::map<PDFWriter::StructAttribute, PDFStructureAttribute > PDFStructAttributes;
455 struct PDFStructureElementKid // for Kids entries
457 sal_Int32 nObject; // an object number if nMCID is -1,
458 // else the page object relevant to MCID
459 sal_Int32 nMCID; // an MCID if >= 0
461 PDFStructureElementKid( sal_Int32 nObj ) : nObject( nObj ), nMCID( -1 ) {}
462 PDFStructureElementKid( sal_Int32 MCID, sal_Int32 nPage ) : nObject( nPage ), nMCID( MCID ) {}
465 struct PDFStructureElement
467 sal_Int32 m_nObject;
468 PDFWriter::StructElement m_eType;
469 rtl::OString m_aAlias;
470 sal_Int32 m_nOwnElement; // index into structure vector
471 sal_Int32 m_nParentElement; // index into structure vector
472 sal_Int32 m_nFirstPageObject;
473 bool m_bOpenMCSeq;
474 std::list< sal_Int32 > m_aChildren; // indexes into structure vector
475 std::list< PDFStructureElementKid > m_aKids;
476 PDFStructAttributes m_aAttributes;
477 Rectangle m_aBBox;
478 rtl::OUString m_aActualText;
479 rtl::OUString m_aAltText;
480 com::sun::star::lang::Locale m_aLocale;
482 // m_aContents contains the element's marked content sequence
483 // as pairs of (page nr, MCID)
485 PDFStructureElement()
486 : m_nObject( 0 ),
487 m_eType( PDFWriter::NonStructElement ),
488 m_nOwnElement( -1 ),
489 m_nParentElement( -1 ),
490 m_nFirstPageObject( 0 ),
491 m_bOpenMCSeq( false )
497 struct PDFAddStream
499 rtl::OUString m_aMimeType;
500 PDFOutputStream* m_pStream;
501 sal_Int32 m_nStreamObject;
502 bool m_bCompress;
504 PDFAddStream() : m_pStream( NULL ), m_nStreamObject( 0 ), m_bCompress( true ) {}
508 // helper structure for drawLayout and friends
509 struct PDFGlyph
511 Point m_aPos;
512 sal_Int32 m_nNativeWidth;
513 sal_Int32 m_nGlyphId;
514 sal_Int32 m_nMappedFontId;
515 sal_uInt8 m_nMappedGlyphId;
517 PDFGlyph( const Point& rPos,
518 sal_Int32 nNativeWidth,
519 sal_Int32 nGlyphId,
520 sal_Int32 nFontId,
521 sal_uInt8 nMappedGlyphId )
522 : m_aPos( rPos ), m_nNativeWidth( nNativeWidth ), m_nGlyphId( nGlyphId ),
523 m_nMappedFontId( nFontId ), m_nMappedGlyphId( nMappedGlyphId )
528 static const sal_Char* getStructureTag( PDFWriter::StructElement );
529 static const sal_Char* getAttributeTag( PDFWriter::StructAttribute eAtr );
530 static const sal_Char* getAttributeValueTag( PDFWriter::StructAttributeValue eVal );
532 // returns true if compression was done
533 // else false
534 static bool compressStream( SvMemoryStream* );
536 static void convertLineInfoToExtLineInfo( const LineInfo& rIn, PDFWriter::ExtLineInfo& rOut );
537 private:
538 static const BuiltinFont m_aBuiltinFonts[14];
540 OutputDevice* m_pReferenceDevice;
542 MapMode m_aMapMode; // PDFWriterImpl scaled units
543 std::vector< PDFPage > m_aPages;
544 PDFDocInfo m_aDocInfo;
545 /* maps object numbers to file offsets (needed for xref) */
546 std::vector< sal_uInt64 > m_aObjects;
547 /* contains Bitmaps until they are written to the
548 * file stream as XObjects*/
549 std::list< BitmapEmit > m_aBitmaps;
550 /* contains JPG streams until written to file */
551 std::list<JPGEmit> m_aJPGs;
552 /*--->i56629 contains all named destinations ever set during the PDF creation,
553 destination id is always the destination's position in this vector
555 std::vector<PDFNamedDest> m_aNamedDests;
556 //<---
557 /* contains all dests ever set during the PDF creation,
558 dest id is always the dest's position in this vector
560 std::vector<PDFDest> m_aDests;
561 /* contains all links ever set during PDF creation,
562 link id is always the link's position in this vector
564 std::vector<PDFLink> m_aLinks;
565 /* makes correctly encoded for export to PDF URLS
567 com::sun::star::uno::Reference< com::sun::star::util::XURLTransformer > m_xTrans;
568 /* maps arbitrary link ids for structure attributes to real link ids
569 (for setLinkPropertyId)
571 std::map<sal_Int32, sal_Int32> m_aLinkPropertyMap;
572 /* contains all outline items,
573 object 0 is the outline root
575 std::vector<PDFOutlineEntry> m_aOutline;
576 /* contains all notes set during PDF creation
578 std::vector<PDFNoteEntry> m_aNotes;
579 /* the root of the structure tree
581 std::vector<PDFStructureElement> m_aStructure;
582 /* current object in the structure hierarchy
584 sal_Int32 m_nCurrentStructElement;
585 /* structure parent tree */
586 std::vector< rtl::OString > m_aStructParentTree;
587 /* emit strucure marks currently (aka. NonStructElement or not)
589 bool m_bEmitStructure;
590 bool m_bNewMCID;
591 /* role map of struct tree root */
592 std::hash_map< rtl::OString, rtl::OString, rtl::OStringHash >
593 m_aRoleMap;
595 /* contains all widgets used in the PDF
597 std::vector<PDFWidget> m_aWidgets;
598 /* maps radio group id to index of radio group control in m_aWidgets */
599 std::map< sal_Int32, sal_Int32 > m_aRadioGroupWidgets;
600 /* used to store control id during beginControlAppearance/endControlAppearance */
601 sal_Int32 m_nCurrentControl;
602 /* hash_map for field names, used to ensure unique field names */
603 std::hash_map< rtl::OString, sal_Int32, rtl::OStringHash > m_aFieldNameMap;
605 /* contains Bitmaps for gradient functions until they are written
606 * to the file stream */
607 std::list< GradientEmit > m_aGradients;
608 /* contains bitmap tiling patterns */
609 std::vector< TilingEmit > m_aTilings;
610 std::list< TransparencyEmit > m_aTransparentObjects;
611 /* contains all font subsets in use */
612 FontSubsetData m_aSubsets;
613 bool m_bEmbedStandardFonts;
614 FontEmbedData m_aEmbeddedFonts;
615 sal_Int32 m_nNextFID;
616 PDFFontCache m_aFontCache;
618 sal_Int32 m_nInheritedPageWidth; // in inch/72
619 sal_Int32 m_nInheritedPageHeight; // in inch/72
620 PDFWriter::Orientation m_eInheritedOrientation;
621 sal_Int32 m_nCurrentPage;
623 sal_Int32 m_nCatalogObject;
624 sal_Int32 m_nResourceDict;
625 ResourceDict m_aGlobalResourceDict;
626 sal_Int32 m_nFontDictObject;
627 std::map< sal_Int32, sal_Int32 > m_aBuiltinFontToObjectMap;
629 PDFWriter::PDFWriterContext m_aContext;
630 oslFileHandle m_aFile;
631 bool m_bOpen;
634 /* output redirection; e.g. to accumulate content streams for
635 XObjects
637 struct StreamRedirect
639 SvStream* m_pStream;
640 MapMode m_aMapMode;
641 Rectangle m_aTargetRect;
642 ResourceDict m_aResourceDict;
644 std::list< StreamRedirect > m_aOutputStreams;
646 // graphics state
647 struct GraphicsState
649 Font m_aFont;
650 MapMode m_aMapMode;
651 Color m_aLineColor;
652 Color m_aFillColor;
653 Color m_aTextLineColor;
654 Color m_aOverlineColor;
655 Region m_aClipRegion;
656 sal_Int32 m_nAntiAlias;
657 sal_Int32 m_nLayoutMode;
658 LanguageType m_aDigitLanguage;
659 sal_Int32 m_nTransparentPercent;
660 sal_uInt16 m_nFlags;
661 sal_uInt16 m_nUpdateFlags;
663 static const sal_uInt16 updateFont = 0x0001;
664 static const sal_uInt16 updateMapMode = 0x0002;
665 static const sal_uInt16 updateLineColor = 0x0004;
666 static const sal_uInt16 updateFillColor = 0x0008;
667 static const sal_uInt16 updateTextLineColor = 0x0010;
668 static const sal_uInt16 updateOverlineColor = 0x0020;
669 static const sal_uInt16 updateClipRegion = 0x0040;
670 static const sal_uInt16 updateAntiAlias = 0x0080;
671 static const sal_uInt16 updateLayoutMode = 0x0100;
672 static const sal_uInt16 updateTransparentPercent = 0x0200;
673 static const sal_uInt16 updateDigitLanguage = 0x0400;
675 GraphicsState() :
676 m_aLineColor( COL_TRANSPARENT ),
677 m_aFillColor( COL_TRANSPARENT ),
678 m_aTextLineColor( COL_TRANSPARENT ),
679 m_aOverlineColor( COL_TRANSPARENT ),
680 m_nAntiAlias( 1 ),
681 m_nLayoutMode( 0 ),
682 m_nTransparentPercent( 0 ),
683 m_nFlags( 0xffff ),
684 m_nUpdateFlags( 0xffff )
686 GraphicsState( const GraphicsState& rState ) :
687 m_aFont( rState.m_aFont ),
688 m_aMapMode( rState.m_aMapMode ),
689 m_aLineColor( rState.m_aLineColor ),
690 m_aFillColor( rState.m_aFillColor ),
691 m_aTextLineColor( rState.m_aTextLineColor ),
692 m_aOverlineColor( rState.m_aOverlineColor ),
693 m_aClipRegion( rState.m_aClipRegion ),
694 m_nAntiAlias( rState.m_nAntiAlias ),
695 m_nLayoutMode( rState.m_nLayoutMode ),
696 m_nTransparentPercent( rState.m_nTransparentPercent ),
697 m_nFlags( rState.m_nFlags ),
698 m_nUpdateFlags( rState.m_nUpdateFlags )
702 GraphicsState& operator=(const GraphicsState& rState )
704 m_aFont = rState.m_aFont;
705 m_aMapMode = rState.m_aMapMode;
706 m_aLineColor = rState.m_aLineColor;
707 m_aFillColor = rState.m_aFillColor;
708 m_aTextLineColor = rState.m_aTextLineColor;
709 m_aOverlineColor = rState.m_aOverlineColor;
710 m_aClipRegion = rState.m_aClipRegion;
711 m_nAntiAlias = rState.m_nAntiAlias;
712 m_nLayoutMode = rState.m_nLayoutMode;
713 m_nTransparentPercent = rState.m_nTransparentPercent;
714 m_nFlags = rState.m_nFlags;
715 m_nUpdateFlags = rState.m_nUpdateFlags;
716 return *this;
719 std::list< GraphicsState > m_aGraphicsStack;
720 GraphicsState m_aCurrentPDFState;
722 ZCodec* m_pCodec;
723 SvMemoryStream* m_pMemStream;
725 std::vector< PDFAddStream > m_aAdditionalStreams;
726 std::set< PDFWriter::ErrorCode > m_aErrors;
728 rtlDigest m_aDocDigest;
731 variables for PDF security
732 i12626
734 /* used to cipher the stream data and for password management */
735 rtlCipher m_aCipher;
736 rtlDigest m_aDigest;
737 /* pad string used for password in Standard security handler */
738 sal_uInt8 m_nPadString[ENCRYPTED_PWD_SIZE];
739 /* the owner password, in clear text */
740 rtl::OUString m_aOwnerPassword;
741 /* the padded owner password */
742 sal_uInt8 m_nPaddedOwnerPassword[ENCRYPTED_PWD_SIZE];
743 /* the encryption dictionary owner password, according to algorithm 3.3 */
744 sal_uInt8 m_nEncryptedOwnerPassword[ENCRYPTED_PWD_SIZE];
745 /* the user password, in clear text */
746 rtl::OUString m_aUserPassword;
747 /* the padded user password */
748 sal_uInt8 m_nPaddedUserPassword[ENCRYPTED_PWD_SIZE];
749 /* the encryption dictionary user password, according to algorithm 3.4 or 3.5 depending on the
750 security handler revision */
751 sal_uInt8 m_nEncryptedUserPassword[ENCRYPTED_PWD_SIZE];
753 /* the encryption key, formed with the user password according to algorithm 3.2, maximum length is 16 bytes + 3 + 2
754 for 128 bit security */
755 sal_uInt8 m_nEncryptionKey[MAXIMUM_RC4_KEY_LENGTH];
756 sal_Int32 m_nKeyLength; // key length, 16 or 5
757 sal_Int32 m_nRC4KeyLength; // key length, 16 or 10, to be input to the algorith 3.1
759 /* set to true if the following stream must be encrypted, used inside writeBuffer() */
760 sal_Bool m_bEncryptThisStream;
762 /* the numerical value of the access permissions, according to PDF spec, must be signed */
763 sal_Int32 m_nAccessPermissions;
764 /* the document ID, the raw MD5 hash */
765 sal_uInt8 m_nDocID[MD5_DIGEST_SIZE];
766 /* string buffer to hold document ID, this is the output string */
767 rtl::OStringBuffer m_aDocID;
768 /* string to hold the PDF creation date */
769 rtl::OStringBuffer m_aCreationDateString;
770 /* string to hold the PDF creation date, for PDF/A metadata */
771 rtl::OStringBuffer m_aCreationMetaDateString;
772 /* the buffer where the data are encrypted, dynamically allocated */
773 sal_uInt8 *m_pEncryptionBuffer;
774 /* size of the buffer */
775 sal_Int32 m_nEncryptionBufferSize;
777 /* check and reallocate the buffer for encryption */
778 sal_Bool checkEncryptionBufferSize( register sal_Int32 newSize )
780 if( m_nEncryptionBufferSize < newSize )
782 /* reallocate the buffer, the used function allocate as rtl_allocateMemory
783 if the pointer parameter is NULL */
784 m_pEncryptionBuffer = (sal_uInt8*)rtl_reallocateMemory( m_pEncryptionBuffer, newSize );
785 if( m_pEncryptionBuffer )
786 m_nEncryptionBufferSize = newSize;
787 else
788 m_nEncryptionBufferSize = 0;
790 return ( m_nEncryptionBufferSize != 0 );
792 /* init the internal pad string */
793 void initPadString()
795 static const sal_uInt8 nPadString[32] =
797 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41, 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
798 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80, 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A
801 for(sal_uInt32 i = 0; i < sizeof( nPadString ); i++ )
802 m_nPadString[i] = nPadString[i];
805 /* initialize the encryption engine */
806 void initEncryption();
808 /* this function implements part of the PDF spec algorithm 3.1 in encryption, the rest (the actual encryption) is in PDFWriterImpl::writeBuffer */
809 void checkAndEnableStreamEncryption( register sal_Int32 nObject )
811 if( m_aContext.Encrypt )
813 m_bEncryptThisStream = true;
814 register sal_Int32 i = m_nKeyLength;
815 m_nEncryptionKey[i++] = (sal_uInt8)nObject;
816 m_nEncryptionKey[i++] = (sal_uInt8)( nObject >> 8 );
817 m_nEncryptionKey[i++] = (sal_uInt8)( nObject >> 16 );
818 //the other location of m_nEncryptionKey are already set to 0, our fixed generation number
819 // do the MD5 hash
820 sal_uInt8 nMD5Sum[ RTL_DIGEST_LENGTH_MD5 ];
821 // the i+2 to take into account the generation number, always zero
822 rtl_digest_MD5( &m_nEncryptionKey, i+2, nMD5Sum, sizeof(nMD5Sum) );
823 // initialize the RC4 with the key
824 // key legth: see algoritm 3.1, step 4: (N+5) max 16
825 rtl_cipher_initARCFOUR( m_aCipher, rtl_Cipher_DirectionEncode, nMD5Sum, m_nRC4KeyLength, NULL, 0 );
829 void disableStreamEncryption() { m_bEncryptThisStream = false; };
831 /* */
832 void enableStringEncryption( register sal_Int32 nObject )
834 register sal_Int32 i = m_nKeyLength;
835 m_nEncryptionKey[i++] = (sal_uInt8)nObject;
836 m_nEncryptionKey[i++] = (sal_uInt8)( nObject >> 8 );
837 m_nEncryptionKey[i++] = (sal_uInt8)( nObject >> 16 );
838 //the other location of m_nEncryptionKey are already set to 0, our fixed generation number
839 // do the MD5 hash
840 sal_uInt8 nMD5Sum[ RTL_DIGEST_LENGTH_MD5 ];
841 // the i+2 to take into account the generation number, always zero
842 rtl_digest_MD5( &m_nEncryptionKey, i+2, nMD5Sum, sizeof(nMD5Sum) );
843 // initialize the RC4 with the key
844 // key legth: see algoritm 3.1, step 4: (N+5) max 16
845 rtl_cipher_initARCFOUR( m_aCipher, rtl_Cipher_DirectionEncode, nMD5Sum, m_nRC4KeyLength, NULL, 0 );
848 // test if the encryption is active, if yes than encrypt the unicode string and add to the OStringBuffer parameter
849 void appendUnicodeTextStringEncrypt( const rtl::OUString& rInString, const sal_Int32 nInObjectNumber, rtl::OStringBuffer& rOutBuffer );
851 void appendLiteralStringEncrypt( const rtl::OUString& rInString, const sal_Int32 nInObjectNumber, rtl::OStringBuffer& rOutBuffer );
852 void appendLiteralStringEncrypt( const rtl::OString& rInString, const sal_Int32 nInObjectNumber, rtl::OStringBuffer& rOutBuffer );
853 void appendLiteralStringEncrypt( rtl::OStringBuffer& rInString, const sal_Int32 nInObjectNumber, rtl::OStringBuffer& rOutBuffer );
855 /* creates fonts and subsets that will be emitted later */
856 void registerGlyphs( int nGlyphs, sal_GlyphId* pGlyphs, sal_Int32* pGlpyhWidths, sal_Ucs* pUnicodes, sal_uInt8* pMappedGlyphs, sal_Int32* pMappedFontObjects, const ImplFontData* pFallbackFonts[] );
858 /* emits a text object according to the passed layout */
859 /* TODO: remove rText as soon as SalLayout will change so that rText is not necessary anymore */
860 void drawVerticalGlyphs( const std::vector<PDFGlyph>& rGlyphs, rtl::OStringBuffer& rLine, const Point& rAlignOffset, const Matrix3& rRotScale, double fAngle, double fXScale, double fSkew, sal_Int32 nFontHeight );
861 void drawHorizontalGlyphs( const std::vector<PDFGlyph>& rGlyphs, rtl::OStringBuffer& rLine, const Point& rAlignOffset, double fAngle, double fXScale, double fSkew, sal_Int32 nFontHeight, sal_Int32 nPixelFontHeight );
862 void drawLayout( SalLayout& rLayout, const String& rText, bool bTextLines );
863 void drawRelief( SalLayout& rLayout, const String& rText, bool bTextLines );
864 void drawShadow( SalLayout& rLayout, const String& rText, bool bTextLines );
866 /* writes differences between graphics stack and current real PDF
867 * state to the file
869 void updateGraphicsState();
871 /* writes a transparency group object */
872 bool writeTransparentObject( TransparencyEmit& rObject );
874 /* writes an XObject of type image, may create
875 a second for the mask
877 bool writeBitmapObject( BitmapEmit& rObject, bool bMask = false );
879 bool writeJPG( JPGEmit& rEmit );
881 /* tries to find the bitmap by its id and returns its emit data if exists,
882 else creates a new emit data block */
883 const BitmapEmit& createBitmapEmit( const BitmapEx& rBitmapEx, bool bDrawMask = false );
885 /* writes the Do operation inside the content stream */
886 void drawBitmap( const Point& rDestPt, const Size& rDestSize, const BitmapEmit& rBitmap, const Color& rFillColor );
887 /* write the function object for a Gradient */
888 bool writeGradientFunction( GradientEmit& rObject );
889 /* creates a GradientEmit and returns its object number */
890 sal_Int32 createGradient( const Gradient& rGradient, const Size& rSize );
892 /* writes all tilings */
893 bool emitTilings();
894 /* writes all gradient patterns */
895 bool emitGradients();
896 /* writes a builtin font object and returns its objectid (or 0 in case of failure ) */
897 sal_Int32 emitBuiltinFont( const ImplFontData*, sal_Int32 nObject = -1 );
898 /* writes a type1 embedded font object and returns its mapping from font ids to object ids (or 0 in case of failure ) */
899 std::map< sal_Int32, sal_Int32 > emitEmbeddedFont( const ImplFontData*, EmbedFont& );
900 /* writes a font descriptor and returns its object id (or 0) */
901 sal_Int32 emitFontDescriptor( const ImplFontData*, FontSubsetInfo&, sal_Int32 nSubsetID, sal_Int32 nStream );
902 /* writes a ToUnicode cmap, returns the corresponding stream object */
903 sal_Int32 createToUnicodeCMap( sal_uInt8* pEncoding, sal_Ucs* pUnicodes, int nGlyphs );
905 /* get resource dict object number */
906 sal_Int32 getResourceDictObj()
908 if( m_nResourceDict <= 0 )
909 m_nResourceDict = createObject();
910 return m_nResourceDict;
912 /* get the font dict object */
913 sal_Int32 getFontDictObject()
915 if( m_nFontDictObject <= 0 )
916 m_nFontDictObject = createObject();
917 return m_nFontDictObject;
919 /* push resource into current (redirected) resource dict */
920 void pushResource( ResourceKind eKind, const rtl::OString& rResource, sal_Int32 nObject );
922 void appendBuiltinFontsToDict( rtl::OStringBuffer& rDict ) const;
923 /* writes a the font dictionary and emits all font objects
924 * returns object id of font directory (or 0 on error)
926 bool emitFonts();
927 /* writes the Resource dictionary;
928 * returns dict object id (or 0 on error)
930 sal_Int32 emitResources();
931 // appends a dest
932 bool appendDest( sal_Int32 nDestID, rtl::OStringBuffer& rBuffer );
933 // write all links
934 bool emitLinkAnnotations();
935 // write all notes
936 bool emitNoteAnnotations();
937 // write the appearance streams of a widget
938 bool emitAppearances( PDFWidget& rWidget, rtl::OStringBuffer& rAnnotDict );
939 // clean up radio button "On" values
940 void ensureUniqueRadioOnValues();
941 // write all widgets
942 bool emitWidgetAnnotations();
943 // writes all annotation objects
944 bool emitAnnotations();
945 // writes the dest dict for the catalog
946 sal_Int32 emitDestDict();
947 //write the named destination stuff
948 sal_Int32 emitNamedDestinations();//i56629
949 // writes outline dict and tree
950 sal_Int32 emitOutline();
951 // puts the attribute objects of a structure element into the returned string,
952 // helper for emitStructure
953 rtl::OString emitStructureAttributes( PDFStructureElement& rEle );
954 //--->i94258
955 // the maximum array elements allowed for PDF array object
956 static const sal_uInt32 ncMaxPDFArraySize = 8191;
957 //check if internal dummy container are needed in the structure elements
958 void addInternalStructureContainer( PDFStructureElement& rEle );
959 //<---i94258
960 // writes document structure
961 sal_Int32 emitStructure( PDFStructureElement& rEle );
962 // writes structure parent tree
963 sal_Int32 emitStructParentTree( sal_Int32 nTreeObject );
964 // writes page tree and catalog
965 bool emitCatalog();
966 // writes xref and trailer
967 bool emitTrailer();
968 // emit additional streams collected; also create there object numbers
969 bool emitAdditionalStreams();
970 // emits info dict (if applicable)
971 sal_Int32 emitInfoDict( );
973 // acrobat reader 5 and 6 use the order of the annotations
974 // as their tab order; since PDF1.5 one can make the
975 // tab order explicit by using the structure tree
976 void sortWidgets();
978 // updates the count numbers of outline items
979 sal_Int32 updateOutlineItemCount( std::vector< sal_Int32 >& rCounts,
980 sal_Int32 nItemLevel,
981 sal_Int32 nCurrentItemId );
982 // default appearences for widgets
983 sal_Int32 findRadioGroupWidget( const PDFWriter::RadioButtonWidget& rRadio );
984 Font replaceFont( const Font& rControlFont, const Font& rAppSetFont );
985 sal_Int32 getBestBuiltinFont( const Font& rFont );
987 // used for edit and listbox
988 Font drawFieldBorder( PDFWidget&, const PDFWriter::AnyWidget&, const StyleSettings& );
990 void createDefaultPushButtonAppearance( PDFWidget&, const PDFWriter::PushButtonWidget& rWidget );
991 void createDefaultCheckBoxAppearance( PDFWidget&, const PDFWriter::CheckBoxWidget& rWidget );
992 void createDefaultRadioButtonAppearance( PDFWidget&, const PDFWriter::RadioButtonWidget& rWidget );
993 void createDefaultEditAppearance( PDFWidget&, const PDFWriter::EditWidget& rWidget );
994 void createDefaultListBoxAppearance( PDFWidget&, const PDFWriter::ListBoxWidget& rWidget );
996 /* ensure proper escapement and uniqueness of field names */
997 rtl::OString convertWidgetFieldName( const rtl::OUString& rString );
998 /* adds an entry to m_aObjects and returns its index+1,
999 * sets the offset to ~0
1001 sal_Int32 createObject();
1002 /* sets the offset of object n to the current position of output file+1
1004 bool updateObject( sal_Int32 n );
1006 bool writeBuffer( const void* pBuffer, sal_uInt64 nBytes );
1007 void beginCompression();
1008 void endCompression();
1009 void beginRedirect( SvStream* pStream, const Rectangle& );
1010 // returns an empty rect if no redirection is happending
1011 Rectangle getRedirectTargetRect() const;
1012 SvStream* endRedirect();
1014 void endPage();
1016 void beginStructureElementMCSeq();
1017 void endStructureElementMCSeq();
1018 /** checks whether a non struct element lies in the ancestor hierarchy
1019 of the current structure element
1021 @returns
1022 <true/> if no NonStructElement was found in ancestor path and tagged
1023 PDF output is enabled
1024 <false/> else
1026 bool checkEmitStructure();
1028 /* draws an emphasis mark */
1029 void drawEmphasisMark( long nX, long nY, const PolyPolygon& rPolyPoly, BOOL bPolyLine, const Rectangle& rRect1, const Rectangle& rRect2 );
1031 /* true if PDF/A-1a or PDF/A-1b is output */
1032 sal_Bool m_bIsPDF_A1;
1035 i12626
1036 methods for PDF security
1038 pad a password according algorithm 3.2, step 1 */
1039 void padPassword( const rtl::OUString aPassword, sal_uInt8 *paPasswordTarget );
1040 /* algorithm 3.2: compute an encryption key */
1041 void computeEncryptionKey( sal_uInt8 *paThePaddedPassword, sal_uInt8 *paEncryptionKey );
1042 /* algorithm 3.3: computing the encryption dictionary'ss owner password value ( /O ) */
1043 void computeODictionaryValue();
1044 /* algorithm 3.4 or 3.5: computing the encryption dictionary's user password value ( /U ) revision 2 or 3 of the standard security handler */
1045 void computeUDictionaryValue();
1047 public:
1048 PDFWriterImpl( const PDFWriter::PDFWriterContext& rContext );
1049 ~PDFWriterImpl();
1051 /* for OutputDevice so the reference device can have a list
1052 * that contains only suitable fonts (subsettable or builtin)
1053 * produces a new font list
1055 ImplDevFontList* filterDevFontList( ImplDevFontList* pFontList );
1056 /* for OutputDevice: get layout for builtin fonts
1058 bool isBuiltinFont( const ImplFontData* ) const;
1059 SalLayout* GetTextLayout( ImplLayoutArgs& rArgs, ImplFontSelectData* pFont );
1060 void getFontMetric( ImplFontSelectData* pFont, ImplFontMetricData* pMetric ) const;
1063 /* for documentation of public functions please see pdfwriter.hxx */
1065 OutputDevice* getReferenceDevice();
1067 /* document structure */
1068 sal_Int32 newPage( sal_Int32 nPageWidth , sal_Int32 nPageHeight, PDFWriter::Orientation eOrientation );
1069 bool emit();
1070 std::set< PDFWriter::ErrorCode > getErrors();
1071 void insertError( PDFWriter::ErrorCode eErr ) { m_aErrors.insert( eErr ); }
1073 Size getCurPageSize() const
1075 Size aSize;
1076 if( m_nCurrentPage >= 0 && m_nCurrentPage < (sal_Int32)m_aPages.size() )
1077 aSize = Size( m_aPages[ m_nCurrentPage ].m_nPageWidth, m_aPages[ m_nCurrentPage ].m_nPageHeight );
1078 return aSize;
1081 PDFWriter::PDFVersion getVersion() const { return m_aContext.Version; }
1082 void setDocInfo( const PDFDocInfo& rInfo );
1083 const PDFDocInfo& getDocInfo() const { return m_aDocInfo; }
1085 void setDocumentLocale( const com::sun::star::lang::Locale& rLoc )
1086 { m_aContext.DocumentLocale = rLoc; }
1089 /* graphics state */
1090 void push( sal_uInt16 nFlags );
1091 void pop();
1093 void setFont( const Font& rFont );
1095 void setMapMode( const MapMode& rMapMode );
1096 void setMapMode() { setMapMode( m_aMapMode ); }
1099 const MapMode& getMapMode() { return m_aGraphicsStack.front().m_aMapMode; }
1101 void setLineColor( const Color& rColor )
1103 m_aGraphicsStack.front().m_aLineColor = ImplIsColorTransparent(rColor) ? Color( COL_TRANSPARENT ) : rColor;
1104 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateLineColor;
1107 void setFillColor( const Color& rColor )
1109 m_aGraphicsStack.front().m_aFillColor = ImplIsColorTransparent(rColor) ? Color( COL_TRANSPARENT ) : rColor;
1110 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateFillColor;
1113 void setTextLineColor()
1115 m_aGraphicsStack.front().m_aTextLineColor = Color( COL_TRANSPARENT );
1116 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateTextLineColor;
1119 void setTextLineColor( const Color& rColor )
1121 m_aGraphicsStack.front().m_aTextLineColor = rColor;
1122 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateTextLineColor;
1125 void setOverlineColor()
1127 m_aGraphicsStack.front().m_aOverlineColor = Color( COL_TRANSPARENT );
1128 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateOverlineColor;
1131 void setOverlineColor( const Color& rColor )
1133 m_aGraphicsStack.front().m_aOverlineColor = rColor;
1134 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateOverlineColor;
1137 void setTextFillColor( const Color& rColor )
1139 m_aGraphicsStack.front().m_aFont.SetFillColor( rColor );
1140 m_aGraphicsStack.front().m_aFont.SetTransparent( ImplIsColorTransparent( rColor ) ? TRUE : FALSE );
1141 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateFont;
1143 void setTextFillColor()
1145 m_aGraphicsStack.front().m_aFont.SetFillColor( Color( COL_TRANSPARENT ) );
1146 m_aGraphicsStack.front().m_aFont.SetTransparent( TRUE );
1147 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateFont;
1149 void setTextColor( const Color& rColor )
1151 m_aGraphicsStack.front().m_aFont.SetColor( rColor );
1152 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateFont;
1155 void clearClipRegion()
1157 m_aGraphicsStack.front().m_aClipRegion.SetNull();
1158 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateClipRegion;
1161 void setClipRegion( const Region& rRegion );
1163 void moveClipRegion( sal_Int32 nX, sal_Int32 nY );
1165 bool intersectClipRegion( const Rectangle& rRect );
1167 bool intersectClipRegion( const Region& rRegion );
1169 void setLayoutMode( sal_Int32 nLayoutMode )
1171 m_aGraphicsStack.front().m_nLayoutMode = nLayoutMode;
1172 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateLayoutMode;
1175 void setDigitLanguage( LanguageType eLang )
1177 m_aGraphicsStack.front().m_aDigitLanguage = eLang;
1178 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateDigitLanguage;
1181 void setTextAlign( TextAlign eAlign )
1183 m_aGraphicsStack.front().m_aFont.SetAlign( eAlign );
1184 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateFont;
1187 void setAntiAlias( sal_Int32 nAntiAlias )
1189 m_aGraphicsStack.front().m_nAntiAlias = nAntiAlias;
1190 m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateAntiAlias;
1193 /* actual drawing functions */
1194 void drawText( const Point& rPos, const String& rText, xub_StrLen nIndex = 0, xub_StrLen nLen = STRING_LEN, bool bTextLines = true );
1195 void drawTextArray( const Point& rPos, const String& rText, const sal_Int32* pDXArray = NULL, xub_StrLen nIndex = 0, xub_StrLen nLen = STRING_LEN, bool bTextLines = true );
1196 void drawStretchText( const Point& rPos, ULONG nWidth, const String& rText,
1197 xub_StrLen nIndex = 0, xub_StrLen nLen = STRING_LEN,
1198 bool bTextLines = true );
1199 void drawText( const Rectangle& rRect, const String& rOrigStr, USHORT nStyle, bool bTextLines = true );
1200 void drawTextLine( const Point& rPos, long nWidth, FontStrikeout eStrikeout, FontUnderline eUnderline, FontUnderline eOverline, bool bUnderlineAbove );
1201 void drawWaveTextLine( rtl::OStringBuffer& aLine, long nWidth, FontUnderline eTextLine, Color aColor, bool bIsAbove );
1202 void drawStraightTextLine( rtl::OStringBuffer& aLine, long nWidth, FontUnderline eTextLine, Color aColor, bool bIsAbove );
1203 void drawStrikeoutLine( rtl::OStringBuffer& aLine, long nWidth, FontStrikeout eStrikeout, Color aColor );
1204 void drawStrikeoutChar( const Point& rPos, long nWidth, FontStrikeout eStrikeout );
1206 void drawLine( const Point& rStart, const Point& rStop );
1207 void drawLine( const Point& rStart, const Point& rStop, const LineInfo& rInfo );
1208 void drawPolygon( const Polygon& rPoly );
1209 void drawPolyPolygon( const PolyPolygon& rPolyPoly );
1210 void drawPolyLine( const Polygon& rPoly );
1211 void drawPolyLine( const Polygon& rPoly, const LineInfo& rInfo );
1212 void drawPolyLine( const Polygon& rPoly, const PDFWriter::ExtLineInfo& rInfo );
1213 void drawWaveLine( const Point& rStart, const Point& rStop, sal_Int32 nDelta, sal_Int32 nLineWidth );
1215 void drawPixel( const Point& rPt, const Color& rColor );
1216 void drawPixel( const Polygon& rPts, const Color* pColors = NULL );
1218 void drawRectangle( const Rectangle& rRect );
1219 void drawRectangle( const Rectangle& rRect, sal_uInt32 nHorzRound, sal_uInt32 nVertRound );
1220 void drawEllipse( const Rectangle& rRect );
1221 void drawArc( const Rectangle& rRect, const Point& rStart, const Point& rStop, bool bWithPie, bool bWidthChord );
1223 void drawBitmap( const Point& rDestPoint, const Size& rDestSize, const Bitmap& rBitmap );
1224 void drawBitmap( const Point& rDestPoint, const Size& rDestSize, const BitmapEx& rBitmap );
1225 void drawMask( const Point& rDestPoint, const Size& rDestSize, const Bitmap& rBitmap, const Color& rFillColor );
1226 void drawJPGBitmap( SvStream& rDCTData, bool bIsTrueColor, const Size& rSizePixel, const Rectangle& rTargetArea, const Bitmap& rMask );
1228 void drawGradient( const Rectangle& rRect, const Gradient& rGradient );
1229 void drawGradient( const PolyPolygon& rPolyPoly, const Gradient& rGradient );
1230 void drawHatch( const PolyPolygon& rPolyPoly, const Hatch& rHatch );
1231 void drawWallpaper( const Rectangle& rRect, const Wallpaper& rWall );
1232 void drawTransparent( const PolyPolygon& rPolyPoly, sal_uInt32 nTransparentPercent );
1233 void beginTransparencyGroup();
1234 void endTransparencyGroup( const Rectangle& rBoundingBox, sal_uInt32 nTransparentPercent );
1235 void endTransparencyGroup( const Rectangle& rBoundingBox, const Bitmap& rAlphaMask );
1236 void beginPattern( const Rectangle& rCell );
1237 sal_Int32 endPattern( const SvtGraphicFill::Transform& rTransform );
1238 void drawPolyPolygon( const PolyPolygon& rPolyPoly, sal_Int32 nPattern, bool bEOFill );
1240 void emitComment( const char* pComment );
1242 //--->i56629 named destinations
1243 sal_Int32 createNamedDest( const rtl::OUString& sDestName, const Rectangle& rRect, sal_Int32 nPageNr = -1, PDFWriter::DestAreaType eType = PDFWriter::XYZ );
1245 //--->i59651
1246 //emits output intent
1247 sal_Int32 emitOutputIntent();
1249 //emits the document metadata
1250 sal_Int32 emitDocumentMetadata();
1252 // links
1253 sal_Int32 createLink( const Rectangle& rRect, sal_Int32 nPageNr = -1 );
1254 sal_Int32 createDest( const Rectangle& rRect, sal_Int32 nPageNr = -1, PDFWriter::DestAreaType eType = PDFWriter::XYZ );
1255 sal_Int32 setLinkDest( sal_Int32 nLinkId, sal_Int32 nDestId );
1256 sal_Int32 setLinkURL( sal_Int32 nLinkId, const rtl::OUString& rURL );
1257 void setLinkPropertyId( sal_Int32 nLinkId, sal_Int32 nPropertyId );
1259 // outline
1260 sal_Int32 createOutlineItem( sal_Int32 nParent = 0, const rtl::OUString& rText = rtl::OUString(), sal_Int32 nDestID = -1 );
1261 sal_Int32 setOutlineItemParent( sal_Int32 nItem, sal_Int32 nNewParent );
1262 sal_Int32 setOutlineItemText( sal_Int32 nItem, const rtl::OUString& rText );
1263 sal_Int32 setOutlineItemDest( sal_Int32 nItem, sal_Int32 nDestID );
1265 // notes
1266 void createNote( const Rectangle& rRect, const PDFNote& rNote, sal_Int32 nPageNr = -1 );
1267 // structure elements
1268 sal_Int32 beginStructureElement( PDFWriter::StructElement eType, const rtl::OUString& rAlias );
1269 void endStructureElement();
1270 bool setCurrentStructureElement( sal_Int32 nElement );
1271 sal_Int32 getCurrentStructureElement();
1272 bool setStructureAttribute( enum PDFWriter::StructAttribute eAttr, enum PDFWriter::StructAttributeValue eVal );
1273 bool setStructureAttributeNumerical( enum PDFWriter::StructAttribute eAttr, sal_Int32 nValue );
1274 void setStructureBoundingBox( const Rectangle& rRect );
1275 void setActualText( const String& rText );
1276 void setAlternateText( const String& rText );
1278 // transitional effects
1279 void setAutoAdvanceTime( sal_uInt32 nSeconds, sal_Int32 nPageNr = -1 );
1280 void setPageTransition( PDFWriter::PageTransition eType, sal_uInt32 nMilliSec, sal_Int32 nPageNr = -1 );
1282 // controls
1283 sal_Int32 createControl( const PDFWriter::AnyWidget& rControl, sal_Int32 nPageNr = -1 );
1284 void beginControlAppearance( sal_Int32 nControl );
1285 bool endControlAppearance( PDFWriter::WidgetState eState );
1287 // additional streams
1288 void addStream( const String& rMimeType, PDFOutputStream* pStream, bool bCompress );
1290 // helper: eventually begin marked content sequence and
1291 // emit a comment in debug case
1292 void MARK( const char*
1293 #if OSL_DEBUG_LEVEL > 1
1294 pString
1295 #endif
1298 beginStructureElementMCSeq();
1299 #if OSL_DEBUG_LEVEL > 1
1300 emitComment( pString );
1301 #endif
1307 #endif //_VCL_PDFEXPORT_HXX