mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibGfx/OpenType: Make glyph_width() only fetch the glyph advance
Instead of fetching a generic set of metrics for each glyph, only fetch the advance when that's all we need. This is extremely hot in LibWeb text layout, where it makes a nice dent.
This commit is contained in:
parent
2b8a920a7c
commit
f48024c2d1
Notes:
sideshowbarker
2024-07-17 17:06:59 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/f48024c2d1 Pull-request: https://github.com/SerenityOS/serenity/pull/23708 Reviewed-by: https://github.com/kalenikaliaksandr ✅
6 changed files with 20 additions and 2 deletions
|
@ -413,6 +413,21 @@ Font::EmbeddedBitmapData Font::embedded_bitmap_data_for_glyph(u32 glyph_id) cons
|
|||
return Empty {};
|
||||
}
|
||||
|
||||
float Font::glyph_advance(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const
|
||||
{
|
||||
if (has_color_bitmaps())
|
||||
return glyph_metrics(glyph_id, x_scale, y_scale, point_width, point_height).advance_width;
|
||||
|
||||
if (!m_hmtx.has_value())
|
||||
return 0;
|
||||
|
||||
if (glyph_id >= glyph_count())
|
||||
glyph_id = 0;
|
||||
|
||||
auto horizontal_metrics = m_hmtx->get_glyph_horizontal_metrics(glyph_id);
|
||||
return static_cast<float>(horizontal_metrics.advance_width) * x_scale;
|
||||
}
|
||||
|
||||
Gfx::ScaledGlyphMetrics Font::glyph_metrics(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const
|
||||
{
|
||||
auto embedded_bitmap_metrics = embedded_bitmap_data_for_glyph(glyph_id).visit(
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
|
||||
virtual Gfx::ScaledFontMetrics metrics(float x_scale, float y_scale) const override;
|
||||
virtual Gfx::ScaledGlyphMetrics glyph_metrics(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const override;
|
||||
virtual float glyph_advance(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const override;
|
||||
virtual float glyphs_horizontal_kerning(u32 left_glyph_id, u32 right_glyph_id, float x_scale) const override;
|
||||
virtual RefPtr<Gfx::Bitmap> rasterize_glyph(u32 glyph_id, float x_scale, float y_scale, Gfx::GlyphSubpixelOffset) const override;
|
||||
virtual bool append_glyph_path_to(Gfx::Path&, u32 glyph_id, float x_scale, float y_scale) const override;
|
||||
|
|
|
@ -110,8 +110,7 @@ float ScaledFont::glyph_left_bearing(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;
|
||||
return m_font->glyph_advance(id, m_x_scale, m_y_scale, m_point_width, m_point_height);
|
||||
}
|
||||
|
||||
template<typename CodePointIterator>
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
virtual ~VectorFont();
|
||||
virtual ScaledFontMetrics metrics(float x_scale, float y_scale) const = 0;
|
||||
virtual ScaledGlyphMetrics glyph_metrics(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const = 0;
|
||||
virtual float glyph_advance(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const = 0;
|
||||
virtual float glyphs_horizontal_kerning(u32 left_glyph_id, u32 right_glyph_id, float x_scale) const = 0;
|
||||
virtual RefPtr<Gfx::Bitmap> rasterize_glyph(u32 glyph_id, float x_scale, float y_scale, GlyphSubpixelOffset) const = 0;
|
||||
virtual bool append_glyph_path_to(Gfx::Path&, u32 glyph_id, float x_scale, float y_scale) const = 0;
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
|
||||
virtual Gfx::ScaledFontMetrics metrics(float x_scale, float y_scale) const override { return m_input_font->metrics(x_scale, y_scale); }
|
||||
virtual Gfx::ScaledGlyphMetrics glyph_metrics(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const override { return m_input_font->glyph_metrics(glyph_id, x_scale, y_scale, point_width, point_height); }
|
||||
virtual float glyph_advance(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const override { return m_input_font->glyph_advance(glyph_id, x_scale, y_scale, point_width, point_height); }
|
||||
virtual float glyphs_horizontal_kerning(u32 left_glyph_id, u32 right_glyph_id, float x_scale) const override { return m_input_font->glyphs_horizontal_kerning(left_glyph_id, right_glyph_id, x_scale); }
|
||||
virtual RefPtr<Gfx::Bitmap> rasterize_glyph(u32 glyph_id, float x_scale, float y_scale, Gfx::GlyphSubpixelOffset subpixel_offset) const override { return m_input_font->rasterize_glyph(glyph_id, x_scale, y_scale, subpixel_offset); }
|
||||
virtual bool append_glyph_path_to(Gfx::Path& path, u32 glyph_id, float x_scale, float y_scale) const override { return m_input_font->append_glyph_path_to(path, glyph_id, x_scale, y_scale); }
|
||||
|
|
|
@ -27,6 +27,7 @@ public:
|
|||
|
||||
virtual Gfx::ScaledFontMetrics metrics(float x_scale, float y_scale) const override { return m_input_font->metrics(x_scale, y_scale); }
|
||||
virtual Gfx::ScaledGlyphMetrics glyph_metrics(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const override { return m_input_font->glyph_metrics(glyph_id, x_scale, y_scale, point_width, point_height); }
|
||||
virtual float glyph_advance(u32 glyph_id, float x_scale, float y_scale, float point_width, float point_height) const override { return m_input_font->glyph_advance(glyph_id, x_scale, y_scale, point_width, point_height); }
|
||||
virtual float glyphs_horizontal_kerning(u32 left_glyph_id, u32 right_glyph_id, float x_scale) const override { return m_input_font->glyphs_horizontal_kerning(left_glyph_id, right_glyph_id, x_scale); }
|
||||
virtual RefPtr<Gfx::Bitmap> rasterize_glyph(u32 glyph_id, float x_scale, float y_scale, Gfx::GlyphSubpixelOffset subpixel_offset) const override
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue