rrtf 0.1.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/.byebug_history +6 -3
  3. data/CHANGELOG.md +24 -0
  4. data/README.md +194 -84
  5. data/documentation/RRTF.html +5 -5
  6. data/documentation/RRTF/AnonymousStyle.html +792 -0
  7. data/documentation/RRTF/BorderFormatting.html +821 -0
  8. data/documentation/RRTF/BorderStyle.html +493 -0
  9. data/documentation/RRTF/CharacterFormatting.html +293 -162
  10. data/documentation/RRTF/CharacterStyle.html +53 -109
  11. data/documentation/RRTF/Colour.html +61 -1
  12. data/documentation/RRTF/ColourTable.html +52 -52
  13. data/documentation/RRTF/CommandNode.html +367 -971
  14. data/documentation/RRTF/ContainerNode.html +44 -44
  15. data/documentation/RRTF/Converters.html +1 -1
  16. data/documentation/RRTF/Converters/HTML.html +1 -1
  17. data/documentation/RRTF/Converters/HTML/Helpers.html +1 -1
  18. data/documentation/RRTF/Converters/HTML/Node.html +1 -1
  19. data/documentation/RRTF/Converters/HTML/NodeSet.html +1 -1
  20. data/documentation/RRTF/Document.html +267 -255
  21. data/documentation/RRTF/DocumentFormatting.html +833 -0
  22. data/documentation/RRTF/DocumentProperties.html +444 -0
  23. data/documentation/RRTF/Font.html +1 -1
  24. data/documentation/RRTF/FontTable.html +1 -1
  25. data/documentation/RRTF/FooterNode.html +16 -16
  26. data/documentation/RRTF/GeometryNode.html +774 -0
  27. data/documentation/RRTF/GeometryProperties.html +1014 -0
  28. data/documentation/RRTF/HeaderNode.html +16 -16
  29. data/documentation/RRTF/ImageNode.html +705 -492
  30. data/documentation/RRTF/Information.html +1 -1
  31. data/documentation/RRTF/LinkNode.html +10 -10
  32. data/documentation/RRTF/ListLevel.html +1 -1
  33. data/documentation/RRTF/ListLevelNode.html +37 -37
  34. data/documentation/RRTF/ListMarker.html +1 -1
  35. data/documentation/RRTF/ListNode.html +19 -19
  36. data/documentation/RRTF/ListTable.html +1 -1
  37. data/documentation/RRTF/ListTemplate.html +1 -1
  38. data/documentation/RRTF/ListTextNode.html +14 -14
  39. data/documentation/RRTF/Node.html +26 -26
  40. data/documentation/RRTF/Page.html +129 -0
  41. data/documentation/RRTF/Page/Margin.html +1158 -0
  42. data/documentation/RRTF/Page/Size.html +946 -0
  43. data/documentation/RRTF/PageFormatting.html +954 -0
  44. data/documentation/RRTF/ParagraphFormatting.html +338 -56
  45. data/documentation/RRTF/ParagraphNode.html +10 -10
  46. data/documentation/RRTF/ParagraphStyle.html +72 -111
  47. data/documentation/RRTF/PositionFormatting.html +780 -0
  48. data/documentation/RRTF/PositionStyle.html +424 -0
  49. data/documentation/RRTF/Properties.html +243 -0
  50. data/documentation/RRTF/RTFError.html +21 -10
  51. data/documentation/RRTF/ShadingFormatting.html +712 -0
  52. data/documentation/RRTF/ShadingStyle.html +424 -0
  53. data/documentation/RRTF/Style.html +284 -697
  54. data/documentation/RRTF/Stylesheet.html +36 -3
  55. data/documentation/RRTF/TableCellNode.html +131 -131
  56. data/documentation/RRTF/TableNode.html +82 -82
  57. data/documentation/RRTF/TableRowNode.html +53 -53
  58. data/documentation/RRTF/TextNode.html +46 -46
  59. data/documentation/RRTF/Utilities.html +837 -17
  60. data/documentation/_index.html +139 -6
  61. data/documentation/class_list.html +1 -1
  62. data/documentation/file.README.html +218 -87
  63. data/documentation/index.html +218 -87
  64. data/documentation/method_list.html +631 -391
  65. data/documentation/top-level-namespace.html +1 -1
  66. data/examples/01.rtf +947 -20
  67. data/examples/01_everything.rb +176 -0
  68. data/examples/02.rtf +13 -0
  69. data/examples/02_basic_paragraph.rb +10 -0
  70. data/examples/03.rtf +20 -0
  71. data/examples/03_paragraph_inline_style.rb +14 -0
  72. data/examples/04.rtf +21 -0
  73. data/examples/04_paragraph_with_character_style.rb +18 -0
  74. data/examples/05.rtf +21 -0
  75. data/examples/05_hyperlinks.rb +21 -0
  76. data/examples/06.rtf +21 -0
  77. data/examples/06_basic_list.rb +21 -0
  78. data/examples/07.rtf +28 -0
  79. data/examples/07_nested_list.rb +27 -0
  80. data/examples/08.rtf +807 -0
  81. data/examples/08_images.rb +17 -0
  82. data/examples/09.rtf +84 -0
  83. data/examples/09_shapes.rb +56 -0
  84. data/examples/10.rtf +34 -0
  85. data/examples/10_stylesheet.rb +18 -0
  86. data/examples/resources/images/redshirt.png +0 -0
  87. data/examples/resources/images/redshirts.jpg +0 -0
  88. data/examples/resources/json/redshirt_styles.json +72 -8
  89. data/examples/~$01.rtf +0 -0
  90. data/lib/rrtf.rb +4 -16
  91. data/lib/rrtf/colour.rb +8 -0
  92. data/lib/rrtf/formatting.rb +988 -0
  93. data/lib/rrtf/node.rb +17 -1851
  94. data/lib/rrtf/node/command_node.rb +242 -0
  95. data/lib/rrtf/node/container_node.rb +75 -0
  96. data/lib/rrtf/node/document.rb +339 -0
  97. data/lib/rrtf/node/footer_node.rb +47 -0
  98. data/lib/rrtf/node/geometry_node.rb +65 -0
  99. data/lib/rrtf/node/header_node.rb +47 -0
  100. data/lib/rrtf/node/image_node.rb +175 -0
  101. data/lib/rrtf/node/link_node.rb +10 -0
  102. data/lib/rrtf/node/list_level_node.rb +44 -0
  103. data/lib/rrtf/node/list_node.rb +30 -0
  104. data/lib/rrtf/node/list_text_node.rb +22 -0
  105. data/lib/rrtf/node/node.rb +53 -0
  106. data/lib/rrtf/node/paragraph_node.rb +11 -0
  107. data/lib/rrtf/node/table_cell_node.rb +233 -0
  108. data/lib/rrtf/node/table_node.rb +136 -0
  109. data/lib/rrtf/node/table_row_node.rb +92 -0
  110. data/lib/rrtf/node/text_node.rb +76 -0
  111. data/lib/rrtf/page.rb +7 -0
  112. data/lib/rrtf/page/margin.rb +98 -0
  113. data/lib/rrtf/page/size.rb +98 -0
  114. data/lib/rrtf/properties.rb +3 -0
  115. data/lib/rrtf/properties/document_properties.rb +34 -0
  116. data/lib/rrtf/properties/geometry_properties.rb +380 -0
  117. data/lib/rrtf/properties/properties.rb +13 -0
  118. data/lib/rrtf/style.rb +4 -5
  119. data/lib/rrtf/style/anonymous_style.rb +73 -0
  120. data/lib/rrtf/style/border_style.rb +27 -0
  121. data/lib/rrtf/style/character_style.rb +1 -7
  122. data/lib/rrtf/style/paragraph_style.rb +0 -6
  123. data/lib/rrtf/style/position_style.rb +26 -0
  124. data/lib/rrtf/style/shading_style.rb +26 -0
  125. data/lib/rrtf/style/style.rb +60 -101
  126. data/lib/rrtf/utilities.rb +138 -0
  127. data/lib/rrtf/version.rb +1 -1
  128. data/rrtf.gemspec +1 -0
  129. metadata +85 -10
  130. data/examples/01_mac_libreoffice5_2_3_3.png +0 -0
  131. data/examples/01_mac_pages6_2.png +0 -0
  132. data/examples/01_mac_textedit1_12.png +0 -0
  133. data/examples/01_mac_word15_36.png +0 -0
  134. data/examples/01_styles_and_paragraphs.rb +0 -32
  135. data/lib/rrtf/paper.rb +0 -53
  136. data/lib/rrtf/style/document_style.rb +0 -116
  137. data/lib/rrtf/style/formatting.rb +0 -320
