diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-02-21 15:55:35 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-02-22 00:47:50 -0500 |
| commit | e1133e93c75172e2815231e68bbc0830de1f7d79 (patch) | |
| tree | ab6b63ef5090b12320333fe0fbd982c7188a93ab /src | |
| parent | 76a38d7f972b17c33a6ffd6dc3772df721139e67 (diff) | |
pke: required chars unicode 9, 10, 13
Diffstat (limited to 'src')
| -rw-r--r-- | src/font.cpp | 27 | ||||
| -rw-r--r-- | src/font.hpp | 9 | ||||
| -rw-r--r-- | src/game.cpp | 2 |
3 files changed, 31 insertions, 7 deletions
diff --git a/src/font.cpp b/src/font.cpp index bf03d1a..30877f2 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -95,7 +95,7 @@ float FontType_Inner_LookAheadWordLength(const FontType *const ft, const FontRen FontGlyphChar *fgc; for (i = index; i < fr->n_glyphs; ++i) { fgc = &ft->glyphs[fr->glyph_indices[i]]; - if (fgc->is_whitespace == true) { + if (PK_HAS_FLAG(fgc->flags, FONT_GLYPH_CHAR_FLAGS_WHITESPACE) == true) { break; } ret += fgc->advance * font_glyph_spacing; @@ -132,8 +132,31 @@ void FontType_Inner_CalcTransforms(const FontType *ft, FontRender *fr, FontInsta scale = glm::vec3(1); fgc = &ft->glyphs[fr->glyph_indices[i]]; - if (fgc->is_whitespace == true) { + if (PK_HAS_FLAG(fgc->flags, FONT_GLYPH_CHAR_FLAGS_NEW_LINE) == true) { + // 10 line feed '\n' + // 13 carriage return '\r' + if ((fgc->unicode == 10 || fgc->unicode == 13) && i+1 < fr->n_glyphs) { + if ((ft->glyphs[fr->glyph_indices[i+1]].unicode == 10 || ft->glyphs[fr->glyph_indices[i+1]].unicode == 13) && ft->glyphs[fr->glyph_indices[i+1]].unicode != fgc->unicode) { + i += 1;// burn /r/n and /n/r + } + } + line_index += 1; + cursor_head = 0; + continue; + } + if (PK_HAS_FLAG(fgc->flags, FONT_GLYPH_CHAR_FLAGS_WHITESPACE) == true) { + // x = 2 + // a = 4 + // 6 = 2 + 4 cursor_head += fgc->advance * font_glyph_spacing; + if (PK_HAS_FLAG(fgc->flags, FONT_GLYPH_CHAR_FLAGS_ALIGN_ADVANCE) == true) { + // x2 = x - (a - (x % a)) + // x2 = 6 - (4 - (6 & 4)) + // x2 = 6 - (4 - 2) + // x2 = 6 - (2) + // x2 = 4 + cursor_head -= (ft->spacing.em_size * font_glyph_spacing) - fmod(cursor_head, (ft->spacing.em_size * font_glyph_spacing)); + } new_word = true; continue; } diff --git a/src/font.hpp b/src/font.hpp index 2d1e55a..09ed87a 100644 --- a/src/font.hpp +++ b/src/font.hpp @@ -11,10 +11,11 @@ TypeSafeInt_H(FontTypeIndex, uint16_t, 0xFFFF); TypeSafeInt_H(FontRenderIndex, uint16_t, 0xFFFF); enum FONT_GLYPH_CHAR_FLAGS : uint8_t { - FONT_GLYPH_CHAR_FLAGS_NONE = (0 << 0), - FONT_GLYPH_CHAR_FLAGS_CONTROL = (1 << 0), - FONT_GLYPH_CHAR_FLAGS_WHITESPACE = (1 << 1), - FONT_GLYPH_CHAR_FLAGS_NEW_LINE = (1 << 2), + FONT_GLYPH_CHAR_FLAGS_NONE = (0 << 0), + FONT_GLYPH_CHAR_FLAGS_CONTROL = (1 << 0), + FONT_GLYPH_CHAR_FLAGS_WHITESPACE = (1 << 1), + FONT_GLYPH_CHAR_FLAGS_ALIGN_ADVANCE = (1 << 2), + FONT_GLYPH_CHAR_FLAGS_NEW_LINE = (1 << 3), }; enum FONT_RENDER_SURFACE_AREA_TYPE_FLAGS : uint8_t { diff --git a/src/game.cpp b/src/game.cpp index 85c2fd5..9a52e1b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -609,7 +609,7 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) { } } - pk_cstr test_text = cstring_to_pk_cstr("012\n3456789\tThe quick brown fox jumped over the lazy dog."); + pk_cstr test_text = cstring_to_pk_cstr("012\n3456789\tThe quick\r\nbrown fox jumped over the lazy dog."); // pk_cstr test_text = cstring_to_pk_cstr("%+-*0123456789$"); // pk_cstr test_text = cstring_to_pk_cstr("$#"); // pk_cstr test_text = cstring_to_pk_cstr("$"); |
