Method: Axlsx::Styles#parse_font_options

Defined in:
lib/axlsx/stylesheet/styles.rb

#parse_font_options(options = {}) ⇒ Font|Integer

Note:

noop if none of the options described here are set on the options parameter.

parses add_style options for fonts. If the options hash contains :type => :dxf we return a new Font object. if not, we return the index of the newly created font object in the styles.fonts collection.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • type (Symbol)

    The type of style object we are working with (dxf or xf)

  • fg_color (String)

    The text color

  • sz (Integer)

    The text size

  • b (Boolean)

    Indicates if the text should be bold

  • i (Boolean)

    Indicates if the text should be italicised

  • u (Boolean)

    Indicates if the text should be underlined

  • strike (Boolean)

    Indicates if the text should be rendered with a strikethrough

  • outline (Boolean)

    Indicates if the text should be rendered with a shadow

  • charset (Integer)

    The character set to use.

  • family (Integer)

    The font family to use.

  • font_name (String)

    The name of the font to use

Returns:



325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/axlsx/stylesheet/styles.rb', line 325

def parse_font_options(options = {})
  return if (options.keys & [:fg_color, :sz, :b, :i, :u, :strike, :outline, :shadow, :charset, :family, :font_name]).empty?

  Axlsx.instance_values_for(fonts.first).each do |key, value|
    # Thanks for that 1.8.7 - cant do a simple merge...
    options[key.to_sym] = value unless options.keys.include?(key.to_sym)
  end
  font = Font.new(options)
  font.color = Color.new(:rgb => options[:fg_color]) if options[:fg_color]
  font.name = options[:font_name] if options[:font_name]
  options[:type] == :dxf ? font : fonts << font
end