fmalita | 2aafe6f | 2015-02-06 12:51:10 -0800 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/svg/SkSVGCanvas.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "src/svg/SkSVGDevice.h" |
| 10 | #include "src/xml/SkXMLWriter.h" |
fmalita | 2aafe6f | 2015-02-06 12:51:10 -0800 | [diff] [blame] | 11 | |
Florin Malita | abc9653 | 2019-07-19 09:11:29 -0400 | [diff] [blame] | 12 | std::unique_ptr<SkCanvas> SkSVGCanvas::Make(const SkRect& bounds, SkWStream* writer, |
| 13 | uint32_t flags) { |
fmalita | 2aafe6f | 2015-02-06 12:51:10 -0800 | [diff] [blame] | 14 | // TODO: pass full bounds to the device |
Florin Malita | 49d140d | 2019-08-21 15:40:46 -0400 | [diff] [blame] | 15 | const auto size = bounds.roundOut().size(); |
| 16 | const auto xml_flags = (flags & kNoPrettyXML_Flag) ? SkToU32(SkXMLStreamWriter::kNoPretty_Flag) |
| 17 | : 0; |
fmalita | 2aafe6f | 2015-02-06 12:51:10 -0800 | [diff] [blame] | 18 | |
Florin Malita | 49d140d | 2019-08-21 15:40:46 -0400 | [diff] [blame] | 19 | auto svgDevice = SkSVGDevice::Make(size, |
Mike Klein | f46d5ca | 2019-12-11 10:45:01 -0500 | [diff] [blame] | 20 | std::make_unique<SkXMLStreamWriter>(writer, xml_flags), |
Florin Malita | 49d140d | 2019-08-21 15:40:46 -0400 | [diff] [blame] | 21 | flags); |
Florin Malita | 99822ac | 2017-09-19 16:12:25 -0400 | [diff] [blame] | 22 | |
Mike Klein | f46d5ca | 2019-12-11 10:45:01 -0500 | [diff] [blame] | 23 | return svgDevice ? std::make_unique<SkCanvas>(std::move(svgDevice)) |
Florin Malita | 562017b | 2019-02-14 13:42:15 -0500 | [diff] [blame] | 24 | : nullptr; |
Florin Malita | 99822ac | 2017-09-19 16:12:25 -0400 | [diff] [blame] | 25 | } |