Flutter Engine
The Flutter Engine
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
25}
26
28}
29
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 rust::Slice<const fontations_ffi::SkiaDesignCoordinate> coordinates;
79 rust::Box<fontations_ffi::BridgeNormalizedCoords> normalizedCoords =
80 resolve_into_normalized_coords(*fontRef, coordinates);
81 fontations_ffi::BridgeFontStyle fontStyle;
82 if (fontations_ffi::get_font_style(*fontRef, *normalizedCoords, fontStyle)) {
83 *style = SkFontStyle(fontStyle.weight, fontStyle.width, (SkFontStyle::Slant)fontStyle.slant);
84 } else {
85 *style = SkFontStyle::Normal();
86 }
87 }
88
89 if (isFixedPitch != nullptr) {
90 *isFixedPitch = false; // TODO
91 }
92
93 return true;
94}
95
#define SkASSERT(cond)
Definition: SkAssert.h:116
const uint8_t * bytes() const
Definition: SkData.h:43
static sk_sp< SkData > MakeFromStream(SkStream *, size_t size)
Definition: SkData.cpp:208
size_t size() const
Definition: SkData.h:30
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
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32