Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions | Variables
SkFontMgr_fuchsia.cpp File Reference
#include "include/ports/SkFontMgr_fuchsia.h"
#include <fuchsia/fonts/cpp/fidl.h>
#include <lib/zx/vmar.h>
#include <strings.h>
#include <memory>
#include <unordered_map>
#include "src/core/SkFontDescriptor.h"
#include "src/ports/SkFontMgr_custom.h"
#include "include/core/SkFontMgr.h"
#include "include/core/SkStream.h"
#include "include/core/SkTypeface.h"
#include "include/private/base/SkThreadAnnotations.h"
#include "src/core/SkTypefaceCache.h"

Go to the source code of this file.

Classes

class  SkFuchsiaFontDataCache
 
struct  TypefaceId
 
class  SkTypeface_Fuchsia
 
class  SkFontMgr_Fuchsia
 
class  SkFontStyleSet_Fuchsia
 

Functions

fuchsia::fonts::Slant SkToFuchsiaSlant (SkFontStyle::Slant slant)
 
SkFontStyle::Slant FuchsiaToSkSlant (fuchsia::fonts::Slant slant)
 
fuchsia::fonts::Width SkToFuchsiaWidth (SkFontStyle::Width width)
 
bool SkToFuchsiaWidth (int skWidth, fuchsia::fonts::Width *outFuchsiaWidth)
 
SkFontStyle::Width FuchsiaToSkWidth (fuchsia::fonts::Width width)
 
fuchsia::fonts::Style2 SkToFuchsiaStyle (const SkFontStyle &style)
 
bool GetGenericFontFamilyByName (const char *name, fuchsia::fonts::GenericFontFamily *outGenericFamily)
 
sk_sp< SkTypefaceCreateTypefaceFromSkStream (std::unique_ptr< SkStreamAsset > stream, const SkFontArguments &args, TypefaceId id)
 
sk_sp< SkTypefaceCreateTypefaceFromSkData (sk_sp< SkData > data, TypefaceId id)
 
static bool FindByTypefaceId (SkTypeface *cachedTypeface, void *ctx)
 
sk_sp< SkFontMgrSkFontMgr_New_Fuchsia (fuchsia::fonts::ProviderSyncPtr provider)
 

Variables

struct { 
 
   const char *   fName 
 
   fuchsia::fonts::GenericFontFamily   fGenericFontFamily 
 
kGenericFontFamiliesByName [] 
 
struct TypefaceId kNullTypefaceId = {0xFFFFFFFF, 0xFFFFFFFF}
 

Function Documentation

◆ CreateTypefaceFromSkData()

sk_sp< SkTypeface > CreateTypefaceFromSkData ( sk_sp< SkData data,
TypefaceId  id 
)

Definition at line 276 of file SkFontMgr_fuchsia.cpp.

276 {
277 return CreateTypefaceFromSkStream(std::make_unique<SkMemoryStream>(std::move(data)),
278 SkFontArguments().setCollectionIndex(id.ttcIndex), id);
279}
sk_sp< SkTypeface > CreateTypefaceFromSkStream(std::unique_ptr< SkStreamAsset > stream, const SkFontArguments &args, TypefaceId id)

◆ CreateTypefaceFromSkStream()

sk_sp< SkTypeface > CreateTypefaceFromSkStream ( std::unique_ptr< SkStreamAsset stream,
const SkFontArguments args,
TypefaceId  id 
)

Definition at line 244 of file SkFontMgr_fuchsia.cpp.

245 {
246 SkFontScanner_FreeType fontScanner;
247 int numInstances;
248 if (!fontScanner.scanFace(stream.get(), args.getCollectionIndex(), &numInstances)) {
249 return nullptr;
250 }
251 bool isFixedPitch;
252 SkFontStyle style;
254 SkFontScanner::AxisDefinitions axisDefinitions;
255 if (!fontScanner.scanInstance(stream.get(),
256 args.getCollectionIndex(),
257 0,
258 &name,
259 &style,
260 &isFixedPitch,
261 &axisDefinitions)) {
262 return nullptr;
263 }
264
265 const SkFontArguments::VariationPosition position = args.getVariationDesignPosition();
266 AutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.size());
267 SkFontScanner_FreeType::computeAxisValues(axisDefinitions, position, axisValues, name, &style);
268
269 auto fontData = std::make_unique<SkFontData>(
270 std::move(stream), args.getCollectionIndex(), args.getPalette().index,
271 axisValues.get(), axisDefinitions.size(),
272 args.getPalette().overrides, args.getPalette().overrideCount);
273 return sk_make_sp<SkTypeface_Fuchsia>(std::move(fontData), style, isFixedPitch, name, id);
274}
bool scanFace(SkStreamAsset *stream, int faceIndex, int *numInstances) const override
static void computeAxisValues(AxisDefinitions axisDefinitions, const SkFontArguments::VariationPosition position, SkFixed *axisValues, const SkString &name, SkFontStyle *style, const SkFontArguments::VariationPosition::Coordinate *currentPosition=nullptr)
bool scanInstance(SkStreamAsset *stream, int faceIndex, int instanceIndex, SkString *name, SkFontStyle *style, bool *isFixedPitch, AxisDefinitions *axes) const override
int size() const
Definition SkTArray.h:416
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const char * name
Definition fuchsia.cc:50

