| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -214,6 +214,10 @@ libpng 1.2 (or later) | |||
| 214 | 214 | ``cycler`` 0.9 or later | |
| 215 | 215 | Composable cycle class used for constructing style-cycles | |
| 216 | 216 | ||
| 217 | + `functools32` | ||
| 218 | + Required for compatibility if running on versions of Python before | ||
| 219 | + Python 3.2. | ||
| 220 | + | ||
| 217 | 221 | ||
| 218 | 222 | Optional GUI framework | |
| 219 | 223 | ^^^^^^^^^^^^^^^^^^^^^^ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,8 +32,8 @@ | |||
| 32 | 32 | FigureManagerBase, FigureCanvasBase | |
| 33 | 33 | from matplotlib.cbook import is_string_like, maxdict, restrict_dict | |
| 34 | 34 | from matplotlib.figure import Figure | |
| 35 | - from matplotlib.font_manager import findfont | ||
| 36 | - from matplotlib.ft2font import FT2Font, LOAD_FORCE_AUTOHINT, LOAD_NO_HINTING, \ | ||
| 35 | + from matplotlib.font_manager import findfont, get_font | ||
| 36 | + from matplotlib.ft2font import LOAD_FORCE_AUTOHINT, LOAD_NO_HINTING, \ | ||
| 37 | 37 | LOAD_DEFAULT, LOAD_NO_AUTOHINT | |
| 38 | 38 | from matplotlib.mathtext import MathTextParser | |
| 39 | 39 | from matplotlib.path import Path | |
@@ -81,7 +81,6 @@ class RendererAgg(RendererBase): | |||
| 81 | 81 | # renderer at a time | |
| 82 | 82 | ||
| 83 | 83 | lock = threading.RLock() | |
| 84 | - _fontd = maxdict(50) | ||
| 85 | 84 | def __init__(self, width, height, dpi): | |
| 86 | 85 | if __debug__: verbose.report('RendererAgg.__init__', 'debug-annoying') | |
| 87 | 86 | RendererBase.__init__(self) | |
@@ -191,6 +190,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): | |||
| 191 | 190 | ||
| 192 | 191 | flags = get_hinting_flag() | |
| 193 | 192 | font = self._get_agg_font(prop) | |
| 193 | + | ||
| 194 | 194 | if font is None: return None | |
| 195 | 195 | if len(s) == 1 and ord(s) > 127: | |
| 196 | 196 | font.load_char(ord(s), flags=flags) | |
@@ -272,18 +272,10 @@ def _get_agg_font(self, prop): | |||
| 272 | 272 | if __debug__: verbose.report('RendererAgg._get_agg_font', | |
| 273 | 273 | 'debug-annoying') | |
| 274 | 274 | ||
| 275 | - key = hash(prop) | ||
| 276 | - font = RendererAgg._fontd.get(key) | ||
| 277 | - | ||
| 278 | - if font is None: | ||
| 279 | - fname = findfont(prop) | ||
| 280 | - font = RendererAgg._fontd.get(fname) | ||
| 281 | - if font is None: | ||
| 282 | - font = FT2Font( | ||
| 283 | - fname, | ||
| 284 | - hinting_factor=rcParams['text.hinting_factor']) | ||
| 285 | - RendererAgg._fontd[fname] = font | ||
| 286 | - RendererAgg._fontd[key] = font | ||
| 275 | + fname = findfont(prop) | ||
| 276 | + font = get_font( | ||
| 277 | + fname, | ||
| 278 | + hinting_factor=rcParams['text.hinting_factor']) | ||
| 287 | 279 | ||
| 288 | 280 | font.clear() | |
| 289 | 281 | size = prop.get_size_in_points() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,11 +35,11 @@ | |||
| 35 | 35 | from matplotlib.cbook import Bunch, is_string_like, \ | |
| 36 | 36 | get_realpath_and_stat, is_writable_file_like, maxdict | |
| 37 | 37 | from matplotlib.figure import Figure | |
| 38 | - from matplotlib.font_manager import findfont, is_opentype_cff_font | ||
| 38 | + from matplotlib.font_manager import findfont, is_opentype_cff_font, get_font | ||
| 39 | 39 | from matplotlib.afm import AFM | |
| 40 | 40 | import matplotlib.type1font as type1font | |
| 41 | 41 | import matplotlib.dviread as dviread | |
| 42 | - from matplotlib.ft2font import FT2Font, FIXED_WIDTH, ITALIC, LOAD_NO_SCALE, \ | ||
| 42 | + from matplotlib.ft2font import FIXED_WIDTH, ITALIC, LOAD_NO_SCALE, \ | ||
| 43 | 43 | LOAD_NO_HINTING, KERNING_UNFITTED | |
| 44 | 44 | from matplotlib.mathtext import MathTextParser | |
| 45 | 45 | from matplotlib.transforms import Affine2D, BboxBase | |
@@ -757,7 +757,7 @@ def createType1Descriptor(self, t1font, fontfile): | |||
| 757 | 757 | if 0: | |
| 758 | 758 | flags |= 1 << 18 | |
| 759 | 759 | ||
| 760 | - ft2font = FT2Font(fontfile) | ||
| 760 | + ft2font = get_font(fontfile) | ||
| 761 | 761 | ||
| 762 | 762 | descriptor = { | |
| 763 | 763 | 'Type': Name('FontDescriptor'), | |
@@ -817,7 +817,7 @@ def _get_xobject_symbol_name(self, filename, symbol_name): | |||
| 817 | 817 | def embedTTF(self, filename, characters): | |
| 818 | 818 | """Embed the TTF font from the named file into the document.""" | |
| 819 | 819 | ||
| 820 | - font = FT2Font(filename) | ||
| 820 | + font = get_font(filename) | ||
| 821 | 821 | fonttype = rcParams['pdf.fonttype'] | |
| 822 | 822 | ||
| 823 | 823 | def cvt(length, upe=font.units_per_EM, nearest=True): | |
@@ -1526,7 +1526,6 @@ def writeTrailer(self): | |||
| 1526 | 1526 | ||
| 1527 | 1527 | ||
| 1528 | 1528 | class RendererPdf(RendererBase): | |
| 1529 | - truetype_font_cache = maxdict(50) | ||
| 1530 | 1529 | afm_font_cache = maxdict(50) | |
| 1531 | 1530 | ||
| 1532 | 1531 | def __init__(self, file, image_dpi): | |
@@ -2127,15 +2126,8 @@ def _get_font_afm(self, prop): | |||
| 2127 | 2126 | return font | |
| 2128 | 2127 | ||
| 2129 | 2128 | def _get_font_ttf(self, prop): | |
| 2130 | - key = hash(prop) | ||
| 2131 | - font = self.truetype_font_cache.get(key) | ||
| 2132 | - if font is None: | ||
| 2133 | - filename = findfont(prop) | ||
| 2134 | - font = self.truetype_font_cache.get(filename) | ||
| 2135 | - if font is None: | ||
| 2136 | - font = FT2Font(filename) | ||
| 2137 | - self.truetype_font_cache[filename] = font | ||
| 2138 | - self.truetype_font_cache[key] = font | ||
| 2129 | + filename = findfont(prop) | ||
| 2130 | + font = get_font(filename) | ||
| 2139 | 2131 | font.clear() | |
| 2140 | 2132 | font.set_size(prop.get_size_in_points(), 72) | |
| 2141 | 2133 | return font | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,10 +36,9 @@ | |||
| 36 | 36 | system_fonts = [] | |
| 37 | 37 | if sys.platform.startswith('win'): | |
| 38 | 38 | from matplotlib import font_manager | |
| 39 | - from matplotlib.ft2font import FT2Font | ||
| 40 | 39 | for f in font_manager.win32InstalledFonts(): | |
| 41 | 40 | try: | |
| 42 | - system_fonts.append(FT2Font(str(f)).family_name) | ||
| 41 | + system_fonts.append(font_manager.get_font(str(f)).family_name) | ||
| 43 | 42 | except: | |
| 44 | 43 | pass # unknown error, skip this font | |
| 45 | 44 | else: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,8 +28,8 @@ def _fn_name(): return sys._getframe(1).f_code.co_name | |||
| 28 | 28 | is_writable_file_like, maxdict, file_requires_unicode | |
| 29 | 29 | from matplotlib.figure import Figure | |
| 30 | 30 | ||
| 31 | - from matplotlib.font_manager import findfont, is_opentype_cff_font | ||
| 32 | - from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING | ||
| 31 | + from matplotlib.font_manager import findfont, is_opentype_cff_font, get_font | ||
| 32 | + from matplotlib.ft2font import KERNING_DEFAULT, LOAD_NO_HINTING | ||
| 33 | 33 | from matplotlib.ttconv import convert_ttf_to_ps | |
| 34 | 34 | from matplotlib.mathtext import MathTextParser | |
| 35 | 35 | from matplotlib._mathtext_data import uni2type1 | |
@@ -199,7 +199,6 @@ class RendererPS(RendererBase): | |||
| 199 | 199 | context instance that controls the colors/styles. | |
| 200 | 200 | """ | |
| 201 | 201 | ||
| 202 | - fontd = maxdict(50) | ||
| 203 | 202 | afmfontd = maxdict(50) | |
| 204 | 203 | ||
| 205 | 204 | def __init__(self, width, height, pswriter, imagedpi=72): | |
@@ -393,15 +392,8 @@ def _get_font_afm(self, prop): | |||
| 393 | 392 | return font | |
| 394 | 393 | ||
| 395 | 394 | def _get_font_ttf(self, prop): | |
| 396 | - key = hash(prop) | ||
| 397 | - font = self.fontd.get(key) | ||
| 398 | - if font is None: | ||
| 399 | - fname = findfont(prop) | ||
| 400 | - font = self.fontd.get(fname) | ||
| 401 | - if font is None: | ||
| 402 | - font = FT2Font(fname) | ||
| 403 | - self.fontd[fname] = font | ||
| 404 | - self.fontd[key] = font | ||
| 395 | + fname = findfont(prop) | ||
| 396 | + font = get_font(fname) | ||
| 405 | 397 | font.clear() | |
| 406 | 398 | size = prop.get_size_in_points() | |
| 407 | 399 | font.set_size(size, 72.0) | |
@@ -1145,7 +1137,7 @@ def print_figure_impl(): | |||
| 1145 | 1137 | if not rcParams['ps.useafm']: | |
| 1146 | 1138 | for font_filename, chars in six.itervalues(ps_renderer.used_characters): | |
| 1147 | 1139 | if len(chars): | |
| 1148 | - font = FT2Font(font_filename) | ||
| 1140 | + font = get_font(font_filename) | ||
| 1149 | 1141 | cmap = font.get_charmap() | |
| 1150 | 1142 | glyph_ids = [] | |
| 1151 | 1143 | for c in chars: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,8 +19,8 @@ | |||
| 19 | 19 | from matplotlib.cbook import is_string_like, is_writable_file_like, maxdict | |
| 20 | 20 | from matplotlib.colors import rgb2hex | |
| 21 | 21 | from matplotlib.figure import Figure | |
| 22 | - from matplotlib.font_manager import findfont, FontProperties | ||
| 23 | - from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING | ||
| 22 | + from matplotlib.font_manager import findfont, FontProperties, get_font | ||
| 23 | + from matplotlib.ft2font import KERNING_DEFAULT, LOAD_NO_HINTING | ||
| 24 | 24 | from matplotlib.mathtext import MathTextParser | |
| 25 | 25 | from matplotlib.path import Path | |
| 26 | 26 | from matplotlib import _path | |
@@ -326,15 +326,8 @@ def _make_flip_transform(self, transform): | |||
| 326 | 326 | .translate(0.0, self.height)) | |
| 327 | 327 | ||
| 328 | 328 | def _get_font(self, prop): | |
| 329 | - key = hash(prop) | ||
| 330 | - font = self.fontd.get(key) | ||
| 331 | - if font is None: | ||
| 332 | - fname = findfont(prop) | ||
| 333 | - font = self.fontd.get(fname) | ||
| 334 | - if font is None: | ||
| 335 | - font = FT2Font(fname) | ||
| 336 | - self.fontd[fname] = font | ||
| 337 | - self.fontd[key] = font | ||
| 329 | + fname = findfont(prop) | ||
| 330 | + font = get_font(fname) | ||
| 338 | 331 | font.clear() | |
| 339 | 332 | size = prop.get_size_in_points() | |
| 340 | 333 | font.set_size(size, 72.0) | |
@@ -495,7 +488,7 @@ def _write_svgfonts(self): | |||
| 495 | 488 | writer = self.writer | |
| 496 | 489 | writer.start('defs') | |
| 497 | 490 | for font_fname, chars in six.iteritems(self._fonts): | |
| 498 | - font = FT2Font(font_fname) | ||
| 491 | + font = get_font(font_fname) | ||
| 499 | 492 | font.set_size(72, 72) | |
| 500 | 493 | sfnt = font.get_sfnt() | |
| 501 | 494 | writer.start('font', id=sfnt[(1, 0, 0, 4)]) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,6 +63,12 @@ | |||
| 63 | 63 | from matplotlib.fontconfig_pattern import \ | |
| 64 | 64 | parse_fontconfig_pattern, generate_fontconfig_pattern | |
| 65 | 65 | ||
| 66 | + try: | ||
| 67 | + from functools import lru_cache | ||
| 68 | + except ImportError: | ||
| 69 | + from functools32 import lru_cache | ||
| 70 | + | ||
| 71 | + | ||
| 66 | 72 | USE_FONTCONFIG = False | |
| 67 | 73 | verbose = matplotlib.verbose | |
| 68 | 74 | ||
@@ -733,7 +739,7 @@ def get_name(self): | |||
| 733 | 739 | Return the name of the font that best matches the font | |
| 734 | 740 | properties. | |
| 735 | 741 | """ | |
| 736 | - return ft2font.FT2Font(findfont(self)).family_name | ||
| 742 | + return get_font(findfont(self)).family_name | ||
| 737 | 743 | ||
| 738 | 744 | def get_style(self): | |
| 739 | 745 | """ | |
@@ -1316,7 +1322,6 @@ def findfont(self, prop, fontext='ttf', directory=None, | |||
| 1316 | 1322 | _lookup_cache[fontext].set(prop, result) | |
| 1317 | 1323 | return result | |
| 1318 | 1324 | ||
| 1319 | - | ||
| 1320 | 1325 | _is_opentype_cff_font_cache = {} | |
| 1321 | 1326 | def is_opentype_cff_font(filename): | |
| 1322 | 1327 | """ | |
@@ -1337,6 +1342,10 @@ def is_opentype_cff_font(filename): | |||
| 1337 | 1342 | fontManager = None | |
| 1338 | 1343 | _fmcache = None | |
| 1339 | 1344 | ||
| 1345 | + | ||
| 1346 | + get_font = lru_cache(64)(ft2font.FT2Font) | ||
| 1347 | + | ||
| 1348 | + | ||
| 1340 | 1349 | # The experimental fontconfig-based backend. | |
| 1341 | 1350 | if USE_FONTCONFIG and sys.platform != 'win32': | |
| 1342 | 1351 | import re | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,8 +50,8 @@ | |||
| 50 | 50 | from matplotlib.afm import AFM | |
| 51 | 51 | from matplotlib.cbook import Bunch, get_realpath_and_stat, \ | |
| 52 | 52 | is_string_like, maxdict | |
| 53 | - from matplotlib.ft2font import FT2Font, FT2Image, KERNING_DEFAULT, LOAD_FORCE_AUTOHINT, LOAD_NO_HINTING | ||
| 54 | - from matplotlib.font_manager import findfont, FontProperties | ||
| 53 | + from matplotlib.ft2font import FT2Image, KERNING_DEFAULT, LOAD_FORCE_AUTOHINT, LOAD_NO_HINTING | ||
| 54 | + from matplotlib.font_manager import findfont, FontProperties, get_font | ||
| 55 | 55 | from matplotlib._mathtext_data import latex_to_bakoma, \ | |
| 56 | 56 | latex_to_standard, tex2uni, latex_to_cmex, stix_virtual_fonts | |
| 57 | 57 | from matplotlib import get_data_path, rcParams | |
@@ -563,7 +563,7 @@ def __init__(self, default_font_prop, mathtext_backend): | |||
| 563 | 563 | self._fonts = {} | |
| 564 | 564 | ||
| 565 | 565 | filename = findfont(default_font_prop) | |
| 566 | - default_font = self.CachedFont(FT2Font(filename)) | ||
| 566 | + default_font = self.CachedFont(get_font(filename)) | ||
| 567 | 567 | self._fonts['default'] = default_font | |
| 568 | 568 | self._fonts['regular'] = default_font | |
| 569 | 569 | ||
@@ -576,10 +576,9 @@ def _get_font(self, font): | |||
| 576 | 576 | basename = self.fontmap[font] | |
| 577 | 577 | else: | |
| 578 | 578 | basename = font | |
| 579 | - | ||
| 580 | 579 | cached_font = self._fonts.get(basename) | |
| 581 | 580 | if cached_font is None and os.path.exists(basename): | |
| 582 | - font = FT2Font(basename) | ||
| 581 | + font = get_font(basename) | ||
| 583 | 582 | cached_font = self.CachedFont(font) | |
| 584 | 583 | self._fonts[basename] = cached_font | |
| 585 | 584 | self._fonts[font.postscript_name] = cached_font | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,12 +49,6 @@ def setup(): | |||
| 49 | 49 | rcParams['text.hinting'] = False | |
| 50 | 50 | rcParams['text.hinting_factor'] = 8 | |
| 51 | 51 | ||
| 52 | - # Clear the font caches. Otherwise, the hinting mode can travel | ||
| 53 | - # from one test to another. | ||
| 54 | - backend_agg.RendererAgg._fontd.clear() | ||
| 55 | - backend_pdf.RendererPdf.truetype_font_cache.clear() | ||
| 56 | - backend_svg.RendererSVG.fontd.clear() | ||
| 57 | - | ||
| 58 | 52 | ||
| 59 | 53 | def assert_str_equal(reference_str, test_str, | |
| 60 | 54 | format_str=('String {str1} and {str2} do not ' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,11 +13,11 @@ | |||
| 13 | 13 | from matplotlib.path import Path | |
| 14 | 14 | from matplotlib import rcParams | |
| 15 | 15 | import matplotlib.font_manager as font_manager | |
| 16 | - from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING | ||
| 16 | + from matplotlib.ft2font import KERNING_DEFAULT, LOAD_NO_HINTING | ||
| 17 | 17 | from matplotlib.ft2font import LOAD_TARGET_LIGHT | |
| 18 | 18 | from matplotlib.mathtext import MathTextParser | |
| 19 | 19 | import matplotlib.dviread as dviread | |
| 20 | - from matplotlib.font_manager import FontProperties | ||
| 20 | + from matplotlib.font_manager import FontProperties, get_font | ||
| 21 | 21 | from matplotlib.transforms import Affine2D | |
| 22 | 22 | from matplotlib.externals.six.moves.urllib.parse import quote as urllib_quote | |
| 23 | 23 | ||
@@ -54,7 +54,7 @@ def _get_font(self, prop): | |||
| 54 | 54 | find a ttf font. | |
| 55 | 55 | """ | |
| 56 | 56 | fname = font_manager.findfont(prop) | |
| 57 | - font = FT2Font(fname) | ||
| 57 | + font = get_font(fname) | ||
| 58 | 58 | font.set_size(self.FONT_SCALE, self.DPI) | |
| 59 | 59 | ||
| 60 | 60 | return font | |
@@ -336,7 +336,7 @@ def get_glyphs_tex(self, prop, s, glyph_map=None, | |||
| 336 | 336 | font_bunch = self.tex_font_map[dvifont.texname] | |
| 337 | 337 | ||
| 338 | 338 | if font_and_encoding is None: | |
| 339 | - font = FT2Font(font_bunch.filename) | ||
| 339 | + font = get_font(font_bunch.filename) | ||
| 340 | 340 | ||
| 341 | 341 | for charmap_name, charmap_code in [("ADOBE_CUSTOM", | |
| 342 | 342 | 1094992451), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments