module

TrueType

High-level Font API for TrueType/OpenType fonts.

This module provides a user-friendly, unified interface for working with fonts, with automatic format detection and convenient methods for common operations.

Quick Start

require "truetype"

# Open any font format with auto-detection
font = TrueType::Font.open("path/to/font.ttf") # TTF, OTF, WOFF, WOFF2, TTC/OTC

# Access font information
puts font.name            # "DejaVu Sans"
puts font.postscript_name # "DejaVuSans"
puts font.style           # "Regular"

# Basic text shaping
glyphs = font.shape("Hello!")
glyphs.each do |glyph|
  puts "Glyph #{glyph.id} at (#{glyph.x_offset}, #{glyph.y_offset})"
end

# Create a variable font instance
if font.variable?
  bold = font.instance(weight: 700)
  puts bold.shape("Bold text")
end

# Subset for embedding
subset = font.subset("Hello World!", preserve_hints: true)
File.write("subset.ttf", subset)

Constants

VERSION = "0.1.0"

Class methods

harfbuzz_available?

Returns true if HarfBuzz support is compiled in

Source

Nested types