Class: TTFunk::Table::Post

Inherits:
TTFunk::Table show all
Defined in:
lib/ttfunk/table/post.rb,
lib/ttfunk/table/post/format10.rb,
lib/ttfunk/table/post/format20.rb,
lib/ttfunk/table/post/format30.rb,
lib/ttfunk/table/post/format40.rb

Overview

PostScript (‘post`) table.

This class can be extended with version-specific modules.

Defined Under Namespace

Modules: Format10, Format20, Format30, Format40

Instance Attribute Summary collapse

Attributes inherited from TTFunk::Table

#file, #length, #offset

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TTFunk::Table

#exists?, #initialize, #raw, #tag

Constructor Details

This class inherits a constructor from TTFunk::Table

Instance Attribute Details

#fixed_pitchInteger (readonly)

0 if the font is proportionally spaced, non-zero if the font is not proportionally spaced.

Returns:

  • (Integer)


35
36
37
# File 'lib/ttfunk/table/post.rb', line 35

def fixed_pitch
  @fixed_pitch
end

#formatInteger (readonly)

Table version.

Returns:

  • (Integer)


18
19
20
# File 'lib/ttfunk/table/post.rb', line 18

def format
  @format
end

#italic_angleInteger (readonly)

Italic angle in counter-clockwise degrees from the vertical.

Returns:

  • (Integer)


22
23
24
# File 'lib/ttfunk/table/post.rb', line 22

def italic_angle
  @italic_angle
end

#max_mem_type1Integer (readonly)

Maximum memory usage when an OpenType font is downloaded as a Type 1 font.

Returns:

  • (Integer)


53
54
55
# File 'lib/ttfunk/table/post.rb', line 53

def max_mem_type1
  @max_mem_type1
end

#max_mem_type42Integer (readonly)

Maximum memory usage when an OpenType font is downloaded.

Returns:

  • (Integer)


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

def max_mem_type42
  @max_mem_type42
end

#min_mem_type1Integer (readonly)

Minimum memory usage when an OpenType font is downloaded as a Type 1 font.

Returns:

  • (Integer)


48
49
50
# File 'lib/ttfunk/table/post.rb', line 48

def min_mem_type1
  @min_mem_type1
end

#min_mem_type42Integer (readonly)

Minimum memory usage when an OpenType font is downloaded.

Returns:

  • (Integer)


39
40
41
# File 'lib/ttfunk/table/post.rb', line 39

def min_mem_type42
  @min_mem_type42
end

#subtableTTFunk::Table::Post::Format10, ... (readonly)

Version-specific fields.



58
59
60
# File 'lib/ttfunk/table/post.rb', line 58

def subtable
  @subtable
end

#underline_positionInteger (readonly)

Suggested distance of the top of the underline from the baseline

Returns:

  • (Integer)


26
27
28
# File 'lib/ttfunk/table/post.rb', line 26

def underline_position
  @underline_position
end

#underline_thicknessInteger (readonly)

Suggested values for the underline thickness.

Returns:

  • (Integer)


30
31
32
# File 'lib/ttfunk/table/post.rb', line 30

def underline_thickness
  @underline_thickness
end

Class Method Details

.encode(post, mapping) ⇒ String?

Encode table.

Parameters:

  • post (TTFunk::Table::Post)
  • mapping (Hash{Integer => Integer})

    keys are new glyph IDs, values are old glyph IDs

Returns:

  • (String, nil)


66
67
68
69
70
# File 'lib/ttfunk/table/post.rb', line 66

def self.encode(post, mapping)
  return if post.nil?

  post.recode(mapping)
end

Instance Method Details

#fixed_pitch?Boolean

Is this font monospaced?

Returns:

  • (Boolean)


75
76
77
# File 'lib/ttfunk/table/post.rb', line 75

def fixed_pitch?
  @fixed_pitch != 0
end

#glyph_for(_code) ⇒ String

Get glyph name for character code.

This is a placeholder.

Parameters:

  • _code (Integer)

Returns:

  • (String)


85
86
87
# File 'lib/ttfunk/table/post.rb', line 85

def glyph_for(_code)
  '.notdef'
end

#recode(mapping) ⇒ String

Re-encode this table.

Parameters:

  • mapping (Hash{Integer => Integer})

    keys are new glyph IDs, values are old glyph IDs

Returns:

  • (String)


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# 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