Class: Axlsx::Font

Inherits:
Object
  • Object
show all
Includes:
OptionsParser
Defined in:
lib/axlsx/stylesheet/font.rb

Overview

Note:

The recommended way to manage fonts, and other styles is Styles#add_style

The Font class details a font instance for use in styling cells.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(options = {}) ⇒ Font

Creates a new Font

Parameters:

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

    a customizable set of options

Options Hash (options):

  • name (String)
  • charset (Integer)
  • family (Integer)
  • family (Integer)
  • b (Boolean)
  • i (Boolean)
  • u (Boolean)
  • strike (Boolean)
  • outline (Boolean)
  • shadow (Boolean)
  • condense (Boolean)
  • extend (Boolean)
  • color (Color)
  • sz (Integer)


24
25
26
# File 'lib/axlsx/stylesheet/font.rb', line 24

def initialize(options={})
  parse_options options
end

Instance Attribute Details

#bBoolean

Indicates if the font should be rendered in bold

Returns:

  • (Boolean)


72
73
74
# File 'lib/axlsx/stylesheet/font.rb', line 72

def b
  @b
end

#charsetInteger

Note:

The following values are defined in the OOXML specification and are OS dependant values 0 ANSI_CHARSET 1 DEFAULT_CHARSET 2 SYMBOL_CHARSET 77 MAC_CHARSET 128 SHIFTJIS_CHARSET 129 HANGUL_CHARSET 130 JOHAB_CHARSET 134 GB2312_CHARSET 136 CHINESEBIG5_CHARSET 161 GREEK_CHARSET 162 TURKISH_CHARSET 163 VIETNAMESE_CHARSET 177 HEBREW_CHARSET 178 ARABIC_CHARSET 186 BALTIC_CHARSET 204 RUSSIAN_CHARSET 222 THAI_CHARSET 238 EASTEUROPE_CHARSET 255 OEM_CHARSET

The charset of the font

Returns:

  • (Integer)


55
56
57
# File 'lib/axlsx/stylesheet/font.rb', line 55

def charset
  @charset
end

#colorColor

The color of the font

Returns:



107
108
109
# File 'lib/axlsx/stylesheet/font.rb', line 107

def color
  @color
end

#condenseBoolean

Indicates if the font should be condensed

Returns:

  • (Boolean)


99
100
101
# File 'lib/axlsx/stylesheet/font.rb', line 99

def condense
  @condense
end

#extendBoolean

The font's extend property

Returns:

  • (Boolean)


103
104
105
# File 'lib/axlsx/stylesheet/font.rb', line 103

def extend
  @extend
end

#familyInteger

Note:

The following are defined OOXML specification 0 Not applicable. 1 Roman 2 Swiss 3 Modern 4 Script 5 Decorative 6..14 Reserved for future use

The font's family

Returns:

  • (Integer)


68
69
70
# File 'lib/axlsx/stylesheet/font.rb', line 68

def family
  @family
end

#iBoolean

Indicates if the font should be rendered italicized

Returns:

  • (Boolean)


76
77
78
# File 'lib/axlsx/stylesheet/font.rb', line 76

def i
  @i
end

#nameString

The name of the font

Returns:

  • (String)


30
31
32
# File 'lib/axlsx/stylesheet/font.rb', line 30

def name
  @name
end

#outlineBoolean

Indicates if the font should be rendered with an outline

Returns:

  • (Boolean)


91
92
93
# File 'lib/axlsx/stylesheet/font.rb', line 91

def outline
  @outline
end

#shadowBoolean

Indicates if the font should be rendered with a shadow

Returns:

  • (Boolean)


95
96
97
# File 'lib/axlsx/stylesheet/font.rb', line 95

def shadow
  @shadow
end

#strikeBoolean

Indicates if the font should be rendered with a strikthrough

Returns:

  • (Boolean)


87
88
89
# File 'lib/axlsx/stylesheet/font.rb', line 87

def strike
  @strike
end

#szInteger

The size of the font.

Returns:

  • (Integer)


111
112
113
# File 'lib/axlsx/stylesheet/font.rb', line 111

def sz
  @sz
end

#uString

Note:

true or false is for backwards compatibility and is reassigned to :single or :none respectively

Indicates if the font should be rendered underlined It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting, true, false

Returns:

  • (String)


83
84
85
# File 'lib/axlsx/stylesheet/font.rb', line 83

def u
  @u
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


148
149
150
151
152
153
154
# File 'lib/axlsx/stylesheet/font.rb', line 148

def to_xml_string(str = '')
  str << '<font>'
  instance_values.each do |k, v|
    v.is_a?(Color) ? v.to_xml_string(str) : (str << ('<' << k.to_s << ' val="' << Axlsx.booleanize(v).to_s << '"/>'))
  end
  str << '</font>'
end