File: directory.rb

package info (click to toggle)
ruby-ttfunk 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,472 kB
  • sloc: ruby: 7,954; makefile: 7
file content (34 lines) | stat: -rw-r--r-- 852 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module TTFunk
  # SFNT table directory.
  class Directory
    # Table descriptors
    # @return [Hash{String => Hash}]
    attr_reader :tables

    # Scaler type
    # @return [Integer]
    attr_reader :scaler_type

    def initialize(io, offset = 0)
      io.seek(offset)

      # https://www.microsoft.com/typography/otspec/otff.htm#offsetTable
      # We're ignoring searchRange, entrySelector, and rangeShift here, but
      # skipping past them to get to the table information.
      @scaler_type, table_count = io.read(12).unpack('Nn')

      @tables = {}
      table_count.times do
        tag, checksum, offset, length = io.read(16).unpack('a4N*')
        @tables[tag] = {
          tag: tag,
          checksum: checksum,
          offset: offset,
          length: length,
        }
      end
    end
  end
end