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