This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 310
/
force_yminmax.py
executable file
·64 lines (50 loc) · 1.87 KB
/
force_yminmax.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
#
# Copyright 2015 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Post-subset changes for Roboto for Android."""
import sys
from fontTools import ttLib
from nototools import font_data
def output_protruding_glyphs(font, ymin, ymax):
"""Outputs all glyphs going outside the specified vertical range."""
protruding_glyphs = []
glyf_table = font['glyf']
for glyph_name in glyf_table.keys():
glyph = glyf_table[glyph_name]
if glyph.numberOfContours == 0:
continue
if glyph.yMin < ymin or glyph.yMax > ymax:
protruding_glyphs.append(glyph_name)
if protruding_glyphs:
print "Protruding glyphs in %s:" % font_data.font_name(font),
print ', '.join(sorted(protruding_glyphs))
YMIN = -555
YMAX = 2163
def main(argv):
"""Forces yMin/yMax values and generates a new font."""
source_font_name = argv[1]
target_font_name = argv[2]
font = ttLib.TTFont(source_font_name, recalcBBoxes=False)
head = font['head']
head.yMin = YMIN
head.yMax = YMAX
output_protruding_glyphs(font, YMIN, YMAX)
font.save(target_font_name)
# Make sure the values are set correctly
font = ttLib.TTFont(target_font_name, recalcBBoxes=False)
head = font['head']
assert head.yMin == YMIN and head.yMax == YMAX
if __name__ == "__main__":
main(sys.argv)