Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
fonts.cc File Reference
#include <memory>
#include "flutter/skwasm/export.h"
#include "flutter/skwasm/live_objects.h"
#include "flutter/skwasm/wrappers.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"

Go to the source code of this file.

Functions

SKWASM_EXPORT Skwasm::FlutterFontCollectionfontCollection_create ()
 
SKWASM_EXPORT void fontCollection_dispose (Skwasm::FlutterFontCollection *collection)
 
static sk_sp< SkFontMgr > default_fontmgr ()
 
SKWASM_EXPORT SkTypeface * typeface_create (SkData *font_data)
 
SKWASM_EXPORT void typeface_dispose (SkTypeface *typeface)
 
SKWASM_EXPORT int typefaces_filterCoveredCodePoints (SkTypeface **typefaces, int typeface_count, SkUnichar *code_points, int code_point_count)
 
SKWASM_EXPORT void fontCollection_registerTypeface (Skwasm::FlutterFontCollection *collection, SkTypeface *typeface, SkString *font_name)
 
SKWASM_EXPORT void fontCollection_clearCaches (Skwasm::FlutterFontCollection *collection)
 

Function Documentation

◆ default_fontmgr()

static sk_sp< SkFontMgr > default_fontmgr ( )
static

Definition at line 33 of file fonts.cc.

33 {
34 static sk_sp<SkFontMgr> mgr = SkFontMgr_New_Custom_Empty();
35 return mgr;
36}

Referenced by typeface_create().

◆ fontCollection_clearCaches()

SKWASM_EXPORT void fontCollection_clearCaches ( Skwasm::FlutterFontCollection collection)

Definition at line 97 of file fonts.cc.

98 {
99 collection->collection->clearCaches();
100}
sk_sp< skia::textlayout::FontCollection > collection
Definition wrappers.h:37

References Skwasm::FlutterFontCollection::collection.

◆ fontCollection_create()

SKWASM_EXPORT Skwasm::FlutterFontCollection * fontCollection_create ( )

Definition at line 15 of file fonts.cc.

15 {
17 auto collection = sk_make_sp<skia::textlayout::FontCollection>();
18 auto provider = sk_make_sp<skia::textlayout::TypefaceFontProvider>();
19 collection->enableFontFallback();
20 collection->setDefaultFontManager(provider, "Roboto");
22 std::move(collection),
23 std::move(provider),
24 };
25}
uint32_t live_font_collection_count

References Skwasm::live_font_collection_count.

◆ fontCollection_dispose()

SKWASM_EXPORT void fontCollection_dispose ( Skwasm::FlutterFontCollection collection)

Definition at line 27 of file fonts.cc.

28 {
30 delete collection;
31}

References Skwasm::live_font_collection_count.

◆ fontCollection_registerTypeface()

SKWASM_EXPORT void fontCollection_registerTypeface ( Skwasm::FlutterFontCollection collection,
SkTypeface *  typeface,
SkString *  font_name 
)

Definition at line 84 of file fonts.cc.

87 {
88 if (font_name) {
89 SkString alias = *font_name;
90 collection->provider->registerTypeface(sk_ref_sp<SkTypeface>(typeface),
91 alias);
92 } else {
93 collection->provider->registerTypeface(sk_ref_sp<SkTypeface>(typeface));
94 }
95}
sk_sp< skia::textlayout::TypefaceFontProvider > provider
Definition wrappers.h:38

References Skwasm::FlutterFontCollection::provider.

◆ typeface_create()

SKWASM_EXPORT SkTypeface * typeface_create ( SkData *  font_data)

Definition at line 38 of file fonts.cc.

38 {
40 auto typeface = default_fontmgr()->makeFromData(sk_ref_sp<SkData>(font_data));
41 return typeface.release();
42}
static sk_sp< SkFontMgr > default_fontmgr()
Definition fonts.cc:33
uint32_t live_typeface_count

References default_fontmgr(), and Skwasm::live_typeface_count.

◆ typeface_dispose()

SKWASM_EXPORT void typeface_dispose ( SkTypeface *  typeface)

Definition at line 44 of file fonts.cc.

44 {
46 typeface->unref();
47}

References Skwasm::live_typeface_count.

◆ typefaces_filterCoveredCodePoints()

SKWASM_EXPORT int typefaces_filterCoveredCodePoints ( SkTypeface **  typefaces,
int  typeface_count,
SkUnichar *  code_points,
int  code_point_count 
)

Definition at line 52 of file fonts.cc.

55 {
56 std::unique_ptr<SkGlyphID[]> glyph_buffer =
57 std::make_unique<SkGlyphID[]>(code_point_count);
58 SkGlyphID* glyph_pointer = glyph_buffer.get();
59 int remaining_code_point_count = code_point_count;
60 for (int typeface_index = 0; typeface_index < typeface_count;
61 typeface_index++) {
62 typefaces[typeface_index]->unicharsToGlyphs(
63 {code_points, remaining_code_point_count},
64 {glyph_pointer, remaining_code_point_count});
65 int output_index = 0;
66 for (int input_index = 0; input_index < remaining_code_point_count;
67 input_index++) {
68 if (glyph_pointer[input_index] == 0) {
69 if (output_index != input_index) {
70 code_points[output_index] = code_points[input_index];
71 }
72 output_index++;
73 }
74 }
75 if (output_index == 0) {
76 return 0;
77 } else {
78 remaining_code_point_count = output_index;
79 }
80 }
81 return remaining_code_point_count;
82}