當前位置: 首頁>>代碼示例>>Python>>正文


Python fontforge.font方法代碼示例

本文整理匯總了Python中fontforge.font方法的典型用法代碼示例。如果您正苦於以下問題:Python fontforge.font方法的具體用法?Python fontforge.font怎麽用?Python fontforge.font使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在fontforge的用法示例。


在下文中一共展示了fontforge.font方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _get_font_max_size_info

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def _get_font_max_size_info(font, start, end):
    """return size information for biggest glyph
    :param fontforge.font font: font object
    :param int start: unicode start point
    :param int end: unicode end point
    :return GlyphSizeInfo: biggest glyph size info"""
    info = None
    for code in range(start, end + 1):
        try:
            _info = get_glyph_size_info(font[code])
            if info is None:
                info = _info
                continue
            for key in dir(_info):
                a = getattr(_info, key)
                b = getattr(info, key)
                if abs(a) > abs(b):
                    setattr(info, key, a)
        except TypeError:
            continue
    return info 
開發者ID:iij,項目名稱:fontmerger,代碼行數:23,代碼來源:fontmerger.py

示例2: get_font_name_info

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def get_font_name_info(font):
    """return font name information
    :param fontforge.font font: a font object
    :return tuple of (font name, font family name, full name, sub-family name)"""
    family = font.familyname
    fullname = font.fullname
    sub_family = 'Regular'
    name = font.fontname
    _, fallback_style = re.match('^([^-]*).*?([^-]*(?!.*-))$', name).groups()
    try:
        sub_family_tuple_index = [x[1] for x in font.sfnt_names].index('SubFamily')
        sub_family = font.sfnt_names[2][sub_family_tuple_index]
    except IndexError:
        pass
    if sub_family == 'Regular':
        sub_family = fallback_style
    family = re.sub(r'[ _-]?{0}$'.format(sub_family), '', family, flags=re.IGNORECASE)
    fullname = re.sub(r'[ _-]?{0}$'.format(sub_family), '', fullname, flags=re.IGNORECASE)
    name = re.sub(r'[ _-]?{0}$'.format(sub_family), '', name, flags=re.IGNORECASE)
    return name, family, fullname, sub_family 
開發者ID:iij,項目名稱:fontmerger,代碼行數:22,代碼來源:fontmerger.py

示例3: copy

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def copy(self, aParent=None):
        """Make a copy of this glyph.
        Note: the copy is not a duplicate fontlab glyph, but
        a RF RGlyph with the same outlines. The new glyph is
        not part of the fontlab font in any way. Use font.appendGlyph(glyph)
        to get it in a FontLab glyph again."""
        from robofab.objects.objectsRF import RGlyph as _RGlyph
        newGlyph = _RGlyph()
        newGlyph.appendGlyph(self)
        for attr in GLYPH_COPY_ATTRS:
            value = getattr(self, attr)
            setattr(newGlyph, attr, value)
        parent = self.getParent()
        if aParent is not None:
            newGlyph.setParent(aParent)
        elif self.getParent() is not None:
            newGlyph.setParent(self.getParent())
        return newGlyph 
開發者ID:rsms,項目名稱:inter,代碼行數:20,代碼來源:objectsFF.py

示例4: __repr__

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def __repr__(self):
        font = "unnamed_font"
        glyph = "unnamed_glyph"
        contourIndex = "unknown_contour"
        contourParent = self.getParent()
        if contourParent is not None:
            try:
                contourIndex = `contourParent.index`
            except AttributeError: pass
            glyphParent = contourParent.getParent()
            if glyphParent is not None:
                try:
                    glyph = glyphParent.name
                except AttributeError: pass
                fontParent = glyphParent.getParent()
                if fontParent is not None:
                    try:
                        font = fontParent.info.fullName
                    except AttributeError: pass
        return "<RPoint for %s.%s[%s]>"%(font, glyph, contourIndex) 
開發者ID:rsms,項目名稱:inter,代碼行數:22,代碼來源:objectsFF.py

示例5: save

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def save(self, path=None):
        """Save this font as sfd file.
        XXX: how to set a sfd path if is none
        """
        if path is not None:
            # trying to save it somewhere else
            _path = path
        else:
            _path = self.path
        if os.path.splitext(_path)[-1] != ".sfd":
            _path = os.path.splitext(_path)[0]+".sfd"
        if __DEBUG__:
            print "RFont.save() to", _path
        self._object.save(_path) 
開發者ID:rsms,項目名稱:inter,代碼行數:16,代碼來源:objectsFF.py

