Class: RTF::CharacterStyle

Inherits:
Style
  • Object
show all
Defined in:
lib/rtf/style.rb

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

Instance Method Summary collapse

Methods inherited from Style

#is_document_style?, #is_paragraph_style?, #is_table_style?, #suffix

Constructor Details

#initializeCharacterStyle

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

#backgroundObject

Attribute accessor.



69
70
71
# File 'lib/rtf/style.rb', line 69

def background
  @background
end

#boldObject

Attribute accessor.



69
70
71
# File 'lib/rtf/style.rb', line 69

def bold
  @bold
end

#capitaliseObject Also known as: capitalize

Attribute accessor.



69
70
71
# File 'lib/rtf/style.rb', line 69

def capitalise
  @capitalise
end

#flowObject

Attribute accessor.



69
70
71
# File 'lib/rtf/style.rb', line 69

def flow
  @flow
end

#fontObject

Attribute accessor.



69
70
71
# File 'lib/rtf/style.rb', line 69

def font
  @font
end

#font_sizeObject

Attribute accessor.



69
70
71
# File 'lib/rtf/style.rb', line 69

def font_size
  @font_size
end

#foregroundObject

Attribute accessor.



69
70
71
# File 'lib/rtf/style.rb', line 69

def foreground
  @foreground
end

#hiddenObject

Attribute accessor.



69
70
71
# File 'lib/rtf/style.rb', line 69

def hidden
  @hidden
end

#italicObject

Attribute accessor.



69
70
71
# File 'lib/rtf/style.rb', line 69

def italic
  @italic
end

#strikeObject

Attribute accessor.



69
70
71
# File 'lib/rtf/style.rb', line 69

def strike
  @strike
end

#subscriptObject

Attribute accessor.



69
70
71
# File 'lib/rtf/style.rb', line 69

def subscript
  @subscript
end

#superscriptObject

Attribute accessor.



69
70
71
# File 'lib/rtf/style.rb', line 69

def superscript
  @superscript
end

#underlineObject

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.

Returns:

  • (Boolean)


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