Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkDocument Class Referenceabstract

High-level API for creating a document-based canvas. More...

#include <SkDocument.h>

Inheritance diagram for SkDocument:
SkRefCnt SkRefCntBase

Classes

struct  OptionalTimestamp
 
struct  PDFMetadata
 Optional metadata to be passed into the PDF factory function. More...
 

Public Member Functions

SkCanvasbeginPage (SkScalar width, SkScalar height, const SkRect *content=NULL)
 Begin a new page for the document, returning the canvas that will draw into the page. More...
 
void endPage ()
 Call endPage() when the content for the current page has been drawn (into the canvas returned by beginPage()). More...
 
void close ()
 Call close() when all pages have been drawn. More...
 
void abort ()
 Call abort() to stop producing the document immediately. More...
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 Default construct, initializing the reference count to 1.
 
virtual ~SkRefCntBase ()
 Destruct, asserting that the reference count is 1.
 
int32_t getRefCnt () const
 Return the reference count. More...
 
void validate () const
 
bool unique () const
 May return true if the caller is the only owner. More...
 
void ref () const
 Increment the reference count. More...
 
void unref () const
 Decrement the reference count. More...
 

Static Public Member Functions

static sk_sp< SkDocumentMakePDF (SkWStream *stream, SkScalar dpi, const SkDocument::PDFMetadata &metadata, sk_sp< SkPixelSerializer > jpegEncoder, bool pdfa)
 Create a PDF-backed document, writing the results into a SkWStream. More...
 
static sk_sp< SkDocumentMakePDF (SkWStream *stream, SkScalar dpi=SK_ScalarDefaultRasterDPI)
 
static sk_sp< SkDocumentMakePDF (const char outputFilePath[], SkScalar dpi=SK_ScalarDefaultRasterDPI)
 Create a PDF-backed document, writing the results into a file.
 

Protected Types

enum  State { kBetweenPages_State, kInPage_State, kClosed_State }
 

Protected Member Functions

 SkDocument (SkWStream *, void(*)(SkWStream *, bool aborted))
 
virtual SkCanvasonBeginPage (SkScalar width, SkScalar height, const SkRect &content)=0
 
virtual void onEndPage ()=0
 
virtual void onClose (SkWStream *)=0
 
virtual void onAbort ()=0
 
SkWStreamgetStream ()
 
State getState () const
 
- Protected Member Functions inherited from SkRefCntBase
void internal_dispose_restore_refcnt_to_1 () const
 Allow subclasses to call this if they've overridden internal_dispose so they can reset fRefCnt before the destructor is called or if they choose not to call the destructor (e.g. More...
 

Private Types

typedef SkRefCnt INHERITED
 

Private Attributes

SkWStreamfStream
 
void(* fDoneProc )(SkWStream *, bool aborted)
 
State fState
 

Detailed Description

High-level API for creating a document-based canvas.

To use..

  1. Create a document, specifying a stream to store the output.
  2. For each "page" of content: a. canvas = doc->beginPage(...) b. draw_my_content(canvas); c. doc->endPage();
  3. Close the document with doc->close().

Member Function Documentation

void SkDocument::abort ( )

Call abort() to stop producing the document immediately.

The stream output must be ignored, and should not be trusted.

SkCanvas* SkDocument::beginPage ( SkScalar  width,
SkScalar  height,
const SkRect content = NULL 
)

Begin a new page for the document, returning the canvas that will draw into the page.

The document owns this canvas, and it will go out of scope when endPage() or close() is called, or the document is deleted.

void SkDocument::close ( )

Call close() when all pages have been drawn.

This will close the file or stream holding the document's contents. After close() the document can no longer add new pages. Deleting the document will automatically call close() if need be.

void SkDocument::endPage ( )

Call endPage() when the content for the current page has been drawn (into the canvas returned by beginPage()).

After this call the canvas returned by beginPage() will be out-of-scope.

static sk_sp<SkDocument> SkDocument::MakePDF ( SkWStream stream,
SkScalar  dpi,
const SkDocument::PDFMetadata metadata,
sk_sp< SkPixelSerializer jpegEncoder,
bool  pdfa 
)
static

Create a PDF-backed document, writing the results into a SkWStream.

PDF pages are sized in point units. 1 pt == 1/72 inch == 127/360 mm.

Parameters
streamA PDF document will be written to this stream. The document may write to the stream at anytime during its lifetime, until either close() is called or the document is deleted.
dpiThe DPI (pixels-per-inch) at which features without native PDF support will be rasterized (e.g. draw image with perspective, draw text with perspective, ...) A larger DPI would create a PDF that reflects the original intent with better fidelity, but it can make for larger PDF files too, which would use more memory while rendering, and it would be slower to be processed or sent online or to printer.
metadataa PDFmetadata object. Any fields may be left empty.
jpegEncoderFor PDF documents, if a jpegEncoder is set, use it to encode SkImages and SkBitmaps as [JFIF]JPEGs. This feature is deprecated and is only supplied for backwards compatability. The prefered method to create PDFs with JPEG images is to use SkImage::NewFromEncoded() and not jpegEncoder. Chromium uses NewFromEncoded. If the encoder is unset, or if jpegEncoder->onEncode() returns NULL, fall back on encoding images losslessly with Deflate.
pdfaIff true, include XMP metadata, a document UUID, and sRGB output intent information. This adds length to the document and makes it non-reproducable, but are necessary features for PDF/A-2b conformance
Returns
NULL if there is an error, otherwise a newly created PDF-backed SkDocument.

The documentation for this class was generated from the following file: