Skip to content

fveilly/opentype-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opentype-rs Build Status

Safe, fast and memory efficient OpenType font file parser

Overview

The OpenType font format is an extension of the TrueType font format, adding support for PostScript font data. The OpenType font format was developed jointly by Microsoft and Adobe. OpenType fonts and the operating system services which support OpenType fonts provide users with a simple way to install and use fonts, whether the fonts contain TrueType outlines or CFF (PostScript) outlines.

See OpenType® specification for details.

Example

extern crate opentype_rs as otf;

use otf::OpenTypeFontFile;
use otf::tables::TableTag;
use otf::tables::head::FontHeaderTable;
use otf::tables::name::NamingTable;
use otf::traits::TableParser;

fn main() {
    let buf = include_bytes!("../fonts/Roboto/Roboto-Regular.ttf") as &[u8];
    let otff = OpenTypeFontFile::parse(buf).unwrap();

    for font in otff {
        for table in font.iter() {
            match table.tag() {
                TableTag::Head => {
                    let font_header_table = FontHeaderTable::parse_table(&table).unwrap();
                    assert_eq!(font_header_table.font_revision(), 140050);
                },
                TableTag::Name => {
                    let naming_table = NamingTable::parse_table(&table).unwrap();
                    assert_eq!(naming_table.string_offset(), 318);
                },
                _ => {}
            }
        }
    }
}

Support

opentype-rs is in early stage and the public APIs are still likely to change.

Required Tables

  • cmap: Character to glyph mapping
  • head: Font header
  • hhea: Horizontal header
  • hmtx: Horizontal metrics
  • maxp: Maximum profile
  • name: Naming table
  • OS/2: OS/2 and Windows specific metrics
  • post: PostScript information

Tables Related to TrueType Outlines

  • cvt: Control Value Table (optional table)
  • fpgm: Font program (optional table)
  • glyf: Glyph data
  • loca: Index to location
  • prep: CVT Program (optional table)
  • gasp: Grid-fitting/Scan-conversion (optional table)

Tables Related to CFF Outlines

  • CFF: Compact Font Format 1.0
  • CFF2: Compact Font Format 2.0
  • VORG: Vertical Origin (optional table)

Table Related to SVG Outlines

  • SVG: The SVG (Scalable Vector Graphics) table

Tables Related to Bitmap Glyphs

  • EBDT: Embedded bitmap data
  • EBLC: Embedded bitmap location data
  • EBSC: Embedded bitmap scaling data
  • CBDT: Color bitmap data
  • CBLC: Color bitmap location data
  • sbix: Standard bitmap graphics

Advanced Typographic Tables

  • BASE: Baseline data
  • GDEF: Glyph definition data
  • GPOS: Glyph positioning data
  • GSUB: Glyph substitution data
  • JSTF: Justification data
  • MATH: Math layout data

Tables used for OpenType Font Variations

  • avar: Axis variations
  • cvar: CVT variations (TrueType outlines only)
  • fvar: Font variations
  • gvar: Glyph variations (TrueType outlines only)
  • HVAR: Horizontal metrics variations
  • MVAR: Metrics variations
  • STAT: Style attributes (required for variable fonts, optional for non-variable fonts)
  • VVAR: Vertical metrics variations

Tables Related to Color Fonts

  • COLR: Color table
  • CPAL: Color palette table
  • CBDT: Color bitmap data
  • CBLC: Color bitmap location data
  • sbix: Standard bitmap graphics
  • SVG: The SVG (Scalable Vector Graphics) table

Other OpenType Tables

  • DSIG: Digital signature
  • hdmx: Horizontal device metrics
  • kern: Kerning
  • LTSH: Linear threshold data
  • MERG: Merge
  • meta: Metadata
  • STAT: Style attributes
  • PCLT: PCL 5 data
  • VDMX: Vertical device metrics
  • vhea: Vertical Metrics header
  • vmtx: Vertical Metrics

License

opentype-rs is distributed under the terms of the MIT license.

See LICENSE-MIT for details.

About

Safe, fast and memory efficient OpenType font file parser

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages