Git Product home page Git Product logo

zttf's Introduction

zttf

Python TTF file parser

This was written to allow fonts to be parsed and then subsets generated for use in a PDF documents.

It was developed using Python 3.4 and will work to a degree with Python 2 it needs additional testing and development there.

Simple Usage

>>> from zttf.ttfile import TTFile
>>> font_file = TTFile('DroidSans.ttf')
>>> font_file.is_valid
True
>>> font_file.faces
[<zttf.ttf.TTFont object at 0x7f3569b73b50>]
>>> face = font_file.faces[0]
>>> face.family_name
Droid Sans
>>> face.name
DroidSans
>>> face.italic_angle
0

When used with a font collection, there will be multiple faces available.

>>> from zttf.ttfile import TTFile
>>> font_file = TTFile('Futura.ttc')
>>> font_file.is_valid
True
>>> font_file.faces
[<zttf.ttf.TTFont object at 0x7fc97520bc50>, <zttf.ttf.TTFont object at 0x7fc97520bc90>, <zttf.ttf.TTFont object at 0x7fc97520bd90>, <zttf.ttf.TTFont object at 0x7fc973b4c190>]
>>> font_file.faces[0].font_family
Futura
>>> font_file.faces[0].name
Futura-Medium
>>> font_file.faces[1].name
Futura-MediumItalic
>>> font_file.faces[2].name
Futura-CondensedMedium
>>> font_file.faces[3].name
Futura-CondensedExtraBold

Subsetting is done by passing in a subset of the characters desired. All required glyphs will be found and copied into the new file.

>>> from zttf.ttfile import TTFile
>>> font_file = TTFile('Futura.ttc')
>>> subset = [ord('H'), ord('e'), ord('l'), ord('o')]
>>> sub_font = font_file.faces[0].make_subset(subset)
>>> sub_font.output()
...
>>> with open('new_font.ttf', 'wb') as fh:
        fh.write(sub_font.output())

zttf's People

Contributors

arpruss avatar zathras777 avatar

Stargazers

John Bates avatar Edgespresso avatar Marc L. avatar Eric Cartner avatar  avatar Ivan Mironov avatar Jurriaan Pruis avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.