Class: Fontisan::OutlineExtractor
- Inherits:
-
Object
- Object
- Fontisan::OutlineExtractor
- Defined in:
- lib/fontisan/outline_extractor.rb
Overview
Extracts glyph outlines from font tables
OutlineExtractor 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
GlyphOutlineobjects
This class is responsible for extraction only, not business logic or
presentation. It's designed to be composed with
GlyphAccessor for higher-level operations.
Reference: docs/GETTING_STARTED.md:125-172
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
41 42 43 44 45 46 47 48 49 |
# File 'lib/fontisan/outline_extractor.rb', line 41 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.
35 36 37 |
# File 'lib/fontisan/outline_extractor.rb', line 35 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.
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fontisan/outline_extractor.rb', line 71 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 |