Ejemplo n.º 1
0
def create_facets_font ( value ):
    """ Create a FacetFont object from a string description.
    """
    if isinstance( value, wx.Font ):
        value = font_to_str( value )

    # Replace any list of fonts by a single matching font:
    value = font_select( value )

    point_size = None
    family     = wx.DEFAULT
    style      = wx.NORMAL
    weight     = wx.NORMAL
    underline  = 0
    facename   = []
    for word in value.split():
        lword = word.lower()
        if font_families.has_key( lword ):
            family = font_families[ lword ]
        elif font_styles.has_key( lword ):
            style = font_styles[ lword ]
        elif font_weights.has_key( lword ):
            weight = font_weights[ lword ]
        elif lword == 'underline':
            underline = 1
        elif lword not in font_noise:
            if point_size is None:
                try:
                    point_size = int( lword )
                    continue
                except:
                    pass

            facename.append( word )

    return FacetsFont( point_size or 10, family, style, weight, underline,
                       ' '.join( facename ) )
Ejemplo n.º 2
0
def create_facets_font ( value ):
    """ Creates a FacetFont object from a string description.
    """
    global font_cache

    if isinstance( value, QFont ):
        return FacetsFont( value )

    # Replace any list of fonts by a single matching font:
    value = font_select( value )

    # Check to see if the font is already in the cache, and return it if it is:
    font = font_cache.get( value )
    if font is not None:
        return font

    point_size = None
    family     = ''
    style      = QFont.StyleNormal
    weight     = QFont.Normal
    underline  = False
    facename   = []

    for word in value.split():
        lword = word.lower()
        if font_families.has_key( lword ):
            f = QFont()
            f.setStyleHint( font_families[ lword ] )
            family = f.defaultFamily()
        elif font_styles.has_key( lword ):
            style = font_styles[ lword ]
        elif font_weights.has_key( lword ):
            weight = font_weights[ lword ]
        elif lword == 'underline':
            underline = True
        elif lword not in font_noise:
            if point_size is None:
                try:
                    point_size = int( lword )
                    continue
                except:
                    pass

            facename.append( word )

    if facename:
        family = ' '.join( facename )

    if family:
        font = FacetsFont( family )
    else:
        font = FacetsFont()

    font.setStyle( style )
    font.setWeight( weight )
    font.setUnderline( underline )

    if point_size is not None:
        font.setPointSize( point_size )

    font_cache[ value ] = font

    return font