Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkFontScanner_fontations.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
9
13
14using namespace skia_private;
15
16namespace {
17rust::Box<::fontations_ffi::BridgeFontRef> make_bridge_font_ref(sk_sp<SkData> fontData,
18 uint32_t index) {
19 rust::Slice<const uint8_t> slice{fontData->bytes(), fontData->size()};
20 return fontations_ffi::make_font_ref(slice, index);
21}
22}
23
26
29
30bool SkFontScanner_Fontations::scanFile(SkStreamAsset* stream, int* numFaces) const {
31 sk_sp<SkData> fontData = SkData::MakeFromStream(stream, stream->getLength());
32 stream->rewind();
33 rust::Slice<const uint8_t> slice{fontData->bytes(), fontData->size()};
34 ::std::uint32_t num_fonts;
35 if (!fontations_ffi::font_or_collection(slice, num_fonts)) {
36 return false;
37 }
38 *numFaces = num_fonts == 0 ? 1 : num_fonts;
39 return true;
40}
41
43 int faceIndex,
44 int* numInstances) const {
45 rust::Box<fontations_ffi::BridgeFontRef> fontRef =
46 make_bridge_font_ref(SkData::MakeFromStream(stream, stream->getLength()), faceIndex);
47 stream->rewind();
48 if (!fontations_ffi::font_ref_is_valid(*fontRef)) {
49 return false;
50 }
51
52 // TODO: For now assume only the default instance (not variation)
53 *numInstances = 1;
54 return true;
55}
56
57// TODO: For now assume only the default instance (not variation)
59 int faceIndex,
60 int instanceIndex,
62 SkFontStyle* style,
63 bool* isFixedPitch,
64 AxisDefinitions* axes) const {
65 SkASSERT(instanceIndex == 0);
66 rust::Box<fontations_ffi::BridgeFontRef> fontRef =
67 make_bridge_font_ref(SkData::MakeFromStream(stream, stream->getLength()), faceIndex);
68 if (!fontations_ffi::font_ref_is_valid(*fontRef)) {
69 return false;
70 }
71
72 if (name != nullptr) {
73 rust::String readFamilyName = fontations_ffi::family_name(*fontRef);
74 *name = SkString(readFamilyName.data(), readFamilyName.size());
75 }
76
77 if (style != nullptr) {
78 fontations_ffi::BridgeFontStyle fontStyle;
79 if (fontations_ffi::get_font_style(*fontRef, fontStyle)) {
80 *style = SkFontStyle(fontStyle.weight, fontStyle.width, (SkFontStyle::Slant)fontStyle.slant);
81 } else {
82 *style = SkFontStyle::Normal();
83 }
84 }
85
86 return true;
87}
88
#define SkASSERT(cond)
Definition SkAssert.h:116
static sk_sp< SkData > MakeFromStream(SkStream *, size_t size)
Definition SkData.cpp:208
bool scanInstance(SkStreamAsset *stream, int faceIndex, int instanceIndex, SkString *name, SkFontStyle *style, bool *isFixedPitch, AxisDefinitions *axes) const override
bool scanFile(SkStreamAsset *stream, int *numFaces) const override
bool scanFace(SkStreamAsset *stream, int faceIndex, int *numInstances) const override
static constexpr SkFontStyle Normal()
Definition SkFontStyle.h:66
const char * name
Definition fuchsia.cc:50