Example #1
0
def report_set_differences(name_to_cpset, out=sys.stderr):
    """Report differences, assuming they are small."""

    # this does ok with 2 or 3 highly overlapping sets, but it will
    # be unintelligible in other cases.

    additional = ''
    while len(name_to_cpset):
        common = None
        if len(name_to_cpset) > 1:
            for name, cpset in name_to_cpset.iteritems():
                if common == None:
                    common = cpset.copy()
                else:
                    common &= cpset
        if common:
            name = ', '.join(sorted(name_to_cpset))
            print >> out, '%d%s in common among %s:' % (len(common),
                                                        additional, name)
            print >> out, lint_config.write_int_ranges(common)

            for name, cpset in sorted(name_to_cpset.iteritems()):
                extra = cpset - common
                if extra:
                    name_to_cpset[name] = extra
                else:
                    print >> out, '%s has no additional' % name
                    del name_to_cpset[name]
            additional = ' additional'
            continue

        for name, cpset in sorted(name_to_cpset.iteritems()):
            print >> out, '%s has %d%s:' % (name, len(cpset), additional)
            print >> out, lint_config.write_int_ranges(cpset)
        break
Example #2
0
def report_compare(compare_result, detailed=True):
  compare, base_cmap_data, target_cmap_data = compare_result
  base_map = cmap_data.create_map_from_table(base_cmap_data.table)
  target_map = cmap_data.create_map_from_table(target_cmap_data.table)

  inverted_target = collections.defaultdict(set)
  for script, row in target_map.iteritems():
    cps = tool_utils.parse_int_ranges(row.ranges)
    for cp in cps:
      inverted_target[cp].add(script)


  base_title = title_from_metadata(base_cmap_data.meta)
  target_title = title_from_metadata(target_cmap_data.meta)

  print 'base: %s' % base_title
  print 'target: %s' % target_title
  for script in sorted(compare):
    added, removed = compare[script]
    if added or removed:
      name = base_map[script].name
      print '%s # %s' % (script, name)
      if added:
        print '  added (%d): %s' % (
            len(added), lint_config.write_int_ranges(added))
        if detailed:
          _print_detailed(added)
      if removed:
        print '  removed (%d): %s' % (
            len(removed), lint_config.write_int_ranges(removed))
        if detailed:
          _print_detailed(removed, inverted_target)
Example #3
0
def report_set_differences(name_to_cpset, out=sys.stderr):
  """Report differences, assuming they are small."""

  # this does ok with 2 or 3 highly overlapping sets, but it will
  # be unintelligible in other cases.

  additional = ''
  while len(name_to_cpset):
    common = None
    if len(name_to_cpset) > 1:
      for name, cpset in name_to_cpset.iteritems():
        if common == None:
          common = cpset.copy()
        else:
          common &= cpset
    if common:
      name = ', '.join(sorted(name_to_cpset))
      print >> out, '%d%s in common among %s:' % (
          len(common), additional, name)
      print >> out, lint_config.write_int_ranges(common)

      for name, cpset in sorted(name_to_cpset.iteritems()):
        extra = cpset - common
        if extra:
          name_to_cpset[name] = extra
        else:
          print >> out, '%s has no additional' % name
          del name_to_cpset[name]
      additional = ' additional'
      continue

    for name, cpset in sorted(name_to_cpset.iteritems()):
      print >> out, '%s has %d%s:' % (name, len(cpset), additional)
      print >> out, lint_config.write_int_ranges(cpset)
    break
Example #4
0
def report_set_differences(name_to_cpset, out=sys.stderr):
    """Report differences, assuming they are small."""

    # this does ok with 2 or 3 highly overlapping sets, but it will
    # be unintelligible in other cases.

    additional = ""
    while len(name_to_cpset):
        common = None
        if len(name_to_cpset) > 1:
            for name, cpset in name_to_cpset.items():
                if common is None:
                    common = cpset.copy()
                else:
                    common &= cpset
        if common:
            name = ", ".join(sorted(name_to_cpset))
            out.write("%d%s in common among %s:\n" % (len(common), additional, name))
            out.write("%s\n" % lint_config.write_int_ranges(common))

            for name, cpset in sorted(name_to_cpset.items()):
                extra = cpset - common
                if extra:
                    name_to_cpset[name] = extra
                else:
                    out.write("%s has no additional\n" % name)
                    del name_to_cpset[name]
            additional = " additional"
            continue

        for name, cpset in sorted(name_to_cpset.items()):
            out.write("%s has %d%s:\n" % (name, len(cpset), additional))
            out.write("%s\n" % lint_config.write_int_ranges(cpset))
        break
