class Prawn::SVG::Font

Constants

GENERIC_CSS_FONT_MAPPING

Attributes

name[R]
style[R]
weight[R]

Public Class Methods

new(name, weight, style, font_registry: nil) click to toggle source
# File lib/prawn/svg/font.rb, line 23
def initialize(name, weight, style, font_registry: nil)
  name = GENERIC_CSS_FONT_MAPPING.fetch(name, name) # If it's a standard CSS font name, map it to one of the standard PDF fonts.

  @font_registry = font_registry
  @name = font_registry.correctly_cased_font_name(name) || name
  @weight = weight
  @style = style
end
weight_for_css_font_weight(weight) click to toggle source
# File lib/prawn/svg/font.rb, line 12
def self.weight_for_css_font_weight(weight)
  case weight
  when '100', '200', '300'    then :light
  when '400', '500', 'normal' then :normal
  when '600'                  then :semibold
  when '700', 'bold'          then :bold
  when '800'                  then :extrabold
  when '900'                  then :black
  end
end

Public Instance Methods

installed?() click to toggle source
# File lib/prawn/svg/font.rb, line 32
def installed?
  subfamilies = @font_registry.installed_fonts[name]
  !subfamilies.nil? && subfamilies.key?(subfamily)
end
subfamily() click to toggle source

Construct a subfamily name, ensuring that the subfamily is a valid one for the font.

# File lib/prawn/svg/font.rb, line 38
def subfamily
  if subfamilies = @font_registry.installed_fonts[name]
    if subfamilies.key?(subfamily_name)
      subfamily_name
    elsif subfamilies.key?(:normal)
      :normal
    else
      subfamilies.keys.first
    end
  end
end

Private Instance Methods

subfamily_name() click to toggle source

Construct a subfamily name from the weight and style information. Note that this name might not actually exist in the font.

# File lib/prawn/svg/font.rb, line 54
def subfamily_name
  if weight == :normal && style
    style
  elsif weight || style
    [weight, style].compact.join('_').to_sym
  else
    :normal
  end
end