diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-09-03 02:37:37 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-09-03 02:37:37 +0200 |
commit | 1ee7d3a84e3bc880abd7226b7dc1336b19d9211d (patch) | |
tree | ff4f7b9466f3c61ae7648b04663ad50dde94530a | |
parent | 53d23bbaf257c588409825ff50857c02b43dd407 (diff) |
Consistently calculate font height for different fonts
-rw-r--r-- | include/Text.hpp | 1 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 2 | ||||
-rw-r--r-- | src/Text.cpp | 16 |
3 files changed, 13 insertions, 6 deletions
diff --git a/include/Text.hpp b/include/Text.hpp index 26ac141..8eb5c96 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -134,6 +134,7 @@ namespace QuickMedia void splitTextByFont(); + float font_get_real_height(sf::Font *font); float get_text_quad_left_side(const VertexRef &vertex_ref) const; float get_text_quad_right_side(const VertexRef &vertex_ref) const; // If the index is past the end, then the caret offset is the right side of the last character, rather than the left side diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index fe3e53c..2157a4d 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -6609,7 +6609,7 @@ namespace QuickMedia { const float body_width = window_size.x; this->body_pos = sf::Vector2f(0.0f, tab_shade_height); - if(window_size.x > 900.0f * get_font_scale() && show_room_side_panel) { + if(window_size.x > 900.0f * get_ui_scale() * get_font_scale() && show_room_side_panel) { this->body_size = sf::Vector2f(std::floor(300.0f * get_ui_scale() * get_font_scale()), window_size.y - tab_shade_height); draw_room_list = true; } else { diff --git a/src/Text.cpp b/src/Text.cpp index e012af5..421de8c 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -305,6 +305,10 @@ namespace QuickMedia } } + float Text::font_get_real_height(sf::Font *font) { + return font->getGlyph('|', characterSize, false).bounds.height + std::floor(4.0f * ((float)characterSize / (float)14.0f)); + } + float Text::get_text_quad_left_side(const VertexRef &vertex_ref) const { return vertices[vertex_ref.vertices_index][vertex_ref.index + 1].position.x; } @@ -392,7 +396,7 @@ namespace QuickMedia float latin_font_height = latin_font->getGlyph(' ', characterSize, false).advance; float hspace = latin_font_height + characterSpacing; - float vspace = latin_font->getLineSpacing(characterSize); // TODO: What about japanese font??? + const float vspace = font_get_real_height(latin_font); const sf::Color url_color = get_current_theme().url_text_color; @@ -650,9 +654,11 @@ namespace QuickMedia else latin_font = FontLoader::get_font(FontLoader::FontType::LATIN); + const float vspace = font_get_real_height(latin_font); + if(vertices_linear.empty()) { caretIndex = 0; - caretPosition = sf::Vector2f(0.0f, floor(latin_font->getLineSpacing(characterSize))); + caretPosition = sf::Vector2f(0.0f, floor(vspace)); caret_offset_x = 0.0f; return; } @@ -708,10 +714,10 @@ namespace QuickMedia caretPosition.x = 0.0f; else caretPosition.x = get_text_quad_right_side(last_vertex); - caretPosition.y = (1 + get_vertex_line(caretIndex)) * floor(latin_font->getLineSpacing(characterSize) + lineSpacing); + caretPosition.y = (1 + get_vertex_line(caretIndex)) * floor(vspace + lineSpacing); } else { caretPosition.x = get_caret_offset_by_caret_index(caretIndex); - caretPosition.y = (1 + get_vertex_line(caretIndex)) * floor(latin_font->getLineSpacing(characterSize) + lineSpacing); + caretPosition.y = (1 + get_vertex_line(caretIndex)) * floor(vspace + lineSpacing); } } @@ -933,7 +939,7 @@ namespace QuickMedia latin_font_type = FontLoader::FontType::LATIN; sf::Font *latin_font = FontLoader::get_font(latin_font_type); - const float vspace = latin_font->getLineSpacing(characterSize); + const float vspace = font_get_real_height(latin_font); pos.y += floor(vspace); // Origin is at bottom left, we want it to be at top left const FontLoader::FontType font_types[] = { latin_font_type, FontLoader::FontType::CJK, FontLoader::FontType::SYMBOLS }; |