Class: RTF::DocumentStyle

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

Overview

This class represents styling attributes that are to be applied at the document level.

Constant Summary collapse

PORTRAIT =

Definition for a document orientation setting.

:portrait
LANDSCAPE =

Definition for a document orientation setting.

:landscape
DEFAULT_LEFT_MARGIN =

Definition for a default margin setting.

1800
DEFAULT_RIGHT_MARGIN =

Definition for a default margin setting.

1800
DEFAULT_TOP_MARGIN =

Definition for a default margin setting.

1440
DEFAULT_BOTTOM_MARGIN =

Definition for a default margin setting.

1440

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

Constructor Details

#initializeDocumentStyle

This is a constructor for the DocumentStyle class. This creates a document style with a default paper setting of A4 and portrait orientation (all other attributes are nil).



244
245
246
247
248
249
250
251
252
# File 'lib/rtf/style.rb', line 244

def initialize
   @paper         = Paper::A4
   @left_margin   = DEFAULT_LEFT_MARGIN
   @right_margin  = DEFAULT_RIGHT_MARGIN
   @top_margin    = DEFAULT_TOP_MARGIN
   @bottom_margin = DEFAULT_BOTTOM_MARGIN
   @gutter        = nil
   @orientation   = PORTRAIT
end

Instance Attribute Details

#bottom_marginObject

Attribute accessor.



234
235
236
# File 'lib/rtf/style.rb', line 234

def bottom_margin
  @bottom_margin
end

#gutterObject

Attribute accessor.



234
235
236
# File 'lib/rtf/style.rb', line 234

def gutter
  @gutter
end

#left_marginObject

Attribute accessor.



234
235
236
# File 'lib/rtf/style.rb', line 234

def left_margin
  @left_margin
end

#orientationObject

Attribute accessor.



234
235
236
# File 'lib/rtf/style.rb', line 234

def orientation
  @orientation
end

#paperObject

Attribute accessor.



234
235
236
# File 'lib/rtf/style.rb', line 234

def paper
  @paper
end

#right_marginObject

Attribute accessor.



234
235
236
# File 'lib/rtf/style.rb', line 234

def right_margin
  @right_margin
end

#top_marginObject

Attribute accessor.



234
235
236
# File 'lib/rtf/style.rb', line 234

def top_margin
  @top_margin
end

Instance Method Details

#body_heightObject

This method fetches the height of the available work area space for a DocumentStyle object.



297
298
299
300
301
302
303
# File 'lib/rtf/style.rb', line 297

def body_height
   if orientation == PORTRAIT
      @paper.height - (@top_margin + @bottom_margin)
   else
      @paper.width - (@top_margin + @bottom_margin)
   end
end

#body_widthObject

This method fetches the width of the available work area space for a DocumentStyle object.



287
288
289
290
291
292
293
# File 'lib/rtf/style.rb', line 287

def body_width
   if orientation == PORTRAIT
      @paper.width - (@left_margin + @right_margin)
   else
      @paper.height - (@left_margin + @right_margin)
   end
end

#is_document_style?Boolean

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

Returns:

  • (Boolean)


256
257
258
# File 'lib/rtf/style.rb', line 256

def is_document_style?
   true
end

#prefix(fonts = nil, colours = nil) ⇒ Object

This method generates a string containing the prefix associated with a style object.

Parameters

document

A reference to the document using the style.



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/rtf/style.rb', line 265

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

   if orientation == LANDSCAPE
      text << "\\paperw#{@paper.height}" if @paper != nil
      text << "\\paperh#{@paper.width}" if @paper != nil
   else
      text << "\\paperw#{@paper.width}" if @paper != nil
      text << "\\paperh#{@paper.height}" if @paper != nil
   end
   text << "\\margl#{@left_margin}" if @left_margin != nil
   text << "\\margr#{@right_margin}" if @right_margin != nil
   text << "\\margt#{@top_margin}" if @top_margin != nil
   text << "\\margb#{@bottom_margin}" if @bottom_margin != nil
   text << "\\gutter#{@gutter}" if @gutter != nil
   text << '\sectd\lndscpsxn' if @orientation == LANDSCAPE

   text.string
end