class TTFunk::Table::Head

Attributes

checksum_adjustment[R]
created[R]
flags[R]
font_direction_hint[R]
font_revision[R]
glyph_data_format[R]
index_to_loc_format[R]
lowest_rec_ppem[R]
mac_style[R]
magic_number[R]
modified[R]
units_per_em[R]
version[R]
x_max[R]
x_min[R]
y_max[R]
y_min[R]

Public Class Methods

encode(head, loca, mapping) click to toggle source

mapping is new -> old glyph ids

# File lib/ttfunk/table/head.rb, line 28
def encode(head, loca, mapping)
  EncodedString.new do |table|
    table <<
      [head.version, head.font_revision].pack('N2') <<
      Placeholder.new(:checksum, length: 4) <<
      [
        head.magic_number,
        head.flags, head.units_per_em,
        head.created, head.modified,
        *min_max_values_for(head, mapping),
        head.mac_style, head.lowest_rec_ppem, head.font_direction_hint,
        loca[:type] || 0, head.glyph_data_format
      ].pack('Nn2q2n*')
  end
end

Private Class Methods

min_max_values_for(head, mapping) click to toggle source
# File lib/ttfunk/table/head.rb, line 46
def min_max_values_for(head, mapping)
  x_min = Min.new
  x_max = Max.new
  y_min = Min.new
  y_max = Max.new

  mapping.each do |_, old_glyph_id|
    glyph = head.file.find_glyph(old_glyph_id)
    next unless glyph

    x_min << glyph.x_min
    x_max << glyph.x_max
    y_min << glyph.y_min
    y_max << glyph.y_max
  end

  [
    x_min.value_or(0), y_min.value_or(0),
    x_max.value_or(0), y_max.value_or(0)
  ]
end

Private Instance Methods

parse!() click to toggle source
# File lib/ttfunk/table/head.rb, line 71
def parse!
  @version, @font_revision, @check_sum_adjustment, @magic_number,
    @flags, @units_per_em, @created, @modified = read(36, 'N4n2q2')

  @x_min, @y_min, @x_max, @y_max = read_signed(4)

  @mac_style, @lowest_rec_ppem, @font_direction_hint,
    @index_to_loc_format, @glyph_data_format = read(10, 'n*')
end