class TTFunk::Table::Post

PostScript (‘post`) table.

This class can be extended with version-specific modules.

@see TTFunk::Table::Post::Format10 @see TTFunk::Table::Post::Format20 @see TTFunk::Table::Post::Format30 @see TTFunk::Table::Post::Format40

Attributes

fixed_pitch[R]

0 if the font is proportionally spaced, non-zero if the font is not proportionally spaced. @return [Integer]

format[R]

Table version. @return [Integer]

italic_angle[R]

Italic angle in counter-clockwise degrees from the vertical. @return [Integer]

max_mem_type1[R]

Maximum memory usage when an OpenType font is downloaded as a Type 1 font. @return [Integer]

max_mem_type42[R]

Maximum memory usage when an OpenType font is downloaded. @return [Integer]

min_mem_type1[R]

Minimum memory usage when an OpenType font is downloaded as a Type 1 font. @return [Integer]

min_mem_type42[R]

Minimum memory usage when an OpenType font is downloaded. @return [Integer]

subtable[R]

Version-specific fields. @return [TTFunk::Table::Post::Format10, TTFunk::Table::Post::Format20,

TTFunk::Table::Post::Format30, TTFunk::Table::Post::Format40]
underline_position[R]

Suggested distance of the top of the underline from the baseline @return [Integer]

underline_thickness[R]

Suggested values for the underline thickness. @return [Integer]

Public Class Methods

encode(post, mapping) click to toggle source

Encode table.

@param post [TTFunk::Table::Post] @param mapping [Hash{Integer => Integer}] keys are new glyph IDs, values

are old glyph IDs

@return [String, nil]

# File lib/ttfunk/table/post.rb, line 66
def self.encode(post, mapping)
  return if post.nil?

  post.recode(mapping)
end

Public Instance Methods

fixed_pitch?() click to toggle source

Is this font monospaced?

@return [Boolean]

# File lib/ttfunk/table/post.rb, line 75
def fixed_pitch?
  @fixed_pitch != 0
end
glyph_for(_code) click to toggle source

Get glyph name for character code.

This is a placeholder.

@param _code [Integer] @return [String]

# File lib/ttfunk/table/post.rb, line 85
def glyph_for(_code)
  '.notdef'
end
recode(mapping) click to toggle source

Re-encode this table.

@param mapping [Hash{Integer => Integer}] keys are new glyph IDs, values

are old glyph IDs

@return [String]

# File lib/ttfunk/table/post.rb, line 94
def recode(mapping)
  return raw if format == 0x00030000

  table = raw[0, 32]
  table[0, 4] = [0x00020000].pack('N')

  index = []
  strings = []

  mapping.keys.sort.each do |new_id|
    post_glyph = glyph_for(mapping[new_id])
    position = Format10::POSTSCRIPT_GLYPHS.index(post_glyph)
    if position
      index << position
    else
      index << (257 + strings.length)
      strings << post_glyph
    end
  end

  table << [mapping.length, *index].pack('n*')
  strings.each do |string|
    table << [string.length, string].pack('CA*')
  end

  table
end

Private Instance Methods

parse!() click to toggle source
# File lib/ttfunk/table/post.rb, line 124
def parse!
  @format, @italic_angle, @underline_position, @underline_thickness,
    @fixed_pitch, @min_mem_type42, @max_mem_type42,
    @min_mem_type1, @max_mem_type1 = read(32, 'N2n2N*')

  @subtable =
    case @format
    when 0x00010000
      extend(Post::Format10)
    when 0x00020000
      extend(Post::Format20)
    when 0x00025000
      raise NotImplementedError,
        'Post format 2.5 is not supported by TTFunk'
    when 0x00030000
      extend(Post::Format30)
    when 0x00040000
      extend(Post::Format40)
    end

  parse_format!
end
parse_format!() click to toggle source
# File lib/ttfunk/table/post.rb, line 147
def parse_format!
  warn(Kernel.format('postscript table format 0x%08X is not supported', @format))
end