Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkDocument.h
1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkDocument_DEFINED
9 #define SkDocument_DEFINED
10 
11 #include "SkBitmap.h"
12 #include "SkPicture.h"
13 #include "SkPixelSerializer.h"
14 #include "SkRect.h"
15 #include "SkRefCnt.h"
16 #include "SkString.h"
17 #include "SkTime.h"
18 
19 class SkCanvas;
20 class SkWStream;
21 
22 #define SK_SUPPORT_LEGACY_DOCUMENT_API
23 
26 #define SK_ScalarDefaultRasterDPI 72.0f
27 
38 class SK_API SkDocument : public SkRefCnt {
39 public:
41  SkTime::DateTime fDateTime;
42  bool fEnabled;
43  OptionalTimestamp() : fEnabled(false) {}
44  };
45 
49  struct PDFMetadata {
87  };
88 
128  static sk_sp<SkDocument> MakePDF(SkWStream* stream,
129  SkScalar dpi,
130  const SkDocument::PDFMetadata& metadata,
131  sk_sp<SkPixelSerializer> jpegEncoder,
132  bool pdfa);
133 
134  static sk_sp<SkDocument> MakePDF(SkWStream* stream,
135  SkScalar dpi = SK_ScalarDefaultRasterDPI) {
136  return SkDocument::MakePDF(stream, dpi, SkDocument::PDFMetadata(),
137  nullptr, false);
138  }
139 
143  static sk_sp<SkDocument> MakePDF(const char outputFilePath[],
144  SkScalar dpi = SK_ScalarDefaultRasterDPI);
145 
150  static sk_sp<SkDocument> MakeXPS(SkWStream* stream,
151  SkScalar dpi = SK_ScalarDefaultRasterDPI);
152 
157  static sk_sp<SkDocument> MakeXPS(const char path[],
158  SkScalar dpi = SK_ScalarDefaultRasterDPI);
159 
160 #ifdef SK_SUPPORT_LEGACY_DOCUMENT_API
161 
182  static SkDocument* CreatePDF(SkWStream* stream,
183  SkScalar dpi = SK_ScalarDefaultRasterDPI) {
184  return SkDocument::MakePDF(stream, dpi, SkDocument::PDFMetadata(),
185  nullptr, false).release();
186  }
187 
202  static SkDocument* CreatePDF(SkWStream* stream,
203  SkScalar dpi,
204  SkPixelSerializer* jpegEncoder) {
205  return SkDocument::MakePDF(stream, dpi, SkDocument::PDFMetadata(),
206  sk_ref_sp(jpegEncoder), false).release();
207  }
208 
212  static SkDocument* CreatePDF(const char outputFilePath[],
213  SkScalar dpi = SK_ScalarDefaultRasterDPI) {
214  return SkDocument::MakePDF(outputFilePath, dpi).release();
215  }
216 
217 #endif // SK_SUPPORT_LEGACY_DOCUMENT_API
218 
224  SkCanvas* beginPage(SkScalar width, SkScalar height,
225  const SkRect* content = NULL);
226 
232  void endPage();
233 
241  bool close();
242 
247  void abort();
248 
249 #ifdef SK_SUPPORT_LEGACY_DOCUMENT_API
250 
269  struct Attribute {
270  SkString fKey, fValue;
271  Attribute(const SkString& k, const SkString& v) : fKey(k), fValue(v) {}
272  };
273  virtual void setMetadata(const SkDocument::Attribute[],
274  int /* attributeCount */,
275  const SkTime::DateTime* /* creationDate */,
276  const SkTime::DateTime* /* modifiedDate */) {}
277 #endif // SK_SUPPORT_LEGACY_DOCUMENT_API
278 
279 protected:
280  SkDocument(SkWStream*, void (*)(SkWStream*, bool aborted));
281 
282  // note: subclasses must call close() in their destructor, as the base class
283  // cannot do this for them.
284  virtual ~SkDocument();
285 
286  virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height,
287  const SkRect& content) = 0;
288  virtual void onEndPage() = 0;
289  virtual bool onClose(SkWStream*) = 0;
290  virtual void onAbort() = 0;
291 
292  // Allows subclasses to write to the stream as pages are written.
293  SkWStream* getStream() { return fStream; }
294 
295  enum State {
296  kBetweenPages_State,
297  kInPage_State,
298  kClosed_State
299  };
300  State getState() const { return fState; }
301 
302 private:
303  SkWStream* fStream;
304  void (*fDoneProc)(SkWStream*, bool aborted);
305  State fState;
306 
307  typedef SkRefCnt INHERITED;
308 };
309 
310 #endif
SkString fCreator
If the document was converted to PDF from another format, the name of the conforming product that cre...
Definition: SkDocument.h:72
A Canvas encapsulates all of the state about drawing into a device (bitmap).
Definition: SkCanvas.h:58
Set the document's metadata, if supported by the document type.
Definition: SkDocument.h:269
SkString fKeywords
Keywords associated with the document.
Definition: SkDocument.h:66
Definition: SkRefCnt.h:135
static sk_sp< SkDocument > MakePDF(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.
SkString fAuthor
The name of the person who created the document.
Definition: SkDocument.h:57
Definition: SkDocument.h:40
OptionalTimestamp fModified
The date and time the document was most recently modified.
Definition: SkDocument.h:86
SkString fTitle
The document’s title.
Definition: SkDocument.h:53
SkString fProducer
The product that is converting this document to PDF.
Definition: SkDocument.h:78
Optional metadata to be passed into the PDF factory function.
Definition: SkDocument.h:49
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:258
static SkDocument * CreatePDF(SkWStream *stream, SkScalar dpi=SK_ScalarDefaultRasterDPI)
Create a PDF-backed document, writing the results into a SkWStream.
Definition: SkDocument.h:182
Interface for serializing pixels, e.g.
Definition: SkPixelSerializer.h:19
OptionalTimestamp fCreation
The date and time the document was created.
Definition: SkDocument.h:82
Definition: SkStream.h:182
Definition: SkRect.h:390
SkString fSubject
The subject of the document.
Definition: SkDocument.h:61
static SkDocument * CreatePDF(SkWStream *stream, SkScalar dpi, SkPixelSerializer *jpegEncoder)
Definition: SkDocument.h:202
Definition: SkTime.h:22
High-level API for creating a document-based canvas.
Definition: SkDocument.h:38
Light weight class for managing strings.
Definition: SkString.h:121
static SkDocument * CreatePDF(const char outputFilePath[], SkScalar dpi=SK_ScalarDefaultRasterDPI)
Create a PDF-backed document, writing the results into a file.
Definition: SkDocument.h:212