Class: Fontisan::Tables::NameRecord
- Inherits:
-
Binary::BaseRecord
- Object
- BinData::Record
- Binary::BaseRecord
- Fontisan::Tables::NameRecord
- 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
-
#string ⇒ Object
The decoded string value (set after reading from string storage).
Instance Method Summary collapse
-
#decode_string(data) ⇒ Object
Decode the string data based on platform and encoding.
-
#length ⇒ Integer
Get the length of the string (for backward compatibility).
Methods inherited from Binary::BaseRecord
Instance Attribute Details
#string ⇒ Object
The decoded string value (set after reading from string storage)
18 19 20 |
# File 'lib/fontisan/tables/name.rb', line 18 def string @string end |
Instance Method Details
#decode_string(data) ⇒ Object
Decode the string data based on platform and encoding
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fontisan/tables/name.rb', line 30 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 |
#length ⇒ Integer
Get the length of the string (for backward compatibility)
23 24 25 |
# File 'lib/fontisan/tables/name.rb', line 23 def length string_length end |