当前位置: 首页>>代码示例>>Python>>正文


Python Font.bin2unistring方法代码示例

本文整理汇总了Python中bakery_cli.ttfont.Font.bin2unistring方法的典型用法代码示例。如果您正苦于以下问题:Python Font.bin2unistring方法的具体用法?Python Font.bin2unistring怎么用?Python Font.bin2unistring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bakery_cli.ttfont.Font的用法示例。


在下文中一共展示了Font.bin2unistring方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_check_names_same_across_platforms

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import bin2unistring [as 别名]
    def test_check_names_same_across_platforms(self):
        """ Font names are same across specific-platforms """
        font = Font.get_ttfont(self.operator.path)

        for name in font.names:
            for name2 in font.names:
                if name.nameID != name2.nameID:
                    continue

                if self.diff_platform(name, name2) or self.diff_platform(name2, name):
                    _name = Font.bin2unistring(name)
                    _name2 = Font.bin2unistring(name2)
                    if _name != _name2:
                        msg = ('Names in "name" table are not the same'
                               ' across specific-platforms')
                        self.fail(msg)
开发者ID:anthrotype,项目名称:fontbakery,代码行数:18,代码来源:test_check_names_same_across_platforms.py

示例2: fix

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import bin2unistring [as 别名]
 def fix(self):
     for name in self.font['name'].names:
         title = Font.bin2unistring(name)
         title = CharacterSymbolsFixer.normalizestr(title)
         if name.platformID == 3 and name.isUnicode():
             name.string = title.encode('utf-16-be')
         else:
             name.string = title
     return True
开发者ID:jessamynsmith,项目名称:fontbakery,代码行数:11,代码来源:fixers.py

示例3: test_check_names_are_ascii_only

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import bin2unistring [as 别名]
    def test_check_names_are_ascii_only(self):
        """ NAME and CFF tables must not contain non-ascii characters """
        font = Font.get_ttfont(self.operator.path)

        for name in font.names:
            string = Font.bin2unistring(name)
            marks = CharacterSymbolsFixer.unicode_marks(string)
            if marks:
                self.fail('Contains {}'.format(marks))
开发者ID:bitforks,项目名称:fontbakery,代码行数:11,代码来源:test_ttf.py

示例4: test_check_names_are_ascii_only

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import bin2unistring [as 别名]
    def test_check_names_are_ascii_only(self):
        """ NAME and CFF tables must not contain non-ascii characters """
        font = Font.get_ttfont(self.path)

        for name_record in font.names:
            string = Font.bin2unistring(name_record)
            try:
                string.encode('ascii')
            except UnicodeEncodeError:
                self.fail("%s contain non-ascii chars" % name_record.nameID)
开发者ID:lowks,项目名称:fontbakery-cli,代码行数:12,代码来源:test_names_are_ascii_only.py

示例5: test_check_full_font_name_begins_with_family_name

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import bin2unistring [as 别名]
    def test_check_full_font_name_begins_with_family_name(self):
        """ Check if full font name begins with the font family name """
        font = Font.get_ttfont(self.operator.path)
        for entry in font.names:
            if entry.nameID != 1:
                continue
            for entry2 in font.names:
                if entry2.nameID != 4:
                    continue
                if (entry.platformID == entry2.platformID
                        and entry.platEncID == entry2.platEncID
                        and entry.langID == entry2.langID):

                    entry2value = Font.bin2unistring(entry2)
                    entryvalue = Font.bin2unistring(entry)
                    if not entry2value.startswith(entryvalue):
                        _ = ('Full font name does not begin with family'
                             ' name: FontFamilyName = "%s";'
                             ' FullFontName = "%s"')
                        self.fail(_ % (entryvalue, entry2value))
开发者ID:bitforks,项目名称:fontbakery,代码行数:22,代码来源:test_ttf.py

示例6: fix_name_table

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import bin2unistring [as 别名]
def fix_name_table(fontfile):
    try:
        font = Font(fontfile)
    except TTLibError:
        print("Unable to open {}".format(os.path.basename(fontfile)),
              file=sys.stderr)
        return

    for name in font['name'].names:
        title = Font.bin2unistring(name)
        title = normalizestr(title)
        if name.platformID == 3:
            name.string = title.encode('utf-16-be')
        else:
            name.string = title

    font.save(fontfile + '.fix')
开发者ID:anthrotype,项目名称:fontbakery,代码行数:19,代码来源:ascii.py

示例7: fix_name_table

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import bin2unistring [as 别名]
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# See AUTHORS.txt for the list of Authors and LICENSE.txt for the License.
import sys

from fontTools.ttLib import TTLibError

from bakery_cli.ttfont import Font


