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



71
72
73
74
75
# File 'lib/fontisan/tables/post_table.rb', line 71

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



120
121
122
123
124
125
# File 'lib/fontisan/tables/post_table.rb', line 120

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



110
111
112
113
114
# File 'lib/fontisan/tables/post_table.rb', line 110

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



130
131
132
133
134
# File 'lib/fontisan/tables/post_table.rb', line 130

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



47
48
49
50
# File 'lib/fontisan/tables/post_table.rb', line 47

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



38
39
40
41
42
# File 'lib/fontisan/tables/post_table.rb', line 38

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



101
102
103
# File 'lib/fontisan/tables/post_table.rb', line 101

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



87
88
89
# File 'lib/fontisan/tables/post_table.rb', line 87

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



94
95
96
# File 'lib/fontisan/tables/post_table.rb', line 94

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



80
81
82
# File 'lib/fontisan/tables/post_table.rb', line 80

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



139
140
141
# File 'lib/fontisan/tables/post_table.rb', line 139

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



57
58
59
# File 'lib/fontisan/tables/post_table.rb', line 57

def underline_position
  parsed&.underline_position
end

#underline_thicknessInteger?

Get underline thickness

Returns:

  • (Integer, nil)

    Underline thickness in FUnits, or nil if not parsed



64
65
66
# File 'lib/fontisan/tables/post_table.rb', line 64

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)



27
28
29
30
31
# File 'lib/fontisan/tables/post_table.rb', line 27

def version
  return nil unless parsed

  parsed.version
end