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

Function PiuFontGetWidth

modules/piu/MC/piuFont.c:105–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105PiuDimension PiuFontGetWidth(PiuFont* self, xsSlot* string, xsIntegerValue offset, xsIntegerValue length)
106{
107 xsMachine* the = (*self)->the;
108 xsStringValue text = PiuToString(string);
109 xsIntegerValue character = 0;
110 PiuGlyph glyph;
111 PiuDimension width = 0;
112 text += offset;
113#if pebble
114 if ((*self)->gfont) {
115 char tmp[100];
116
117 GContext *ctx = app_state_get_graphics_context();
118 if ((-1 != length) && text[length]) {
119 if (length >= (xsIntegerValue)sizeof(tmp))
120 length = sizeof(tmp) - 1;
121
122 c_memmove(tmp, text, length);
123 tmp[length] = 0;
124 text = tmp;
125 }
126
127 GSize size = graphics_text_layout_get_max_used_size(
128 ctx, text,
129 (*self)->gfont, GRect(0, 0, 10000, 100),
130 GTextOverflowModeTrailingEllipsis,
131 GTextAlignmentLeft, NULL);
132
133
134 return size.w;
135 }
136#endif
137 const char *substitute = C_NULL;
138 while (length || substitute) {
139 xsStringValue formerText = text;
140#if MODDEF_CFE_KERN
141 xsIntegerValue formerCharacter = character;
142#endif
143 if (substitute) {
144 substitute = fxUTF8Decode((char *)substitute, &character);
145 if (!c_read8(substitute))
146 substitute = C_NULL;
147
148 glyph = PiuFontGetGlyph(self, character, 0);
149 }
150 else {
151 text = fxUTF8Decode(text, &character);
152 if (character <= 0)
153 break;
154 length -= text - formerText;
155
156 glyph = PiuFontGetGlyph(self, character, 0);
157 if (glyph && glyph->substitute) {
158 substitute = glyph->substitute;
159#if MODDEF_CFE_KERN
160 character = formerCharacter;
161#endif
162 continue;

Callers 6

PiuTextDrawFunction · 0.50
PiuTextFormatFunction · 0.50
PiuTextHitFunction · 0.50
PiuPort_drawStringFunction · 0.50
PiuPort_measureStringFunction · 0.50
PiuStyleGetWidthFunction · 0.50

Calls 3

fxUTF8DecodeFunction · 0.85
PiuFontGetGlyphFunction · 0.85
CFEGetKerningOffsetFunction · 0.50

Tested by

no test coverage detected