Class: Fontisan::Tables::Cff2::TableBuilder

Inherits:
Fontisan::Tables::Cff::TableBuilder show all
Defined in:
lib/fontisan/tables/cff2/table_builder.rb

Overview

Rebuilds CFF2 table with modifications while preserving variation data

CFF2TableBuilder extends CFF TableBuilder to handle CFF2-specific structures including Variable Store and blend operators in CharStrings. It preserves variation data while applying hints to variable fonts.

Key Principles:

  • Variable Store is read-only and preserved unchanged

  • Blend operators in CharStrings are maintained

  • Blend in Private DICT is preserved

  • Reuses Phase 1+2 infrastructure for CharString modification

Reference: Adobe Technical Note #5177 (CFF2)

Examples:

Rebuild CFF2 with hints

reader = CFF2TableReader.new(cff2_data)
builder = CFF2TableBuilder.new(reader, hint_set)
new_cff2 = builder.build

Constant Summary collapse

INVALID_CFF_KEYS =

CFF2-specific operators not supported by CFF DictBuilder

[24].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Fontisan::Tables::Cff::TableBuilder

#apply_modifications, rebuild, #serialize

Constructor Details

#initialize(reader, hint_set = nil) ⇒ TableBuilder

Initialize builder with CFF2 table reader and hint set

Parameters:

  • reader (CFF2TableReader)

    CFF2 table reader

  • hint_set (Object) (defaults to: nil)

    Hint set with font-level and per-glyph hints



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fontisan/tables/cff2/table_builder.rb', line 50

def initialize(reader, hint_set = nil)
  @reader = reader
  @hint_set = hint_set

  # Read CFF2 structures
  @reader.read_header
  @reader.read_top_dict
  @variable_store = @reader.read_variable_store

  # Determine number of axes from Variable Store
  @num_axes = extract_num_axes

  # Don't call super - CFF2 has different structure
end

Instance Attribute Details

#num_axesInteger (readonly)

Returns Number of variation axes.

Returns:

  • (Integer)

    Number of variation axes



44
45
46
# File 'lib/fontisan/tables/cff2/table_builder.rb', line 44

def num_axes
  @num_axes
end

#readerCFF2TableReader (readonly)

Returns CFF2 table reader.

Returns:

  • (CFF2TableReader)

    CFF2 table reader



38
39
40
# File 'lib/fontisan/tables/cff2/table_builder.rb', line 38

def reader
  @reader
end

#variable_storeHash? (readonly)

Returns Variable Store data.

Returns:

  • (Hash, nil)

    Variable Store data



41
42
43
# File 'lib/fontisan/tables/cff2/table_builder.rb', line 41

def variable_store
  @variable_store
end

Instance Method Details

#buildString

Build CFF2 table with hints applied

Returns:

  • (String)

    Binary CFF2 table data



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/fontisan/tables/cff2/table_builder.rb', line 68

def build
  # Check if we need to modify anything
  return @reader.data unless should_modify?

  # Extract and modify sections
  header_data = extract_header
  top_dict_hash = @reader.top_dict
  charstrings_data = extract_and_modify_charstrings
  private_dict_data = extract_and_modify_private_dict
  vstore_data = extract_variable_store

  # Rebuild CFF2 table
  rebuild_cff2_table(
    header: header_data,
    top_dict: top_dict_hash,
    charstrings: charstrings_data,
    private_dict: private_dict_data,
    vstore: vstore_data,
  )
end

#variable?Boolean

Check if table has variation data

Returns:

  • (Boolean)

    True if Variable Store present



92
93
94
# File 'lib/fontisan/tables/cff2/table_builder.rb', line 92

def variable?
  !@variable_store.nil?
end