diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-12-02 13:23:37 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-12-02 13:23:37 -0500 |
| commit | c9164f7af0661fae28772200992436cd27e4f93b (patch) | |
| tree | f384fcf873cdf341914b2384f3c7f1402f5cf94a | |
| parent | 96bf1092d9c0fc53ab3ab2da9d5af979ce890c81 (diff) | |
pke: font center vertical
| -rw-r--r-- | src/font.cpp | 1 | ||||
| -rw-r--r-- | tests/pke-test-font.cpp | 12 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/font.cpp b/src/font.cpp index 2296466..3e6f3bc 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -291,6 +291,7 @@ bool FontType_Inner_CalcTransforms(const FontType *ft, FontRender *fr, FontInsta line_index = 0; line_offset = 0; line_height = font_glyph_spacing * ft->spacing.line_height * fr->settings.line_height_scale; + line_offset -= (font_glyph_spacing * fr->settings.line_height_scale) / 2.0; line_length = FontType_Inner_LookAheadLineLength(ft, fr, 0, font_glyph_spacing); if (PK_HAS_FLAG(fr->settings.surface_area_type_flags, FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_CENTER_HORIZONTAL)) { diff --git a/tests/pke-test-font.cpp b/tests/pke-test-font.cpp index b4a1235..3ecd694 100644 --- a/tests/pke-test-font.cpp +++ b/tests/pke-test-font.cpp @@ -526,7 +526,8 @@ int pke_test_font_007() { coord.y *= 1080.f/2.f; PK_TEST_ASSERT_GTE_RET(2.98, coord.x); PK_TEST_ASSERT_LTE_RET(2.99, coord.x); - // tmp = coord.x; + PK_TEST_ASSERT_GTE_RET(139.86f, coord.y); + PK_TEST_ASSERT_LTE_RET(139.87f, coord.y); // bottom right coord = fibis[12].pos_scale * glm::vec4(pkeIntrinsicsPlane.vert[2], 0, 1); @@ -536,11 +537,14 @@ int pke_test_font_007() { coord.y *= 1080.f/2.f; PK_TEST_ASSERT_GTE_RET(2.98, frs.surface_area_size.x-coord.x); PK_TEST_ASSERT_LTE_RET(2.99, frs.surface_area_size.x-coord.x); - PK_TEST_ASSERT_GTE_RET(frs.surface_area_size.x-3, coord.x); - PK_TEST_ASSERT_LTE_RET(frs.surface_area_size.x-2, coord.x); + // I'm not 100% sure why these differ from above. + // However, a manual test reveals that this value is correct. + // using the test project, center some text and change its container's + // size; the text will remain in the same position (center box too). + PK_TEST_ASSERT_GTE_RET(151.11f, frs.surface_area_size.y-coord.y); + PK_TEST_ASSERT_LTE_RET(151.12f, frs.surface_area_size.y-coord.y); } - return 0; } |
