forked from adam7/delugia-code
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- correcting `xAvgCharWidth` using `ttx` from `fonttools` - build hdmx table for odd and hinted ppems
- Loading branch information
Showing
2 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#! /usr/bin/python | ||
|
||
# credit: https://github.com/be5invis/Sarasa-Gothic/issues/108#issuecomment-517240248 | ||
|
||
# usage: | ||
# python build-hdmx-for-sarasa.py your-sarasa-font.ttf | ||
|
||
import sys | ||
import math | ||
|
||
from fontTools.ttLib import TTFont, newTable | ||
|
||
|
||
def main(): | ||
headFlagInstructionsMayAlterAdvanceWidth = 0x0010 | ||
sarasaHintPpemMin = 11 | ||
sarasaHintPpemMax = 48 | ||
|
||
filename = sys.argv[1] | ||
|
||
font = TTFont(filename, recalcBBoxes=False) | ||
|
||
originFontHead = font["head"] | ||
originFontHmtx = font["hmtx"] | ||
|
||
originFontHead.flags |= headFlagInstructionsMayAlterAdvanceWidth | ||
|
||
hdmxTable = newTable("hdmx") | ||
hdmxTable.hdmx = {} | ||
|
||
# build hdmx table for odd and hinted ppems only. | ||
for ppem in range( | ||
math.floor(sarasaHintPpemMin / 2) * 2 + 1, sarasaHintPpemMax + 1, 2 | ||
): | ||
halfUpm = originFontHead.unitsPerEm / 2 | ||
halfPpem = math.ceil(ppem / 2) | ||
hdmxTable.hdmx[ppem] = { | ||
name: math.ceil(width / halfUpm) * halfPpem | ||
for name, (width, _) in originFontHmtx.metrics.items() | ||
} | ||
|
||
font["hdmx"] = hdmxTable | ||
|
||
font.save(filename) | ||
font.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
145000b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit should be able to resolve #1