MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / getUIFontCached

Function getUIFontCached

packages/core/ui/styling/font.ios.ts:26–67  ·  view source on GitHub ↗
(fontDescriptor: FontDescriptor)

Source from the content-addressed store, hash-verified

24}
25
26function getUIFontCached(fontDescriptor: FontDescriptor) {
27 const cacheKey = computeFontCacheKey(fontDescriptor);
28
29 if (uiFontCache.has(cacheKey)) {
30 if (Trace.isEnabled()) {
31 Trace.write(`UIFont reuse from cache: ${JSON.stringify(fontDescriptor)}, cache size: ${uiFontCache.size}`, Trace.categories.Style, Trace.messageType.info);
32 }
33 return uiFontCache.get(cacheKey);
34 }
35 let uiFont = NativeScriptUtils.createUIFont(fontDescriptor as any);
36 if (fontDescriptor.fontVariationSettings?.length) {
37 let font = CGFontCreateWithFontName(uiFont.fontName);
38 const variationAxes: NSArray<NSDictionary<FontVariationAxisType, string | number>> = CGFontCopyVariationAxes(font);
39 // This can be null if font doesn't support axes
40 if (variationAxes?.count) {
41 const variationSettings = NSMutableDictionary.new();
42 const variationAxesCount = variationAxes.count;
43 const variationAxesNames: string[] = [];
44
45 for (let i = 0, length = variationAxes.count; i < length; i++) {
46 variationAxesNames.push(String(variationAxes[i].objectForKey('kCGFontVariationAxisName')));
47 }
48
49 for (const variationSetting of fontDescriptor.fontVariationSettings) {
50 const axisName = fuzzySearch(variationSetting.axis, variationAxesNames);
51 if (axisName?.length) {
52 variationSettings.setValueForKey(variationSetting.value, axisName[0]);
53 }
54 }
55
56 font = CGFontCreateCopyWithVariations(font, variationSettings);
57 uiFont = CTFontCreateWithGraphicsFont(font, fontDescriptor.fontSize, null, null);
58 }
59 }
60
61 uiFontCache.set(cacheKey, uiFont);
62 if (Trace.isEnabled()) {
63 Trace.write(`UIFont creation: ${JSON.stringify(fontDescriptor)}, cache size: ${uiFontCache.size}`, Trace.categories.Style, Trace.messageType.info);
64 }
65
66 return uiFont;
67}
68
69export class Font extends FontBase {
70 static default = new Font(undefined, undefined);

Callers 1

getUIFontMethod · 0.85

Calls 10

fuzzySearchFunction · 0.90
isEnabledMethod · 0.80
objectForKeyMethod · 0.80
computeFontCacheKeyFunction · 0.70
writeMethod · 0.65
getMethod · 0.65
StringClass · 0.50
newMethod · 0.45
pushMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected