Hello community, here is the log from the commit of package ttf-converter for openSUSE:Factory checked in at 2020-07-03 00:00:20 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ttf-converter (Old) and /work/SRC/openSUSE:Factory/.ttf-converter.new.3060 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ttf-converter" Fri Jul 3 00:00:20 2020 rev:3 rq:818036 version:1.0.6 Changes: -------- --- /work/SRC/openSUSE:Factory/ttf-converter/ttf-converter.changes 2020-06-23 20:59:50.748915770 +0200 +++ /work/SRC/openSUSE:Factory/.ttf-converter.new.3060/ttf-converter.changes 2020-07-03 00:01:12.173839701 +0200 @@ -1,0 +2,38 @@ +Tue Jun 30 17:35:53 UTC 2020 - alarr...@suse.com + +- Update to version 1.0.6: + * Standarize output when converting vector and bitmap fonts + * Add more subfamilies fixes (boo#1169444) + +------------------------------------------------------------------- +Mon Jun 29 12:09:28 UTC 2020 - Antonio Larrosa <alarr...@suse.com> + +- Update to version 1.0.5: + * Add --family and --subfamily arguments to force values on those + fields + * Add parameters to fix glyph unicode values + --fix-glyph-unicode : Try to fix unicode points and glyph names + based on glyph names containing hexadecimal codes (like + "$0C00", "char12345" or "uni004F") + --replace-unicode-values: When passed 2 comma separated numbers + a,b the glyph with an unicode value of a is replaced with the + unicode value b. Can be used more than once. + --shift-unicode-values: When passed 3 comma separated numbers + a,b,c this shifts the unicode values of glyphs between a and b + (both included) by adding c. Can be used more than once. + * Add --bitmapTransform parameter to transform bitmap glyphs. When + used, all glyphs are modified with the transformation function and + values passed as parameters. The parameter has three values + separated by commas: fliph|flipv|rotate90cw|rotate90ccw| + rotate180|skew|transmove,xoff,yoff + (boo#1169444) + +------------------------------------------------------------------- +Thu Jun 25 10:38:37 UTC 2020 - alarr...@suse.com + +- Update to version 1.0.4: + * Add support to convert bitmap fonts (boo#1169444) + * Rename MediumItalic subfamily to Medium Italic + * Show some more information when removing duplicated glyphs + +------------------------------------------------------------------- Old: ---- ttf-converter-1.0.3.tar.xz New: ---- ttf-converter-1.0.6.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ttf-converter.spec ++++++ --- /var/tmp/diff_new_pack.kWgW2Q/_old 2020-07-03 00:01:15.073849303 +0200 +++ /var/tmp/diff_new_pack.kWgW2Q/_new 2020-07-03 00:01:15.073849303 +0200 @@ -17,7 +17,7 @@ Name: ttf-converter -Version: 1.0.3 +Version: 1.0.6 Release: 0 Summary: Python script that converts fonts to TrueType format License: GPL-3.0-only @@ -25,6 +25,7 @@ Source: ttf-converter-%{version}.tar.xz BuildRequires: python3 Requires: fontforge +Requires: ftdump Requires: python3-base BuildArch: noarch ++++++ _service ++++++ --- /var/tmp/diff_new_pack.kWgW2Q/_old 2020-07-03 00:01:15.105849409 +0200 +++ /var/tmp/diff_new_pack.kWgW2Q/_new 2020-07-03 00:01:15.105849409 +0200 @@ -2,7 +2,8 @@ <service name="tar_scm" mode="disabled"> <param name="url">https://github.com/antlarr-suse/ttf-converter</param> <param name="filename">ttf-converter</param> - <param name="version">1.0.3</param> + <param name="version">1.0.6</param> + <param name="revision">1.0.6</param> <param name="scm">git</param> <param name="changesgenerate">enable</param> </service> ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.kWgW2Q/_old 2020-07-03 00:01:15.129849489 +0200 +++ /var/tmp/diff_new_pack.kWgW2Q/_new 2020-07-03 00:01:15.133849502 +0200 @@ -1,4 +1,4 @@ <servicedata> <service name="tar_scm"> <param name="url">https://github.com/antlarr-suse/ttf-converter</param> - <param name="changesrevision">6ec51ca498265a020d1d66f1e7b1ba32b9ee4ea7</param></service></servicedata> \ No newline at end of file + <param name="changesrevision">30c9627432c2ded1ab65bc3c4c022476edfabfa7</param></service></servicedata> \ No newline at end of file ++++++ ttf-converter-1.0.3.tar.xz -> ttf-converter-1.0.6.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ttf-converter-1.0.3/ttf-converter new/ttf-converter-1.0.6/ttf-converter --- old/ttf-converter-1.0.3/ttf-converter 2020-06-22 11:52:52.000000000 +0200 +++ new/ttf-converter-1.0.6/ttf-converter 2020-06-30 19:29:39.000000000 +0200 @@ -25,6 +25,10 @@ import math import psMat from glob import glob +import subprocess +import tempfile +import gzip +import unicodedata class SkipFont(Exception): @@ -47,7 +51,7 @@ seen[glyph.unicode] = (idx, glyph.glyphname) for glyph in glyphs_to_remove: - print(f'Removing glyph {glyph.glyphname}') + print(f'Removing glyph {glyph.glyphname} {hex(glyph.unicode)}') font.removeGlyph(glyph) @@ -128,7 +132,7 @@ return True -def fix_subfamily(font): +def fix_subfamily(font, force_subfamily=None): sfnt_names = list(font.sfnt_names) subfamily_index = [x[1] for x in sfnt_names].index('SubFamily') translations = {'BoldCond': 'Bold Condensed', @@ -140,20 +144,27 @@ 'DemiObli': 'Demi Oblique', 'DemiBold': 'Demi Bold', 'DemiBoldItal': 'Demi Bold Italic', + 'DemiBoldItalic': 'Demi Bold Italic', 'LighItal': 'Light Italic', 'MediItal': 'Medium Italic', + 'MediumItalic': 'Medium Italic', + 'MediumOblique': 'Medium Oblique', 'ReguCond': 'Regular Condensed', 'ReguCondItal': 'Regular Condensed Italic', 'ReguItal': 'Regular Italic', 'ReguObli': 'Regular Oblique', + 'RegularItalic': 'Regular Italic', 'StandardSymL': 'Regular'} # The last one is for the Standard Symbols L font - try: - new_value = translations[sfnt_names[subfamily_index][2]] - except KeyError: - # Nothing to fix - return + if force_subfamily: + new_value = force_subfamily + else: + try: + new_value = translations[sfnt_names[subfamily_index][2]] + except KeyError: + # Nothing to fix + return print(f'Fixing subfamily: Renaming {sfnt_names[subfamily_index][2]} ' f'to {new_value}.') @@ -211,10 +222,37 @@ print(f'{glyph.width}... done') +def fix_glyph_data(font, shift_unicode_values=[], replace_unicode_values={}): + for idx, glyph in enumerate(font.glyphs()): + shift = [x[2] for x in shift_unicode_values + if x[0] <= glyph.unicode <= x[1]] + if glyph.unicode in replace_unicode_values: + corrected_unicode = replace_unicode_values[glyph.unicode] + elif shift: + corrected_unicode = glyph.unicode + shift[0] + elif glyph.glyphname.startswith('$'): + corrected_unicode = int(glyph.glyphname[1:], 16) + elif glyph.glyphname.startswith('char'): + corrected_unicode = int(glyph.glyphname[4:]) + elif glyph.glyphname.startswith('uni'): + corrected_unicode = int(glyph.glyphname[3:],16) + else: + continue + + glyph.unicode = corrected_unicode + try: + glyph.glyphname = unicodedata.name(chr(glyph.unicode)) + except ValueError: + print(f'No unicode character name for {glyph.unicode}') + def convert_font(input_filename, output_filename=None, output_dir='.', - force_monospaced=False): + force_monospaced=False, + force_family=None, force_subfamily=None): font = fontforge.open(input_filename) + if force_family: + font.fontname = force_family + if not output_filename: output_filename = font.fontname + '.ttf' @@ -225,7 +263,7 @@ fix_font(font) - fix_subfamily(font) + fix_subfamily(font, force_subfamily) if force_monospaced: force_monospaced_font(font) @@ -241,12 +279,112 @@ return glob(os.path.join(directory, '*.pf[ab]')) +def convert_vector_fonts(input_files, args): + skipped_filenames = [] + for input_file in sorted(input_files): + print('--------') + try: + convert_font(input_file, + output_dir=args.output_dir, + force_monospaced=args.force_monospaced) + except SkipFont: + print(f'Skipping font {input_file}') + skipped_filenames.append(input_file) + + if skipped_filenames: + print('--------') + print('Files that were not converted:') + for filename in skipped_filenames: + print(filename) + + +# get font family name and style name by ftdump +def get_font_fullname(filename): + output = subprocess.check_output('ftdump ' + filename, shell=True) + + output = output.decode('utf8') + # only contain one font face + assert 'Face number: 1' not in output + result = {} + for row in output.split('\n'): + if ':' in row: + key, value = row.split(': ') + result[key.strip()] = value.strip() + + familyname, stylename = result['family'], result['style'] + return (familyname, stylename) + + +def bitmap_transform_font(font, arguments): + funcname, xoff, yoff = arguments.split(',') + xoff, yoff = int(xoff), int(yoff) + + if not getattr(font, 'bitmapTransform', None): + raise RuntimeError('Please, patch your fontforge build to add the ' + 'bitmapTransform function if you want to use it') + font.bitmapTransform(funcname, xoff, yoff) + + +def convert_bitmap_fonts(input_files, args): + font_filenames = {} + output_dir = args.output_dir + + for filename in input_files: + if '-ISO8859-' in filename or '-KOI8-' in filename: + continue + fullname = get_font_fullname(filename) + font_filenames.setdefault(fullname, []).append(filename) + + for familyandstyle, filenames in font_filenames.items(): + familyname, stylename = familyandstyle + if args.family: + familyname = args.family + if args.subfamily: + stylename = args.subfamily + fullname = f'{familyname} {stylename}' + font = fontforge.open(filenames[0]) + for filename in filenames[1:]: + if filename.endswith('.gz'): + with tempfile.NamedTemporaryFile(suffix='.pcf') as tmpfile: + gzipfile = gzip.open(filename) + print(filename, tmpfile.name) + tmpfile.write(gzipfile.read()) + font.importBitmaps(tmpfile.name) + else: + font.importBitmaps(filename) + + if args.bitmapTransform: + bitmap_transform_font(font, args.bitmapTransform) + + font.familyname = familyname + fix_subfamily(font, args.subfamily) + + shift_unicode_values = [[int(z,0) for z in x.split(',')] + for x in args.shift_unicode_values] + replace_unicode_values = dict([[int(z,0) for z in x.split(',')] + for x in args.replace_unicode_values]) + + if args.fix_glyph_unicode or shift_unicode_values or replace_unicode_values: + fix_glyph_data(font, shift_unicode_values, replace_unicode_values) + + output_filename = fullname.replace(' ', '-') + '.otb' + print(f'Converting {" ".join(filenames)} to {output_filename}') + + if output_dir: + output_filename = os.path.join(output_dir, output_filename) + font.generate(output_filename, bitmap_type='otb', flags=("opentype",)) + + def main(): parser = argparse.ArgumentParser(description="This script converts fonts " "to ttf format") parser.add_argument('--input-dir', default=None, help='Read fonts to convert from all *.pf[ab] files ' 'in this directory') + parser.add_argument('--family', default=None, + help='Set family name of the output font') + parser.add_argument('--subfamily', default=None, + help='Set subfamily/style name of the output font') parser.add_argument('--output-dir', default='.', help='Output directory for generated files') parser.add_argument('input_files', nargs='*', default=[], @@ -254,13 +392,40 @@ parser.add_argument('--force-monospaced', action="store_true", help='Force the output font to be monospaced by ' 'resizing glyphs if needed') + + parser.add_argument('--bitmap-fonts', action="store_true", + help='Handle all parameters as bitmap fonts and merge ' + 'different sizes of same families together') + + parser.add_argument('--fix-glyph-unicode', action="store_true", + help='Try to fix unicode points and glyph names based ' + 'on glyph names containing hexadecimal codes') + + parser.add_argument('--replace-unicode-values', action='append', + default=[], + help='When passed 2 comma separated numbers a,b ' + 'the glyph with an unicode value of `a` is replaced ' + 'with the unicode value `b`. ' + 'Can be used more than once') + + parser.add_argument('--shift-unicode-values', action='append', + default=[], + help='When passed 3 comma separated numbers a,b,c ' + 'this shifts the unicode values of glyphs between a ' + 'and b by adding c. Can be used more than once') + + parser.add_argument('--bitmapTransform', default=None, + help='If used, all glyphs are modified with the ' + 'transformation function and values passed as ' + 'parameters (<fliph|flipv|rotate90cw|rotate90ccw|' + 'rotate180|skew|transmove>,<xoff>,<yoff>)') + parser.add_argument('--version', action='version', - version='%(prog)s 1.0.3') + version='%(prog)s 1.0.6') args = parser.parse_args() input_files = set(args.input_files) - force_monospaced = args.force_monospaced if args.input_dir: input_files.update(get_input_files_from_directory(args.input_dir)) @@ -271,22 +436,10 @@ 'is not a directory') sys.exit(1) - skipped_filenames = [] - for input_file in sorted(input_files): - print('--------') - try: - convert_font(input_file, - output_dir=args.output_dir, - force_monospaced=force_monospaced) - except SkipFont: - print(f'Skipping font {input_file}') - skipped_filenames.append(input_file) - - if skipped_filenames: - print('--------') - print('Files that were not converted:') - for filename in skipped_filenames: - print(filename) + if args.bitmap_fonts: + convert_bitmap_fonts(input_files, args) + else: + convert_vector_fonts(input_files, args) if __name__ == '__main__':