diff options
| -rw-r--r-- | editor/editor.cpp | 5 | ||||
| -rw-r--r-- | src/font.cpp | 86 | ||||
| -rw-r--r-- | src/font.hpp | 4 |
3 files changed, 85 insertions, 10 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp index 6e7db59..f5402a6 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -747,7 +747,7 @@ void GenerateMTSDF(FontTypeMSDFSettings *msdf_settings, const Asset *a) { glyph.edgeColoring(&msdfgen::edgeColoringByDistance, maxCornerAngle, 0); auto &metrics = fontGeometry.getMetrics(); - ft_spacing.geometryScale = fontGeometry.getGeometryScale(); + ft_spacing.geometry_scale = fontGeometry.getGeometryScale(); ft_spacing.em_size = metrics.emSize; ft_spacing.ascender_y = metrics.ascenderY; ft_spacing.descender_y = metrics.descenderY; @@ -833,8 +833,7 @@ void GenerateMTSDF(FontTypeMSDFSettings *msdf_settings, const Asset *a) { font_title.val = pk_new<char>(font_title.reserved); snprintf((char *)font_title.val, AssetKeyLength, "%s", a->key); assert(ah_image != ah_glyphs && ah_image != AssetHandle_MAX); - // TODO pass FontTypeSpacing either here or another way - FontType_RegisterFont(font_title, ah_image, ah_glyphs); + FontType_RegisterFont(font_title, ah_image, ah_glyphs, &ft_spacing); } void RecordImGuiAssets() { diff --git a/src/font.cpp b/src/font.cpp index efed570..1ecb831 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -11,9 +11,16 @@ // TODO threading -const char *PKE_PROJECT_FONT_TITLE = "Font::Title: "; -const char *PKE_PROJECT_FONT_TEXTURE_HANDLE = "Font::TextureHandle: "; -const char *PKE_PROJECT_FONT_GLYPH_DETAILS_HANDLE = "Font::GlyphDetailsHandle: "; +const char *PKE_PROJECT_FONT_TITLE = "title: "; +const char *PKE_PROJECT_FONT_TEXTURE_HANDLE = "texture_handle: "; +const char *PKE_PROJECT_FONT_GLYPH_DETAILS_HANDLE = "glyph_details_handle: "; +const char *PKE_PROJECT_FONT_SPACING_GEOMETRY_SCALE = "spacing_geometry_scale: "; +const char *PKE_PROJECT_FONT_SPACING_EM_SIZE = "spacing_em_size: "; +const char *PKE_PROJECT_FONT_SPACING_ASCENDER_Y = "spacing_ascender_y: "; +const char *PKE_PROJECT_FONT_SPACING_DESCENDER_Y = "spacing_descender_y: "; +const char *PKE_PROJECT_FONT_SPACING_LINE_HEIGHT = "spacing_line_height: "; +const char *PKE_PROJECT_FONT_SPACING_UNDERLINE_Y = "spacing_underline_y: "; +const char *PKE_PROJECT_FONT_SPACING_UNDERLINE_THICKNESS = "spacing_underline_thickness: "; TypeSafeInt_B(FontTypeIndex); TypeSafeInt_B(FontRenderIndex); @@ -101,6 +108,8 @@ void FontType_Teardown() { } void FontType_Serialize(std::ofstream &stream, FontType *ft) { + FontTypeSpacing sp{}; + memset(&sp, 0, sizeof(sp)); NULL_CHAR_ARR(handleStr, AssetKeyLength + 2); const Asset *txtr = AM_Get(ft->fontTextureAssetHandle); const Asset *glyphs = AM_Get(ft->glyphDetailsAssetHandle); @@ -109,6 +118,27 @@ void FontType_Serialize(std::ofstream &stream, FontType *ft) { stream << PKE_PROJECT_FONT_TEXTURE_HANDLE << handleStr << std::endl; snprintf(handleStr, AssetKeyLength + 1, "%s", glyphs->key); stream << PKE_PROJECT_FONT_GLYPH_DETAILS_HANDLE << handleStr << std::endl; + if (ft->spacing.geometry_scale != sp.geometry_scale) { + stream << PKE_PROJECT_FONT_SPACING_GEOMETRY_SCALE << ft->spacing.geometry_scale << std::endl; + } + if (ft->spacing.em_size != sp.em_size) { + stream << PKE_PROJECT_FONT_SPACING_EM_SIZE << ft->spacing.em_size << std::endl; + } + if (ft->spacing.ascender_y != sp.ascender_y) { + stream << PKE_PROJECT_FONT_SPACING_ASCENDER_Y << ft->spacing.ascender_y << std::endl; + } + if (ft->spacing.descender_y != sp.descender_y) { + stream << PKE_PROJECT_FONT_SPACING_DESCENDER_Y << ft->spacing.descender_y << std::endl; + } + if (ft->spacing.line_height != sp.line_height) { + stream << PKE_PROJECT_FONT_SPACING_LINE_HEIGHT << ft->spacing.line_height << std::endl; + } + if (ft->spacing.underline_y != sp.underline_y) { + stream << PKE_PROJECT_FONT_SPACING_UNDERLINE_Y << ft->spacing.underline_y << std::endl; + } + if (ft->spacing.underline_thickness != sp.underline_thickness) { + stream << PKE_PROJECT_FONT_SPACING_UNDERLINE_THICKNESS << ft->spacing.underline_thickness << std::endl; + } AM_Release(ft->glyphDetailsAssetHandle); AM_Release(ft->fontTextureAssetHandle); } @@ -116,12 +146,14 @@ void FontType_Serialize(std::ofstream &stream, FontType *ft) { void FontType_Deserialize(std::ifstream &stream) { uint64_t i; NULL_CHAR_ARR(readLine, 128); + FontTypeSpacing sp{}; pk_cstr title; AssetKey fontTextureKey; AssetKey glyphDetailsKey; + memset(&sp, 0, sizeof(sp)); while (memset(readLine, 0, 128), stream.getline(readLine, 128)) { if (strcmp("", readLine) == 0) { - FontType_RegisterFont(title, AM_GetHandle(fontTextureKey), AM_GetHandle(glyphDetailsKey)); + FontType_RegisterFont(title, AM_GetHandle(fontTextureKey), AM_GetHandle(glyphDetailsKey), &sp); return; } if (strstr(readLine, PKE_PROJECT_FONT_TITLE)) { @@ -146,6 +178,48 @@ void FontType_Deserialize(std::ifstream &stream) { } continue; } + if (strstr(readLine, PKE_PROJECT_FONT_SPACING_GEOMETRY_SCALE)) { + uint64_t prefixLen = strlen(PKE_PROJECT_FONT_SPACING_GEOMETRY_SCALE); + auto result = pk_stn_double(&sp.geometry_scale, readLine + prefixLen); + assert(result == PK_STN_RES_SUCCESS); + continue; + } + if (strstr(readLine, PKE_PROJECT_FONT_SPACING_EM_SIZE)) { + uint64_t prefixLen = strlen(PKE_PROJECT_FONT_SPACING_EM_SIZE); + auto result = pk_stn_double(&sp.em_size, readLine + prefixLen); + assert(result == PK_STN_RES_SUCCESS); + continue; + } + if (strstr(readLine, PKE_PROJECT_FONT_SPACING_ASCENDER_Y)) { + uint64_t prefixLen = strlen(PKE_PROJECT_FONT_SPACING_ASCENDER_Y); + auto result = pk_stn_double(&sp.ascender_y, readLine + prefixLen); + assert(result == PK_STN_RES_SUCCESS); + continue; + } + if (strstr(readLine, PKE_PROJECT_FONT_SPACING_DESCENDER_Y)) { + uint64_t prefixLen = strlen(PKE_PROJECT_FONT_SPACING_DESCENDER_Y); + auto result = pk_stn_double(&sp.descender_y, readLine + prefixLen); + assert(result == PK_STN_RES_SUCCESS); + continue; + } + if (strstr(readLine, PKE_PROJECT_FONT_SPACING_LINE_HEIGHT)) { + uint64_t prefixLen = strlen(PKE_PROJECT_FONT_SPACING_LINE_HEIGHT); + auto result = pk_stn_double(&sp.line_height, readLine + prefixLen); + assert(result == PK_STN_RES_SUCCESS); + continue; + } + if (strstr(readLine, PKE_PROJECT_FONT_SPACING_UNDERLINE_Y)) { + uint64_t prefixLen = strlen(PKE_PROJECT_FONT_SPACING_UNDERLINE_Y); + auto result = pk_stn_double(&sp.underline_y, readLine + prefixLen); + assert(result == PK_STN_RES_SUCCESS); + continue; + } + if (strstr(readLine, PKE_PROJECT_FONT_SPACING_UNDERLINE_THICKNESS)) { + uint64_t prefixLen = strlen(PKE_PROJECT_FONT_SPACING_UNDERLINE_THICKNESS); + auto result = pk_stn_double(&sp.underline_thickness, readLine + prefixLen); + assert(result == PK_STN_RES_SUCCESS); + continue; + } } } @@ -154,7 +228,7 @@ FontType* FontType_GetFonts(FontTypeIndex &count) { return ftd.arr_ft; } -FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle, AssetHandle glyphsHandle) { +FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle, AssetHandle glyphsHandle, FontTypeSpacing *spacing) { PKVK_TmpBufferDetails tmpBufferDetails{}; VkResult vkResult; pk_arr arr_vert_mem_reqs; @@ -168,6 +242,7 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle constexpr VkDeviceSize startingGlyphCount = 4; assert(fontTextureHandle != AssetHandle_MAX); assert(glyphsHandle != AssetHandle_MAX); + assert(spacing != nullptr); VkMemoryRequirements combined_vert_mem_reqs; VkMemoryRequirements combined_texture_mem_reqs; @@ -190,6 +265,7 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle ft->glyphDetailsAssetHandle = glyphsHandle; ft->renders = pk_new<FontRender>(startingGlyphCount); ft->n_render = FontRenderIndex{startingGlyphCount}; + ft->spacing = *spacing; const Asset *glyphs = AM_Get(glyphsHandle); ft->n_glyphs = glyphs->size / sizeof(FontGlyphChar); diff --git a/src/font.hpp b/src/font.hpp index 4d0d0a7..9be881c 100644 --- a/src/font.hpp +++ b/src/font.hpp @@ -46,7 +46,7 @@ struct FontTypeMSDFSettings { float px_range; }; struct FontTypeSpacing { - double geometryScale; + double geometry_scale; double em_size; double ascender_y; double descender_y; @@ -93,7 +93,7 @@ void FontType_Tick(); void FontType_Serialize(std::ofstream &stream, FontType *ft); void FontType_Deserialize(std::ifstream &stream); FontType* FontType_GetFonts(FontTypeIndex &count); -FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle, AssetHandle glyphsHandle); +FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle, AssetHandle glyphsHandle, FontTypeSpacing *spacing); void FontType_Unload(FontTypeIndex idx); FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_cstr cstr); void FontType_RemoveStringRender(FontRender fr); |
