API Reference
This section provides detailed API documentation for Fontisan's core classes, converters, validators, and models.
Core Classes
- FontLoader — Unified font loading with automatic format detection
- FontWriter — Write fonts to various formats
- ConversionOptions — Type-safe conversion configuration
- SfntFont — Base class for TrueType/OpenType fonts
- Type1Font — Adobe Type 1 font handler
Converters
- OutlineConverter — TTF ↔ OTF outline conversion
- CurveConverter — Quadratic ↔ Cubic curve conversion
- HintConverter — TrueType ↔ PostScript hint conversion
Validators
- FontValidator — Main validation entry point
- ValidationProfile — Validation profile definitions
- ValidationHelper — Individual validation helpers
Models
- Glyph — Font glyph representation
- GlyphAccessor — Unified glyph access with caching
- TableAnalyzer — Font table analysis
Using the API
Loading Fonts
ruby
require 'fontisan'
# Automatic format detection
font = Fontisan::FontLoader.load('font.ttf')
font = Fontisan::FontLoader.load('font.otf')
font = Fontisan::FontLoader.load('font.pfb')
# Load from IO
font = Fontisan::FontLoader.load(io)Converting Fonts
ruby
# Get recommended options
options = Fontisan::ConversionOptions.recommended(from: :ttf, to: :otf)
# Convert with options
converter = Fontisan::Converters::OutlineConverter.new
tables = converter.convert(font, options: options)
# Write the result
Fontisan::FontWriter.write(font, 'output.otf')Validating Fonts
ruby
# Validate with a profile
result = Fontisan::FontValidator.validate('font.ttf', profile: :google_fonts)
# Check results
if result.passed?
puts "Font is valid!"
else
result.errors.each do |error|
puts "#{error.code}: #{error.message}"
end
end