Flutter Engine
The Flutter Engine
Functions
fonts.cpp File Reference
#include "export.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#include "third_party/skia/include/ports/SkFontMgr_empty.h"
#include "third_party/skia/modules/skparagraph/include/FontCollection.h"
#include "third_party/skia/modules/skparagraph/include/TypefaceFontProvider.h"
#include "wrappers.h"
#include <memory>

Go to the source code of this file.

Functions

SKWASM_EXPORT FlutterFontCollectionfontCollection_create ()
 
SKWASM_EXPORT void fontCollection_dispose (FlutterFontCollection *collection)
 
static sk_sp< SkFontMgrdefault_fontmgr ()
 
SKWASM_EXPORT SkTypefacetypeface_create (SkData *fontData)
 
SKWASM_EXPORT void typeface_dispose (SkTypeface *typeface)
 
SKWASM_EXPORT int typefaces_filterCoveredCodePoints (SkTypeface **typefaces, int typefaceCount, SkUnichar *codePoints, int codePointCount)
 
SKWASM_EXPORT void fontCollection_registerTypeface (FlutterFontCollection *collection, SkTypeface *typeface, SkString *fontName)
 
SKWASM_EXPORT void fontCollection_clearCaches (FlutterFontCollection *collection)
 

Function Documentation

◆ default_fontmgr()

static sk_sp< SkFontMgr > default_fontmgr ( )
static

Definition at line 32 of file fonts.cpp.

32 {
34 return mgr;
35}
SK_API sk_sp< SkFontMgr > SkFontMgr_New_Custom_Empty()

◆ fontCollection_clearCaches()

SKWASM_EXPORT void fontCollection_clearCaches ( FlutterFontCollection collection)

Definition at line 92 of file fonts.cpp.

93 {
94 collection->collection->clearCaches();
95}
sk_sp< skia::textlayout::FontCollection > collection
Definition: wrappers.h:33

◆ fontCollection_create()

SKWASM_EXPORT FlutterFontCollection * fontCollection_create ( )

Definition at line 17 of file fonts.cpp.

17 {
18 auto collection = sk_make_sp<FontCollection>();
19 auto provider = sk_make_sp<TypefaceFontProvider>();
20 collection->enableFontFallback();
21 collection->setDefaultFontManager(provider, "Roboto");
22 return new FlutterFontCollection{
23 std::move(collection),
24 std::move(provider),
25 };
26}

◆ fontCollection_dispose()

SKWASM_EXPORT void fontCollection_dispose ( FlutterFontCollection collection)

Definition at line 28 of file fonts.cpp.

28 {
29 delete collection;
30}

◆ fontCollection_registerTypeface()

SKWASM_EXPORT void fontCollection_registerTypeface ( FlutterFontCollection collection,
SkTypeface typeface,
SkString fontName 
)

Definition at line 79 of file fonts.cpp.

82 {
83 if (fontName) {
84 SkString alias = *fontName;
85 collection->provider->registerTypeface(sk_ref_sp<SkTypeface>(typeface),
86 alias);
87 } else {
88 collection->provider->registerTypeface(sk_ref_sp<SkTypeface>(typeface));
89 }
90}
size_t registerTypeface(sk_sp< SkTypeface > typeface)
sk_sp< skia::textlayout::TypefaceFontProvider > provider
Definition: wrappers.h:34

◆ typeface_create()

SKWASM_EXPORT SkTypeface * typeface_create ( SkData fontData)

Definition at line 37 of file fonts.cpp.

37 {
38 auto typeface = default_fontmgr()->makeFromData(sk_ref_sp<SkData>(fontData));
39 return typeface.release();
40}
sk_sp< SkTypeface > makeFromData(sk_sp< SkData >, int ttcIndex=0) const
Definition: SkFontMgr.cpp:120
T * release()
Definition: SkRefCnt.h:324
static sk_sp< SkFontMgr > default_fontmgr()
Definition: fonts.cpp:32

◆ typeface_dispose()

SKWASM_EXPORT void typeface_dispose ( SkTypeface typeface)

Definition at line 42 of file fonts.cpp.

42 {
43 typeface->unref();
44}
void unref() const
Definition: SkRefCnt.h:72

◆ typefaces_filterCoveredCodePoints()

SKWASM_EXPORT int typefaces_filterCoveredCodePoints ( SkTypeface **  typefaces,
int  typefaceCount,
SkUnichar codePoints,
int  codePointCount 
)

Definition at line 49 of file fonts.cpp.

52 {
53 std::unique_ptr<SkGlyphID[]> glyphBuffer =
54 std::make_unique<SkGlyphID[]>(codePointCount);
55 SkGlyphID* glyphPointer = glyphBuffer.get();
56 int remainingCodePointCount = codePointCount;
57 for (int typefaceIndex = 0; typefaceIndex < typefaceCount; typefaceIndex++) {
58 typefaces[typefaceIndex]->unicharsToGlyphs(
59 codePoints, remainingCodePointCount, glyphPointer);
60 int outputIndex = 0;
61 for (int inputIndex = 0; inputIndex < remainingCodePointCount;
62 inputIndex++) {
63 if (glyphPointer[inputIndex] == 0) {
64 if (outputIndex != inputIndex) {
65 codePoints[outputIndex] = codePoints[inputIndex];
66 }
67 outputIndex++;
68 }
69 }
70 if (outputIndex == 0) {
71 return 0;
72 } else {
73 remainingCodePointCount = outputIndex;
74 }
75 }
76 return remainingCodePointCount;
77}
uint16_t SkGlyphID
Definition: SkTypes.h:179
void unicharsToGlyphs(const SkUnichar uni[], int count, SkGlyphID glyphs[]) const
Definition: SkTypeface.cpp:357