Class: Fontisan::Tables::NameRecord

Inherits:
Binary::BaseRecord show all
Defined in:
lib/fontisan/tables/name.rb

Overview

BinData structure for a single name record

Represents metadata about a string in the name table, including platform, encoding, language, and offset information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Binary::BaseRecord

#raw_data, read, #valid?

Instance Attribute Details

#stringObject

The decoded string value (set after reading from string storage)



20
21
22
# File 'lib/fontisan/tables/name.rb', line 20

def string
  @string
end

Instance Method Details

#decode_string(data) ⇒ Object

Decode the string data based on platform and encoding

Parameters:

  • data (String)

    Raw binary string data



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fontisan/tables/name.rb', line 32

def decode_string(data)
  @string = case platform_id
            when Name::PLATFORM_MACINTOSH
              # Platform 1 (Mac): ASCII/MacRoman
              data.dup.force_encoding("ASCII-8BIT").encode("UTF-8",
                                                           invalid: :replace,
                                                           undef: :replace)
            when Name::PLATFORM_WINDOWS
              # Platform 3 (Windows): UTF-16BE
              data.dup.force_encoding("UTF-16BE").encode("UTF-8",
                                                         invalid: :replace,
                                                         undef: :replace)
            when Name::PLATFORM_UNICODE
              # Platform 0 (Unicode): UTF-16BE
              data.dup.force_encoding("UTF-16BE").encode("UTF-8",
                                                         invalid: :replace,
                                                         undef: :replace)
            else
              # Unknown platform: try UTF-8
              data.dup.force_encoding("UTF-8")
            end
end

#lengthInteger

Get the length of the string (for backward compatibility)

Returns:

  • (Integer)

    String length in bytes



25
26
27
# File 'lib/fontisan/tables/name.rb', line 25

def length
  string_length
end