MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / SysFont_TextWidth

Function SysFont_TextWidth

src/SystemFonts.c:812–848  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

810}
811
812int SysFont_TextWidth(struct DrawTextArgs* args) {
813 struct SysFont* font = (struct SysFont*)args->font->handle;
814 FT_Face face = font->face;
815 cc_string text = args->text;
816 int i, width = 0, charWidth;
817 FT_Error res;
818 cc_unichar uc;
819
820 for (i = 0; i < text.length; i++) {
821 char c = text.buffer[i];
822 if (c == '&' && Drawer2D_ValidColorCodeAt(&text, i + 1)) {
823 i++; continue; /* skip over the color code */
824 }
825
826 charWidth = font->widths[(cc_uint8)c];
827 /* need to calculate glyph width */
828 if (charWidth == UInt16_MaxValue) {
829 uc = Convert_CP437ToUnicode(c);
830 res = FT_Load_Char(face, uc, 0);
831
832 if (res) {
833 Platform_Log2("Error %e measuring width of %r", &res, &c);
834 charWidth = 0;
835 } else {
836 charWidth = face->glyph->advance.x;
837 }
838
839 font->widths[(cc_uint8)c] = charWidth;
840 }
841 width += charWidth;
842 }
843 if (!width) return 0;
844
845 width = TEXT_CEIL(width);
846 if (args->useShadow) width += 2;
847 return width;
848}
849
850static void DrawGrayscaleGlyph(FT_Bitmap* img, struct Bitmap* bmp, int x, int y, BitmapCol col) {
851 cc_uint8* src;

Callers 1

Drawer2D_TextWidthFunction · 0.85

Calls 8

Convert_CP437ToUnicodeFunction · 0.85
FT_Load_CharFunction · 0.85
Platform_Log2Function · 0.85
Drawer2D_UNSAFE_NextPartFunction · 0.85
String_EncodeUtf8Function · 0.85
Math_CeilFunction · 0.85
FallbackFont_TextWidthFunction · 0.85

Tested by

no test coverage detected