match_font - arnthor89/pygame GitHub Wiki
match_font
Description
Similar to the SysFont function match_font searches the system fonts with parameter name as a comma-separated list of font names. It returns a path to the TTF file of the first item it finds in the system resources. The function uses a small set of common font aliases, in the case a specific font is not available an alternative may be used.
Complexity
The reason for the high complexity of the function is that the system has to account for different system resources, create aliases and handle if a user does not have a specific font in his resources. It also handles both italic and bold style fonts for different styles.
Refactoring strategy
Since this function is very closely related to the SysFont function we could use the refactoring we will do there in order to simplify this function by calling get_font_name(name, bold=False, italic=False). This will give us a path to the .TTF file.
Remove the code from 394-410 and add fontname = get_font_name(name, bold, italic)