Skia
2DGraphicsLibrary
 All Classes Namespaces 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 #ifdef SK_BUILD_FOR_WIN
23 struct IXpsOMObjectFactory;
24 #endif
25 
28 #define SK_ScalarDefaultRasterDPI 72.0f
29 
40 class SK_API SkDocument : public SkRefCnt {
41 public:
43  SkTime::DateTime fDateTime;
44  bool fEnabled;
45  OptionalTimestamp() : fEnabled(false) {}
46  };
47 
51  struct PDFMetadata {
89  };
90 
130  static sk_sp<SkDocument> MakePDF(SkWStream* stream,
131  SkScalar dpi,
132  const SkDocument::PDFMetadata& metadata,
133  sk_sp<SkPixelSerializer> jpegEncoder,
134  bool pdfa);
135 
136  static sk_sp<SkDocument> MakePDF(SkWStream* stream,
137  SkScalar dpi = SK_ScalarDefaultRasterDPI) {
138  return SkDocument::MakePDF(stream, dpi, SkDocument::PDFMetadata(),
139  nullptr, false);
140  }
141 
145  static sk_sp<SkDocument> MakePDF(const char outputFilePath[],
146  SkScalar dpi = SK_ScalarDefaultRasterDPI);
147 
148 #ifdef SK_BUILD_FOR_WIN
149 
170  static sk_sp<SkDocument> MakeXPS(SkWStream* stream,
171  IXpsOMObjectFactory* xpsFactory,
172  SkScalar dpi = SK_ScalarDefaultRasterDPI);
173 #endif
174 
180  SkCanvas* beginPage(SkScalar width, SkScalar height,
181  const SkRect* content = NULL);
182 
188  void endPage();
189 
196  void close();
197 
202  void abort();
203 
204 protected:
205  SkDocument(SkWStream*, void (*)(SkWStream*, bool aborted));
206 
207  // note: subclasses must call close() in their destructor, as the base class
208  // cannot do this for them.
209  virtual ~SkDocument();
210 
211  virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height,
212  const SkRect& content) = 0;
213  virtual void onEndPage() = 0;
214  virtual void onClose(SkWStream*) = 0;
215  virtual void onAbort() = 0;
216 
217  // Allows subclasses to write to the stream as pages are written.
218  SkWStream* getStream() { return fStream; }
219 
220  enum State {
221  kBetweenPages_State,
222  kInPage_State,
223  kClosed_State
224  };
225  State getState() const { return fState; }
226 
227 private:
228  SkWStream* fStream;
229  void (*fDoneProc)(SkWStream*, bool aborted);
230  State fState;
231 
232  typedef SkRefCnt INHERITED;
233 };
234 
235 #endif
SkString fCreator
If the document was converted to PDF from another format, the name of the conforming product that cre...
Definition: SkDocument.h:74
A Canvas encapsulates all of the state about drawing into a device (bitmap).
Definition: SkCanvas.h:59
SkString fKeywords
Keywords associated with the document.
Definition: SkDocument.h:68
Definition: SkRefCnt.h:125
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:59
Definition: SkDocument.h:42
OptionalTimestamp fModified
The date and time the document was most recently modified.
Definition: SkDocument.h:88
SkString fTitle
The document's title.
Definition: SkDocument.h:55
SkString fProducer
The product that is converting this document to PDF.
Definition: SkDocument.h:80
Optional metadata to be passed into the PDF factory function.
Definition: SkDocument.h:51
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:246
OptionalTimestamp fCreation
The date and time the document was created.
Definition: SkDocument.h:84
Definition: SkStream.h:182
Definition: SkRect.h:404
SkString fSubject
The subject of the document.
Definition: SkDocument.h:63
Definition: SkTime.h:22
High-level API for creating a document-based canvas.
Definition: SkDocument.h:40
Light weight class for managing strings.
Definition: SkString.h:121