|
26 | 26 | from functools import lru_cache |
27 | 27 | import json |
28 | 28 | import logging |
| 29 | +from numbers import Number |
29 | 30 | import os |
30 | 31 | from pathlib import Path |
31 | 32 | import subprocess |
@@ -1049,8 +1050,8 @@ def score_style(self, style1, style2): |
1049 | 1050 | """ |
1050 | 1051 | if style1 == style2: |
1051 | 1052 | return 0.0 |
1052 | | - elif style1 in ('italic', 'oblique') and \ |
1053 | | - style2 in ('italic', 'oblique'): |
| 1053 | + elif (style1 in ('italic', 'oblique') |
| 1054 | + and style2 in ('italic', 'oblique')): |
1054 | 1055 | return 0.1 |
1055 | 1056 | return 1.0 |
1056 | 1057 |
|
@@ -1094,21 +1095,12 @@ def score_weight(self, weight1, weight2): |
1094 | 1095 | the CSS numeric values of *weight1* and *weight2*, normalized between |
1095 | 1096 | 0.05 and 1.0. |
1096 | 1097 | """ |
1097 | | - |
1098 | 1098 | # exact match of the weight names, e.g. weight1 == weight2 == "regular" |
1099 | | - if (isinstance(weight1, str) and |
1100 | | - isinstance(weight2, str) and |
1101 | | - weight1 == weight2): |
| 1099 | + if cbook._str_equal(weight1, weight2): |
1102 | 1100 | return 0.0 |
1103 | | - try: |
1104 | | - weightval1 = int(weight1) |
1105 | | - except ValueError: |
1106 | | - weightval1 = weight_dict.get(weight1, 500) |
1107 | | - try: |
1108 | | - weightval2 = int(weight2) |
1109 | | - except ValueError: |
1110 | | - weightval2 = weight_dict.get(weight2, 500) |
1111 | | - return 0.95*(abs(weightval1 - weightval2) / 1000.0) + 0.05 |
| 1101 | + w1 = weight1 if isinstance(weight1, Number) else weight_dict[weight1] |
| 1102 | + w2 = weight2 if isinstance(weight2, Number) else weight_dict[weight2] |
| 1103 | + return 0.95 * (abs(w1 - w2) / 1000) + 0.05 |
1112 | 1104 |
|
1113 | 1105 | def score_size(self, size1, size2): |
1114 | 1106 | """ |
|
0 commit comments