def get_font(self, weight='medium', slant='upright', width='normal'):
        """Return the font matching or closest to the given style

        If a font with the given weight, slant and width is available, return
        it. Otherwise, return the font that is closest in style.

        Args:
            weight (FontWeight): weight of the font
            slant (FontSlant): slant of the font
            width (FontWidth): width of the font

        Returns:
            Font: the requested font

        """
        def find_closest_style(style, styles, alternatives):
            try:
                return style, styles[style]
            except KeyError:
                for option in alternatives[style]:
                    try:
                        return option, styles[option]
                    except KeyError:
                        continue

        def find_closest_weight(weight, weights):
            index = FontWeight.values.index(weight)
            min_distance = len(FontWeight.values)
            closest = None
            for i, option in enumerate(FontWeight.values):
                if option in weights and abs(index - i) < min_distance:
                    min_distance = abs(index - i)
                    closest = option
            return closest, weights[closest]

        available_width, slants = find_closest_style(width, self,
                                                     FontWidth.alternatives)
        available_slant, weights = find_closest_style(slant, slants,
                                                      FontSlant.alternatives)
        available_weight, font = find_closest_weight(weight, weights)

        if (available_width != width or available_slant != slant or
            available_weight != weight):
            warn('{} does not include a {} {} {} font. Falling back to {} {} '
                 '{}'.format(self.name, width, weight, slant, available_width,
                             available_weight, available_slant))
        return font
def get_font ( self , weight = 'medium' , slant = 'upright' , width = 'normal' ) : def find_closest_style ( style , styles , alternatives ) : try : return style , styles [ style ] except KeyError : for option in alternatives [ style ] : try : return option , styles [ option ] except KeyError : continue def find_closest_weight ( weight , weights ) : index = FontWeight . values . index ( weight ) min_distance = len ( FontWeight . values ) closest = None for i , option in enumerate ( FontWeight . values ) : if option in weights and abs ( index - i ) < min_distance : min_distance = abs ( index - i ) closest = option return closest , weights [ closest ] available_width , slants = find_closest_style ( width , self , FontWidth . alternatives ) available_slant , weights = find_closest_style ( slant , slants , FontSlant . alternatives ) available_weight , font = find_closest_weight ( weight , weights ) if ( available_width != width or available_slant != slant or available_weight != weight ) : warn ( '{} does not include a {} {} {} font. Falling back to {} {} ' '{}' . format ( self . name , width , weight , slant , available_width , available_weight , available_slant ) ) return font
Return the font matching or closest to the given style

        If a font with the given weight, slant and width is available, return
        it. Otherwise, return the font that is closest in style.

        Args:
            weight (FontWeight): weight of the font
            slant (FontSlant): slant of the font
            width (FontWidth): width of the font

        Returns:
            Font: the requested font