def check_familyname(name, styles): notofont = noto_fonts.get_noto_font('unhinted/' + name + '-Regular.ttf') if not notofont: print 'Error: could not parse', name return False print name, noto_fonts.noto_font_to_wws_family_id(notofont), styles return True
def check_familyname(name, styles): notofont = noto_fonts.get_noto_font("unhinted/" + name + "-Regular.ttf") if not notofont: print("Error: could not parse", name) return False print(name, noto_fonts.noto_font_to_wws_family_id(notofont), styles) return True
def create_family_to_name_info(notofonts, phase): family_to_parts = collections.defaultdict(set) family_to_name_styles = collections.defaultdict(set) cjk_families = set() for noto_font in notofonts: family_id = noto_fonts.noto_font_to_wws_family_id(noto_font) preferred_family, preferred_subfamily = _preferred_parts(noto_font) _, subfamily_parts = _wws_parts(preferred_family, preferred_subfamily) family_to_parts[family_id].update(subfamily_parts) # It's been asserted that the family name can't be longer than 32 chars. # Assume this is only true for nameID 1 and not nameID 16 or 17. family_parts, _ = _original_parts(preferred_family, preferred_subfamily) family_name_style = _name_style_for_length(family_parts, 31) family_to_name_styles[family_id].add(family_name_style) if noto_font.is_cjk: cjk_families.add(family_id) result = {} for family_id, part_set in family_to_parts.iteritems(): # Even through CJK mono fonts are in their own families and have only # bold and regular weights, they behave like they have more weights like # the rest of CJK. family_is_cjk = family_id in cjk_families no_style_linking = phase == 2 and family_is_cjk use_preferred = no_style_linking or bool(part_set - _ORIGINAL_PARTS) # In phase 3, we keep 'Regular' in the postscript/full name always, prior to # that we only do so for CJK. omit_regular = phase == 2 and not family_is_cjk name_style = 'normal' if phase == 2 else _select_name_style( family_to_name_styles[family_id]) result[family_id] = FamilyNameInfo(no_style_linking, use_preferred, omit_regular, name_style) return result
def create_family_to_name_info(notofonts, phase): if phase not in [2, 3]: raise ValueError('expected phase 2 or 3 but got "%s"' % phase) family_to_parts = collections.defaultdict(set) family_to_name_styles = collections.defaultdict(set) cjk_families = set() for noto_font in notofonts: family_id = noto_fonts.noto_font_to_wws_family_id(noto_font) preferred_family, preferred_subfamily = _preferred_parts(noto_font) _, subfamily_parts = _wws_parts(preferred_family, preferred_subfamily) family_to_parts[family_id].update(subfamily_parts) # It's been asserted that the family name can't be longer than 32 chars. # Assume this is only true for nameID 1 and not nameID 16 or 17. family_parts, _ = _original_parts(preferred_family, preferred_subfamily) family_name_style = _name_style_for_length(family_parts, 31) family_to_name_styles[family_id].add(family_name_style) if noto_font.is_cjk: cjk_families.add(family_id) result = {} for family_id, part_set in family_to_parts.iteritems(): # Even through CJK mono fonts are in their own families and have only # bold and regular weights, they behave like they have more weights like # the rest of CJK. family_is_cjk = family_id in cjk_families no_style_linking = phase == 2 and family_is_cjk use_preferred = no_style_linking or bool(part_set - _ORIGINAL_PARTS) # Keep 'Regular' in the postscript/full name only for CJK. include_regular = family_is_cjk name_style = 'normal' if phase == 2 else _select_name_style( family_to_name_styles[family_id]) result[family_id] = FamilyNameInfo( no_style_linking, use_preferred, include_regular, name_style) return result
def name_table_data(noto_font, family_to_name_info, phase): """Returns a NameTableData for this font given the family_to_name_info.""" family_id = noto_fonts.noto_font_to_wws_family_id(noto_font) try: info = family_to_name_info[family_id] except KeyError: sys.stderr.write('no family name info for "%s"\n' % family_id) return None family_parts, subfamily_parts = _wws_parts(*_preferred_parts(noto_font)) if not info.use_preferred and subfamily_parts not in [ ["Regular"], ["Bold"], ["Italic"], ["Bold", "Italic"], ]: sys.stderr.write( "Error in family name info: %s requires preferred names, but info says none are required.\n" % path.basename(noto_font.filepath)) sys.stderr.write("%s\n" % subfamily_parts) return None # for phase 3 we'll now force include_regular include_regular = phase == 3 or info.include_regular ofn, osfn = _original_names(family_parts, subfamily_parts, info.no_style_linking, info.family_name_style) # If we limit the original names (to put weights into the original family) # then we need a preferred name to undo this. When info is read or generated, # the code should ensure use_preferred is set. pfn, psfn = _preferred_names(family_parts, subfamily_parts, info.use_preferred) if pfn and pfn == ofn: pfn = None if psfn and psfn == osfn: psfn = None return NameTableData( copyright_re=_copyright_re(noto_font), original_family=ofn, original_subfamily=osfn, unique_id="-", full_name=_full_name(family_parts, subfamily_parts, include_regular), version_re=_version_re(noto_font, phase), postscript_name=_postscript_name(family_parts, subfamily_parts, include_regular), trademark=_trademark(noto_font), manufacturer=_manufacturer(noto_font), designer=_designer(noto_font, phase), description_re=_description_re(noto_font, phase), vendor_url=NOTO_URL, designer_url=_designer_url(noto_font), license_text=_license_text(noto_font), license_url=_license_url(noto_font), preferred_family=pfn, preferred_subfamily=psfn, wws_family=None, wws_subfamily=None, )
def name_table_data(noto_font, family_to_name_info, phase): """Returns a NameTableData for this font given the family_to_name_info.""" family_id = noto_fonts.noto_font_to_wws_family_id(noto_font) try: info = family_to_name_info[family_id] except KeyError: print >> sys.stderr, 'no family name info for "%s"' % family_id return None family_parts, subfamily_parts = _wws_parts(*_preferred_parts(noto_font)) if not info.use_preferred and subfamily_parts not in [ ['Regular'], ['Bold'], ['Italic'], ['Bold', 'Italic']]: print >> sys.stderr, ( 'Error in family name info: %s requires preferred names, but info ' 'says none are required.' % path.basename(noto_font.filepath)) print >> sys.stderr, subfamily_parts return None ofn, osfn = _original_names( family_parts, subfamily_parts, info.no_style_linking, info.family_name_style) # If we limit the original names (to put weights into the original family) # then we need a preferred name to undo this. When info is read or generated, # the code should ensure use_preferred is set. pfn, psfn = _preferred_names( family_parts, subfamily_parts, info.use_preferred) if pfn and pfn == ofn: pfn = None if psfn and psfn == osfn: psfn = None return NameTableData( copyright_re=_copyright_re(noto_font), original_family=ofn, original_subfamily=osfn, unique_id='-', full_name=_full_name(family_parts, subfamily_parts, info.include_regular), version_re=_version_re(noto_font, phase), postscript_name=_postscript_name( family_parts, subfamily_parts, info.include_regular), trademark=_trademark(noto_font), manufacturer=_manufacturer(noto_font), designer=_designer(noto_font, phase), description_re=_description_re(noto_font, phase), vendor_url=NOTO_URL, designer_url=_designer_url(noto_font), license_text=_license_text(noto_font), license_url=_license_url(noto_font), preferred_family=pfn, preferred_subfamily=psfn, wws_family=None, wws_subfamily=None)
def name_table_data(noto_font, family_to_name_info, phase): """Returns a NameTableData for this font given the family_to_name_info.""" family_id = noto_fonts.noto_font_to_wws_family_id(noto_font) try: info = family_to_name_info[family_id] except KeyError: print >> sys.stderr, 'no family name info for "%s"' % family_id return None family_parts, subfamily_parts = _wws_parts(*_preferred_parts(noto_font)) if not info.use_preferred and subfamily_parts not in [['Regular'], [ 'Bold' ], ['Italic'], ['Bold', 'Italic']]: print >> sys.stderr, ( 'Error in family name info: %s requires preferred names, but info ' 'says none are required.' % path.basename(noto_font.filepath)) print >> sys.stderr, subfamily_parts return None ofn, osfn = _original_names(family_parts, subfamily_parts, info.no_style_linking, info.family_name_style) # If we limit the original names (to put weights into the original family) # then we need a preferred name to undo this. When info is read or generated, # the code should ensure use_preferred is set. pfn, psfn = _preferred_names(family_parts, subfamily_parts, info.use_preferred) if pfn and pfn == ofn: pfn = None if psfn and psfn == osfn: psfn = None return NameTableData(copyright_re=_copyright_re(noto_font), original_family=ofn, original_subfamily=osfn, unique_id='-', full_name=_full_name(family_parts, subfamily_parts, info.omit_regular), version_re=_version_re(noto_font, phase), postscript_name=_postscript_name( family_parts, subfamily_parts, info.omit_regular), trademark=_trademark(noto_font), manufacturer=_manufacturer(noto_font), designer=_designer(noto_font, phase), description_re=_description_re(noto_font, phase), vendor_url=NOTO_URL, designer_url=_designer_url(noto_font), license_text=_license_text(noto_font), license_url=_license_url(noto_font), preferred_family=pfn, preferred_subfamily=psfn, wws_family=None, wws_subfamily=None)
def create_family_to_name_info(notofonts, phase, extra_styles): if phase not in [2, 3]: raise ValueError('expected phase 2 or 3 but got "%s"' % phase) family_to_parts = collections.defaultdict(set) family_to_name_styles = collections.defaultdict(set) cjk_families = set() for noto_font in notofonts: family_id = noto_fonts.noto_font_to_wws_family_id(noto_font) preferred_family, preferred_subfamily = _preferred_parts(noto_font) _, subfamily_parts = _wws_parts(preferred_family, preferred_subfamily) family_to_parts[family_id].update(subfamily_parts) # It's been asserted that the family name can't be longer than 32 chars. # Assume this is only true for nameID 1 and not nameID 16 or 17. family_parts, _ = _original_parts(preferred_family, preferred_subfamily) family_name_style = _name_style_for_length(family_parts, ORIGINAL_FAMILY_LIMIT) family_to_name_styles[family_id].add(family_name_style) if noto_font.is_cjk: cjk_families.add(family_id) # If extra_styles is true, we assume all wws styles are present. The # practical import of this is that use_preferred will be true, and the # family name style will be short enough to accommodate the longest # wws style name. So we just synthesize this and run each font through # one more time with those styles. # For a given wws id the fonts should all be wws variants. Since we # substitute fixed wws values, any font with the same wws id will do. # # This is a kludge, as it duplicates a lot of the above code. if extra_styles: seen_ids = set() for noto_font in notofonts: if noto_font.is_cjk: # Don't do this for cjk continue family_id = noto_fonts.noto_font_to_wws_family_id(noto_font) if family_id in seen_ids: continue seen_ids.add(family_id) preferred_family, _ = _preferred_parts(noto_font) preferred_subfamily = filter( None, [ 'Mono' if noto_font.is_mono else None, 'UI' if noto_font.is_UI else None, 'Display' if noto_font.is_display else None, 'ExtraCondensed', # longest width name 'ExtraLight', # longest weight name 'Italic' ]) # longest slope name _, subfamily_parts = _wws_parts(preferred_family, preferred_subfamily) family_to_parts[family_id].update(subfamily_parts) family_parts, _ = _original_parts(preferred_family, preferred_subfamily) family_name_style = _name_style_for_length(family_parts, ORIGINAL_FAMILY_LIMIT) family_to_name_styles[family_id].add(family_name_style) result = {} for family_id, part_set in family_to_parts.iteritems(): # Even through CJK mono fonts are in their own families and have only # bold and regular weights, they behave like they have more weights like # the rest of CJK. family_is_cjk = family_id in cjk_families no_style_linking = phase == 2 and family_is_cjk use_preferred = no_style_linking or bool(part_set - _ORIGINAL_PARTS) # Keep 'Regular' in the postscript/full name only for CJK in phase 2, # or always if phase 3. include_regular = phase == 3 or family_is_cjk name_style = 'normal' if phase == 2 else _select_name_style( family_to_name_styles[family_id]) result[family_id] = FamilyNameInfo(no_style_linking, use_preferred, include_regular, name_style) return result