Class: RRTF::ParagraphStyle
- Includes:
- CharacterFormatting, ParagraphFormatting
- Defined in:
- lib/rrtf/style/paragraph_style.rb
Overview
paragraphs can be styled with character commands in addition to paragraph commands, thus this class includes both paragraph & character formatting modules.
This class represents a styling for a paragraph within an RTF document.
Constant Summary
Constants included from CharacterFormatting
CharacterFormatting::CHARACTER_ATTRIBUTES
Constants included from ParagraphFormatting
RRTF::ParagraphFormatting::PARAGRAPH_ATTRIBUTES
Instance Attribute Summary
Attributes inherited from Style
#additive, #auto_update, #based_on_style_handle, #handle, #hidden, #name, #next_style_handle, #primary, #priority
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ParagraphStyle
constructor
This is the constructor for the CharacterStyle class.
-
#is_paragraph_style? ⇒ Boolean
This method overrides the is_paragraph_style? method inherited from the Style class to always return true.
-
#prefix(document) ⇒ Object
This method generates a string containing the prefix associated with a style object.
- #rtf_formatting(document) ⇒ Object
-
#to_rtf(document, options = {}) ⇒ Object
Converts the stylesheet paragraph style into its RTF representation.
Methods included from CharacterFormatting
#character_formatting_to_rtf, included, #initialize_character_formatting, #push_colours, #push_fonts, #set_character_formatting_from_hashmap
Methods included from ParagraphFormatting
included, #initialize_paragraph_formatting, #paragraph_formatting_to_rtf, #set_paragraph_formatting_from_hashmap
Methods inherited from Style
#is_character_style?, #is_document_style?, #is_table_style?, #styledef, #stylename, #suffix
Constructor Details
#initialize(options = {}) ⇒ ParagraphStyle
This is the constructor for the CharacterStyle class.
18 19 20 21 22 |
# File 'lib/rrtf/style/paragraph_style.rb', line 18 def initialize( = {}) super() initialize_paragraph_formatting() initialize_character_formatting() 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.
26 27 28 |
# File 'lib/rrtf/style/paragraph_style.rb', line 26 def is_paragraph_style? true end |
#prefix(document) ⇒ 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).
73 74 75 76 77 78 79 80 |
# File 'lib/rrtf/style/paragraph_style.rb', line 73 def prefix(document) text = StringIO.new text << "\\s#{handle} " unless handle.nil? text << rtf_formatting(document) text.string end |
#rtf_formatting(document) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rrtf/style/paragraph_style.rb', line 82 def rtf_formatting(document) rtf = StringIO.new pf = paragraph_formatting_to_rtf(document) cf = character_formatting_to_rtf(document) rtf << pf unless pf.nil? rtf << cf unless cf.nil? rtf.string end |
#to_rtf(document, options = {}) ⇒ Object
Converts the stylesheet paragraph style into its RTF representation
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).
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rrtf/style/paragraph_style.rb', line 37 def to_rtf(document, = {}) # load default options = { "uglify" => false, "base_indent" => 0 }.merge() # build formatting helpers base_prefix = ["uglify"] ? '' : ' '*["base_indent"] name_prefix = ["uglify"] ? ' ' : '' suffix = ["uglify"] ? '' : ' ' rtf = StringIO.new rtf << base_prefix rtf << "{\\s#{handle}#{suffix}" rtf << "#{rtf_formatting(document)}#{suffix}" rtf << "\\additive#{suffix}" if @additive rtf << "\\sbasedon#{@based_on_style_handle}#{suffix}" unless @based_on_style_handle.nil? rtf << "\\sautoupd#{suffix}" if @auto_update rtf << "\\snext#{@next_style_handle}#{suffix}" unless @next_style_handle.nil? rtf << "\\sqformat#{suffix}" if @primary rtf << "\\spriority#{@priority}#{suffix}" unless @priority.nil? rtf << "\\shidden#{suffix}" if @hidden rtf << "#{name_prefix}#{name};}" rtf.string end |