def test_finds_all_required_fonts(self): loader = FontLoader(None, True) loader.fonts.append(FontInfo(['Arial'], False, False, FontWeight.FW_NORMAL, 'random', '1')) loader.fonts.append(FontInfo(['Arial Black'], False, False, FontWeight.FW_NORMAL, 'random', '2')) data = {StyleInfo('Arial', 0, False) : UsageData(), StyleInfo('Arial Black', 0, False) : UsageData()} found, not_found = loader.get_fonts_for_list(data) self.assertEqual(2, len(found))
def test_returns_only_appropriate_font(self): loader = FontLoader(None, True) loader.fonts.append(FontInfo(['Arial'], False, False, FontWeight.FW_NORMAL, 'random', '1')) loader.fonts.append(FontInfo(['Arial Black'], False, False, FontWeight.FW_NORMAL, 'random', '2')) data = {StyleInfo('Arial', 0, False) : UsageData()} found, not_found = loader.get_fonts_for_list(data) self.assertEqual(1, len(found))
def test_returns_all_not_found_fonts(self): loader = FontLoader(None, True) data = { StyleInfo('Jorvik', 0, False): UsageData(), StyleInfo('Random font', 0, False): UsageData() } found, not_found = loader.get_fonts_for_list(data) self.assertEqual(2, len(not_found))
def test_returns_all_found_fonts(self): loader = FontLoader([get_file_in_test_directory('')], True) data = { StyleInfo('Jorvik Informal V2', 0, False): UsageData(), StyleInfo('Random font', 0, False): UsageData() } found, not_found = loader.get_fonts_for_list(data) self.assertEqual(1, len(found)) self.assertIn('Jorvik Informal V2', list(found.values())[0].names)
def test_does_not_add_same_font_twice(self): loader = FontLoader( [get_file_in_test_directory(''), get_file_in_test_directory('')], True) data = { StyleInfo('Jorvik', 0, False): UsageData(), StyleInfo('Jorvik informal', 0, False): UsageData() } found, not_found = loader.get_fonts_for_list(data) self.assertEqual(1, len(found))
def test_returns_only_appropriate_font(self): loader = FontLoader(None, True) loader.fonts.append( FontInfo(['Arial'], False, False, FontWeight.FW_NORMAL, 'random', '1')) loader.fonts.append( FontInfo(['Arial Black'], False, False, FontWeight.FW_NORMAL, 'random', '2')) data = {StyleInfo('Arial', 0, False): UsageData()} found, not_found = loader.get_fonts_for_list(data) self.assertEqual(1, len(found))
def test_correctly_finds_yanone_kaffeesatz_bold(self): logging.basicConfig(level=logging.DEBUG) f = TTFFont(get_file_in_test_directory('YanoneKaffeesatz-Bold.otf')) print(f.get_info().weight) f.print_headers() stat = AssParser.get_fonts_statistics(get_file_in_test_directory('3.ass'), True, True) loader = FontLoader([get_file_in_test_directory('')]) found, not_found = loader.get_fonts_for_list(stat) self.assertFalse(not_found) logging.disable(logging.DEBUG)
def test_finds_all_required_fonts(self): loader = FontLoader(None, True) loader.fonts.append( FontInfo(['Arial'], False, False, FontWeight.FW_NORMAL, 'random', '1')) loader.fonts.append( FontInfo(['Arial Black'], False, False, FontWeight.FW_NORMAL, 'random', '2')) data = { StyleInfo('Arial', 0, False): UsageData(), StyleInfo('Arial Black', 0, False): UsageData() } found, not_found = loader.get_fonts_for_list(data) self.assertEqual(2, len(found))
def test_correctly_finds_yanone_kaffeesatz_bold(self): logging.basicConfig(level=logging.DEBUG) f = TTFFont(get_file_in_test_directory('YanoneKaffeesatz-Bold.otf')) print(f.get_info().weight) f.print_headers() stat = AssParser.get_fonts_statistics( get_file_in_test_directory('3.ass'), True, True) loader = FontLoader([get_file_in_test_directory('')]) found, not_found = loader.get_fonts_for_list(stat) self.assertFalse(not_found) logging.disable(logging.DEBUG)
def process(args): config = get_config(args) fonts = AssParser.get_fonts_statistics(os.path.abspath(config['script']), config['exclude_unused_fonts'], config['exclude_comments']) if config['rebuild_cache']: FontLoader.discard_cache() collector = FontLoader(config['font_dirs'], config['include_system_fonts']) found, not_found, paths = collector.get_fonts_for_list(fonts) if len(not_found) != 0: print(file=sys.stderr, *not_found, sep="\n") sys.exit(1) elif len(found) != 0: print(*paths, sep="\n")
def process(args): config = get_config(args) set_logging(config['log_file'], config['verbose']) logging.debug(str(config)) start_time = time() logging.info('-----Started new task at %s-----' % str(ctime())) fonts = AssParser.get_fonts_statistics(os.path.abspath(config['script']), config['exclude_unused_fonts'], config['exclude_comments']) if config['rebuild_cache']: FontLoader.discard_cache() collector = FontLoader(config['font_dirs'], config['include_system_fonts']) found, not_found = collector.get_fonts_for_list(fonts) for font, usage in not_found.items(): text = "Could not find font '%s'" % str(font) if usage.styles: text += '\nUsed in styles %s' % str(usage.styles) if usage.lines: if len(usage.lines) > 50: text += '\nUsed on more than 50 lines' else: text += '\nUsed on lines %s' % str(usage.lines) text += '\n\n' logging.warning(text) logging.info('Total found: %i', len(found)) logging.info('Total not found: %i', len(not_found)) if config['output_location'] is not None: if config['output_location'].endswith('.mks'): create_mks_file(config['mmg'], config['output_location'], config['script'], found.values()) else: copy_fonts_to_folder(config['output_location'], found.values()) logging.debug('Job done in %fs' % round(time() - start_time, 5))
def __init__(self, filepath, orientation="P", layout="letter", font_list=None, font_dir=None): if font_dir is not None: FontLoader.load_from_dir(font_dir) elif font_list is not None: FontLoader.load_from_list(font_list) else: FontLoader.load_fonts() self.filepath = filepath self.destination = None if hasattr(self.filepath, 'write'): self.destination = self.filepath elif self.filepath == 'string': self.destination = 'string' # Create session and document objects self.session = _Session(self) self.document = PDFDocument(self.session, orientation, layout) # Full width display mode default self.set_display_mode() # Set default PDF version number self.pdf_version = '1.7' # Initialize PDF information self.set_information() self.set_compression()
def test_returns_all_not_found_fonts(self): loader = FontLoader(None, True) data = {StyleInfo('Jorvik', 0, False) : UsageData(), StyleInfo('Random font', 0, False) : UsageData()} found, not_found = loader.get_fonts_for_list(data) self.assertEqual(2, len(not_found))
def test_performs_case_insensitive_search(self): loader = FontLoader([get_file_in_test_directory('')], True) data = {StyleInfo('JoRvIk INFormAl v2', 0, False): UsageData()} found, not_found = loader.get_fonts_for_list(data) self.assertEqual(1, len(found))
def test_loads_at_least_some_system_fonts(self): loader = FontLoader(None, True) self.assertTrue(len(loader.fonts) > 0)
def test_does_not_add_same_font_twice(self): loader = FontLoader([get_file_in_test_directory(''), get_file_in_test_directory('')], True) data = {StyleInfo('Jorvik', 0, False) : UsageData(), StyleInfo('Jorvik informal', 0, False) : UsageData()} found, not_found = loader.get_fonts_for_list(data) self.assertEqual(1, len(found))
def test_performs_case_insensitive_search(self): loader = FontLoader([get_file_in_test_directory('')], True) data = {StyleInfo('JoRvIk INFormAl v2', 0, False) : UsageData()} found, not_found = loader.get_fonts_for_list(data) self.assertEqual(1, len(found))
def test_returns_all_found_fonts(self): loader = FontLoader([get_file_in_test_directory('')], True) data = {StyleInfo('Jorvik Informal V2', 0, False) : UsageData(), StyleInfo('Random font', 0, False) : UsageData()} found, not_found = loader.get_fonts_for_list(data) self.assertEqual(1, len(found)) self.assertIn('Jorvik Informal V2', list(found.values())[0].names)