Class: Fontisan::Tables::Cff::TableBuilder
- Inherits:
-
Object
- Object
- Fontisan::Tables::Cff::TableBuilder
- Defined in:
- lib/fontisan/tables/cff/table_builder.rb
Overview
Rebuilds CFF table with modifications
This builder extracts sections from a source CFF table, applies modifications (e.g., hint parameters to Private DICT), recalculates offsets, and assembles a new CFF table.
Process:
- Extract all CFF sections (header, indexes, dicts)
- Apply modifications to Private DICT
- Recalculate offsets (charstrings, private)
- Rebuild Top DICT INDEX with new offsets
- Reassemble all sections into new CFF table
Class Method Summary collapse
-
.rebuild(source_cff, modifications = {}) ⇒ String
Rebuild CFF table with modifications.
Instance Method Summary collapse
-
#apply_modifications(mods) ⇒ Object
Apply modifications to CFF structure.
-
#initialize(source_cff) ⇒ TableBuilder
constructor
Initialize with source CFF.
-
#serialize ⇒ String
Serialize to binary CFF table.
Constructor Details
#initialize(source_cff) ⇒ TableBuilder
Initialize with source CFF
40 41 42 43 |
# File 'lib/fontisan/tables/cff/table_builder.rb', line 40 def initialize(source_cff) @source = source_cff @sections = extract_sections end |
Class Method Details
.rebuild(source_cff, modifications = {}) ⇒ String
Rebuild CFF table with modifications
31 32 33 34 35 |
# File 'lib/fontisan/tables/cff/table_builder.rb', line 31 def self.rebuild(source_cff, modifications = {}) new(source_cff).tap do |builder| builder.apply_modifications(modifications) end.serialize end |
Instance Method Details
#apply_modifications(mods) ⇒ Object
Apply modifications to CFF structure
48 49 50 51 |
# File 'lib/fontisan/tables/cff/table_builder.rb', line 48 def apply_modifications(mods) update_private_dict(mods[:private_dict_hints]) if mods[:private_dict_hints] update_charstrings(mods[:per_glyph_hints]) if mods[:per_glyph_hints] end |
#serialize ⇒ String
Serialize to binary CFF table
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fontisan/tables/cff/table_builder.rb', line 56 def serialize # Calculate initial offsets offsets = OffsetRecalculator.calculate_offsets(@sections) top_dict = extract_top_dict_data updated = OffsetRecalculator.update_top_dict(top_dict, offsets) rebuild_top_dict_index(updated) # Recalculate after Top DICT rebuild (size may change) offsets = OffsetRecalculator.calculate_offsets(@sections) updated = OffsetRecalculator.update_top_dict(top_dict, offsets) rebuild_top_dict_index(updated) assemble end |