Skip to content

Simple Swift API for accessing font data from OpenType font files.

License

Notifications You must be signed in to change notification settings

mossprescott/OpenTypeSwift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenTypeSwift

Simple API for OpenType tables, extending CTFont. Core Text provides access to the raw data, this library just makes it nice to use from Swift, with named accessors for all supported values.

Example

Check if the MATH table is present:

let helvetica12 = CTFontCreateWithName("Helvetica" as CFString, 12.0, nil)
if let metrics = helvetica12.mathMetrics {
    print("That's surprising!")
}

Access a constant, scaled to the font size:

let lm12 = CTFontCreateWithName("Latin Modern Math" as CFString, 12.0, nil)
let metrics = lm12.mathMetrics!
print("axis height above baseline, in pts: \(metrics.axisHeight)")  // 3.0

Tests

The Latin Modern Math font is required to run the tests. It can be downloaded from CTAN.

Status

OpenType is a very large spec, with many archaic corners. This library isn't intended to be complete by any stretch.

In fact, it currently provides only the MathConstants values from the MATH table. If you'd like to see something else, please submit an issue or PR.

See also

CoreTextSwift uses a similar approach to expose the existing Core Text APIs in a nice way, and was an inspiration.

Microsoft's OpenType spec is the best reference.

About

Simple Swift API for accessing font data from OpenType font files.

Topics

Resources

License

Stars

Watchers

Forks

Languages