示例#1
0
 def test_does_not_include_new_lines(self):
     styles = {"style": StyleInfo("Font", FontWeight.FW_NORMAL, False)}
     used_styles = defaultdict(UsageData)
     event = AssParser.AssEvent(1, "style", r"rardo\nmm\Nmm", False)
     AssParser.process_event(event, used_styles, styles)
     result = list(used_styles.values())[0]
     self.assertSequenceEqual({"r", "a", "d", "o", "m"}, result.chars)
示例#2
0
 def test_find_all_unique_plain_text_characters(self):
     styles = {'style' : StyleInfo('Font', FontWeight.FW_NORMAL, False)}
     used_styles = defaultdict(UsageData)
     event = AssParser.AssEvent(1, 'style','randommmm' ,False)
     AssParser.process_event(event, used_styles, styles)
     result = list(used_styles.values())[0]
     self.assertSequenceEqual({'r','a', 'n', 'd','o','m'}, result.chars)
示例#3
0
 def test_replaces_h_with_tab(self):
     styles = {"style": StyleInfo("Font", FontWeight.FW_NORMAL, False)}
     used_styles = defaultdict(UsageData)
     event = AssParser.AssEvent(1, "style", r"lolol\hlolol", False)
     AssParser.process_event(event, used_styles, styles)
     result = list(used_styles.values())[0]
     self.assertSequenceEqual({"l", "o", "\xA0"}, result.chars)
示例#4
0
 def test_does_not_include_new_lines(self):
     styles = {'style' : StyleInfo('Font', FontWeight.FW_NORMAL, False)}
     used_styles = defaultdict(UsageData)
     event = AssParser.AssEvent(1, 'style',r'rardo\nmm\Nmm' ,False)
     AssParser.process_event(event, used_styles, styles)
     result = list(used_styles.values())[0]
     self.assertSequenceEqual({'r','a', 'd','o','m'}, result.chars)
示例#5
0
 def test_replaces_h_with_tab(self):
     styles = {'style' : StyleInfo('Font', FontWeight.FW_NORMAL, False)}
     used_styles = defaultdict(UsageData)
     event = AssParser.AssEvent(1, 'style',r'lolol\hlolol' ,False)
     AssParser.process_event(event, used_styles, styles)
     result = list(used_styles.values())[0]
     self.assertSequenceEqual({'l','o', "\xA0"}, result.chars)
示例#6
0
 def test_find_all_unique_plain_text_characters(self):
     styles = {"style": StyleInfo("Font", FontWeight.FW_NORMAL, False)}
     used_styles = defaultdict(UsageData)
     event = AssParser.AssEvent(1, "style", "randommmm", False)
     AssParser.process_event(event, used_styles, styles)
     result = list(used_styles.values())[0]
     self.assertSequenceEqual({"r", "a", "n", "d", "o", "m"}, result.chars)
示例#7
0
 def test_correctly_processes_double_font_italic_overrides(self):
     styles = {"style": StyleInfo("Font", 0, False)}
     used_styles = defaultdict(UsageData)
     event = AssParser.AssEvent(
         1, "style", r"{\an5\blur1.1\fs90\pos(970,454)\1a&H12}She {\i1\b1}is{\i0\b0} annoying.", False
     )
     AssParser.process_event(event, used_styles, styles)
     self.assertEqual(len(used_styles), 2)
示例#8
0
    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)
示例#9
0
    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)
示例#10
0
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")
示例#11
0
文件: assfc.py 项目: tp7/assfc
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))
示例#12
0
 def test_returns_empty_list_on_empty_string(self):
     blocks = AssParser.parse_tags("")
     self.assertFalse(blocks)
示例#13
0
 def test_does_not_include_drawing(self):
     blocks = AssParser.parse_tags(r'{\b1\p1}blablabla{\p0}blablabla')
     self.assertEqual(len(blocks),3)
示例#14
0
 def test_gets_correct_count_of_styles_font_used_in(self):
     stat = AssParser.get_fonts_statistics(get_file_in_test_directory('1.ass'), True, True)
     for key, value in stat.items():
         if key.fontname == 'YANEF':
             found = value
     self.assertEqual(len(found.styles), 1)
示例#15
0
 def test_does_not_include_comments(self):
     blocks = AssParser.parse_tags(r"{comment line}text")
     self.assertTrue(len(blocks), 1)
     self.assertIsInstance(blocks[0], AssParser.AssBlockPlain)
