def test_options_newline_crlf(): tto = ttx.Options([("--newline", "CRLF")], 1) assert tto.newlinestr == "\r\n"
def test_options_z_invalidoption(): with pytest.raises(getopt.GetoptError): ttx.Options([("-z", "bogus")], 1)
def test_options_y_invalidvalue(): with pytest.raises(ValueError): ttx.Options([("-y", "A")], 1)
def test_options_t_withpadding(): tto = ttx.Options([("-t", "CFF")], 1) assert len(tto.onlyTables) == 1 assert tto.onlyTables[0] == "CFF "
def test_options_i(): tto = ttx.Options([("-i", "")], 1) assert tto.disassembleInstructions is False
def test_options_f(): tto = ttx.Options([("-f", "")], 1) assert tto.overWrite is True
def test_options_q(): tto = ttx.Options([("-q", "")], 1) assert tto.quiet is True assert tto.logLevel == logging.WARNING
def test_options_quiet_and_verbose_shouldfail(): with pytest.raises(getopt.GetoptError): ttx.Options([("-q", ""), ("-v", "")], 1)
def test_options_mergefile_and_flavor_shouldfail(): with pytest.raises(getopt.GetoptError): ttx.Options([("-m", "testfont.ttf"), ("--flavor", "woff")], 1)
def test_options_with_zopfli(): tto = ttx.Options([("--with-zopfli", ""), ("--flavor", "woff")], 1) assert tto.useZopfli is True
def test_options_with_zopfli_fails_without_woff_flavor(): with pytest.raises(getopt.GetoptError): ttx.Options([("--with-zopfli", "")], 1)
def test_options_flavor(): tto = ttx.Options([("--flavor", "woff")], 1) assert tto.flavor == "woff"
def test_options_recalc_timestamp(): tto = ttx.Options([("--recalc-timestamp", "")], 1) assert tto.recalcTimestamp is True
def test_options_newline_invalid(): with pytest.raises(getopt.GetoptError): ttx.Options([("--newline", "BOGUS")], 1)
def test_options_d_badpath(): with pytest.raises(getopt.GetoptError): ttx.Options([("-d", "bogusdir")], 1)
def test_options_onlytables_and_skiptables_shouldfail(): with pytest.raises(getopt.GetoptError): ttx.Options([("-t", "CFF"), ("-x", "CFF2")], 1)
def test_options_o(): tto = ttx.Options([("-o", "testfile.ttx")], 1) assert tto.outputFile == "testfile.ttx"
def test_options_mergefile_and_multiplefiles_shouldfail(): with pytest.raises(getopt.GetoptError): ttx.Options([("-m", "testfont.ttf")], 2)
def test_options_v(): tto = ttx.Options([("-v", "")], 1) assert tto.verbose is True assert tto.logLevel == logging.DEBUG
def test_options_woff2_and_zopfli_shouldfail(): with pytest.raises(getopt.GetoptError): ttx.Options([("--with-zopfli", ""), ("--flavor", "woff2")], 1)
def test_options_l(): tto = ttx.Options([("-l", "")], 1) assert tto.listTables is True
URL = "https://hidden-island-93990.squarectf.com/ea6c95c6d0ff24545cad" # Fetch HTML from the page and get the base64-encoded TTF res = requests.get(URL) soup = BeautifulSoup(res.text, "html.parser") ttf = re.findall(r"base64,([a-zA-Z0-9\/+=]*)", res.text)[0] ttf = base64.decodestring(ttf) # Save TTF to file with open('font.ttf', 'w') as f: f.write(ttf) # Dump the TTX from the TTF file using fontTools ttx.ttDump('font.ttf', 'font.ttx', ttx.Options([], 1)) tree = ElementTree.parse('font.ttx').getroot() # Map to values of the TTGlyph attributes from a TTX file mapped by hand ttglyph_mapping = { "0": { "xMin": 0, "yMin": 0, "xMax": 585, "yMax": 660, }, "1": { "xMin": 0, "yMin": 0, "xMax": 311, "yMax": 673,
def test_options_g(): tto = ttx.Options([("-g", "")], 1) assert tto.splitGlyphs is True assert tto.splitTables is True
# Generates ttf, woff, and woff2 fonts from ttx source. import sys from fontTools import subset from fontTools import ttx from fontTools.ttLib import sfnt # Arguments TTX = sys.argv[1] # Files TTF = TTX.replace(".ttx", ".ttf") WOFF = TTX.replace(".ttx", ".woff") WOFF2 = TTX.replace(".ttx", ".woff2") # Make ttf ttx.ttCompile(TTX, TTF, ttx.Options([], 1)) # Make woff sfnt.ZOPFLI_LEVELS[sfnt.ZLIB_COMPRESSION_LEVEL] = 1000 for w in (WOFF, WOFF2): subset.main([ TTF, "--glyphs=*", "--notdef-glyph", "--notdef-outline", "--no-name-legacy", "--no-glyph-names", "--no-legacy-cmap", "--no-symbol-cmap", "--no-recalc-bounds", "--no-recalc-timestamp", "--canonical-order", "--prune-unicode-ranges", "--no-recalc-average-width", "--with-zopfli", "--flavor=" + w.split(".")[-1], "--output-file=" + w ])
def test_options_z_validoptions(): valid_options = ("raw", "row", "bitwise", "extfile") for option in valid_options: tto = ttx.Options([("-z", option)], 1) assert tto.bitmapGlyphDataFormat == option
def test_options_flag_h(capsys): with pytest.raises(SystemExit): ttx.Options([("-h", None)], 1) out, err = capsys.readouterr() assert "TTX -- From OpenType To XML And Back" in out
def test_options_y_validvalue(): tto = ttx.Options([("-y", "1")], 1) assert tto.fontNumber == 1
def test_options_d_goodpath(tmpdir): temp_dir_path = str(tmpdir) tto = ttx.Options([("-d", temp_dir_path)], 1) assert tto.outputDir == temp_dir_path
def test_options_m(): tto = ttx.Options([("-m", "testfont.ttf")], 1) assert tto.mergeFile == "testfont.ttf"
def test_options_unicodedata(): tto = ttx.Options([("--unicodedata", "UnicodeData.txt")], 1) assert tto.unicodedata == "UnicodeData.txt"