Skip to content

Commit

Permalink
Don’t cache Pango fonts
Browse files Browse the repository at this point in the history
Calculating the description hash is cheap, but we really should cache this in
the FontConfiguration object where the Pango map is stored.

Fix #2144.
  • Loading branch information
liZe committed May 2, 2024
1 parent 6dd6470 commit bd9bca2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions weasyprint/text/fonts.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bd9bca2

Please sign in to comment.