summaryrefslogtreecommitdiff
path: root/src/font.cpp
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-02-12 09:45:17 -0500
committerJonathan Bradley <jcb@pikum.xyz>2025-02-12 09:45:17 -0500
commitf8b69d8a6832369c16dd10cc28d428690cda11b2 (patch)
tree5a9c7414be061908c68aa4858dde4744b7c1614a /src/font.cpp
parent26f5f1ccd0681797e49cf932dd417b7221adaa06 (diff)
pke: FontTypeSpacing usage and serialization
Diffstat (limited to 'src/font.cpp')
-rw-r--r--src/font.cpp86
1 files changed, 81 insertions, 5 deletions
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);