diff options
| author | Siddharth Roy <[email protected]> | 2022-01-26 17:25:34 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-01-26 12:55:34 +0100 |
| commit | e5ee69a0f51e7dc6e3d9c99a185c05fb8e1addb2 (patch) | |
| tree | 61ac42911d0ffb4d3f57d04917ac8fa5c6f7a61a /src/rtext.c | |
| parent | 76b6efc827ccd90ddfb5d7a0d6890d9f0a5074cf (diff) | |
| download | raylib-e5ee69a0f51e7dc6e3d9c99a185c05fb8e1addb2.tar.gz raylib-e5ee69a0f51e7dc6e3d9c99a185c05fb8e1addb2.zip | |
Add DrawTextCodepoints (#2308)
* Add DrawTextCodepoints
* Fixed top comment
Diffstat (limited to 'src/rtext.c')
| -rw-r--r-- | src/rtext.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/rtext.c b/src/rtext.c index 523712a3..f07b8804 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -1091,6 +1091,38 @@ void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSiz DrawTexturePro(font.texture, srcRec, dstRec, (Vector2){ 0, 0 }, 0.0f, tint); } +// Draw multiple character (codepoints) +void DrawTextCodepoints(Font font, int *codepoints, int count, Vector2 position, float fontSize, float spacing, Color tint) +{ + int textOffsetY = 0; // Offset between lines (on line break '\n') + float textOffsetX = 0.0f; // Offset X to next character to draw + + float scaleFactor = fontSize/font.baseSize; // Character quad scaling factor + + for (int i = 0; i < count; i++) + { + int index = GetGlyphIndex(font, codepoints[i]); + + if (codepoints[i] == '\n') + { + // NOTE: Fixed line spacing of 1.5 line-height + // TODO: Support custom line spacing defined by user + textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor); + textOffsetX = 0.0f; + } + else + { + if ((codepoints[i] != ' ') && (codepoints[i] != '\t')) + { + DrawTextCodepoint(font, codepoints[i], (Vector2){ position.x + textOffsetX, position.y + textOffsetY }, fontSize, tint); + } + + if (font.glyphs[index].advanceX == 0) textOffsetX += ((float)font.recs[index].width*scaleFactor + spacing); + else textOffsetX += ((float)font.glyphs[index].advanceX*scaleFactor + spacing); + } + } +} + // Measure string width for default font int MeasureText(const char *text, int fontSize) { |
