Class: PDF::Reader::WidthCalculator::TypeZero

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/reader/width_calculator/type_zero.rb

Overview

Type0 (or Composite) fonts are a “root font” that rely on a “descendant font” to do the heavy lifting. The “descendant font” is a CID-Keyed font. see Section 9.7.1, PDF 32000-1:2008, pp 267 so if we are calculating a Type0 font width, we just pass off to the descendant font

Instance Method Summary collapse

Constructor Details

#initialize(font) ⇒ TypeZero

: (PDF::Reader::Font) -> void



15
16
17
# File 'lib/pdf/reader/width_calculator/type_zero.rb', line 15

def initialize(font)
  @font = font
end

Instance Method Details

#glyph_width(code_point) ⇒ Object

: (Integer?) -> Numeric



20
21
22
23
24
25
26
27
28
# File 'lib/pdf/reader/width_calculator/type_zero.rb', line 20

def glyph_width(code_point)
  return 0 if code_point.nil? || code_point < 0

  if descendant_font = @font.descendantfonts.first
    descendant_font.glyph_width(code_point).to_f
  else
    0
  end
end