Class: RRTF::DocumentStyle

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

Overview

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

Constant Summary

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
STYLESHEET_SORT_NAME =

stylesheet sorting codes

0
STYLESHEET_SORT_DEFAULT =

stylesheet styles sorted by name

1
STYLESHEET_SORT_FONT =

stylesheet styles sorted by system default

2
STYLESHEET_SORT_BASEDON =

stylesheet styles sorted by font

3
STYLESHEET_SORT_TYPE =

stylesheet styles sorted by based-on fonts

4

Instance Attribute Summary collapse

Attributes inherited from Style

#additive, #auto_update, #based_on_style_handle, #handle, #hidden, #name, #next_style_handle, #primary, #priority

Instance Method Summary collapse

Methods inherited from Style

#is_character_style?, #is_paragraph_style?, #is_table_style?, #rtf_formatting, #styledef, #stylename, #suffix, #to_rtf

Constructor Details

#initialize(options = {}) ⇒ DocumentStyle

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rrtf/style/document_style.rb', line 41

def initialize(options = {})
  # load default options
  options = {
    "paper_size" => Paper::LETTER,
    "left_margin" => DEFAULT_LEFT_MARGIN,
    "right_margin" => DEFAULT_RIGHT_MARGIN,
    "top_margin" => DEFAULT_TOP_MARGIN,
    "bottom_margin" => DEFAULT_BOTTOM_MARGIN,
    "gutter" => nil,
    "orientation" => PORTRAIT,
    "stylesheet_sort" => STYLESHEET_SORT_DEFAULT
  }.merge(options)

   @paper           = options.delete("paper_size")
   @left_margin     = options.delete("left_margin")
   @right_margin    = options.delete("right_margin")
   @top_margin      = options.delete("top_margin")
   @bottom_margin   = options.delete("bottom_margin")
   @gutter          = options.delete("gutter")
   @orientation     = options.delete("orientation")
   @stylesheet_sort = options.delete("stylesheet_sort")
end

Instance Attribute Details

#bottom_marginObject

Attribute accessor.



31
32
33
# File 'lib/rrtf/style/document_style.rb', line 31

def bottom_margin
  @bottom_margin
end

#gutterObject

Attribute accessor.



31
32
33
# File 'lib/rrtf/style/document_style.rb', line 31

def gutter
  @gutter
end

#left_marginObject

Attribute accessor.



31
32
33
# File 'lib/rrtf/style/document_style.rb', line 31

def left_margin
  @left_margin
end

#orientationObject

Attribute accessor.



31
32
33
# File 'lib/rrtf/style/document_style.rb', line 31

def orientation
  @orientation
end

#paperObject

Attribute accessor.



31
32
33
# File 'lib/rrtf/style/document_style.rb', line 31

def paper
  @paper
end

#right_marginObject

Attribute accessor.



31
32
33
# File 'lib/rrtf/style/document_style.rb', line 31

def right_margin
  @right_margin
end

#stylesheet_sortObject

Attribute accessor.



31
32
33
# File 'lib/rrtf/style/document_style.rb', line 31

def stylesheet_sort
  @stylesheet_sort
end

#top_marginObject

Attribute accessor.



31
32
33
# File 'lib/rrtf/style/document_style.rb', line 31

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.



108
109
110
111
112
113
114
# File 'lib/rrtf/style/document_style.rb', line 108

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.



98
99
100
101
102
103
104
# File 'lib/rrtf/style/document_style.rb', line 98

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)


66
67
68
# File 'lib/rrtf/style/document_style.rb', line 66

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.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rrtf/style/document_style.rb', line 75

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

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

   text.string
end