From 3ed0381a2a78f0a652a3e37464c61c784334a13f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 19 Aug 2024 18:05:29 +0200 Subject: [PATCH] LibGfx: Remove unused font code dealing with left-side bearing --- Userland/Libraries/LibGfx/Font/Font.h | 1 - Userland/Libraries/LibGfx/Font/ScaledFont.cpp | 6 ------ Userland/Libraries/LibGfx/Font/ScaledFont.h | 1 - Userland/Libraries/LibGfx/TextLayout.cpp | 8 +------- Userland/Libraries/LibGfx/TextLayout.h | 12 +----------- .../Libraries/LibWeb/Layout/InlineLevelIterator.cpp | 2 +- .../LibWeb/Painting/DisplayListRecorder.cpp | 2 +- 7 files changed, 4 insertions(+), 28 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/Font.h b/Userland/Libraries/LibGfx/Font/Font.h index a0416efccef..10db1b4c086 100644 --- a/Userland/Libraries/LibGfx/Font/Font.h +++ b/Userland/Libraries/LibGfx/Font/Font.h @@ -76,7 +76,6 @@ public: virtual bool contains_glyph(u32 code_point) const = 0; virtual u32 glyph_id_for_code_point(u32 code_point) const = 0; - virtual float glyph_left_bearing(u32 code_point) const = 0; virtual float glyph_width(u32 code_point) const = 0; virtual float glyph_or_emoji_width(Utf8CodePointIterator&) const = 0; virtual float glyphs_horizontal_kerning(u32 left_code_point, u32 right_code_point) const = 0; diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp index 48a5e47375b..9971c84595a 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp @@ -63,12 +63,6 @@ ALWAYS_INLINE float ScaledFont::unicode_view_width(T const& view) const return longest_width; } -float ScaledFont::glyph_left_bearing(u32 code_point) const -{ - auto id = glyph_id_for_code_point(code_point); - return glyph_metrics(id).left_side_bearing; -} - float ScaledFont::glyph_width(u32 code_point) const { auto id = glyph_id_for_code_point(code_point); diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.h b/Userland/Libraries/LibGfx/Font/ScaledFont.h index a9e011bba06..7ad91010b3f 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.h +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.h @@ -29,7 +29,6 @@ public: virtual Gfx::FontPixelMetrics pixel_metrics() const override; virtual u8 slope() const override { return m_typeface->slope(); } virtual u16 weight() const override { return m_typeface->weight(); } - virtual float glyph_left_bearing(u32 code_point) const override; virtual bool contains_glyph(u32 code_point) const override { return m_typeface->glyph_id_for_code_point(code_point) > 0; } virtual float glyph_width(u32 code_point) const override; virtual float glyph_or_emoji_width(Utf8CodePointIterator&) const override; diff --git a/Userland/Libraries/LibGfx/TextLayout.cpp b/Userland/Libraries/LibGfx/TextLayout.cpp index afa68e77fa4..c7a78dc703b 100644 --- a/Userland/Libraries/LibGfx/TextLayout.cpp +++ b/Userland/Libraries/LibGfx/TextLayout.cpp @@ -22,7 +22,7 @@ static DrawGlyphOrEmoji construct_glyph_or_emoji(size_t index, FloatPoint const& }; } -void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, Gfx::Font const& font, Function callback, IncludeLeftBearing include_left_bearing, Optional width) +void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, Gfx::Font const& font, Function callback, Optional width) { hb_buffer_t* buffer = hb_buffer_create(); ScopeGuard destroy_buffer = [&]() { hb_buffer_destroy(buffer); }; @@ -46,12 +46,6 @@ void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, Gfx::Fo auto position = point - FloatPoint { 0, font.pixel_metrics().ascent } + FloatPoint { positions[i].x_offset, positions[i].y_offset } / text_shaping_resolution; - if (include_left_bearing == IncludeLeftBearing::Yes) { - VERIFY(is(font)); - auto bearing = static_cast(font).glyph_metrics(glyph_info[i].codepoint).left_side_bearing; - position += FloatPoint { bearing, 0 }; - } - callback(construct_glyph_or_emoji(i, position, font, { glyph_info, glyph_count }, input_glyph_info.span())); point += FloatPoint { positions[i].x_advance, positions[i].y_advance } / text_shaping_resolution; } diff --git a/Userland/Libraries/LibGfx/TextLayout.h b/Userland/Libraries/LibGfx/TextLayout.h index 81493b36238..7e452b59b2b 100644 --- a/Userland/Libraries/LibGfx/TextLayout.h +++ b/Userland/Libraries/LibGfx/TextLayout.h @@ -20,16 +20,6 @@ namespace Gfx { -inline bool should_paint_as_space(u32 code_point) -{ - return is_ascii_space(code_point) || code_point == 0xa0; -} - -enum class IncludeLeftBearing { - Yes, - No -}; - struct DrawGlyph { FloatPoint position; u32 glyph_id; @@ -72,6 +62,6 @@ private: NonnullRefPtr m_font; }; -void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, Gfx::Font const& font, Function callback, IncludeLeftBearing include_left_bearing = IncludeLeftBearing::No, Optional width = {}); +void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, Gfx::Font const& font, Function callback, Optional width = {}); } diff --git a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp index 0b5d1424573..7c3ee7ceff0 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp @@ -201,7 +201,7 @@ Optional InlineLevelIterator::next_without_lookahead( { 0, 0 }, chunk.view, chunk.font, [&](Gfx::DrawGlyphOrEmoji const& glyph_or_emoji) { glyph_run.append(glyph_or_emoji); }, - Gfx::IncludeLeftBearing::No, glyph_run_width); + glyph_run_width); CSSPixels chunk_width = CSSPixels::nearest_value_for(glyph_run_width); diff --git a/Userland/Libraries/LibWeb/Painting/DisplayListRecorder.cpp b/Userland/Libraries/LibWeb/Painting/DisplayListRecorder.cpp index 5cffdd42104..dfb158e4d21 100644 --- a/Userland/Libraries/LibWeb/Painting/DisplayListRecorder.cpp +++ b/Userland/Libraries/LibWeb/Painting/DisplayListRecorder.cpp @@ -239,7 +239,7 @@ void DisplayListRecorder::draw_text(Gfx::IntRect const& rect, String raw_text, G { 0, 0 }, raw_text.code_points(), font, [&](Gfx::DrawGlyphOrEmoji const& glyph_or_emoji) { glyph_run->append(glyph_or_emoji); }, - Gfx::IncludeLeftBearing::No, glyph_run_width); + glyph_run_width); float baseline_x = 0; if (alignment == Gfx::TextAlignment::CenterLeft) {