Class: Fontisan::Tables::Cff::OffsetRecalculator
- Inherits:
-
Object
- Object
- Fontisan::Tables::Cff::OffsetRecalculator
- Defined in:
- lib/fontisan/tables/cff/offset_recalculator.rb
Overview
Recalculates CFF table offsets after structure modifications
When the Private DICT size changes (e.g., adding hint parameters), all offsets in the CFF table must be recalculated. This class computes new offsets based on section sizes.
CFF Structure (sequential layout):
-
Header (fixed size)
-
Name INDEX
-
Top DICT INDEX (contains offsets to CharStrings and Private DICT)
-
String INDEX
-
Global Subr INDEX
-
CharStrings INDEX
-
Private DICT (variable size)
-
Local Subr INDEX (optional, within Private DICT)
Key offsets to recalculate:
-
charstrings: Offset from CFF start to CharStrings INDEX
-
private: [size, offset] in Top DICT pointing to Private DICT
Class Method Summary collapse
-
.calculate_offsets(sections) ⇒ Hash
Calculate offsets for all CFF sections.
-
.update_top_dict(top_dict, offsets) ⇒ Hash
Update Top DICT with new offsets.
Class Method Details
.calculate_offsets(sections) ⇒ Hash
Calculate offsets for all CFF sections
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fontisan/tables/cff/offset_recalculator.rb', line 30 def self.calculate_offsets(sections) offsets = {} pos = 0 # Track position through CFF structure pos += sections[:header].bytesize pos += sections[:name_index].bytesize # Top DICT INDEX starts here offsets[:top_dict_start] = pos pos += sections[:top_dict_index].bytesize pos += sections[:string_index].bytesize pos += sections[:global_subr_index].bytesize # CharStrings INDEX offset (referenced in Top DICT) offsets[:charstrings] = pos pos += sections[:charstrings_index].bytesize # Private DICT offset and size (referenced in Top DICT) offsets[:private] = pos offsets[:private_size] = sections[:private_dict].bytesize offsets end |
.update_top_dict(top_dict, offsets) ⇒ Hash
Update Top DICT with new offsets
61 62 63 64 65 66 |
# File 'lib/fontisan/tables/cff/offset_recalculator.rb', line 61 def self.update_top_dict(top_dict, offsets) updated = top_dict.dup updated[:charstrings] = offsets[:charstrings] updated[:private] = [offsets[:private_size], offsets[:private]] updated end |