Class: Fontisan::Tables::PostTable

Inherits:
SfntTable
  • Object
show all
Defined in:
lib/fontisan/tables/post_table.rb

Overview

OOP representation of the 'post' (PostScript) table

The post table contains PostScript information, primarily glyph names. Different versions exist (1.0, 2.0, 2.5, 3.0, 4.0) with varying glyph name storage strategies.

This class extends SfntTable to provide post-specific validation and convenience methods for accessing PostScript metrics and glyph names.

Examples:

Accessing post table data

post = font.sfnt_table("post")
post.italic_angle      # => 0.0
post.underline_position # => -100
post.underline_thickness # => 50
post.glyph_name_for(42) # => "A"

Instance Attribute Summary

Attributes inherited from SfntTable

#data, #entry, #font, #parsed

Instance Method Summary collapse

Methods inherited from SfntTable

#available?, #calculate_checksum, #checksum, #data_loaded?, #human_name, #initialize, #inspect, #length, #load_data!, #offset, #parse, #parsed?, #required?, #tag, #to_s, #validate!

Constructor Details

This class inherits a constructor from Fontisan::SfntTable

Instance Method Details

#fixed_pitch?Boolean

Check if font is fixed pitch (monospaced)

Returns:

  • (Boolean)

    true if font is monospaced



68
69
70
71
72
# File 'lib/fontisan/tables/post_table.rb', line 68

def fixed_pitch?
  return false unless parsed

  parsed.is_fixed_pitch == 1
end

#glyph_name_for(glyph_id) ⇒ String?

Get glyph name by ID

Parameters:

  • glyph_id (Integer)

    Glyph ID

Returns:

  • (String, nil)

    Glyph name, or nil if not found



117
118
119
120
121
122
# File 'lib/fontisan/tables/post_table.rb', line 117

def glyph_name_for(glyph_id)
  names = glyph_names
  return nil if glyph_id.negative? || glyph_id >= names.length

  names[glyph_id]
end

#glyph_namesArray<String>

Get all glyph names

Only available for version 1.0 and 2.0

Returns:

  • (Array<String>)

    Array of glyph names



107
108
109
110
111
# File 'lib/fontisan/tables/post_table.rb', line 107

def glyph_names
  return [] unless parsed

  parsed.glyph_names || []
end

#has_glyph_names?Boolean

Check if glyph names are available

Returns:

  • (Boolean)

    true if glyph names can be retrieved



127
128
129
130
131
# File 'lib/fontisan/tables/post_table.rb', line 127

def has_glyph_names?
  return false unless parsed

  parsed.has_glyph_names?
end

#italic?Boolean

Check if font is italic

Returns:

  • (Boolean)

    true if italic_angle != 0



44
45
46
47
# File 'lib/fontisan/tables/post_table.rb', line 44

def italic?
  angle = italic_angle
  !angle.nil? && angle != 0
end

#italic_angleFloat?

Get italic angle in degrees

Positive value means counter-clockwise tilt

Returns:

  • (Float, nil)

    Italic angle in degrees, or nil if not parsed



35
36
37
38
39
# File 'lib/fontisan/tables/post_table.rb', line 35

def italic_angle
  return nil unless parsed

  parsed.italic_angle
end

#max_mem_type1Integer?

Get maximum memory for Type 1 fonts

Returns:

  • (Integer, nil)

    Maximum memory in bytes, or nil if not parsed



98
99
100
# File 'lib/fontisan/tables/post_table.rb', line 98

def max_mem_type1
  parsed&.max_mem_type1
end

#max_mem_type42Integer?

Get maximum memory for Type 42 fonts

Returns:

  • (Integer, nil)

    Maximum memory in bytes, or nil if not parsed



84
85
86
# File 'lib/fontisan/tables/post_table.rb', line 84

def max_mem_type42
  parsed&.max_mem_type42
end

#min_mem_type1Integer?

Get minimum memory for Type 1 fonts

Returns:

  • (Integer, nil)

    Minimum memory in bytes, or nil if not parsed



91
92
93
# File 'lib/fontisan/tables/post_table.rb', line 91

def min_mem_type1
  parsed&.min_mem_type1
end

#min_mem_type42Integer?

Get minimum memory for Type 42 fonts

Returns:

  • (Integer, nil)

    Minimum memory in bytes, or nil if not parsed



77
78
79
# File 'lib/fontisan/tables/post_table.rb', line 77

def min_mem_type42
  parsed&.min_mem_type42
end

#named_glyph_countInteger

Get the number of glyphs with names

Returns:

  • (Integer)

    Number of named glyphs



136
137
138
# File 'lib/fontisan/tables/post_table.rb', line 136

def named_glyph_count
  glyph_names.length
end

#underline_positionInteger?

Get underline position

Distance from baseline to top of underline (negative for under baseline)

Returns:

  • (Integer, nil)

    Underline position in FUnits, or nil if not parsed



54
55
56
# File 'lib/fontisan/tables/post_table.rb', line 54

def underline_position
  parsed&.underline_position
end

#underline_thicknessInteger?

Get underline thickness

Returns:

  • (Integer, nil)

    Underline thickness in FUnits, or nil if not parsed



61
62
63
# File 'lib/fontisan/tables/post_table.rb', line 61

def underline_thickness
  parsed&.underline_thickness
end

#versionFloat?

Get post table version

Returns:

  • (Float, nil)

    Version number (1.0, 2.0, 2.5, 3.0, or 4.0)



24
25
26
27
28
# File 'lib/fontisan/tables/post_table.rb', line 24

def version
  return nil unless parsed

  parsed.version
end