From 555d7a6fced8a3014b3ad6d6b380d8c27270e72d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 3 Jan 2023 14:55:48 +0100 Subject: [PATCH] LibGfx: Make Font::glyph_width*() APIs return float --- Userland/Libraries/LibGfx/Font/BitmapFont.cpp | 2 +- Userland/Libraries/LibGfx/Font/BitmapFont.h | 4 ++-- Userland/Libraries/LibGfx/Font/Font.h | 4 ++-- Userland/Libraries/LibGfx/Font/ScaledFont.cpp | 4 ++-- Userland/Libraries/LibGfx/Font/ScaledFont.h | 4 ++-- Userland/Libraries/LibGfx/Painter.cpp | 2 +- Userland/Libraries/LibVT/TerminalWidget.cpp | 8 ++++---- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp index 7fb9d9ad39c..0975befe14d 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp @@ -308,7 +308,7 @@ bool BitmapFont::contains_glyph(u32 code_point) const return index.has_value() && m_glyph_widths[index.value()] > 0; } -u8 BitmapFont::glyph_width(u32 code_point) const +float BitmapFont::glyph_width(u32 code_point) const { if (is_ascii(code_point) && !is_ascii_printable(code_point)) return 0; diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.h b/Userland/Libraries/LibGfx/Font/BitmapFont.h index c0f680a17a5..9a36fe8472a 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.h +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.h @@ -56,7 +56,7 @@ public: bool contains_glyph(u32 code_point) const override; bool contains_raw_glyph(u32 code_point) const { return m_glyph_widths[code_point] > 0; } - ALWAYS_INLINE int glyph_or_emoji_width(u32 code_point) const override + virtual float glyph_or_emoji_width(u32 code_point) const override { if (m_fixed_width) return m_glyph_width; @@ -67,7 +67,7 @@ public: int x_height() const override { return m_x_height; } int preferred_line_height() const override { return glyph_height() + m_line_gap; } - u8 glyph_width(u32 code_point) const override; + virtual float glyph_width(u32 code_point) const override; u8 raw_glyph_width(u32 code_point) const { return m_glyph_widths[code_point]; } u8 min_glyph_width() const override { return m_min_glyph_width; } diff --git a/Userland/Libraries/LibGfx/Font/Font.h b/Userland/Libraries/LibGfx/Font/Font.h index 578ffad8aaa..38fffa31cea 100644 --- a/Userland/Libraries/LibGfx/Font/Font.h +++ b/Userland/Libraries/LibGfx/Font/Font.h @@ -126,8 +126,8 @@ public: virtual Glyph glyph(u32 code_point) const = 0; virtual bool contains_glyph(u32 code_point) const = 0; - virtual u8 glyph_width(u32 code_point) const = 0; - virtual int glyph_or_emoji_width(u32 code_point) const = 0; + virtual float glyph_width(u32 code_point) const = 0; + virtual float glyph_or_emoji_width(u32 code_point) const = 0; 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; diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp index 26cd070b72e..aac93571738 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp @@ -57,14 +57,14 @@ Gfx::Glyph ScaledFont::glyph(u32 code_point) const return Gfx::Glyph(bitmap, metrics.left_side_bearing, metrics.advance_width, metrics.ascender); } -u8 ScaledFont::glyph_width(u32 code_point) const +float ScaledFont::glyph_width(u32 code_point) const { auto id = glyph_id_for_code_point(code_point); auto metrics = glyph_metrics(id); return metrics.advance_width; } -int ScaledFont::glyph_or_emoji_width(u32 code_point) const +float ScaledFont::glyph_or_emoji_width(u32 code_point) const { auto id = glyph_id_for_code_point(code_point); auto metrics = glyph_metrics(id); diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.h b/Userland/Libraries/LibGfx/Font/ScaledFont.h index fd2b4186ee6..15d3fa7d40b 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.h +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.h @@ -43,8 +43,8 @@ public: virtual u16 weight() const override { return m_font->weight(); } virtual Gfx::Glyph glyph(u32 code_point) const override; virtual bool contains_glyph(u32 code_point) const override { return m_font->glyph_id_for_code_point(code_point) > 0; } - virtual u8 glyph_width(u32 code_point) const override; - virtual int glyph_or_emoji_width(u32 code_point) const override; + 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 u8 glyph_height() const override { return m_point_height; } diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index afbd2933c00..a8133e433b8 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -2450,7 +2450,7 @@ void Gfx::Painter::draw_ui_text(Gfx::IntRect const& rect, StringView text, Gfx:: if (underline_offset.has_value()) { Utf8View utf8_view { name_to_draw }; - int width = 0; + float width = 0; for (auto it = utf8_view.begin(); it != utf8_view.end(); ++it) { if (utf8_view.byte_offset_of(it) >= underline_offset.value()) { int y = text_rect.bottom() + 1; diff --git a/Userland/Libraries/LibVT/TerminalWidget.cpp b/Userland/Libraries/LibVT/TerminalWidget.cpp index cc83670d077..83a337fe9ae 100644 --- a/Userland/Libraries/LibVT/TerminalWidget.cpp +++ b/Userland/Libraries/LibVT/TerminalWidget.cpp @@ -154,13 +154,13 @@ Gfx::IntRect TerminalWidget::glyph_rect(u16 row, u16 column) { int y = row * m_line_height; int x = column * font().glyph_width('x'); - return { x + frame_thickness() + m_inset, y + frame_thickness() + m_inset, font().glyph_width('x'), font().glyph_height() }; + return { x + frame_thickness() + m_inset, y + frame_thickness() + m_inset, static_cast(ceilf(font().glyph_width('x'))), font().glyph_height() }; } Gfx::IntRect TerminalWidget::row_rect(u16 row) { int y = row * m_line_height; - Gfx::IntRect rect = { frame_thickness() + m_inset, y + frame_thickness() + m_inset, font().glyph_width('x') * m_terminal.columns(), font().glyph_height() }; + Gfx::IntRect rect = { frame_thickness() + m_inset, y + frame_thickness() + m_inset, static_cast(ceilf(font().glyph_width('x'))) * m_terminal.columns(), font().glyph_height() }; rect.inflate(0, m_line_spacing); return rect; } @@ -534,7 +534,7 @@ Gfx::IntSize TerminalWidget::compute_base_size() const void TerminalWidget::apply_size_increments_to_window(GUI::Window& window) { - window.set_size_increment({ font().glyph_width('x'), m_line_height }); + window.set_size_increment({ static_cast(ceilf(font().glyph_width('x'))), m_line_height }); window.set_base_size(compute_base_size()); } @@ -1230,7 +1230,7 @@ void TerminalWidget::update_color_scheme() Gfx::IntSize TerminalWidget::widget_size_for_font(Gfx::Font const& font) const { return { - (frame_thickness() * 2) + (m_inset * 2) + (m_terminal.columns() * font.glyph_width('x')) + m_scrollbar->width(), + (frame_thickness() * 2) + (m_inset * 2) + (m_terminal.columns() * static_cast(ceilf(font.glyph_width('x')))) + m_scrollbar->width(), (frame_thickness() * 2) + (m_inset * 2) + (m_terminal.rows() * (font.glyph_height() + m_line_spacing)) }; }