◆ FindByTypefaceId()

static bool FindByTypefaceId ( SkTypeface cachedTypeface,
void *  ctx 
)
static

Definition at line 498 of file SkFontMgr_fuchsia.cpp.

498 {
499 SkTypeface_Fuchsia* cachedFuchsiaTypeface = static_cast<SkTypeface_Fuchsia*>(cachedTypeface);
500 TypefaceId* id = static_cast<TypefaceId*>(ctx);
501
502 return cachedFuchsiaTypeface->id() == *id;
503}
const uintptr_t id

◆ FuchsiaToSkSlant()

SkFontStyle::Slant FuchsiaToSkSlant ( fuchsia::fonts::Slant  slant)

Definition at line 109 of file SkFontMgr_fuchsia.cpp.

109 {
110 switch (slant) {
111 case fuchsia::fonts::Slant::OBLIQUE:
113 case fuchsia::fonts::Slant::ITALIC:
115 case fuchsia::fonts::Slant::UPRIGHT:
116 default:
118 }
119}

◆ FuchsiaToSkWidth()

SkFontStyle::Width FuchsiaToSkWidth ( fuchsia::fonts::Width  width)

Definition at line 157 of file SkFontMgr_fuchsia.cpp.

157 {
158 switch (width) {
159 case fuchsia::fonts::Width::ULTRA_CONDENSED:
161 case fuchsia::fonts::Width::EXTRA_CONDENSED:
163 case fuchsia::fonts::Width::CONDENSED:
165 case fuchsia::fonts::Width::SEMI_CONDENSED:
167 case fuchsia::fonts::Width::NORMAL:
169 case fuchsia::fonts::Width::SEMI_EXPANDED:
171 case fuchsia::fonts::Width::EXPANDED:
173 case fuchsia::fonts::Width::EXTRA_EXPANDED:
175 case fuchsia::fonts::Width::ULTRA_EXPANDED:
177 }
178}
@ kExtraExpanded_Width
Definition SkFontStyle.h:40
@ kExtraCondensed_Width
Definition SkFontStyle.h:34
@ kSemiCondensed_Width
Definition SkFontStyle.h:36
@ kUltraExpanded_Width
Definition SkFontStyle.h:41
@ kSemiExpanded_Width
Definition SkFontStyle.h:38
@ kUltraCondensed_Width
Definition SkFontStyle.h:33
int32_t width

◆ GetGenericFontFamilyByName()

bool GetGenericFontFamilyByName ( const char *  name,
fuchsia::fonts::GenericFontFamily *  outGenericFamily 
)

Definition at line 208 of file SkFontMgr_fuchsia.cpp.

209 {
210 if (!name) return false;
211 for (auto& genericFamily : kGenericFontFamiliesByName) {
212 if (strcasecmp(genericFamily.fName, name) == 0) {
213 *outGenericFamily = genericFamily.fGenericFontFamily;
214 return true;
215 }
216 }
217 return false;
218}
constexpr struct @426 kGenericFontFamiliesByName[]

◆ SkFontMgr_New_Fuchsia()

sk_sp< SkFontMgr > SkFontMgr_New_Fuchsia ( fuchsia::fonts::ProviderSyncPtr  provider)

Definition at line 520 of file SkFontMgr_fuchsia.cpp.

520 {
521 return sk_make_sp<SkFontMgr_Fuchsia>(std::move(provider));
522}

◆ SkToFuchsiaSlant()

