diff options
author | Andreas Kling <kling@serenityos.org> | 2023-01-05 17:13:55 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-01-06 12:02:20 +0100 |
commit | 2a61d66b0afbe30751fb268cfac2c136553294e7 (patch) | |
tree | 8803357e4cf2493201604a66573e5fc6a26f43a1 | |
parent | 43a10674d03a2dabea723787347354ef48e31197 (diff) | |
download | serenity-2a61d66b0afbe30751fb268cfac2c136553294e7.zip |
LibGfx: Make Font::preferred_line_height() more correct
Return a float, and fix a bogus calculation of ascender + descender.
-rw-r--r-- | Userland/Applications/PixelPaint/Tools/TextTool.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/TextEditor.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Font/BitmapFont.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Font/Font.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Font/OpenType/Font.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Font/ScaledFont.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Font/ScaledFont.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Font/VectorFont.h | 4 |
8 files changed, 10 insertions, 10 deletions
diff --git a/Userland/Applications/PixelPaint/Tools/TextTool.cpp b/Userland/Applications/PixelPaint/Tools/TextTool.cpp index a8dfd8df6d..b2d579bddd 100644 --- a/Userland/Applications/PixelPaint/Tools/TextTool.cpp +++ b/Userland/Applications/PixelPaint/Tools/TextTool.cpp @@ -130,7 +130,7 @@ void TextTool::on_second_paint(Layer const* layer, GUI::PaintEvent& event) painter.translate(editor_layer_location(*layer)); auto typed_text = m_text_editor->text(); auto text_width = max<int>(m_selected_font->width(typed_text), m_selected_font->width(" "sv)); - auto text_height = m_selected_font->preferred_line_height() * max<int>(static_cast<int>(m_text_editor->line_count()), 1); + auto text_height = static_cast<int>(ceilf(m_selected_font->preferred_line_height() * max<int>(static_cast<int>(m_text_editor->line_count()), 1))); auto text_location = editor_stroke_position(m_add_text_position, 1); // Since ImageEditor can be zoomed in/out, we need to be able to render the preview properly scaled @@ -238,7 +238,7 @@ void TextTool::apply_text_to_layer() auto demo_text = m_text_editor->text(); auto text_width = m_selected_font->width(demo_text); - auto text_height = m_selected_font->preferred_line_height() * static_cast<int>(m_text_editor->line_count()); + auto text_height = static_cast<int>(ceilf(m_selected_font->preferred_line_height() * static_cast<int>(m_text_editor->line_count()))); painter.set_font(*m_selected_font); auto text_rect = Gfx::Rect<int>(m_add_text_position, { static_cast<int>(ceilf(text_width)), text_height }); diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 1aaad0d4bb..3e7361cd5b 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -2193,7 +2193,7 @@ void TextEditor::set_editing_engine(OwnPtr<EditingEngine> editing_engine) int TextEditor::line_height() const { - return font().preferred_line_height(); + return static_cast<int>(ceilf(font().preferred_line_height())); } int TextEditor::fixed_glyph_width() const diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.h b/Userland/Libraries/LibGfx/Font/BitmapFont.h index 0d51de96f3..b1f77d444b 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.h +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.h @@ -69,7 +69,7 @@ public: float glyphs_horizontal_kerning(u32, u32) const override { return 0.f; } u8 glyph_height() const override { return m_glyph_height; } int x_height() const override { return m_x_height; } - int preferred_line_height() const override { return glyph_height() + m_line_gap; } + virtual float preferred_line_height() const override { return glyph_height() + m_line_gap; } virtual float glyph_width(u32 code_point) const override; u8 raw_glyph_width(u32 code_point) const { return m_glyph_widths[code_point]; } diff --git a/Userland/Libraries/LibGfx/Font/Font.h b/Userland/Libraries/LibGfx/Font/Font.h index f5786923ec..0ae909ffcb 100644 --- a/Userland/Libraries/LibGfx/Font/Font.h +++ b/Userland/Libraries/LibGfx/Font/Font.h @@ -156,7 +156,7 @@ public: virtual float glyphs_horizontal_kerning(u32 left_code_point, u32 right_code_point) const = 0; virtual u8 glyph_height() const = 0; virtual int x_height() const = 0; - virtual int preferred_line_height() const = 0; + virtual float preferred_line_height() const = 0; virtual u8 min_glyph_width() const = 0; virtual u8 max_glyph_width() const = 0; diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp index fbf01b04c8..ec7365400b 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp @@ -534,7 +534,7 @@ Gfx::ScaledFontMetrics Font::metrics([[maybe_unused]] float x_scale, float y_sca return Gfx::ScaledFontMetrics { .ascender = static_cast<float>(raw_ascender) * y_scale, - .descender = static_cast<float>(raw_descender) * y_scale, + .descender = -static_cast<float>(raw_descender) * y_scale, .line_gap = static_cast<float>(raw_line_gap) * y_scale, }; } diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp index 9f2c5700d6..70437e9040 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp @@ -111,7 +111,7 @@ Gfx::FontPixelMetrics ScaledFont::pixel_metrics() const .advance_of_ascii_zero = (float)glyph_width('0'), .glyph_spacing = (float)glyph_spacing(), .ascent = metrics.ascender, - .descent = -metrics.descender, + .descent = metrics.descender, .line_gap = metrics.line_gap, }; } diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.h b/Userland/Libraries/LibGfx/Font/ScaledFont.h index e346c7b581..25c037893d 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.h +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.h @@ -55,7 +55,7 @@ public: virtual float glyph_width(u32 code_point) const override; virtual float glyph_or_emoji_width(u32 code_point) const override; virtual float glyphs_horizontal_kerning(u32 left_code_point, u32 right_code_point) const override; - virtual int preferred_line_height() const override { return metrics().height() + metrics().line_gap; } + virtual float preferred_line_height() const override { return metrics().height() + metrics().line_gap; } virtual u8 glyph_height() const override { return m_point_height; } virtual int x_height() const override { return m_point_height; } // FIXME: Read from font virtual u8 min_glyph_width() const override { return 1; } // FIXME: Read from font diff --git a/Userland/Libraries/LibGfx/Font/VectorFont.h b/Userland/Libraries/LibGfx/Font/VectorFont.h index 2a47fb3406..df49609fb4 100644 --- a/Userland/Libraries/LibGfx/Font/VectorFont.h +++ b/Userland/Libraries/LibGfx/Font/VectorFont.h @@ -18,9 +18,9 @@ struct ScaledFontMetrics { float descender { 0 }; float line_gap { 0 }; - int height() const + float height() const { - return ascender - descender; + return ascender + descender; } }; |