Example #5
0
def report_compare(compare_result, detailed=True):
  compare, base_cmap_data, target_cmap_data = compare_result
  base_map = cmap_data.create_map_from_table(base_cmap_data.table)
  target_map = cmap_data.create_map_from_table(target_cmap_data.table)

  base_title = title_from_metadata(base_cmap_data.meta)
  target_title = title_from_metadata(target_cmap_data.meta)

  print 'base: %s' % base_title
  print 'target: %s' % target_title
  for script in sorted(compare):
    added, removed = compare[script]
    if added or removed:
      name = base_map[script].name
      print '%s # %s' % (script, name)
      if added:
        print '  added (%d): %s' % (
            len(added), lint_config.write_int_ranges(added))
        if detailed:
          for cp in sorted(added):
            print '    %6s %s' % (
                '%04x' % cp, unicode_data.name(cp, ''))
      if removed:
        print '  removed (%d): %s' % (
            len(removed), lint_config.write_int_ranges(removed))
        if detailed:
          for cp in sorted(removed):
            print '    %6s %s' % (
                '%04x' % cp, unicode_data.name(cp, ''))
 def report_cps(label, cps, inverted=None):
   if not cps:
     return
   print '  %s (%d): %s' % (
       label, len(cps), lint_config.write_int_ranges(cps))
   if detailed:
     _print_detailed(cps, inverted)
Example #7
0
 def report_cps(label, cps, inverted=None):
     if not cps:
         return
     print('  %s (%d): %s' %
           (label, len(cps), lint_config.write_int_ranges(cps)))
     if detailed:
         _print_detailed(cps, inverted)
Example #8
0
def _process_font(filepath, args):
  sorted_chars = sorted(character_set(filepath))
  if args.info:
    _print_char_info(sorted_chars)
  if args.text:
    _write_char_text(sorted_chars, filepath, args.chars_per_line)
  if args.ranges:
    print 'ranges:\n  ' + lint_config.write_int_ranges(sorted_chars, True)
Example #9
0
 def report_data_error(index, script_data):
     sys.stderr.write(
         "  %d: %s, %d, %s\n"
         % (
             index,
             script_data.family_name,
             script_data.script,
             len(script_data.cpset),
             lint_config.write_int_ranges(script_data.cpset),
         )
     )
Example #10
0
def _process_font(filepath, args):
  char_set = character_set(filepath)
  if args.limit_set:
    char_set = char_set & args.limit_set
    if not char_set:
      print('limit excludes all chars in %s' % filepath)
      return
  sorted_chars = sorted(char_set)
  if args.info:
    _print_char_info(sorted_chars)
  if args.text:
    _write_char_text(sorted_chars, filepath, args.chars_per_line, args.sep)
  if args.ranges:
    print('ranges:\n  ' + lint_config.write_int_ranges(sorted_chars, True))
Example #11
0
def _process_font(filepath, args):
  char_set = character_set(filepath)
  if args.limit_set:
    char_set = char_set & args.limit_set
    if not char_set:
      print 'limit excludes all chars in %s' % filepath
      return
  sorted_chars = sorted(char_set)
  if args.info:
    _print_char_info(sorted_chars)
  if args.text:
    _write_char_text(sorted_chars, filepath, args.chars_per_line, args.sep)
  if args.ranges:
    print 'ranges:\n  ' + lint_config.write_int_ranges(sorted_chars, True)
Example #12
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("files",
                        help="Files to dump",
                        metavar="file",
                        nargs="+")
    parser.add_argument("--ranges",
                        help="Dump cmap as hex ranges",
                        action="store_true")
    parser.add_argument("--text",
                        help="Dump cmap as sample text",
                        action="store_true")
    parser.add_argument("--sep",
                        help="Separator between chars in text, default space",
                        default=" ")
    parser.add_argument(
        "--info",
        help="Dump cmap as cp and unicode name, one per line",
        action="store_true",
    )
    parser.add_argument(
        "--chars_per_line",
        help="Format text in lines of at most this "
        "many codepoints,  0 to format as a single line",
        type=int,
        metavar="N",
        default=32,
    )
    parser.add_argument(
        "--limit",
        help="string of hex codepoint ranges limiting cmap "
        "to output",
        metavar="ranges",
    )
    args = parser.parse_args()

    if not (args.ranges or args.text or args.info):
        args.info = True

    if args.limit:
        args.limit_set = lint_config.parse_int_ranges(args.limit)
        print("limit to: " + lint_config.write_int_ranges(args.limit_set))
    else:
        # make sure it exists so checks don't have to care
        args.limit_set = None

    for fontpath in args.files:
        print("Font: " + path.normpath(fontpath))
        _process_font(fontpath, args)
