blob: 2c0bc2717cc330d2f42a7794fe7b80d1e1c8e59a [file] [log] [blame]
Florin Malitab3418102020-10-15 18:10:29 -04001/*
2 * Copyright 2016 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 SkSVGDOM_DEFINED
9#define SkSVGDOM_DEFINED
10
Florin Malita7006e152020-11-10 15:24:59 -050011#include "include/core/SkFontMgr.h"
Florin Malitab3418102020-10-15 18:10:29 -040012#include "include/core/SkRefCnt.h"
13#include "include/core/SkSize.h"
14#include "include/private/SkTemplates.h"
15#include "modules/svg/include/SkSVGIDMapper.h"
16
17class SkCanvas;
18class SkDOM;
19class SkStream;
20class SkSVGNode;
Florin Malita7006e152020-11-10 15:24:59 -050021class SkSVGSVG;
Florin Malitab3418102020-10-15 18:10:29 -040022
23class SkSVGDOM : public SkRefCnt {
24public:
Florin Malita7006e152020-11-10 15:24:59 -050025 class Builder final {
26 public:
27 /**
28 * Specify a font manager for loading SVG fonts.
29 */
30 Builder& setFontManager(sk_sp<SkFontMgr>);
Florin Malitab3418102020-10-15 18:10:29 -040031
Florin Malita7006e152020-11-10 15:24:59 -050032 sk_sp<SkSVGDOM> make(SkStream&) const;
33
34 private:
Florin Malita64400d92021-01-27 18:51:44 +000035 sk_sp<SkFontMgr> fFontMgr;
Florin Malita7006e152020-11-10 15:24:59 -050036 };
37
38 static sk_sp<SkSVGDOM> MakeFromStream(SkStream& str) {
39 return Builder().make(str);
40 }
Florin Malitab3418102020-10-15 18:10:29 -040041
42 const SkSize& containerSize() const;
43 void setContainerSize(const SkSize&);
44
Florin Malitab3418102020-10-15 18:10:29 -040045 // Returns the node with the given id, or nullptr if not found.
46 sk_sp<SkSVGNode>* findNodeById(const char* id);
47
48 void render(SkCanvas*) const;
49
50private:
Florin Malita64400d92021-01-27 18:51:44 +000051 SkSVGDOM(sk_sp<SkSVGSVG>, sk_sp<SkFontMgr>, SkSVGIDMapper&&);
Florin Malitab3418102020-10-15 18:10:29 -040052
Florin Malita64400d92021-01-27 18:51:44 +000053 const sk_sp<SkSVGSVG> fRoot;
54 const sk_sp<SkFontMgr> fFontMgr;
55 const SkSVGIDMapper fIDMapper;
Florin Malitab3418102020-10-15 18:10:29 -040056
Florin Malita7006e152020-11-10 15:24:59 -050057 SkSize fContainerSize;
Florin Malitab3418102020-10-15 18:10:29 -040058};
59
60#endif // SkSVGDOM_DEFINED