class TTFunk::Table::Cff::PrivateDict

CFF Private dict.

Constants

DEFAULT_WIDTH_X_DEFAULT

Default value of Default Width X.

DEFAULT_WIDTH_X_NOMINAL

Default value of Nominal Width X.

OPERATORS

Operators we care about in this dict.

OPERATOR_CODES

Inverse operator mapping.

PLACEHOLDER_LENGTH

Length of placeholders.

Public Instance Methods

default_width_x() click to toggle source

Default Width X.

@return [Integer]

# File lib/ttfunk/table/cff/private_dict.rb, line 75
def default_width_x
  if (width = self[OPERATORS[:default_width_x]])
    width.first
  else
    DEFAULT_WIDTH_X_DEFAULT
  end
end
encode() click to toggle source

Encode dict.

@return [TTFunk::EncodedString]

# File lib/ttfunk/table/cff/private_dict.rb, line 30
def encode
  # TODO: use mapping to determine which subroutines are still used.
  # For now, just encode them all.
  EncodedString.new do |result|
    each do |operator, operands|
      case OPERATOR_CODES[operator]
      when :subrs
        result << encode_subrs
      else
        operands.each { |operand| result << encode_operand(operand) }
      end

      result << encode_operator(operator)
    end
  end
end
finalize(private_dict_data) click to toggle source

Finalize dict.

@param private_dict_data [TTFunk::EncodedString] @return [void]

# File lib/ttfunk/table/cff/private_dict.rb, line 51
def finalize(private_dict_data)
  return unless subr_index

  encoded_subr_index = subr_index.encode
  encoded_offset = encode_integer32(private_dict_data.length)

  private_dict_data.resolve_placeholder(:"subrs_#{@table_offset}", encoded_offset)

  private_dict_data << encoded_subr_index
end
nominal_width_x() click to toggle source

Nominal Width X.

@return [Integer]

# File lib/ttfunk/table/cff/private_dict.rb, line 86
def nominal_width_x
  if (width = self[OPERATORS[:nominal_width_x]])
    width.first
  else
    DEFAULT_WIDTH_X_NOMINAL
  end
end
subr_index() click to toggle source

Subroutine index.

@return [TTFunk::Table::Cff::SubrIndex, nil]

# File lib/ttfunk/table/cff/private_dict.rb, line 65
def subr_index
  @subr_index ||=
    if (subr_offset = self[OPERATORS[:subrs]])
      SubrIndex.new(file, table_offset + subr_offset.first)
    end
end

Private Instance Methods

encode_subrs() click to toggle source
# File lib/ttfunk/table/cff/private_dict.rb, line 96
def encode_subrs
  EncodedString.new do |result|
    result << Placeholder.new(:"subrs_#{@table_offset}", length: PLACEHOLDER_LENGTH)
  end
end