@@ -1,3 +1,3 @@
1
1
  module RRTF
2
- VERSION = "0.1.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  # Required for HTML converter functionality
29
29
  spec.add_dependency "nokogiri"
30
30
  spec.add_dependency "tidy"
31
+ spec.add_dependency "fastimage"
31
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rrtf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wesley Hileman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-24 00:00:00.000000000 Z
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: fastimage
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description:
112
126
  email:
113
127
  - whileman133@gmail.com
@@ -119,6 +133,7 @@ files:
119
133
  - ".gitignore"
120
134
  - ".rspec"
121
135
  - ".travis.yml"
136
+ - CHANGELOG.md
122
137
  - Gemfile
123
138
  - LICENSE.txt
124
139
  - README.md
@@ -126,6 +141,9 @@ files:
126
141
  - bin/console
127
142
  - bin/setup
128
143
  - documentation/RRTF.html
144
+ - documentation/RRTF/AnonymousStyle.html
145
+ - documentation/RRTF/BorderFormatting.html
146
+ - documentation/RRTF/BorderStyle.html
129
147
  - documentation/RRTF/CharacterFormatting.html
130
148
  - documentation/RRTF/CharacterStyle.html
131
149
  - documentation/RRTF/Colour.html
@@ -138,10 +156,14 @@ files:
138
156
  - documentation/RRTF/Converters/HTML/Node.html
