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

Function get_weight

lib/matplotlib/font_manager.py:494–517  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

492 styles = [*filter(None, styles)] or [font.style_name]
493
494 def get_weight(): # From fontconfig's FcFreeTypeQueryFaceInternal.
495 # OS/2 table weight.
496 os2 = font.get_sfnt_table("OS/2")
497 if os2 and os2["version"] != 0xffff:
498 return os2["usWeightClass"]
499 # PostScript font info weight.
500 try:
501 ps_font_info_weight = (
502 font.get_ps_font_info()["weight"].replace(" ", "") or "")
503 except ValueError:
504 pass
505 else:
506 for regex, weight in _weight_regexes:
507 if re.fullmatch(regex, ps_font_info_weight, re.I):
508 return weight
509 # Style name weight.
510 for style in styles:
511 style = style.replace(" ", "")
512 for regex, weight in _weight_regexes:
513 if re.search(regex, style, re.I):
514 return weight
515 if ft2font.StyleFlags.BOLD in font.style_flags:
516 return 700 # "bold"
517 return 500 # "medium", not "regular"!
518
519 weight = int(get_weight())
520

Callers 1

ttfFontPropertyFunction · 0.85

Calls 1

searchMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…