Class: Fontisan::FontLoader
- Inherits:
-
Object
- Object
- Fontisan::FontLoader
- Defined in:
- lib/fontisan/font_loader.rb
Overview
FontLoader provides unified font loading with automatic format detection.
This class is the primary entry point for loading fonts in Fontisan. It automatically detects the font format and returns the appropriate domain object (TrueTypeFont, OpenTypeFont, TrueTypeCollection, or OpenTypeCollection).
Class Method Summary collapse
-
.load(path, font_index: 0) ⇒ TrueTypeFont, OpenTypeFont
Load a font from file with automatic format detection.
Class Method Details
.load(path, font_index: 0) ⇒ TrueTypeFont, OpenTypeFont
Load a font from file with automatic format detection
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fontisan/font_loader.rb', line 31 def self.load(path, font_index: 0) raise Errno::ENOENT, "File not found: #{path}" unless File.exist?(path) File.open(path, "rb") do |io| signature = io.read(4) io.rewind case signature when Constants::TTC_TAG load_from_collection(io, path, font_index) when pack_uint32(Constants::SFNT_VERSION_TRUETYPE) TrueTypeFont.from_file(path) when "OTTO" OpenTypeFont.from_file(path) when "wOFF" raise UnsupportedFormatError, "Unsupported font format: WOFF. Fontisan currently supports TTF, OTF, TTC, and OTC files." when "wOF2" raise UnsupportedFormatError, "Unsupported font format: WOFF2. Fontisan currently supports TTF, OTF, TTC, and OTC files." else raise InvalidFontError, "Unknown font format. Expected TTF, OTF, TTC, or OTC file." end end end |