| 1 |
/* |
| 2 |
* Copyright 2015 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 SkSVGCanvas_DEFINED |
| 9 |
#define SkSVGCanvas_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkTypes.h" |
| 12 |
|
| 13 |
#include <cstdint> |
| 14 |
#include <memory> |
| 15 |
|
| 16 |
class SkCanvas; |
| 17 |
class SkWStream; |
| 18 |
class SkPixmap; |
| 19 |
struct SkRect; |
| 20 |
|
| 21 |
class SK_API SkSVGCanvas { |
| 22 |
public: |
| 23 |
enum Flags { |
| 24 |
kConvertTextToPaths_Flag = 0x01, // emit text as <path>s |
| 25 |
kNoPrettyXML_Flag = 0x02, // suppress newlines and tabs in output |
| 26 |
kRelativePathEncoding_Flag = 0x04, // use relative commands for path encoding |
| 27 |
}; |
| 28 |
|
| 29 |
using EncodePngCallback = bool (*)(SkWStream* dst, const SkPixmap& src); |
| 30 |
|
| 31 |
struct Options { |
| 32 |
Flags flags = static_cast<Flags>(0x00); |
| 33 |
|
| 34 |
/** Clients can provide a way to encode png. |
| 35 |
* |
| 36 |
* If `pngEncoder` is null and `SK_DISABLE_LEGACY_SVG_FACTORIES` isn't |
| 37 |
* set then this will be (temporarily, until the legacy mode is |
| 38 |
* removed) filled based on presence of |
| 39 |
* `SK_CODEC_ENCODES_PNG_WITH_RUST` and/or |
| 40 |
* `SK_CODEC_ENCODES_PNG_WITH_LIBPNG`. |
| 41 |
*/ |
| 42 |
EncodePngCallback pngEncoder = nullptr; |
| 43 |
}; |
| 44 |
|
| 45 |
/** |
| 46 |
* Returns a new canvas that will generate SVG commands from its draw calls, and send |
| 47 |
* them to the provided stream. Ownership of the stream is not transfered, and it must |
| 48 |
* remain valid for the lifetime of the returned canvas. |
| 49 |
* |
| 50 |
* The canvas may buffer some drawing calls, so the output is not guaranteed to be valid |
| 51 |
* or complete until the canvas instance is deleted. |
| 52 |
* |
| 53 |
* The 'bounds' parameter defines an initial SVG viewport (viewBox attribute on the root |
| 54 |
* SVG element). |
| 55 |
*/ |
| 56 |
static std::unique_ptr<SkCanvas> Make(const SkRect& bounds, SkWStream*, Options opts); |
| 57 |
#if !defined(SK_DISABLE_LEGACY_SVG_FACTORIES) |
| 58 |
static std::unique_ptr<SkCanvas> Make(const SkRect& bounds, SkWStream*, uint32_t flags = 0); |
| 59 |
#endif |
| 60 |
}; |
| 61 |
|
| 62 |
#endif |