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. @return [Integer]
Font creation time. @return [Integer] Long Date Time timestamp.
Flags. @return [Integer]
Font direction hint. Deprecated, set to 2. @return [Integer]
Font revision. @return [Integer]
Glyph data format. @return [Integer]
Index to Location format. @return [Integer]
Smallest readable size in pixels. @return [Integer]
Mac font style. @return [Integer]
Magic number. @return [Integer] must be ‘0x5F0F3CF5`
Font modification time. @return [Integer] Long Date Time timestamp.
Units per Em. @return [Integer]
Table
version. @return [Integer]
Maximum x coordinate across all glyph bounding boxes. @return [Integer]
Minimum x coordinate across all glyph bounding boxes. @return [Integer]
Maximum y coordinate across all glyph bounding boxes. @return [Integer]
Minimum y coordinate across all glyph bounding boxes. @return [Integer]
Public Class Methods
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
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
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
# 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
# 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