示例6: __init__

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def __init__(self, font):
        """Font's size hints
        :param fontforge.font font: a font object"""
        self.font = font
        self._half = None
        self._full = None
        self.ascent = font.hhea_ascent
        self.descent = font.hhea_descent 
開發者ID:iij,項目名稱:fontmerger,代碼行數:10,代碼來源:fontmerger.py

示例7: half

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def half(self):
        """returns size info for half-width font
        :return GlyphSizeInfo: glyph's size info"""
        if not self._half:
            self._half = _get_font_max_size_info(self.font, 0x23, 0x7e)
        return self._half 
開發者ID:iij,項目名稱:fontmerger,代碼行數:8,代碼來源:fontmerger.py

示例8: full

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def full(self):
        """returns size info for full-width font
        :return: GlyphSizeInfo: glyph's size info
        """
        if not self._full:
            self._full = _get_font_max_size_info(self.font, 0xff01, 0xff5e)
        return self._full 
開發者ID:iij,項目名稱:fontmerger,代碼行數:9,代碼來源:fontmerger.py

示例9: display_unicode_utf8

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def display_unicode_utf8(ctx, fd=sys.stdout):
    """display unicode characters as UTF-8
    :param MergingContext ctx: a merging font context
    :param file fd: display target"""
    font = fontforge.open(ctx.filename)
    unicode_range = ctx.unicode_range
    start = 0
    end = 0
    if len(unicode_range) >= 1:
        start = int(unicode_range[0], 16)
    if len(unicode_range) >= 2:
        end = int(unicode_range[1], 16)
    remap_start_point = ctx.remap_start_point
    delta = 0
    if remap_start_point is not None:
        delta = int(remap_start_point, 16) - start
    if start is 0:
        font.selection.all()
    else:
        font.selection.select(('ranges', 'unicode'), start, end)
    length = 0
    line = ''
    fd.write('{0:-^80}\n'.format(' ' + ctx.id + ' '))
    for glyph in list(font.selection.byGlyphs):
        line += unichr(glyph.encoding + delta)
        info = get_glyph_size_info(glyph)
        if info.width <= font.em / 2:
            # half width
            line += ' '
        length += 1
        if length is 40:
            fd.write(line.encode('utf-8') + '\n')
            length = 0
            line = ''
    if length > 0:
        fd.write(line.encode('utf-8') + '\n')
    fd.flush()
    font.close() 
開發者ID:iij,項目名稱:fontmerger,代碼行數:40,代碼來源:fontmerger.py

示例10: get_height

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def get_height(font):
    """return font height
    :param fontforge.font font: a font object
    :return font height"""
    return font.hhea_ascent + abs(font.hhea_descent) 
開發者ID:iij,項目名稱:fontmerger,代碼行數:7,代碼來源:fontmerger.py

示例11: NewFont

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def NewFont(fontPath=None):
    _font = fontforge.font()
    if __DEBUG__:
        print "NewFont", fontPath
        print "result:", _font
    return RFont(_font) 
開發者ID:rsms,項目名稱:inter,代碼行數:8,代碼來源:objectsFF.py

示例12: __init__

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def __init__(self, font=None):
        if font is None:
            # make a new font
            pass
        else:
            self._object = font
    
    # -----------------------------------------------------------------
    #
    #   access 
開發者ID:rsms,項目名稱:inter,代碼行數:12,代碼來源:objectsFF.py

示例13: keys

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def keys(self):
        """FF implements __iter__ for the font object - better?"""
        return [n.glyphname for n in self._object.glyphs()] 
開發者ID:rsms,項目名稱:inter,代碼行數:5,代碼來源:objectsFF.py

示例14: getGlyph

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def getGlyph(self, glyphName):
        try:
            ffGlyph = self._object[glyphName]
        except TypeError:
            print "font.getGlyph, can't find glyphName, returning new glyph"
            return self.newGlyph(glyphName)
        glyph = RGlyph(ffGlyph)
        glyph.setParent(self)
        return glyph 
開發者ID:rsms,項目名稱:inter,代碼行數:11,代碼來源:objectsFF.py

示例15: _get_mark

# 需要導入模塊: import fontforge [as 別名]
# 或者: from fontforge import font [as 別名]
def _get_mark(self):
        """color of the glyph box in the font view. This accepts a 6 hex digit number.
        
        XXX the FL implementation accepts a 
        """
        import colorsys
        r = (self._object.color&0xff0000)>>16
        g = (self._object.color&0xff00)>>8
        g = (self._object.color&0xff)>>4
        return colorsys.rgb_to_hsv( r, g, b)[0] 
開發者ID:rsms,項目名稱:inter,代碼行數:12,代碼來源:objectsFF.py


注:本文中的fontforge.font方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。