xref: /aoo41x/main/vcl/source/gdi/pdfwriter_impl.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 #ifndef _VCL_PDFWRITER_IMPL_HXX
28 #define _VCL_PDFWRITER_IMPL_HXX
29 
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 "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"
46 
47 #include <sallayout.hxx>
48 #include "pdffontcache.hxx"
49 
50 #include <vector>
51 #include <map>
52 #include <hash_map>
53 #include <list>
54 
55 #include <boost/shared_array.hpp>
56 
57 class ImplFontSelectData;
58 class ImplFontMetricData;
59 class FontSubsetInfo;
60 class ZCodec;
61 class EncHashTransporter;
62 struct BitStreamState;
63 
64 // the maximum password length
65 #define ENCRYPTED_PWD_SIZE     32
66 #define MD5_DIGEST_SIZE        16
67 #define SECUR_40BIT_KEY         5
68 // security 128 bit
69 #define SECUR_128BIT_KEY       16
70 // maximum length of MD5 digest input, in step 2 of algorithm 3.1
71 // PDF spec ver. 1.4: see there for details
72 #define MAXIMUM_RC4_KEY_LENGTH (SECUR_128BIT_KEY+3+2)
73 
74 namespace vcl
75 {
76 
77 class PDFSalLayout;
78 class PDFStreamIf;
79 class Matrix3;
80 
81 class PDFWriterImpl
82 {
83     friend class PDFSalLayout;
84     friend class PDFStreamIf;
85 public:
86     // definition of structs
87     struct BuiltinFont
88     {
89         const char *        		m_pName;                     // Name
90         const char *        		m_pStyleName;                // StyleName
91         const char *        		m_pPSName;					 // PSName
92         int							m_nAscent;
93         int							m_nDescent;
94         FontFamily					m_eFamily;                   // Family
95 		CharSet						m_eCharSet;                  // CharSet
96 	    FontPitch					m_ePitch;                    // Pitch
97 		FontWidth					m_eWidthType;                // WidthType
98 		FontWeight					m_eWeight;                   // Weight
99 		FontItalic					m_eItalic;                   // Italic
100         int							m_aWidths[256];				 // character metrics
101 
102         rtl::OString getNameObject() const;
103     };
104 
105 
106     enum ResourceKind { ResXObject, ResExtGState, ResShading, ResPattern };
107     typedef std::map< rtl::OString, sal_Int32 > ResourceMap;
108     struct ResourceDict
109     {
110         // note: handle fonts globally for performance
111         ResourceMap m_aXObjects;
112         ResourceMap m_aExtGStates;
113         ResourceMap m_aShadings;
114         ResourceMap m_aPatterns;
115 
116         void append( rtl::OStringBuffer&, sal_Int32 nFontDictObject );
117     };
118 
119     struct PDFPage
120     {
121         PDFWriterImpl*				m_pWriter;
122         sal_Int32					m_nPageWidth;			// in inch/72
123         sal_Int32					m_nPageHeight;			// in inch/72
124         PDFWriter::Orientation		m_eOrientation;
125         sal_Int32					m_nPageObject;
126         sal_Int32					m_nPageIndex;
127         std::vector<sal_Int32>		m_aStreamObjects;
128         sal_Int32					m_nStreamLengthObject;
129         sal_uInt64					m_nBeginStreamPos;
130         std::vector<sal_Int32>		m_aAnnotations;
131         std::vector<sal_Int32>		m_aMCIDParents;
132         PDFWriter::PageTransition	m_eTransition;
133         sal_uInt32					m_nTransTime;
134         sal_uInt32					m_nDuration;
135         bool                        m_bHasWidgets;
136 
137         PDFPage( PDFWriterImpl* pWriter, sal_Int32 nPageWidth, sal_Int32 nPageHeight, PDFWriter::Orientation eOrientation );
138         ~PDFPage();
139 
140         void beginStream();
141         void endStream();
142         bool emit( sal_Int32 nParentPage );
143 
144         // converts point from ref device coordinates to
145         // page coordinates and appends the point to the buffer
146         // if bNeg is true, the coordinates are inverted AFTER transformation
147         // to page (useful for transformation matrices
148         // if pOutPoint is set it will be updated to the emitted point
149         // (in PDF map mode, that is 10th of point)
150         void appendPoint( const Point& rPoint, rtl::OStringBuffer& rBuffer, bool bNeg = false, Point* pOutPoint = NULL ) const;
151         // appends a B2DPoint without further transformation
152         void appendPixelPoint( const basegfx::B2DPoint& rPoint, rtl::OStringBuffer& rBuffer ) const;
153         // appends a rectangle
154         void appendRect( const Rectangle& rRect, rtl::OStringBuffer& rBuffer ) const;
155         // converts a rectangle to 10th points page space
156         void convertRect( Rectangle& rRect ) const;
157         // appends a polygon optionally closing it
158         void appendPolygon( const Polygon& rPoly, rtl::OStringBuffer& rBuffer, bool bClose = true ) const;
159         // appends a polygon optionally closing it
160         void appendPolygon( const basegfx::B2DPolygon& rPoly, rtl::OStringBuffer& rBuffer, bool bClose = true ) const;
161         // appends a polypolygon optionally closing the subpaths
162         void appendPolyPolygon( const PolyPolygon& rPolyPoly, rtl::OStringBuffer& rBuffer, bool bClose = true ) const;
163         // appends a polypolygon optionally closing the subpaths
164         void appendPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPoly, rtl::OStringBuffer& rBuffer, bool bClose = true ) const;
165         // converts a length (either vertical or horizontal; this
166         // can be important if the source MapMode is not
167         // symmetrical) to page length and appends it to the buffer
168         // if pOutLength is set it will be updated to the emitted length
169         // (in PDF map mode, that is 10th of point)
170         void appendMappedLength( sal_Int32 nLength, rtl::OStringBuffer& rBuffer, bool bVertical = true, sal_Int32* pOutLength = NULL ) const;
171         // the same for double values
172         void appendMappedLength( double fLength, rtl::OStringBuffer& rBuffer, bool bVertical = true, sal_Int32* pOutLength = NULL, sal_Int32 nPrecision = 5 ) const;
173         // appends LineInfo
174         // returns false if too many dash array entry were created for
175         // the implementation limits of some PDF readers
176         bool appendLineInfo( const LineInfo& rInfo, rtl::OStringBuffer& rBuffer ) const;
177         // appends a horizontal waveline with vertical offset (helper for drawWaveLine)
178         void appendWaveLine( sal_Int32 nLength, sal_Int32 nYOffset, sal_Int32 nDelta, rtl::OStringBuffer& rBuffer ) const;
179 
180         sal_Int32 getWidth() const { return m_nPageWidth ? m_nPageWidth : m_pWriter->m_nInheritedPageWidth; }
181         sal_Int32 getHeight() const { return m_nPageHeight ? m_nPageHeight : m_pWriter->m_nInheritedPageHeight; }
182     };
183 
184     friend struct PDFPage;
185 
186     struct BitmapID
187     {
188         Size		m_aPixelSize;
189         sal_Int32	m_nSize;
190         sal_Int32	m_nChecksum;
191         sal_Int32	m_nMaskChecksum;
192 
193         BitmapID() : m_nSize( 0 ), m_nChecksum( 0 ), m_nMaskChecksum( 0 ) {}
194 
195         BitmapID& operator=( const BitmapID& rCopy )
196         {
197             m_aPixelSize	= rCopy.m_aPixelSize;
198             m_nSize			= rCopy.m_nSize;
199             m_nChecksum		= rCopy.m_nChecksum;
200             m_nMaskChecksum	= rCopy.m_nMaskChecksum;
201             return *this;
202         }
203 
204         bool operator==( const BitmapID& rComp )
205         {
206             return (m_aPixelSize == rComp.m_aPixelSize &&
207                     m_nSize == rComp.m_nSize &&
208                     m_nChecksum == rComp.m_nChecksum &&
209                     m_nMaskChecksum == rComp.m_nMaskChecksum );
210         }
211     };
212 
213     struct BitmapEmit
214     {
215         BitmapID	m_aID;
216         BitmapEx	m_aBitmap;
217         sal_Int32	m_nObject;
218         bool		m_bDrawMask;
219 
220         BitmapEmit() : m_bDrawMask( false ) {}
221     };
222 
223     struct JPGEmit
224     {
225         BitmapID			m_aID;
226         SvMemoryStream*		m_pStream;
227         Bitmap				m_aMask;
228         sal_Int32			m_nObject;
229         bool                m_bTrueColor;
230 
231         JPGEmit() : m_pStream( NULL ) {}
232         ~JPGEmit() { delete m_pStream; }
233     };
234 
235     struct GradientEmit
236     {
237         Gradient	m_aGradient;
238         Size		m_aSize;
239         sal_Int32	m_nObject;
240     };
241 
242 	// for tilings (drawWallpaper, begin/endPattern)
243     struct TilingEmit
244     {
245         sal_Int32                   m_nObject;
246         Rectangle                   m_aRectangle;
247         Size                        m_aCellSize;
248         SvtGraphicFill::Transform   m_aTransform;
249         ResourceDict                m_aResources;
250         SvMemoryStream*             m_pTilingStream;
251 
252         TilingEmit()
253                 : m_nObject( 0 ),
254                   m_pTilingStream( NULL )
255         {}
256     };
257 
258     // for transparency group XObjects
259     struct TransparencyEmit
260     {
261         sal_Int32			m_nObject;
262         sal_Int32			m_nExtGStateObject;
263         double				m_fAlpha;
264         Rectangle			m_aBoundRect;
265         SvMemoryStream*		m_pContentStream;
266         SvMemoryStream*		m_pSoftMaskStream;
267 
268         TransparencyEmit()
269                 : m_nObject( 0 ),
270                   m_nExtGStateObject( -1 ),
271                   m_fAlpha( 0.0 ),
272                   m_pContentStream( NULL ),
273                   m_pSoftMaskStream( NULL )
274         {}
275         ~TransparencyEmit()
276         {
277             delete m_pContentStream;
278             delete m_pSoftMaskStream;
279         }
280     };
281 
282     // font subsets
283     class GlyphEmit
284     {
285         // performance: actually this should probably a vector;
286         sal_Ucs		                    m_aBufferedUnicodes[3];
287         sal_Int32                       m_nUnicodes;
288         sal_Int32                       m_nMaxUnicodes;
289         boost::shared_array<sal_Ucs>    m_pUnicodes;
290         sal_uInt8                       m_nSubsetGlyphID;
291 
292     public:
293         GlyphEmit() : m_nUnicodes(0), m_nSubsetGlyphID(0)
294         {
295             rtl_zeroMemory( m_aBufferedUnicodes, sizeof( m_aBufferedUnicodes ) );
296             m_nMaxUnicodes = sizeof(m_aBufferedUnicodes)/sizeof(m_aBufferedUnicodes[0]);
297         }
298         ~GlyphEmit()
299         {
300         }
301 
302         void setGlyphId( sal_uInt8 i_nId ) { m_nSubsetGlyphID = i_nId; }
303         sal_uInt8 getGlyphId() const { return m_nSubsetGlyphID; }
304 
305         void addCode( sal_Ucs i_cCode )
306         {
307             if( m_nUnicodes == m_nMaxUnicodes )
308             {
309                 sal_Ucs* pNew = new sal_Ucs[ 2 * m_nMaxUnicodes];
310                 if( m_pUnicodes.get() )
311                     rtl_copyMemory( pNew, m_pUnicodes.get(), m_nMaxUnicodes * sizeof(sal_Ucs) );
312                 else
313                     rtl_copyMemory( pNew, m_aBufferedUnicodes, m_nMaxUnicodes * sizeof(sal_Ucs) );
314                 m_pUnicodes.reset( pNew );
315                 m_nMaxUnicodes *= 2;
316             }
317             if( m_pUnicodes.get() )
318                 m_pUnicodes[ m_nUnicodes++ ] = i_cCode;
319             else
320                 m_aBufferedUnicodes[ m_nUnicodes++ ] = i_cCode;
321         }
322         sal_Int32 countCodes() const { return m_nUnicodes; }
323         sal_Ucs getCode( sal_Int32 i_nIndex ) const
324         {
325             sal_Ucs nRet = 0;
326             if( i_nIndex < m_nUnicodes )
327                 nRet = m_pUnicodes.get() ? m_pUnicodes[ i_nIndex ] : m_aBufferedUnicodes[ i_nIndex ];
328             return nRet;
329         }
330     };
331     typedef std::map< sal_GlyphId, GlyphEmit > FontEmitMapping;
332     struct FontEmit
333     {
334         sal_Int32			m_nFontID;
335         FontEmitMapping		m_aMapping;
336 
337         FontEmit( sal_Int32 nID ) : m_nFontID( nID ) {}
338     };
339     typedef std::list< FontEmit > FontEmitList;
340     struct Glyph
341     {
342         sal_Int32	m_nFontID;
343         sal_uInt8	m_nSubsetGlyphID;
344     };
345     typedef std::map< sal_GlyphId, Glyph > FontMapping;
346     struct FontSubset
347     {
348         FontEmitList		m_aSubsets;
349         FontMapping			m_aMapping;
350     };
351     typedef std::map< const ImplFontData*, FontSubset > FontSubsetData;
352     struct EmbedCode
353     {
354         sal_Ucs				m_aUnicode;
355         rtl::OString		m_aName;
356     };
357     struct EmbedEncoding
358     {
359         sal_Int32						m_nFontID;
360         std::vector< EmbedCode >		m_aEncVector;
361         std::map< sal_Ucs, sal_Int8 >	m_aCMap;
362     };
363     struct EmbedFont
364     {
365         sal_Int32						m_nNormalFontID;
366         std::list< EmbedEncoding >		m_aExtendedEncodings;
367 
368         EmbedFont() : m_nNormalFontID( 0 ) {}
369     };
370     typedef std::map< const ImplFontData*, EmbedFont > FontEmbedData;
371 
372     struct PDFDest
373     {
374         sal_Int32					m_nPage;
375         PDFWriter::DestAreaType		m_eType;
376         Rectangle					m_aRect;
377     };
378 
379 //--->i56629
380     struct PDFNamedDest
381     {
382         rtl::OUString               m_aDestName;
383         sal_Int32					m_nPage;
384         PDFWriter::DestAreaType		m_eType;
385         Rectangle					m_aRect;
386     };
387 //<---
388 
389     struct PDFOutlineEntry
390     {
391         sal_Int32					m_nParentID;
392         sal_Int32					m_nObject;
393         sal_Int32					m_nParentObject;
394         sal_Int32					m_nNextObject;
395         sal_Int32					m_nPrevObject;
396         std::vector< sal_Int32 >	m_aChildren;
397         rtl::OUString				m_aTitle;
398         sal_Int32					m_nDestID;
399 
400         PDFOutlineEntry()
401                 : m_nParentID( -1 ),
402                   m_nObject( 0 ),
403                   m_nParentObject( 0 ),
404                   m_nNextObject( 0 ),
405                   m_nPrevObject( 0 ),
406                   m_nDestID( -1 )
407         {}
408     };
409 
410     struct PDFAnnotation
411     {
412         sal_Int32					m_nObject;
413         Rectangle					m_aRect;
414         sal_Int32					m_nPage;
415 
416         PDFAnnotation()
417                 : m_nObject( -1 ),
418                   m_nPage( -1 )
419         {}
420     };
421 
422     struct PDFLink : public PDFAnnotation
423     {
424         sal_Int32					m_nDest; // set to -1 for URL, to a dest else
425         rtl::OUString				m_aURL;
426         sal_Int32                   m_nStructParent; // struct parent entry
427 
428         PDFLink()
429                 : m_nDest( -1 ),
430                   m_nStructParent( -1 )
431         {}
432     };
433 
434     struct PDFNoteEntry : public PDFAnnotation
435     {
436         PDFNote						m_aContents;
437 
438         PDFNoteEntry()
439         {}
440     };
441 
442     typedef std::hash_map< rtl::OString, SvMemoryStream*, rtl::OStringHash > PDFAppearanceStreams;
443     typedef std::hash_map< rtl::OString, PDFAppearanceStreams, rtl::OStringHash > PDFAppearanceMap;
444 
445     struct PDFWidget : public PDFAnnotation
446     {
447         PDFWriter::WidgetType		m_eType;
448         rtl::OString				m_aName;
449         rtl::OUString				m_aDescription;
450         rtl::OUString				m_aText;
451         sal_uInt16						m_nTextStyle;
452         rtl::OUString				m_aValue;
453         rtl::OString                m_aDAString;
454         rtl::OString                m_aDRDict;
455         rtl::OString				m_aMKDict;
456 		rtl::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         rtl::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;
470         bool                        m_bSubmitGet;
471         sal_Int32                   m_nDest;
472         std::vector<rtl::OUString>	m_aListEntries;
473         std::vector<sal_Int32>      m_aSelectedEntries;
474         PDFAppearanceMap			m_aAppearances;
475         PDFWidget()
476                 : m_eType( PDFWriter::PushButton ),
477                   m_nTextStyle( 0 ),
478                   m_nFlags( 0 ),
479                   m_nParent( 0 ),
480                   m_nRadioGroup( -1 ),
481                   m_nMaxLen( 0 ),
482                   m_bSubmit( false ),
483                   m_bSubmitGet( false ),
484                   m_nDest( -1 )
485         {}
486     };
487 
488     struct PDFStructureAttribute
489     {
490         PDFWriter::StructAttributeValue		eValue;
491         sal_Int32							nValue;
492 
493         PDFStructureAttribute()
494                 : eValue( PDFWriter::Invalid ),
495                   nValue( 0 )
496         {}
497 
498         PDFStructureAttribute( PDFWriter::StructAttributeValue eVal )
499                 : eValue( eVal ),
500                   nValue( 0 )
501         {}
502 
503         PDFStructureAttribute( sal_Int32 nVal )
504                 : eValue( PDFWriter::Invalid ),
505                   nValue( nVal )
506         {}
507     };
508 
509     typedef std::map<PDFWriter::StructAttribute, PDFStructureAttribute > PDFStructAttributes;
510 
511     struct PDFStructureElementKid // for Kids entries
512     {
513         sal_Int32 nObject;  // an object number if nMCID is -1,
514                             // else the page object relevant to MCID
515         sal_Int32 nMCID;    // an MCID if >= 0
516 
517         PDFStructureElementKid( sal_Int32 nObj ) : nObject( nObj ), nMCID( -1 ) {}
518         PDFStructureElementKid( sal_Int32 MCID, sal_Int32 nPage ) : nObject( nPage ), nMCID( MCID ) {}
519     };
520 
521     struct PDFStructureElement
522     {
523         sal_Int32											m_nObject;
524         PDFWriter::StructElement							m_eType;
525         rtl::OString                                        m_aAlias;
526         sal_Int32											m_nOwnElement; // index into structure vector
527         sal_Int32											m_nParentElement; // index into structure vector
528         sal_Int32											m_nFirstPageObject;
529         bool												m_bOpenMCSeq;
530         std::list< sal_Int32 >								m_aChildren; // indexes into structure vector
531         std::list< PDFStructureElementKid >                 m_aKids;
532         PDFStructAttributes									m_aAttributes;
533         Rectangle											m_aBBox;
534         rtl::OUString										m_aActualText;
535         rtl::OUString										m_aAltText;
536         com::sun::star::lang::Locale                        m_aLocale;
537 
538         // m_aContents contains the element's marked content sequence
539         // as pairs of (page nr, MCID)
540 
541         PDFStructureElement()
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 
553     struct PDFAddStream
554     {
555         rtl::OUString           m_aMimeType;
556         PDFOutputStream*        m_pStream;
557         sal_Int32               m_nStreamObject;
558         bool                    m_bCompress;
559 
560         PDFAddStream() : m_pStream( NULL ), m_nStreamObject( 0 ), m_bCompress( true ) {}
561     };
562 
563 
564     // helper structure for drawLayout and friends
565     struct PDFGlyph
566     {
567         Point       m_aPos;
568         sal_Int32   m_nNativeWidth;
569         sal_Int32   m_nGlyphId;
570         sal_Int32   m_nMappedFontId;
571         sal_uInt8   m_nMappedGlyphId;
572 
573         PDFGlyph( const Point& rPos,
574                   sal_Int32 nNativeWidth,
575                   sal_Int32 nGlyphId,
576                   sal_Int32 nFontId,
577                   sal_uInt8 nMappedGlyphId )
578         : m_aPos( rPos ), m_nNativeWidth( nNativeWidth ), m_nGlyphId( nGlyphId ),
579           m_nMappedFontId( nFontId ), m_nMappedGlyphId( nMappedGlyphId )
580         {}
581     };
582 
583 
584     static const sal_Char* getStructureTag( PDFWriter::StructElement );
585     static const sal_Char* getAttributeTag( PDFWriter::StructAttribute eAtr );
586     static const sal_Char* getAttributeValueTag( PDFWriter::StructAttributeValue eVal );
587 
588     // returns true if compression was done
589     // else false
590     static bool compressStream( SvMemoryStream* );
591 
592     static void convertLineInfoToExtLineInfo( const LineInfo& rIn, PDFWriter::ExtLineInfo& rOut );
593 private:
594     static const BuiltinFont m_aBuiltinFonts[14];
595 
596     OutputDevice*						m_pReferenceDevice;
597 
598     MapMode								m_aMapMode; // PDFWriterImpl scaled units
599     std::vector< PDFPage >				m_aPages;
600     /* maps object numbers to file offsets (needed for xref) */
601     std::vector< sal_uInt64 >			m_aObjects;
602     /* contains Bitmaps until they are written to the
603      *  file stream as XObjects*/
604     std::list< BitmapEmit >				m_aBitmaps;
605     /* contains JPG streams until written to file     */
606     std::list<JPGEmit>					m_aJPGs;
607     /*--->i56629 contains all named destinations ever set during the PDF creation,
608        destination id is always the destination's position in this vector
609      */
610     std::vector<PDFNamedDest>		    m_aNamedDests;
611     //<---
612     /* contains all dests ever set during the PDF creation,
613        dest id is always the dest's position in this vector
614      */
615     std::vector<PDFDest>				m_aDests;
616     /** contains destinations accessible via a public Id, instead of being linked to by an ordinary link
617     */
618     ::std::map< sal_Int32, sal_Int32 >  m_aDestinationIdTranslation;
619     /* contains all links ever set during PDF creation,
620        link id is always the link's position in this vector
621     */
622     std::vector<PDFLink>				m_aLinks;
623     /* makes correctly encoded for export to PDF URLS
624     */
625     com::sun::star::uno::Reference< com::sun::star::util::XURLTransformer > m_xTrans;
626     /* maps arbitrary link ids for structure attributes to real link ids
627        (for setLinkPropertyId)
628     */
629     std::map<sal_Int32, sal_Int32>		m_aLinkPropertyMap;
630     /* contains all outline items,
631        object 0 is the outline root
632      */
633     std::vector<PDFOutlineEntry>		m_aOutline;
634     /* contains all notes set during PDF creation
635      */
636     std::vector<PDFNoteEntry>			m_aNotes;
637 	/* the root of the structure tree
638      */
639     std::vector<PDFStructureElement>	m_aStructure;
640     /* current object in the structure hierarchy
641      */
642     sal_Int32							m_nCurrentStructElement;
643     /* structure parent tree */
644     std::vector< rtl::OString >         m_aStructParentTree;
645     /* emit strucure marks currently (aka. NonStructElement or not)
646      */
647     bool								m_bEmitStructure;
648     bool								m_bNewMCID;
649     /* role map of struct tree root */
650     std::hash_map< rtl::OString, rtl::OString, rtl::OStringHash >
651                                         m_aRoleMap;
652 
653     /* contains all widgets used in the PDF
654      */
655     std::vector<PDFWidget>				m_aWidgets;
656     /* maps radio group id to index of radio group control in m_aWidgets */
657     std::map< sal_Int32, sal_Int32 >	m_aRadioGroupWidgets;
658     /* used to store control id during beginControlAppearance/endControlAppearance */
659     sal_Int32							m_nCurrentControl;
660     /* hash_map for field names, used to ensure unique field names */
661     std::hash_map< rtl::OString, sal_Int32, rtl::OStringHash > m_aFieldNameMap;
662 
663     /* contains Bitmaps for gradient functions until they are written
664      *  to the file stream */
665     std::list< GradientEmit >			m_aGradients;
666     /* contains bitmap tiling patterns */
667     std::vector< TilingEmit >		    m_aTilings;
668     std::list< TransparencyEmit >		m_aTransparentObjects;
669     /*  contains all font subsets in use */
670     FontSubsetData						m_aSubsets;
671     bool                                m_bEmbedStandardFonts;
672     FontEmbedData						m_aEmbeddedFonts;
673     FontEmbedData                       m_aSystemFonts;
674     sal_Int32							m_nNextFID;
675     PDFFontCache                        m_aFontCache;
676 
677     sal_Int32							m_nInheritedPageWidth;  // in inch/72
678     sal_Int32							m_nInheritedPageHeight; // in inch/72
679     PDFWriter::Orientation				m_eInheritedOrientation;
680     sal_Int32							m_nCurrentPage;
681 
682     sal_Int32							m_nCatalogObject;
683     sal_Int32							m_nResourceDict;
684     ResourceDict                        m_aGlobalResourceDict;
685     sal_Int32                           m_nFontDictObject;
686     std::map< sal_Int32, sal_Int32 >    m_aBuiltinFontToObjectMap;
687 
688     PDFWriter::PDFWriterContext			m_aContext;
689     oslFileHandle						m_aFile;
690     bool								m_bOpen;
691 
692 
693     /* output redirection; e.g. to accumulate content streams for
694        XObjects
695      */
696     struct StreamRedirect
697     {
698         SvStream*		m_pStream;
699         MapMode   		m_aMapMode;
700         Rectangle       m_aTargetRect;
701         ResourceDict    m_aResourceDict;
702     };
703     std::list< StreamRedirect >			m_aOutputStreams;
704 
705     // graphics state
706     struct GraphicsState
707     {
708         Font			                 m_aFont;
709         MapMode			                 m_aMapMode;
710         Color			                 m_aLineColor;
711         Color			                 m_aFillColor;
712         Color			                 m_aTextLineColor;
713         Color			                 m_aOverlineColor;
714         basegfx::B2DPolyPolygon			 m_aClipRegion;
715         bool                             m_bClipRegion;
716         sal_Int32		                 m_nAntiAlias;
717         sal_Int32		                 m_nLayoutMode;
718         LanguageType                     m_aDigitLanguage;
719         sal_Int32		                 m_nTransparentPercent;
720         sal_uInt16		                 m_nFlags;
721         sal_uInt16                       m_nUpdateFlags;
722 
723         static const sal_uInt16 updateFont                  = 0x0001;
724         static const sal_uInt16 updateMapMode               = 0x0002;
725         static const sal_uInt16 updateLineColor             = 0x0004;
726         static const sal_uInt16 updateFillColor             = 0x0008;
727         static const sal_uInt16 updateTextLineColor         = 0x0010;
728         static const sal_uInt16 updateOverlineColor         = 0x0020;
729         static const sal_uInt16 updateClipRegion            = 0x0040;
730         static const sal_uInt16 updateAntiAlias             = 0x0080;
731         static const sal_uInt16 updateLayoutMode            = 0x0100;
732         static const sal_uInt16 updateTransparentPercent    = 0x0200;
733         static const sal_uInt16 updateDigitLanguage         = 0x0400;
734 
735         GraphicsState() :
736                 m_aLineColor( COL_TRANSPARENT ),
737                 m_aFillColor( COL_TRANSPARENT ),
738                 m_aTextLineColor( COL_TRANSPARENT ),
739                 m_aOverlineColor( COL_TRANSPARENT ),
740                 m_bClipRegion( false ),
741                 m_nAntiAlias( 1 ),
742                 m_nLayoutMode( 0 ),
743                 m_aDigitLanguage( 0 ),
744                 m_nTransparentPercent( 0 ),
745                 m_nFlags( 0xffff ),
746                 m_nUpdateFlags( 0xffff )
747         {}
748         GraphicsState( const GraphicsState& rState ) :
749                 m_aFont( rState.m_aFont ),
750                 m_aMapMode( rState.m_aMapMode ),
751                 m_aLineColor( rState.m_aLineColor ),
752                 m_aFillColor( rState.m_aFillColor ),
753                 m_aTextLineColor( rState.m_aTextLineColor ),
754                 m_aOverlineColor( rState.m_aOverlineColor ),
755                 m_aClipRegion( rState.m_aClipRegion ),
756                 m_bClipRegion( rState.m_bClipRegion ),
757                 m_nAntiAlias( rState.m_nAntiAlias ),
758                 m_nLayoutMode( rState.m_nLayoutMode ),
759                 m_aDigitLanguage( rState.m_aDigitLanguage ),
760                 m_nTransparentPercent( rState.m_nTransparentPercent ),
761                 m_nFlags( rState.m_nFlags ),
762                 m_nUpdateFlags( rState.m_nUpdateFlags )
763         {
764         }
765 
766         GraphicsState& operator=(const GraphicsState& rState )
767         {
768             m_aFont					= rState.m_aFont;
769             m_aMapMode				= rState.m_aMapMode;
770             m_aLineColor			= rState.m_aLineColor;
771             m_aFillColor			= rState.m_aFillColor;
772             m_aTextLineColor		= rState.m_aTextLineColor;
773             m_aOverlineColor		= rState.m_aOverlineColor;
774             m_aClipRegion			= rState.m_aClipRegion;
775             m_bClipRegion           = rState.m_bClipRegion;
776             m_nAntiAlias			= rState.m_nAntiAlias;
777             m_nLayoutMode			= rState.m_nLayoutMode;
778             m_aDigitLanguage        = rState.m_aDigitLanguage;
779             m_nTransparentPercent	= rState.m_nTransparentPercent;
780             m_nFlags				= rState.m_nFlags;
781             m_nUpdateFlags          = rState.m_nUpdateFlags;
782             return *this;
783         }
784     };
785     std::list< GraphicsState >				m_aGraphicsStack;
786     GraphicsState							m_aCurrentPDFState;
787 
788     ZCodec*									m_pCodec;
789     SvMemoryStream*							m_pMemStream;
790 
791     std::vector< PDFAddStream >             m_aAdditionalStreams;
792     std::set< PDFWriter::ErrorCode >        m_aErrors;
793 
794     rtlDigest                               m_aDocDigest;
795 
796 /*
797 variables for PDF security
798 i12626
799 */
800 /* used to cipher the stream data and for password management */
801 	rtlCipher								m_aCipher;
802 	rtlDigest								m_aDigest;
803 	/* pad string used for password in Standard security handler */
804 	static const sal_uInt8					s_nPadString[ENCRYPTED_PWD_SIZE];
805 
806 	/* the encryption key, formed with the user password according to algorithm 3.2, maximum length is 16 bytes + 3 + 2
807 	for 128 bit security   */
808 	sal_Int32								m_nKeyLength; // key length, 16 or 5
809 	sal_Int32								m_nRC4KeyLength; // key length, 16 or 10, to be input to the algorith 3.1
810 
811 	/* set to true if the following stream must be encrypted, used inside writeBuffer() */
812 	sal_Bool								m_bEncryptThisStream;
813 
814 	/* the numerical value of the access permissions, according to PDF spec, must be signed */
815 	sal_Int32                               m_nAccessPermissions;
816 	/* string to hold the PDF creation date */
817 	rtl::OString						    m_aCreationDateString;
818 	/* string to hold the PDF creation date, for PDF/A metadata */
819 	rtl::OString						    m_aCreationMetaDateString;
820 	/* the buffer where the data are encrypted, dynamically allocated */
821 	sal_uInt8								*m_pEncryptionBuffer;
822 	/* size of the buffer */
823 	sal_Int32								m_nEncryptionBufferSize;
824 
825 	/* check and reallocate the buffer for encryption */
826 	sal_Bool checkEncryptionBufferSize( register sal_Int32 newSize );
827 	/* this function implements part of the PDF spec algorithm 3.1 in encryption, the rest (the actual encryption) is in PDFWriterImpl::writeBuffer */
828     void checkAndEnableStreamEncryption( register sal_Int32 nObject );
829 
830 	void disableStreamEncryption() { m_bEncryptThisStream = false; };
831 
832 	/* */
833     void enableStringEncryption( register sal_Int32 nObject );
834 
835 // test if the encryption is active, if yes than encrypt the unicode string  and add to the OStringBuffer parameter
836 	void appendUnicodeTextStringEncrypt( const rtl::OUString& rInString, const sal_Int32 nInObjectNumber, rtl::OStringBuffer& rOutBuffer );
837 
838 	void appendLiteralStringEncrypt( const rtl::OUString& rInString, const sal_Int32 nInObjectNumber, rtl::OStringBuffer& rOutBuffer, rtl_TextEncoding nEnc = RTL_TEXTENCODING_ASCII_US );
839 	void appendLiteralStringEncrypt( const rtl::OString& rInString, const sal_Int32 nInObjectNumber, rtl::OStringBuffer& rOutBuffer );
840 	void appendLiteralStringEncrypt( rtl::OStringBuffer& rInString, const sal_Int32 nInObjectNumber, rtl::OStringBuffer& rOutBuffer );
841 
842     /* creates fonts and subsets that will be emitted later */
843     void registerGlyphs( int nGlyphs, sal_GlyphId* pGlyphs, sal_Int32* pGlpyhWidths, sal_Ucs* pUnicodes, sal_Int32* pUnicodesPerGlyph, sal_uInt8* pMappedGlyphs, sal_Int32* pMappedFontObjects, const ImplFontData* pFallbackFonts[] );
844 
845     /*  emits a text object according to the passed layout */
846     /* TODO: remove rText as soon as SalLayout will change so that rText is not necessary anymore */
847     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 );
848     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 );
849     void drawLayout( SalLayout& rLayout, const String& rText, bool bTextLines );
850     void drawRelief( SalLayout& rLayout, const String& rText, bool bTextLines );
851     void drawShadow( SalLayout& rLayout, const String& rText, bool bTextLines );
852 
853     /*  writes differences between graphics stack and current real PDF
854      *   state to the file
855      */
856     void updateGraphicsState();
857 
858     /* writes a transparency group object */
859     bool writeTransparentObject( TransparencyEmit& rObject );
860 
861     /* writes an XObject of type image, may create
862        a second for the mask
863      */
864     bool writeBitmapObject( BitmapEmit& rObject, bool bMask = false );
865 
866     bool writeJPG( JPGEmit& rEmit );
867 
868     /* tries to find the bitmap by its id and returns its emit data if exists,
869        else creates a new emit data block */
870     const BitmapEmit& createBitmapEmit( const BitmapEx& rBitmapEx, bool bDrawMask = false );
871 
872     /* writes the Do operation inside the content stream */
873     void drawBitmap( const Point& rDestPt, const Size& rDestSize, const BitmapEmit& rBitmap, const Color& rFillColor );
874     /* write the function object for a Gradient */
875     bool writeGradientFunction( GradientEmit& rObject );
876     /* creates a GradientEmit and returns its object number */
877     sal_Int32 createGradient(  const Gradient& rGradient, const Size& rSize );
878 
879     /* writes all tilings */
880     bool emitTilings();
881     /* writes all gradient patterns */
882     bool emitGradients();
883     /* writes a builtin font object and returns its objectid (or 0 in case of failure ) */
884     sal_Int32 emitBuiltinFont( const ImplFontData*, sal_Int32 nObject = -1 );
885     /* writes a type1 embedded font object and returns its mapping from font ids to object ids (or 0 in case of failure ) */
886     std::map< sal_Int32, sal_Int32 > emitEmbeddedFont( const ImplFontData*, EmbedFont& );
887     /* writes a type1 system font object and returns its mapping from font ids to object ids (or 0 in case of failure ) */
888     std::map< sal_Int32, sal_Int32 > emitSystemFont( const ImplFontData*, EmbedFont& );
889     /* writes a font descriptor and returns its object id (or 0) */
890     sal_Int32 emitFontDescriptor( const ImplFontData*, FontSubsetInfo&, sal_Int32 nSubsetID, sal_Int32 nStream );
891     /* writes a ToUnicode cmap, returns the corresponding stream object */
892     sal_Int32 createToUnicodeCMap( sal_uInt8* pEncoding, sal_Ucs* pUnicodes, sal_Int32* pUnicodesPerGlyph, sal_Int32* pEncToUnicodeIndex, int nGlyphs );
893 
894     /* get resource dict object number */
895     sal_Int32 getResourceDictObj()
896     {
897         if( m_nResourceDict <= 0 )
898             m_nResourceDict = createObject();
899         return m_nResourceDict;
900     }
901     /* get the font dict object */
902     sal_Int32 getFontDictObject()
903     {
904         if( m_nFontDictObject <= 0 )
905             m_nFontDictObject = createObject();
906         return m_nFontDictObject;
907     }
908     /* push resource into current (redirected) resource dict */
909     void pushResource( ResourceKind eKind, const rtl::OString& rResource, sal_Int32 nObject );
910 
911     void appendBuiltinFontsToDict( rtl::OStringBuffer& rDict ) const;
912     /* writes a the font dictionary and emits all font objects
913      * returns object id of font directory (or 0 on error)
914      */
915     bool emitFonts();
916 	/* writes the Resource dictionary;
917      * returns dict object id (or 0 on error)
918      */
919     sal_Int32 emitResources();
920     // appends a dest
921     bool appendDest( sal_Int32 nDestID, rtl::OStringBuffer& rBuffer );
922     // write all links
923     bool emitLinkAnnotations();
924     // write all notes
925     bool emitNoteAnnotations();
926     // write the appearance streams of a widget
927     bool emitAppearances( PDFWidget& rWidget, rtl::OStringBuffer& rAnnotDict );
928     // clean up radio button "On" values
929     void ensureUniqueRadioOnValues();
930     // write all widgets
931     bool emitWidgetAnnotations();
932     // writes all annotation objects
933     bool emitAnnotations();
934     // writes the dest dict for the catalog
935     sal_Int32 emitDestDict();
936     //write the named destination stuff
937     sal_Int32 emitNamedDestinations();//i56629
938     // writes outline dict and tree
939     sal_Int32 emitOutline();
940     // puts the attribute objects of a structure element into the returned string,
941     // helper for emitStructure
942     rtl::OString emitStructureAttributes( PDFStructureElement& rEle );
943     //--->i94258
944     // the maximum array elements allowed for PDF array object
945     static const sal_uInt32 ncMaxPDFArraySize = 8191;
946     //check if internal dummy container are needed in the structure elements
947     void addInternalStructureContainer( PDFStructureElement& rEle );
948     //<---i94258
949     // writes document structure
950     sal_Int32 emitStructure( PDFStructureElement& rEle );
951     // writes structure parent tree
952     sal_Int32 emitStructParentTree( sal_Int32 nTreeObject );
953     // writes page tree and catalog
954     bool emitCatalog();
955     // writes xref and trailer
956     bool emitTrailer();
957     // emit additional streams collected; also create there object numbers
958     bool emitAdditionalStreams();
959     // emits info dict (if applicable)
960     sal_Int32 emitInfoDict( );
961 
962     // acrobat reader 5 and 6 use the order of the annotations
963     // as their tab order; since PDF1.5 one can make the
964     // tab order explicit by using the structure tree
965     void sortWidgets();
966 
967     // updates the count numbers of outline items
968     sal_Int32 updateOutlineItemCount( std::vector< sal_Int32 >& rCounts,
969                                       sal_Int32 nItemLevel,
970                                       sal_Int32 nCurrentItemId );
971     // default appearences for widgets
972     sal_Int32 findRadioGroupWidget( const PDFWriter::RadioButtonWidget& rRadio );
973     Font replaceFont( const Font& rControlFont, const Font& rAppSetFont );
974     sal_Int32 getBestBuiltinFont( const Font& rFont );
975     sal_Int32 getSystemFont( const Font& i_rFont );
976 
977     // used for edit and listbox
978     Font drawFieldBorder( PDFWidget&, const PDFWriter::AnyWidget&, const StyleSettings& );
979 
980     void createDefaultPushButtonAppearance( PDFWidget&, const PDFWriter::PushButtonWidget& rWidget );
981     void createDefaultCheckBoxAppearance( PDFWidget&, const PDFWriter::CheckBoxWidget& rWidget );
982     void createDefaultRadioButtonAppearance( PDFWidget&, const PDFWriter::RadioButtonWidget& rWidget );
983     void createDefaultEditAppearance( PDFWidget&, const PDFWriter::EditWidget& rWidget );
984     void createDefaultListBoxAppearance( PDFWidget&, const PDFWriter::ListBoxWidget& rWidget );
985 
986     /* ensure proper escapement and uniqueness of field names */
987     void createWidgetFieldName( sal_Int32 i_nWidgetsIndex, const PDFWriter::AnyWidget& i_rInWidget );
988     /* adds an entry to m_aObjects and returns its index+1,
989      * sets the offset to ~0
990      */
991     sal_Int32 createObject();
992     /* sets the offset of object n to the current position of output file+1
993      */
994     bool updateObject( sal_Int32 n );
995 
996     bool writeBuffer( const void* pBuffer, sal_uInt64 nBytes );
997     void beginCompression();
998     void endCompression();
999     void beginRedirect( SvStream* pStream, const Rectangle& );
1000     // returns an empty rect if no redirection is happending
1001     Rectangle getRedirectTargetRect() const;
1002     SvStream* endRedirect();
1003 
1004     void endPage();
1005 
1006     void beginStructureElementMCSeq();
1007     void endStructureElementMCSeq();
1008     /** checks whether a non struct element lies in the ancestor hierarchy
1009         of the current structure element
1010 
1011         @returns
1012         <true/> if no NonStructElement was found in ancestor path and tagged
1013         PDF output is enabled
1014         <false/> else
1015      */
1016     bool checkEmitStructure();
1017 
1018     /* draws an emphasis mark */
1019     void drawEmphasisMark(  long nX, long nY, const PolyPolygon& rPolyPoly, sal_Bool bPolyLine, const Rectangle& rRect1, const Rectangle& rRect2 );
1020 
1021     /* true if PDF/A-1a or PDF/A-1b is output */
1022     sal_Bool        m_bIsPDF_A1;
1023     PDFWriter&      m_rOuterFace;
1024 
1025     /*
1026     i12626
1027     methods for PDF security
1028 
1029     pad a password according  algorithm 3.2, step 1 */
1030     static void padPassword( const rtl::OUString& i_rPassword, sal_uInt8* o_pPaddedPW );
1031     /* algorithm 3.2: compute an encryption key */
1032 	static bool computeEncryptionKey( EncHashTransporter*,
1033 	                                  vcl::PDFWriter::PDFEncryptionProperties& io_rProperties,
1034 	                                  sal_Int32 i_nAccessPermissions
1035 	                                 );
1036 	/* algorithm 3.3: computing the encryption dictionary'ss owner password value ( /O ) */
1037 	static bool computeODictionaryValue( const sal_uInt8* i_pPaddedOwnerPassword, const sal_uInt8* i_pPaddedUserPassword,
1038 	                                     std::vector< sal_uInt8 >& io_rOValue,
1039 	                                     sal_Int32 i_nKeyLength
1040 	                                    );
1041 	/* algorithm 3.4 or 3.5: computing the encryption dictionary's user password value ( /U ) revision 2 or 3 of the standard security handler */
1042 	static bool computeUDictionaryValue( EncHashTransporter* i_pTransporter,
1043 	                                     vcl::PDFWriter::PDFEncryptionProperties& io_rProperties,
1044 	                                     sal_Int32 i_nKeyLength,
1045 	                                     sal_Int32 i_nAccessPermissions
1046 	                                    );
1047 
1048 	static void computeDocumentIdentifier( std::vector< sal_uInt8 >& o_rIdentifier,
1049 	                                       const vcl::PDFWriter::PDFDocInfo& i_rDocInfo,
1050 	                                       rtl::OString& o_rCString1,
1051 	                                       rtl::OString& o_rCString2
1052 	                                      );
1053 	static sal_Int32 computeAccessPermissions( const vcl::PDFWriter::PDFEncryptionProperties& i_rProperties,
1054 	                                           sal_Int32& o_rKeyLength, sal_Int32& o_rRC4KeyLength );
1055     void setupDocInfo();
1056     bool prepareEncryption( const com::sun::star::uno::Reference< com::sun::star::beans::XMaterialHolder >& );
1057 
1058 	// helper for playMetafile
1059     void implWriteGradient( const PolyPolygon& rPolyPoly, const Gradient& rGradient,
1060                             VirtualDevice* pDummyVDev, const vcl::PDFWriter::PlayMetafileContext& );
1061     void implWriteBitmapEx( const Point& rPoint, const Size& rSize, const BitmapEx& rBitmapEx,
1062                            VirtualDevice* pDummyVDev, const vcl::PDFWriter::PlayMetafileContext& );
1063 
1064     // helpers for CCITT 1bit bitmap stream
1065     void putG4Bits( sal_uInt32 i_nLength, sal_uInt32 i_nCode, BitStreamState& io_rState );
1066     void putG4Span( long i_nSpan, bool i_bWhitePixel, BitStreamState& io_rState );
1067     void writeG4Stream( BitmapReadAccess* i_pBitmap );
1068 
1069     // color helper functions
1070     void appendStrokingColor( const Color& rColor, rtl::OStringBuffer& rBuffer );
1071     void appendNonStrokingColor( const Color& rColor, rtl::OStringBuffer& rBuffer );
1072 public:
1073     PDFWriterImpl( const PDFWriter::PDFWriterContext& rContext, const com::sun::star::uno::Reference< com::sun::star::beans::XMaterialHolder >&, PDFWriter& );
1074     ~PDFWriterImpl();
1075 
1076     static com::sun::star::uno::Reference< com::sun::star::beans::XMaterialHolder >
1077            initEncryption( const rtl::OUString& i_rOwnerPassword,
1078                            const rtl::OUString& i_rUserPassword,
1079                            bool b128Bit );
1080 
1081     /*	for OutputDevice so the reference device can have a list
1082      *	that contains only suitable fonts (subsettable or builtin)
1083      *	produces a new font list
1084      */
1085     ImplDevFontList* filterDevFontList( ImplDevFontList* pFontList );
1086     /*  for OutputDevice: get layout for builtin fonts
1087      */
1088     bool isBuiltinFont( const ImplFontData* ) const;
1089     SalLayout* GetTextLayout( ImplLayoutArgs& rArgs, ImplFontSelectData* pFont );
1090     void getFontMetric( ImplFontSelectData* pFont, ImplFontMetricData* pMetric ) const;
1091 
1092 
1093     /* for documentation of public functions please see pdfwriter.hxx */
1094 
1095     OutputDevice* getReferenceDevice();
1096 
1097     /* document structure */
1098     sal_Int32 newPage( sal_Int32 nPageWidth , sal_Int32 nPageHeight, PDFWriter::Orientation eOrientation );
1099     bool emit();
1100     std::set< PDFWriter::ErrorCode > getErrors();
1101     void insertError( PDFWriter::ErrorCode eErr ) { m_aErrors.insert( eErr ); }
1102     void playMetafile( const GDIMetaFile&, vcl::PDFExtOutDevData*, const vcl::PDFWriter::PlayMetafileContext&, VirtualDevice* pDummyDev = NULL );
1103 
1104     Size getCurPageSize() const
1105     {
1106         Size aSize;
1107         if( m_nCurrentPage >= 0 && m_nCurrentPage < (sal_Int32)m_aPages.size() )
1108             aSize = Size( m_aPages[ m_nCurrentPage ].m_nPageWidth, m_aPages[ m_nCurrentPage ].m_nPageHeight );
1109         return aSize;
1110     }
1111 
1112     PDFWriter::PDFVersion getVersion() const { return m_aContext.Version; }
1113 
1114     void setDocumentLocale( const com::sun::star::lang::Locale& rLoc )
1115     { m_aContext.DocumentLocale = rLoc; }
1116 
1117 
1118     /* graphics state */
1119     void push( sal_uInt16 nFlags );
1120     void pop();
1121 
1122     void setFont( const Font& rFont );
1123 
1124     void setMapMode( const MapMode& rMapMode );
1125     void setMapMode() { setMapMode( m_aMapMode ); }
1126 
1127 
1128     const MapMode& getMapMode() { return m_aGraphicsStack.front().m_aMapMode; }
1129 
1130     void setLineColor( const Color& rColor )
1131     {
1132         m_aGraphicsStack.front().m_aLineColor = ImplIsColorTransparent(rColor) ? Color( COL_TRANSPARENT ) : rColor;
1133         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateLineColor;
1134     }
1135 
1136     void setFillColor( const Color& rColor )
1137     {
1138         m_aGraphicsStack.front().m_aFillColor = ImplIsColorTransparent(rColor) ? Color( COL_TRANSPARENT ) : rColor;
1139         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateFillColor;
1140     }
1141 
1142     void setTextLineColor()
1143     {
1144         m_aGraphicsStack.front().m_aTextLineColor = Color( COL_TRANSPARENT );
1145         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateTextLineColor;
1146     }
1147 
1148     void setTextLineColor( const Color& rColor )
1149     {
1150         m_aGraphicsStack.front().m_aTextLineColor = rColor;
1151         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateTextLineColor;
1152     }
1153 
1154     void setOverlineColor()
1155     {
1156         m_aGraphicsStack.front().m_aOverlineColor = Color( COL_TRANSPARENT );
1157         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateOverlineColor;
1158     }
1159 
1160     void setOverlineColor( const Color& rColor )
1161     {
1162         m_aGraphicsStack.front().m_aOverlineColor = rColor;
1163         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateOverlineColor;
1164     }
1165 
1166     void setTextFillColor( const Color& rColor )
1167     {
1168         m_aGraphicsStack.front().m_aFont.SetFillColor( rColor );
1169         m_aGraphicsStack.front().m_aFont.SetTransparent( ImplIsColorTransparent( rColor ) ? sal_True : sal_False );
1170         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateFont;
1171     }
1172     void setTextFillColor()
1173     {
1174         m_aGraphicsStack.front().m_aFont.SetFillColor( Color( COL_TRANSPARENT ) );
1175         m_aGraphicsStack.front().m_aFont.SetTransparent( sal_True );
1176         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateFont;
1177     }
1178     void setTextColor( const Color& rColor )
1179     {
1180         m_aGraphicsStack.front().m_aFont.SetColor( rColor );
1181         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateFont;
1182     }
1183 
1184     void clearClipRegion()
1185     {
1186         m_aGraphicsStack.front().m_aClipRegion.clear();
1187         m_aGraphicsStack.front().m_bClipRegion = false;
1188         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateClipRegion;
1189     }
1190 
1191     void setClipRegion( const basegfx::B2DPolyPolygon& rRegion );
1192 
1193     void moveClipRegion( sal_Int32 nX, sal_Int32 nY );
1194 
1195     bool intersectClipRegion( const Rectangle& rRect );
1196 
1197     bool intersectClipRegion( const basegfx::B2DPolyPolygon& rRegion );
1198 
1199     void setLayoutMode( sal_Int32 nLayoutMode )
1200     {
1201         m_aGraphicsStack.front().m_nLayoutMode = nLayoutMode;
1202         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateLayoutMode;
1203     }
1204 
1205     void setDigitLanguage( LanguageType eLang )
1206     {
1207         m_aGraphicsStack.front().m_aDigitLanguage = eLang;
1208         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateDigitLanguage;
1209     }
1210 
1211     void setTextAlign( TextAlign eAlign )
1212     {
1213         m_aGraphicsStack.front().m_aFont.SetAlign( eAlign );
1214         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateFont;
1215     }
1216 
1217     void setAntiAlias( sal_Int32 nAntiAlias )
1218     {
1219         m_aGraphicsStack.front().m_nAntiAlias = nAntiAlias;
1220         m_aGraphicsStack.front().m_nUpdateFlags |= GraphicsState::updateAntiAlias;
1221     }
1222 
1223     /* actual drawing functions */
1224     void drawText( const Point& rPos, const String& rText, xub_StrLen nIndex = 0, xub_StrLen nLen = STRING_LEN, bool bTextLines = true );
1225     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 );
1226     void drawStretchText( const Point& rPos, sal_uLong nWidth, const String& rText,
1227                           xub_StrLen nIndex = 0, xub_StrLen nLen = STRING_LEN,
1228                           bool bTextLines = true  );
1229     void drawText( const Rectangle& rRect, const String& rOrigStr, sal_uInt16 nStyle, bool bTextLines = true  );
1230     void drawTextLine( const Point& rPos, long nWidth, FontStrikeout eStrikeout, FontUnderline eUnderline, FontUnderline eOverline, bool bUnderlineAbove );
1231     void drawWaveTextLine( rtl::OStringBuffer& aLine, long nWidth, FontUnderline eTextLine, Color aColor, bool bIsAbove );
1232     void drawStraightTextLine( rtl::OStringBuffer& aLine, long nWidth, FontUnderline eTextLine, Color aColor, bool bIsAbove );
1233     void drawStrikeoutLine( rtl::OStringBuffer& aLine, long nWidth, FontStrikeout eStrikeout, Color aColor );
1234     void drawStrikeoutChar( const Point& rPos, long nWidth, FontStrikeout eStrikeout );
1235 
1236     void drawLine( const Point& rStart, const Point& rStop );
1237     void drawLine( const Point& rStart, const Point& rStop, const LineInfo& rInfo );
1238     void drawPolygon( const Polygon& rPoly );
1239     void drawPolyPolygon( const PolyPolygon& rPolyPoly );
1240     void drawPolyLine( const Polygon& rPoly );
1241     void drawPolyLine( const Polygon& rPoly, const LineInfo& rInfo );
1242     void drawPolyLine( const Polygon& rPoly, const PDFWriter::ExtLineInfo& rInfo );
1243     void drawWaveLine( const Point& rStart, const Point& rStop, sal_Int32 nDelta, sal_Int32 nLineWidth );
1244 
1245     void drawPixel( const Point& rPt, const Color& rColor );
1246     void drawPixel( const Polygon& rPts, const Color* pColors = NULL );
1247 
1248     void drawRectangle( const Rectangle& rRect );
1249     void drawRectangle( const Rectangle& rRect, sal_uInt32 nHorzRound, sal_uInt32 nVertRound );
1250     void drawEllipse( const Rectangle& rRect );
1251     void drawArc( const Rectangle& rRect, const Point& rStart, const Point& rStop, bool bWithPie, bool bWidthChord );
1252 
1253     void drawBitmap( const Point& rDestPoint, const Size& rDestSize, const Bitmap& rBitmap );
1254     void drawBitmap( const Point& rDestPoint, const Size& rDestSize, const BitmapEx& rBitmap );
1255     void drawMask( const Point& rDestPoint, const Size& rDestSize, const Bitmap& rBitmap, const Color& rFillColor );
1256     void drawJPGBitmap( SvStream& rDCTData, bool bIsTrueColor, const Size& rSizePixel, const Rectangle& rTargetArea, const Bitmap& rMask );
1257 
1258     void drawGradient( const Rectangle& rRect, const Gradient& rGradient );
1259     void drawGradient( const PolyPolygon& rPolyPoly, const Gradient& rGradient );
1260     void drawHatch( const PolyPolygon& rPolyPoly, const Hatch& rHatch );
1261     void drawWallpaper( const Rectangle& rRect, const Wallpaper& rWall );
1262     void drawTransparent( const PolyPolygon& rPolyPoly, sal_uInt32 nTransparentPercent );
1263     void beginTransparencyGroup();
1264     void endTransparencyGroup( const Rectangle& rBoundingBox, sal_uInt32 nTransparentPercent );
1265     void endTransparencyGroup( const Rectangle& rBoundingBox, const Bitmap& rAlphaMask );
1266     void beginPattern( const Rectangle& rCell );
1267     sal_Int32 endPattern( const SvtGraphicFill::Transform& rTransform );
1268     void drawPolyPolygon( const PolyPolygon& rPolyPoly, sal_Int32 nPattern, bool bEOFill );
1269 
1270     void emitComment( const char* pComment );
1271 
1272     //--->i56629 named destinations
1273     sal_Int32 createNamedDest( const rtl::OUString& sDestName, const Rectangle& rRect, sal_Int32 nPageNr = -1, PDFWriter::DestAreaType eType = PDFWriter::XYZ );
1274 
1275     //--->i59651
1276     //emits output intent
1277     sal_Int32   emitOutputIntent();
1278 
1279     //emits the document metadata
1280     sal_Int32   emitDocumentMetadata();
1281 
1282     // links
1283     sal_Int32 createLink( const Rectangle& rRect, sal_Int32 nPageNr = -1 );
1284     sal_Int32 createDest( const Rectangle& rRect, sal_Int32 nPageNr = -1, PDFWriter::DestAreaType eType = PDFWriter::XYZ );
1285     sal_Int32 registerDestReference( sal_Int32 nDestId, const Rectangle& rRect, sal_Int32 nPageNr = -1, PDFWriter::DestAreaType eType = PDFWriter::XYZ );
1286     sal_Int32 setLinkDest( sal_Int32 nLinkId, sal_Int32 nDestId );
1287     sal_Int32 setLinkURL( sal_Int32 nLinkId, const rtl::OUString& rURL );
1288     void setLinkPropertyId( sal_Int32 nLinkId, sal_Int32 nPropertyId );
1289 
1290     // outline
1291     sal_Int32 createOutlineItem( sal_Int32 nParent = 0, const rtl::OUString& rText = rtl::OUString(), sal_Int32 nDestID = -1 );
1292     sal_Int32 setOutlineItemParent( sal_Int32 nItem, sal_Int32 nNewParent );
1293     sal_Int32 setOutlineItemText( sal_Int32 nItem, const rtl::OUString& rText );
1294     sal_Int32 setOutlineItemDest( sal_Int32 nItem, sal_Int32 nDestID );
1295 
1296     // notes
1297     void createNote( const Rectangle& rRect, const PDFNote& rNote, sal_Int32 nPageNr = -1 );
1298     // structure elements
1299     sal_Int32 beginStructureElement( PDFWriter::StructElement eType, const rtl::OUString& rAlias );
1300     void endStructureElement();
1301     bool setCurrentStructureElement( sal_Int32 nElement );
1302     sal_Int32 getCurrentStructureElement();
1303     bool setStructureAttribute( enum PDFWriter::StructAttribute eAttr, enum PDFWriter::StructAttributeValue eVal );
1304     bool setStructureAttributeNumerical( enum PDFWriter::StructAttribute eAttr, sal_Int32 nValue );
1305     void setStructureBoundingBox( const Rectangle& rRect );
1306     void setActualText( const String& rText );
1307     void setAlternateText( const String& rText );
1308 
1309     // transitional effects
1310     void setAutoAdvanceTime( sal_uInt32 nSeconds, sal_Int32 nPageNr = -1 );
1311     void setPageTransition( PDFWriter::PageTransition eType, sal_uInt32 nMilliSec, sal_Int32 nPageNr = -1 );
1312 
1313     // controls
1314     sal_Int32 createControl( const PDFWriter::AnyWidget& rControl, sal_Int32 nPageNr = -1 );
1315     void beginControlAppearance( sal_Int32 nControl );
1316     bool endControlAppearance( PDFWriter::WidgetState eState );
1317 
1318     // additional streams
1319     void addStream( const String& rMimeType, PDFOutputStream* pStream, bool bCompress );
1320 
1321     // helper: eventually begin marked content sequence and
1322     // emit a comment in debug case
1323     void MARK( const char*
1324 #if OSL_DEBUG_LEVEL > 1
1325         pString
1326 #endif
1327         )
1328     {
1329         beginStructureElementMCSeq();
1330 #if OSL_DEBUG_LEVEL > 1
1331         emitComment( pString );
1332 #endif
1333     }
1334 };
1335 
1336 }
1337 
1338 #endif //_VCL_PDFEXPORT_HXX
1339 
1340 
1341