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