MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _get_text_metrics_with_cache

Function _get_text_metrics_with_cache

lib/matplotlib/text.py:47–59  ·  view source on GitHub ↗

Call ``renderer.get_text_width_height_descent``, caching the results.

(renderer, text, fontprop, ismath, dpi)

Source from the content-addressed store, hash-verified

45
46
47def _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi):
48 """Call ``renderer.get_text_width_height_descent``, caching the results."""
49
50 # hit the outer cache layer and get the function to compute the metrics
51 # for this renderer instance
52 get_text_metrics = _get_text_metrics_function(renderer)
53 # call the function to compute the metrics and return
54 #
55 # We pass a copy of the fontprop because FontProperties is both mutable and
56 # has a `__hash__` that depends on that mutable state. This is not ideal
57 # as it means the hash of an object is not stable over time which leads to
58 # very confusing behavior when used as keys in dictionaries or hashes.
59 return get_text_metrics(text, fontprop.copy(), ismath, dpi)
60
61
62def _get_text_metrics_function(input_renderer, _cache=weakref.WeakKeyDictionary()):

Callers 2

_get_layoutMethod · 0.85

Calls 2

copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…