blob: c9e0b312dc03dae9971f20d56ca018f394486f8a [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"
Florin Malita24df67d2021-01-26 18:45:34 -050015#include "modules/skresources/include/SkResources.h"
Florin Malitab3418102020-10-15 18:10:29 -040016#include "modules/svg/include/SkSVGIDMapper.h"
17
18class SkCanvas;
19class SkDOM;
20class SkStream;
21class SkSVGNode;
Florin Malita7006e152020-11-10 15:24:59 -050022class SkSVGSVG;
Florin Malitab3418102020-10-15 18:10:29 -040023
24class SkSVGDOM : public SkRefCnt {
25public:
Florin Malita7006e152020-11-10 15:24:59 -050026 class Builder final {
27 public:
28 /**
29 * Specify a font manager for loading SVG fonts.
30 */
31 Builder& setFontManager(sk_sp<SkFontMgr>);
Florin Malitab3418102020-10-15 18:10:29 -040032
Florin Malita24df67d2021-01-26 18:45:34 -050033 /**
34 * Specify a resource provider for loading images etc.
35 */
36 Builder& setResourceProvider(sk_sp<skresources::ResourceProvider>);
37
Florin Malita7006e152020-11-10 15:24:59 -050038 sk_sp<SkSVGDOM> make(SkStream&) const;
39
40 private:
Florin Malita24df67d2021-01-26 18:45:34 -050041 sk_sp<SkFontMgr> fFontMgr;
42 sk_sp<skresources::ResourceProvider> fResourceProvider;
Florin Malita7006e152020-11-10 15:24:59 -050043 };
44
45 static sk_sp<SkSVGDOM> MakeFromStream(SkStream& str) {
46 return Builder().make(str);
47 }
Florin Malitab3418102020-10-15 18:10:29 -040048
49 const SkSize& containerSize() const;
50 void setContainerSize(const SkSize&);
51
Florin Malitab3418102020-10-15 18:10:29 -040052 // Returns the node with the given id, or nullptr if not found.
53 sk_sp<SkSVGNode>* findNodeById(const char* id);
54
55 void render(SkCanvas*) const;
56
57private:
Florin Malita24df67d2021-01-26 18:45:34 -050058 SkSVGDOM(sk_sp<SkSVGSVG>, sk_sp<SkFontMgr>, sk_sp<skresources::ResourceProvider>,
59 SkSVGIDMapper&&);
Florin Malitab3418102020-10-15 18:10:29 -040060
Florin Malita24df67d2021-01-26 18:45:34 -050061 const sk_sp<SkSVGSVG> fRoot;
62 const sk_sp<SkFontMgr> fFontMgr;
63 const sk_sp<skresources::ResourceProvider> fResourceProvider;
64 const SkSVGIDMapper fIDMapper;
Florin Malitab3418102020-10-15 18:10:29 -040065
Florin Malita7006e152020-11-10 15:24:59 -050066 SkSize fContainerSize;
Florin Malitab3418102020-10-15 18:10:29 -040067};
68
69#endif // SkSVGDOM_DEFINED