Class: JotPDF::Document::FontManager

Inherits:
Object
  • Object
show all
Defined in:
lib/jot_pdf/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_font:) ⇒ FontManager

Returns a new instance of FontManager.



53
54
55
56
# File 'lib/jot_pdf/document.rb', line 53

def initialize(default_font:)
  @fonts = {}
  @default_font = default_font
end

Instance Attribute Details

#default_font=(value) ⇒ Object (writeonly)

Sets the attribute default_font

Parameters:

  • value

    the value to set the attribute default_font to.



51
52
53
# File 'lib/jot_pdf/document.rb', line 51

def default_font=(value)
  @default_font = value
end

Instance Method Details

#load_font(path) ⇒ Object



58
59
60
61
62
# File 'lib/jot_pdf/document.rb', line 58

def load_font(path)
  font = TTFunk::File.open(path)
  name = font.name.postscript_name
  @fonts[name] = NonstandardFont.new(font)
end

#loaded_fontsObject



73
74
75
# File 'lib/jot_pdf/document.rb', line 73

def loaded_fonts
  @fonts
end

#require(spec = nil) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/jot_pdf/document.rb', line 64

def require(spec = nil)
  spec ||= @default_font
  if spec.is_a? Symbol
    @fonts[spec] ||= StandardFont.new(spec)
  else
    @fonts.fetch(spec)
  end
end