def fix_name_table(fontfile):
    try:
        font = Font(fontfile)
    except TTLibError, ex:
        print >> sys.stderr, "ERROR: %s" % ex
        return
    for name_record in font['name'].names:
        name_record.string = Font.bin2unistring(name_record.string)
    font.save(fontfile + '.fix')
开发者ID:lowks,项目名称:fontbakery-cli,代码行数:32,代码来源:ascii.py

示例8: find_italic_in_name_table

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import bin2unistring [as 别名]
 def find_italic_in_name_table(self, ttfont):
     for entry in ttfont.names:
         if 'italic' in Font.bin2unistring(entry).lower():
             return True
开发者ID:adrientetar,项目名称:fontbakery,代码行数:6,代码来源:test_metadata.py

示例9: test_ttx_family_naming_recommendation

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import bin2unistring [as 别名]
    def test_ttx_family_naming_recommendation(self):
        "The font follows the font family naming recommendation."
        # See http://forum.fontlab.com/index.php?topic=313.0
        font = Font.get_ttfont(self.operator.path)

        length = len(Font.bin2unistring(font['name'].getName(4, 3, 1, 1033)))
        self.assertLess(length, 64,
                        msg=('`Full Font Name` limitation is less'
                             ' than 64 chars. Now: %s') % length)

        length = len(Font.bin2unistring(font['name'].getName(6, 3, 1, 1033)))
        self.assertLess(length, 30,
                        msg=('`PostScript Name` limitation is less'
                             ' than 30 chars. Now: %s') % length)

        # <Postscript name> may contain only a-zA-Z0-9
        # and one hyphen
        name = Font.bin2unistring(font['name'].getName(6, 3, 1, 1033))
        self.assertRegexpMatches(name, r'[a-zA-Z0-9-]+',
                                 msg=('`PostScript Name` may contain'
                                      ' only a-zA-Z0-9 characters and'
                                      ' one hyphen'))
        self.assertLessEqual(name.count('-'), 1,
                             msg=('`PostScript Name` may contain only'
                                  ' one hyphen'))

        # <Family Name> limitation is 32 chars
        length = len(Font.bin2unistring(font['name'].getName(1, 3, 1, 1033)))
        self.assertLess(length, 32,
                        msg=('`Family Name` limitation is < 32 chars.'
                             ' Now: %s') % length)

        # <Style Name> limitation is 32 chars
        length = len(Font.bin2unistring(font['name'].getName(2, 3, 1, 1033)))
        self.assertLess(length, 32,
                        msg=('`Style Name` limitation is < 32 chars.'
                             ' Now: %s') % length)

        # <OT Family Name> limitation is 32 chars
        length = len(Font.bin2unistring(font['name'].getName(16, 3, 1, 1033)))
        self.assertLess(length, 32,
                        msg=('`OT Family Name` limitation is < 32 chars.'
                             ' Now: %s') % length)

        # <OT Style Name> limitation is 32 chars
        length = len(Font.bin2unistring(font['name'].getName(17, 3, 1, 1033)))
        self.assertLess(length, 32,
                        msg=('`OT Style Name` limitation is < 32 chars.'
                             ' Now: %s') % length)

        if 'OS/2' in font:
            # <Weight> value >= 250 and <= 900 in steps of 50
            self.assertTrue(bool(font['OS/2'].usWeightClass % 50 == 0),
                            msg=('OS/2 usWeightClass has to be in steps of 50.'
                                 ' Now: %s') % font['OS/2'].usWeightClass)

            self.assertGreaterEqual(font['OS/2'].usWeightClass, 250)
            self.assertLessEqual(font['OS/2'].usWeightClass, 900)

        if 'CFF' in font:
            self.assertTrue(bool(font['CFF'].Weight % 50 == 0),
                            msg=('CFF Weight has to be in steps of 50.'
                                 ' Now: %s') % font['CFF'].Weight)

            self.assertGreaterEqual(font['CFF'].Weight, 250)
            self.assertLessEqual(font['CFF'].Weight, 900)
开发者ID:bitforks,项目名称:fontbakery,代码行数:68,代码来源:test_ttf.py

示例10: fix

# 需要导入模块: from bakery_cli.ttfont import Font [as 别名]
# 或者: from bakery_cli.ttfont.Font import bin2unistring [as 别名]
 def fix(self):
     for name in self.font['name'].names:
         title = Font.bin2unistring(name)
         title = CharacterSymbolsFixer.normalizestr(title)
         name.string = title.encode(name.getEncoding())
     return True
开发者ID:davelab6,项目名称:fontbakery,代码行数:8,代码来源:fixers.py


注:本文中的bakery_cli.ttfont.Font.bin2unistring方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。