class TTFunk::Table::Hmtx
Constants
- HorizontalMetric
Attributes
left_side_bearings[R]
metrics[R]
widths[R]
Public Class Methods
encode(hmtx, mapping)
click to toggle source
# File lib/ttfunk/table/hmtx.rb, line 12 def self.encode(hmtx, mapping) metrics = mapping.keys.sort.map do |new_id| metric = hmtx.for(mapping[new_id]) [metric.advance_width, metric.left_side_bearing] end { number_of_metrics: metrics.length, table: metrics.flatten.pack('n*') } end
Public Instance Methods
for(glyph_id)
click to toggle source
# File lib/ttfunk/table/hmtx.rb, line 27 def for(glyph_id) @metrics[glyph_id] || metrics_cache[glyph_id] ||= HorizontalMetric.new( @metrics.last.advance_width, @left_side_bearings[glyph_id - @metrics.length] ) end
Private Instance Methods
metrics_cache()
click to toggle source
# File lib/ttfunk/table/hmtx.rb, line 38 def metrics_cache @metrics_cache ||= {} end
parse!()
click to toggle source
# File lib/ttfunk/table/hmtx.rb, line 42 def parse! @metrics = [] file.horizontal_header.number_of_metrics.times do advance = read(2, 'n').first lsb = read_signed(1).first @metrics.push HorizontalMetric.new(advance, lsb) end lsb_count = file.maximum_profile.num_glyphs - file.horizontal_header.number_of_metrics @left_side_bearings = read_signed(lsb_count) @widths = @metrics.map(&:advance_width) @widths += [@widths.last] * @left_side_bearings.length end