diff options
Diffstat (limited to 'src/font.cpp')
| -rw-r--r-- | src/font.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/font.cpp b/src/font.cpp index e905da3..6357a1d 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -89,12 +89,27 @@ uint32_t utf8_to_unicode(const char* str, uint32_t &out) { return i; } +float FontType_Inner_LookAheadWordLength(const FontType *const ft, const FontRender *const fr, uint32_t index, float font_glyph_spacing) { + uint32_t i; + float ret = 0; + FontGlyphChar *fgc; + for (i = index; i < fr->n_glyphs; ++i) { + fgc = &ft->glyphs[fr->glyph_indices[i]]; + if (fgc->is_whitespace == true) { + break; + } + ret += fgc->advance * font_glyph_spacing; + } + return ret; +} + void FontType_Inner_CalcTransforms(const FontType *ft, FontRender *fr, FontInstanceBufferItem *ptr_dst) { assert(ft != nullptr); assert(fr != nullptr); assert(ptr_dst != nullptr); FontGlyphChar *fgc; FontInstanceBufferItem *buf_item; + bool new_word = true; uint32_t i; float font_glyph_spacing; float cursor_head, line_index, line_height; @@ -119,8 +134,17 @@ void FontType_Inner_CalcTransforms(const FontType *ft, FontRender *fr, FontInsta if (fgc->is_whitespace == true) { cursor_head += fgc->advance * font_glyph_spacing; + new_word = true; continue; } + if (new_word == true) { + float word_width = FontType_Inner_LookAheadWordLength(ft, fr, i, font_glyph_spacing); + if (cursor_head + word_width > fr->settings.surface_area_size.x) { + line_index += 1; + cursor_head = 0; + } + new_word = false; + } // left, bottom, right, top // x, y, z, w @@ -151,7 +175,7 @@ void FontType_Inner_CalcTransforms(const FontType *ft, FontRender *fr, FontInsta // box position translate.y = fr->settings.surface_area_pos.y; // baseline - current line (+1 to not draw above the box) - translate.y -= ((line_index + 1) * line_height); + translate.y += ((line_index + 1) * line_height); // places the top line of the glyph on the baseline translate.y += (font_glyph_spacing / 2.0) + (glyph_size.y / 2.0); // move glyph to the height relative to the baseline (cursor) |
