michael@0: michael@0: /* michael@0: * Copyright 2010 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkPDFDocument_DEFINED michael@0: #define SkPDFDocument_DEFINED michael@0: michael@0: #include "SkAdvancedTypefaceMetrics.h" michael@0: #include "SkRefCnt.h" michael@0: #include "SkTDArray.h" michael@0: #include "SkTemplates.h" michael@0: michael@0: class SkPDFCatalog; michael@0: class SkPDFDevice; michael@0: class SkPDFDict; michael@0: class SkPDFPage; michael@0: class SkPDFObject; michael@0: class SkWStream; michael@0: template class SkTSet; michael@0: michael@0: /** \class SkPDFDocument michael@0: michael@0: A SkPDFDocument assembles pages together and generates the final PDF file. michael@0: */ michael@0: class SkPDFDocument { michael@0: public: michael@0: enum Flags { michael@0: kNoCompression_Flags = 0x01, //!< DEPRECATED. michael@0: kFavorSpeedOverSize_Flags = 0x01, //!< Don't compress the stream, but michael@0: // if it is already compressed return michael@0: // the compressed stream. michael@0: kNoLinks_Flags = 0x02, //!< do not honor link annotations. michael@0: michael@0: kDraftMode_Flags = 0x01, michael@0: }; michael@0: /** Create a PDF document. michael@0: */ michael@0: explicit SK_API SkPDFDocument(Flags flags = (Flags)0); michael@0: SK_API ~SkPDFDocument(); michael@0: michael@0: /** Output the PDF to the passed stream. It is an error to call this (it michael@0: * will return false and not modify stream) if no pages have been added michael@0: * or there are pages missing (i.e. page 1 and 3 have been added, but not michael@0: * page 2). michael@0: * michael@0: * @param stream The writable output stream to send the PDF to. michael@0: */ michael@0: SK_API bool emitPDF(SkWStream* stream); michael@0: michael@0: /** Sets the specific page to the passed PDF device. If the specified michael@0: * page is already set, this overrides it. Returns true if successful. michael@0: * Will fail if the document has already been emitted. michael@0: * michael@0: * @param pageNumber The position to add the passed device (1 based). michael@0: * @param pdfDevice The page to add to this document. michael@0: */ michael@0: SK_API bool setPage(int pageNumber, SkPDFDevice* pdfDevice); michael@0: michael@0: /** Append the passed pdf device to the document as a new page. Returns michael@0: * true if successful. Will fail if the document has already been emitted. michael@0: * michael@0: * @param pdfDevice The page to add to this document. michael@0: */ michael@0: SK_API bool appendPage(SkPDFDevice* pdfDevice); michael@0: michael@0: /** Get the count of unique font types used in the document. michael@0: */ michael@0: SK_API void getCountOfFontTypes( michael@0: int counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]) const; michael@0: michael@0: private: michael@0: SkAutoTDelete fCatalog; michael@0: int64_t fXRefFileOffset; michael@0: michael@0: SkTDArray fPages; michael@0: SkTDArray fPageTree; michael@0: SkPDFDict* fDocCatalog; michael@0: SkTSet* fFirstPageResources; michael@0: SkTSet* fOtherPageResources; michael@0: SkTDArray fSubstitutes; michael@0: michael@0: SkPDFDict* fTrailerDict; michael@0: michael@0: /** Output the PDF header to the passed stream. michael@0: * @param stream The writable output stream to send the header to. michael@0: */ michael@0: void emitHeader(SkWStream* stream); michael@0: michael@0: /** Get the size of the header. michael@0: */ michael@0: size_t headerSize(); michael@0: michael@0: /** Output the PDF footer to the passed stream. michael@0: * @param stream The writable output stream to send the footer to. michael@0: * @param objCount The number of objects in the PDF. michael@0: */ michael@0: void emitFooter(SkWStream* stream, int64_t objCount); michael@0: }; michael@0: michael@0: #endif