<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import itertools <EOL> import os <EOL> import re <EOL> import sys <EOL> import xml . etree . ElementTree <EOL> import coverage <EOL> import font_caching <EOL> import render <EOL> def _regular_expression_from_set ( character_set ) : <EOL> """<STR_LIT>""" <EOL> character_set -= set ( range ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> literal_list = [ ] <EOL> for code in character_set : <EOL> char = unichr ( code ) <EOL> if char in [ '<STR_LIT:\\>' , '<STR_LIT:[>' , '<STR_LIT:]>' , '<STR_LIT>' , '<STR_LIT:->' ] : <EOL> char = '<STR_LIT:\\>' + char <EOL> literal_list . append ( char ) <EOL> regexp = '<STR_LIT:[>' + '<STR_LIT>' . join ( literal_list ) + '<STR_LIT>' <EOL> return re . compile ( regexp ) <EOL> def test_rendering ( <EOL> data , font_file_name , min_allowed , max_allowed , language = None ) : <EOL> """<STR_LIT>""" <EOL> font_characters = coverage . character_set ( font_file_name ) <EOL> font_characters |= set ( range ( ord ( '<STR_LIT:0>' ) , ord ( '<STR_LIT>' ) + <NUM_LIT:1> ) ) <EOL> supported_chars_regex = _regular_expression_from_set ( font_characters ) <EOL> harfbuzz_input = [ ] <EOL> for match in supported_chars_regex . finditer ( data ) : <EOL> harfbuzz_input . append ( match . group ( <NUM_LIT:0> ) ) <EOL> harfbuzz_input = '<STR_LIT:\n>' . join ( harfbuzz_input ) <EOL> return render . test_text_vertical_extents ( <EOL> harfbuzz_input , font_file_name , min_allowed , max_allowed , language ) <EOL> def test_rendering_from_file ( <EOL> file_handle , font_file_name , min_allowed , max_allowed , language = None ) : <EOL> """<STR_LIT>""" <EOL> input_data = file_handle . read ( ) <EOL> if input_data . startswith ( '<STR_LIT>' ) : <EOL> root = xml . etree . ElementTree . fromstring ( input_data ) <EOL> assert root . tag == '<STR_LIT>' <EOL> test_strings = [ ] <EOL> for child in root : <EOL> if child . text is not None : <EOL> test_strings . append ( child . text ) <EOL> input_data = '<STR_LIT:\n>' . join ( test_strings ) <EOL> else : <EOL> input_data = unicode ( input_data , '<STR_LIT>' ) <EOL> return test_rendering ( <EOL> input_data , font_file_name , min_allowed , max_allowed , language ) <EOL> def test_all_combinations ( <EOL> max_len , font_file_name , min_allowed , max_allowed , language = None ) : <EOL> """<STR_LIT>""" <EOL> font_characters = coverage . character_set ( font_file_name ) <EOL> font_characters -= set ( range ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> font_characters = [ unichr ( code ) for code in font_characters ] <EOL> font_characters = sorted ( font_characters ) <EOL> all_strings = [ ] <EOL> for length in range ( <NUM_LIT:1> , max_len + <NUM_LIT:1> ) : <EOL> all_combinations = itertools . product ( font_characters , repeat = length ) <EOL> all_strings += [ '<STR_LIT>' . join ( comb ) for comb in all_combinations ] <EOL> test_data = '<STR_LIT:\n>' . join ( all_strings ) <EOL> return test_rendering ( <EOL> test_data , font_file_name , min_allowed , max_allowed , language ) <EOL> def _is_noto_ui_font ( font_file_name ) : <EOL> """<STR_LIT>""" <EOL> base_name = os . path . basename ( font_file_name ) <EOL> return base_name . startswith ( '<STR_LIT>' ) and '<STR_LIT>' in base_name <EOL> def main ( argv ) : <EOL> """<STR_LIT>""" <EOL> font_file_name = argv [ <NUM_LIT:1> ] <EOL> if len ( argv ) > <NUM_LIT:2> : <EOL> language = argv [ <NUM_LIT:2> ] <EOL> else : <EOL> language = None <EOL> if len ( argv ) > <NUM_LIT:4> : <EOL> ymin = int ( argv [ <NUM_LIT:3> ] ) <EOL> ymax = int ( argv [ <NUM_LIT:4> ] ) <EOL> else : <EOL> font = font_caching . open_font ( font_file_name ) <EOL> ymin = - font [ '<STR_LIT>' ] . usWinDescent <EOL> ymax = font [ '<STR_LIT>' ] . usWinAscent <EOL> if _is_noto_ui_font ( font_file_name ) : <EOL> ymin = max ( ymin , - <NUM_LIT> ) <EOL> ymax = min ( ymax , <NUM_LIT> ) <EOL> exceeding_lines = test_rendering_from_file ( <EOL> sys . stdin , font_file_name , ymin , ymax , language ) <EOL> for line_bounds , text_piece in exceeding_lines : <EOL> print text_piece . encode ( '<STR_LIT>' ) , line_bounds <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( sys . argv ) </s>
