def test_check_nbsp_width_matches_sp_width(self): """ Check non-breaking space's advancewidth is the same as space """ checker = NbspAndSpaceSameWidth(self, self.operator.path) space = checker.getGlyph(0x0020) nbsp = checker.getGlyph(0x00A0) self.assertTrue(space, "Font does not contain a space glyph") self.assertTrue(nbsp, "Font does not contain a nbsp glyph") spaceWidth = checker.getWidth(space) nbspWidth = checker.getWidth(nbsp) self.assertEqual(spaceWidth, nbspWidth, ("The nbsp advance width does not match " "the space advance width"))
def test_check_nbsp_width_matches_sp_width(self): """ Check non-breaking space's advancewidth is the same as space """ checker = NbspAndSpaceSameWidth(self, self.operator.path) space = checker.getGlyph(0x0020) nbsp = checker.getGlyph(0x00A0) tab = checker.getGlyph(0x0009) self.assertTrue(space, "Font does not contain a space glyph") self.assertTrue(nbsp, "Font does not contain a nbsp glyph") self.assertTrue(tab, "Font does not contain a tab glyph") spaceWidth = checker.getWidth(space) nbspWidth = checker.getWidth(nbsp) tabWidth = checker.getWidth(tab) self.assertEqual(spaceWidth, nbspWidth, ("The nbsp advance width does not match " "the space advance width")) self.assertEqual(spaceWidth, tabWidth, ("The tab advance width does not match " "the space advance width"))
from bakery_cli.logger import logger from bakery_cli.fixers import NbspAndSpaceSameWidth description = ('Fixes TTF non-breaking-space glyph to exist' ' with same advanceWidth as space') parser = argparse.ArgumentParser(description=description) parser.add_argument('ttf_font', nargs='+', help='Font in OpenType (TTF/OTF) format') parser.add_argument('--autofix', action='store_true', help='Apply autofix') parser.add_argument('--verbose', action='store_true', help='Print output in verbose') args = parser.parse_args() if args.verbose: logger.setLevel(logging.INFO) for path in args.ttf_font: if not os.path.exists(path): continue fixer = NbspAndSpaceSameWidth(None, path) if args.autofix: fixer.apply() else: fixer.fix(check=True) # this will print only
# for all fonts found in a directory tree, using fontTools import argparse import os from bakery_cli.bakery import Bakery from bakery_cli.fixers import NbspAndSpaceSameWidth description = ('Fixes TTF non-breaking-space glyph to exist' ' with same advanceWidth as space') parser = argparse.ArgumentParser(description=description) parser.add_argument('ttf_font', nargs='+', help='Font in OpenType (TTF/OTF) format') parser.add_argument('--autofix', action='store_true', help='Apply autofix') parser.add_argument('--verbose', action='store_true', help='Print output in verbose') args = parser.parse_args() Bakery.verbose = args.verbose for path in args.ttf_font: if not os.path.exists(path): continue fixer = NbspAndSpaceSameWidth(None, path) if args.autofix: fixer.apply() else: fixer.fix(check=True) # this will print only