vttcompilepy 0.0.1.6__zip → 0.0.1.8__zip
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of vttcompilepy might be problematic. Click here for more details.
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/PKG-INFO +2 -1
- vttcompilepy-0.0.1.8/setup.py +92 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/TTAssembler.cpp +128 -34
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/TextBuffer.cpp +15 -4
- vttcompilepy-0.0.1.8/src/application.h +47 -0
- vttcompilepy-0.0.1.8/src/pch.h +68 -0
- vttcompilepy-0.0.1.8/tests/test_vttcompile.py +163 -0
- vttcompilepy-0.0.1.8/vttcompilepy/quit_to_glyphs.py +115 -0
- vttcompilepy-0.0.1.8/vttcompilepy/vttcompilepy.cpp +14392 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/vttcompilepy.egg-info/PKG-INFO +2 -1
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/vttcompilepy.egg-info/SOURCES.txt +4 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/vttcompilepy.egg-info/entry_points.txt +1 -0
- vttcompilepy-0.0.1.6/setup.py +0 -69
- vttcompilepy-0.0.1.6/vttcompilepy/vttcompilepy.cpp +0 -8474
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/README.md +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/pyproject.toml +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/setup.cfg +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/CvtManager.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/File.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/List.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/MathUtils.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/Memory.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/Platform.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/TMTParser.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/TTEngine.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/TTFont.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/TTGenerator.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/Variation.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/VariationInstance.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/VariationModels.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/application.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/src/ttiua.cpp +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/vttcompilepy/__init__.py +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/vttcompilepy/__main__.py +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/vttcompilepy/_version.py +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/vttcompilepy.egg-info/dependency_links.txt +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/vttcompilepy.egg-info/not-zip-safe +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/vttcompilepy.egg-info/requires.txt +0 -0
- {vttcompilepy-0.0.1.6 → vttcompilepy-0.0.1.8}/vttcompilepy.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Copyright (c) Microsoft Corporation.
|
|
2
|
+
# Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import vttcompilepy as vtt
|
|
5
|
+
from fontTools.ttLib import TTFont
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
TESTDATA = Path(__file__).parent / "data"
|
|
10
|
+
IN_SELAWIK = TESTDATA / "Selawik-variable.ttf"
|
|
11
|
+
|
|
12
|
+
@pytest.fixture
|
|
13
|
+
def original_font():
|
|
14
|
+
return TTFont(IN_SELAWIK)
|
|
15
|
+
|
|
16
|
+
@pytest.fixture
|
|
17
|
+
def compiled_font_file():
|
|
18
|
+
compiler = vtt.Compiler(IN_SELAWIK)
|
|
19
|
+
compiler.compile_all()
|
|
20
|
+
out_compiled = TESTDATA / "out_c1.ttf"
|
|
21
|
+
compiler.save_font(out_compiled, vtt.StripLevel.STRIP_NOTHING)
|
|
22
|
+
return TTFont(out_compiled)
|
|
23
|
+
|
|
24
|
+
@pytest.fixture
|
|
25
|
+
def compiled_font_file_str():
|
|
26
|
+
in_selawik_str = str(IN_SELAWIK)
|
|
27
|
+
compiler = vtt.Compiler(in_selawik_str)
|
|
28
|
+
compiler.compile_all()
|
|
29
|
+
out_compiled_str = str(TESTDATA / "out_c2.ttf")
|
|
30
|
+
compiler.save_font(out_compiled_str, vtt.StripLevel.STRIP_NOTHING)
|
|
31
|
+
return TTFont(out_compiled_str)
|
|
32
|
+
|
|
33
|
+
@pytest.fixture
|
|
34
|
+
def compiled_font_mem():
|
|
35
|
+
tt = TTFont(IN_SELAWIK)
|
|
36
|
+
compiler = vtt.Compiler(tt)
|
|
37
|
+
compiler.compile_all()
|
|
38
|
+
tt1 = compiler.get_ttfont(vtt.StripLevel.STRIP_NOTHING)
|
|
39
|
+
return tt1
|
|
40
|
+
|
|
41
|
+
@pytest.fixture
|
|
42
|
+
def compiled_font_file_mem():
|
|
43
|
+
compiler = vtt.Compiler(IN_SELAWIK)
|
|
44
|
+
compiler.compile_all()
|
|
45
|
+
tt1 = compiler.get_ttfont(vtt.StripLevel.STRIP_NOTHING)
|
|
46
|
+
return tt1
|
|
47
|
+
|
|
48
|
+
@pytest.fixture
|
|
49
|
+
def compiled_font_mem_file():
|
|
50
|
+
tt = TTFont(IN_SELAWIK)
|
|
51
|
+
compiler = vtt.Compiler(tt)
|
|
52
|
+
compiler.compile_all()
|
|
53
|
+
out_compiled = TESTDATA / "out_c3.ttf"
|
|
54
|
+
compiler.save_font(out_compiled, vtt.StripLevel.STRIP_NOTHING)
|
|
55
|
+
return TTFont(out_compiled)
|
|
56
|
+
|
|
57
|
+
@pytest.fixture
|
|
58
|
+
def compiled_stripped_font_file():
|
|
59
|
+
compiler = vtt.Compiler(IN_SELAWIK)
|
|
60
|
+
compiler.compile_all()
|
|
61
|
+
out_compiled_stripped = TESTDATA / "out_c_s1.ttf"
|
|
62
|
+
compiler.save_font(out_compiled_stripped, vtt.StripLevel.STRIP_SOURCE)
|
|
63
|
+
return TTFont(out_compiled_stripped)
|
|
64
|
+
|
|
65
|
+
@pytest.fixture
|
|
66
|
+
def compiled_stripped_font_mem():
|
|
67
|
+
tt = TTFont(IN_SELAWIK)
|
|
68
|
+
compiler = vtt.Compiler(tt)
|
|
69
|
+
compiler.compile_all()
|
|
70
|
+
tt1 = compiler.get_ttfont(vtt.StripLevel.STRIP_SOURCE)
|
|
71
|
+
return tt1
|
|
72
|
+
|
|
73
|
+
@pytest.fixture
|
|
74
|
+
def compiled_source_from_bin_font_file():
|
|
75
|
+
compiler = vtt.Compiler(IN_SELAWIK)
|
|
76
|
+
compiler.import_source_from_binary()
|
|
77
|
+
out_import = TESTDATA / "out_c_c4i.ttf"
|
|
78
|
+
compiler.save_font(out_import, vtt.StripLevel.STRIP_NOTHING)
|
|
79
|
+
compiler.compile_all()
|
|
80
|
+
out_import_compiled = TESTDATA / "out_c_c4.ttf"
|
|
81
|
+
compiler.save_font(out_import_compiled, vtt.StripLevel.STRIP_NOTHING)
|
|
82
|
+
return TTFont(out_import_compiled)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@pytest.fixture
|
|
86
|
+
def compiled_source_from_bin_font_mem():
|
|
87
|
+
tt = TTFont(IN_SELAWIK)
|
|
88
|
+
compiler = vtt.Compiler(tt)
|
|
89
|
+
compiler.import_source_from_binary()
|
|
90
|
+
compiler.compile_all()
|
|
91
|
+
tt1 = compiler.get_ttfont(vtt.StripLevel.STRIP_NOTHING)
|
|
92
|
+
return tt1
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def compare_fonts(ttorig, ttcomp) -> None:
|
|
96
|
+
assert ttorig['maxp'].numGlyphs == ttcomp['maxp'].numGlyphs
|
|
97
|
+
assert ttorig['maxp'] == ttcomp['maxp']
|
|
98
|
+
assert ttorig['fpgm'] == ttcomp['fpgm']
|
|
99
|
+
assert ttorig['prep'] == ttcomp['prep']
|
|
100
|
+
|
|
101
|
+
glyf_orig = ttorig['glyf']
|
|
102
|
+
glyf_comp = ttcomp['glyf']
|
|
103
|
+
|
|
104
|
+
for glyph1 in ttorig.glyphOrder:
|
|
105
|
+
print(glyph1)
|
|
106
|
+
assert glyf_orig[glyph1].isComposite() == glyf_comp[glyph1].isComposite()
|
|
107
|
+
assert glyf_orig[glyph1].getCoordinates(glyf_orig) == glyf_comp[glyph1].getCoordinates(glyf_comp)
|
|
108
|
+
assert glyf_orig[glyph1].getComponentNames(glyf_orig) == glyf_comp[glyph1].getComponentNames(glyf_comp)
|
|
109
|
+
assert hasattr(glyf_orig[glyph1],'program') == hasattr(glyf_comp[glyph1],'program')
|
|
110
|
+
haveInstructions = hasattr(glyf_orig[glyph1], "program")
|
|
111
|
+
if haveInstructions:
|
|
112
|
+
#orig_codes = glyf_orig[glyph1].program.getBytecode()
|
|
113
|
+
orig_assembly = glyf_orig[glyph1].program.getAssembly()
|
|
114
|
+
print(orig_assembly)
|
|
115
|
+
#comp_codes = glyf_comp[glyph1].program.getBytecode()
|
|
116
|
+
comp_assembly = glyf_comp[glyph1].program.getAssembly()
|
|
117
|
+
print(comp_assembly)
|
|
118
|
+
assert orig_assembly == comp_assembly
|
|
119
|
+
|
|
120
|
+
def check_stripped(ttorig, ttstrip) -> None:
|
|
121
|
+
assert("TSI0" in ttorig)
|
|
122
|
+
assert("TSI0" not in ttstrip)
|
|
123
|
+
|
|
124
|
+
assert("TSI1" in ttorig)
|
|
125
|
+
assert("TSI1" not in ttstrip)
|
|
126
|
+
|
|
127
|
+
assert("TSI2" in ttorig)
|
|
128
|
+
assert("TSI2" not in ttstrip)
|
|
129
|
+
|
|
130
|
+
assert("TSI3" in ttorig)
|
|
131
|
+
assert("TSI3" not in ttstrip)
|
|
132
|
+
|
|
133
|
+
assert("TSI5" in ttorig)
|
|
134
|
+
assert("TSI5" not in ttstrip)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def test_compiled_file_file_path(original_font, tmp_path: Path, compiled_font_file):
|
|
138
|
+
compare_fonts(original_font, compiled_font_file)
|
|
139
|
+
|
|
140
|
+
def test_compiled_file_file_str(original_font, tmp_path: Path, compiled_font_file_str):
|
|
141
|
+
compare_fonts(original_font, compiled_font_file_str)
|
|
142
|
+
|
|
143
|
+
def test_stripped_file_file(original_font, tmp_path: Path, compiled_stripped_font_file):
|
|
144
|
+
check_stripped(original_font, compiled_stripped_font_file)
|
|
145
|
+
|
|
146
|
+
def test_compiled_file_mem(original_font, compiled_font_file_mem):
|
|
147
|
+
compare_fonts(original_font, compiled_font_file_mem)
|
|
148
|
+
|
|
149
|
+
def test_compiled_mem_file(original_font, compiled_font_mem_file):
|
|
150
|
+
compare_fonts(original_font, compiled_font_mem_file)
|
|
151
|
+
|
|
152
|
+
def test_compile_mem_mem(original_font, compiled_font_mem):
|
|
153
|
+
compare_fonts(original_font, compiled_font_mem)
|
|
154
|
+
|
|
155
|
+
def test_stripped_mem_mem(original_font, compiled_stripped_font_mem):
|
|
156
|
+
check_stripped(original_font, compiled_stripped_font_mem)
|
|
157
|
+
|
|
158
|
+
def test_import_source_from_binary_file(original_font, compiled_source_from_bin_font_file):
|
|
159
|
+
compare_fonts(original_font, compiled_source_from_bin_font_file)
|
|
160
|
+
|
|
161
|
+
def test_import_source_from_binary_mem(original_font, compiled_source_from_bin_font_mem):
|
|
162
|
+
compare_fonts(original_font, compiled_source_from_bin_font_mem)
|
|
163
|
+
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from fontTools.ttLib import TTFont
|
|
3
|
+
import vttcompilepy as vtt
|
|
4
|
+
import argparse
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def add_quit_to_glyph_program(
|
|
8
|
+
font_path, output_path, compile, start_index, end_index, remove, iterate
|
|
9
|
+
):
|
|
10
|
+
try:
|
|
11
|
+
# Load the font
|
|
12
|
+
font = TTFont(font_path)
|
|
13
|
+
|
|
14
|
+
# Access the TSI3 table (if it exists)
|
|
15
|
+
if "TSI3" in font:
|
|
16
|
+
tsi3_table = font["TSI3"]
|
|
17
|
+
glyph_set = font.getGlyphSet()
|
|
18
|
+
num_glyphs = len(glyph_set)
|
|
19
|
+
if end_index is None:
|
|
20
|
+
end_index = num_glyphs - 1
|
|
21
|
+
glyph_ids = list(range(start_index, end_index + 1))
|
|
22
|
+
glyph_names = font.getGlyphNameMany(glyph_ids)
|
|
23
|
+
added = 0
|
|
24
|
+
removed = 0
|
|
25
|
+
|
|
26
|
+
for glyph_name, glyph_id in zip(glyph_names, glyph_ids):
|
|
27
|
+
if glyph_name not in tsi3_table.glyphPrograms:
|
|
28
|
+
print(f"{glyph_name} id = {glyph_id} does not have a glyph program")
|
|
29
|
+
continue
|
|
30
|
+
if iterate:
|
|
31
|
+
try:
|
|
32
|
+
print(f"Iterate - trying {glyph_name} id = {glyph_id}")
|
|
33
|
+
compiler = vtt.Compiler(font)
|
|
34
|
+
compiler.compile_glyph_range(glyph_id, glyph_id)
|
|
35
|
+
|
|
36
|
+
except Exception:
|
|
37
|
+
# If compilation fails, add quit()
|
|
38
|
+
# Check if the glyph program already starts with "quit()"
|
|
39
|
+
if not tsi3_table.glyphPrograms[glyph_name].startswith(
|
|
40
|
+
"quit()"
|
|
41
|
+
):
|
|
42
|
+
tsi3_table.glyphPrograms[glyph_name] = (
|
|
43
|
+
"quit() \n" + tsi3_table.glyphPrograms[glyph_name]
|
|
44
|
+
)
|
|
45
|
+
print(f"Added quit() to {glyph_name} id = {glyph_id}")
|
|
46
|
+
added += 1
|
|
47
|
+
|
|
48
|
+
# Add or remove "quit()" to/from the beginning of each glyphProgram
|
|
49
|
+
elif remove:
|
|
50
|
+
# Check if the glyph program contains "quit()"
|
|
51
|
+
if "quit()" in tsi3_table.glyphPrograms[glyph_name]:
|
|
52
|
+
tsi3_table.glyphPrograms[glyph_name] = tsi3_table.glyphPrograms[
|
|
53
|
+
glyph_name
|
|
54
|
+
].replace("quit()", "")
|
|
55
|
+
print(f"Removed quit() from {glyph_name} id = {glyph_id}")
|
|
56
|
+
removed += 1
|
|
57
|
+
else:
|
|
58
|
+
# Check if the glyph program already starts with "quit()"
|
|
59
|
+
if not tsi3_table.glyphPrograms[glyph_name].startswith("quit()"):
|
|
60
|
+
tsi3_table.glyphPrograms[glyph_name] = (
|
|
61
|
+
"quit() \n" + tsi3_table.glyphPrograms[glyph_name]
|
|
62
|
+
)
|
|
63
|
+
print(f"Added quit() to {glyph_name} id = {glyph_id}")
|
|
64
|
+
added += 1
|
|
65
|
+
|
|
66
|
+
if compile or iterate:
|
|
67
|
+
# Compile the font
|
|
68
|
+
compiler = vtt.Compiler(font)
|
|
69
|
+
compiler.compile_all()
|
|
70
|
+
font = compiler.get_ttfont(vtt.StripLevel.STRIP_NOTHING)
|
|
71
|
+
print("Font compiled")
|
|
72
|
+
|
|
73
|
+
# Save the modified font to the output path
|
|
74
|
+
font.save(output_path)
|
|
75
|
+
|
|
76
|
+
print(f"Modified font saved to {output_path}")
|
|
77
|
+
print(f"Added quit() to {added} glyphs")
|
|
78
|
+
print(f"Removed quit() from {removed} glyphs")
|
|
79
|
+
else:
|
|
80
|
+
print("The font does not have a TSI3 table")
|
|
81
|
+
|
|
82
|
+
except Exception as e:
|
|
83
|
+
print(f"Error: {e}")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def main():
|
|
87
|
+
parser = argparse.ArgumentParser(
|
|
88
|
+
description="Add or remove quit to/from glyph program."
|
|
89
|
+
)
|
|
90
|
+
parser.add_argument("input_font_path", help="The path to the input font file.")
|
|
91
|
+
parser.add_argument("output_font_path", help="The path to the output font file.")
|
|
92
|
+
parser.add_argument("--compile", action="store_true", help="Compile the font.")
|
|
93
|
+
parser.add_argument("--start", type=int, default=0, help="Start glyph index.")
|
|
94
|
+
parser.add_argument("--end", type=int, default=None, help="End glyph index.")
|
|
95
|
+
parser.add_argument(
|
|
96
|
+
"--remove", action="store_true", help="Remove quit() from glyph program."
|
|
97
|
+
)
|
|
98
|
+
parser.add_argument(
|
|
99
|
+
"--iterate", action="store_true", help="Only add quit() to glyphs that need it."
|
|
100
|
+
)
|
|
101
|
+
args = parser.parse_args()
|
|
102
|
+
|
|
103
|
+
add_quit_to_glyph_program(
|
|
104
|
+
args.input_font_path,
|
|
105
|
+
args.output_font_path,
|
|
106
|
+
args.compile,
|
|
107
|
+
args.start,
|
|
108
|
+
args.end,
|
|
109
|
+
args.remove,
|
|
110
|
+
args.iterate,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
if __name__ == "__main__":
|
|
115
|
+
main()
|