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

Function xs_poco_drawText

modules/commodetto/commodettoPocoCore.c:987–1190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

985}
986
987void xs_poco_drawText(xsMachine *the)
988{
989 Poco poco = xsmcGetHostDataPoco(xsThis);
990 int argc = xsmcArgc;
991 PocoCoordinate x, y;
992 CommodettoBitmap cb = NULL;
993 PocoBitmapRecord bits;
994 static const unsigned char *ellipsisFallback = (unsigned char *)"...";
995 static const unsigned char ellipsisUTF8[4] = {0xE2, 0x80, 0xA6, 0}; // 0x2026
996 const unsigned char *ellipsis = C_NULL;
997 PocoDimension ellipsisWidth = 0;
998 int width = 0;
999 void *fontData;
1000 xsUnsignedValue fontDataLength;
1001 uint8_t isColor = 0;
1002 PocoBitmapRecord mask;
1003#if MODDEF_CFE_KERN
1004 uint32_t previousUnicode = 0;
1005#endif
1006 const unsigned char *text;
1007
1008 x = (PocoCoordinate)xsmcToInteger(xsArg(3)) + poco->xOrigin;
1009 y = (PocoCoordinate)xsmcToInteger(xsArg(4)) + poco->yOrigin;
1010
1011 if (argc > 5)
1012 width = xsmcToInteger(xsArg(5));
1013
1014 PocoColor color = (xsReferenceType != xsmcTypeOf(xsArg(2))) ? (PocoColor)xsmcToInteger(xsArg(2)) : 0;
1015
1016 text = (const unsigned char *)xsmcToString(xsArg(0));
1017
1018 xsmcVars(2);
1019
1020 xsmcGetBufferReadable(xsArg(1), &fontData, &fontDataLength);
1021 CFESetFontData(gCFE, fontData, fontDataLength);
1022
1023 if (argc > 5) {
1024 CFEGlyph glyph = CFEGetGlyphFromUnicode(gCFE, 0x2026, false);
1025 if (glyph && !glyph->substitute) {
1026 ellipsisWidth = glyph->advance;
1027 ellipsis = ellipsisUTF8;
1028 }
1029 else {
1030 glyph = CFEGetGlyphFromUnicode(gCFE, '.', false);
1031 ellipsisWidth = glyph ? glyph->advance * 3 : 0;
1032 ellipsis = ellipsisFallback;
1033 }
1034 }
1035 else {
1036 ellipsisWidth = 0;
1037 ellipsis = C_NULL; // appease compiler
1038 }
1039
1040 const char *substitute = C_NULL;
1041 while (true) {
1042 PocoCoordinate cx, cy, sx, sy;
1043 PocoDimension sw, sh;
1044 CFEGlyph glyph;

Callers

nothing calls this directly

Calls 8

PocoNextFromUTF8Function · 0.85
PocoGrayBitmapDrawFunction · 0.85
pocoGetBitmapPixelsFunction · 0.85
PocoBitmapDrawFunction · 0.85
PocoBitmapDrawMaskedFunction · 0.85
CFESetFontDataFunction · 0.70
CFEGetGlyphFromUnicodeFunction · 0.70
CFEGetKerningOffsetFunction · 0.70

Tested by

no test coverage detected