Formatting
ci / checks (push) Successful in 42m54s

This commit is contained in:
khodowany
2026-09-15 00:06:02 -05:00
parent 44e100985a
commit fe42d811fa
81 changed files with 4349 additions and 3340 deletions
+26 -28
View File
@@ -5,34 +5,32 @@ from pathlib import Path
from fontTools.pens.boundsPen import BoundsPen
from fontTools.ttLib import TTFont
def generate(font_path, output):
with TTFont(font_path) as font:
glyphs, cmap = font.getGlyphSet(), font.getBestCmap()
units = font['head'].unitsPerEm / 4
ranges = [(0xE050, 0xE06F), (0xE080, 0xE09F), (0xE0A0, 0xE0A5),
(0xE101, 0xE102), (0xE1E7, 0xE1E8), (0xE240, 0xE250),
(0xE260, 0xE270), (0xE4E0, 0xE4EE)]
records = []
for start, end in ranges:
for codepoint in range(start, end):
if codepoint not in cmap:
continue
pen = BoundsPen(glyphs)
glyphs[cmap[codepoint]].draw(pen)
if pen.bounds:
box = ', '.join(f'{v / units:.8f}F' for v in pen.bounds)
records.append(f' {{{codepoint}, {{{box}}}}},')
output.parent.mkdir(parents=True, exist_ok=True)
output.write_text('#pragma once\n#include <array>\n#include <cstdint>\nnamespace vamp_zero::font_data {\n'
'struct glyph { std::int32_t codepoint; std::array<float, 4> bounds; };\n'
f'inline constexpr std::array<glyph, {len(records)}> glyphs = {{{{\n'
+ '\n'.join(records) + '\n}};\n}\n', encoding='ascii')
with TTFont(font_path) as font:
glyphs, cmap = font.getGlyphSet(), font.getBestCmap()
units = font['head'].unitsPerEm / 4
ranges = [(0xE050, 0xE06F), (0xE080, 0xE09F), (0xE0A0, 0xE0A5),
(0xE101, 0xE102), (0xE1E7, 0xE1E8), (0xE240, 0xE250),
(0xE260, 0xE270), (0xE4E0, 0xE4EE)]
records = []
for start, end in ranges:
for codepoint in range(start, end):
if codepoint not in cmap:
continue
pen = BoundsPen(glyphs)
glyphs[cmap[codepoint]].draw(pen)
if pen.bounds:
box = ', '.join(f'{v / units:.8f}F' for v in pen.bounds)
records.append(f' {{{codepoint}, {{{box}}}}},')
output.parent.mkdir(parents=True, exist_ok=True)
output.write_text('#pragma once\n#include <array>\n#include <cstdint>\nnamespace vamp_zero::font_data {\n'
'struct glyph { std::int32_t codepoint; std::array<float, 4> bounds; };\n'
f'inline constexpr std::array<glyph, {len(records)}> glyphs = {{{{\n'
+ '\n'.join(records) + '\n}};\n}\n', encoding='ascii')
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--font', type=Path, required=True)
parser.add_argument('--output', type=Path, required=True)
args = parser.parse_args()
generate(args.font, args.output)
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--font', type=Path, required=True)
parser.add_argument('--output', type=Path, required=True)
args = parser.parse_args()
generate(args.font, args.output)