Created
May 1, 2019 09:14
-
-
Save AmitAronovitch/806f730b048cf8e5ec8827a7a8b6984a to your computer and use it in GitHub Desktop.
playing with ttf fonts
This file contains hidden or 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
from fontTools.ttLib import TTFont | |
class Tracer: | |
def __init__(self, name): | |
# print('initializing {}'.format(name)) | |
self.name = name | |
def __call__(self, *args): | |
# print('call {}(*{}, **{})'.format(self.name, args, kwargs)) | |
print('{}{}'.format(self.name, args)) | |
class MockPen: | |
def __getattr__(self, attr): | |
return Tracer(attr) | |
def char_range(first, last): | |
for i in range(ord(first), ord(last)+1): | |
yield chr(i) | |
def main(): | |
font = TTFont('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf') | |
gs = font.getGlyphSet() | |
for letter in char_range('A', 'D'): | |
print('drawing letter: ', letter) | |
gs[letter].draw(MockPen()) | |
print() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
requirements:
pip install fonttools
output: