Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
TestSVGTypeface.h
Go to the documentation of this file.
1/*
2 * Copyright 2014 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 TestSVGTypeface_DEFINED
9#define TestSVGTypeface_DEFINED
10
15#include "include/core/SkRect.h"
18#include "include/core/SkSpan.h"
26#include "src/core/SkTHash.h"
27
28#include <memory>
29
30class SkCanvas;
31class SkDescriptor;
33class SkFontStyle;
34class SkGlyph;
35class SkPath;
36class SkScalerContext;
37class SkSVGDOM;
38class SkWStream;
42
43#ifdef SK_ENABLE_SVG
44
45struct SkSVGTestTypefaceGlyphData {
46 const char* fSvgResourcePath;
47 SkPoint fOrigin; // y-down
48 SkScalar fAdvance;
49 SkUnichar fUnicode; // TODO: this limits to 1:1
50};
51
52class TestSVGTypeface : public SkTypeface {
53public:
54 ~TestSVGTypeface() override;
55 SkVector getAdvance(SkGlyphID) const;
56 void getFontMetrics(SkFontMetrics* metrics) const;
57
59 static sk_sp<TestSVGTypeface> Planets();
60 void exportTtxCbdt(SkWStream*, SkSpan<unsigned> strikeSizes) const;
61 void exportTtxSbix(SkWStream*, SkSpan<unsigned> strikeSizes) const;
62 void exportTtxColr(SkWStream*) const;
63 virtual bool getPathOp(SkColor, SkPathOp*) const = 0;
64
65 struct GlyfLayerInfo {
66 GlyfLayerInfo(int layerColorIndex, SkIRect bounds)
67 : fLayerColorIndex(layerColorIndex), fBounds(bounds) {}
68 int fLayerColorIndex;
70 };
71 struct GlyfInfo {
72 GlyfInfo() : fBounds(SkIRect::MakeEmpty()) {}
75 };
76
77protected:
78 void exportTtxCommon(
79 SkWStream*, const char* type, const skia_private::TArray<GlyfInfo>* = nullptr) const;
80
81 std::unique_ptr<SkScalerContext> onCreateScalerContext(const SkScalerContextEffects&,
82 const SkDescriptor* desc) const override;
83 void onFilterRec(SkScalerContextRec* rec) const override;
84 void getGlyphToUnicodeMap(SkUnichar*) const override;
85 std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override;
86
87 sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
88 return sk_ref_sp(this);
89 }
90
91 void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const override = 0;
92
93 void onCharsToGlyphs(const SkUnichar* chars, int count, SkGlyphID glyphs[]) const override;
94
95 void getPostScriptGlyphNames(SkString*) const override {}
96
97 int onCountGlyphs() const override { return fGlyphCount; }
98
99 int onGetUPEM() const override { return fUpem; }
100
101 void onGetFamilyName(SkString* familyName) const override;
102 bool onGetPostScriptName(SkString*) const override;
104
105 bool onGlyphMaskNeedsCurrentColor() const override { return false; }
106
108 int coordinateCount) const override {
109 return 0;
110 }
111
113 int parameterCount) const override {
114 return 0;
115 }
116
117 int onGetTableTags(SkFontTableTag tags[]) const override { return 0; }
118
120 size_t offset,
121 size_t length,
122 void* data) const override {
123 return 0;
124 }
125
126private:
127 TestSVGTypeface(const char* name,
128 int upem,
129 const SkFontMetrics& metrics,
131 const SkFontStyle& style);
132 struct Glyph {
133 Glyph();
134 ~Glyph();
135 SkPoint fOrigin;
136 SkScalar fAdvance;
137 const char* fResourcePath;
138
139 SkSize size() const;
140 void render(SkCanvas*) const;
141
142 private:
143 // Lazily parses the SVG from fResourcePath, and manages mutex locking.
144 template <typename Fn> void withSVG(Fn&&) const;
145
146 // The mutex guards lazy parsing of the SVG, but also predates that.
147 // Must be SkSVGDOM::render() is not thread safe?
148 // If not, an SkOnce is enough here.
149 mutable SkMutex fSvgMutex;
150 mutable bool fParsedSvg = false;
151 mutable sk_sp<SkSVGDOM> fSvg;
152 };
153
155 int fUpem;
156 const SkFontMetrics fFontMetrics;
157 std::unique_ptr<Glyph[]> fGlyphs;
158 int fGlyphCount;
160 friend class SkTestSVGScalerContext;
161};
162
163#endif // SK_ENABLE_SVG
164
165#endif // TestSVGTypeface_DEFINED
const char * fName
uint16_t glyphs[5]
int count
sktext::gpu::Glyph Glyph
const SkRect fBounds
static sk_sp< SkImage > render(const SkPicture &p)
uint32_t SkColor
Definition SkColor.h:37
SkPathOp
Definition SkPathOps.h:22
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
uint32_t SkFontTableTag
Definition SkTypeface.h:41
int32_t SkUnichar
Definition SkTypes.h:175
uint16_t SkGlyphID
Definition SkTypes.h:179
virtual void getPostScriptGlyphNames(SkString *) const =0
virtual std::unique_ptr< SkAdvancedTypefaceMetrics > onGetAdvancedMetrics() const =0
virtual void getGlyphToUnicodeMap(SkUnichar *dstArray) const =0
virtual std::unique_ptr< SkScalerContext > onCreateScalerContext(const SkScalerContextEffects &, const SkDescriptor *) const =0
virtual int onCountGlyphs() const =0
virtual int onGetTableTags(SkFontTableTag tags[]) const =0
virtual void onGetFontDescriptor(SkFontDescriptor *, bool *isLocal) const =0
virtual sk_sp< SkTypeface > onMakeClone(const SkFontArguments &) const =0
virtual size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void *data) const =0
virtual bool onGetPostScriptName(SkString *) const =0
virtual void onGetFamilyName(SkString *familyName) const =0
virtual void onFilterRec(SkScalerContextRec *) const =0
virtual bool onGlyphMaskNeedsCurrentColor() const =0
virtual LocalizedStrings * onCreateFamilyNameIterator() const =0
virtual int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[], int parameterCount) const =0
virtual void onCharsToGlyphs(const SkUnichar *chars, int count, SkGlyphID glyphs[]) const =0
virtual int onGetUPEM() const =0
virtual int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[], int coordinateCount) const =0
float SkScalar
Definition extension.cpp:12
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const char * name
Definition fuchsia.cc:50
size_t length
Optional< SkRect > bounds
Definition SkRecords.h:189
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
Point offset