Class: TTFunk::Table::Cff::Dict

Inherits:
SubTable
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ttfunk/table/cff/dict.rb

Overview

CFF Dict.

Direct Known Subclasses

FontDict, PrivateDict, TopDict

Defined Under Namespace

Classes: InvalidOperandError, TooManyOperandsError

Constant Summary collapse

OPERATOR_BZERO =

Single-byte operators.

(0..21).freeze
OPERAND_BZERO =

Bytes indicating an operand.

[28..30, 32..254].freeze
WIDE_OPERATOR_BZERO =

Two-byte operator

12
WIDE_OPERATOR_ADJUSTMENT =

Two-byte operator adjustment. Used for encoding and decoding of wide operators.

1200
MAX_OPERANDS =

Maximum number of operands allowed per operator.

48
VALID_SCI_SIGNIFICAND_RE =

Scientific notation operand significand validation regular experession.

/\A-?(\.\d+|\d+|\d+\.\d+)\z/.freeze
VALID_SCI_EXPONENT_RE =

Scientific notation operand exponent validation regular experession.

/\A-?\d+\z/.freeze

Instance Attribute Summary

Attributes inherited from SubTable

#file, #length, #table_offset

Instance Method Summary collapse

Methods inherited from SubTable

#eot?, #initialize, #read

Constructor Details

This class inherits a constructor from TTFunk::SubTable

Instance Method Details

#[](operator) ⇒ Array<Integer, TTFunk::SciForm>

Get dict value by operator.

Parameters:

  • operator (Integer)

Returns:



43
44
45
# File 'lib/ttfunk/table/cff/dict.rb', line 43

def [](operator)
  @dict[operator]
end

#[]=(operator, *operands) ⇒ Object

Add dict entry.

Parameters:

  • operator (Integer)

    Entry operator. Must be in range 0..255. Wide operators must be in range 1200..1455.

  • operands (Array<Integer, TTFunk::SciForm>)


51
52
53
# File 'lib/ttfunk/table/cff/dict.rb', line 51

def []=(operator, *operands)
  @dict[operator] = Array(*operands)
end

#each {|key, value| ... } ⇒ void Also known as: each_pair

This method returns an undefined value.

Iterate over dict entries.

Yield Parameters:



60
61
62
# File 'lib/ttfunk/table/cff/dict.rb', line 60

def each(&block)
  @dict.each(&block)
end

#encodeString

Encode dict.

Returns:

  • (String)


69
70
71
72
73
74
75
76
# File 'lib/ttfunk/table/cff/dict.rb', line 69

def encode
  sort_by(&:first)
    .map { |(operator, operands)|
      operands.map { |operand| encode_operand(operand) }.join +
        encode_operator(operator)
    }
    .join
end