Call ``renderer.get_text_width_height_descent``, caching the results.
(renderer, text, fontprop, ismath, dpi)
| 45 | |
| 46 | |
| 47 | def _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 | |
| 62 | def _get_text_metrics_function(input_renderer, _cache=weakref.WeakKeyDictionary()): |
no test coverage detected
searching dependent graphs…