Class: HexaPDF::Font::TrueType::Table::Name::Record

Inherits:
String
  • Object
show all
Defined in:
lib/hexapdf/font/true_type/table/name.rb

Overview

Contains the information for a Name Record.

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

Constant Summary collapse

PLATFORM_UNICODE =

Indicates Unicode version.

0
PLATFORM_MACINTOSH =

QuickDraw Script Manager code for Macintosh.

1
PLATFORM_MICROSOFT =

Microsoft encoding.

3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, pid, eid, lid) ⇒ Record

Create a new name record.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/hexapdf/font/true_type/table/name.rb', line 100

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

Instance Attribute Details

#encoding_idObject (readonly)

The platform specific encoding identified.



94
95
96
# File 'lib/hexapdf/font/true_type/table/name.rb', line 94

def encoding_id
  @encoding_id
end

#language_idObject (readonly)

The language identified.



97
98
99
# File 'lib/hexapdf/font/true_type/table/name.rb', line 97

def language_id
  @language_id
end

#platform_idObject (readonly)

The platform identifier code.



91
92
93
# File 'lib/hexapdf/font/true_type/table/name.rb', line 91

def platform_id
  @platform_id
end

Instance Method Details

#platform?(identifier) ⇒ Boolean

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

Returns:

  • (Boolean)


117
118
119
120
121
122
123
124
125
# File 'lib/hexapdf/font/true_type/table/name.rb', line 117

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?Boolean

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:

  • platform_id :macintosh, encoding_id 0 (Roman) and language_id 0 (English); or

  • platform_id :microsoft, encoding_id 1 (Unicode) and language_id 1033 (US English).

Returns:

  • (Boolean)


133
134
135
136
# File 'lib/hexapdf/font/true_type/table/name.rb', line 133

def preferred?
  (platform_id == PLATFORM_MACINTOSH && encoding_id == 0 && language_id == 0) ||
    (platform_id == PLATFORM_MICROSOFT && encoding_id == 1 && language_id == 1033)
end