Class: Fontisan::Type1::FontDictionary::Encoding

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/type1/font_dictionary.rb

Overview

Encoding vector

Maps character codes to glyph names in the font.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEncoding

Returns a new instance of Encoding.



430
431
432
433
# File 'lib/fontisan/type1/font_dictionary.rb', line 430

def initialize
  @encoding_map = {}
  @encoding_type = :standard
end

Instance Attribute Details

#encoding_mapHash (readonly)

Returns Character code to glyph name mapping.

Returns:

  • (Hash)

    Character code to glyph name mapping



425
426
427
# File 'lib/fontisan/type1/font_dictionary.rb', line 425

def encoding_map
  @encoding_map
end

#encoding_typeSymbol (readonly)

Returns Encoding type (:standard, :custom, :identity).

Returns:

  • (Symbol)

    Encoding type (:standard, :custom, :identity)



428
429
430
# File 'lib/fontisan/type1/font_dictionary.rb', line 428

def encoding_type
  @encoding_type
end

Instance Method Details

#[](char_code) ⇒ String?

Get glyph name for character code

Parameters:

  • char_code (Integer)

    Character code

Returns:

  • (String, nil)

    Glyph name or nil



456
457
458
# File 'lib/fontisan/type1/font_dictionary.rb', line 456

def [](char_code)
  @encoding_map[char_code]
end

#parse(dict_data) ⇒ Object

Parse encoding from dictionary data

Parameters:

  • dict_data (Hash)

    Dictionary data



438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/fontisan/type1/font_dictionary.rb', line 438

def parse(dict_data)
  # Type 1 fonts typically use StandardEncoding by default
  # Custom encodings are specified as an array

  @encoding_type = if dict_data[:encoding]
                     :custom
                   else
                     :standard
                   end

  # Populate with StandardEncoding if standard
  populate_standard_encoding if @encoding_type == :standard
end

#standard?Boolean

Check if encoding is standard

Returns:

  • (Boolean)

    True if using StandardEncoding



463
464
465
# File 'lib/fontisan/type1/font_dictionary.rb', line 463

def standard?
  @encoding_type == :standard
end