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
The platform specific encoding identified.
The language identified.
The platform identifier code.
Public Class Methods
Create a new name record.
# 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
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
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) andlanguage_id
0 (English); or -
platform_id
:microsoft,encoding_id
1 (Unicode) andlanguage_id
1033 (US English).
# 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