Return a match score between the list of font families in *families* and the font family name *family2*. An exact match at the head of the list returns 0.0. A match further down the list will return between 0 and 1. No match will return 1.0.
(self, families, family2)
| 1342 | # Each of the scoring functions below should return a value between |
| 1343 | # 0.0 (perfect match) and 1.0 (terrible match) |
| 1344 | def score_family(self, families, family2): |
| 1345 | """ |
| 1346 | Return a match score between the list of font families in |
| 1347 | *families* and the font family name *family2*. |
| 1348 | |
| 1349 | An exact match at the head of the list returns 0.0. |
| 1350 | |
| 1351 | A match further down the list will return between 0 and 1. |
| 1352 | |
| 1353 | No match will return 1.0. |
| 1354 | """ |
| 1355 | if not isinstance(families, (list, tuple)): |
| 1356 | families = [families] |
| 1357 | elif len(families) == 0: |
| 1358 | return 1.0 |
| 1359 | family2 = family2.lower() |
| 1360 | step = 1 / len(families) |
| 1361 | for i, family1 in enumerate(families): |
| 1362 | family1 = family1.lower() |
| 1363 | if family1 in font_family_aliases: |
| 1364 | options = [*map(str.lower, self._expand_aliases(family1))] |
| 1365 | if family2 in options: |
| 1366 | idx = options.index(family2) |
| 1367 | return (i + (idx / len(options))) * step |
| 1368 | elif family1 == family2: |
| 1369 | # The score should be weighted by where in the |
| 1370 | # list the font was found. |
| 1371 | return i * step |
| 1372 | return 1.0 |
| 1373 | |
| 1374 | def score_style(self, style1, style2): |
| 1375 | """ |
no test coverage detected