def generate_font_table(compare_data): lines = [] def write_lines(key, fdata): lines.append( '<tr><td><div class="box %s"> </div><td><b>File</b> %s' % (key, fdata.file[pfx_len:])) version = fdata.version if version.startswith("Version "): version = version[len("Version "):] lines.append("<tr><td><td><b>Version</b> %s" % version) lines.append( "<tr><td><td><b>Upem</b> %d, <b>Ascent</b> %d, <b>Descent</b> %d, " "<b>Glyphs</b> %d, <b>CPs</b> %d" % ( fdata.upem, fdata.ascent, fdata.descent, fdata.num_glyphs, fdata.codepoints, )) pfx, paths = tool_utils.commonpathprefix( (compare_data.base_fdata.file, compare_data.target_fdata.file)) pfx_len = len(pfx) write_lines("b", compare_data.base_fdata) write_lines("t", compare_data.target_fdata) return "\n".join(lines)
def write_html_page(filename, page_title, font, dir_infos, keys, aliases, excluded, annotations, standalone, colors, info): out_dir = path.dirname(filename) if font: if standalone: # the assumption with standalone is that the source data and # output directory don't overlap, this should probably be checked... rel_fontpath = path.join('font', path.basename(font)) new_font = path.join(out_dir, rel_fontpath) tool_utils.ensure_dir_exists(path.dirname(new_font)) shutil.copy2(font, new_font) font = rel_fontpath else: common_prefix, (rel_dir, rel_font) = tool_utils.commonpathprefix( [out_dir, font]) if rel_dir == '': # font is in a subdirectory of the target, so just use the relative # path font = rel_font else: # use the absolute path font = path.normpath(path.join(common_prefix, rel_font)) content = _generate_content(path.dirname(filename), font, dir_infos, keys, aliases, excluded, annotations, standalone, colors) N_STYLE = STYLE if font: FONT_FACE_STYLE = """ <style>@font-face { font-family: "Emoji"; src: local("Noto Color Emoji"), url("%s"); }</style>""" % font N_STYLE += ' span.efont { font-family: "Emoji"; font-size:32pt }\n' else: FONT_FACE_STYLE = '' num_final_cols = len(colors) col_colors = [''] for i, color in enumerate(colors): col_colors.append( """td:nth-last-of-type(%d) { background-color: #%s }\n""" % (2 + num_final_cols - i, color)) N_STYLE += ' '.join(col_colors) text = _instantiate_template( TEMPLATE, { 'title': page_title, 'fontFaceStyle': FONT_FACE_STYLE, 'style': N_STYLE, 'content': content, 'info': info }) with codecs.open(filename, 'w', 'utf-8') as f: f.write(text)