139
157
  - documentation/RRTF/Converters/HTML/NodeSet.html
140
158
  - documentation/RRTF/Document.html
159
+ - documentation/RRTF/DocumentFormatting.html
160
+ - documentation/RRTF/DocumentProperties.html
141
161
  - documentation/RRTF/DocumentStyle.html
142
162
  - documentation/RRTF/Font.html
143
163
  - documentation/RRTF/FontTable.html
144
164
  - documentation/RRTF/FooterNode.html
165
+ - documentation/RRTF/GeometryNode.html
166
+ - documentation/RRTF/GeometryProperties.html
145
167
  - documentation/RRTF/HeaderNode.html
146
168
  - documentation/RRTF/ImageNode.html
147
169
  - documentation/RRTF/Information.html
@@ -154,11 +176,20 @@ files:
154
176
  - documentation/RRTF/ListTemplate.html
155
177
  - documentation/RRTF/ListTextNode.html
156
178
  - documentation/RRTF/Node.html
179
+ - documentation/RRTF/Page.html
180
+ - documentation/RRTF/Page/Margin.html
181
+ - documentation/RRTF/Page/Size.html
182
+ - documentation/RRTF/PageFormatting.html
157
183
  - documentation/RRTF/Paper.html
158
184
  - documentation/RRTF/ParagraphFormatting.html
159
185
  - documentation/RRTF/ParagraphNode.html
160
186
  - documentation/RRTF/ParagraphStyle.html
187
+ - documentation/RRTF/PositionFormatting.html
188
+ - documentation/RRTF/PositionStyle.html
189
+ - documentation/RRTF/Properties.html
161
190
  - documentation/RRTF/RTFError.html
191
+ - documentation/RRTF/ShadingFormatting.html
192
+ - documentation/RRTF/ShadingStyle.html
162
193
  - documentation/RRTF/Style.html
163
194
  - documentation/RRTF/Stylesheet.html
164
195
  - documentation/RRTF/TableCellNode.html
@@ -181,28 +212,72 @@ files:
181
212
  - documentation/method_list.html
182
213
  - documentation/top-level-namespace.html
183
214
  - examples/01.rtf
184
- - examples/01_mac_libreoffice5_2_3_3.png
185
- - examples/01_mac_pages6_2.png
186
- - examples/01_mac_textedit1_12.png
187
- - examples/01_mac_word15_36.png
188
- - examples/01_styles_and_paragraphs.rb
215
+ - examples/01_everything.rb
216
+ - examples/02.rtf
217
+ - examples/02_basic_paragraph.rb
218
+ - examples/03.rtf
219
+ - examples/03_paragraph_inline_style.rb
220
+ - examples/04.rtf
221
+ - examples/04_paragraph_with_character_style.rb
222
+ - examples/05.rtf
223
+ - examples/05_hyperlinks.rb
224
+ - examples/06.rtf
225
+ - examples/06_basic_list.rb
226
+ - examples/07.rtf
227
+ - examples/07_nested_list.rb
228
+ - examples/08.rtf
229
+ - examples/08_images.rb
230
+ - examples/09.rtf
231
+ - examples/09_shapes.rb
232
+ - examples/10.rtf
233
+ - examples/10_stylesheet.rb
234
+ - examples/resources/images/redshirt.png
235
+ - examples/resources/images/redshirts.jpg
189
236
  - examples/resources/json/redshirt_styles.json
237
+ - examples/~$01.rtf
190
238
  - lib/rrtf.rb
191
239
  - lib/rrtf/colour.rb
192
240
  - lib/rrtf/converters.rb
193
241
  - lib/rrtf/converters/html.rb
194
242
  - lib/rrtf/font.rb
243
+ - lib/rrtf/formatting.rb
195
244
  - lib/rrtf/information.rb
196
245
  - lib/rrtf/list.rb
197
246
  - lib/rrtf/node.rb
198
- - lib/rrtf/paper.rb
247
+ - lib/rrtf/node/command_node.rb
248
+ - lib/rrtf/node/container_node.rb
249
+ - lib/rrtf/node/document.rb
250
+ - lib/rrtf/node/footer_node.rb
251
+ - lib/rrtf/node/geometry_node.rb
252
+ - lib/rrtf/node/header_node.rb
253
+ - lib/rrtf/node/image_node.rb
254
+ - lib/rrtf/node/link_node.rb
255
+ - lib/rrtf/node/list_level_node.rb
256
+ - lib/rrtf/node/list_node.rb
257
+ - lib/rrtf/node/list_text_node.rb
258
+ - lib/rrtf/node/node.rb
259
+ - lib/rrtf/node/paragraph_node.rb
260
+ - lib/rrtf/node/table_cell_node.rb
261
+ - lib/rrtf/node/table_node.rb
262
+ - lib/rrtf/node/table_row_node.rb
263
+ - lib/rrtf/node/text_node.rb
264
+ - lib/rrtf/page.rb
265
+ - lib/rrtf/page/margin.rb
266
+ - lib/rrtf/page/size.rb
267
+ - lib/rrtf/properties.rb
268
+ - lib/rrtf/properties/document_properties.rb
269
+ - lib/rrtf/properties/geometry_properties.rb
270
+ - lib/rrtf/properties/properties.rb
199
271
  - lib/rrtf/style.rb
