MCPcopy Create free account
hub / github.com/PageBot/PageBot / match

Method match

Lib/pagebot/fonttoolbox/objects/font.py:802–848  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 9

__init__Method · 0.80
runMethod · 0.80
detabMethod · 0.80
detectTabbedMethod · 0.80
unique_refMethod · 0.80
titlecaseFunction · 0.80
slick.min.jsFile · 0.80
slick.jsFile · 0.80
_findFontMethod · 0.80

Calls 6

nameMatchMethod · 0.95
weightMatchMethod · 0.95
widthMatchMethod · 0.95
isItalicMethod · 0.95
path2FontNameFunction · 0.90
appendMethod · 0.45

Tested by

no test coverage detected