summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor/editor.cpp25
-rw-r--r--src/font.cpp4
-rw-r--r--src/font.hpp9
-rw-r--r--src/game.cpp6
4 files changed, 38 insertions, 6 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index ed1b017..e3f6b7c 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -715,6 +715,13 @@ int SortFontGlyphChar(const void *a, const void *b) {
}
void GenerateMTSDF(FontTypeMSDFSettings *msdf_settings, const Asset *a) {
+ static const uint64_t REQUIRED_UNICODE_CHAR_LENGTH = 3;
+ static uint32_t required_unicode_codes[REQUIRED_UNICODE_CHAR_LENGTH] = {
+ 9, // horizontal tab
+ 10, // line feed
+ 13, // carriage return
+ };
+ uint64_t found_unicode_map = 0;
assert(PK_HAS_FLAG(a->type, PKE_ASSET_TYPE_FONT));
FontTypeSpacing ft_spacing{};
glm::dvec4 dbounds;
@@ -798,6 +805,13 @@ void GenerateMTSDF(FontTypeMSDFSettings *msdf_settings, const Asset *a) {
arr[i].unicode = glyphs[i].getCodepoint();
arr[i].is_whitespace = glyphs[i].isWhitespace();
+ for (uint64_t k = 0; k < REQUIRED_UNICODE_CHAR_LENGTH; ++k) {
+ if (arr[i].unicode == required_unicode_codes[k]) {
+ found_unicode_map |= (1ull << k);
+ break;
+ }
+ }
+
glyphs[i].getQuadPlaneBounds(dbounds.x, dbounds.y, dbounds.z, dbounds.a);
arr[i].plane_bounds = dbounds;
@@ -806,6 +820,17 @@ void GenerateMTSDF(FontTypeMSDFSettings *msdf_settings, const Asset *a) {
arr[i].sprite_region_min = glm::vec2(dbounds.x, height - dbounds.a);
arr[i].sprite_region_max = glm::vec2(dbounds.z, height - dbounds.y);
}
+
+ for (uint64_t k = 0; k < REQUIRED_UNICODE_CHAR_LENGTH; ++k) {
+ if ((found_unicode_map & (1ull << k)) != 0) {
+ continue;
+ }
+ FontGlyphChar fgc{};
+ memset(&fgc, 0, sizeof(FontGlyphChar));
+ fgc.unicode = required_unicode_codes[k];
+ pk_arr_append(&arr_glyphs, &fgc);
+ }
+
qsort(arr_glyphs.data, arr_glyphs.next, arr_glyphs.stride, SortFontGlyphChar);
auto f = fopen(path_glyphs, "w+");
diff --git a/src/font.cpp b/src/font.cpp
index 6357a1d..bf03d1a 100644
--- a/src/font.cpp
+++ b/src/font.cpp
@@ -1120,7 +1120,7 @@ FontRenderHandle FontType_AddStringRender(FontTypeIndex idx_ft, const pk_str str
// determine unicode char
ii = utf8_to_unicode(&str.val[i], u);
if (ii == 0) {
- fprintf(stderr, "failed to determine unicode for character: '%c' at byte index: '%i'\n", str.val[i], i);
+ fprintf(stderr, "failed to determine unicode for character: at byte index: '%i'\n", i);
i += 1;
continue;
}
@@ -1139,7 +1139,7 @@ FontRenderHandle FontType_AddStringRender(FontTypeIndex idx_ft, const pk_str str
} while (fgc->unicode != u && l <= r);
if (fgc->unicode != u) {
- fprintf(stderr, "font: '%s' doesn't contain unicode character '%u': '%lc'\n", ft->title.val, u, (wint_t)u);
+ fprintf(stderr, "font: '%s' does not contain unicode character '%u'\n", ft->title.val, u);
continue;
}
count += 1;
diff --git a/src/font.hpp b/src/font.hpp
index 46ffcf9..2d1e55a 100644
--- a/src/font.hpp
+++ b/src/font.hpp
@@ -10,6 +10,13 @@
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),
+};
+
enum FONT_RENDER_SURFACE_AREA_TYPE_FLAGS : uint8_t {
FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_NONE = 0,
FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_GROW_VERTICAL = (1 << 0),
@@ -30,7 +37,7 @@ struct FontGlyphChar {
glm::vec2 sprite_region_max;
glm::dvec4 plane_bounds;
uint32_t unicode;
- bool is_whitespace;
+ FONT_GLYPH_CHAR_FLAGS flags;
};
struct FontRenderSettings {
float char_scale;
diff --git a/src/game.cpp b/src/game.cpp
index 6714910..85c2fd5 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -609,11 +609,11 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) {
}
}
- // pk_cstr test_text = cstring_to_pk_cstr("0123456789 The quick brown fox jumped over the lazy dog.");
- pk_cstr test_text = cstring_to_pk_cstr("%+-*0123456789$");
+ 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("%+-*0123456789$");
// pk_cstr test_text = cstring_to_pk_cstr("$#");
// pk_cstr test_text = cstring_to_pk_cstr("$");
- pk_cstr test_text2 = cstring_to_pk_cstr("+0123456789 The quick brown fox jumped over the lazy dog.");
+ pk_cstr test_text2 = cstring_to_pk_cstr("+0123456\n789\tThe quick brown fox jumped over the lazy dog.");
FontTypeIndex font_type_count;
FontRenderSettings fr_set;
fr_set.char_scale = 9 * 7.0;