Class: RRTF::DocumentStyle
- 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
-
#bottom_margin ⇒ Object
Attribute accessor.
-
#gutter ⇒ Object
Attribute accessor.
-
#left_margin ⇒ Object
Attribute accessor.
-
#orientation ⇒ Object
Attribute accessor.
-
#paper ⇒ Object
Attribute accessor.
-
#right_margin ⇒ Object
Attribute accessor.
-
#stylesheet_sort ⇒ Object
Attribute accessor.
-
#top_margin ⇒ Object
Attribute accessor.
Attributes inherited from Style
#additive, #auto_update, #based_on_style_handle, #handle, #hidden, #name, #next_style_handle, #primary, #priority
Instance Method Summary collapse
-
#body_height ⇒ Object
This method fetches the height of the available work area space for a DocumentStyle object.
-
#body_width ⇒ Object
This method fetches the width of the available work area space for a DocumentStyle object.
-
#initialize(options = {}) ⇒ DocumentStyle
constructor
This is a constructor for the DocumentStyle class.
-
#is_document_style? ⇒ Boolean
This method overrides the is_document_style? method inherited from the Style class to always return true.
-
#prefix(fonts = nil, colours = nil) ⇒ Object
This method generates a string containing the prefix associated with a style object.
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( = {}) # load default 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() @paper = .delete("paper_size") @left_margin = .delete("left_margin") @right_margin = .delete("right_margin") @top_margin = .delete("top_margin") @bottom_margin = .delete("bottom_margin") @gutter = .delete("gutter") @orientation = .delete("orientation") @stylesheet_sort = .delete("stylesheet_sort") end |
Instance Attribute Details
#bottom_margin ⇒ Object
Attribute accessor.
31 32 33 |
# File 'lib/rrtf/style/document_style.rb', line 31 def bottom_margin @bottom_margin end |
#gutter ⇒ Object
Attribute accessor.
31 32 33 |
# File 'lib/rrtf/style/document_style.rb', line 31 def gutter @gutter end |
#left_margin ⇒ Object
Attribute accessor.
31 32 33 |
# File 'lib/rrtf/style/document_style.rb', line 31 def left_margin @left_margin end |
#orientation ⇒ Object
Attribute accessor.
31 32 33 |
# File 'lib/rrtf/style/document_style.rb', line 31 def orientation @orientation end |
#paper ⇒ Object
Attribute accessor.
31 32 33 |
# File 'lib/rrtf/style/document_style.rb', line 31 def paper @paper end |
#right_margin ⇒ Object
Attribute accessor.
31 32 33 |
# File 'lib/rrtf/style/document_style.rb', line 31 def right_margin @right_margin end |
#stylesheet_sort ⇒ Object
Attribute accessor.
31 32 33 |
# File 'lib/rrtf/style/document_style.rb', line 31 def stylesheet_sort @stylesheet_sort end |
#top_margin ⇒ Object
Attribute accessor.
31 32 33 |
# File 'lib/rrtf/style/document_style.rb', line 31 def top_margin @top_margin end |
Instance Method Details
#body_height ⇒ Object
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_width ⇒ Object
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.
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 |