Module: RRTF::PageFormatting
- Included in:
- DocumentProperties, SectionStyle
- Defined in:
- lib/rrtf/formatting.rb
Overview
Page formatting attributes and methods.
Constant Summary
- PAGE_ATTRIBUTES =
Formatting attributes that can be applied to an RTF document or a section in a document.
{ "orientation" => { "default" => :portrait, "dictionary" => { "PORTRAIT" => :portrait, "LANDSCAPE" => :landscape }, "to_rtf" => lambda do |value, targ| case targ when :document "\\landscape" if value == :landscape when :section "\\lndscpsxn" if value == :landscape end # case end }, "size" => { "default" => RRTF::Page::Size.new, "from_user" => lambda{ |value| RRTF::Page::Size.new(value) }, "to_rtf" => lambda do |value, targ| case targ when :document "\\paperw#{value.width}\\paperh#{value.height}" when :section "\\pgwsxn#{value.width}\\pghsxn#{value.height}" end # case end }, "margin" => { "default" => RRTF::Page::Margin.new, "from_user" => lambda{ |value| RRTF::Page::Margin.new(value) }, "to_rtf" => lambda do |value, targ| case targ when :document "\\margl#{value.left}\\margr#{value.right}\\margt#{value.top}\\margb#{value.bottom}" when :section "\\marglsxn#{value.left}\\margrsnx#{value.right}\\margtsxn#{value.top}\\margbsnx#{value.bottom}" end # case end }, "gutter" => { "default" => nil, "from_user" => lambda{ |value| RRTF::Utilities.value2twips(value) }, "to_rtf" => lambda do |value, targ| case targ when :document "\\gutter#{value}" unless value.nil? when :section "\\guttersxn#{value}" unless value.nil? end # case end } }.freeze
- PAGE_FORMATTING_TARGET_DICTIONARY =
{ "DOCUMENT" => :document, "SECTION" => :section }.freeze
Instance Attribute Summary collapse
Class Method Summary collapse
-
.included(base) ⇒ Object
Generates attribute accessors for all page attributes when the module is included in another module or class.
Instance Method Summary collapse
-
#initialize_page_formatting(options = {}, target = "DOCUMENT") ⇒ Object
Initializes page formatting attributes.
-
#page_formatting_to_rtf ⇒ String
Generates an RTF string representing all applied page formatting.
-
#set_page_formatting_from_hashmap(hash) ⇒ Object
Sets document formatting attributes according to the supplied hashmap.
Instance Attribute Details
#target ⇒ Object
1055 1056 1057 |
# File 'lib/rrtf/formatting.rb', line 1055 def target @target end |
Class Method Details
.included(base) ⇒ Object
Generates attribute accessors for all page attributes when the module is included in another module or class.
1059 1060 1061 1062 1063 1064 1065 1066 |
# File 'lib/rrtf/formatting.rb', line 1059 def self.included(base) # define accessors in base for document attributes base.class_eval do PAGE_ATTRIBUTES.each do |key, | attr_accessor :#{key}" end # each end # class_eval end |
Instance Method Details
#initialize_page_formatting(options = {}, target = "DOCUMENT") ⇒ Object
The behavior of the “gutter” option changes with the document “facing_pages” setting.
Initializes page formatting attributes.
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 |
# File 'lib/rrtf/formatting.rb', line 1077 def initialize_page_formatting( = {}, target = "DOCUMENT") @target = PAGE_FORMATTING_TARGET_DICTIONARY[target] # load default attribute values PAGE_ATTRIBUTES.each do |key, | send("#{key}=", ["default"]) end # each # overwrite default attribute values with given values set_page_formatting_from_hashmap() end |
#page_formatting_to_rtf ⇒ String
Generates an RTF string representing all applied page formatting.
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 |
# File 'lib/rrtf/formatting.rb', line 1108 def page_formatting_to_rtf text = StringIO.new # accumulate RTF representations of page attributes PAGE_ATTRIBUTES.each do |key, | if .has_key?("to_rtf") rtf = ["to_rtf"].call(send(key), @target) text << rtf unless rtf.nil? end # if end # each text.string end |
#set_page_formatting_from_hashmap(hash) ⇒ Object
Sets document formatting attributes according to the supplied hashmap.
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 |
# File 'lib/rrtf/formatting.rb', line 1090 def set_page_formatting_from_hashmap(hash) hash.each do |attribute, value| # skip unreconized attributes next unless(PAGE_ATTRIBUTES.keys.include?(attribute)) # preprocess value if nessesary if PAGE_ATTRIBUTES[attribute].has_key?("from_user") value = PAGE_ATTRIBUTES[attribute]["from_user"].call(value) elsif PAGE_ATTRIBUTES[attribute].has_key?("dictionary") && value.is_a?(String) value = PAGE_ATTRIBUTES[attribute]["dictionary"][value] end # if # set attribute value send("#{attribute}=", value) end # each end |