コード例 #1
0
ファイル: builder.py プロジェクト: xen/pyfontaine
    def construct_tree(self, fonts):

        tree = OrderedDict({'fonts': []})

        for font_filename in fonts:
            font = Font(font_filename, charmaps=self.charmaps)

            F = OrderedDict()
            desc = OrderedDict()
            desc['commonName'] = font.common_name
            desc['subFamily'] = font.sub_family
            desc['style'] = font.style_flags
            desc['weight'] = font.weight
            desc['fixedWidth'] = yesno(font.is_fixed_width)
            desc['fixedSizes'] = yesno(font.has_fixed_sizes)
            desc['copyright'] = extract_firstline(font.copyright or '')
            desc['license'] = extract_firstline(font.license or '')
            desc['licenseUrl'] = font.license_url
            desc['version'] = font.version
            desc['vendor'] = extract_firstline(font.vendor or '')
            desc['vendorUrl'] = font.vendor_url
            desc['designer'] = font.designer
            desc['designerUrl'] = font.designer_url
            desc['glyphCount'] = font.glyph_num
            desc['characterCount'] = font.character_count
            for charmap, support_level, coverage, missing \
                    in font.get_orthographies():
                if support_level == SUPPORT_LEVEL_UNSUPPORTED:
                    continue
                if 'orthographies' not in desc:
                    desc['orthographies'] = []

                orth = OrderedDict({'orthography': OrderedDict()})
                orth['orthography']['commonName'] = charmap.common_name
                orth['orthography']['nativeName'] = charmap.native_name
                orth['orthography']['supportLevel'] = support_level

                if support_level != SUPPORT_LEVEL_FULL:
                    values = u'\n%s' % u'\n'.join(unicodevalues_asstring(missing))
                    orth['orthography']['percentCoverage'] = coverage
                    if self.missingValues:
                        orth['orthography']['missingValues'] = values

                desc['orthographies'].append(orth)

            if self.generate_coverage:
                self.represent_coverage_png(font)

            F['font'] = desc
            tree['fonts'].append(F)

        return tree
コード例 #2
0
ファイル: utils.py プロジェクト: Troush/fontbakery
def project_fontaine(project, build):
    from fontaine.font import Font

    param = {'login': project.login, 'id': project.id,
        'revision': build.revision, 'build': build.id}

    _out = os.path.join(DATA_ROOT, '%(login)s/%(id)s.out/%(build)s.%(revision)s/' % param)

    # Its very likely that _out exists, but just in case:
    if os.path.exists(_out):
        os.chdir(_out)
    else:
        # This is very unlikely, but should it happen, just return
        return

    # Run pyFontaine on all the TTF fonts
    fonts = {}
    for filename in glob.glob("*.ttf"):
        fontaine = Font(filename)
        fonts[filename] = fontaine

    # Make a plain dictionary, unlike the fancy data structures used by pyFontaine :)
    family = {}
    for fontfilename, fontaine in fonts.iteritems():
        # Use the font file name as a key to a dictionary of char sets
        family[fontfilename] = {}
        for charset, coverage, percentcomplete, missingchars in fontaine.get_orthographies():
            # Use each char set name as a key to a dictionary of this font's coverage details
            charsetname = charset.common_name
            family[fontfilename][charsetname] = {}
            family[fontfilename][charsetname]['coverage'] = coverage  # unsupport, fragmentary, partial, full
            family[fontfilename][charsetname]['percentcomplete'] = percentcomplete  # int
            family[fontfilename][charsetname]['missingchars'] = missingchars  # list of ord numbers
            # Use the char set name as a key to a list of the family's average coverage
            if not charsetname in family:
                family[charsetname] = []
            # Append the char set percentage of each font file to the list
            family[charsetname].append(percentcomplete)  # [10, 32, 40, 40] etc
            # And finally, if the list now has all the font files, make it the mean average percentage
            if len(family[charsetname]) == len(fonts.items()):
                family[charsetname] = sum(family[charsetname]) / len(fonts.items())
    # Make a plain dictionary with just the bits we want on the dashboard
    totals = {}
    totals['gwf'] = family.get('GWF latin', None)
    totals['al3'] = family.get('Adobe Latin 3', None)
    # Store it in the $(id).state.yaml file
    project.config['local']['charsets'] = totals
    project.save_state()

    # fonts.itervalues() emits <fontaine.font.Font instance at 0x106123c68> objects that we return for the rfiles.html template
    return fonts.itervalues()
