Class: Fontisan::OutlineExtractor
- Inherits:
-
Object
- Object
- Fontisan::OutlineExtractor
- Defined in:
- lib/fontisan/outline_extractor.rb
Overview
Extracts glyph outlines from font tables
[‘OutlineExtractor`](lib/fontisan/outline_extractor.rb) provides a unified interface for extracting glyph outline data from both TrueType (glyf table) and CFF (Compact Font Format) fonts. It uses a strategy pattern to handle the different outline formats transparently.
The extractor:
-
Automatically detects font format (TrueType vs CFF)
-
Handles simple glyphs (direct outline data)
-
Handles compound glyphs (recursively resolves components)
-
Returns standardized [‘GlyphOutline`](lib/fontisan/models/glyph_outline.rb) objects
This class is responsible for extraction only, not business logic or presentation. It’s designed to be composed with [‘GlyphAccessor`](lib/fontisan/glyph_accessor.rb) for higher-level operations.
Reference: [‘docs/GETTING_STARTED.md:125-172`](docs/GETTING_STARTED.md:125)
Instance Attribute Summary collapse
-
#font ⇒ TrueTypeFont, OpenTypeFont
readonly
Font instance.
Instance Method Summary collapse
-
#extract(glyph_id) ⇒ Models::GlyphOutline?
Extract outline for a specific glyph.
-
#initialize(font) ⇒ OutlineExtractor
constructor
Initialize a new outline extractor.
Constructor Details
#initialize(font) ⇒ OutlineExtractor
Initialize a new outline extractor
43 44 45 46 47 48 49 50 51 |
# File 'lib/fontisan/outline_extractor.rb', line 43 def initialize(font) raise ArgumentError, "Font cannot be nil" if font.nil? unless font.respond_to?(:table) raise ArgumentError, "Font must respond to :table method" end @font = font end |
Instance Attribute Details
#font ⇒ TrueTypeFont, OpenTypeFont (readonly)
Returns Font instance.
37 38 39 |
# File 'lib/fontisan/outline_extractor.rb', line 37 def font @font end |
Instance Method Details
#extract(glyph_id) ⇒ Models::GlyphOutline?
Extract outline for a specific glyph
This method automatically detects the font format and delegates to the appropriate extraction strategy. For compound glyphs (TrueType only), it recursively resolves component outlines and combines them with proper transformations.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fontisan/outline_extractor.rb', line 73 def extract(glyph_id) validate_glyph_id!(glyph_id) if cff_font? extract_cff_outline(glyph_id) elsif truetype_font? extract_truetype_outline(glyph_id) else raise Fontisan::MissingTableError, "Font has neither glyf nor CFF table" end end |