Class: Axlsx::Font

Inherits:
Object
  • Object
show all
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)

Constructor Details

- (Font) initialize(options = {})

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)
  • strike (Boolean)
  • outline (Boolean)
  • shadow (Boolean)
  • condense (Boolean)
  • extend (Boolean)
  • color (Color)
  • sz (Integer)


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

def initialize(options={})
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
  end
end

Instance Attribute Details

- (Boolean) b

Indicates if the font should be rendered in bold

Returns:

  • (Boolean)


50
51
52
# File 'lib/axlsx/stylesheet/font.rb', line 50

def b
  @b
end

- (Integer) charset

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)


33
34
35
# File 'lib/axlsx/stylesheet/font.rb', line 33

def charset
  @charset
end

- (Color) color

The color of the font

Returns:



78
79
80
# File 'lib/axlsx/stylesheet/font.rb', line 78

def color
  @color
end

- (Boolean) condense

Indicates if the font should be condensed

Returns:

  • (Boolean)


70
71
72
# File 'lib/axlsx/stylesheet/font.rb', line 70

def condense
  @condense
end

- (Boolean) extend

The font’s extend property

Returns:

  • (Boolean)


74
75
76
# File 'lib/axlsx/stylesheet/font.rb', line 74

def extend
  @extend
end

- (Integer) family

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)


46
47
48
# File 'lib/axlsx/stylesheet/font.rb', line 46

def family
  @family
end

- (Boolean) i

Indicates if the font should be rendered italicized

Returns:

  • (Boolean)


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

def i
  @i
end

- (String) name

The name of the font

Returns:

  • (String)


8
9
10
# File 'lib/axlsx/stylesheet/font.rb', line 8

def name
  @name
end

- (Boolean) outline

Indicates if the font should be rendered with an outline

Returns:

  • (Boolean)


62
63
64
# File 'lib/axlsx/stylesheet/font.rb', line 62

def outline
  @outline
end

- (Boolean) shadow

Indicates if the font should be rendered with a shadow

Returns:

  • (Boolean)


66
67
68
# File 'lib/axlsx/stylesheet/font.rb', line 66

def shadow
  @shadow
end

- (Boolean) strike

Indicates if the font should be rendered with a strikthrough

Returns:

  • (Boolean)


58
59
60
# File 'lib/axlsx/stylesheet/font.rb', line 58

def strike
  @strike
end

- (Integer) sz

The size of the font.

Returns:

  • (Integer)


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

def sz
  @sz
end

Instance Method Details

- (String) to_xml(xml)

Serializes the fill

Parameters:

  • xml (Nokogiri::XML::Builder)

    The document builder instance this objects xml will be added to.

Returns:

  • (String)


120
121
122
123
124
125
126
# File 'lib/axlsx/stylesheet/font.rb', line 120

def to_xml(xml)
  xml.font {
    self.instance_values.each do |k, v|
      v.is_a?(Color) ? v.to_xml(xml) : xml.send(k, {:val => v})            
    end
  }
end