gfx/skia/trunk/include/core/SkDocument.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef SkDocument_DEFINED
michael@0 9 #define SkDocument_DEFINED
michael@0 10
michael@0 11 #include "SkBitmap.h"
michael@0 12 #include "SkPicture.h"
michael@0 13 #include "SkRect.h"
michael@0 14 #include "SkRefCnt.h"
michael@0 15
michael@0 16 class SkCanvas;
michael@0 17 class SkWStream;
michael@0 18
michael@0 19 /** SK_ScalarDefaultDPI is 72 DPI.
michael@0 20 */
michael@0 21 #define SK_ScalarDefaultRasterDPI 72.0f
michael@0 22
michael@0 23 /**
michael@0 24 * High-level API for creating a document-based canvas. To use..
michael@0 25 *
michael@0 26 * 1. Create a document, specifying a stream to store the output.
michael@0 27 * 2. For each "page" of content:
michael@0 28 * a. canvas = doc->beginPage(...)
michael@0 29 * b. draw_my_content(canvas);
michael@0 30 * c. doc->endPage();
michael@0 31 * 3. Close the document with doc->close().
michael@0 32 */
michael@0 33 class SkDocument : public SkRefCnt {
michael@0 34 public:
michael@0 35 SK_DECLARE_INST_COUNT(SkDocument)
michael@0 36
michael@0 37 /**
michael@0 38 * Create a PDF-backed document, writing the results into a file.
michael@0 39 * If there is an error trying to create the doc, returns NULL.
michael@0 40 * encoder sets the DCTEncoder for images, to encode a bitmap
michael@0 41 * as JPEG (DCT).
michael@0 42 * rasterDpi - the DPI at which features without native PDF support
michael@0 43 * will be rasterized (e.g. draw image with perspective,
michael@0 44 * draw text with perspective, ...)
michael@0 45 * A larger DPI would create a PDF that reflects the original
michael@0 46 * intent with better fidelity, but it can make for larger
michael@0 47 * PDF files too, which would use more memory while rendering,
michael@0 48 * and it would be slower to be processed or sent online or
michael@0 49 * to printer.
michael@0 50 */
michael@0 51 static SkDocument* CreatePDF(
michael@0 52 const char filename[],
michael@0 53 SkPicture::EncodeBitmap encoder = NULL,
michael@0 54 SkScalar rasterDpi = SK_ScalarDefaultRasterDPI);
michael@0 55
michael@0 56 /**
michael@0 57 * Create a PDF-backed document, writing the results into a stream.
michael@0 58 * If there is an error trying to create the doc, returns NULL.
michael@0 59 *
michael@0 60 * The document may write to the stream at anytime during its lifetime,
michael@0 61 * until either close() is called or the document is deleted. Once close()
michael@0 62 * has been called, and all of the data has been written to the stream,
michael@0 63 * if there is a Done proc provided, it will be called with the stream.
michael@0 64 * The proc can delete the stream, or whatever it needs to do.
michael@0 65 * encoder sets the DCTEncoder for images, to encode a bitmap
michael@0 66 * as JPEG (DCT).
michael@0 67 * Done - clean up method intended to allow deletion of the stream.
michael@0 68 * Its aborted parameter is true if the cleanup is due to an abort
michael@0 69 * call. It is false otherwise.
michael@0 70 * rasterDpi - the DPI at which features without native PDF support
michael@0 71 * will be rasterized (e.g. draw image with perspective,
michael@0 72 * draw text with perspective, ...)
michael@0 73 * A larger DPI would create a PDF that reflects the original
michael@0 74 * intent with better fidelity, but it can make for larger
michael@0 75 * PDF files too, which would use more memory while rendering,
michael@0 76 * and it would be slower to be processed or sent online or
michael@0 77 * to printer. */
michael@0 78 static SkDocument* CreatePDF(
michael@0 79 SkWStream*, void (*Done)(SkWStream*,bool aborted) = NULL,
michael@0 80 SkPicture::EncodeBitmap encoder = NULL,
michael@0 81 SkScalar rasterDpi = SK_ScalarDefaultRasterDPI);
michael@0 82
michael@0 83 /**
michael@0 84 * Begin a new page for the document, returning the canvas that will draw
michael@0 85 * into the page. The document owns this canvas, and it will go out of
michael@0 86 * scope when endPage() or close() is called, or the document is deleted.
michael@0 87 */
michael@0 88 SkCanvas* beginPage(SkScalar width, SkScalar height,
michael@0 89 const SkRect* content = NULL);
michael@0 90
michael@0 91 /**
michael@0 92 * Call endPage() when the content for the current page has been drawn
michael@0 93 * (into the canvas returned by beginPage()). After this call the canvas
michael@0 94 * returned by beginPage() will be out-of-scope.
michael@0 95 */
michael@0 96 void endPage();
michael@0 97
michael@0 98 /**
michael@0 99 * Call close() when all pages have been drawn. This will close the file
michael@0 100 * or stream holding the document's contents. After close() the document
michael@0 101 * can no longer add new pages. Deleting the document will automatically
michael@0 102 * call close() if need be.
michael@0 103 * Returns true on success or false on failure.
michael@0 104 */
michael@0 105 bool close();
michael@0 106
michael@0 107 /**
michael@0 108 * Call abort() to stop producing the document immediately.
michael@0 109 * The stream output must be ignored, and should not be trusted.
michael@0 110 */
michael@0 111 void abort();
michael@0 112
michael@0 113 protected:
michael@0 114 SkDocument(SkWStream*, void (*)(SkWStream*, bool aborted));
michael@0 115 // note: subclasses must call close() in their destructor, as the base class
michael@0 116 // cannot do this for them.
michael@0 117 virtual ~SkDocument();
michael@0 118
michael@0 119 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height,
michael@0 120 const SkRect& content) = 0;
michael@0 121 virtual void onEndPage() = 0;
michael@0 122 virtual bool onClose(SkWStream*) = 0;
michael@0 123 virtual void onAbort() = 0;
michael@0 124
michael@0 125 enum State {
michael@0 126 kBetweenPages_State,
michael@0 127 kInPage_State,
michael@0 128 kClosed_State
michael@0 129 };
michael@0 130 State getState() const { return fState; }
michael@0 131
michael@0 132 private:
michael@0 133 SkWStream* fStream;
michael@0 134 void (*fDoneProc)(SkWStream*, bool aborted);
michael@0 135 State fState;
michael@0 136
michael@0 137 typedef SkRefCnt INHERITED;
michael@0 138 };
michael@0 139
michael@0 140 #endif

mercurial