Flutter Engine
The Flutter Engine
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()
40 .setFontManager(ToolUtils::TestFontMgr())
41 .setTextShapingFactory(SkShapers::BestAvailable())
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 SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static SkString Basename(const char *fullPath)
Definition: SkOSPath.cpp:23
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()
DlVertices::Builder Builder
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
Definition: SkSize.h:52