def _MakeMetadata(fontdir, is_new): """Builds a dictionary matching a METADATA.pb file. Args: fontdir: Directory containing font files for which we want metadata. is_new: Whether this is an existing or new family. Returns: OrderedDict of a complete METADATA.pb structure. Raises: RuntimeError: If the variable font axes info differs between font files of same family. """ file_family_style_weights = _FileFamilyStyleWeights(fontdir) first_file = file_family_style_weights[0].file subsets = ['menu'] + [ s[0] for s in fonts.SubsetsInFont(first_file, FLAGS.min_pct, FLAGS.min_pct_ext) ] old_metadata_file = os.path.join(fontdir, 'METADATA.pb') font_license = fonts.LicenseFromPath(fontdir) metadata = fonts_pb2.FamilyProto() metadata.name = file_family_style_weights[0].family if not is_new: old_metadata = fonts_pb2.FamilyProto() with open(old_metadata_file, 'rb') as old_meta: text_format.Parse(old_meta.read(), old_metadata) metadata.designer = old_metadata.designer metadata.category = old_metadata.category metadata.date_added = old_metadata.date_added else: metadata.designer = 'UNKNOWN' metadata.category = 'SANS_SERIF' metadata.date_added = time.strftime('%Y-%m-%d') metadata.license = font_license subsets = sorted(subsets) for subset in subsets: metadata.subsets.append(subset) for (fontfile, family, style, weight) in file_family_style_weights: filename = os.path.basename(fontfile) font_psname = fonts.ExtractName(fontfile, fonts.NAME_PSNAME, os.path.splitext(filename)[0]) font_copyright = fonts.ExtractName(fontfile, fonts.NAME_COPYRIGHT, '???.').strip() font_metadata = metadata.fonts.add() font_metadata.name = family font_metadata.style = style font_metadata.weight = weight font_metadata.filename = filename font_metadata.post_script_name = font_psname default_fullname = os.path.splitext(filename)[0].replace('-', ' ') font_metadata.full_name = fonts.ExtractName(fontfile, fonts.NAME_FULLNAME, default_fullname) font_metadata.copyright = font_copyright axes_info_from_font_files \ = {_AxisInfo(f.file) for f in file_family_style_weights} if len(axes_info_from_font_files) != 1: raise RuntimeError( 'Variable axes info not matching between font files') for axes_info in axes_info_from_font_files: if axes_info: for axes in axes_info: var_axes = metadata.axes.add() var_axes.tag = axes[0] var_axes.min_value = axes[1] var_axes.default_value = axes[2] var_axes.max_value = axes[3] return metadata
def main(argv): for arg in argv[1:]: subsets = fonts.SubsetsInFont(arg, FLAGS.min_pct, FLAGS.min_pct_ext) for (subset, available, total) in subsets: print '%s %s %d/%d' % (os.path.basename(arg), subset, available, total)