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)
Source Code
lib/ttfunk/table/post.rb, line 35
35
def fixed_pitch
36
  @fixed_pitch
37
end

#formatInteger (readonly)

Table version.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/post.rb, line 18
18
def format
19
  @format
20
end

#italic_angleInteger (readonly)

Italic angle in counter-clockwise degrees from the vertical.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/post.rb, line 22
22
def italic_angle
23
  @italic_angle
24
end

#max_mem_type1Integer (readonly)

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

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/post.rb, line 53
53
def max_mem_type1
54
  @max_mem_type1
55
end

#max_mem_type42Integer (readonly)

Maximum memory usage when an OpenType font is downloaded.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/post.rb, line 43
43
def max_mem_type42
44
  @max_mem_type42
45
end

#min_mem_type1Integer (readonly)

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

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/post.rb, line 48
48
def min_mem_type1
49
  @min_mem_type1
50
end

#min_mem_type42Integer (readonly)

Minimum memory usage when an OpenType font is downloaded.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/post.rb, line 39
39
def min_mem_type42
40
  @min_mem_type42
41
end

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

Version-specific fields.

Source Code
lib/ttfunk/table/post.rb, line 58
58
def subtable
59
  @subtable
60
end

#underline_positionInteger (readonly)

Suggested distance of the top of the underline from the baseline

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/post.rb, line 26
26
def underline_position
27
  @underline_position
28
end

#underline_thicknessInteger (readonly)

Suggested values for the underline thickness.

Returns:

  • (Integer)
Source Code
lib/ttfunk/table/post.rb, line 30
30
def underline_thickness
31
  @underline_thickness
32
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)
Source Code
lib/ttfunk/table/post.rb, line 66
66
def self.encode(post, mapping)
67
  return if post.nil?
68
69
  post.recode(mapping)
70
end

Instance Method Details

#fixed_pitch?Boolean

Is this font monospaced?

Returns:

  • (Boolean)
Source Code
lib/ttfunk/table/post.rb, line 75
75
def fixed_pitch?
76
  @fixed_pitch != 0
77
end

#glyph_for(_code) ⇒ String

Get glyph name for character code.

This is a placeholder.

Parameters:

  • _code (Integer)

Returns:

  • (String)
Source Code
lib/ttfunk/table/post.rb, line 85
85
def glyph_for(_code)
86
  '.notdef'
87
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)
Source Code
lib/ttfunk/table/post.rb, line 94
94
def recode(mapping)
95
  return raw if format == 0x00030000
96
97
  table = raw[0, 32]
98
  table[0, 4] = [0x00020000].pack('N')
99
100
  index = []
101
  strings = []
102
103
  mapping.keys.sort.each do |new_id|
104
    post_glyph = glyph_for(mapping[new_id])
105
    position = Format10::POSTSCRIPT_GLYPHS.index(post_glyph)
106
    if position
107
      index << position
108
    else
109
      index << (257 + strings.length)
110
      strings << post_glyph
111
    end
112
  end
113
114
  table << [mapping.length, *index].pack('n*')
115
  strings.each do |string|
116
    table << [string.length, string].pack('CA*')
117
  end
118
119
  table
120
end