Class: Font
- Inherits:
-
Object
- Object
- Font
- Defined in:
- lib/surpass/formatting.rb
Constant Summary collapse
- ESCAPEMENT_NONE =
0x00
- ESCAPEMENT_SUPERSCRIPT =
0x01
- ESCAPEMENT_SUBSCRIPT =
0x02
- UNDERLINE_NONE =
0x00
- UNDERLINE_SINGLE =
0x01
- UNDERLINE_SINGLE_ACC =
0x21
- UNDERLINE_DOUBLE =
0x02
- UNDERLINE_DOUBLE_ACC =
0x22
- FAMILY_NONE =
0x00
- FAMILY_ROMAN =
0x01
- FAMILY_SWISS =
0x02
- FAMILY_MODERN =
0x03
- FAMILY_SCRIPT =
0x04
- FAMILY_DECORATIVE =
0x05
- CHARSET_ANSI_LATIN =
0x00
- CHARSET_SYS_DEFAULT =
0x01
- CHARSET_SYMBOL =
0x02
- CHARSET_APPLE_ROMAN =
0x4D
- CHARSET_ANSI_JAP_SHIFT_JIS =
0x80
- CHARSET_ANSI_KOR_HANGUL =
0x81
- CHARSET_ANSI_KOR_JOHAB =
0x82
- CHARSET_ANSI_CHINESE_GBK =
0x86
- CHARSET_ANSI_CHINESE_BIG5 =
0x88
- CHARSET_ANSI_GREEK =
0xA1
- CHARSET_ANSI_TURKISH =
0xA2
- CHARSET_ANSI_VIETNAMESE =
0xA3
- CHARSET_ANSI_HEBREW =
0xB1
- CHARSET_ANSI_ARABIC =
0xB2
- CHARSET_ANSI_BALTIC =
0xBA
- CHARSET_ANSI_CYRILLIC =
0xCC
- CHARSET_ANSI_THAI =
0xDE
- CHARSET_ANSI_LATIN_II =
0xEE
- CHARSET_OEM_LATIN_I =
0xFF
- PLAIN =
0x00
- BOLD =
0x01
- ITALIC =
0x02
- UNDERLINE =
0x04
- STRUCK_OUT =
0x08
- OUTLINE =
0x010
- SHADOW =
0x020
Instance Attribute Summary collapse
-
#bold ⇒ Object
Returns the value of attribute bold.
-
#charset ⇒ Object
Returns the value of attribute charset.
-
#colour_index ⇒ Object
Returns the value of attribute colour_index.
-
#escapement ⇒ Object
Returns the value of attribute escapement.
-
#family ⇒ Object
Returns the value of attribute family.
-
#height ⇒ Object
Returns the value of attribute height.
-
#italic ⇒ Object
Returns the value of attribute italic.
-
#name ⇒ Object
Returns the value of attribute name.
-
#outline ⇒ Object
Returns the value of attribute outline.
-
#shadow ⇒ Object
Returns the value of attribute shadow.
-
#struck_out ⇒ Object
Returns the value of attribute struck_out.
-
#underline ⇒ Object
Returns the value of attribute underline.
-
#weight ⇒ Object
Looks like only 400 = normal, 700 = bold are supported so just use bold = true.
Instance Method Summary collapse
- #colour=(colour_name) ⇒ Object (also: #color=)
- #colour_index_from_name(colour_name) ⇒ Object
-
#initialize(hash = {}) ⇒ Font
constructor
A new instance of Font.
-
#size=(points) ⇒ Object
Convert font size in points to native twips.
- #strikethrough=(arg) ⇒ Object
- #subscript=(arg) ⇒ Object
- #superscript=(arg) ⇒ Object
- #to_biff ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Font
Returns a new instance of Font.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/surpass/formatting.rb', line 122 def initialize(hash = {}) @height = 200 # font size 10 @italic = false @struck_out = false @outline = false @shadow = false @colour_index = 0x7FFF @bold = false @weight = 400 # regular @escapement = ESCAPEMENT_NONE @charset = CHARSET_SYS_DEFAULT @name = 'Arial' @family = FAMILY_NONE @underline = UNDERLINE_NONE hash.each do |k, v| self.send((k.to_s + '=').to_sym, v) end end |
Instance Attribute Details
#bold ⇒ Object
Returns the value of attribute bold.
113 114 115 |
# File 'lib/surpass/formatting.rb', line 113 def bold @bold end |
#charset ⇒ Object
Returns the value of attribute charset.
116 117 118 |
# File 'lib/surpass/formatting.rb', line 116 def charset @charset end |
#colour_index ⇒ Object
Returns the value of attribute colour_index.
112 113 114 |
# File 'lib/surpass/formatting.rb', line 112 def colour_index @colour_index end |
#escapement ⇒ Object
Returns the value of attribute escapement.
115 116 117 |
# File 'lib/surpass/formatting.rb', line 115 def escapement @escapement end |
#family ⇒ Object
Returns the value of attribute family.
119 120 121 |
# File 'lib/surpass/formatting.rb', line 119 def family @family end |
#height ⇒ Object
Returns the value of attribute height.
107 108 109 |
# File 'lib/surpass/formatting.rb', line 107 def height @height end |
#italic ⇒ Object
Returns the value of attribute italic.
108 109 110 |
# File 'lib/surpass/formatting.rb', line 108 def italic @italic end |
#name ⇒ Object
Returns the value of attribute name.
117 118 119 |
# File 'lib/surpass/formatting.rb', line 117 def name @name end |
#outline ⇒ Object
Returns the value of attribute outline.
110 111 112 |
# File 'lib/surpass/formatting.rb', line 110 def outline @outline end |
#shadow ⇒ Object
Returns the value of attribute shadow.
111 112 113 |
# File 'lib/surpass/formatting.rb', line 111 def shadow @shadow end |
#struck_out ⇒ Object
Returns the value of attribute struck_out.
109 110 111 |
# File 'lib/surpass/formatting.rb', line 109 def struck_out @struck_out end |
#underline ⇒ Object
Returns the value of attribute underline.
120 121 122 |
# File 'lib/surpass/formatting.rb', line 120 def underline @underline end |
#weight ⇒ Object
Looks like only 400 = normal, 700 = bold are supported so just use bold = true.
114 115 116 |
# File 'lib/surpass/formatting.rb', line 114 def weight @weight end |
Instance Method Details
#colour=(colour_name) ⇒ Object Also known as: color=
208 209 210 211 212 213 214 215 |
# File 'lib/surpass/formatting.rb', line 208 def colour=(colour_name) new_colour = colour_index_from_name(colour_name) if new_colour.nil? raise "Invalid Colour #{colour_name}" else @colour_index = new_colour end end |
#colour_index_from_name(colour_name) ⇒ Object
204 205 206 |
# File 'lib/surpass/formatting.rb', line 204 def colour_index_from_name(colour_name) Formatting::COLOURS[colour_name.to_s] end |
#size=(points) ⇒ Object
Convert font size in points to native twips
148 149 150 |
# File 'lib/surpass/formatting.rb', line 148 def size=(points) @height = points * 20 end |
#strikethrough=(arg) ⇒ Object
152 153 154 |
# File 'lib/surpass/formatting.rb', line 152 def strikethrough=(arg) @struck_out = arg end |
#subscript=(arg) ⇒ Object
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/surpass/formatting.rb', line 156 def subscript=(arg) case arg when TrueClass @escapement = ESCAPEMENT_SUBSCRIPT when FalseClass @escapement = ESCAPEMENT_NONE else raise "I don't know how to set subscript to #{arg.inspect}." end end |
#superscript=(arg) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/surpass/formatting.rb', line 167 def superscript=(arg) case arg when TrueClass @escapement = ESCAPEMENT_SUPERSCRIPT when FalseClass @escapement = ESCAPEMENT_NONE else raise "I don't know how to set superscript to #{arg.inspect}." end end |
#to_biff ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/surpass/formatting.rb', line 219 def to_biff = PLAIN |= BOLD if @bold |= ITALIC if @italic |= UNDERLINE if (@underline != UNDERLINE_NONE) |= STRUCK_OUT if @struck_out |= OUTLINE if @outline |= SHADOW if @shadow @weight = 700 if @bold args = [@height, , @colour_index, @weight, @escapement, @underline, @family, @charset, @name] FontRecord.new(*args).to_biff end |