def test_split(self): timer = Timer() time.sleep(0.01) fist_lap = timer.split() assert timer.elapsed == fist_lap time.sleep(0.1) second_lap = timer.split() assert second_lap > fist_lap assert timer.elapsed == second_lap
def test_split(self): timer = Timer() time.sleep(0.01) fist_lap = timer.split() assert timer.elapsed == fist_lap time.sleep(0.1) second_lap = timer.split() assert second_lap > fist_lap assert timer.elapsed == second_lap
def main(): t = Timer() parser = ArgumentParser() parser.add_argument("-d", "--directory", default="./", help="Path to directory containing the fonts") parser.add_argument("-o", "--output", default="merged.ttf", help="Path to output file.") parser.add_argument( "-v", "--verbose", action="store_true", help="Verbose mode, printing out more info", ) args = parser.parse_args() logging.basicConfig( level=logging.INFO if args.verbose else logging.WARNING) valid_files = build_valid_filenames(directory=args.directory) if len(valid_files) <= 1: log.warning( "expecting at least two fonts to merge, but only got %d " + "font(s).", len(valid_files), ) sys.exit(-1) for idx, file in enumerate(valid_files): if not has_gsub_table(file): log.info("adding default GSUB table to %s." % file) valid_files[idx] = add_gsub_to_font(file) merger = merge.Merger() print("Merging %d Fonts..." % len(valid_files)) font = merger.merge(valid_files) # Use the line metric in the first font to replace the one in final result. metrics = read_line_metrics(ttLib.TTFont(valid_files[0])) set_line_metrics(font, metrics) font.save(args.output) font.close() print("%d fonts are merged. %d fonts are skipped. Cost %0.3f s." % (len(valid_files), len(files) - len(valid_files), t.time())) print("Please check the result at %s." % os.path.abspath(os.path.realpath(args.output)))
def test_using_logger(self, logger): with Timer(logger, 'do something'): time.sleep(0.01) assert re.match( "Took [0-9]\.[0-9]{3}s to do something", logger.handlers[0].stream.getvalue())
def __call__(self, font, glyphSet=None): """ Run this filter on all the included glyphs. Return the set of glyph names that were modified, if any. If `glyphSet` (dict) argument is provided, run the filter on the glyphs contained therein (which may be copies). Otherwise, run the filter in-place on the font's default glyph set. """ if glyphSet is None: glyphSet = font context = self.set_context(font, glyphSet) filter_ = self.filter include = self.include modified = context.modified with Timer() as t: # we sort the glyph names to make loop deterministic for glyphName in sorted(glyphSet.keys()): if glyphName in modified: continue glyph = glyphSet[glyphName] if include(glyph) and filter_(glyph): modified.add(glyphName) num = len(modified) if num > 0: logger.debug("Took %.3fs to run %s on %d glyph%s", t, self.name, len(modified), "" if num == 1 else "s") return modified
def main(): t = Timer() parser = ArgumentParser() parser.add_argument('-f', '--files', help='Path to YAML file containing paths to the fonts') parser.add_argument('-o', '--output', default='merged.ttf', help='Path to output file.') parser.add_argument('-v', '--verbose', action='store_true', help='Verbose mode, printing out more info') args = parser.parse_args() logging.basicConfig(level=logging.INFO if args.verbose else logging.WARNING) if not args.files: print('add -h for usage') sys.exit(2) with open(args.files, 'r') as stream: try: valid_files = yaml.safe_load(stream) except yaml.YAMLError as exc: print(exc) if len(valid_files) <= 1: log.warn('expecting at least two fonts to merge, but only got %d ' + 'font(s).', len(valid_files)) sys.exit(-1) for idx, file in enumerate(valid_files): if not has_gsub_table(file): log.info('adding default GSUB table to %s.' % file) valid_files[idx] = add_gsub_to_font(file) merger = merge.Merger() print('Merging %d Fonts...' % len(valid_files)) font = merger.merge(valid_files) # Use the line metric in the first font to replace the one in final result. metrics = read_line_metrics(ttLib.TTFont(valid_files[0])) set_line_metrics(font, metrics) font.save(args.output) font.close() print('%d fonts are merged. Cost %0.3f s.' % (len(valid_files), t.time())) print('Please check the result at %s.' % os.path.abspath( os.path.realpath(args.output)))
def main(newName, files): t = Timer() parser = ArgumentParser() parser.add_argument('-d', '--directory', default='./', help='Path to directory containing the fonts') # parser.add_argument('-o', '--output', default='merged.ttf', # help='Path to output file.') parser.add_argument('-v', '--verbose', action='store_true', help='Verbose mode, printing out more info') args = parser.parse_args() logging.basicConfig( level=logging.INFO if args.verbose else logging.WARNING) valid_files = build_valid_filenames(files=files, directory=args.directory) if len(valid_files) <= 1: log.warning( 'expecting at least two fonts to merge, but only got %d ' + 'font(s).', len(valid_files)) # sys.exit(-1) return for idx, file in enumerate(valid_files): if not has_gsub_table(file): log.info('adding default GSUB table to %s.' % file) valid_files[idx] = add_gsub_to_font(file) merger = merge.Merger() print('Merging %d Fonts...' % len(valid_files)) font = merger.merge(valid_files) # Use the line metric in the first font to replace the one in final result. metrics = read_line_metrics(ttLib.TTFont(valid_files[0])) set_line_metrics(font, metrics) # print(os.path.basename(valid_files[0])) font.save(newName) font.close() print('%d fonts are merged. %d fonts are skipped. Cost %0.3f s.' % (len(valid_files), len(files) - len(valid_files), t.time())) print('Please check the result at %s.' % os.path.abspath(os.path.realpath(newName)))
def test_using_logger_calling_instance(self, logger): timer = Timer(logger) with timer(): time.sleep(0.01) assert re.match(r"elapsed time: [0-9]\.[0-9]{3}s", logger.handlers[0].stream.getvalue()) # do it again but with custom level with timer('redo it', level=logging.WARNING): time.sleep(0.02) assert re.search(r"WARNING: Took [0-9]\.[0-9]{3}s to redo it", logger.handlers[0].stream.getvalue())
def test_function_decorator(self, logger): timer = Timer(logger) @timer() def test1(): time.sleep(0.01) @timer('run test 2', level=logging.INFO) def test2(): time.sleep(0.02) test1() assert re.match(r"Took [0-9]\.[0-9]{3}s to run 'test1'", logger.handlers[0].stream.getvalue()) test2() assert re.search(r"Took [0-9]\.[0-9]{3}s to run test 2", logger.handlers[0].stream.getvalue())
def main(): t = Timer() parser = ArgumentParser() parser.add_argument('-d', '--directory', default='./', help='Path to directory containing the fonts') parser.add_argument('-o', '--output', default='merged.ttf', help='Path to output file.') parser.add_argument('-v', '--verbose', action='store_true', help='Verbose mode, printing out more info') args = parser.parse_args() logging.basicConfig(level=logging.INFO if args.verbose else logging.WARNING) valid_files = build_valid_filenames(directory=args.directory) if len(valid_files) <= 1: log.warn('expecting at least two fonts to merge, but only got %d ' + 'font(s).', len(valid_files)) sys.exit(-1) for idx, file in enumerate(valid_files): if not has_gsub_table(file): log.info('adding default GSUB table to %s.' % file) valid_files[idx] = add_gsub_to_font(file) merger = merge.Merger() print('Merging %d Fonts...' % len(valid_files)) font = merger.merge(valid_files) # Use the line metric in the first font to replace the one in final result. metrics = read_line_metrics(ttLib.TTFont(valid_files[0])) set_line_metrics(font, metrics) font.save(args.output) font.close() print('%d fonts are merged. %d fonts are skipped. Cost %0.3f s.' % (len(valid_files), len(files) - len(valid_files), t.time())) print('Please check the result at %s.' % os.path.abspath( os.path.realpath(args.output)))
def test_time(self): timer = Timer() time.sleep(0.01) overall_time = timer.time() assert overall_time > 0
Use value 1 to perform operation serially. Usage (command line): From the command line, you can either run the package as a module, $ python -m compreffor --help Or call the `compreffor` console script installed with the package. Use -h/--help to list all the available options. """ import logging from fontTools.misc.loggingTools import Timer log = logging.getLogger(__name__) timer = Timer(logger=logging.getLogger(log.name + ".timer")) from compreffor import cxxCompressor, pyCompressor __version__ = "0.4.6" def compress(ttFont, method_python=False, **options): """ Subroutinize TTFont instance in-place using the C++ Compreffor. If 'method_python' is True, use the slower, pure-Python Compreffor. If the font already contains subroutines, it is first decompressed. """ if has_subrs(ttFont): log.warning("There are subroutines in font; must decompress it first") decompress(ttFont) if method_python:
from fontTools.misc.py23 import * from fontTools.misc.timeTools import timestampNow from fontTools import ttLib, cffLib from fontTools.ttLib.tables import otTables, _h_e_a_d from fontTools.ttLib.tables.DefaultTable import DefaultTable from fontTools.misc.loggingTools import Timer from fontTools.pens.recordingPen import DecomposingRecordingPen from functools import reduce import sys import time import operator import logging log = logging.getLogger("fontTools.merge") timer = Timer(logger=logging.getLogger(__name__+".timer"), level=logging.INFO) def _add_method(*clazzes, **kwargs): """Returns a decorator function that adds a new method to one or more classes.""" allowDefault = kwargs.get('allowDefaultTable', False) def wrapper(method): done = [] for clazz in clazzes: if clazz in done: continue # Support multiple names of a clazz done.append(clazz) assert allowDefault or clazz != DefaultTable, 'Oops, table class not found.' assert method.__name__ not in clazz.__dict__, \ "Oops, class '%s' has method '%s'." % (clazz.__name__, method.__name__) setattr(clazz, method.__name__, method)
from fontTools import designspaceLib from fontTools.misc.loggingTools import Timer, configLogger from fontTools.misc.plistlib import load as readPlist from fontTools.ttLib import TTFont from fontTools.varLib.interpolate_layout import interpolate_layout from ufo2ft import CFFOptimization from ufo2ft.featureCompiler import parseLayoutFeatures from ufo2ft.featureWriters import FEATURE_WRITERS_KEY, loadFeatureWriters from ufo2ft.util import makeOfficialGlyphOrder from fontmake import instantiator from fontmake.errors import FontmakeError, TTFAError from fontmake.ttfautohint import ttfautohint logger = logging.getLogger(__name__) timer = Timer(logging.getLogger("fontmake.timer"), level=logging.DEBUG) PUBLIC_PREFIX = "public." GLYPHS_PREFIX = "com.schriftgestaltung." # for glyphsLib < 2.3.0 KEEP_GLYPHS_OLD_KEY = GLYPHS_PREFIX + "Keep Glyphs" # for glyphsLib >= 2.3.0 KEEP_GLYPHS_NEW_KEY = ( GLYPHS_PREFIX + "customParameter.InstanceDescriptorAsGSInstance.Keep Glyphs") GLYPH_EXPORT_KEY = GLYPHS_PREFIX + "Glyphs.Export" INTERPOLATABLE_OUTPUTS = frozenset( ["ttf-interpolatable", "otf-interpolatable", "variable", "variable-cff2"])
from fontTools.misc.py23 import tobytes, basestring from fontTools.misc.loggingTools import configLogger, Timer from fontTools.misc.transform import Transform from fontTools.pens.transformPen import TransformPen from fontTools.ttLib import TTFont from fontTools import varLib from fontTools.varLib.interpolate_layout import interpolate_layout from ufo2ft import compileOTF, compileTTF from ufo2ft.featureCompiler import FeatureCompiler from ufo2ft.kernFeatureWriter import KernFeatureWriter from ufo2ft.markFeatureWriter import MarkFeatureWriter from fontmake.ttfautohint import ttfautohint logger = logging.getLogger(__name__) timer = Timer(logging.getLogger('fontmake.timer'), level=logging.DEBUG) PUBLIC_PREFIX = 'public.' GLYPHS_PREFIX = 'com.schriftgestaltung.' class FontProject(object): """Provides methods for building fonts.""" def __init__(self, timing=False, verbose='INFO'): logging.basicConfig(level=getattr(logging, verbose.upper())) logging.getLogger('fontTools.subset').setLevel(logging.WARNING) if timing: configLogger(logger=timer.logger, level=logging.DEBUG) @timer() def build_master_ufos(self,
def test_context_manager(self): with Timer() as t: time.sleep(0.01) assert t.elapsed > 0
def test_time(self): timer = Timer() time.sleep(0.01) overall_time = timer.time() assert overall_time > 0