Exemplo n.º 1
0
    def addFontFiles(self, font_paths, monospace_only=True):
        """ Add a list of font files to the FontManger font search space.
        Each element of the font_paths list must be a valid path including
        the font file name. Relative paths can be used, with the current
        working directory being the origin.

        If monospace_only is True, each font file will only be added if it is
        a monospace font (as only monospace fonts are currently supported by
        TextBox).

        Adding fonts to the FontManager is not persistent across runs of
        the script, so any extra font paths need to be added each time the
        script starts.
        """

        fi_list = []
        for fp in font_paths:
            if os.path.isfile(fp) and os.path.exists(fp):
                face = Face(fp)
                if monospace_only:
                    if face.is_fixed_width:
                        fi_list.append(self._createFontInfo(fp, face))
                else:
                    fi_list.append(self._createFontInfo(fp, face))

        self.font_family_styles.sort()

        return fi_list
Exemplo n.º 2
0
    def __init__(self, font_info, size, dpi):
        self.font_info = font_info
        self.size = size
        self.dpi = dpi
        self.id = self.getIdFromArgs(font_info, size, dpi)
        self._face = Face(font_info.path)
        self._face.set_char_size(height=self.size * 64, vres=self.dpi)

        self.charcode2glyph = None
        self.charcode2unichr = None
        self.charcode2displaylist = None
        self.max_ascender = None
        self.max_descender = None
        self.max_tile_width = None
        self.max_tile_height = None
        self.max_bitmap_size = None
        self.total_bitmap_area = 0
        self.atlas = None
Exemplo n.º 3
0
    def addFontFiles(self,font_paths,monospace_only=True):
        """
        Add a list of font files to the FontManger font search space. Each element
        of the font_paths list must be a valid path including the font file name.
        Relative paths can be used, with the current working directory being
        the origin.

        If monospace_only is True, each font file will only be added if it is a
        monospace font (as only monospace fonts are currently supported by
        TextBox).

        Adding fonts to the FontManager is not persistant across runs of
        the script, so any extra font paths need to be added each time the
        script starts.
        """

        fi_list=[]
        for fp in font_paths:
            if os.path.isfile(fp) and os.path.exists(fp):
                try:
                    face = Face(fp)
                    if monospace_only:
                        if face.is_fixed_width:
                            fi_list.append(self._createFontInfo(fp,face))
                    else:
                        fi_list.append(self._createFontInfo(fp,face))
                except FT_Exception, fte:
                    pass
                except Exception, e:
                    print
                    print ' --- Error --- '
                    print 'Error opening font path:', fp
                    print 'Loaded OK count:', len(fi_list)
                    import traceback
                    traceback.print_exc()
                    return None