class HexaPDF::Font::TrueType::Table::Name::Record

Contains the information for a Name Record.

The string value is converted to UTF-8 if possible, otherwise it stays in BINARY.

Constants

PLATFORM_MACINTOSH

QuickDraw Script Manager code for Macintosh.

PLATFORM_MICROSOFT

Microsoft encoding.

PLATFORM_UNICODE

Indicates Unicode version.

Attributes

encoding_id[R]

The platform specific encoding identified.

language_id[R]

The language identified.

platform_id[R]

The platform identifier code.

Public Class Methods

new(text, pid, eid, lid) click to toggle source

Create a new name record.

Calls superclass method
# File lib/hexapdf/font/true_type/table/name.rb, line 99
def initialize(text, pid, eid, lid)
  @platform_id = pid
  @encoding_id = eid
  @language_id = lid

  if platform?(:unicode) ||
      (platform?(:microsoft) && encoding_id == 1 || encoding_id == 10)
    text.encode!(::Encoding::UTF_8, ::Encoding::UTF_16BE)
  elsif platform?(:macintosh) && encoding_id == 0
    text.encode!(::Encoding::UTF_8, ::Encoding::MACROMAN)
  end

  super(text)
end

Public Instance Methods

platform?(identifier) click to toggle source

Returns true if this record has the given platform identifier which can either be :unicode, :macintosh or :microsoft.

# File lib/hexapdf/font/true_type/table/name.rb, line 116
def platform?(identifier)
  platform_id == case identifier
                 when :unicode then PLATFORM_UNICODE
                 when :macintosh then PLATFORM_MACINTOSH
                 when :microsoft then PLATFORM_MICROSOFT
                 else
                   raise ArgumentError, "Unknown platform identifier: #{identifier}"
                 end
end
preferred?() click to toggle source

Returns true if this record is a “preferred” one.

The label “preferred” is set on a name if it represents the US English version of the name in a decodable encoding:

# File lib/hexapdf/font/true_type/table/name.rb, line 132
def preferred?
  (platform_id == PLATFORM_MACINTOSH && encoding_id == 0 && language_id == 0) ||
    (platform_id == PLATFORM_MICROSOFT && encoding_id == 1 && language_id == 1033)
end