Module: Fontisan::Ufo::Compile::Meta

Defined in:
lib/fontisan/ufo/compile/meta.rb

Overview

Builds the OpenType meta table.

The meta table stores font metadata as tagged data — longer-form strings than the name table supports. Common tags:

"dlng" — design languages (BCP-47 tags)
"slng" — supported languages

Constant Summary collapse

VERSION =
1
HEADER_SIZE =
16
DATA_MAP_SIZE =

tag(4) + offset(4) + length(4)

12

Class Method Summary collapse

Class Method Details

.build(data:) ⇒ String?

Returns meta table bytes, or nil if no data.

Parameters:

  • data (Hash<String,String>)

    tag → UTF-8 string value

Returns:

  • (String, nil)

    meta table bytes, or nil if no data



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fontisan/ufo/compile/meta.rb', line 21

def self.build(data:)
  return nil if data.nil? || data.empty?

  count = data.size
  data_offset = HEADER_SIZE + (count * DATA_MAP_SIZE)

  io = +""
  io << [VERSION, 0, count, data_offset].pack("NNNN")

  # Two iterations over the same data: the meta table has two
  # distinct output sections (data map entries then data values)
  # that cannot be interleaved. The map-entry section records
  # offsets that depend on the total size of the value section,
  # so the value section must be produced last.
  #
  # rubocop:disable Style/CombinableLoops
  offset = data_offset
  data.each do |tag, value|
    io << tag.ljust(4, " ")[0, 4]
    io << [offset, value.bytesize].pack("NN")
    offset += value.bytesize
  end
  data.each_value { |value| io << value.b }
  # rubocop:enable Style/CombinableLoops

  io
end