def guessFamilies(styleNames): u"""Find the family relation of all fonts in the list. Note that this cannot be a 100% safe guess. Answer a dictionary with Family instances. Key is family name.""" families = {} # Keys is guessed family name. for styleName in styleNames: if styleName.startswith( '.' ): # Filter the system fonts that has a name with initial "." continue path = getFontPathOfFont(styleName) # Could have an extension like .ttf or .otf, by OSX system font don't have an extension. # o we just try to open the plain file and see how that goes. # Try to open the font in font tools, so we have access to a lot of information for our proof. # Create Style instance, as storage within our page composition passes. font = Font(path, styleName) if font.info is None: continue # Could not open the font file. # Skip if there is not a clear family name and style name derived from FontInfo if font.info.familyName and font.info.styleName: # Make a family collection of style names, if not already there. if not font.info.familyName in families: families[font.info.familyName] = Family(font.info.familyName) # Store the style name and path in the family collection. families[font.info.familyName].addFont(font) return families
def getSystemFontPaths(): u"""Answer the cleaned list of installed font names.""" fontPaths = [] for fontName in installedFonts(): if not fontName.startswith('.'): fontPaths.append(getFontPathOfFont(fontName)) return fontPaths
def getFamilyFontPaths(familyName): # Collect the DrawBot names of all available fonts for the named family, that are installed in the system. fontPaths = {} # Dictionary, where key is the DrawBot font name, value is the OS path of the font file. for fontName in installedFonts(): # Answers complete list of all installed fonts. if familyName in fontName: # If this is a with with the familyName that we are looking for... fontPaths[fontName] = getFontPathOfFont(fontName) # Store the name and find the font path name. return fontPaths # Answer the dictionary. This is empty, if no Bitcount fonts are installed now.
# Show all installed font names that have "Caslon" inside for fontName in installedFonts(): if 'Caslon' in fontName: print fontName # Get function that goes from font name to font path from pagebot.fonttoolbox.objects.font import getFontPathOfFont, Font # Get the path path = getFontPathOfFont('ACaslonPro-BoldItalic') # Make a PageBot font f = Font(path) print f.info.familyName # Get a PageBot glyph object g = f['A'] print g.name, g.width # Print the kerning pairs that have "A" on the left and their values. for pair, value in f.kerning.items(): if pair[0] == g.name: print pair, value