Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
fonts.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <memory>
6
10#include "third_party/skia/include/core/SkFontMgr.h"
11#include "third_party/skia/include/ports/SkFontMgr_empty.h"
12#include "third_party/skia/modules/skparagraph/include/FontCollection.h"
13#include "third_party/skia/modules/skparagraph/include/TypefaceFontProvider.h"
14
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}
26
32
33static sk_sp<SkFontMgr> default_fontmgr() {
34 static sk_sp<SkFontMgr> mgr = SkFontMgr_New_Custom_Empty();
35 return mgr;
36}
37
38SKWASM_EXPORT SkTypeface* typeface_create(SkData* font_data) {
40 auto typeface = default_fontmgr()->makeFromData(sk_ref_sp<SkData>(font_data));
41 return typeface.release();
42}
43
44SKWASM_EXPORT void typeface_dispose(SkTypeface* typeface) {
46 typeface->unref();
47}
48
51 SkTypeface* typeface,
52 SkString* font_name) {
53 if (font_name) {
54 SkString alias = *font_name;
55 collection->provider->registerTypeface(sk_ref_sp<SkTypeface>(typeface),
56 alias);
57 } else {
58 collection->provider->registerTypeface(sk_ref_sp<SkTypeface>(typeface));
59 }
60}
61
64 collection->collection->clearCaches();
65}
static sk_sp< SkFontMgr > default_fontmgr()
Definition fonts.cc:33
SKWASM_EXPORT void fontCollection_clearCaches(Skwasm::FlutterFontCollection *collection)
Definition fonts.cc:62
SKWASM_EXPORT void fontCollection_dispose(Skwasm::FlutterFontCollection *collection)
Definition fonts.cc:27
SKWASM_EXPORT void typeface_dispose(SkTypeface *typeface)
Definition fonts.cc:44
SKWASM_EXPORT void fontCollection_registerTypeface(Skwasm::FlutterFontCollection *collection, SkTypeface *typeface, SkString *font_name)
Definition fonts.cc:49
SKWASM_EXPORT Skwasm::FlutterFontCollection * fontCollection_create()
Definition fonts.cc:15
SKWASM_EXPORT SkTypeface * typeface_create(SkData *font_data)
Definition fonts.cc:38
uint32_t live_typeface_count
uint32_t live_font_collection_count
#define SKWASM_EXPORT
Definition export.h:10
sk_sp< skia::textlayout::TypefaceFontProvider > provider
Definition wrappers.h:38
sk_sp< skia::textlayout::FontCollection > collection
Definition wrappers.h:37