Class: Fontisan::Tables::Cvar
- Inherits:
-
Binary::BaseRecord
- Object
- BinData::Record
- Binary::BaseRecord
- Fontisan::Tables::Cvar
- Defined in:
- lib/fontisan/tables/cvar.rb
Overview
Parser for the ‘cvar’ (CVT Variations) table
The cvar table provides variation data for the Control Value Table (CVT) in TrueType variable fonts with hinting. The CVT contains scalar values that are referenced by TrueType instructions for grid-fitting.
Like gvar, this table uses a TupleVariationStore structure with packed delta values rather than ItemVariationStore.
Reference: OpenType specification, cvar table
Instance Attribute Summary collapse
-
#axis_count ⇒ Object
Get axis count from fvar table (needs to be provided externally) This is a placeholder that should be set by the caller.
Instance Method Summary collapse
-
#shared_point_numbers? ⇒ Boolean
Check if using shared point numbers.
-
#summary ⇒ Hash
Get summary of CVT variations.
-
#tuple_count ⇒ Integer
Get tuple count.
-
#tuple_variation_data(tuple_index) ⇒ Hash?
Parse CVT deltas for a specific tuple.
-
#tuple_variations ⇒ Array<Hash>
Parse tuple variation headers.
-
#valid? ⇒ Boolean
Check if table is valid.
-
#variation_data ⇒ String?
Get variation data section.
-
#version ⇒ Float
Get version as a float.
Methods inherited from Binary::BaseRecord
Instance Attribute Details
#axis_count ⇒ Object
Get axis count from fvar table (needs to be provided externally) This is a placeholder that should be set by the caller
53 54 55 |
# File 'lib/fontisan/tables/cvar.rb', line 53 def axis_count @axis_count end |
Instance Method Details
#shared_point_numbers? ⇒ Boolean
Check if using shared point numbers
47 48 49 |
# File 'lib/fontisan/tables/cvar.rb', line 47 def shared_point_numbers? (tuple_variation_count & 0x8000) != 0 end |
#summary ⇒ Hash
Get summary of CVT variations
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/fontisan/tables/cvar.rb', line 178 def summary { version: version, tuple_count: tuple_count, shared_points: shared_point_numbers?, data_offset: data_offset, tuples: tuple_variations.map do |t| { embedded_peak: t[:embedded_peak], intermediate: t[:intermediate], private_points: t[:private_points], peak: t[:peak], } end, } end |
#tuple_count ⇒ Integer
Get tuple count
40 41 42 |
# File 'lib/fontisan/tables/cvar.rb', line 40 def tuple_count tuple_variation_count & 0x0FFF end |
#tuple_variation_data(tuple_index) ⇒ Hash?
Parse CVT deltas for a specific tuple
This is a simplified parser that returns the raw delta data. Full delta unpacking would require knowing point counts and delta formats.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/fontisan/tables/cvar.rb', line 158 def tuple_variation_data(tuple_index) return nil if tuple_index >= tuple_count tuples = tuple_variations return nil if tuple_index >= tuples.length tuple = tuples[tuple_index] # Calculate data offset for this tuple # This is complex and requires walking through all previous tuples # For now, return tuple metadata { tuple: tuple, data_size: tuple[:data_size], } end |
#tuple_variations ⇒ Array<Hash>
Parse tuple variation headers
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/fontisan/tables/cvar.rb', line 58 def tuple_variations return @tuple_variations if @tuple_variations return @tuple_variations = [] if tuple_count.zero? data = raw_data # Tuple records start after header (8 bytes) offset = 8 count = tuple_count tuples = [] count.times do |_i| break if offset + 4 > data.bytesize header_data = data.byteslice(offset, 4) header = Variation::TupleVariationHeader.read(header_data) offset += 4 tuple_info = { data_size: header.variation_data_size, embedded_peak: header., intermediate: header.intermediate_region?, private_points: header.private_point_numbers?, shared_index: header.shared_tuple_index, } # Read peak tuple if embedded if header. && axis_count peak = Array.new(axis_count) do next nil if offset + 2 > data.bytesize coord_data = data.byteslice(offset, 2) offset += 2 value = coord_data.unpack1("n") signed = value > 0x7FFF ? value - 0x10000 : value signed / 16384.0 end.compact tuple_info[:peak] = peak end # Read intermediate region if present if header.intermediate_region? && axis_count start_tuple = Array.new(axis_count) do next nil if offset + 2 > data.bytesize coord_data = data.byteslice(offset, 2) offset += 2 value = coord_data.unpack1("n") signed = value > 0x7FFF ? value - 0x10000 : value signed / 16384.0 end.compact end_tuple = Array.new(axis_count) do next nil if offset + 2 > data.bytesize coord_data = data.byteslice(offset, 2) offset += 2 value = coord_data.unpack1("n") signed = value > 0x7FFF ? value - 0x10000 : value signed / 16384.0 end.compact tuple_info[:start] = start_tuple tuple_info[:end] = end_tuple end tuples << tuple_info end @tuple_variations = tuples rescue StandardError => e warn "Failed to parse cvar tuple variations: #{e.}" @tuple_variations = [] end |
#valid? ⇒ Boolean
Check if table is valid
198 199 200 |
# File 'lib/fontisan/tables/cvar.rb', line 198 def valid? major_version == 1 && minor_version.zero? end |
#variation_data ⇒ String?
Get variation data section
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/fontisan/tables/cvar.rb', line 139 def variation_data return @variation_data if defined?(@variation_data) data = raw_data offset = data_offset return @variation_data = nil if offset >= data.bytesize @variation_data = data.byteslice(offset..-1) end |
#version ⇒ Float
Get version as a float
33 34 35 |
# File 'lib/fontisan/tables/cvar.rb', line 33 def version major_version + (minor_version / 10.0) end |