Class: TTFunk::Table::Cff::FontDict

Inherits:
Dict show all
Defined in:
lib/ttfunk/table/cff/font_dict.rb

Overview

CFF Font dict.

Constant Summary collapse

PLACEHOLDER_LENGTH =

Length of placeholders.

5
OPERATORS =

Operators we care about in this dict.

{ private: 18 }.freeze
OPERATOR_CODES =

Inverse operator mapping.

OPERATORS.invert

Constants inherited from Dict

Dict::MAX_OPERANDS, Dict::OPERAND_BZERO, Dict::OPERATOR_BZERO, Dict::VALID_SCI_EXPONENT_RE, Dict::VALID_SCI_SIGNIFICAND_RE, Dict::WIDE_OPERATOR_ADJUSTMENT, Dict::WIDE_OPERATOR_BZERO

Instance Attribute Summary collapse

Attributes inherited from SubTable

#file, #length, #table_offset

Instance Method Summary collapse

Methods inherited from Dict

#[], #[]=, #each

Methods inherited from SubTable

#eot?, #read

Constructor Details

#initialize(top_dict, file, offset, length = nil) ⇒ FontDict

Returns a new instance of FontDict.

Parameters:

  • top_dict (TTFunk::Table:Cff::TopDict)
  • file (TTFunk::File)
  • offset (Integer)
  • length (Integer) (defaults to: nil)


25
26
27
28
# File 'lib/ttfunk/table/cff/font_dict.rb', line 25

def initialize(top_dict, file, offset, length = nil)
  @top_dict = top_dict
  super(file, offset, length)
end

Instance Attribute Details

#top_dictTTFunk::Table::Cff::TopDict (readonly)

Top dict.



19
20
21
# File 'lib/ttfunk/table/cff/font_dict.rb', line 19

def top_dict
  @top_dict
end

Instance Method Details

#encodeTTFunk::EncodedString

Encode dict.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ttfunk/table/cff/font_dict.rb', line 33

def encode
  EncodedString.new do |result|
    each do |operator, operands|
      case OPERATOR_CODES[operator]
      when :private
        result << encode_private
      else
        operands.each { |operand| result << encode_operand(operand) }
      end

      result << encode_operator(operator)
    end
  end
end

#finalize(new_cff_data) ⇒ void

This method returns an undefined value.

Finalize dict.

Parameters:



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ttfunk/table/cff/font_dict.rb', line 52

def finalize(new_cff_data)
  encoded_private_dict = private_dict.encode
  encoded_offset = encode_integer32(new_cff_data.length)
  encoded_length = encode_integer32(encoded_private_dict.length)

  new_cff_data.resolve_placeholder(:"private_length_#{@table_offset}", encoded_length)
  new_cff_data.resolve_placeholder(:"private_offset_#{@table_offset}", encoded_offset)

  private_dict.finalize(encoded_private_dict)
  new_cff_data << encoded_private_dict
end

#private_dictTTFunk::Table::Cff::PrivateDict?

Private dict.



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ttfunk/table/cff/font_dict.rb', line 67

def private_dict
  @private_dict ||=
    if (info = self[OPERATORS[:private]])
      private_dict_length, private_dict_offset = info

      PrivateDict.new(
        file,
        top_dict.cff_offset + private_dict_offset,
        private_dict_length,
      )
    end
end