int textGetStringWidth(TEXT_FONT *font, const char *string) { int i, w; unsigned int glyph; for (i = w = 0; string[i] != 0; ) { glyph = utf8GetChar(&string[i]); i += utf8GetValidatedCharLength(&string[i]); w += textGetGlyphWidth(font, glyph); } return w; }
int textThisManyGlyphsWillFit(TEXT_SURFACE *surface, const char *str, unsigned int width) { int i, k; float j; unsigned int glyph; for (i = j = k = 0; str[i] != 0; k++) { glyph = utf8GetChar(&str[i]); j += textGetGlyphWidthf(surface->font, glyph); if (j > width) return k; i += utf8GetValidatedCharLength(&str[i]); } return k; }
int textStringWordLength(TEXT_FONT *font, const char *string, int *bytes) { int i, w; unsigned int glyph; if (bytes) *bytes = 0; if (!font) return 0; for (i = w = 0; string[i] != 0 && string[i] != ' ' && string[i] != '\n';) { glyph = utf8GetChar(&string[i]); i += utf8GetValidatedCharLength(&string[i]); w += textGetGlyphWidth(font, glyph); } if (bytes) *bytes = i; return w; }
int textStringBytesOnLine(TEXT_FONT *font, const char *string, int linelen, int *w_m) { int i, w; unsigned int glyph; if (!font) return 0; for (i = w = 0; string[i] != 0;) { glyph = utf8GetChar(&string[i]); if (textGetGlyphWidth(font, glyph) + w > linelen) { *w_m = w; return i; } w += textGetGlyphWidth(font, glyph); i += utf8GetValidatedCharLength(&string[i]); } *w_m = w; return i; }
unsigned int EXPORT_THIS d_font_glyph_w(void *font, const char *s) { unsigned int c; c = utf8GetChar(s); return textGetGlyphWidth(font, c); }