vttcompilepy 0.0.1.7__cp311-cp311-win_amd64.whl → 0.0.1.9__cp311-cp311-win_amd64.whl
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/quit_to_glyphs.py +115 -0
- vttcompilepy/vttcompilepy.cp311-win_amd64.pyd +0 -0
- {vttcompilepy-0.0.1.7.dist-info → vttcompilepy-0.0.1.9.dist-info}/METADATA +1 -1
- vttcompilepy-0.0.1.9.dist-info/RECORD +10 -0
- {vttcompilepy-0.0.1.7.dist-info → vttcompilepy-0.0.1.9.dist-info}/WHEEL +1 -1
- {vttcompilepy-0.0.1.7.dist-info → vttcompilepy-0.0.1.9.dist-info}/entry_points.txt +1 -0
- vttcompilepy-0.0.1.7.dist-info/RECORD +0 -9
- {vttcompilepy-0.0.1.7.dist-info → vttcompilepy-0.0.1.9.dist-info}/top_level.txt +0 -0
|
@@ -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()
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
vttcompilepy/__init__.py,sha256=rRj1kyo3VO-gNPedFT72RQ1rPQvWuRIy1duD6Lm9gsQ,141
|
|
2
|
+
vttcompilepy/__main__.py,sha256=98i0scCVfvS3M-fzjCYEn6inF29yNtxa1_o7CuryitM,2415
|
|
3
|
+
vttcompilepy/_version.py,sha256=xI2rzwqw6yD9ZFfXvbxHAlAhpl5bcY39u2eNO3qD2wU,33
|
|
4
|
+
vttcompilepy/quit_to_glyphs.py,sha256=XIQT92hAgsUKu4F3OtO8IRDDKwxKClp6Io1t7gDjZC8,4691
|
|
5
|
+
vttcompilepy/vttcompilepy.cp311-win_amd64.pyd,sha256=0YeYqtSvSbHnO5Ke4-tWwhQ806DQVHk6l5zujzZQLHw,529408
|
|
6
|
+
vttcompilepy-0.0.1.9.dist-info/METADATA,sha256=m2cPPdHOf_ue2IhHIcAXe83qpnUDjPJ-FtrfbtX-MbA,1808
|
|
7
|
+
vttcompilepy-0.0.1.9.dist-info/WHEEL,sha256=nSybvzWlmdJnHiUQSY-d7V1ycwEVUTqXiTvr2eshg44,102
|
|
8
|
+
vttcompilepy-0.0.1.9.dist-info/entry_points.txt,sha256=PpJiPR2lPxot3g6h6iUOSFH_v8hIeny0KKXzLplu4do,110
|
|
9
|
+
vttcompilepy-0.0.1.9.dist-info/top_level.txt,sha256=71VktNtpjUWIU6OZsRlXy-v9gauYZkgQOaUI_DlE2Mo,13
|
|
10
|
+
vttcompilepy-0.0.1.9.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
vttcompilepy/__init__.py,sha256=rRj1kyo3VO-gNPedFT72RQ1rPQvWuRIy1duD6Lm9gsQ,141
|
|
2
|
-
vttcompilepy/__main__.py,sha256=98i0scCVfvS3M-fzjCYEn6inF29yNtxa1_o7CuryitM,2415
|
|
3
|
-
vttcompilepy/_version.py,sha256=xI2rzwqw6yD9ZFfXvbxHAlAhpl5bcY39u2eNO3qD2wU,33
|
|
4
|
-
vttcompilepy/vttcompilepy.cp311-win_amd64.pyd,sha256=ijwcJ6yYutCopihOoVIeybNdO_EW0OrjMqKmQcB00Eg,527872
|
|
5
|
-
vttcompilepy-0.0.1.7.dist-info/METADATA,sha256=jh8k3cMeQfDp6xfKt2fNm7BPPg1AzQ1CL6tKNjVe_ss,1808
|
|
6
|
-
vttcompilepy-0.0.1.7.dist-info/WHEEL,sha256=badvNS-y9fEq0X-qzdZYvql_JFjI7Xfw-wR8FsjoK0I,102
|
|
7
|
-
vttcompilepy-0.0.1.7.dist-info/entry_points.txt,sha256=9SCBB-WZIMHOJz2pmB9lsGTpQT4SUATS4pZQe0ezxAU,60
|
|
8
|
-
vttcompilepy-0.0.1.7.dist-info/top_level.txt,sha256=71VktNtpjUWIU6OZsRlXy-v9gauYZkgQOaUI_DlE2Mo,13
|
|
9
|
-
vttcompilepy-0.0.1.7.dist-info/RECORD,,
|
|
File without changes
|