()
| 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 |
no test coverage detected
searching dependent graphs…