示例#16
0
 def test_returns_correct_number_of_blocks_but_does_not_include_useless_ones(self):
     blocks = AssParser.parse_tags(r"{\an5\blur1.1\fsp3\1a&H32\pos(962.2,918.8)}Animation number 392")
     self.assertEqual(len(blocks), 1)
示例#17
0
 def test_returns_correct_number_of_all_fonts_in_bakemono_script(self):
     stat = AssParser.get_fonts_statistics(get_file_in_test_directory('1.ass'), False, False)
     self.assertEqual(len(stat), 19)
示例#18
0
 def test_does_not_include_comments(self):
     blocks = AssParser.parse_tags(r'{comment line}text')
     self.assertTrue(len(blocks),1)
     self.assertIsInstance(blocks[0], AssParser.AssBlockPlain)
示例#19
0
 def test_includes_tags_in_correct_order(self):
     blocks = AssParser.parse_tags(r"{\b1}blablabla{\b0}blablabla")
     self.assertIsInstance(blocks[0], AssParser.AssBlockOverride)
     self.assertIsInstance(blocks[1], AssParser.AssBlockPlain)
     self.assertIsInstance(blocks[2], AssParser.AssBlockOverride)
     self.assertIsInstance(blocks[3], AssParser.AssBlockPlain)
示例#20
0
 def test_does_not_remove_styles_used_in_r(self):
     stat = AssParser.get_fonts_statistics(get_file_in_test_directory("2.ass"), True, True)
     styles = set()
     for info in stat.values():
         styles.update(info.styles)
     self.assertIn("EDromajiEng", styles)
示例#21
0
 def test_includes_tags_in_correct_order(self):
     blocks = AssParser.parse_tags(r'{\b1}blablabla{\b0}blablabla')
     self.assertIsInstance(blocks[0], AssParser.AssBlockOverride)
     self.assertIsInstance(blocks[1], AssParser.AssBlockPlain)
     self.assertIsInstance(blocks[2], AssParser.AssBlockOverride)
     self.assertIsInstance(blocks[3], AssParser.AssBlockPlain)
示例#22
0
 def test_gets_correct_count_of_lines_font_used_in(self):
     stat = AssParser.get_fonts_statistics(get_file_in_test_directory("1.ass"), False, False)
     for key, value in stat.items():
         if key.fontname == "this is totally not real font":
             found = value
     self.assertEqual(len(found.lines), 1)
示例#23
0
 def test_gets_correct_count_of_styles_font_used_in(self):
     stat = AssParser.get_fonts_statistics(get_file_in_test_directory("1.ass"), True, True)
     for key, value in stat.items():
         if key.fontname == "YANEF":
             found = value
     self.assertEqual(len(found.styles), 1)
示例#24
0
 def test_returns_correct_number_of_all_fonts_in_bakemono_script_without_unused_fonts_and_comments(self):
     stat = AssParser.get_fonts_statistics(get_file_in_test_directory("1.ass"), True, True)
     self.assertEqual(len(stat), 17)
示例#25
0
 def test_returns_correct_number_of_all_fonts_in_bakemono_script(self):
     stat = AssParser.get_fonts_statistics(get_file_in_test_directory("1.ass"), False, False)
     self.assertEqual(len(stat), 19)
示例#26
0
 def test_treats_not_closed_override_block_as_plain_text(self):
     with disabled_logging(logging.WARNING):
         blocks = AssParser.parse_tags(r"{\b1\b0blablabla")
     self.assertIsInstance(blocks[0], AssParser.AssBlockPlain)
示例#27
0
 def test_treats_not_closed_override_block_as_plain_text(self):
     with disabled_logging(logging.WARNING):
         blocks = AssParser.parse_tags(r'{\b1\b0blablabla')
     self.assertIsInstance(blocks[0], AssParser.AssBlockPlain)
示例#28
0
 def test_does_not_remove_styles_used_in_r(self):
     stat = AssParser.get_fonts_statistics(get_file_in_test_directory('2.ass'), True, True)
     styles = set()
     for info in stat.values():
         styles.update(info.styles)
     self.assertIn('EDromajiEng', styles)
示例#29
0
 def test_does_not_include_completely_empty_override_blocks(self):
     blocks = AssParser.parse_tags(r'{}text')
     self.assertTrue(len(blocks),1)
     self.assertIsInstance(blocks[0], AssParser.AssBlockPlain)
示例#30
0
 def test_returns_correct_value_for_italic_and_bold_when_specified_as_a_single_digit(self):
     block = AssParser.AssBlockOverride(r'\blur12\b0\fnFont\i1')
     self.assertEqual(block.tags['i'], '1')
     self.assertEqual(block.tags['b'], '0')
