Class: Fontisan::Woff2::CollectionEncoder
- Inherits:
-
Object
- Object
- Fontisan::Woff2::CollectionEncoder
- Defined in:
- lib/fontisan/woff2/collection_encoder.rb
Overview
Encodes a TTC/OTC font collection into WOFF2 collection format per spec section 4.2.
Output layout:
[WOFF2Header (48 bytes, flavor = 'ttcf')]
[TableDirectory] # one entry per unique table
[CollectionDirectory] # CollectionHeader + N CollectionFontEntry
[CompressedFontData] # single brotli stream of all tables
Each font references tables via indices in its CollectionFontEntry. Identical tables across fonts share a single directory entry.
Per spec section 5.5, glyf/loca pairs from the same font MUST be adjacent (loca immediately follows glyf) in the directory.
Constant Summary collapse
- TTC_FLAVOR =
'ttcf'
0x74746366
Instance Method Summary collapse
-
#encode_fonts(fonts) ⇒ String
Encode an array of fonts as a WOFF2 collection.
-
#initialize(brotli_quality: 11) ⇒ CollectionEncoder
constructor
A new instance of CollectionEncoder.
Constructor Details
#initialize(brotli_quality: 11) ⇒ CollectionEncoder
Returns a new instance of CollectionEncoder.
26 27 28 |
# File 'lib/fontisan/woff2/collection_encoder.rb', line 26 def initialize(brotli_quality: 11) @brotli_quality = brotli_quality end |
Instance Method Details
#encode_fonts(fonts) ⇒ String
Encode an array of fonts as a WOFF2 collection.
34 35 36 37 38 39 40 41 42 |
# File 'lib/fontisan/woff2/collection_encoder.rb', line 34 def encode_fonts(fonts) raise ArgumentError, "fonts cannot be empty" if fonts.nil? || fonts.empty? prepared = fonts.map.with_index { |font, i| prepare_font(font, i) } _, font_to_ckeys = deduplicate(prepared) layout = build_layout(prepared, font_to_ckeys) compressed = compress_stream(layout) assemble(fonts:, layout:, font_to_ckeys:, compressed:) end |