vttcompilepy 0.0.1.13__cp314-cp314t-macosx_10_15_universal2.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.
@@ -0,0 +1,6 @@
1
+ from .vttcompilepy import *
2
+
3
+ try:
4
+ from ._version import version as __version__
5
+ except ImportError:
6
+ __version__ = "0.0.0+unknown"
@@ -0,0 +1,71 @@
1
+ import vttcompilepy as vtt
2
+
3
+ import argparse
4
+ import sys
5
+ from pathlib import Path
6
+ from . import __version__ as vtt_version
7
+
8
+ def main(args=None):
9
+ if args is None:
10
+ args = sys.argv[1:]
11
+ parser = argparse.ArgumentParser()
12
+
13
+ parser.add_argument('--version', action='version', version='%(prog)s {version}'.format(version=vtt_version))
14
+
15
+ parser.add_argument("input", help="Input file")
16
+ parser.add_argument("output", help="Output file")
17
+
18
+ parser.add_argument("-i", "--importsourcefrombinary", action="store_true", help ="Import source from binary")
19
+
20
+ cgroup = parser.add_argument_group("Compile options")
21
+ cgroup.add_argument("-a", "--all", action="store_true", help ="Compile everything")
22
+ cgroup.add_argument("-l", "--legacy", action="store_true", help ="Rare cases for very old fonts")
23
+ cgroup.add_argument("-v", "--disablevariationcompositeguard", action="store_true", help ="Disable variation composite guard (default: enabled)")
24
+
25
+ sgroup = parser.add_argument_group("Strip options")
26
+ sgroup.add_argument("-s", "--source", action="store_true", help="Strip source")
27
+ sgroup.add_argument("-b", "--hints", action="store_true", help="Strip source and hints")
28
+ sgroup.add_argument("-c", "--cache", action="store_true", help="Strip source and hints and cache tables")
29
+
30
+ args = parser.parse_args(args)
31
+
32
+ print(args.input)
33
+ print(args.output)
34
+ inpath = Path(args.input)
35
+ outpath = Path(args.output)
36
+
37
+ compiler = vtt.Compiler(inpath)
38
+
39
+ legacy = False
40
+ variationCompositeGuard = True
41
+
42
+ if args.legacy:
43
+ legacy = True
44
+
45
+ if args.disablevariationcompositeguard:
46
+ variationCompositeGuard = False
47
+
48
+ if args.importsourcefrombinary:
49
+ compiler.import_source_from_binary()
50
+
51
+ if args.all:
52
+ compiler.compile_all(legacy, variationCompositeGuard)
53
+
54
+ #StripCommand strip = stripNothing;
55
+ #if (bStripCache) strip = stripBinary;
56
+ #else if (bStripHints) strip = stripHints;
57
+ #else if (bStripSource) strip = stripSource;
58
+
59
+ level = vtt.StripLevel.STRIP_NOTHING
60
+
61
+ if args.cache:
62
+ level = vtt.StripLevel.STRIP_BINARY
63
+ elif args.hints:
64
+ level = vtt.StripLevel.STRIP_HINTS
65
+ elif args.source:
66
+ level = vtt.StripLevel.STRIP_SOURCE
67
+
68
+ compiler.save_font(outpath, level)
69
+
70
+ if __name__ == "__main__":
71
+ sys.exit(main())
@@ -0,0 +1 @@
1
+ __version__ = version = '0.0.1.6'
@@ -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()
@@ -0,0 +1,62 @@
1
+ Metadata-Version: 2.4
2
+ Name: vttcompilepy
3
+ Version: 0.0.1.13
4
+ Summary: Python extension for Visual TrueType font compile.
5
+ Home-page: https://github.com/microsoft/VisualTrueType
6
+ Author: Paul Linnerud
7
+ Author-email: paulli@microsoft.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Requires-Python: >=3.7
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: fonttools>=4.33.0
14
+ Dynamic: author
15
+ Dynamic: author-email
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: home-page
20
+ Dynamic: license
21
+ Dynamic: requires-dist
22
+ Dynamic: requires-python
23
+ Dynamic: summary
24
+
25
+ # Project
26
+
27
+ VTTCompilePy is a Python extension built using Cython. It provides streamlined bindings for
28
+ various compilers from Visual TrueType.
29
+
30
+ VTTCompilePy was developed to support a Python based font development environment. In addition to the Python interface,
31
+ a command line interface is also installed. Usage is available with "vttcompilepy --help".
32
+
33
+ ### Example
34
+
35
+ ```python
36
+ import sys
37
+ from pathlib import Path
38
+ import vttcompilepy as vtt
39
+
40
+ TESTDATA = Path(__file__).parent / "data"
41
+ IN_PATH = TESTDATA / "selawik-variable.ttf"
42
+ OUT_PATH = TESTDATA / "out.ttf"
43
+
44
+ print(bytes(IN_PATH))
45
+
46
+ print('VTTCompilePy Test Client')
47
+
48
+ compiler = vtt.Compiler(IN_PATH)
49
+
50
+ compiler.compile_all()
51
+
52
+ compiler.save_font(OUT_PATH, vtt.StripLevel.STRIP_NOTHING)
53
+
54
+ ```
55
+
56
+ ## Trademarks
57
+
58
+ This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
59
+ trademarks or logos is subject to and must follow
60
+ [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
61
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
62
+ Any use of third-party trademarks or logos are subject to those third-party's policies.
@@ -0,0 +1,10 @@
1
+ vttcompilepy/_version.py,sha256=xI2rzwqw6yD9ZFfXvbxHAlAhpl5bcY39u2eNO3qD2wU,33
2
+ vttcompilepy/vttcompilepy.cpython-314t-darwin.so,sha256=a0ZU-yBPusU7fAJGSYYGB3uDz0m0RV5rpY_jepPJYVU,1695408
3
+ vttcompilepy/__init__.py,sha256=rRj1kyo3VO-gNPedFT72RQ1rPQvWuRIy1duD6Lm9gsQ,141
4
+ vttcompilepy/quit_to_glyphs.py,sha256=USPDqC0iJmLK-SHBR3-nR1ReacNIKs7KE2MRj1vf-AU,4576
5
+ vttcompilepy/__main__.py,sha256=doQ-R0Ms6U5dyo5Ey21rq1OgrXUsOqOYMbbCp9XiyRA,2344
6
+ vttcompilepy-0.0.1.13.dist-info/RECORD,,
7
+ vttcompilepy-0.0.1.13.dist-info/WHEEL,sha256=65gUNPbS3f2aTVAlw4K7IpOE3gqwRvvFMKvMHZZfBm8,143
8
+ vttcompilepy-0.0.1.13.dist-info/entry_points.txt,sha256=PpJiPR2lPxot3g6h6iUOSFH_v8hIeny0KKXzLplu4do,110
9
+ vttcompilepy-0.0.1.13.dist-info/top_level.txt,sha256=71VktNtpjUWIU6OZsRlXy-v9gauYZkgQOaUI_DlE2Mo,13
10
+ vttcompilepy-0.0.1.13.dist-info/METADATA,sha256=Y94b2nxXkX3WtReTSbA2Q8ErLagZzSjXTisUlFDRC8Q,1970
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp314-cp314t-macosx_10_15_universal2
5
+ Generator: delocate 0.13.0
6
+
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ quit_to_glyphs = vttcompilepy.quit_to_glyphs:main
3
+ vttcompilepy = vttcompilepy.__main__:main
@@ -0,0 +1 @@
1
+ vttcompilepy