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
49// Calculates the code points that are not covered by the specified typefaces.
50// This function mutates the `code_points` buffer in place and returns the count
51// of code points that are not covered by the fonts.
53 int typeface_count,
54 SkUnichar* code_points,
55 int code_point_count) {
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}
83
86 SkTypeface* typeface,
87 SkString* font_name) {
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}
96
99 collection->collection->clearCaches();
100}
static sk_sp< SkFontMgr > default_fontmgr()
Definition fonts.cc:33
SKWASM_EXPORT void fontCollection_clearCaches(Skwasm::FlutterFontCollection *collection)
Definition fonts.cc:97
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 int typefaces_filterCoveredCodePoints(SkTypeface **typefaces, int typeface_count, SkUnichar *code_points, int code_point_count)
Definition fonts.cc:52
SKWASM_EXPORT void fontCollection_registerTypeface(Skwasm::FlutterFontCollection *collection, SkTypeface *typeface, SkString *font_name)
Definition fonts.cc:84
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