272
+ - lib/rrtf/style/anonymous_style.rb
273
+ - lib/rrtf/style/border_style.rb
200
274
  - lib/rrtf/style/character_style.rb
201
- - lib/rrtf/style/document_style.rb
202
- - lib/rrtf/style/formatting.rb
203
275
  - lib/rrtf/style/paragraph_style.rb
276
+ - lib/rrtf/style/position_style.rb
277
+ - lib/rrtf/style/shading_style.rb
204
278
  - lib/rrtf/style/style.rb
205
279
  - lib/rrtf/stylesheet.rb
280
+ - lib/rrtf/utilities.rb
206
281
  - lib/rrtf/version.rb
207
282
  - rrtf.gemspec
208
283
  homepage: https://github.com/whileman133/rrtf
Binary file
@@ -1,32 +0,0 @@
1
- require 'rrtf'
2
- require 'JSON'
3
-
4
- DIR = File.dirname(__FILE__)
5
-
6
- raw_styles = JSON.parse File.read(DIR+'/resources/json/redshirt_styles.json')
7
-
8
- rtf = RRTF::Document.new("stylesheet" => raw_styles)
9
- styles = rtf.stylesheet.styles
10
-
11
- rtf.paragraph(styles['TITLE']) << "RedShirts 101"
12
- rtf.paragraph(styles['BODY']) do |p|
13
- p << "Should you ever find yourself on a spacefaring vessel wearing a"
14
- p.apply(styles['EMPH']) << " red "
15
- p << "shirt, take heed and be on guard, for danger is immanent and you are "
16
- p << "likely expendable among the crew..."
17
- end
18
- rtf.paragraph(styles['H1']) << "1. The Danger of Away Missions"
19
- rtf.paragraph(styles['BODY']) do |p|
20
- p << "If you're ever assigned an away mission, it's almost certain to be your doom. "
21
- p << "The optimal strategy is to avoid away missions to begin with..."
22
- end
23
- rtf.paragraph(styles['H1']) << "2. Avoiding High-Ranking Officers"
24
- rtf.paragraph(styles['BODY']) do |p|
25
- p << "You're likely to notice an influx of unfortunate outcomes around "
26
- p << "certain high-ranking officers. Its to your advantage to quickly identify and "
27
- p << "avoid these officers..."
28
- end
29
-
30
- File.open(DIR+'/01.rtf', 'w') do |file|
31
- file.write(rtf.to_rtf)
32
- end
@@ -1,53 +0,0 @@
1
- module RRTF
2
- # This class represents a definition for a paper size and provides a set
3
- # of class constants for common paper sizes. An instance of the Paper class
4
- # is considered immutable after creation.
5
- class Paper
6
- # Attribute accessor.
7
- attr_reader :name, :width, :height
8
-
9
-
10
- # This is the constructor for the Paper class. All dimension parameters
11
- # to this method are in twips.
12
- #
13
- # ==== Parameters
14
- # name:: The name for the paper object.
15
- # width:: The width of the paper in portrait mode.
16
- # height:: The height of the paper in portrait mode.
17
- def initialize(name, width, height)
18
- @name = name
19
- @width = width
20
- @height = height
21
- end
22
-
23
- # Definition of an international paper constant.
24
- A0 = Paper.new('A0', 47685, 67416)
25
-
26
- # Definition of an international paper constant.
27
- A1 = Paper.new('A1', 33680, 47685)
28
-
29
- # Definition of an international paper constant.
30
- A2 = Paper.new('A2', 23814, 33680)
31
-
32
- # Definition of an international paper constant.
33
- A3 = Paper.new('A3', 16840, 23814)
34
-
35
- # Definition of an international paper constant.
36
- A4 = Paper.new('A4', 11907, 16840)
37
-
38
- # Definition of an international paper constant.
39
- A5 = Paper.new('A5', 8392, 11907)
40
-
41
- # Definition of a US paper constant.
42
- LETTER = Paper.new('Letter', 12247, 15819)
43
-
44
- # Definition of a US paper constant.
45
- LEGAL = Paper.new('Legal', 12247, 20185)
46
-
47
- # Definition of a US paper constant.
48
- EXECUTIVE = Paper.new('Executive', 10773, 14402)
49
-
50
- # Definition of a US paper constant.
51
- LEDGER_TABLOID = Paper.new('Ledger/Tabloid', 15819, 24494)
52
- end # End of the Paper class.
53
- end # End of the RTF module.
@@ -1,116 +0,0 @@
1
- module RRTF
2
- # This class represents styling attributes that are to be applied at the
3
- # document level.
4
- class DocumentStyle < Style
5
- # Definition for a document orientation setting.
6
- PORTRAIT = :portrait
7
-
8
- # Definition for a document orientation setting.
9
- LANDSCAPE = :landscape
10
-
11
- # Definition for a default margin setting.
12
- DEFAULT_LEFT_MARGIN = 1800
13
-
14
- # Definition for a default margin setting.
15
- DEFAULT_RIGHT_MARGIN = 1800
16
-
17
- # Definition for a default margin setting.
18
- DEFAULT_TOP_MARGIN = 1440
19
-
20
- # Definition for a default margin setting.
21
- DEFAULT_BOTTOM_MARGIN = 1440
22
-
23
- # stylesheet sorting codes
24
- STYLESHEET_SORT_NAME = 0 # stylesheet styles sorted by name
25
- STYLESHEET_SORT_DEFAULT = 1 # stylesheet styles sorted by system default
26
- STYLESHEET_SORT_FONT = 2 # stylesheet styles sorted by font
27
- STYLESHEET_SORT_BASEDON = 3 # stylesheet styles sorted by based-on fonts
28
- STYLESHEET_SORT_TYPE = 4 # stylesheet styles sorted by type
29
-
30
- # Attribute accessor.
31
- attr_reader :paper, :left_margin, :right_margin, :top_margin,
32
- :bottom_margin, :gutter, :orientation, :stylesheet_sort
33
-
34
- # Attribute mutator.
35
- attr_writer :paper, :left_margin, :right_margin, :top_margin,
36
- :bottom_margin, :gutter, :orientation, :stylesheet_sort
37
-
38
- # This is a constructor for the DocumentStyle class. This creates a
39
- # document style with a default paper setting of LETTER and portrait
40
- # orientation (all other attributes are nil).
41
- def initialize(options = {})
42
- # load default options
43
- options = {
44
- "paper_size" => Paper::LETTER,
45
- "left_margin" => DEFAULT_LEFT_MARGIN,
46
- "right_margin" => DEFAULT_RIGHT_MARGIN,
47
- "top_margin" => DEFAULT_TOP_MARGIN,
48
- "bottom_margin" => DEFAULT_BOTTOM_MARGIN,
49
- "gutter" => nil,
50
- "orientation" => PORTRAIT,
51
- "stylesheet_sort" => STYLESHEET_SORT_DEFAULT
52
- }.merge(options)
53
-
54
- @paper = options.delete("paper_size")
55
- @left_margin = options.delete("left_margin")
56
- @right_margin = options.delete("right_margin")
57
- @top_margin = options.delete("top_margin")
58
- @bottom_margin = options.delete("bottom_margin")
59
- @gutter = options.delete("gutter")
60
- @orientation = options.delete("orientation")
61
- @stylesheet_sort = options.delete("stylesheet_sort")
62
- end
63
-
64
- # This method overrides the is_document_style? method inherited from the
65
- # Style class to always return true.
66
- def is_document_style?
67
- true
68
- end
69
-
70
- # This method generates a string containing the prefix associated with a
71
- # style object.
72
- #
73
- # ==== Parameters
74
- # document:: A reference to the document using the style.
75
- def prefix(fonts=nil, colours=nil)
76
- text = StringIO.new
77
-
78
- text << "\\stylesortmethod#{@stylesheet_sort}" unless @stylesheet_sort.nil?
79
- if orientation == LANDSCAPE
80
- text << "\\paperw#{@paper.height}" unless @paper.nil?
81
- text << "\\paperh#{@paper.width}" unless @paper.nil?
82
- else
83
- text << "\\paperw#{@paper.width}" unless @paper.nil?
84
- text << "\\paperh#{@paper.height}" unless @paper.nil?
85
- end
86
- text << "\\margl#{@left_margin}" unless @left_margin.nil?
87
- text << "\\margr#{@right_margin}" unless @right_margin.nil?
88
- text << "\\margt#{@top_margin}" unless @top_margin.nil?
89
- text << "\\margb#{@bottom_margin}" unless @bottom_margin.nil?
90
- text << "\\gutter#{@gutter}" unless @gutter.nil?
91
- text << '\sectd\lndscpsxn' if @orientation == LANDSCAPE
92
-
93
- text.string
94
- end
95
-
96
- # This method fetches the width of the available work area space for a
97
- # DocumentStyle object.
98
- def body_width
99
- if orientation == PORTRAIT
100
- @paper.width - (@left_margin + @right_margin)
101
- else
102
- @paper.height - (@left_margin + @right_margin)
103
- end
104
- end
105
-
106
- # This method fetches the height of the available work area space for a
107
- # DocumentStyle object.
108
- def body_height
109
- if orientation == PORTRAIT
110
- @paper.height - (@top_margin + @bottom_margin)
111
- else
112
- @paper.width - (@top_margin + @bottom_margin)
113
- end
114
- end
115
- end # End of the DocumentStyle class.
116
- end # module RRTF
@@ -1,320 +0,0 @@
1
- require 'stringio'
2
-
3
- # Encapsulates all character formatting methods shared between style types.
4
- # @author Wesley Hileman
5
- module RRTF::CharacterFormatting
6
- CHARACTER_ATTRIBUTES = {
7
- # toggable attributes
8
- "bold" => {
9
- "default" => nil,
10
- "to_rtf" => lambda{ |value, document| (value ? '\b' : '\b0') unless value.nil? }
11
- },
12
- "italic" => {
13
- "default" => nil,
14
- "to_rtf" => lambda{ |value, document| (value ? '\i' : '\i0') unless value.nil? }
15
- },
16
- "underline" => {
17
- "default" => nil,
18
- "dictionary" => {
19
- "SINGLE" => "",
20
- "DOUBLE" => "db",
21
- "THICK" => "th",
22
- "DASH" => "dash",
23
- "LONG_DASH" => "ldash",
24
- "DOT" => "d",
25
- "DASH_DOT" => "dashd",
26
- "DASH_DOT_DOT" => "dashdd",
27
- "WAVE" => 'wave',
28
- "THICK_DASH" => "thdash",
29
- "THICK_LONG_DASH" => "thldash",
30
- "THICK_DOT" => "thd",
31
- "THICK_DASH_DOT" => "thdashd",
32
- "THICK_DASH_DOT_DOT" => "thdashdd",
33
- "THICK_WAVE" => 'hwave',
34
- "DOUBLE_WAVE" => 'uldbwave'
35
- },
36
- "to_rtf" => lambda do |value, document|
37
- return if value.nil?
38
- case value
39
- when TrueClass
40
- '\ul'
41
- when FalseClass
42
- '\ulnone'
43
- when String
44
- "\\ul#{value}"
45
- end # case
46
- end
47
- },
48
- "uppercase" => {
49
- "default" => nil,
50
- "to_rtf" => lambda{ |value, document| (value ? '\caps' : '\caps0') unless value.nil? }
51
- },
52
- "superscript" => {
53
- "default" => nil,
54
- "to_rtf" => lambda{ |value, document| (value ? '\super' : '\super0') unless value.nil? }
55
- },
56
- "subscript" => {
57
- "default" => nil,
58
- "to_rtf" => lambda{ |value, document| (value ? '\sub' : '\sub0') unless value.nil? }
59
- },
60
- "strike" => {
61
- "default" => nil,
62
- "to_rtf" => lambda{ |value, document| (value ? '\strike' : '\strike0') unless value.nil? }
63
- },
64
- "emboss" => {
65
- "default" => nil,
66
- "to_rtf" => lambda{ |value, document| (value ? '\embo' : '\embo0') unless value.nil? }
67
- },
68
- "imprint" => {
69
- "default" => nil,
70
- "to_rtf" => lambda{ |value, document| (value ? '\impr' : '\impr0') unless value.nil? }
71
- },
72
- "outline" => {
73
- "default" => nil,
74
- "to_rtf" => lambda{ |value, document| (value ? '\outl' : '\outl0') unless value.nil? }
75
- },
76
- "text_hidden" => {
77
- "default" => nil,
78
- "to_rtf" => lambda{ |value, document| (value ? '\v' : '\v0') unless value.nil? }
79
- },
80
- "kerning" => {
81
- "default" => nil,
82
- "to_rtf" => lambda{ |value, document| (value.is_a?(Integer) ? "\\kerning#{value}" : '\kerning0') unless value.nil? }
83
- },
84
- # non-toggable attributes
85
- "character_spacing_offset" => {
86
- "default" => nil,
87
- "to_rtf" => lambda{ |value, document| "\\expnd#{value}" unless value.nil? }
88
- },
89
- "foreground_color" => {
90
- "default" => nil,
91
- "from_user" => lambda{ |value| value.is_a?(RRTF::Colour) ? value : RRTF::Colour.from_string(value) },
92
- "to_rtf" => lambda{ |value, document| "\\cf#{document.colours.index(value)}" unless value.nil? }
93
- },
94
- "background_color" => {
95
- "default" => nil,
96
- "from_user" => lambda{ |value| value.is_a?(RRTF::Colour) ? value : RRTF::Colour.from_string(value) },
97
- "to_rtf" => lambda{ |value, document| "\\cb#{document.colours.index(value)}" unless value.nil? }
98
- },
99
- "underline_color" => {
100
- "default" => nil,
101
- "from_user" => lambda{ |value| value.is_a?(RRTF::Colour) ? value : RRTF::Colour.from_string(value) },
102
- "to_rtf" => lambda{ |value, document| "\\ulc#{document.colours.index(value)}" unless value.nil? }
103
- },
104
- "font" => {
105
- "default" => nil,
106
- "from_user" => lambda{ |value| value.is_a?(RRTF::Font) ? value : RRTF::Font.from_string(value) },
107
- "to_rtf" => lambda{ |value, document| "\\f#{document.fonts.index(value)}" unless value.nil? }
108
- },
109
- "font_size" => {
110
- "default" => nil,
111
- "to_rtf" => lambda{ |value, document| "\\fs#{value}" unless value.nil? }
112
- }
113
- }.freeze
114
-
115
- def self.included(base)
116
- # define accessors in base for paragraph attributes
117
- base.class_eval do
118
- CHARACTER_ATTRIBUTES.each do |key, options|
119
- attr_accessor :"#{key}"
120
- end # each
121
- end # class_eval
122
- end
123
-
124
- # Initializes character formatting attributes.
125
- #
126
- # @param [Hash] options the character formatting options.
127
- # @option options [Boolean] "bold" (nil) enable or disable bold (nil to remain same).
128
- # @option options [Boolean] "italic" (nil) enable or disable italic (nil to remain same).
129
- # @option options [Boolean, String] "underline" (nil) enable or disable underline (nil to remain same); can also be a string (see {CharacterFormatting::CHARACTER_ATTRIBUTES}).
130
- # @option options [Boolean] "uppercase" (nil) enable or disable all caps (nil to remain same).
131
- # @option options [Boolean] "superscript" (nil) enable or disable superscript (nil to remain same).
132
- # @option options [Boolean] "subscript" (nil) enable or disable subscript (nil to remain same).
133
- # @option options [Boolean] "strike" (nil) enable or disable single line-through (nil to remain same).
134
- # @option options [Boolean] "emboss" (nil) enable or disable emboss (nil to remain same).
135
- # @option options [Boolean] "imprint" (nil) enable or disable imprint (nil to remain same).
136
- # @option options [Boolean] "outline" (nil) enable or disable outline (nil to remain same).
137
- # @option options [Boolean] "text_hidden" (nil) enable or disable hidden (nil to remain same).
138
- # @option options [Boolean, Integer] "kerning" (nil) enable or disable kerning (nil to remain same); to enable specify the font size in half-points above which kerining will be applied.
139
- # @option options [Integer] "character_spacing_offset" (nil) quarter points by which to expand or compress character spacing (negative for compress).
140
- # @option options [String, Colour] "foreground_color" (nil) colour to apply to the foreground (text); see {Colour.from_string} for string format.
141
- # @option options [String, Colour] "background_color" (nil) colour to apply to the background (highlight); see {Colour.from_string} for string format.
142
- # @option options [String, Colour] "underline_color" (nil) colour to apply to the underline; see {Colour.from_string} for string format.
143
- # @option options [String, Font] "font" (nil) font to apply to text; see {Font.from_string} for string format.
144
- # @option options [Integer] "font_size" (nil) font size in half-points.
145
- def initialize_character_formatting(options = {})
146
- # load default attribute values
147
- CHARACTER_ATTRIBUTES.each do |key, options|
148
- send("#{key}=", options["default"])
149
- end # each
150
- # overwrite default attribute values with given values
151
- set_character_formatting_from_hashmap(options)
152
- end
153
-
154
- def set_character_formatting_from_hashmap(hash)
155
- hash.each do |attribute, value|
156
- # skip unreconized attributes
157
- next unless(CHARACTER_ATTRIBUTES.keys.include?(attribute))
158
- # preprocess value if nessesary
159
- if CHARACTER_ATTRIBUTES[attribute].has_key?("from_user")
160
- value = CHARACTER_ATTRIBUTES[attribute]["from_user"].call(value)
161
- elsif CHARACTER_ATTRIBUTES[attribute].has_key?("dictionary") && value.is_a?(String)
162
- value = CHARACTER_ATTRIBUTES[attribute]["dictionary"][value]
163
- end # if
164
- # set attribute value
165
- send("#{attribute}=", value)
166
- end # each
167
- end
168
-
169
- def push_colours(colours)
170
- colours << foreground_color unless foreground_color.nil?
171
- colours << background_color unless background_color.nil?
172
- colours << underline_color unless underline_color.nil?
173
- end
174
-
175
- def push_fonts(fonts)
176
- fonts << font unless font.nil?
177
- end
178
-
179
- def character_formatting_to_rtf(document)
180
- text = StringIO.new
181
-
182
- # accumulate RTF representations of attributes
183
- CHARACTER_ATTRIBUTES.each do |key, options|
184
- if options.has_key?("to_rtf")
185
- rtf = options["to_rtf"].call(send(key), document)
186
- text << rtf unless rtf.nil?
187
- end # if
188
- end # each
189
-
190
- text.string
191
- end
192
- end # module CharacterFormatting
193
-
194
- # Encapsulates all paragraph formatting methods shared between style types.
195
- # @author Wesley Hileman
196
- module RRTF::ParagraphFormatting
197
- PARAGRAPH_ATTRIBUTES = {
198
- "justification" => {
199
- "default" => "l",
200
- "dictionary" => {
201
- "LEFT" => "l",
202
- "RIGHT" => "r",
203
- "CENTER" => "c",
204
- "CENTRE" => "c",
205
- "FULL" => "j"
206
- },
207
- "to_rtf" => lambda{ |value, document| "\\q#{value}" }
208
- },
209
- "left_indent" => {
210
- "default" => nil,
211
- "to_rtf" => lambda{ |value, document| "\\li#{value}" unless value.nil? }
212
- },
213
- "right_indent" => {
214
- "default" => nil,
215
- "to_rtf" => lambda{ |value, document| "\\ri#{value}" unless value.nil? }
216
- },
217
- "first_line_indent" => {
218
- "default" => nil,
219
- "to_rtf" => lambda{ |value, document| "\\fi#{value}" unless value.nil? }
220
- },
221
- "space_before" => {
222
- "default" => nil,
223
- "to_rtf" => lambda{ |value, document| "\\sb#{value}" unless value.nil? }
224
- },
225
- "space_after" => {
226
- "default" => nil,
227
- "to_rtf" => lambda{ |value, document| "\\sa#{value}" unless value.nil? }
228
- },
229
- "line_spacing" => {
230
- "default" => nil,
231
- "to_rtf" => lambda{ |value, document| "\\sl#{value}" unless value.nil? }
232
- },
233
- "widow_orphan_ctl" => {
234
- "default" => nil,
235
- "to_rtf" => lambda{ |value, document| (value ? "\\widctlpar" : "\\nowidctlpar") unless value.nil? }
236
- },
237
- "no_break" => {
238
- "default" => false,
239
- "to_rtf" => lambda{ |value, document| "\\keep" if value }
240
- },
241
- "no_break_with_next" => {
242
- "default" => false,
243
- "to_rtf" => lambda{ |value, document| "\\keepn" if value }
244
- },
245
- "hyphenate" => {
246
- "default" => nil,
247
- "to_rtf" => lambda{ |value, document| (value ? "\\hyphpar" : "\\hyphpar0") unless value.nil? }
248
- },
249
- "paragraph_flow" => {
250
- "default" => 'ltr',
251
- "dictionary" => {
252
- "LEFT_TO_RIGHT" => 'ltr',
253
- "RIGHT_TO_LEFT" => 'rtl'
254
- },
255
- "to_rtf" => lambda{ |value, document| "\\#{value}par" unless value.nil? }
256
- }
257
- }.freeze
258
-
259
- def self.included(base)
260
- # define accessors in base for paragraph attributes
261
- base.class_eval do
262
- PARAGRAPH_ATTRIBUTES.each do |key, options|
263
- attr_accessor :"#{key}"
264
- end # each
265
- end # class_eval
266
- end
267
-
268
- # Initializes paragraph formatting attributes.
269
- #
270
- # @param [Hash] options the paragraph formatting options.
271
- # @option options [String] "justification" ('LEFT') the paragraph justification ('LEFT', 'CENTER'/'CENTRE', 'RIGHT', or 'FULL').
272
- # @option options [Integer] "left_indent" (nil) the left indent of the paragraph (twentieth points).
273
- # @option options [Integer] "right_indent" (nil) the right indent of the paragraph (twentieth points).
274
- # @option options [Integer] "first_line_indent" (nil) the first line indent of the paragraph (twentieth points).
275
- # @option options [Integer] "space_before" (nil) the space before the paragraph (twentieth points).
276
- # @option options [Integer] "space_after" (nil) the space after the paragraph (twentieth points).
277
- # @option options [Integer] "line_spacing" (nil) the line spacing in the paragraph (twentieth points).
278
- # @option options [Boolean] "widow_orphan_ctl" (nil) enable or disable widow-and-orphan control.
279
- # @option options [Boolean] "no_break" (nil) when true, tries to keep the paragraph on the same page (i.e. without breaking).
280
- # @option options [Boolean] "no_break_with_next" (nil) when true, tries to keep the paragraph with the next paragraph on the same page (i.e. without breaking).
281
- # @option options [Boolean] "hyphenate" (nil) enable or disable hyphenation for the paragraph.
282
- # @option options [String] "paragraph_flow" ('LEFT_TO_RIGHT') the text flow direction in the paragraph ('LEFT_TO_RIGHT' or 'RIGHT_TO_LEFT').
283
- def initialize_paragraph_formatting(options = {})
284
- # load default attribute values
285
- PARAGRAPH_ATTRIBUTES.each do |key, options|
286
- send("#{key}=", options["default"])
287
- end # each
288
- # overwrite default attribute values with given values
289
- set_paragraph_formatting_from_hashmap(options)
290
- end
291
-
292
- def set_paragraph_formatting_from_hashmap(hash)
293
- hash.each do |attribute, value|
294
- # skip unreconized attributes
295
- next unless(PARAGRAPH_ATTRIBUTES.keys.include?(attribute))
296
- # preprocess value if nessesary
297
- if PARAGRAPH_ATTRIBUTES[attribute].has_key?("from_user")
298
- value = PARAGRAPH_ATTRIBUTES[attribute]["from_user"].call(value)
299
- elsif PARAGRAPH_ATTRIBUTES[attribute].has_key?("dictionary") && value.is_a?(String)
300
- value = PARAGRAPH_ATTRIBUTES[attribute]["dictionary"][value]
301
- end # if
302
- # set attribute value
303
- send("#{attribute}=", value)
304
- end # each
305
- end
306
-
307
- def paragraph_formatting_to_rtf(document)
308
- text = StringIO.new
309
-
310
- # accumulate RTF representations of paragraph attributes
311
- PARAGRAPH_ATTRIBUTES.each do |key, options|
312
- if options.has_key?("to_rtf")
313
- rtf = options["to_rtf"].call(send(key), document)
314
- text << rtf unless rtf.nil?
315
- end # if
316
- end # each
317
-
318
- text.string
319
- end
320
- end # module ParagraphFormatting