def check_text_size(path, min_page_ratio='6'): """ Looking through all page layouts for text and comparing it size to page size """ rez = [] min_page_ratio = float(min_page_ratio) for page_num, page_layout in document_pages_layouts(path): # comparing only heights of page and text page_size = page_layout.height for character in layout_characters(page_layout): if character.size * min_page_ratio < page_size: rez.append({ 'id': 'C1002', 'page': 'Slide %s' % (page_num + 1), 'msg_name': 'font-to-small', 'msg': "Font is to small: Text should take up " "a minimum of 1/%sth the page." % min_page_ratio, 'help': "Font is to small: Text should take up " "a minimum of 1/6th(by default) the page." }) break return rez
def goes_throught_pages(source): """ yields characters info and its background per page """ with tempdir.TempDir() as dist: raw_html, images = tranform2html(source, dist) color_extractor = TextColorExtractor(raw_html) document_layout = document_pages_layouts(source) for (page_num, page_layout), image in izip(document_layout, images): page_background = Image.open(image) page_text_colors = color_extractor(page_num) page_images = get_text_color_and_background( page_text_colors, page_layout, page_background) yield page_num, page_images
def check_text_size(path, min_page_ratio='6'): """ Looking through all page layouts for text and comparing it size to page size """ rez = [] min_page_ratio = float(min_page_ratio) for page_num, page_layout in document_pages_layouts(path): # comparing only heights of page and text page_size = page_layout.height for character in layout_characters(page_layout): if character.size * min_page_ratio < page_size: rez.append( {'id': 'C1002', 'page': 'Slide %s' % (page_num + 1), 'msg_name': 'font-to-small', 'msg': "Font is to small: Text should take up " "a minimum of 1/%sth the page." % min_page_ratio, 'help': "Font is to small: Text should take up " "a minimum of 1/6th(by default) the page."} ) break return rez
def check_edges_danger_zone(path, min_page_ratio=12): """ Looking through all page layouts for text and comparing it size to page size """ # return [] rez = [] min_page_ratio = float(min_page_ratio) for page_num, page_layout in document_pages_layouts(path): width_dist = page_layout.width / min_page_ratio height_dist = page_layout.height / min_page_ratio # correlation of zero coordinates save_zone = (width_dist, height_dist, page_layout.width - width_dist, page_layout.height - height_dist) # checking save zone for character in layout_characters(page_layout): legal = (save_zone[0] < character.bbox[0], save_zone[1] < character.bbox[1], save_zone[2] > character.bbox[2], save_zone[3] > character.bbox[3]) if not all(legal): rez.append({ 'id': 'C1003', 'page': 'Slide %s' % (page_num + 1), 'msg_name': 'too-close-to-edges', 'msg': 'Too close to edges: Text should not appear ' 'closer than 1/%sth of the page size ' 'to the edges.' % min_page_ratio, 'help': 'Too close to edges: Text should not appear ' 'closer than 1/12th(by default) of the' ' page size to the edges.', }) break return rez
def check_edges_danger_zone(path, min_page_ratio=12): """ Looking through all page layouts for text and comparing it size to page size """ # return [] rez = [] min_page_ratio = float(min_page_ratio) for page_num, page_layout in document_pages_layouts(path): width_dist = page_layout.width / min_page_ratio height_dist = page_layout.height / min_page_ratio # correlation of zero coordinates save_zone = ( width_dist, height_dist, page_layout.width - width_dist, page_layout.height - height_dist) # checking save zone for character in layout_characters(page_layout): legal = ( save_zone[0] < character.bbox[0], save_zone[1] < character.bbox[1], save_zone[2] > character.bbox[2], save_zone[3] > character.bbox[3]) if not all(legal): rez.append({ 'id': 'C1003', 'page': 'Slide %s' % (page_num + 1), 'msg_name': 'too-close-to-edges', 'msg': 'Too close to edges: Text should not appear ' 'closer than 1/%sth of the page size ' 'to the edges.' % min_page_ratio, 'help': 'Too close to edges: Text should not appear ' 'closer than 1/12th(by default) of the' ' page size to the edges.'} ) break return rez