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
Nested types
- TrueType::Bidi
- TrueType::Contour
- TrueType::Error
- TrueType::Font
- TrueType::FontCollection
- TrueType::FontCollectionHeader
- TrueType::GlyphOutline
- TrueType::HarfBuzz
- TrueType::HarfBuzzNotAvailable
- TrueType::IOHelpers
- TrueType::LayoutOptions
- TrueType::MalformedTableError
- TrueType::MissingTableError
- TrueType::OutlineError
- TrueType::OutlineExtractor
- TrueType::OutlinePoint
- TrueType::ParagraphLayout
- TrueType::ParseError
- TrueType::Parser
- TrueType::PointType
- TrueType::PositionedGlyph
- TrueType::ShapingOptions
- TrueType::SubsetError
- TrueType::SubsetOptions
- TrueType::Subsetter
- TrueType::TableRecord
- TrueType::Tables
- TrueType::TextAlign
- TrueType::TextDirection
- TrueType::TextLayout
- TrueType::TextLine
- TrueType::UnsupportedFormatError
- TrueType::ValidationResult
- TrueType::Validator
- TrueType::VariationInstance
- TrueType::Warning
- TrueType::WarningCollector
- TrueType::Woff
- TrueType::Woff2
- TrueType::Woff2GlyfTransform
- TrueType::Woff2Header
- TrueType::Woff2HmtxTransform
- TrueType::Woff2TableEntry
- TrueType::WoffHeader
- TrueType::WoffTableEntry