Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
SkSVGOpenTypeSVGDecoder Class Reference

#include <SkSVGOpenTypeSVGDecoder.h>

Inheritance diagram for SkSVGOpenTypeSVGDecoder:
SkOpenTypeSVGDecoder

Public Member Functions

size_t approximateSize () override
 
bool render (SkCanvas &, int upem, SkGlyphID glyphId, SkColor foregroundColor, SkSpan< SkColor > palette) override
 
 ~SkSVGOpenTypeSVGDecoder () override
 
- Public Member Functions inherited from SkOpenTypeSVGDecoder
virtual size_t approximateSize ()=0
 
virtual bool render (SkCanvas &, int upem, SkGlyphID glyphId, SkColor foregroundColor, SkSpan< SkColor > palette)=0
 
virtual ~SkOpenTypeSVGDecoder ()=default
 

Static Public Member Functions

static std::unique_ptr< SkOpenTypeSVGDecoderMake (const uint8_t *svg, size_t svgLength)
 

Detailed Description

Definition at line 19 of file SkSVGOpenTypeSVGDecoder.h.

Constructor & Destructor Documentation

◆ ~SkSVGOpenTypeSVGDecoder()

SkSVGOpenTypeSVGDecoder::~SkSVGOpenTypeSVGDecoder ( )
overridedefault

Member Function Documentation

◆ approximateSize()

size_t SkSVGOpenTypeSVGDecoder::approximateSize ( )
overridevirtual

Each instance probably owns an SVG DOM. The instance may be cached so needs to report how much memory it retains.

Implements SkOpenTypeSVGDecoder.

Definition at line 123 of file SkSVGOpenTypeSVGDecoder.cpp.

123 {
124 // TODO
125 return fApproximateSize;
126}

◆ Make()

std::unique_ptr< SkOpenTypeSVGDecoder > SkSVGOpenTypeSVGDecoder::Make ( const uint8_t *  svg,
size_t  svgLength 
)
static

Definition at line 105 of file SkSVGOpenTypeSVGDecoder.cpp.

106 {
107 std::unique_ptr<SkStreamAsset> stream = SkMemoryStream::MakeDirect(svg, svgLength);
108 if (!stream) {
109 return nullptr;
110 }
112 builder.setResourceProvider(DataResourceProvider::Make());
113 // We shouldn't need to set this builder's font manager or shaping utils because hopefully
114 // the SVG we are decoding doesn't itself have <text> tags.
115 sk_sp<SkSVGDOM> skSvg = builder.make(*stream);
116 if (!skSvg) {
117 return nullptr;
118 }
119 return std::unique_ptr<SkOpenTypeSVGDecoder>(
120 new SkSVGOpenTypeSVGDecoder(std::move(skSvg), svgLength));
121}
static std::unique_ptr< SkMemoryStream > MakeDirect(const void *data, size_t length)
Definition: SkStream.cpp:310
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
const char * svg

◆ render()

bool SkSVGOpenTypeSVGDecoder::render ( SkCanvas canvas,
int  upem,
SkGlyphID  glyphId,
SkColor  foregroundColor,
SkSpan< SkColor palette 
)
overridevirtual

Implements SkOpenTypeSVGDecoder.

Definition at line 128 of file SkSVGOpenTypeSVGDecoder.cpp.

129 {
130 SkSize emSize = SkSize::Make(SkScalar(upem), SkScalar(upem));
131 fSkSvg->setContainerSize(emSize);
132
134 pctx.fInherited.fColor.set(foregroundColor);
135
137 if (!palette.empty()) {
138 for (auto&& [i, color] : SkMakeEnumerate(palette)) {
139 constexpr const size_t colorStringLen = sizeof("color") - 1;
140 char colorIdString[colorStringLen + kSkStrAppendU32_MaxSize + 1] = "color";
141 *SkStrAppendU32(colorIdString + colorStringLen, i) = 0;
142
143 namedColors.set(SkString(colorIdString), color);
144 }
145 pctx.fNamedColors = &namedColors;
146 }
147
148 constexpr const size_t glyphStringLen = sizeof("glyph") - 1;
149 char glyphIdString[glyphStringLen + kSkStrAppendU32_MaxSize + 1] = "glyph";
150 *SkStrAppendU32(glyphIdString + glyphStringLen, glyphId) = 0;
151
152 fSkSvg->renderNode(&canvas, pctx, glyphIdString);
153 return true;
154}
constexpr SkEnumerate< Iter > SkMakeEnumerate(C &c)
Definition: SkEnumerate.h:102
static constexpr int kSkStrAppendU32_MaxSize
Definition: SkString.h:84
char * SkStrAppendU32(char buffer[], uint32_t)
Definition: SkString.cpp:100
void renderNode(SkCanvas *, SkSVGPresentationContext &, const char *id) const
Definition: SkSVGDOM.cpp:476
void setContainerSize(const SkSize &)
Definition: SkSVGDOM.cpp:497
void set(SkSVGPropertyState state)
Definition: SkSVGTypes.h:70
constexpr bool empty() const
Definition: SkSpan_impl.h:96
V * set(K key, V val)
Definition: SkTHash.h:487
DlColor color
float SkScalar
Definition: extension.cpp:12
SkSVGProperty< SkSVGColorType, true > fColor
SkSVGPresentationAttributes fInherited
const skia_private::THashMap< SkString, SkSVGColorType > * fNamedColors
Definition: SkSize.h:52
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56

The documentation for this class was generated from the following files: