diff --git a/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp b/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp index 6dad4fcbb6..b9c4e94494 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp +++ b/Userland/Libraries/LibPDF/Fonts/Type1Font.cpp @@ -79,7 +79,7 @@ void Type1Font::draw_glyph(Gfx::Painter& painter, Gfx::FloatPoint point, float w point = point.translated(translation); auto glyph_position = Gfx::GlyphRasterPosition::get_nearest_fit_for(point); - Gfx::GlyphIndexWithSubpixelOffset index { char_code, glyph_position.subpixel_offset }; + Type1GlyphCacheKey index { char_code, glyph_position.subpixel_offset, width }; RefPtr bitmap; auto maybe_bitmap = m_glyph_cache.get(index); diff --git a/Userland/Libraries/LibPDF/Fonts/Type1Font.h b/Userland/Libraries/LibPDF/Fonts/Type1Font.h index ced7adce69..911626f6e1 100644 --- a/Userland/Libraries/LibPDF/Fonts/Type1Font.h +++ b/Userland/Libraries/LibPDF/Fonts/Type1Font.h @@ -12,6 +12,14 @@ namespace PDF { +struct Type1GlyphCacheKey { + u32 glyph_id; + Gfx::GlyphSubpixelOffset subpixel_offset; + float width; + + bool operator==(Type1GlyphCacheKey const&) const = default; +}; + class Type1Font : public SimpleFont { public: float get_glyph_width(u8 char_code) const override; @@ -25,7 +33,19 @@ protected: private: RefPtr m_font_program; RefPtr m_font; - HashMap> m_glyph_cache; + HashMap> m_glyph_cache; +}; + +} + +namespace AK { + +template<> +struct Traits : public GenericTraits { + static unsigned hash(PDF::Type1GlyphCacheKey const& index) + { + return pair_int_hash(pair_int_hash(index.glyph_id, (index.subpixel_offset.x << 8) | index.subpixel_offset.y), int_hash(bit_cast(index.width))); + } }; }