| 72 | } |
| 73 | |
| 74 | float textCalcWidth(const char* text) |
| 75 | { |
| 76 | float width = 0.0f; |
| 77 | float maxWidth = 0.0f; |
| 78 | ssize_t units; |
| 79 | uint32_t code; |
| 80 | const uint8_t* p = (const uint8_t*)text; |
| 81 | do |
| 82 | { |
| 83 | if (!*p) break; |
| 84 | units = decode_utf8(&code, p); |
| 85 | if (units == -1) |
| 86 | break; |
| 87 | p += units; |
| 88 | |
| 89 | if (code == '\n') |
| 90 | { |
| 91 | maxWidth = maxf(width, maxWidth); |
| 92 | width = 0.0f; |
| 93 | continue; |
| 94 | } |
| 95 | |
| 96 | if (code > 0) |
| 97 | { |
| 98 | int glyphIdx = fontGlyphIndexFromCodePoint(NULL, code); |
| 99 | charWidthInfo_s* cwi = fontGetCharWidthInfo(NULL, glyphIdx); |
| 100 | width += cwi->charWidth; |
| 101 | } |
| 102 | } while (code > 0); |
| 103 | return s_textScale*maxf(width, maxWidth); |
| 104 | } |
| 105 | |
| 106 | void textDraw(float x, float y, float scaleX, float scaleY, bool baseline, const char* text) |
| 107 | { |