diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-02-17 10:49:00 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-02-17 10:49:00 -0500 |
| commit | cdad60ab666ac27209138ba127d91caf7337e6fc (patch) | |
| tree | ff93eb6ebe562d6ec4263e7cc9f8d6d0312ee6da /src/font.cpp | |
| parent | 5f77c5f905d2a3063230bde1176372ebd074bc99 (diff) | |
pke: more mtsdf work, refactor code for debugging
Diffstat (limited to 'src/font.cpp')
| -rw-r--r-- | src/font.cpp | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/src/font.cpp b/src/font.cpp index 203eea3..96a93a6 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -91,23 +91,34 @@ void FontType_Inner_CalcTransforms(const FontType *ft, FontRender *fr, FontInsta FontGlyphChar *fgc; FontInstanceBufferItem *buf_item; uint32_t i; + float font_glyph_spacing_inverse; float cursor_head, line_index, line_height; float glyph_ratio, screen_ratio; glm::vec2 glyph_size; + glm::vec2 translate; glm::mat3 tr_scale_glyph = glm::mat3(1); glm::mat3 tr_scale_screen = glm::mat3(1); glm::mat3 tr_translate = glm::mat3(1); + font_glyph_spacing_inverse = (ft->spacing.em_size / ft->spacing.geometry_scale); cursor_head = 0; line_index = 0; - line_height = (1 / ft->spacing.geometry_scale) * ft->spacing.line_height; + line_height = font_glyph_spacing_inverse * ft->spacing.line_height * fr->settings.char_scale; for (i = 0; i < fr->n_glyphs; ++i) { fgc = &ft->glyphs[fr->glyph_indices[i]]; + // left, bottom, right, top + // x, y, z, w glyph_size.x = fgc->baseline_bounding_box.z - fgc->baseline_bounding_box.x; + glyph_size.x *= font_glyph_spacing_inverse; + glyph_size.x *= fr->settings.char_scale; + glyph_size.y = fgc->baseline_bounding_box.w - fgc->baseline_bounding_box.y; + glyph_size.y *= font_glyph_spacing_inverse; + glyph_size.y *= fr->settings.char_scale; + glyph_ratio = glyph_size.x / glyph_size.y; // this might break if the screen is vertical? @@ -126,10 +137,34 @@ void FontType_Inner_CalcTransforms(const FontType *ft, FontRender *fr, FontInsta tr_scale_screen[1][1] = screen_ratio; // move to appropriate position + char placement - tr_translate[2][0] = ((fr->settings.surface_area_pos.x + cursor_head) - (Extent.width / 2.0)) / (Extent.width / 2.0); - tr_translate[2][1] = ((fr->settings.surface_area_pos.y + ((line_index + 1) * line_height)) - (Extent.width / 2.0)) / (Extent.width / 2.0); - cursor_head += fgc->advance * fr->settings.char_scale * (ft->spacing.em_size / ft->spacing.geometry_scale); + // ((val) - (width/2)) / (width/2) + // box position + translate.x = fr->settings.surface_area_pos.x; + // current char position on x axis + translate.x += cursor_head; + // draw from top left [-1,-1], so add left + // (add because "left" from mtsdf is likely negative) + // (while testing, the char '#' had a negative "left") + translate.x += font_glyph_spacing_inverse * fgc->baseline_bounding_box.x; + translate.x -= (Extent.width / 2.0); + translate.x /= (Extent.width / 2.0); + + // ((val) - (width/2)) / (width/2) + // box position + translate.y = fr->settings.surface_area_pos.y; + // current line (+1 to not draw above the box) + translate.y += ((line_index + 1) * line_height); + // draw from top left [-1,-1], so subtract top + // (subtract because vulkan to go up) + translate.y -= (ft->spacing.em_size / ft->spacing.geometry_scale) * fgc->baseline_bounding_box.w; + translate.y -= (Extent.width / 2.0); + translate.y /= (Extent.width / 2.0); + + tr_translate[2][0] = translate.x; + tr_translate[2][1] = translate.y; + + cursor_head += fgc->advance * font_glyph_spacing_inverse * fr->settings.char_scale; buf_item = &ptr_dst[i]; buf_item->pos_scale = tr_translate * tr_scale_glyph * tr_scale_screen; @@ -137,8 +172,8 @@ void FontType_Inner_CalcTransforms(const FontType *ft, FontRender *fr, FontInsta buf_item->bg_color = glm::vec4(0.0, 0.0, 0.0, 0.0); buf_item->sprite_region_min = fgc->sprite_region_min; buf_item->sprite_region_max = fgc->sprite_region_max; - buf_item->width = 1; - // buf_item->pos_scale[0][1] *= -1.0; + // TODO check me, not sure this is correct + buf_item->width = fr->settings.char_scale; } } |
