Class: RTF::CharacterStyle
Overview
This class represents a character style for an RTF document.
Constant Summary
Constants inherited from Style
Style::LEFT_TO_RIGHT, Style::RIGHT_TO_LEFT
Instance Attribute Summary collapse
-
#background ⇒ Object
Attribute accessor.
-
#bold ⇒ Object
Attribute accessor.
-
#capitalise ⇒ Object
(also: #capitalize)
Attribute accessor.
-
#flow ⇒ Object
Attribute accessor.
-
#font ⇒ Object
Attribute accessor.
-
#font_size ⇒ Object
Attribute accessor.
-
#foreground ⇒ Object
Attribute accessor.
-
#hidden ⇒ Object
Attribute accessor.
-
#italic ⇒ Object
Attribute accessor.
-
#strike ⇒ Object
Attribute accessor.
-
#subscript ⇒ Object
Attribute accessor.
-
#superscript ⇒ Object
Attribute accessor.
-
#underline ⇒ Object
Attribute accessor.
Instance Method Summary collapse
-
#initialize ⇒ CharacterStyle
constructor
This is the constructor for the CharacterStyle class.
-
#is_character_style? ⇒ Boolean
This method overrides the is_character_style? method inherited from the Style class to always return true.
-
#prefix(fonts, colours) ⇒ Object
This method generates a string containing the prefix associated with a style object.
Methods inherited from Style
#is_document_style?, #is_paragraph_style?, #is_table_style?, #suffix
Constructor Details
#initialize ⇒ CharacterStyle
This is the constructor for the CharacterStyle class.
Exceptions
- RTFError
-
Generate if the parent style specified is not an instance of the CharacterStyle class.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rtf/style.rb', line 83 def initialize @bold = false @italic = false @underline = false @superscript = false @capitalise = false @strike = false @subscript = false @hidden = false @foreground = nil @background = nil @font = nil @font_size = nil @flow = LEFT_TO_RIGHT end |
Instance Attribute Details
#background ⇒ Object
Attribute accessor.
69 70 71 |
# File 'lib/rtf/style.rb', line 69 def background @background end |
#bold ⇒ Object
Attribute accessor.
69 70 71 |
# File 'lib/rtf/style.rb', line 69 def bold @bold end |
#capitalise ⇒ Object Also known as: capitalize
Attribute accessor.
69 70 71 |
# File 'lib/rtf/style.rb', line 69 def capitalise @capitalise end |
#flow ⇒ Object
Attribute accessor.
69 70 71 |
# File 'lib/rtf/style.rb', line 69 def flow @flow end |
#font ⇒ Object
Attribute accessor.
69 70 71 |
# File 'lib/rtf/style.rb', line 69 def font @font end |
#font_size ⇒ Object
Attribute accessor.
69 70 71 |
# File 'lib/rtf/style.rb', line 69 def font_size @font_size end |
#foreground ⇒ Object
Attribute accessor.
69 70 71 |
# File 'lib/rtf/style.rb', line 69 def foreground @foreground end |
#hidden ⇒ Object
Attribute accessor.
69 70 71 |
# File 'lib/rtf/style.rb', line 69 def hidden @hidden end |
#italic ⇒ Object
Attribute accessor.
69 70 71 |
# File 'lib/rtf/style.rb', line 69 def italic @italic end |
#strike ⇒ Object
Attribute accessor.
69 70 71 |
# File 'lib/rtf/style.rb', line 69 def strike @strike end |
#subscript ⇒ Object
Attribute accessor.
69 70 71 |
# File 'lib/rtf/style.rb', line 69 def subscript @subscript end |
#superscript ⇒ Object
Attribute accessor.
69 70 71 |
# File 'lib/rtf/style.rb', line 69 def superscript @superscript end |
#underline ⇒ Object
Attribute accessor.
69 70 71 |
# File 'lib/rtf/style.rb', line 69 def underline @underline end |
Instance Method Details
#is_character_style? ⇒ Boolean
This method overrides the is_character_style? method inherited from the Style class to always return true.
101 102 103 |
# File 'lib/rtf/style.rb', line 101 def is_character_style? true end |
#prefix(fonts, colours) ⇒ Object
This method generates a string containing the prefix associated with a style object.
Parameters
- fonts
-
A reference to a FontTable containing any fonts used by the style (may be nil if no fonts used).
- colours
-
A reference to a ColourTable containing any colours used by the style (may be nil if no colours used).
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/rtf/style.rb', line 113 def prefix(fonts, colours) text = StringIO.new text << '\b' if @bold text << '\i' if @italic text << '\ul' if @underline text << '\super' if @superscript text << '\caps' if @capitalise text << '\strike' if @strike text << '\sub' if @subscript text << '\v' if @hidden text << "\\cf#{colours.index(@foreground)}" if @foreground != nil text << "\\cb#{colours.index(@background)}" if @background != nil text << "\\f#{fonts.index(@font)}" if @font != nil text << "\\fs#{@font_size.to_i}" if @font_size != nil text << '\rtlch' if @flow == RIGHT_TO_LEFT text.string.length > 0 ? text.string : nil end |