class TTFunk::Table::Head

Font Header (‘head`) Table.

Constants

LONG_DATE_TIME_BASIS

Long date time (used in TTF headers). January 1, 1904 00:00:00 UTC basis used by Long date time. @see developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html

TrueType Font Tables

Attributes

checksum_adjustment[R]

Checksum adjustment. @return [Integer]

created[R]

Font creation time. @return [Integer] Long Date Time timestamp.

flags[R]

Flags. @return [Integer]

font_direction_hint[R]

Font direction hint. Deprecated, set to 2. @return [Integer]

font_revision[R]

Font revision. @return [Integer]

glyph_data_format[R]

Glyph data format. @return [Integer]

index_to_loc_format[R]

Index to Location format. @return [Integer]

lowest_rec_ppem[R]

Smallest readable size in pixels. @return [Integer]

mac_style[R]

Mac font style. @return [Integer]

magic_number[R]

Magic number. @return [Integer] must be ‘0x5F0F3CF5`

modified[R]

Font modification time. @return [Integer] Long Date Time timestamp.

units_per_em[R]

Units per Em. @return [Integer]

version[R]

Table version. @return [Integer]

x_max[R]

Maximum x coordinate across all glyph bounding boxes. @return [Integer]

x_min[R]

Minimum x coordinate across all glyph bounding boxes. @return [Integer]

y_max[R]

Maximum y coordinate across all glyph bounding boxes. @return [Integer]

y_min[R]

Minimum y coordinate across all glyph bounding boxes. @return [Integer]

Public Class Methods

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

Encode table.

@param head [TTFunk::Table::Head] @param loca [Hash] result of encoding Index to Location (‘loca`) table @param mapping [Hash{Integer => Integer}] keys are new glyph IDs, values

are old glyph IDs

@return [EncodedString]

# File lib/ttfunk/table/head.rb, line 92
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('Nn2q>2n*')
  end
end
from_long_date_time(ldt) click to toggle source

Convert Long Date Time timestamp to Time. @param ldt [Float, Integer] @return [Time]

# File lib/ttfunk/table/head.rb, line 111
def from_long_date_time(ldt)
  Time.at(ldt + LONG_DATE_TIME_BASIS, in: 'UTC')
end
to_long_date_time(time) click to toggle source

Convert Time to Long Date Time timestamp @param time [Time] @return [Integer]

# File lib/ttfunk/table/head.rb, line 118
def to_long_date_time(time)
  Integer(time) - LONG_DATE_TIME_BASIS
end

Private Class Methods

min_max_values_for(head, mapping) click to toggle source
# File lib/ttfunk/table/head.rb, line 124
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_value 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 149
def parse!
  @version, @font_revision, @check_sum_adjustment, @magic_number,
    @flags, @units_per_em, @created, @modified = read(36, 'N4n2q>2')

  @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