|
33 | 33 | from functools import lru_cache
|
34 | 34 | import json
|
35 | 35 | import logging
|
| 36 | +from numbers import Number |
36 | 37 | import os
|
37 | 38 | from pathlib import Path
|
38 | 39 | import subprocess
|
@@ -1066,8 +1067,8 @@ def score_style(self, style1, style2):
|
1066 | 1067 | """
|
1067 | 1068 | if style1 == style2:
|
1068 | 1069 | return 0.0
|
1069 |
| - elif style1 in ('italic', 'oblique') and \ |
1070 |
| - style2 in ('italic', 'oblique'): |
| 1070 | + elif (style1 in ('italic', 'oblique') |
| 1071 | + and style2 in ('italic', 'oblique')): |
1071 | 1072 | return 0.1
|
1072 | 1073 | return 1.0
|
1073 | 1074 |
|
@@ -1111,21 +1112,12 @@ def score_weight(self, weight1, weight2):
|
1111 | 1112 | the CSS numeric values of *weight1* and *weight2*, normalized between
|
1112 | 1113 | 0.05 and 1.0.
|
1113 | 1114 | """
|
1114 |
| - |
1115 | 1115 | # exact match of the weight names, e.g. weight1 == weight2 == "regular"
|
1116 |
| - if (isinstance(weight1, str) and |
1117 |
| - isinstance(weight2, str) and |
1118 |
| - weight1 == weight2): |
| 1116 | + if cbook._str_equal(weight1, weight2): |
1119 | 1117 | return 0.0
|
1120 |
| - try: |
1121 |
| - weightval1 = int(weight1) |
1122 |
| - except ValueError: |
1123 |
| - weightval1 = weight_dict.get(weight1, 500) |
1124 |
| - try: |
1125 |
| - weightval2 = int(weight2) |
1126 |
| - except ValueError: |
1127 |
| - weightval2 = weight_dict.get(weight2, 500) |
1128 |
| - return 0.95*(abs(weightval1 - weightval2) / 1000.0) + 0.05 |
| 1118 | + w1 = weight1 if isinstance(weight1, Number) else weight_dict[weight1] |
| 1119 | + w2 = weight2 if isinstance(weight2, Number) else weight_dict[weight2] |
| 1120 | + return 0.95 * (abs(w1 - w2) / 1000) + 0.05 |
1129 | 1121 |
|
1130 | 1122 | def score_size(self, size1, size2):
|
1131 | 1123 | """
|
|
0 commit comments