1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-05 08:27:22 +03:00

Don't use a global cache to store font features

This commit is contained in:
Guillaume Ayoub 2018-03-25 16:20:24 +02:00
parent 34e29926b5
commit 4bdfae4eb6
2 changed files with 5 additions and 5 deletions

View File

@ -79,7 +79,10 @@ class LayoutContext(object):
self.excluded_shapes = None # Not initialized yet
self.string_set = defaultdict(lambda: defaultdict(lambda: list()))
self.current_page = None
# Cache
self.strut_layouts = {}
self.font_features = {}
def create_block_formatting_context(self):
self.excluded_shapes = []

View File

@ -27,9 +27,6 @@ CAIRO_DUMMY_CONTEXT = {
False: cairo.Context(cairo.PDFSurface(None, 1, 1))}
PANGO_ATTR_FONT_FEATURES_CACHE = {}
ffi = cffi.FFI()
ffi.cdef('''
// Cairo
@ -889,7 +886,7 @@ def create_layout(text, style, context, max_width, justification_spacing):
# TODO: attributes should be freed.
# In the meantime, keep a cache to avoid leaking too many of them.
attr = PANGO_ATTR_FONT_FEATURES_CACHE.get(features)
attr = context.font_features.get(features)
if attr is None:
try:
attr = pango.pango_attr_font_features_new(
@ -898,7 +895,7 @@ def create_layout(text, style, context, max_width, justification_spacing):
LOGGER.error(
'OpenType features are not available with Pango < 1.38')
else:
PANGO_ATTR_FONT_FEATURES_CACHE[features] = attr
context.font_features[features] = attr
if attr is not None:
attr_list = pango.pango_attr_list_new()
pango.pango_attr_list_insert(attr_list, attr)