コード例 #3
0
ファイル: builder.py プロジェクト: xen/pyfontaine
    def wiki(fonts):
        for font_filename in fonts:
            font = Font(font_filename)
            print('=== %s ===' % font.common_name.encode('ascii', 'ignore'))
            print('{|')
            print('| colspan=3 |')
            for subset in library.charmaps:
                charmap, supported, coverage, missing = font.get_othography_info(subset)
                if supported == SUPPORT_LEVEL_UNSUPPORTED:
                    continue

                glyphs = charmap.glyphs
                if callable(glyphs):
                    glyphs = glyphs()

                print('|-')
                print("| [[ %s ]] (%s/%s)  || style='text-align:right'" % (charmap.common_name, len(glyphs) - len(missing), len(glyphs)),
                      " | {{bartable|%s|%%|2||background:green}}" % coverage)
            print('|}')
コード例 #4
0
ファイル: result_test.py プロジェクト: Troush/fontbakery
class FontaineTest(TestCase):
    targets = ['result']
    tool = 'pyfontaine'
    name = __name__
    path = '.'

    def setUp(self):
        self.font = Font(self.path)
        # You can use ipdb here to interactively develop tests!
        # Uncommand the next line, then at the iPython prompt: print(self.path)
        # import ipdb; ipdb.set_trace()

    # def test_ok(self):
    #     """ This test succeeds """
    #     self.assertTrue(True)
    #
    # def test_failure(self):
    #     """ This test fails """
    #     self.assertTrue(False)
    #
    # def test_error(self):
    #     """ Unexpected error """
    #     1 / 0
    #     self.assertTrue(False)

    def test_charMaker(self):
        # import ipdb; ipdb.set_trace()
        pattern = re.compile('[\W_]+')
        functionTemplate = """def test_charset_%s(self, p): self.test_charset_%s.__func__.__doc__ = "Is %s covered 100%%?"; self.assertTrue(p == 100)"""
        for orthographyTuple in self.font.get_orthographies():
            charmap = orthographyTuple[0]
            percent = orthographyTuple[2]
            shortname = pattern.sub('', charmap.common_name)
            print "TODO: This doesn't work yet..."
            print functionTemplate % (shortname, shortname, charmap.common_name)
            print 'test_charset_%s(self, 100)' % shortname
            exec functionTemplate % (shortname, shortname, charmap.common_name)
            exec 'test_charset_%s(self, 100)' % shortname
コード例 #5
0
ファイル: result_test.py プロジェクト: Troush/fontbakery
 def setUp(self):
     self.font = Font(self.path)
コード例 #6
0
ファイル: famchar.py プロジェクト: Troush/fontbakery
if len(sys.argv) < 2:
    print __doc__
    sys.exit()
# Check the arg is a directory
workingDir = sys.argv[1]
if os.path.exists(workingDir):
    # If it is a directory, change context to it
    os.chdir(workingDir)
else:
    print __doc__
    sys.exit()

# Run pyFontaine on all the TTF fonts
fonts = {}
for filename in glob.glob("*.*tf"):
    fontaine = Font(filename)
    fonts[filename] = fontaine

# Make a plain dictionary 
family = {}
for fontfilename, fontaine in fonts.iteritems():
    # Use the font file name as a key to a dictionary of char sets
    family[fontfilename] = {}
    #print fontfilename
    for charset, coverage, percentcomplete, missingchars in fontaine.get_orthographies():
        # Use each char set name as a key to a dictionary of this font's coverage details
        charsetname = charset.common_name
        family[fontfilename][charsetname] = {}
        family[fontfilename][charsetname]['coverage'] = coverage # unsupport, fragmentary, partial, full
        family[fontfilename][charsetname]['percentcomplete'] = percentcomplete # int
        family[fontfilename][charsetname]['missingchars'] = missingchars # list of ord numbers