Class: RTF::DocumentStyle
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
-
#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.
-
#top_margin ⇒ Object
Attribute accessor.
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 ⇒ 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?, #suffix
Constructor Details
#initialize ⇒ DocumentStyle
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_margin ⇒ Object
Attribute accessor.
234 235 236 |
# File 'lib/rtf/style.rb', line 234 def bottom_margin @bottom_margin end |
#gutter ⇒ Object
Attribute accessor.
234 235 236 |
# File 'lib/rtf/style.rb', line 234 def gutter @gutter end |
#left_margin ⇒ Object
Attribute accessor.
234 235 236 |
# File 'lib/rtf/style.rb', line 234 def left_margin @left_margin end |
#orientation ⇒ Object
Attribute accessor.
234 235 236 |
# File 'lib/rtf/style.rb', line 234 def orientation @orientation end |
#paper ⇒ Object
Attribute accessor.
234 235 236 |
# File 'lib/rtf/style.rb', line 234 def paper @paper end |
#right_margin ⇒ Object
Attribute accessor.
234 235 236 |
# File 'lib/rtf/style.rb', line 234 def right_margin @right_margin end |
#top_margin ⇒ Object
Attribute accessor.
234 235 236 |
# File 'lib/rtf/style.rb', line 234 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.
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_width ⇒ Object
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.
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 |