示例#1
0
def test_options_newline_crlf():
    tto = ttx.Options([("--newline", "CRLF")], 1)
    assert tto.newlinestr == "\r\n"
示例#2
0
def test_options_z_invalidoption():
    with pytest.raises(getopt.GetoptError):
        ttx.Options([("-z", "bogus")], 1)
示例#3
0
def test_options_y_invalidvalue():
    with pytest.raises(ValueError):
        ttx.Options([("-y", "A")], 1)
示例#4
0
def test_options_t_withpadding():
    tto = ttx.Options([("-t", "CFF")], 1)
    assert len(tto.onlyTables) == 1
    assert tto.onlyTables[0] == "CFF "
示例#5
0
def test_options_i():
    tto = ttx.Options([("-i", "")], 1)
    assert tto.disassembleInstructions is False
示例#6
0
def test_options_f():
    tto = ttx.Options([("-f", "")], 1)
    assert tto.overWrite is True
示例#7
0
def test_options_q():
    tto = ttx.Options([("-q", "")], 1)
    assert tto.quiet is True
    assert tto.logLevel == logging.WARNING
示例#8
0
def test_options_quiet_and_verbose_shouldfail():
    with pytest.raises(getopt.GetoptError):
        ttx.Options([("-q", ""), ("-v", "")], 1)
示例#9
0
def test_options_mergefile_and_flavor_shouldfail():
    with pytest.raises(getopt.GetoptError):
        ttx.Options([("-m", "testfont.ttf"), ("--flavor", "woff")], 1)
示例#10
0
def test_options_with_zopfli():
    tto = ttx.Options([("--with-zopfli", ""), ("--flavor", "woff")], 1)
    assert tto.useZopfli is True
示例#11
0
def test_options_with_zopfli_fails_without_woff_flavor():
    with pytest.raises(getopt.GetoptError):
        ttx.Options([("--with-zopfli", "")], 1)
示例#12
0
def test_options_flavor():
    tto = ttx.Options([("--flavor", "woff")], 1)
    assert tto.flavor == "woff"
示例#13
0
def test_options_recalc_timestamp():
    tto = ttx.Options([("--recalc-timestamp", "")], 1)
    assert tto.recalcTimestamp is True
示例#14
0
def test_options_newline_invalid():
    with pytest.raises(getopt.GetoptError):
        ttx.Options([("--newline", "BOGUS")], 1)
示例#15
0
def test_options_d_badpath():
    with pytest.raises(getopt.GetoptError):
        ttx.Options([("-d", "bogusdir")], 1)
示例#16
0
def test_options_onlytables_and_skiptables_shouldfail():
    with pytest.raises(getopt.GetoptError):
        ttx.Options([("-t", "CFF"), ("-x", "CFF2")], 1)
示例#17
0
def test_options_o():
    tto = ttx.Options([("-o", "testfile.ttx")], 1)
    assert tto.outputFile == "testfile.ttx"
示例#18
0
def test_options_mergefile_and_multiplefiles_shouldfail():
    with pytest.raises(getopt.GetoptError):
        ttx.Options([("-m", "testfont.ttf")], 2)
示例#19
0
def test_options_v():
    tto = ttx.Options([("-v", "")], 1)
    assert tto.verbose is True
    assert tto.logLevel == logging.DEBUG
示例#20
0
def test_options_woff2_and_zopfli_shouldfail():
    with pytest.raises(getopt.GetoptError):
        ttx.Options([("--with-zopfli", ""), ("--flavor", "woff2")], 1)
示例#21
0
def test_options_l():
    tto = ttx.Options([("-l", "")], 1)
    assert tto.listTables is True
示例#22
0
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,
示例#23
0
def test_options_g():
    tto = ttx.Options([("-g", "")], 1)
    assert tto.splitGlyphs is True
    assert tto.splitTables is True
示例#24
0
# 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
    ])
示例#25
0
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
示例#26
0
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
示例#27
0
def test_options_y_validvalue():
    tto = ttx.Options([("-y", "1")], 1)
    assert tto.fontNumber == 1
示例#28
0
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
示例#29
0
def test_options_m():
    tto = ttx.Options([("-m", "testfont.ttf")], 1)
    assert tto.mergeFile == "testfont.ttf"
示例#30
0
def test_options_unicodedata():
    tto = ttx.Options([("--unicodedata", "UnicodeData.txt")], 1)
    assert tto.unicodedata == "UnicodeData.txt"