module Fontina::Formats::OpenType

Constants

ENCODINGS
FW_BOLD
FW_NORMAL
LANGUAGES
OT_VERSION
PLATFORMS
TT_VERSION

Public Class Methods

read(io) click to toggle source
# File lib/fontina/formats/open_type.rb, line 8
def read(io)
  package container.read io
end

Private Class Methods

container() click to toggle source
# File lib/fontina/formats/open_type.rb, line 14
def container
  @container ||= begin
    %w[
      ../mac/language_codes
      ../windows/language_codes
      shared/e_string
      open_type/constants
      open_type/name_table
      open_type/head_table
      open_type/os2_table
      open_type/table
      open_type/table_directory
      open_type/offset_table
      open_type/container
    ].each { |file| require_relative file }

    Class.new(OT_Container) { auto_call_delayed_io }
  end
end
get_style(ot) click to toggle source
# File lib/fontina/formats/open_type.rb, line 57
def get_style(ot)
  get_table(ot, 'OS/2').tap do |t|
    return [
      t.weight_class,
      t.fs_selection[0] == 1,
      t.fs_selection[1] == 1,
      t.fs_selection[4] == 1
    ] if t
  end

  get_table(ot, 'head').tap do |t|
    return [
      t.mac_style[0] == 1 ? FW_BOLD : FW_NORMAL,
      t.mac_style[1] == 1,
      t.mac_style[2] == 1,
      nil
    ]
  end
end
get_table(ot, tag) click to toggle source
# File lib/fontina/formats/open_type.rb, line 52
def get_table(ot, tag)
  entry = ot.table_directory.find { |t| t.tag == tag } and
  entry.table
end
package(ot) click to toggle source
# File lib/fontina/formats/open_type.rb, line 34
def package(ot)
  name_records = get_table(ot, 'name').names

  Package[
    [],

    [Font[
      name_records.find_all { |n| n.name_id == 4 }
        .map { |n| QualifiedName[n.string, n.platform.value, n.language.value] },
      name_records.find_all { |n| n.name_id == 1 }
        .map { |n| QualifiedName[n.string, n.platform.value, n.language.value] },
      :vector,
      nil,
      *get_style(ot)
    ]]
  ]
end