Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SVGFileSlide.cpp
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
9
10#if defined(SK_ENABLE_SVG)
11
17#include "src/core/SkOSFile.h"
18#include "src/utils/SkOSPath.h"
19#include "src/xml/SkDOM.h"
21#include "tools/viewer/Slide.h"
22
23namespace {
24
25class SVGFileSlide : public Slide {
26public:
27 SVGFileSlide(const SkString& path) : fPath(path) {
28 fName = SkStringPrintf("[%s]", SkOSPath::Basename(path.c_str()).c_str());
29 }
30 ~SVGFileSlide() override = default;
31
32 void load(SkScalar w, SkScalar h) override {
33 SkFILEStream svgStream(fPath.c_str());
34 if (!svgStream.isValid()) {
35 SkDebugf("file not found: \"%s\"\n", fPath.c_str());
36 return;
37 }
38
39 fDom = SkSVGDOM::Builder()
42 .make(svgStream);
43 if (fDom) {
44 fDom->setContainerSize(SkSize{w, h});
45 }
46 }
47
48 void draw(SkCanvas* canvas) override {
49 if (fDom) {
50 fDom->render(canvas);
51 }
52 }
53
54 void resize(SkScalar w, SkScalar h) override {
55 if (fDom) {
56 fDom->setContainerSize({w, h});
57 }
58 }
59
60private:
61 sk_sp<SkSVGDOM> fDom;
63};
64
65} // anonymous namespace
66
67Slide* CreateSampleSVGFileSlide(const SkString& filename) {
68 return new SVGFileSlide(filename);
69}
70#endif // defined(SK_ENABLE_SVG)
SkPath fPath
const char * fName
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
static SkString Basename(const char *fullPath)
Definition SkOSPath.cpp:23
Builder & setTextShapingFactory(sk_sp< SkShapers::Factory >)
Definition SkSVGDOM.cpp:400
sk_sp< SkSVGDOM > make(SkStream &) const
Definition SkSVGDOM.cpp:405
Builder & setFontManager(sk_sp< SkFontMgr >)
Definition SkSVGDOM.cpp:390
void setContainerSize(const SkSize &)
Definition SkSVGDOM.cpp:488
const char * c_str() const
Definition SkString.h:133
Definition Slide.h:29
virtual void resize(SkScalar winWidth, SkScalar winHeight)
Definition Slide.h:41
virtual void load(SkScalar winWidth, SkScalar winHeight)
Definition Slide.h:40
virtual void draw(SkCanvas *canvas)=0
float SkScalar
Definition extension.cpp:12
sk_sp< Factory > BestAvailable()
sk_sp< SkFontMgr > TestFontMgr()
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
SkScalar w
SkScalar h