blob: 30c9198c5bd6e2aa034faa0c1473900f3f245f3e [file] [log] [blame]
fmalita2aafe6f2015-02-06 12:51:10 -08001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/svg/SkSVGCanvas.h"
9#include "src/core/SkMakeUnique.h"
10#include "src/svg/SkSVGDevice.h"
11#include "src/xml/SkXMLWriter.h"
fmalita2aafe6f2015-02-06 12:51:10 -080012
Florin Malitaabc96532019-07-19 09:11:29 -040013std::unique_ptr<SkCanvas> SkSVGCanvas::Make(const SkRect& bounds, SkWStream* writer,
14 uint32_t flags) {
fmalita2aafe6f2015-02-06 12:51:10 -080015 // TODO: pass full bounds to the device
Florin Malita49d140d2019-08-21 15:40:46 -040016 const auto size = bounds.roundOut().size();
17 const auto xml_flags = (flags & kNoPrettyXML_Flag) ? SkToU32(SkXMLStreamWriter::kNoPretty_Flag)
18 : 0;
fmalita2aafe6f2015-02-06 12:51:10 -080019
Florin Malita49d140d2019-08-21 15:40:46 -040020 auto svgDevice = SkSVGDevice::Make(size,
21 skstd::make_unique<SkXMLStreamWriter>(writer, xml_flags),
22 flags);
Florin Malita99822ac2017-09-19 16:12:25 -040023
Florin Malita49d140d2019-08-21 15:40:46 -040024 return svgDevice ? skstd::make_unique<SkCanvas>(std::move(svgDevice))
Florin Malita562017b2019-02-14 13:42:15 -050025 : nullptr;
Florin Malita99822ac2017-09-19 16:12:25 -040026}