class Prawn::SVG::Properties

Constants

ATTR_NAMES
Config
EM
FONT_SIZES
NAMES
PROPERTIES
PROPERTY_CONFIGS

Public Instance Methods

compute_properties(other) click to toggle source
# File lib/prawn/svg/properties.rb, line 86
def compute_properties(other)
  PROPERTY_CONFIGS.each do |config|
    value = other.send(config.attr)

    if value && value != 'inherit'
      value = compute_font_size_property(value).to_s if config.attr == "font_size"
      instance_variable_set(config.ivar, value)

    elsif value.nil? && !config.inheritable?
      instance_variable_set(config.ivar, config.default)
    end
  end
end
load_default_stylesheet() click to toggle source
# File lib/prawn/svg/properties.rb, line 52
def load_default_stylesheet
  PROPERTY_CONFIGS.each do |config|
    instance_variable_set(config.ivar, config.default)
  end

  self
end
load_hash(hash) click to toggle source
# File lib/prawn/svg/properties.rb, line 82
def load_hash(hash)
  hash.each { |name, value| set(name, value) if value }
end
numerical_font_size() click to toggle source
# File lib/prawn/svg/properties.rb, line 100
def numerical_font_size
  # px = pt for PDFs
  FONT_SIZES[font_size] || font_size.to_f
end
set(name, value) click to toggle source
# File lib/prawn/svg/properties.rb, line 60
def set(name, value)
  if config = PROPERTIES[name.to_s.downcase]
    value = value.strip
    keyword = value.downcase
    keywords = config.keywords || ['inherit']

    if keywords.include?(keyword)
      value = keyword
    elsif config.keyword_restricted?
      value = config.default
    end

    instance_variable_set(config.ivar, value)
  end
end
to_h() click to toggle source
# File lib/prawn/svg/properties.rb, line 76
def to_h
  PROPERTIES.each.with_object({}) do |(name, config), result|
    result[name] = instance_variable_get(config.ivar)
  end
end

Private Instance Methods

compute_font_size_property(value) click to toggle source
# File lib/prawn/svg/properties.rb, line 107
def compute_font_size_property(value)
  if value[-1] == "%"
    numerical_font_size * (value.to_f / 100.0)
  elsif value == 'larger'
    numerical_font_size + 4
  elsif value == 'smaller'
    numerical_font_size - 4
  elsif value.match(/(\d|\.)em\z/i)
    numerical_font_size * value.to_f
  elsif value.match(/(\d|\.)rem\z/i)
    value.to_f * EM
  else
    FONT_SIZES[value] || value.to_f
  end
end