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:

Source Code
lib/ttfunk/table/cff/dict.rb, line 43
43
def [](operator)
44
  @dict[operator]
45
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>)
Source Code
lib/ttfunk/table/cff/dict.rb, line 51
51
def []=(operator, *operands)
52
  @dict[operator] = Array(*operands)
53
end

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

This method returns an undefined value.

Iterate over dict entries.

Yield Parameters:

Source Code
lib/ttfunk/table/cff/dict.rb, line 60
60
def each(&block)
61
  @dict.each(&block)
62
end

#encodeString

Encode dict.

Returns:

  • (String)
Source Code
lib/ttfunk/table/cff/dict.rb, line 69
69
def encode
70
  sort_by(&:first)
71
    .map { |(operator, operands)|
72
      operands.map { |operand| encode_operand(operand) }.join +
73
        encode_operator(operator)
74
    }
75
    .join
76
end