Class: Fontisan::Audit::StyleExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/audit/style_extractor.rb

Overview

Extracts style descriptors from a loaded font's OS/2 and head tables. One extractor per font; cheap to construct.

All fields return nil when the underlying table is absent or the value is unset (e.g., Type 1 fonts have no OS/2). Callers must tolerate nils.

Scope: OS/2 + head only. fvar-derived fields (axes, named instances, variable presence) live on Extractors::VariationDetail — this is the MECE split between static style metadata and variation metadata.

Duck typing: uses only font.has_table?(tag) and font.table(tag). No class-specific branching — any object that honors the SFNT contract works (TrueTypeFont, OpenTypeFont, WoffFont, Woff2Font, and individual faces from collections).

Instance Method Summary collapse

Constructor Details

#initialize(font) ⇒ StyleExtractor

Returns a new instance of StyleExtractor.

Parameters:

  • font (Object)

    an SFNT-compatible font object



26
27
28
# File 'lib/fontisan/audit/style_extractor.rb', line 26

def initialize(font)
  @font = font
end

Instance Method Details

#boldObject

head.macStyle bit 0 (BOLD). Per OpenType convention, bold is read from head, not OS/2.



47
48
49
50
51
# File 'lib/fontisan/audit/style_extractor.rb', line 47

def bold
  return nil unless head

  (head.mac_style.to_i & (1 << MAC_STYLE_BOLD_BIT)).nonzero?
end

#italicObject

OS/2.fsSelection bit 0 (ITALIC).



39
40
41
42
43
# File 'lib/fontisan/audit/style_extractor.rb', line 39

def italic
  return nil unless os2

  (os2.fs_selection.to_i & (1 << FS_SELECTION_ITALIC_BIT)).nonzero?
end

#panoseObject

OS/2.panose as a space-joined 10-digit string, e.g. "2 0 5 3 0 0 0 0 0 0". Returns nil if there is no OS/2 table.



55
56
57
58
59
60
61
62
63
# File 'lib/fontisan/audit/style_extractor.rb', line 55

def panose
  bytes = os2&.panose
  return nil if bytes.nil?

  bytes = bytes.to_a
  return nil if bytes.empty?

  bytes.join(" ")
end

#weight_classObject



30
31
32
# File 'lib/fontisan/audit/style_extractor.rb', line 30

def weight_class
  os2&.us_weight_class&.to_i
end

#width_classObject



34
35
36
# File 'lib/fontisan/audit/style_extractor.rb', line 34

def width_class
  os2&.us_width_class&.to_i
end