vttcompilepy 0.0.1.7__zip → 0.0.1.9__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.7 → vttcompilepy-0.0.1.9}/PKG-INFO +2 -1
- vttcompilepy-0.0.1.9/setup.py +92 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/TextBuffer.cpp +15 -4
- vttcompilepy-0.0.1.9/vttcompilepy/quit_to_glyphs.py +115 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/vttcompilepy/vttcompilepy.cpp +383 -306
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/vttcompilepy.egg-info/PKG-INFO +2 -1
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/vttcompilepy.egg-info/SOURCES.txt +1 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/vttcompilepy.egg-info/entry_points.txt +1 -0
- vttcompilepy-0.0.1.7/setup.py +0 -69
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/README.md +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/pyproject.toml +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/setup.cfg +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/CvtManager.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/File.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/List.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/MathUtils.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/Memory.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/Platform.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/TMTParser.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/TTAssembler.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/TTEngine.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/TTFont.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/TTGenerator.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/Variation.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/VariationInstance.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/VariationModels.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/application.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/application.h +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/pch.h +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/src/ttiua.cpp +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/tests/test_vttcompile.py +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/vttcompilepy/__init__.py +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/vttcompilepy/__main__.py +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/vttcompilepy/_version.py +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/vttcompilepy.egg-info/dependency_links.txt +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/vttcompilepy.egg-info/not-zip-safe +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/vttcompilepy.egg-info/requires.txt +0 -0
- {vttcompilepy-0.0.1.7 → vttcompilepy-0.0.1.9}/vttcompilepy.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: vttcompilepy
|
|
3
|
-
Version: 0.0.1.
|
|
3
|
+
Version: 0.0.1.9
|
|
4
4
|
Summary: Python extension for Visual TrueType font compile.
|
|
5
5
|
Home-page: https://github.com/microsoft/VisualTrueType
|
|
6
6
|
Author: Paul Linnerud
|
|
@@ -10,6 +10,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
10
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
11
|
Requires-Python: >=3.7
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
|
+
Requires-Dist: fonttools>=4.33.0
|
|
13
14
|
|
|
14
15
|
# Project
|
|
15
16
|
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from io import open
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import platform
|
|
6
|
+
from setuptools import Extension, setup
|
|
7
|
+
from Cython.Build import cythonize
|
|
8
|
+
|
|
9
|
+
# from _version import __version__ as vttpy_version
|
|
10
|
+
|
|
11
|
+
here = os.path.abspath(os.path.dirname(__file__))
|
|
12
|
+
|
|
13
|
+
# Get the long description from the pypi.md file
|
|
14
|
+
with open(os.path.join(here, "pypi.md"), encoding="utf-8") as f:
|
|
15
|
+
long_description = f.read()
|
|
16
|
+
|
|
17
|
+
define_macros = [("UNICODE", 1), ("_UNICODE", 1)]
|
|
18
|
+
linetrace = False
|
|
19
|
+
if int(os.environ.get("CYTHON_LINETRACE", "0")):
|
|
20
|
+
linetrace = True
|
|
21
|
+
define_macros.append(("CYTHON_TRACE_NOGIL", "1"))
|
|
22
|
+
|
|
23
|
+
extra_compile_args = []
|
|
24
|
+
|
|
25
|
+
if platform.system() != "Windows":
|
|
26
|
+
extra_compile_args.append("-std=c++14")
|
|
27
|
+
|
|
28
|
+
if platform.system() == "Windows":
|
|
29
|
+
extra_compile_args.append("-sdl")
|
|
30
|
+
|
|
31
|
+
extension = Extension(
|
|
32
|
+
"vttcompilepy.vttcompilepy",
|
|
33
|
+
define_macros=define_macros,
|
|
34
|
+
include_dirs=[".", "src"],
|
|
35
|
+
sources=[
|
|
36
|
+
"vttcompilepy/vttcompilepy.pyx",
|
|
37
|
+
"src/application.cpp",
|
|
38
|
+
"src/CvtManager.cpp",
|
|
39
|
+
"src/File.cpp",
|
|
40
|
+
"src/List.cpp",
|
|
41
|
+
"src/MathUtils.cpp",
|
|
42
|
+
"src/Memory.cpp",
|
|
43
|
+
"src/Platform.cpp",
|
|
44
|
+
"src/TextBuffer.cpp",
|
|
45
|
+
"src/TMTParser.cpp",
|
|
46
|
+
"src/TTAssembler.cpp",
|
|
47
|
+
"src/TTEngine.cpp",
|
|
48
|
+
"src/TTFont.cpp",
|
|
49
|
+
"src/TTGenerator.cpp",
|
|
50
|
+
"src/Variation.cpp",
|
|
51
|
+
"src/VariationInstance.cpp",
|
|
52
|
+
"src/VariationModels.cpp",
|
|
53
|
+
"src/ttiua.cpp",
|
|
54
|
+
],
|
|
55
|
+
language="c++",
|
|
56
|
+
extra_compile_args=extra_compile_args,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
setup(
|
|
60
|
+
name="vttcompilepy",
|
|
61
|
+
# version= vttpy_version,
|
|
62
|
+
version="0.0.1.9",
|
|
63
|
+
description="Python extension for Visual TrueType font compile. ",
|
|
64
|
+
long_description=long_description,
|
|
65
|
+
long_description_content_type="text/markdown",
|
|
66
|
+
author="Paul Linnerud",
|
|
67
|
+
author_email="paulli@microsoft.com",
|
|
68
|
+
url="https://github.com/microsoft/VisualTrueType",
|
|
69
|
+
license="MIT",
|
|
70
|
+
classifiers=[
|
|
71
|
+
"Programming Language :: Python :: 3",
|
|
72
|
+
"License :: OSI Approved :: MIT License",
|
|
73
|
+
],
|
|
74
|
+
package_dir={"": "."},
|
|
75
|
+
packages=["vttcompilepy"],
|
|
76
|
+
zip_safe=False,
|
|
77
|
+
install_requires=[
|
|
78
|
+
"fonttools>=4.33.0",
|
|
79
|
+
],
|
|
80
|
+
python_requires=">=3.7",
|
|
81
|
+
ext_modules=cythonize(
|
|
82
|
+
extension,
|
|
83
|
+
annotate=bool(int(os.environ.get("CYTHON_ANNOTATE", "0"))),
|
|
84
|
+
compiler_directives={"linetrace": linetrace},
|
|
85
|
+
),
|
|
86
|
+
entry_points={
|
|
87
|
+
"console_scripts": [
|
|
88
|
+
"vttcompilepy = vttcompilepy.__main__:main",
|
|
89
|
+
"quit_to_glyphs = vttcompilepy.quit_to_glyphs:main",
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
)
|
|
@@ -122,9 +122,20 @@ void TextBuffer::SetText(int32_t textLen, const char text[])
|
|
|
122
122
|
}
|
|
123
123
|
else
|
|
124
124
|
{
|
|
125
|
-
std::
|
|
126
|
-
|
|
127
|
-
|
|
125
|
+
std::wstring wstr;
|
|
126
|
+
std::string str(reinterpret_cast<const char*>(text), textLen);
|
|
127
|
+
try
|
|
128
|
+
{
|
|
129
|
+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
|
130
|
+
wstr = converter.from_bytes(str);
|
|
131
|
+
}
|
|
132
|
+
catch (const std::range_error)
|
|
133
|
+
{
|
|
134
|
+
// Some really old VTT source data has sequences that fail above conversion so we do a naive conversion as backup.
|
|
135
|
+
// Note that VTT desktop version of this code uses Windows MultiByteToWideChar() which seems more error resilient.
|
|
136
|
+
wstr.resize(str.length(), L' ');
|
|
137
|
+
std::copy(str.begin(), str.end(), wstr.begin());
|
|
138
|
+
}
|
|
128
139
|
|
|
129
140
|
this->SetText(wstr.length(), wstr.c_str());
|
|
130
141
|
}
|
|
@@ -354,4 +365,4 @@ bool TextBuffer::AssertTextSize(size_t deltaSize) {
|
|
|
354
365
|
this->text = tmpText;
|
|
355
366
|
}
|
|
356
367
|
return tmpText != NULL;
|
|
357
|
-
} // TextBuffer::AssertTextSize
|
|
368
|
+
} // TextBuffer::AssertTextSize
|
|
@@ -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()
|