fuchsia::fonts::Slant SkToFuchsiaSlant ( SkFontStyle::Slant  slant)

Definition at line 97 of file SkFontMgr_fuchsia.cpp.

97 {
98 switch (slant) {
100 return fuchsia::fonts::Slant::OBLIQUE;
102 return fuchsia::fonts::Slant::ITALIC;
104 default:
105 return fuchsia::fonts::Slant::UPRIGHT;
106 }
107}

◆ SkToFuchsiaStyle()

fuchsia::fonts::Style2 SkToFuchsiaStyle ( const SkFontStyle style)

Definition at line 180 of file SkFontMgr_fuchsia.cpp.

180 {
181 fuchsia::fonts::Style2 fuchsiaStyle;
182 fuchsiaStyle.set_slant(SkToFuchsiaSlant(style.slant())).set_weight(style.weight());
183
184 fuchsia::fonts::Width fuchsiaWidth = fuchsia::fonts::Width::NORMAL;
185 if (SkToFuchsiaWidth(style.width(), &fuchsiaWidth)) {
186 fuchsiaStyle.set_width(fuchsiaWidth);
187 }
188
189 return fuchsiaStyle;
190}
fuchsia::fonts::Slant SkToFuchsiaSlant(SkFontStyle::Slant slant)
fuchsia::fonts::Width SkToFuchsiaWidth(SkFontStyle::Width width)
Slant slant() const
Definition SkFontStyle.h:64
int width() const
Definition SkFontStyle.h:63
int weight() const
Definition SkFontStyle.h:62

◆ SkToFuchsiaWidth() [1/2]

bool SkToFuchsiaWidth ( int  skWidth,
fuchsia::fonts::Width *  outFuchsiaWidth 
)

Definition at line 147 of file SkFontMgr_fuchsia.cpp.

147 {
150 return false;
151 }
152 auto typedSkWidth = static_cast<SkFontStyle::Width>(skWidth);
153 *outFuchsiaWidth = SkToFuchsiaWidth(typedSkWidth);
154 return true;
155}

◆ SkToFuchsiaWidth() [2/2]

fuchsia::fonts::Width SkToFuchsiaWidth ( SkFontStyle::Width  width)

Definition at line 121 of file SkFontMgr_fuchsia.cpp.

121 {
122 switch (width) {
124 return fuchsia::fonts::Width::ULTRA_CONDENSED;
126 return fuchsia::fonts::Width::EXTRA_CONDENSED;
128 return fuchsia::fonts::Width::CONDENSED;
130 return fuchsia::fonts::Width::SEMI_CONDENSED;
132 return fuchsia::fonts::Width::NORMAL;
134 return fuchsia::fonts::Width::SEMI_EXPANDED;
136 return fuchsia::fonts::Width::EXPANDED;
138 return fuchsia::fonts::Width::EXTRA_EXPANDED;
140 return fuchsia::fonts::Width::ULTRA_EXPANDED;
141 }
142}

Variable Documentation

◆ fGenericFontFamily

fuchsia::fonts::GenericFontFamily fGenericFontFamily

Definition at line 194 of file SkFontMgr_fuchsia.cpp.

◆ fName

const char* fName

Definition at line 193 of file SkFontMgr_fuchsia.cpp.

◆ [struct]

constexpr struct { ... } kGenericFontFamiliesByName[]
Initial value:
= {{"serif", fuchsia::fonts::GenericFontFamily::SERIF},
{"sans", fuchsia::fonts::GenericFontFamily::SANS_SERIF},
{"sans-serif", fuchsia::fonts::GenericFontFamily::SANS_SERIF},
{"mono", fuchsia::fonts::GenericFontFamily::MONOSPACE},
{"monospace", fuchsia::fonts::GenericFontFamily::MONOSPACE},
{"cursive", fuchsia::fonts::GenericFontFamily::CURSIVE},
{"fantasy", fuchsia::fonts::GenericFontFamily::FANTASY},
{"system-ui", fuchsia::fonts::GenericFontFamily::SYSTEM_UI},
{"emoji", fuchsia::fonts::GenericFontFamily::EMOJI},
{"math", fuchsia::fonts::GenericFontFamily::MATH},
{"fangsong", fuchsia::fonts::GenericFontFamily::FANGSONG}}

◆ kNullTypefaceId

struct TypefaceId kNullTypefaceId = {0xFFFFFFFF, 0xFFFFFFFF}