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)
Source Code
lib/ttfunk/table/head.rb, line 19
19
def checksum_adjustment
20
  @checksum_adjustment
21
end

#createdInteger (readonly)

Font creation time.

Returns:

  • (Integer)

    Long Date Time timestamp.

Source Code
lib/ttfunk/table/head.rb, line 35
35
def created
36
  @created
37
end

#flagsInteger (readonly)

Flags.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 27
27
def flags
28
  @flags
29
end

#font_direction_hintInteger (readonly)

Font direction hint. Deprecated, set to 2.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 67
67
def font_direction_hint
68
  @font_direction_hint
69
end

#font_revisionInteger (readonly)

Font revision.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 15
15
def font_revision
16
  @font_revision
17
end

#glyph_data_formatInteger (readonly)

Glyph data format.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 75
75
def glyph_data_format
76
  @glyph_data_format
77
end

#index_to_loc_formatInteger (readonly)

Index to Location format.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 71
71
def index_to_loc_format
72
  @index_to_loc_format
73
end

#lowest_rec_ppemInteger (readonly)

Smallest readable size in pixels.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 63
63
def lowest_rec_ppem
64
  @lowest_rec_ppem
65
end

#mac_styleInteger (readonly)

Mac font style.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 59
59
def mac_style
60
  @mac_style
61
end

#magic_numberInteger (readonly)

Magic number.

Returns:

  • (Integer)

    must be 0x5F0F3CF5

Source Code
lib/ttfunk/table/head.rb, line 23
23
def magic_number
24
  @magic_number
25
end

#modifiedInteger (readonly)

Font modification time.

Returns:

  • (Integer)

    Long Date Time timestamp.

Source Code
lib/ttfunk/table/head.rb, line 39
39
def modified
40
  @modified
41
end

#units_per_emInteger (readonly)

Units per Em.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 31
31
def units_per_em
32
  @units_per_em
33
end

#versionInteger (readonly)

Table version.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 11
11
def version
12
  @version
13
end

#x_maxInteger (readonly)

Maximum x coordinate across all glyph bounding boxes.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 51
51
def x_max
52
  @x_max
53
end

#x_minInteger (readonly)

Minimum x coordinate across all glyph bounding boxes.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 43
43
def x_min
44
  @x_min
45
end

#y_maxInteger (readonly)

Maximum y coordinate across all glyph bounding boxes.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 55
55
def y_max
56
  @y_max
57
end

#y_minInteger (readonly)

Minimum y coordinate across all glyph bounding boxes.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 47
47
def y_min
48
  @y_min
49
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:

Source Code
lib/ttfunk/table/head.rb, line 92
92
def encode(head, loca, mapping)
93
  EncodedString.new do |table|
94
    table <<
95
      [head.version, head.font_revision].pack('N2') <<
96
      Placeholder.new(:checksum, length: 4) <<
97
      [
98
        head.magic_number,
99
        head.flags, head.units_per_em,
100
        head.created, head.modified,
101
        *min_max_values_for(head, mapping),
102
        head.mac_style, head.lowest_rec_ppem, head.font_direction_hint,
103
        loca[:type] || 0, head.glyph_data_format,
104
      ].pack('Nn2q>2n*')
105
  end
106
end

.from_long_date_time(ldt) ⇒ Time

Convert Long Date Time timestamp to Time.

Parameters:

  • ldt (Float, Integer)

Returns:

  • (Time)
Source Code
lib/ttfunk/table/head.rb, line 111
111
def from_long_date_time(ldt)
112
  Time.at(ldt + LONG_DATE_TIME_BASIS, in: 'UTC')
113
end

.to_long_date_time(time) ⇒ Integer

Convert Time to Long Date Time timestamp

Parameters:

  • time (Time)

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/head.rb, line 118
118
def to_long_date_time(time)
119
  Integer(time) - LONG_DATE_TIME_BASIS
120
end