GithubHelp home page GithubHelp logo

isabella232 / compositor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from robotools/compositor

0.0 0.0 0.0 347 KB

A basic OpenType GSUB and GPOS layout engine.

License: MIT License

Python 100.00%

compositor's Introduction

compositor

A basic OpenType GSUB and GPOS layout engine written in Python.

Table of Contents


Usage Reference

This document covers the basic usage of the compositor package. For more detailed information read the documentation strings in the source.

Assumptions

Some assumptions about the OpenType fonts being used are made by the package:

  • The font is valid.
  • The font's cmap table contains Platform 3 Encoding 1.
  • The font does not contain GSUB or GPOS lookup types that are not supported by the GSUB or GPOS objects. If an unsupported lookup type is present, the lookup will simply be ignored. It will not raise an error.

The Font Object

Importing

from compositor import Font

Construction

font = Font(path)
path
A path to an OpenType font.

Special Behavior

glyph = font["aGlyphName"]

Returns the glyph object named aGlyphName. This will raise a KeyError if aGlyphName is not in the font.

isThere = "aGlyphName" in font

Returns a boolean representing if aGlyphName is in the font.

Methods

font.keys()

A list of all glyph names in the font.

glyphRecords = font.process(aString)

This is the most important method. It takes a string (Unicode or plain ASCII) and processes it with the features defined in the font's GSUB and GPOS tables. A list of GlyphRecord objects will be returned.

featureTags = font.getFeatureList()

A list of all available features in GSUB and GPOS.

state = font.getFeatureState(featureTag)

Get a boolean representing if a feature is on or not. This assumes that the feature state is consistent in both the GSUB and GPOS tables. A CompositorError will be raised if the feature is inconsistently applied. A CompositorError will be raised if featureTag is not defined in GSUB or GPOS.

font.setFeatureState(self, featureTag, state)

Set the application state of a feature.

Attributes

info
The Info object for the font.

The GlyphRecord Object

Attributes

glyphName
The name of the referenced glyph.
xPlacement
Horizontal placement.
yPlacement
Vertical placement.
xAdvance
Horizontal adjustment for advance.
yAdvance
Vertical adjustment for advance.
alternates
A list of `GlyphRecords` indicating alternates for the glyph.

The Glyph Object

Methods

glyph.draw(pen)

Draws the glyph with a FontTools pen.

Attributes

name
The name of the glyph.
index
The glyph's index within the source font.
width
The width of the glyph.
bounds
The bounding box for the glyph. Formatted as `(xMin, yMin, xMax, yMax)`. If the glyph contains no outlines, this will return `None`.

The Info Object

Attributes

  • familyName
  • styleName
  • unitsPerEm
  • ascender
  • descender

Development

Relationship to the GSUB and GPOS Specification

The Compositor GSUB and GPOS tables adhere as closely as possible to the GSUB and GPOS specification. Every effort has been made to keep terminology consistent. All known deviations from the spec are documented. (The deviations are generally trivial. For example, most the of the subtables don't implement the Count attributes. This is done because the Python iterator provides a more convenient and faster way to deal with iteration than creating a range. Therefore, the Count objects are not needed.)

Object Loading

For performance reasons, when a new font is loaded, all of the GSUB and GPOS data is extracted from the font with fontTools. The data is placed into compositor objects. These objects are then used to process text. This initial loading can be relatively expensive, but the processing speed of the objects is worth the initial expense.

Installation

To install this package, type the following in the command line:

python setup.py install

compositor's People

Contributors

typesupply avatar benkiel avatar adrientetar avatar typemytype avatar jenskutilek avatar gferreira avatar justvanrossum 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.