示例#31
0
 def test_does_not_include_drawing(self):
     blocks = AssParser.parse_tags(r"{\b1\p1}blablabla{\p0}blablabla")
     self.assertEqual(len(blocks), 3)
示例#32
0
 def test_detects_drawing(self):
     block = AssParser.AssBlockOverride(r'\blur1\p1\fnFont')
     self.assertEqual(block.tags['p'], '1')
示例#33
0
 def test_correctly_processes_double_font_italic_overrides(self):
     styles = {'style' : StyleInfo('Font', 0, False)}
     used_styles = defaultdict(UsageData)
     event = AssParser.AssEvent(1, 'style',r'{\an5\blur1.1\fs90\pos(970,454)\1a&H12}She {\i1\b1}is{\i0\b0} annoying.' ,False)
     AssParser.process_event(event, used_styles, styles)
     self.assertEqual(len(used_styles), 2)
示例#34
0
 def test_parses_style_override_with_style_name(self):
     block = AssParser.AssBlockOverride(r'\blur1\rRandom Style\fnFont')
     self.assertEqual(block.tags['r'], 'Random Style')
示例#35
0
 def test_returns_correct_number_of_all_fonts_in_bakemono_script_without_unused_fonts_and_comments(self):
     stat = AssParser.get_fonts_statistics(get_file_in_test_directory('1.ass'), True, True)
     self.assertEqual(len(stat), 17)
示例#36
0
 def test_returns_last_tag_value(self):
     block = AssParser.AssBlockOverride(r'\blur12\b1\fnFont\b0\i')
     self.assertEqual(block.tags['b'], '0')
示例#37
0
 def test_gets_correct_count_of_lines_font_used_in(self):
     stat = AssParser.get_fonts_statistics(get_file_in_test_directory('1.ass'), False, False)
     for key, value in stat.items():
         if key.fontname == 'this is totally not real font':
             found = value
     self.assertEqual(len(found.lines), 1)
示例#38
0
 def test_does_not_include_completely_empty_override_blocks(self):
     blocks = AssParser.parse_tags(r"{}text")
     self.assertTrue(len(blocks), 1)
     self.assertIsInstance(blocks[0], AssParser.AssBlockPlain)
示例#39
0
 def test_does_not_include_blur(self):
     block = AssParser.AssBlockOverride(r'\blur12\fnFont\i1')
     with self.assertRaises(KeyError):
         tag = block.tags['b']
示例#40
0
 def test_get_tag_raises_key_error_if_tag_is_not_present(self):
     block = AssParser.AssBlockOverride('')
     with self.assertRaises(KeyError):
         value = block.get_tag('b', 12)
示例#41
0
 def test_returns_empty_string_when_italic_or_bold_does_not_have_digits(self):
     block = AssParser.AssBlockOverride(r'\blur12\b\fnFont\i')
     self.assertEqual(block.tags['i'], '')
     self.assertEqual(block.tags['b'], '')
示例#42
0
 def test_get_tag_returns_default_if_value_is_empty_string(self):
     block = AssParser.AssBlockOverride(r'\b\p1')
     self.assertEqual(block.get_tag('b', 12), 12)
示例#43
0
 def test_parses_empty_style_override(self):
     block = AssParser.AssBlockOverride(r'\blur1\r\fnFont')
     self.assertEqual(block.tags['r'], '')
示例#44
0
 def test_get_tag_returns_value_if_it_exists(self):
     block = AssParser.AssBlockOverride(r'\b1\p1')
     self.assertTrue(block.get_tag('b', 12), 1)
示例#45
0
 def test_returns_correct_font_name_even_if_it_has_spaces(self):
     block = AssParser.AssBlockOverride(r'\blur12\b\fnFont with spaces\i')
     self.assertEqual(block.tags['fn'], 'Font with spaces')
示例#46
0
 def test_returns_empty_list_on_empty_string(self):
     blocks = AssParser.parse_tags('')
     self.assertFalse(blocks)
示例#47
0
 def test_returns_weight_for_bold_if_tag_has_multiple_digits(self):
     block = AssParser.AssBlockOverride(r'\blur12\b123\fnFont')
     self.assertEqual(block.tags['b'], '123')
示例#48
0
 def test_returns_correct_number_of_blocks_but_does_not_include_useless_ones(self):
     blocks = AssParser.parse_tags(r"{\an5\blur1.1\fsp3\1a&H32\pos(962.2,918.8)}Animation number 392")
     self.assertEqual(len(blocks), 1)