MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / PiuStyleLookupFont

Function PiuStyleLookupFont

modules/piu/MC/piuFont.c:213–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211#endif
212
213void PiuStyleLookupFont(PiuStyle* self)
214{
215 xsMachine* the = (*self)->the;
216 void* archive = NULL;
217 PiuFontList* fontList;
218 PiuFont* font = NULL;
219 xsStringValue name;
220 char path[256];
221 void* buffer;
222 size_t bufferSize;
223 int32_t ascent, descent, leading;
224
225 if ((*self)->archive) {
226 xsResult = xsReference((*self)->archive);
227 archive = xsGetHostData(xsResult);
228 }
229 xsResult = xsGet(xsGlobal, xsID_fonts);
230 if (xsTest(xsResult)) {
231 fontList = PIU(FontList, xsResult);
232 font = (*fontList)->first;
233 while (font) {
234 if (((*font)->family == (*self)->family)
235 && ((*font)->size == (*self)->size)
236 && ((*font)->weight == (*self)->weight)
237 && ((*font)->flags == ((*self)->flags & piuStyleBits))) {
238// fprintf(stderr, "CACHE\n");
239 (*self)->font = font;
240 return;
241 }
242 font = (*font)->next;
243 }
244 }
245 else {
246 gCFEUseCount++;
247 if (!gCFE)
248 gCFE = CFENew();
249 PiuFontListNew(the);
250 xsSet(xsGlobal, xsID_fonts, xsResult);
251 fontList = PIU(FontList, xsResult);
252 }
253
254 name = xsName((*self)->family);
255 if (name)
256 c_strcpy(path, name);
257 else
258 c_strcpy(path, "undefined");
259 if (((*self)->flags & (piuStyleCondensedBit | piuStyleItalicBit)) || ((*self)->weight) || ((*self)->size)) {
260 xsIntegerValue flag = 0;
261 c_strcat(path, "-");
262 if ((*self)->flags & piuStyleCondensedBit)
263 c_strcat(path, "Condensed");
264 else
265 flag |= 1;
266 switch ((*self)->weight) {
267 case 1: c_strcat(path, "Ultralight"); break;
268 case 2: c_strcat(path, "Thin"); break;
269 case 3: c_strcat(path, "Light"); break;
270 case 5: c_strcat(path, "Medium");break;

Callers 5

PiuPort_drawStringFunction · 0.50
PiuPort_drawStyleFunction · 0.50
PiuPort_measureStringFunction · 0.50
PiuStyleLinkComputeFunction · 0.50
PiuStyle_measureFunction · 0.50

Calls 9

modFindPebbleFontFunction · 0.85
fxGetResourceFunction · 0.85
fxIntegerToStringFunction · 0.85
PiuFontListNewFunction · 0.70
PiuFontNewFunction · 0.70
CFENewFunction · 0.50
CFESetFontDataFunction · 0.50
CFESetFontSizeFunction · 0.50
CFEGetFontMetricsFunction · 0.50

Tested by

no test coverage detected