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)
Source Code
lib/ttfunk/table/cff/font_dict.rb, line 25
25
def initialize(top_dict, file, offset, length = nil)
26
  @top_dict = top_dict
27
  super(file, offset, length)
28
end

Instance Attribute Details

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

Top dict.

Source Code
lib/ttfunk/table/cff/font_dict.rb, line 19
19
def top_dict
20
  @top_dict
21
end

Instance Method Details

#encodeTTFunk::EncodedString

Encode dict.

Source Code
lib/ttfunk/table/cff/font_dict.rb, line 33
33
def encode
34
  EncodedString.new do |result|
35
    each do |operator, operands|
36
      case OPERATOR_CODES[operator]
37
      when :private
38
        result << encode_private
39
      else
40
        operands.each { |operand| result << encode_operand(operand) }
41
      end
42
43
      result << encode_operator(operator)
44
    end
45
  end
46
end

#finalize(new_cff_data) ⇒ void

This method returns an undefined value.

Finalize dict.

Parameters:

Source Code
lib/ttfunk/table/cff/font_dict.rb, line 52
52
def finalize(new_cff_data)
53
  encoded_private_dict = private_dict.encode
54
  encoded_offset = encode_integer32(new_cff_data.length)
55
  encoded_length = encode_integer32(encoded_private_dict.length)
56
57
  new_cff_data.resolve_placeholder(:"private_length_#{@table_offset}", encoded_length)
58
  new_cff_data.resolve_placeholder(:"private_offset_#{@table_offset}", encoded_offset)
59
60
  private_dict.finalize(encoded_private_dict)
61
  new_cff_data << encoded_private_dict
62
end

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

Private dict.

Source Code
lib/ttfunk/table/cff/font_dict.rb, line 67
67
def private_dict
68
  @private_dict ||=
69
    if (info = self[OPERATORS[:private]])
70
      private_dict_length, private_dict_offset = info
71
72
      PrivateDict.new(
73
        file,
74
        top_dict.cff_offset + private_dict_offset,
75
        private_dict_length,
76
      )
77
    end
78
end