LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/vcl/source/gdi - pdfwriter_impl.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 207 0.0 %
Date: 2013-07-09 Functions: 0 109 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10