class TTFunk::Table::Hmtx
Horizontal Metrics (‘hmtx`) table.
Constants
- HorizontalMetric
-
Horyzontal glyph metric.
@!attribute [rw] advance_width
@return [Integer] Advance width.
@!attribute [rw] left_side_bearing
@return [Integer] Left side bearing.
Attributes
Left side bearings. @return [Array<Ingteger>]
Glyph horizontal metrics. @return [Array<HorizontalMetric>]
Glyph widths. @return [Array<Integer>]
Public Class Methods
Source
# File lib/ttfunk/table/hmtx.rb, line 29 def self.encode(hmtx, mapping) metrics = mapping.keys.sort.map { |new_id| metric = hmtx.for(mapping[new_id]) [metric.advance_width, metric.left_side_bearing] } { number_of_metrics: metrics.length, table: metrics.flatten.pack('n*'), } end
Encode table.
@param hmtx [TTFunk::Table::Hmtx] @param mapping [Hash{Integer => Integer}] keys are new glyph IDs, values
are old glyph IDs
@return [Hash{:number_of_metrics => Integer, :table => String}]
* `:number_of_metrics` - number of mertrics is the table. * `:table` - encoded table.
Public Instance Methods
Source
# File lib/ttfunk/table/hmtx.rb, line 54 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
Get horizontal metric for glyph.
@param glyph_id [Integer] @return [HorizontalMetric]
Private Instance Methods
Source
# File lib/ttfunk/table/hmtx.rb, line 65 def metrics_cache @metrics_cache ||= {} end
Source
# File lib/ttfunk/table/hmtx.rb, line 69 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