Class: RTF::ParagraphStyle

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

Overview

This class represents a styling for a paragraph within an RTF document.

Constant Summary collapse

LEFT_JUSTIFY =

A definition for a paragraph justification setting.

:ql
RIGHT_JUSTIFY =

A definition for a paragraph justification setting.

:qr
CENTER_JUSTIFY =

A definition for a paragraph justification setting.

:qc
CENTRE_JUSTIFY =

A definition for a paragraph justification setting.

:qc
FULL_JUSTIFY =

A definition for a paragraph justification setting.

:qj

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_character_style?, #is_document_style?, #is_table_style?, #suffix

Constructor Details

#initialize(base = nil) ⇒ ParagraphStyle

This is a constructor for the ParagraphStyle class.

Parameters

base

A reference to base object that the new style will inherit its initial properties from. Defaults to nil.



170
171
172
173
174
175
176
177
178
179
# File 'lib/rtf/style.rb', line 170

def initialize(base=nil)
   @justification     = base == nil ? LEFT_JUSTIFY : base.justification
   @left_indent       = base == nil ? nil : base.left_indent
   @right_indent      = base == nil ? nil : base.right_indent
   @first_line_indent = base == nil ? nil : base.first_line_indent
   @space_before      = base == nil ? nil : base.space_before
   @space_after       = base == nil ? nil : base.space_after
   @line_spacing      = base == nil ? nil : base.line_spacing
   @flow              = base == nil ? LEFT_TO_RIGHT : base.flow
end

Instance Attribute Details

#first_line_indentObject

Attribute accessor.



156
157
158
# File 'lib/rtf/style.rb', line 156

def first_line_indent
  @first_line_indent
end

#flowObject

Attribute accessor.



156
157
158
# File 'lib/rtf/style.rb', line 156

def flow
  @flow
end

#justificationObject

Attribute accessor.



156
157
158
# File 'lib/rtf/style.rb', line 156

def justification
  @justification
end

#left_indentObject

Attribute accessor.



156
157
158
# File 'lib/rtf/style.rb', line 156

def left_indent
  @left_indent
end

#line_spacingObject

Attribute accessor.



156
157
158
# File 'lib/rtf/style.rb', line 156

def line_spacing
  @line_spacing
end

#right_indentObject

Attribute accessor.



156
157
158
# File 'lib/rtf/style.rb', line 156

def right_indent
  @right_indent
end

#space_afterObject

Attribute accessor.



156
157
158
# File 'lib/rtf/style.rb', line 156

def space_after
  @space_after
end

#space_beforeObject

Attribute accessor.



156
157
158
# File 'lib/rtf/style.rb', line 156

def space_before
  @space_before
end

Instance Method Details

#is_paragraph_style?Boolean

This method overrides the is_paragraph_style? method inherited from the Style class to always return true.

Returns:

  • (Boolean)


183
184
185
# File 'lib/rtf/style.rb', line 183

def is_paragraph_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).



195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/rtf/style.rb', line 195

def prefix(fonts, colours)
   text = StringIO.new

   text << "\\#{@justification.id2name}"
   text << "\\li#{@left_indent}" if @left_indent != nil
   text << "\\ri#{@right_indent}" if @right_indent != nil
   text << "\\fi#{@first_line_indent}" if @first_line_indent != nil
   text << "\\sb#{@space_before}" if @space_before != nil
   text << "\\sa#{@space_after}" if @space_after != nil
   text << "\\sl#{@line_spacing}" if @line_spacing != nil
   text << '\rtlpar' if @flow == RIGHT_TO_LEFT

   text.string.length > 0 ? text.string : nil
end