Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0129d3a

Browse files
committed
Remove now unused StandardPsFonts, latex_to_{standard,cmex}, use_cmex.
1 parent 713919d commit 0129d3a

File tree

2 files changed

+1
-330
lines changed

2 files changed

+1
-330
lines changed

lib/matplotlib/_mathtext.py

Lines changed: 1 addition & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
import matplotlib as mpl
2121
from . import cbook
2222
from ._mathtext_data import (
23-
latex_to_bakoma, latex_to_standard, stix_glyph_fixes, stix_virtual_fonts,
24-
tex2uni)
25-
from .afm import AFM
23+
latex_to_bakoma, stix_glyph_fixes, stix_virtual_fonts, tex2uni)
2624
from .font_manager import FontProperties, findfont, get_font
2725
from .ft2font import KERNING_DEFAULT
2826

@@ -397,7 +395,6 @@ class UnicodeFonts(TruetypeFonts):
397395
This class will "fallback" on the Bakoma fonts when a required
398396
symbol can not be found in the font.
399397
"""
400-
use_cmex = True # Unused; delete once mathtext becomes private.
401398

402399
def __init__(self, *args, **kwargs):
403400
# This must come first so the backend's owner is set correctly
@@ -511,7 +508,6 @@ def get_sized_alternatives_for_symbol(self, fontname, sym):
511508

512509

513510
class DejaVuFonts(UnicodeFonts):
514-
use_cmex = False # Unused; delete once mathtext becomes private.
515511

516512
def __init__(self, *args, **kwargs):
517513
# This must come first so the backend's owner is set correctly
@@ -614,7 +610,6 @@ class StixFonts(UnicodeFonts):
614610
4: 'STIXSizeFourSym',
615611
5: 'STIXSizeFiveSym',
616612
}
617-
use_cmex = False # Unused; delete once mathtext becomes private.
618613
cm_fallback = False
619614
_sans = False
620615

@@ -704,163 +699,6 @@ class StixSansFonts(StixFonts):
704699
_sans = True
705700

706701

707-
class StandardPsFonts(Fonts):
708-
"""
709-
Use the standard postscript fonts for rendering to backend_ps
710-
711-
Unlike the other font classes, BakomaFont and UnicodeFont, this
712-
one requires the Ps backend.
713-
"""
714-
basepath = str(cbook._get_data_path('fonts/afm'))
715-
716-
fontmap = {
717-
'cal': 'pzcmi8a', # Zapf Chancery
718-
'rm': 'pncr8a', # New Century Schoolbook
719-
'tt': 'pcrr8a', # Courier
720-
'it': 'pncri8a', # New Century Schoolbook Italic
721-
'sf': 'phvr8a', # Helvetica
722-
'bf': 'pncb8a', # New Century Schoolbook Bold
723-
None: 'psyr', # Symbol
724-
}
725-
726-
def __init__(self, default_font_prop, mathtext_backend=None):
727-
if mathtext_backend is None:
728-
# Circular import, can be dropped after public access to
729-
# StandardPsFonts is removed and mathtext_backend made a required
730-
# parameter.
731-
from . import mathtext
732-
mathtext_backend = mathtext.MathtextBackendPath()
733-
super().__init__(default_font_prop, mathtext_backend)
734-
self.glyphd = {}
735-
self.fonts = {}
736-
737-
filename = findfont(default_font_prop, fontext='afm',
738-
directory=self.basepath)
739-
if filename is None:
740-
filename = findfont('Helvetica', fontext='afm',
741-
directory=self.basepath)
742-
with open(filename, 'rb') as fd:
743-
default_font = AFM(fd)
744-
default_font.fname = filename
745-
746-
self.fonts['default'] = default_font
747-
self.fonts['regular'] = default_font
748-
749-
def _get_font(self, font):
750-
if font in self.fontmap:
751-
basename = self.fontmap[font]
752-
else:
753-
basename = font
754-
755-
cached_font = self.fonts.get(basename)
756-
if cached_font is None:
757-
fname = os.path.join(self.basepath, basename + ".afm")
758-
with open(fname, 'rb') as fd:
759-
cached_font = AFM(fd)
760-
cached_font.fname = fname
761-
self.fonts[basename] = cached_font
762-
self.fonts[cached_font.get_fontname()] = cached_font
763-
return cached_font
764-
765-
def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True):
766-
"""Load the cmfont, metrics and glyph with caching."""
767-
key = fontname, sym, fontsize, dpi
768-
tup = self.glyphd.get(key)
769-
770-
if tup is not None:
771-
return tup
772-
773-
# Only characters in the "Letter" class should really be italicized.
774-
# This class includes greek letters, so we're ok
775-
if (fontname == 'it' and
776-
(len(sym) > 1
777-
or not unicodedata.category(sym).startswith("L"))):
778-
fontname = 'rm'
779-
780-
found_symbol = False
781-
782-
if sym in latex_to_standard:
783-
fontname, num = latex_to_standard[sym]
784-
glyph = chr(num)
785-
found_symbol = True
786-
elif len(sym) == 1:
787-
glyph = sym
788-
num = ord(glyph)
789-
found_symbol = True
790-
else:
791-
_log.warning(
792-
"No TeX to built-in Postscript mapping for {!r}".format(sym))
793-
794-
slanted = (fontname == 'it')
795-
font = self._get_font(fontname)
796-
797-
if found_symbol:
798-
try:
799-
glyph_name = font.get_name_char(glyph)
800-
except KeyError:
801-
_log.warning(
802-
"No glyph in standard Postscript font {!r} for {!r}"
803-
.format(font.get_fontname(), sym))
804-
found_symbol = False
805-
806-
if not found_symbol:
807-
glyph = '?'
808-
num = ord(glyph)
809-
glyph_name = font.get_name_char(glyph)
810-
811-
offset = 0
812-
813-
scale = 0.001 * fontsize
814-
815-
xmin, ymin, xmax, ymax = [val * scale
816-
for val in font.get_bbox_char(glyph)]
817-
metrics = types.SimpleNamespace(
818-
advance = font.get_width_char(glyph) * scale,
819-
width = font.get_width_char(glyph) * scale,
820-
height = font.get_height_char(glyph) * scale,
821-
xmin = xmin,
822-
xmax = xmax,
823-
ymin = ymin+offset,
824-
ymax = ymax+offset,
825-
# iceberg is the equivalent of TeX's "height"
826-
iceberg = ymax + offset,
827-
slanted = slanted
828-
)
829-
830-
self.glyphd[key] = types.SimpleNamespace(
831-
font = font,
832-
fontsize = fontsize,
833-
postscript_name = font.get_fontname(),
834-
metrics = metrics,
835-
glyph_name = glyph_name,
836-
symbol_name = glyph_name, # Backcompat alias.
837-
num = num,
838-
glyph = glyph,
839-
offset = offset
840-
)
841-
842-
return self.glyphd[key]
843-
844-
def get_kern(self, font1, fontclass1, sym1, fontsize1,
845-
font2, fontclass2, sym2, fontsize2, dpi):
846-
if font1 == font2 and fontsize1 == fontsize2:
847-
info1 = self._get_info(font1, fontclass1, sym1, fontsize1, dpi)
848-
info2 = self._get_info(font2, fontclass2, sym2, fontsize2, dpi)
849-
font = info1.font
850-
return (font.get_kern_dist(info1.glyph, info2.glyph)
851-
* 0.001 * fontsize1)
852-
return super().get_kern(font1, fontclass1, sym1, fontsize1,
853-
font2, fontclass2, sym2, fontsize2, dpi)
854-
855-
def get_xheight(self, font, fontsize, dpi):
856-
font = self._get_font(font)
857-
return font.get_xheight() * 0.001 * fontsize
858-
859-
def get_underline_thickness(self, font, fontsize, dpi):
860-
font = self._get_font(font)
861-
return font.get_underline_thickness() * 0.001 * fontsize
862-
863-
864702
##############################################################################
865703
# TeX-LIKE BOX MODEL
866704

lib/matplotlib/_mathtext_data.py

Lines changed: 0 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -236,173 +236,6 @@
236236
'\\_' : ('cmtt10', 0x5f)
237237
}
238238

239-
latex_to_cmex = { # Unused; delete once mathtext becomes private.
240-
r'\__sqrt__' : 112,
241-
r'\bigcap' : 92,
242-
r'\bigcup' : 91,
243-
r'\bigodot' : 75,
244-
r'\bigoplus' : 77,
245-
r'\bigotimes' : 79,
246-
r'\biguplus' : 93,
247-
r'\bigvee' : 95,
248-
r'\bigwedge' : 94,
249-
r'\coprod' : 97,
250-
r'\int' : 90,
251-
r'\leftangle' : 173,
252-
r'\leftbrace' : 169,
253-
r'\oint' : 73,
254-
r'\prod' : 89,
255-
r'\rightangle' : 174,
256-
r'\rightbrace' : 170,
257-
r'\sum' : 88,
258-
r'\widehat' : 98,
259-
r'\widetilde' : 101,
260-
}
261-
262-
latex_to_standard = {
263-
r'\cong' : ('psyr', 64),
264-
r'\Delta' : ('psyr', 68),
265-
r'\Phi' : ('psyr', 70),
266-
r'\Gamma' : ('psyr', 89),
267-
r'\alpha' : ('psyr', 97),
268-
r'\beta' : ('psyr', 98),
269-
r'\chi' : ('psyr', 99),
270-
r'\delta' : ('psyr', 100),
271-
r'\varepsilon' : ('psyr', 101),
272-
r'\phi' : ('psyr', 102),
273-
r'\gamma' : ('psyr', 103),
274-
r'\eta' : ('psyr', 104),
275-
r'\iota' : ('psyr', 105),
276-
r'\varphi' : ('psyr', 106),
277-
r'\kappa' : ('psyr', 108),
278-
r'\nu' : ('psyr', 110),
279-
r'\pi' : ('psyr', 112),
280-
r'\theta' : ('psyr', 113),
281-
r'\rho' : ('psyr', 114),
282-
r'\sigma' : ('psyr', 115),
283-
r'\tau' : ('psyr', 116),
284-
r'\upsilon' : ('psyr', 117),
285-
r'\varpi' : ('psyr', 118),
286-
r'\omega' : ('psyr', 119),
287-
r'\xi' : ('psyr', 120),
288-
r'\psi' : ('psyr', 121),
289-
r'\zeta' : ('psyr', 122),
290-
r'\sim' : ('psyr', 126),
291-
r'\leq' : ('psyr', 163),
292-
r'\infty' : ('psyr', 165),
293-
r'\clubsuit' : ('psyr', 167),
294-
r'\diamondsuit' : ('psyr', 168),
295-
r'\heartsuit' : ('psyr', 169),
296-
r'\spadesuit' : ('psyr', 170),
297-
r'\leftrightarrow' : ('psyr', 171),
298-
r'\leftarrow' : ('psyr', 172),
299-
r'\uparrow' : ('psyr', 173),
300-
r'\rightarrow' : ('psyr', 174),
301-
r'\downarrow' : ('psyr', 175),
302-
r'\pm' : ('psyr', 176),
303-
r'\geq' : ('psyr', 179),
304-
r'\times' : ('psyr', 180),
305-
r'\propto' : ('psyr', 181),
306-
r'\partial' : ('psyr', 182),
307-
r'\bullet' : ('psyr', 183),
308-
r'\div' : ('psyr', 184),
309-
r'\neq' : ('psyr', 185),
310-
r'\equiv' : ('psyr', 186),
311-
r'\approx' : ('psyr', 187),
312-
r'\ldots' : ('psyr', 188),
313-
r'\aleph' : ('psyr', 192),
314-
r'\Im' : ('psyr', 193),
315-
r'\Re' : ('psyr', 194),
316-
r'\wp' : ('psyr', 195),
317-
r'\otimes' : ('psyr', 196),
318-
r'\oplus' : ('psyr', 197),
319-
r'\oslash' : ('psyr', 198),
320-
r'\cap' : ('psyr', 199),
321-
r'\cup' : ('psyr', 200),
322-
r'\supset' : ('psyr', 201),
323-
r'\supseteq' : ('psyr', 202),
324-
r'\subset' : ('psyr', 204),
325-
r'\subseteq' : ('psyr', 205),
326-
r'\in' : ('psyr', 206),
327-
r'\notin' : ('psyr', 207),
328-
r'\angle' : ('psyr', 208),
329-
r'\nabla' : ('psyr', 209),
330-
r'\textregistered' : ('psyr', 210),
331-
r'\copyright' : ('psyr', 211),
332-
r'\texttrademark' : ('psyr', 212),
333-
r'\Pi' : ('psyr', 213),
334-
r'\prod' : ('psyr', 213),
335-
r'\surd' : ('psyr', 214),
336-
r'\__sqrt__' : ('psyr', 214),
337-
r'\cdot' : ('psyr', 215),
338-
r'\urcorner' : ('psyr', 216),
339-
r'\vee' : ('psyr', 217),
340-
r'\wedge' : ('psyr', 218),
341-
r'\Leftrightarrow' : ('psyr', 219),
342-
r'\Leftarrow' : ('psyr', 220),
343-
r'\Uparrow' : ('psyr', 221),
344-
r'\Rightarrow' : ('psyr', 222),
345-
r'\Downarrow' : ('psyr', 223),
346-
r'\Diamond' : ('psyr', 224),
347-
r'\Sigma' : ('psyr', 229),
348-
r'\sum' : ('psyr', 229),
349-
r'\forall' : ('psyr', 34),
350-
r'\exists' : ('psyr', 36),
351-
r'\lceil' : ('psyr', 233),
352-
r'\lbrace' : ('psyr', 123),
353-
r'\Psi' : ('psyr', 89),
354-
r'\bot' : ('psyr', 0o136),
355-
r'\Omega' : ('psyr', 0o127),
356-
r'\leftbracket' : ('psyr', 0o133),
357-
r'\rightbracket' : ('psyr', 0o135),
358-
r'\leftbrace' : ('psyr', 123),
359-
r'\leftparen' : ('psyr', 0o50),
360-
r'\prime' : ('psyr', 0o242),
361-
r'\sharp' : ('psyr', 0o43),
362-
r'\slash' : ('psyr', 0o57),
363-
r'\Lambda' : ('psyr', 0o114),
364-
r'\neg' : ('psyr', 0o330),
365-
r'\Upsilon' : ('psyr', 0o241),
366-
r'\rightbrace' : ('psyr', 0o175),
367-
r'\rfloor' : ('psyr', 0o373),
368-
r'\lambda' : ('psyr', 0o154),
369-
r'\to' : ('psyr', 0o256),
370-
r'\Xi' : ('psyr', 0o130),
371-
r'\emptyset' : ('psyr', 0o306),
372-
r'\lfloor' : ('psyr', 0o353),
373-
r'\rightparen' : ('psyr', 0o51),
374-
r'\rceil' : ('psyr', 0o371),
375-
r'\ni' : ('psyr', 0o47),
376-
r'\epsilon' : ('psyr', 0o145),
377-
r'\Theta' : ('psyr', 0o121),
378-
r'\langle' : ('psyr', 0o341),
379-
r'\leftangle' : ('psyr', 0o341),
380-
r'\rangle' : ('psyr', 0o361),
381-
r'\rightangle' : ('psyr', 0o361),
382-
r'\rbrace' : ('psyr', 0o175),
383-
r'\circ' : ('psyr', 0o260),
384-
r'\diamond' : ('psyr', 0o340),
385-
r'\mu' : ('psyr', 0o155),
386-
r'\mid' : ('psyr', 0o352),
387-
r'\imath' : ('pncri8a', 105),
388-
r'\%' : ('pncr8a', 37),
389-
r'\$' : ('pncr8a', 36),
390-
r'\{' : ('pncr8a', 123),
391-
r'\}' : ('pncr8a', 125),
392-
r'\backslash' : ('pncr8a', 92),
393-
r'\ast' : ('pncr8a', 42),
394-
r'\#' : ('pncr8a', 35),
395-
396-
r'\circumflexaccent' : ('pncri8a', 124), # for \hat
397-
r'\combiningbreve' : ('pncri8a', 81), # for \breve
398-
r'\combininggraveaccent' : ('pncri8a', 114), # for \grave
399-
r'\combiningacuteaccent' : ('pncri8a', 63), # for \accute
400-
r'\combiningdiaeresis' : ('pncri8a', 91), # for \ddot
401-
r'\combiningtilde' : ('pncri8a', 75), # for \tilde
402-
r'\combiningrightarrowabove' : ('pncri8a', 110), # for \vec
403-
r'\combiningdotabove' : ('pncri8a', 26), # for \dot
404-
}
405-
406239
# Automatically generated.
407240

408241
type12uni = {

0 commit comments

Comments
 (0)