mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 01:29:17 +00:00
LibGfx: Remove Bitmap::glyph_spacing()
This was only ever non-zero for SerenityOS bitmap fonts.
This commit is contained in:
parent
04a6e2f83d
commit
1a2a34fa43
Notes:
sideshowbarker
2024-07-17 06:40:35 +09:00
Author: https://github.com/awesomekling
Commit: 1a2a34fa43
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/42
9 changed files with 10 additions and 26 deletions
|
@ -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;
|
||||
|
|
|
@ -29,7 +29,6 @@ ScaledFont::ScaledFont(NonnullRefPtr<VectorFont> 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,
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -116,14 +116,12 @@ Vector<ByteString, 32> TextLayout::wrap_lines(TextElision elision, TextWrapping
|
|||
Vector<ByteString> 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<ByteString, 32> 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<ByteString, 32> 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<float>(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);
|
||||
}
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ template<typename Callback>
|
|||
void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, FontCascadeList const& font_list, Callback callback, IncludeLeftBearing include_left_bearing = IncludeLeftBearing::No, Optional<float&> 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<DrawGlyph>())
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -204,9 +204,6 @@ Optional<InlineLevelIterator::Item> 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.
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue