From bd9bca2424964239baeaf9d1b5ecb1be4d87fa68 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Thu, 2 May 2024 16:23:09 +0200 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20cache=20Pango=20fonts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calculating the description hash is cheap, but we really should cache this in the FontConfiguration object where the Pango map is stored. Fix #2144. --- weasyprint/text/fonts.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/weasyprint/text/fonts.py b/weasyprint/text/fonts.py index 98aa0a0bd..110166f7a 100644 --- a/weasyprint/text/fonts.py +++ b/weasyprint/text/fonts.py @@ -1,6 +1,5 @@ """Interface with external libraries managing fonts installed on the system.""" -from functools import lru_cache from hashlib import md5 from io import BytesIO from pathlib import Path @@ -389,9 +388,12 @@ def get_hb_object_data(hb_object, ot_color=None, glyph=None): return data -@lru_cache() def get_pango_font_key(pango_font): """Get key corresponding to given Pango font.""" + # TODO: This value is stable for a given Pango font in a given Pango map, but can’t + # be cached with just the Pango font as a key because two Pango fonts could point to + # the same address for two different Pango maps. We should cache it in the + # FontConfiguration object. See https://github.com/Kozea/WeasyPrint/issues/2144 description = ffi.gc( pango.pango_font_describe(pango_font), pango.pango_font_description_free)