mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
LibGfx: Don't try to paint glyphs that aren't in a font
Fixes https://github.com/LadybirdBrowser/ladybird/issues/88
This commit is contained in:
parent
1bde774918
commit
fbc42e7d42
Notes:
sideshowbarker
2024-07-17 07:14:09 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/fbc42e7d42 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/179 Issue: https://github.com/LadybirdBrowser/ladybird/issues/88
@ -25,12 +25,12 @@ void GlyphAtlas::update(HashMap<Gfx::Font const*, HashTable<u32>> const& unique_
|
||||
for (auto const& [font, code_points] : unique_glyphs) {
|
||||
for (auto const& code_point : code_points) {
|
||||
auto glyph = font->glyph(code_point);
|
||||
if (!glyph.has_value())
|
||||
continue;
|
||||
auto atlas_key = GlyphsTextureKey { font, code_point };
|
||||
if (!m_glyphs_texture_map.contains(atlas_key))
|
||||
need_to_rebuild_texture = true;
|
||||
if (glyph.bitmap()) {
|
||||
glyph_bitmaps.set(atlas_key, *glyph.bitmap());
|
||||
}
|
||||
glyph_bitmaps.set(atlas_key, *glyph->bitmap());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
|
||||
bool is_color_bitmap() const { return m_color_bitmap; }
|
||||
|
||||
RefPtr<Bitmap> bitmap() const { return m_bitmap; }
|
||||
[[nodiscard]] NonnullRefPtr<Bitmap> bitmap() const { return m_bitmap; }
|
||||
float left_bearing() const { return m_left_bearing; }
|
||||
float advance() const { return m_advance; }
|
||||
float ascent() const { return m_ascent; }
|
||||
@ -116,8 +116,8 @@ public:
|
||||
virtual int pixel_size_rounded_up() const = 0;
|
||||
|
||||
virtual u16 weight() const = 0;
|
||||
virtual Glyph glyph(u32 code_point) const = 0;
|
||||
virtual Glyph glyph(u32 code_point, GlyphSubpixelOffset) const = 0;
|
||||
virtual Optional<Glyph> glyph(u32 code_point) const = 0;
|
||||
virtual Optional<Glyph> glyph(u32 code_point, GlyphSubpixelOffset) const = 0;
|
||||
virtual bool contains_glyph(u32 code_point) const = 0;
|
||||
|
||||
virtual float glyph_left_bearing(u32 code_point) const = 0;
|
||||
|
@ -80,15 +80,17 @@ bool ScaledFont::append_glyph_path_to(Gfx::Path& path, u32 glyph_id) const
|
||||
return m_font->append_glyph_path_to(path, glyph_id, m_x_scale, m_y_scale);
|
||||
}
|
||||
|
||||
Gfx::Glyph ScaledFont::glyph(u32 code_point) const
|
||||
Optional<Glyph> ScaledFont::glyph(u32 code_point) const
|
||||
{
|
||||
return glyph(code_point, GlyphSubpixelOffset { 0, 0 });
|
||||
}
|
||||
|
||||
Gfx::Glyph ScaledFont::glyph(u32 code_point, GlyphSubpixelOffset subpixel_offset) const
|
||||
Optional<Glyph> ScaledFont::glyph(u32 code_point, GlyphSubpixelOffset subpixel_offset) const
|
||||
{
|
||||
auto id = glyph_id_for_code_point(code_point);
|
||||
auto bitmap = rasterize_glyph(id, subpixel_offset);
|
||||
if (!bitmap)
|
||||
return {};
|
||||
auto metrics = glyph_metrics(id);
|
||||
return Gfx::Glyph(*bitmap, metrics.left_side_bearing, metrics.advance_width, metrics.ascender, m_font->has_color_bitmaps());
|
||||
}
|
||||
|
@ -37,9 +37,9 @@ public:
|
||||
virtual Gfx::FontPixelMetrics pixel_metrics() const override;
|
||||
virtual u8 slope() const override { return m_font->slope(); }
|
||||
virtual u16 weight() const override { return m_font->weight(); }
|
||||
virtual Gfx::Glyph glyph(u32 code_point) const override;
|
||||
virtual Optional<Glyph> glyph(u32 code_point) const override;
|
||||
virtual float glyph_left_bearing(u32 code_point) const override;
|
||||
virtual Glyph glyph(u32 code_point, GlyphSubpixelOffset) const override;
|
||||
virtual Optional<Glyph> glyph(u32 code_point, GlyphSubpixelOffset) const override;
|
||||
virtual bool contains_glyph(u32 code_point) const override { return m_font->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;
|
||||
|
@ -849,7 +849,10 @@ FLATTEN void Painter::draw_glyph(FloatPoint point, u32 code_point, Font const& f
|
||||
{
|
||||
auto top_left = point + FloatPoint(font.glyph_left_bearing(code_point), 0);
|
||||
auto glyph_position = Gfx::GlyphRasterPosition::get_nearest_fit_for(top_left);
|
||||
auto glyph = font.glyph(code_point, glyph_position.subpixel_offset);
|
||||
auto maybe_glyph = font.glyph(code_point, glyph_position.subpixel_offset);
|
||||
if (!maybe_glyph.has_value())
|
||||
return;
|
||||
auto glyph = maybe_glyph.release_value();
|
||||
|
||||
if (glyph.is_color_bitmap()) {
|
||||
float scaled_width = glyph.advance();
|
||||
|
Loading…
Reference in New Issue
Block a user