Module: Fontico::Prawn::DocumentExtensions

Defined in:
lib/fontico/prawn.rb

Instance Method Summary collapse

Instance Method Details

#fontico!(family: FAMILY, path: Fontico.font_file) ⇒ Object

Registers the built TTF as a font family. Call once per document.



22
23
24
25
26
27
28
29
30
# File 'lib/fontico/prawn.rb', line 22

def fontico!(family: FAMILY, path: Fontico.font_file)
  unless File.exist?(path)
    raise Fontico::Error,
          "#{path} does not exist — add `ttf` to targets: and run rake fontico:build"
  end

  font_families.update(family => { normal: path })
  self
end

#glyph(name) ⇒ Object

The glyph character for name, for interpolating into a text run. Wrap the run in font(Fontico::Prawn::FAMILY) so it renders.



34
# File 'lib/fontico/prawn.rb', line 34

def glyph(name) = Fontico.glyph(name)

#icon(name, size: font_size, color: nil, family: FAMILY, **options) ⇒ Object

Draws one icon. Colour and size come from Prawn, exactly like text, because a glyph is text.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fontico/prawn.rb', line 38

def icon(name, size: font_size, color: nil, family: FAMILY, **options)
  if Fontico.lockfile.multicolor?(name.to_s)
    raise Fontico::Error,
          "#{name} is multicolour and is not in the font. Draw it with " \
          "prawn-svg from the sprite source instead."
  end

  previous = fill_color
  fill_color(color) if color
  font(family, size: size) { text(Fontico.glyph(name), **options) }
  fill_color(previous) if color
  self
end

#icon_at(name, at:, size: font_size, family: FAMILY) ⇒ Object

Same, positioned — for letterheads and table cells.



53
54
55
56
# File 'lib/fontico/prawn.rb', line 53

def icon_at(name, at:, size: font_size, family: FAMILY)
  font(family, size: size) { draw_text(Fontico.glyph(name), at: at) }
  self
end