Answers a value between 0 and 1 to the amount that self matches the defined parameters. Only defined values count in the matching. >>> from pagebot.fonttoolbox.fontpaths import getTestFontsPath >>> path = getTestFontsPath() + '/google/roboto/Roboto-Black.ttf' >>> fon
(self, name=None, weight=None, width=None, italic=None)
| 800 | return 0 |
| 801 | |
| 802 | def match(self, name=None, weight=None, width=None, italic=None): |
| 803 | """Answers a value between 0 and 1 to the amount that self matches the |
| 804 | defined parameters. Only defined values count in the matching. |
| 805 | |
| 806 | >>> from pagebot.fonttoolbox.fontpaths import getTestFontsPath |
| 807 | >>> path = getTestFontsPath() + '/google/roboto/Roboto-Black.ttf' |
| 808 | >>> font = getFont(path) |
| 809 | >>> font.info.widthClass, font.info.weightClass |
| 810 | (5, 900) |
| 811 | >>> font.match(name='Roboto') |
| 812 | 1.0 |
| 813 | >>> font.match(name='Robo', weight='Black') |
| 814 | 1.0 |
| 815 | >>> # Only match on the name. |
| 816 | >>> font.match(name='Robo', weight='Light') |
| 817 | 0.5 |
| 818 | >>> font.match(name='Robo', width=5) |
| 819 | 1.0 |
| 820 | """ |
| 821 | |
| 822 | """ |
| 823 | TODO: Fix these tests |
| 824 | |
| 825 | >>> font.match(name='Robo', weight=900, width=5) |
| 826 | 1.0 |
| 827 | >>> font.match(name='Robo', weight=900, width=5, italic=True) |
| 828 | 0.75 |
| 829 | >>> font.match(name='Robo', weight='Black', width=5, italic=False) |
| 830 | 1.0 |
| 831 | >>> font.match(name='Robo', weight='Blackish', width=5, italic=False) |
| 832 | 0.75 |
| 833 | """ |
| 834 | matches = [] |
| 835 | fontName = path2FontName(self.path) |
| 836 | if name is not None: |
| 837 | matches.append(self.nameMatch(name)) |
| 838 | # Currently the matches only answer 0 or 1. In future implementations this value may vary |
| 839 | # as float between 0 and 1. |
| 840 | if weight is not None: |
| 841 | matches.append(self.weightMatch(weight)) |
| 842 | if width is not None: |
| 843 | matches.append(self.widthMatch(width)) |
| 844 | if italic is not None: |
| 845 | matches.append(italic == self.isItalic()) |
| 846 | if not matches: |
| 847 | return 0 # Avoif division by zero |
| 848 | return sum(matches)/len(matches) # Normalize to value between 0..1 |
| 849 | |
| 850 | def keys(self): |
| 851 | """Answers the glyph names of the font. |
no test coverage detected