1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/pdf/SkPDFDocument.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2010 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#ifndef SkPDFDocument_DEFINED 1.14 +#define SkPDFDocument_DEFINED 1.15 + 1.16 +#include "SkAdvancedTypefaceMetrics.h" 1.17 +#include "SkRefCnt.h" 1.18 +#include "SkTDArray.h" 1.19 +#include "SkTemplates.h" 1.20 + 1.21 +class SkPDFCatalog; 1.22 +class SkPDFDevice; 1.23 +class SkPDFDict; 1.24 +class SkPDFPage; 1.25 +class SkPDFObject; 1.26 +class SkWStream; 1.27 +template <typename T> class SkTSet; 1.28 + 1.29 +/** \class SkPDFDocument 1.30 + 1.31 + A SkPDFDocument assembles pages together and generates the final PDF file. 1.32 +*/ 1.33 +class SkPDFDocument { 1.34 +public: 1.35 + enum Flags { 1.36 + kNoCompression_Flags = 0x01, //!< DEPRECATED. 1.37 + kFavorSpeedOverSize_Flags = 0x01, //!< Don't compress the stream, but 1.38 + // if it is already compressed return 1.39 + // the compressed stream. 1.40 + kNoLinks_Flags = 0x02, //!< do not honor link annotations. 1.41 + 1.42 + kDraftMode_Flags = 0x01, 1.43 + }; 1.44 + /** Create a PDF document. 1.45 + */ 1.46 + explicit SK_API SkPDFDocument(Flags flags = (Flags)0); 1.47 + SK_API ~SkPDFDocument(); 1.48 + 1.49 + /** Output the PDF to the passed stream. It is an error to call this (it 1.50 + * will return false and not modify stream) if no pages have been added 1.51 + * or there are pages missing (i.e. page 1 and 3 have been added, but not 1.52 + * page 2). 1.53 + * 1.54 + * @param stream The writable output stream to send the PDF to. 1.55 + */ 1.56 + SK_API bool emitPDF(SkWStream* stream); 1.57 + 1.58 + /** Sets the specific page to the passed PDF device. If the specified 1.59 + * page is already set, this overrides it. Returns true if successful. 1.60 + * Will fail if the document has already been emitted. 1.61 + * 1.62 + * @param pageNumber The position to add the passed device (1 based). 1.63 + * @param pdfDevice The page to add to this document. 1.64 + */ 1.65 + SK_API bool setPage(int pageNumber, SkPDFDevice* pdfDevice); 1.66 + 1.67 + /** Append the passed pdf device to the document as a new page. Returns 1.68 + * true if successful. Will fail if the document has already been emitted. 1.69 + * 1.70 + * @param pdfDevice The page to add to this document. 1.71 + */ 1.72 + SK_API bool appendPage(SkPDFDevice* pdfDevice); 1.73 + 1.74 + /** Get the count of unique font types used in the document. 1.75 + */ 1.76 + SK_API void getCountOfFontTypes( 1.77 + int counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]) const; 1.78 + 1.79 +private: 1.80 + SkAutoTDelete<SkPDFCatalog> fCatalog; 1.81 + int64_t fXRefFileOffset; 1.82 + 1.83 + SkTDArray<SkPDFPage*> fPages; 1.84 + SkTDArray<SkPDFDict*> fPageTree; 1.85 + SkPDFDict* fDocCatalog; 1.86 + SkTSet<SkPDFObject*>* fFirstPageResources; 1.87 + SkTSet<SkPDFObject*>* fOtherPageResources; 1.88 + SkTDArray<SkPDFObject*> fSubstitutes; 1.89 + 1.90 + SkPDFDict* fTrailerDict; 1.91 + 1.92 + /** Output the PDF header to the passed stream. 1.93 + * @param stream The writable output stream to send the header to. 1.94 + */ 1.95 + void emitHeader(SkWStream* stream); 1.96 + 1.97 + /** Get the size of the header. 1.98 + */ 1.99 + size_t headerSize(); 1.100 + 1.101 + /** Output the PDF footer to the passed stream. 1.102 + * @param stream The writable output stream to send the footer to. 1.103 + * @param objCount The number of objects in the PDF. 1.104 + */ 1.105 + void emitFooter(SkWStream* stream, int64_t objCount); 1.106 +}; 1.107 + 1.108 +#endif