Example #13
0
def create_table_from_map(script_to_cmap):
  """Create a table from a map from script to cmaps.  Outputs
  the script code, script name, count of code points, and the
  codepoint ranges in hex separated by space."""
  table_header = 'script,name,count,ranges'.split(',')
  RowData = collections.namedtuple('RowData', table_header)

  table_rows = []
  for script in sorted(script_to_cmap):
    cmap = script_to_cmap.get(script)
    name = noto_fonts.script_name_for_report(script)
    count = len(cmap)
    cp_ranges = lint_config.write_int_ranges(cmap)
    table_rows.append(RowData(script, name, str(count), cp_ranges))
  return TableData(table_header, table_rows)
Example #14
0
def create_table_from_map(script_to_cmap):
  """Create a table from a map from script to cmaps.  Outputs
  the script code, script name, count of code points, and the
  codepoint ranges in hex separated by space."""
  table_header = 'script,name,count,ranges'.split(',')
  RowData = collections.namedtuple('RowData', table_header)

  table_rows = []
  for script in sorted(script_to_cmap):
    cmap = script_to_cmap.get(script)
    name = noto_lint.script_name_for_report(script)
    count = len(cmap)
    cp_ranges = lint_config.write_int_ranges(cmap)
    table_rows.append(RowData(script, name, str(count), cp_ranges))
  return TableData(table_header, table_rows)
Example #15
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('files',
                        help='Files to dump',
                        metavar='file',
                        nargs='+')
    parser.add_argument('--ranges',
                        help='Dump cmap as hex ranges',
                        action='store_true')
    parser.add_argument('--text',
                        help='Dump cmap as sample text',
                        action='store_true')
    parser.add_argument('--sep',
                        help='Separator between chars in text, default space',
                        default=' ')
    parser.add_argument('--info',
                        help='Dump cmap as cp and unicode name, one per line',
                        action='store_true')
    parser.add_argument('--chars_per_line',
                        help='Format text in lines of at most this '
                        'many codepoints,  0 to format as a single line',
                        type=int,
                        metavar='N',
                        default=32)
    parser.add_argument('--limit',
                        help='string of hex codepoint ranges limiting cmap '
                        'to output',
                        metavar='ranges')
    args = parser.parse_args()

    if not (args.ranges or args.text or args.info):
        args.info = True

    if args.limit:
        args.limit_set = lint_config.parse_int_ranges(args.limit)
        print 'limit to: ' + lint_config.write_int_ranges(args.limit_set)
    else:
        # make sure it exists so checks don't have to care
        args.limit_set = None

    for fontpath in args.files:
        print 'Font: ' + path.normpath(fontpath)
        _process_font(fontpath, args)
Example #16
0
def main():
  parser = argparse.ArgumentParser()
  parser.add_argument('files', help='Files to dump', metavar='file', nargs='+')
  parser.add_argument('--ranges',
                      help='Dump cmap as hex ranges',
                      action='store_true')
  parser.add_argument('--text',
                      help='Dump cmap as sample text',
                      action='store_true')
  parser.add_argument('--sep',
                      help='Separator between chars in text, default space',
                      default=' ')
  parser.add_argument('--info',
                      help='Dump cmap as cp and unicode name, one per line',
                      action='store_true')
  parser.add_argument('--chars_per_line',
                      help='Format text in lines of at most this '
                      'many codepoints,  0 to format as a single line',
                      type=int,
                      metavar='N',
                      default=32)
  parser.add_argument('--limit',
                      help='string of hex codepoint ranges limiting cmap '
                      'to output',
                      metavar='ranges')
  args = parser.parse_args()

  if not (args.ranges or args.text or args.info):
    args.info = True

  if args.limit:
    args.limit_set = lint_config.parse_int_ranges(args.limit)
    print 'limit to: ' + lint_config.write_int_ranges(args.limit_set)
  else:
    # make sure it exists so checks don't have to care
    args.limit_set = None

  for fontpath in args.files:
    print 'Font: ' + path.normpath(fontpath)
    _process_font(fontpath, args)
Example #17
0
 def report_data_error(index, script_data):
   print >> sys.stderr, '  %d: %s, %d, %s' % (
       index, script_data.family_name, script_data.script,
       len(script_data.cpset),
       lint_config.write_int_ranges(script_data.cpset))
Example #18
0
 def report_data_error(index, script_data):
     print >> sys.stderr, '  %d: %s, %d, %s' % (
         index, script_data.family_name, script_data.script,
         len(script_data.cpset),
         lint_config.write_int_ranges(script_data.cpset))