2013-06-07 20:30:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkDocument_DEFINED
|
|
|
|
#define SkDocument_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
2013-06-07 20:30:16 +00:00
|
|
|
|
|
|
|
class SkCanvas;
|
|
|
|
class SkWStream;
|
2018-09-20 14:26:25 +00:00
|
|
|
struct SkRect;
|
2013-06-07 20:30:16 +00:00
|
|
|
|
2018-09-20 14:26:25 +00:00
|
|
|
/** SK_ScalarDefaultDPI is 72 dots per inch. */
|
|
|
|
static constexpr SkScalar SK_ScalarDefaultRasterDPI = 72.0f;
|
2013-10-21 17:14:37 +00:00
|
|
|
|
2013-06-07 20:30:16 +00:00
|
|
|
/**
|
|
|
|
* 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().
|
|
|
|
*/
|
2014-11-14 21:24:18 +00:00
|
|
|
class SK_API SkDocument : public SkRefCnt {
|
2013-06-07 20:30:16 +00:00
|
|
|
public:
|
2016-04-27 14:45:18 +00:00
|
|
|
|
2013-06-07 20:30:16 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-12-14 18:25:04 +00:00
|
|
|
SkCanvas* beginPage(SkScalar width, SkScalar height, const SkRect* content = nullptr);
|
2013-06-07 20:30:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void endPage();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-09-22 21:12:46 +00:00
|
|
|
void close();
|
2013-10-09 21:09:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call abort() to stop producing the document immediately.
|
|
|
|
* The stream output must be ignored, and should not be trusted.
|
|
|
|
*/
|
|
|
|
void abort();
|
2013-06-07 20:30:16 +00:00
|
|
|
|
|
|
|
protected:
|
2018-01-08 20:02:36 +00:00
|
|
|
SkDocument(SkWStream*);
|
2015-02-20 02:50:05 +00:00
|
|
|
|
2013-06-07 20:30:16 +00:00
|
|
|
// note: subclasses must call close() in their destructor, as the base class
|
|
|
|
// cannot do this for them.
|
|
|
|
virtual ~SkDocument();
|
|
|
|
|
2017-07-02 02:17:15 +00:00
|
|
|
virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height) = 0;
|
2013-06-07 20:30:16 +00:00
|
|
|
virtual void onEndPage() = 0;
|
2016-09-22 21:12:46 +00:00
|
|
|
virtual void onClose(SkWStream*) = 0;
|
2013-10-09 21:09:00 +00:00
|
|
|
virtual void onAbort() = 0;
|
2013-06-07 20:30:16 +00:00
|
|
|
|
2014-10-30 18:29:00 +00:00
|
|
|
// Allows subclasses to write to the stream as pages are written.
|
|
|
|
SkWStream* getStream() { return fStream; }
|
|
|
|
|
2013-06-07 20:30:16 +00:00
|
|
|
enum State {
|
|
|
|
kBetweenPages_State,
|
|
|
|
kInPage_State,
|
|
|
|
kClosed_State
|
|
|
|
};
|
|
|
|
State getState() const { return fState; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkWStream* fStream;
|
2013-06-08 07:01:13 +00:00
|
|
|
State fState;
|
2013-07-11 22:29:29 +00:00
|
|
|
|
|
|
|
typedef SkRefCnt INHERITED;
|
2013-06-07 20:30:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|