Skia
2D Graphics Library
SkSVGDOM.h
Go to the documentation of this file.
1 /*
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 
11 #include "include/core/SkFontMgr.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/core/SkSize.h"
14 #include "include/private/base/SkTemplates.h"
15 #include "modules/skresources/include/SkResources.h"
17 
18 class SkCanvas;
19 class SkDOM;
20 class SkStream;
21 class SkSVGNode;
23 class SkSVGSVG;
24 
25 class SK_API SkSVGDOM : public SkRefCnt {
26 public:
27  class Builder final {
28  public:
36 
41 
43 
44  private:
45  sk_sp<SkFontMgr> fFontMgr;
46  sk_sp<skresources::ResourceProvider> fResourceProvider;
47  };
48 
50  return Builder().make(str);
51  }
52 
56  SkSVGSVG* getRoot() const { return fRoot.get(); }
57 
67  void setContainerSize(const SkSize&);
68 
81  const SkSize& containerSize() const;
82 
83  // Returns the node with the given id, or nullptr if not found.
84  sk_sp<SkSVGNode>* findNodeById(const char* id);
85 
86  void render(SkCanvas*) const;
87 
89  void renderNode(SkCanvas*, SkSVGPresentationContext&, const char* id) const;
90 
91 private:
93  SkSVGIDMapper&&);
94 
95  const sk_sp<SkSVGSVG> fRoot;
96  const sk_sp<SkFontMgr> fFontMgr;
97  const sk_sp<skresources::ResourceProvider> fResourceProvider;
98  const SkSVGIDMapper fIDMapper;
99 
100  SkSize fContainerSize;
101 };
102 
103 #endif // SkSVGDOM_DEFINED
skia_private::THashMap< SkString, sk_sp< SkSVGNode > > SkSVGIDMapper
Definition: SkSVGIDMapper.h:17
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:99
Definition: SkRefCnt.h:119
Definition: SkSVGDOM.h:27
sk_sp< SkSVGDOM > make(SkStream &) const
Builder & setResourceProvider(sk_sp< skresources::ResourceProvider >)
Specify a resource provider for loading images etc.
Builder & setFontManager(sk_sp< SkFontMgr >)
Specify a font manager for loading fonts (e.g.
Definition: SkSVGDOM.h:25
const SkSize & containerSize() const
DEPRECATED: use getRoot()->intrinsicSize() to query the root element intrinsic size.
void renderNode(SkCanvas *, SkSVGPresentationContext &, const char *id) const
Render the node with the given id as if it were the only child of the root.
static sk_sp< SkSVGDOM > MakeFromStream(SkStream &str)
Definition: SkSVGDOM.h:49
void render(SkCanvas *) const
sk_sp< SkSVGNode > * findNodeById(const char *id)
SkSVGSVG * getRoot() const
Returns the root (outermost) SVG element.
Definition: SkSVGDOM.h:56
void setContainerSize(const SkSize &)
Specify a "container size" for the SVG dom.
Definition: SkSVGNode.h:95
Definition: SkSVGSVG.h:17
SkStream – abstraction for a source of bytes.
Definition: SkStream.h:29
Definition: SkSVGRenderContext.h:50
Definition: SkSize.h:51