Class: Fontisan::Subset::TableSubsetter
- Inherits:
-
Object
- Object
- Fontisan::Subset::TableSubsetter
- Defined in:
- lib/fontisan/subset/table_subsetter.rb
Overview
Table-specific subsetting dispatcher.
Per-table subsetting logic lives in [TableStrategy] classes (one per OpenType tag). This class:
1. Holds the inputs to a subsetting run (font, mapping, options)
plus the cross-strategy [SharedState] (glyf/loca data, bbox,
max advance, color bitmap subsetter cache).
2. Dispatches `subset_table(tag, table)` to the right strategy
via [TableStrategy.for(tag)].
3. Keeps `subset_<tag>` wrappers for backward compatibility with
specs that exercise a single strategy in isolation.
Adding a new subsetting strategy does NOT require editing this
file — register it in lib/fontisan/subset/table_strategy.rb.
Instance Attribute Summary collapse
- #font ⇒ SfntFont readonly
- #mapping ⇒ GlyphMapping readonly
- #options ⇒ Options readonly
- #state ⇒ SharedState readonly
Instance Method Summary collapse
-
#initialize(font, mapping, options) ⇒ TableSubsetter
constructor
A new instance of TableSubsetter.
- #subset_cmap(table) ⇒ Object
- #subset_glyf(table) ⇒ Object
- #subset_head(table) ⇒ Object
- #subset_hhea(table, hmtx = nil) ⇒ Object
- #subset_hmtx(table) ⇒ Object
- #subset_loca(table) ⇒ Object
-
#subset_maxp(table) ⇒ Object
--- Backward-compat wrappers -------------------------------------- Specs and external callers may invoke
subset_<tag>(table)directly. - #subset_name(table) ⇒ Object
- #subset_os2(table) ⇒ Object
- #subset_post(table) ⇒ Object
-
#subset_table(tag, table) ⇒ String
Subset one table by dispatching to its strategy.
Constructor Details
#initialize(font, mapping, options) ⇒ TableSubsetter
Returns a new instance of TableSubsetter.
37 38 39 40 41 42 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 37 def initialize(font, mapping, ) @font = font @mapping = mapping @options = @state = SharedState.new end |
Instance Attribute Details
#font ⇒ SfntFont (readonly)
26 27 28 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 26 def font @font end |
#mapping ⇒ GlyphMapping (readonly)
29 30 31 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 29 def mapping @mapping end |
#options ⇒ Options (readonly)
32 33 34 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 32 def @options end |
#state ⇒ SharedState (readonly)
35 36 37 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 35 def state @state end |
Instance Method Details
#subset_cmap(table) ⇒ Object
82 83 84 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 82 def subset_cmap(table) subset_table("cmap", table) end |
#subset_glyf(table) ⇒ Object
74 75 76 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 74 def subset_glyf(table) subset_table("glyf", table) end |
#subset_head(table) ⇒ Object
94 95 96 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 94 def subset_head(table) subset_table("head", table) end |
#subset_hhea(table, hmtx = nil) ⇒ Object
65 66 67 68 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 65 def subset_hhea(table, hmtx = nil) _ = hmtx # ignored; the strategy recomputes from source hmtx subset_table("hhea", table) end |
#subset_hmtx(table) ⇒ Object
70 71 72 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 70 def subset_hmtx(table) subset_table("hmtx", table) end |
#subset_loca(table) ⇒ Object
78 79 80 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 78 def subset_loca(table) subset_table("loca", table) end |
#subset_maxp(table) ⇒ Object
--- Backward-compat wrappers --------------------------------------
Specs and external callers may invoke subset_<tag>(table)
directly. Each wrapper delegates to the corresponding strategy.
61 62 63 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 61 def subset_maxp(table) subset_table("maxp", table) end |
#subset_name(table) ⇒ Object
90 91 92 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 90 def subset_name(table) subset_table("name", table) end |
#subset_os2(table) ⇒ Object
98 99 100 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 98 def subset_os2(table) subset_table("OS/2", table) end |
#subset_post(table) ⇒ Object
86 87 88 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 86 def subset_post(table) subset_table("post", table) end |
#subset_table(tag, table) ⇒ String
Subset one table by dispatching to its strategy. Unknown tables fall through to [TableStrategy::PassThrough] which preserves the source bytes verbatim.
51 52 53 54 55 |
# File 'lib/fontisan/subset/table_subsetter.rb', line 51 def subset_table(tag, table) TableStrategy.for(tag).call( context: subset_context, tag: tag, table: table, ) end |