From 1a2a34fa435bd0dfde318706da66c4f232b004f8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 4 Jun 2024 07:02:22 +0200 Subject: [PATCH] LibGfx: Remove Bitmap::glyph_spacing() This was only ever non-zero for SerenityOS bitmap fonts. --- Userland/Libraries/LibGfx/Font/Font.h | 3 --- Userland/Libraries/LibGfx/Font/ScaledFont.cpp | 1 - Userland/Libraries/LibGfx/Font/ScaledFont.h | 1 - Userland/Libraries/LibGfx/Painter.cpp | 4 ++-- Userland/Libraries/LibGfx/TextLayout.cpp | 11 ++--------- Userland/Libraries/LibGfx/TextLayout.h | 6 +++--- Userland/Libraries/LibWeb/CSS/Length.cpp | 2 +- .../Libraries/LibWeb/Layout/InlineLevelIterator.cpp | 3 --- .../Libraries/LibWeb/Painting/PaintableFragment.cpp | 5 ++--- 9 files changed, 10 insertions(+), 26 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/Font.h b/Userland/Libraries/LibGfx/Font/Font.h index 518d324d44f..f2ed6189258 100644 --- a/Userland/Libraries/LibGfx/Font/Font.h +++ b/Userland/Libraries/LibGfx/Font/Font.h @@ -116,7 +116,6 @@ struct FontPixelMetrics { float size { 0 }; float x_height { 0 }; float advance_of_ascii_zero { 0 }; - float glyph_spacing { 0 }; // Number of pixels the font extends above the baseline. float ascent { 0 }; @@ -195,8 +194,6 @@ public: virtual bool is_fixed_width() const = 0; - virtual u8 glyph_spacing() const = 0; - virtual size_t glyph_count() const = 0; virtual String family() const = 0; diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp index 51b38d1cdee..81e3e240512 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp @@ -29,7 +29,6 @@ ScaledFont::ScaledFont(NonnullRefPtr font, float point_width, float .size = (float)pixel_size(), .x_height = metrics.x_height, .advance_of_ascii_zero = (float)glyph_width('0'), - .glyph_spacing = (float)glyph_spacing(), .ascent = metrics.ascender, .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 11fae5eec8c..b895921ba53 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.h +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.h @@ -62,7 +62,6 @@ public: virtual int width_rounded_up(StringView) const override; virtual String name() const override { return MUST(String::formatted("{} {}", family(), variant())); } virtual bool is_fixed_width() const override { return m_font->is_fixed_width(); } - virtual u8 glyph_spacing() const override { return 0; } virtual size_t glyph_count() const override { return m_font->glyph_count(); } virtual String family() const override { return m_font->family(); } virtual String variant() const override { return m_font->variant(); } diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 616df39af67..0226ec3ebd0 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -1028,7 +1028,7 @@ void draw_text_line(FloatRect const& a_rect, Utf8View const& text, Font const& f } auto point = rect.location(); - auto space_width = font.glyph_width(' ') + font.glyph_spacing(); + auto space_width = font.glyph_width(' '); if (direction == TextDirection::RTL) { point.translate_by(rect.width(), 0); // Start drawing from the end @@ -1049,7 +1049,7 @@ void draw_text_line(FloatRect const& a_rect, Utf8View const& text, Font const& f point.translate_by(direction == TextDirection::LTR ? kerning : -kerning, 0); auto it_copy = it; // The callback function will advance the iterator, so create a copy for this lookup. - FloatSize glyph_size(font.glyph_or_emoji_width(it_copy) + font.glyph_spacing(), font.pixel_size()); + FloatSize glyph_size(font.glyph_or_emoji_width(it_copy), font.pixel_size()); if (direction == TextDirection::RTL) point.translate_by(-glyph_size.width(), 0); // If we are drawing right to left, we have to move backwards before drawing the glyph diff --git a/Userland/Libraries/LibGfx/TextLayout.cpp b/Userland/Libraries/LibGfx/TextLayout.cpp index 54a6b6f15be..62bf8aab29a 100644 --- a/Userland/Libraries/LibGfx/TextLayout.cpp +++ b/Userland/Libraries/LibGfx/TextLayout.cpp @@ -116,14 +116,12 @@ Vector TextLayout::wrap_lines(TextElision elision, TextWrapping Vector lines; StringBuilder builder; float line_width = 0; - size_t current_block = 0; for (Block& block : blocks) { switch (block.type) { case BlockType::Newline: { lines.append(builder.to_byte_string()); builder.clear(); line_width = 0; - current_block++; continue; } case BlockType::Whitespace: @@ -131,9 +129,6 @@ Vector TextLayout::wrap_lines(TextElision elision, TextWrapping float block_width = m_font.width(block.characters); // FIXME: This should look at the specific advance amount of the // last character, but we don't support that yet. - if (current_block != blocks.size() - 1) { - block_width += m_font.glyph_spacing(); - } if (wrapping == TextWrapping::Wrap && line_width + block_width > m_rect.width()) { lines.append(builder.to_byte_string()); @@ -143,7 +138,6 @@ Vector TextLayout::wrap_lines(TextElision elision, TextWrapping builder.append(block.characters.as_string()); line_width += block_width; - current_block++; } } } @@ -170,7 +164,6 @@ ByteString TextLayout::elide_text_from_right(Utf8View text) const if (text_width > static_cast(m_rect.width())) { float ellipsis_width = m_font.width("..."sv); float current_width = ellipsis_width; - size_t glyph_spacing = m_font.glyph_spacing(); // FIXME: This code will break when the font has glyphs with advance // amounts different from the actual width of the glyph @@ -182,10 +175,10 @@ ByteString TextLayout::elide_text_from_right(Utf8View text) const // NOTE: Glyph spacing should not be added after the last glyph on the line, // but since we are here because the last glyph does not actually fit on the line, // we don't have to worry about spacing. - auto width_with_this_glyph_included = current_width + glyph_width + glyph_spacing; + auto width_with_this_glyph_included = current_width + glyph_width; if (width_with_this_glyph_included > m_rect.width()) break; - current_width += glyph_width + glyph_spacing; + current_width += glyph_width; offset = text.iterator_offset(it); } diff --git a/Userland/Libraries/LibGfx/TextLayout.h b/Userland/Libraries/LibGfx/TextLayout.h index a4e24e108a5..5d66ca60261 100644 --- a/Userland/Libraries/LibGfx/TextLayout.h +++ b/Userland/Libraries/LibGfx/TextLayout.h @@ -123,7 +123,7 @@ template void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, FontCascadeList const& font_list, Callback callback, IncludeLeftBearing include_left_bearing = IncludeLeftBearing::No, Optional width = {}) { auto const& space_glyph_font = font_list.font_for_code_point(' '); - float space_width = space_glyph_font.glyph_width(' ') + space_glyph_font.glyph_spacing(); + float space_width = space_glyph_font.glyph_width(' '); u32 last_code_point = 0; @@ -145,7 +145,7 @@ void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, FontCas if (kerning != 0.0f) point.translate_by(kerning, 0); - auto glyph_width = font->glyph_or_emoji_width(it) + font->glyph_spacing(); + auto glyph_width = font->glyph_or_emoji_width(it); auto glyph_or_emoji = prepare_draw_glyph_or_emoji(point, code_point_iterator, *font); if (include_left_bearing == IncludeLeftBearing::Yes) { if (glyph_or_emoji.has()) @@ -159,7 +159,7 @@ void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, FontCas } if (width.has_value()) - *width = point.x() - font_list.first().glyph_spacing(); + *width = point.x(); } } diff --git a/Userland/Libraries/LibWeb/CSS/Length.cpp b/Userland/Libraries/LibWeb/CSS/Length.cpp index 7b2097885aa..968bac6267a 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.cpp +++ b/Userland/Libraries/LibWeb/CSS/Length.cpp @@ -25,7 +25,7 @@ Length::FontMetrics::FontMetrics(CSSPixels font_size, Gfx::FontPixelMetrics cons // FIXME: This is only approximately the cap height. The spec suggests measuring the "O" glyph: // https://www.w3.org/TR/css-values-4/#cap , cap_height(pixel_metrics.ascent) - , zero_advance(pixel_metrics.advance_of_ascii_zero + pixel_metrics.glyph_spacing) + , zero_advance(pixel_metrics.advance_of_ascii_zero) , line_height(round(pixel_metrics.line_spacing())) { } diff --git a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp index 1f76c1b1d38..fc32c38aca8 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp @@ -204,9 +204,6 @@ Optional InlineLevelIterator::next_without_lookahead( }, Gfx::IncludeLeftBearing::No, glyph_run_width); - if (!m_text_node_context->is_last_chunk) - glyph_run_width += text_node.first_available_font().glyph_spacing(); - CSSPixels chunk_width = CSSPixels::nearest_value_for(glyph_run_width); // NOTE: We never consider `content: ""` to be collapsible whitespace. diff --git a/Userland/Libraries/LibWeb/Painting/PaintableFragment.cpp b/Userland/Libraries/LibWeb/Painting/PaintableFragment.cpp index 388679031b9..2d12ed89cb6 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableFragment.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableFragment.cpp @@ -41,7 +41,6 @@ int PaintableFragment::text_index_at(CSSPixels x) const Utf8View view(string_view()); CSSPixels relative_x = x - absolute_rect().x(); - CSSPixels glyph_spacing = font.glyph_spacing(); if (relative_x < 0) return 0; @@ -51,10 +50,10 @@ int PaintableFragment::text_index_at(CSSPixels x) const auto previous_it = it; CSSPixels glyph_width = CSSPixels::nearest_value_for(font.glyph_or_emoji_width(it)); - if ((width_so_far + glyph_width + glyph_spacing / 2) > relative_x) + if ((width_so_far + glyph_width) > relative_x) return m_start + view.byte_offset_of(previous_it); - width_so_far += glyph_width + glyph_spacing; + width_so_far += glyph_width; } return m_start + m_length;