Class: Pdfrb::Font::TrueType::OS2

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/font/true_type/os2.rb

Overview

OS/2 table parser. Exposes typographic extents and Windows metrics used to compute font ascent / descent / cap height for layout.

Spec: OpenType "OS/2" versions 1–5; offsets vary by version. Only the fields relevant to layout are exposed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ OS2

Returns a new instance of OS2.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pdfrb/font/true_type/os2.rb', line 18

def initialize(data)
  @data = data
  return unless data && data.bytesize >= 78

  @version = u16(0)
  @s_typo_ascender = s16(68)
  @s_typo_descender = s16(70)
  @s_typo_line_gap = s16(72)
  @us_win_ascent = u16(74)
  @us_win_descent = u16(76)

  return unless @version >= 2 && data.bytesize >= 96

  @sx_height = s16(86)
  @s_cap_height = s16(88)
  @us_weight_class = u16(4)
  @fs_selection = u16(62)
end

Instance Attribute Details

#fs_selectionObject (readonly)

Returns the value of attribute fs_selection.



13
14
15
# File 'lib/pdfrb/font/true_type/os2.rb', line 13

def fs_selection
  @fs_selection
end

#s_cap_heightObject (readonly)

Returns the value of attribute s_cap_height.



13
14
15
# File 'lib/pdfrb/font/true_type/os2.rb', line 13

def s_cap_height
  @s_cap_height
end

#s_typo_ascenderObject (readonly)

Returns the value of attribute s_typo_ascender.



13
14
15
# File 'lib/pdfrb/font/true_type/os2.rb', line 13

def s_typo_ascender
  @s_typo_ascender
end

#s_typo_descenderObject (readonly)

Returns the value of attribute s_typo_descender.



13
14
15
# File 'lib/pdfrb/font/true_type/os2.rb', line 13

def s_typo_descender
  @s_typo_descender
end

#s_typo_line_gapObject (readonly)

Returns the value of attribute s_typo_line_gap.



13
14
15
# File 'lib/pdfrb/font/true_type/os2.rb', line 13

def s_typo_line_gap
  @s_typo_line_gap
end

#sx_heightObject (readonly)

Returns the value of attribute sx_height.



13
14
15
# File 'lib/pdfrb/font/true_type/os2.rb', line 13

def sx_height
  @sx_height
end

#us_weight_classObject (readonly)

Returns the value of attribute us_weight_class.



13
14
15
# File 'lib/pdfrb/font/true_type/os2.rb', line 13

def us_weight_class
  @us_weight_class
end

#us_win_ascentObject (readonly)

Returns the value of attribute us_win_ascent.



13
14
15
# File 'lib/pdfrb/font/true_type/os2.rb', line 13

def us_win_ascent
  @us_win_ascent
end

#us_win_descentObject (readonly)

Returns the value of attribute us_win_descent.



13
14
15
# File 'lib/pdfrb/font/true_type/os2.rb', line 13

def us_win_descent
  @us_win_descent
end

#versionObject (readonly)

Returns the value of attribute version.



13
14
15
# File 'lib/pdfrb/font/true_type/os2.rb', line 13

def version
  @version
end

Instance Method Details

#bold?Boolean

Returns:

  • (Boolean)


37
# File 'lib/pdfrb/font/true_type/os2.rb', line 37

def bold?; (@fs_selection || 0) & 0x20 != 0; end

#italic?Boolean

Returns:

  • (Boolean)


38
# File 'lib/pdfrb/font/true_type/os2.rb', line 38

def italic?; (@fs_selection || 0) & 0x01 != 0; end