diff options
| -rw-r--r-- | editor/editor.cpp | 10 | ||||
| -rw-r--r-- | src/font.cpp | 47 |
2 files changed, 47 insertions, 10 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp index d246c66..27d993e 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -795,16 +795,18 @@ void GenerateMTSDF(FontTypeMSDFSettings *msdf_settings, const Asset *a) { arr_glyphs.stride = sizeof(FontGlyphChar); pk_arr_resize(&arr_glyphs, glyphs.size()); FontGlyphChar *arr = reinterpret_cast<FontGlyphChar *>(arr_glyphs.data); + uint32_t u; for (uint64_t i = 0; i < glyphs.size(); ++i) { arr[i].advance = glyphs[i].getAdvance(); arr[i].unicode = glyphs[i].getCodepoint(); arr[i].is_whitespace = glyphs[i].isWhitespace(); - glyphs[i].getBoxRect(ibounds.x, ibounds.y, ibounds.z, ibounds.a); + u = arr[i].unicode; + (void)u; // TODO double-check this math - glyphs[i].getQuadAtlasBounds(dbounds.x, dbounds.y, dbounds.z, dbounds.a); - arr[i].baseline_bounding_box = dbounds - glm::dvec4(ibounds); + glyphs[i].getQuadPlaneBounds(dbounds.x, dbounds.y, dbounds.z, dbounds.a); + arr[i].baseline_bounding_box = dbounds; // library counts up from the bottom of the image to the bottom of the glyph ibounds.y = height - (ibounds.y + ibounds.a); @@ -845,7 +847,7 @@ void RecordImGuiAssets() { // User should input these values on a per-font basis. struct FontTypeMSDFSettings msdf_settings{}; msdf_settings.minimum_scale = 7 * 2; - msdf_settings.px_range = 1; + msdf_settings.px_range = 2; static ImGuiTableFlags tableFlags{ ImGuiTableFlags_Borders | 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; } } |
