Class: TTFunk::Table::Head

Inherits:
TTFunk::Table show all
Defined in:
lib/ttfunk/table/head.rb

Overview

Font Header (‘head`) Table.

Instance Attribute Summary collapse

Attributes inherited from TTFunk::Table

#file, #length, #offset

Class Method Summary collapse

Methods inherited from TTFunk::Table

#exists?, #initialize, #raw, #tag

Constructor Details

This class inherits a constructor from TTFunk::Table

Instance Attribute Details

#checksum_adjustmentInteger (readonly)

Checksum adjustment.

Returns:

  • (Integer)


19
20
21
# File 'lib/ttfunk/table/head.rb', line 19

def checksum_adjustment
  @checksum_adjustment
end

#createdInteger (readonly)

Font creation time.

Returns:

  • (Integer)

    Long Date Time timestamp.



35
36
37
# File 'lib/ttfunk/table/head.rb', line 35

def created
  @created
end

#flagsInteger (readonly)

Flags.

Returns:

  • (Integer)


27
28
29
# File 'lib/ttfunk/table/head.rb', line 27

def flags
  @flags
end

#font_direction_hintInteger (readonly)

Font direction hint. Deprecated, set to 2.

Returns:

  • (Integer)


67
68
69
# File 'lib/ttfunk/table/head.rb', line 67

def font_direction_hint
  @font_direction_hint
end

#font_revisionInteger (readonly)

Font revision.

Returns:

  • (Integer)


15
16
17
# File 'lib/ttfunk/table/head.rb', line 15

def font_revision
  @font_revision
end

#glyph_data_formatInteger (readonly)

Glyph data format.

Returns:

  • (Integer)


75
76
77
# File 'lib/ttfunk/table/head.rb', line 75

def glyph_data_format
  @glyph_data_format
end

#index_to_loc_formatInteger (readonly)

Index to Location format.

Returns:

  • (Integer)


71
72
73
# File 'lib/ttfunk/table/head.rb', line 71

def index_to_loc_format
  @index_to_loc_format
end

#lowest_rec_ppemInteger (readonly)

Smallest readable size in pixels.

Returns:

  • (Integer)


63
64
65
# File 'lib/ttfunk/table/head.rb', line 63

def lowest_rec_ppem
  @lowest_rec_ppem
end

#mac_styleInteger (readonly)

Mac font style.

Returns:

  • (Integer)


59
60
61
# File 'lib/ttfunk/table/head.rb', line 59

def mac_style
  @mac_style
end

#magic_numberInteger (readonly)

Magic number.

Returns:

  • (Integer)

    must be ‘0x5F0F3CF5`



23
24
25
# File 'lib/ttfunk/table/head.rb', line 23

def magic_number
  @magic_number
end

#modifiedInteger (readonly)

Font modification time.

Returns:

  • (Integer)

    Long Date Time timestamp.



39
40
41
# File 'lib/ttfunk/table/head.rb', line 39

def modified
  @modified
end

#units_per_emInteger (readonly)

Units per Em.

Returns:

  • (Integer)


31
32
33
# File 'lib/ttfunk/table/head.rb', line 31

def units_per_em
  @units_per_em
end

#versionInteger (readonly)

Table version.

Returns:

  • (Integer)


11
12
13
# File 'lib/ttfunk/table/head.rb', line 11

def version
  @version
end

#x_maxInteger (readonly)

Maximum x coordinate across all glyph bounding boxes.

Returns:

  • (Integer)


51
52
53
# File 'lib/ttfunk/table/head.rb', line 51

def x_max
  @x_max
end

#x_minInteger (readonly)

Minimum x coordinate across all glyph bounding boxes.

Returns:

  • (Integer)


43
44
45
# File 'lib/ttfunk/table/head.rb', line 43

def x_min
  @x_min
end

#y_maxInteger (readonly)

Maximum y coordinate across all glyph bounding boxes.

Returns:

  • (Integer)


55
56
57
# File 'lib/ttfunk/table/head.rb', line 55

def y_max
  @y_max
end

#y_minInteger (readonly)

Minimum y coordinate across all glyph bounding boxes.

Returns:

  • (Integer)


47
48
49
# File 'lib/ttfunk/table/head.rb', line 47

def y_min
  @y_min
end

Class Method Details

.encode(head, loca, mapping) ⇒ EncodedString

Encode table.

Parameters:

  • head (TTFunk::Table::Head)
  • loca (Hash)

    result of encoding Index to Location (‘loca`) table

  • mapping (Hash{Integer => Integer})

    keys are new glyph IDs, values are old glyph IDs

Returns:



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# 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) ⇒ Time

Convert Long Date Time timestamp to Time.

Parameters:

  • ldt (Float, Integer)

Returns:

  • (Time)


111
112
113
# 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) ⇒ Integer

Convert Time to Long Date Time timestamp

Parameters:

  • time (Time)

Returns:

  • (Integer)


118
119
120
# File 'lib/ttfunk/table/head.rb', line 118

def to_long_date_time(time)
  Integer(time) - LONG_DATE_TIME_BASIS
end