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
@@ -0,0 +1,53 @@
1
+ module RRTF
2
+ # This class represents an element within an RTF document. The class provides
3
+ # a base class for more specific node types.
4
+ class Node
5
+ # Node parent.
6
+ attr_accessor :parent
7
+
8
+ # Constructor for the Node class.
9
+ #
10
+ # ==== Parameters
11
+ # parent:: A reference to the Node that owns the new Node. May be nil
12
+ # to indicate a base or root node.
13
+ def initialize(parent)
14
+ @parent = parent
15
+ end
16
+
17
+ # This method retrieves a Node objects previous peer node, returning nil
18
+ # if the Node has no previous peer.
19
+ def previous_node
20
+ peer = nil
21
+ if !parent.nil? and parent.respond_to?(:children)
22
+ index = parent.children.index(self)
23
+ peer = index > 0 ? parent.children[index - 1] : nil
24
+ end
25
+ peer
26
+ end
27
+
28
+ # This method retrieves a Node objects next peer node, returning nil
29
+ # if the Node has no previous peer.
30
+ def next_node
31
+ peer = nil
32
+ if !parent.nil? and parent.respond_to?(:children)
33
+ index = parent.children.index(self)
34
+ peer = parent.children[index + 1]
35
+ end
36
+ peer
37
+ end
38
+
39
+ # This method is used to determine whether a Node object represents a
40
+ # root or base element. The method returns true if the Nodes parent is
41
+ # nil, false otherwise.
42
+ def is_root?
43
+ @parent.nil?
44
+ end
45
+
46
+ # This method traverses a Node tree to locate the root element.
47
+ def root
48
+ node = self
49
+ node = node.parent while !node.parent.nil?
50
+ node
51
+ end
52
+ end # End of the Node class.
53
+ end
@@ -0,0 +1,11 @@
1
+ module RRTF
2
+ # This class represents a paragraph within an RTF document.
3
+ class ParagraphNode < CommandNode
4
+ def initialize(parent, style=nil)
5
+ prefix = '\pard'
6
+ prefix << style.prefix(parent.root) if style
7
+
8
+ super(parent, prefix, '\par')
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,233 @@
1
+ module RRTF
2
+ # This class represents a cell within an RTF table. The TableCellNode is a
3
+ # specialised command node that is forbidden from creating tables or having
4
+ # its parent changed.
5
+ class TableCellNode < CommandNode
6
+ # A definition for the default width for the cell.
7
+ DEFAULT_WIDTH = 300
8
+ # Top border
9
+ TOP = 0
10
+ # Right border
11
+ RIGHT = 1
12
+ # Bottom border
13
+ BOTTOM = 2
14
+ # Left border
15
+ LEFT = 3
16
+ # Width of cell
17
+ attr_accessor :width
18
+ # Attribute accessor.
19
+ attr_reader :shading_colour, :style
20
+
21
+ # This is the constructor for the TableCellNode class.
22
+ #
23
+ # ==== Parameters
24
+ # row:: The row that the cell belongs to.
25
+ # width:: The width to be assigned to the cell. This defaults to
26
+ # TableCellNode::DEFAULT_WIDTH.
27
+ # style:: The style that is applied to the cell. This must be a
28
+ # ParagraphStyle class. Defaults to nil.
29
+ # top:: The border width for the cells top border. Defaults to nil.
30
+ # right:: The border width for the cells right hand border. Defaults to
31
+ # nil.
32
+ # bottom:: The border width for the cells bottom border. Defaults to nil.
33
+ # left:: The border width for the cells left hand border. Defaults to
34
+ # nil.
35
+ #
36
+ # ==== Exceptions
37
+ # RTFError:: Generated whenever an invalid style setting is specified.
38
+ def initialize(row, width=DEFAULT_WIDTH, style=nil, top=nil, right=nil,
39
+ bottom=nil, left=nil)
40
+ super(row, nil)
41
+ if !style.nil? and !style.is_paragraph_style?
42
+ RTFError.fire("Non-paragraph style specified for TableCellNode "\
43
+ "constructor.")
44
+ end
45
+
46
+ @width = (width != nil && width > 0) ? width : DEFAULT_WIDTH
47
+ @borders = [(top != nil && top > 0) ? top : nil,
48
+ (right != nil && right > 0) ? right : nil,
49
+ (bottom != nil && bottom > 0) ? bottom : nil,
50
+ (left != nil && left > 0) ? left : nil]
51
+ @shading_colour = nil
52
+ @style = style
53
+ end
54
+
55
+ # Attribute mutator.
56
+ #
57
+ # ==== Parameters
58
+ # style:: A reference to the style object to be applied to the cell.
59
+ # Must be an instance of the ParagraphStyle class. Set to nil
60
+ # to clear style settings.
61
+ #
62
+ # ==== Exceptions
63
+ # RTFError:: Generated whenever an invalid style setting is specified.
64
+ def style=(style)
65
+ if !style.nil? and !style.is_paragraph_style?
66
+ RTFError.fire("Non-paragraph style specified for TableCellNode "\
67
+ "constructor.")
68
+ end
69
+ @style = style
70
+ end
71
+
72
+ # This method assigns a width, in twips, for the borders on all sides of
73
+ # the cell. Negative widths will be ignored and a width of zero will
74
+ # switch the border off.
75
+ #
76
+ # ==== Parameters
77
+ # width:: The setting for the width of the border.
78
+ def border_width=(width)
79
+ size = width.nil? ? 0 : width
80
+ if size > 0
81
+ @borders[TOP] = @borders[RIGHT] = @borders[BOTTOM] = @borders[LEFT] = size.to_i
82
+ else
83
+ @borders = [nil, nil, nil, nil]
84
+ end
85
+ end
86
+
87
+ # This method assigns a border width to the top side of a table cell.
88
+ # Negative values are ignored and a value of 0 switches the border off.
89
+ #
90
+ # ==== Parameters
91
+ # width:: The new border width setting.
92
+ def top_border_width=(width)
93
+ size = width.nil? ? 0 : width
94
+ if size > 0
95
+ @borders[TOP] = size.to_i
96
+ else
97
+ @borders[TOP] = nil
98
+ end
99
+ end
100
+
101
+ # This method assigns a border width to the right side of a table cell.
102
+ # Negative values are ignored and a value of 0 switches the border off.
103
+ #
104
+ # ==== Parameters
105
+ # width:: The new border width setting.
106
+ def right_border_width=(width)
107
+ size = width.nil? ? 0 : width
108
+ if size > 0
109
+ @borders[RIGHT] = size.to_i
110
+ else
111
+ @borders[RIGHT] = nil
112
+ end
113
+ end
114
+
115
+ # This method assigns a border width to the bottom side of a table cell.
116
+ # Negative values are ignored and a value of 0 switches the border off.
117
+ #
118
+ # ==== Parameters
119
+ # width:: The new border width setting.
120
+ def bottom_border_width=(width)
121
+ size = width.nil? ? 0 : width
122
+ if size > 0
123
+ @borders[BOTTOM] = size.to_i
124
+ else
125
+ @borders[BOTTOM] = nil
126
+ end
127
+ end
128
+
129
+ # This method assigns a border width to the left side of a table cell.
130
+ # Negative values are ignored and a value of 0 switches the border off.
131
+ #
132
+ # ==== Parameters
133
+ # width:: The new border width setting.
134
+ def left_border_width=(width)
135
+ size = width.nil? ? 0 : width
136
+ if size > 0
137
+ @borders[LEFT] = size.to_i
138
+ else
139
+ @borders[LEFT] = nil
140
+ end
141
+ end
142
+
143
+ # This method alters the shading colour associated with a TableCellNode
144
+ # object.
145
+ #
146
+ # ==== Parameters
147
+ # colour:: A reference to the Colour object to use in shading the cell.
148
+ # Assign nil to clear cell shading.
149
+ def shading_colour=(colour)
150
+ root.colours << colour
151
+ @shading_colour = colour
152
+ end
153
+
154
+ # This method retrieves an array with the cell border width settings.
155
+ # The values are inserted in top, right, bottom, left order.
156
+ def border_widths
157
+ widths = []
158
+ @borders.each {|entry| widths.push(entry.nil? ? 0 : entry)}
159
+ widths
160
+ end
161
+
162
+ # This method fetches the width for top border of a cell.
163
+ def top_border_width
164
+ @borders[TOP].nil? ? 0 : @borders[TOP]
165
+ end
166
+
167
+ # This method fetches the width for right border of a cell.
168
+ def right_border_width
169
+ @borders[RIGHT].nil? ? 0 : @borders[RIGHT]
170
+ end
171
+
172
+ # This method fetches the width for bottom border of a cell.
173
+ def bottom_border_width
174
+ @borders[BOTTOM].nil? ? 0 : @borders[BOTTOM]
175
+ end
176
+
177
+ # This method fetches the width for left border of a cell.
178
+ def left_border_width
179
+ @borders[LEFT].nil? ? 0 : @borders[LEFT]
180
+ end
181
+
182
+ # This method overloads the paragraph method inherited from the
183
+ # ComamndNode class to forbid the creation of paragraphs.
184
+ #
185
+ # ==== Parameters
186
+ # style:: The paragraph style, ignored
187
+ def paragraph(style=nil)
188
+ RTFError.fire("TableCellNode#paragraph() called. Table cells cannot "\
189
+ "contain paragraphs.")
190
+ end
191
+
192
+ # This method overloads the parent= method inherited from the Node class
193
+ # to forbid the alteration of the cells parent.
194
+ #
195
+ # ==== Parameters
196
+ # parent:: A reference to the new node parent.
197
+ def parent=(parent)
198
+ RTFError.fire("Table cell nodes cannot have their parent changed.")
199
+ end
200
+
201
+ # This method overrides the table method inherited from CommandNode to
202
+ # forbid its use in table cells.
203
+ #
204
+ # ==== Parameters
205
+ # rows:: The number of rows for the table.
206
+ # columns:: The number of columns for the table.
207
+ # *widths:: One or more integers representing the widths for the table
208
+ # columns.
209
+ def table(rows, columns, *widths)
210
+ RTFError.fire("TableCellNode#table() called. Nested tables not allowed.")
211
+ end
212
+
213
+ # This method generates the RTF document text for a TableCellNode object.
214
+ def to_rtf
215
+ text = StringIO.new
216
+ separator = split? ? "\n" : " "
217
+ line = (separator == " ")
218
+
219
+ text << "\\pard\\intbl"
220
+ text << @style.prefix(root) if @style != nil
221
+ text << separator
222
+ self.each do |entry|
223
+ text << "\n" if line
224
+ line = true
225
+ text << entry.to_rtf
226
+ end
227
+ text << (split? ? "\n" : " ")
228
+ text << "\\cell"
229
+
230
+ text.string
231
+ end
232
+ end # End of the TableCellNode class.
233
+ end
@@ -0,0 +1,136 @@
1
+ module RRTF
2
+ # This class represents a table node within an RTF document. Table nodes are
3
+ # specialised container nodes that contain only TableRowNodes and have their
4
+ # size specified when they are created an cannot be resized after that.
5
+ class TableNode < ContainerNode
6
+ # Cell margin. Default to 100
7
+ attr_accessor :cell_margin
8
+
9
+ # This is a constructor for the TableNode class.
10
+ #
11
+ # ==== Parameters
12
+ # parent:: A reference to the node that owns the table.
13
+ # rows:: The number of rows in the table.
14
+ # columns:: The number of columns in the table.
15
+ # *widths:: One or more integers specifying the widths of the table
16
+ # columns.
17
+ def initialize(parent, *args, &block)
18
+ if args.size>=2
19
+ rows=args.shift
20
+ columns=args.shift
21
+ widths=args
22
+ super(parent) do
23
+ entries = []
24
+ rows.times {entries.push(TableRowNode.new(self, columns, *widths))}
25
+ entries
26
+ end
27
+
28
+ elsif block
29
+ block.arity<1 ? self.instance_eval(&block) : block.call(self)
30
+ else
31
+ raise "You should use 0 or >2 args"
32
+ end
33
+ @cell_margin = 100
34
+ end
35
+
36
+ # Attribute accessor.
37
+ def rows
38
+ entries.size
39
+ end
40
+
41
+ # Attribute accessor.
42
+ def columns
43
+ entries[0].length
44
+ end
45
+
46
+ # This method assigns a border width setting to all of the sides on all
47
+ # of the cells within a table.
48
+ #
49
+ # ==== Parameters
50
+ # width:: The border width setting to apply. Negative values are ignored
51
+ # and zero switches the border off.
52
+ def border_width=(width)
53
+ self.each {|row| row.border_width = width}
54
+ end
55
+
56
+ # This method assigns a shading colour to a specified row within a
57
+ # TableNode object.
58
+ #
59
+ # ==== Parameters
60
+ # index:: The offset from the first row of the row to have shading
61
+ # applied to it.
62
+ # colour:: A reference to a Colour object representing the shading colour
63
+ # to be used. Set to nil to clear shading.
64
+ def row_shading_colour(index, colour)
65
+ row = self[index]
66
+ row.shading_colour = colour if row != nil
67
+ end
68
+
69
+ # This method assigns a shading colour to a specified column within a
70
+ # TableNode object.
71
+ #
72
+ # ==== Parameters
73
+ # index:: The offset from the first column of the column to have shading
74
+ # applied to it.
75
+ # colour:: A reference to a Colour object representing the shading colour
76
+ # to be used. Set to nil to clear shading.
77
+ def column_shading_colour(index, colour)
78
+ self.each do |row|
79
+ cell = row[index]
80
+ cell.shading_colour = colour if cell != nil
81
+ end
82
+ end
83
+
84
+ # This method provides a means of assigning a shading colour to a
85
+ # selection of cells within a table. The method accepts a block that
86
+ # takes three parameters - a TableCellNode representing a cell within the
87
+ # table, an integer representing the x offset of the cell and an integer
88
+ # representing the y offset of the cell. If the block returns true then
89
+ # shading will be applied to the cell.
90
+ #
91
+ # ==== Parameters
92
+ # colour:: A reference to a Colour object representing the shading colour
93
+ # to be applied. Set to nil to remove shading.
94
+ def shading_colour(colour)
95
+ if block_given?
96
+ 0.upto(self.size - 1) do |x|
97
+ row = self[x]
98
+ 0.upto(row.size - 1) do |y|
99
+ apply = yield row[y], x, y
100
+ row[y].shading_colour = colour if apply
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ # This method overloads the store method inherited from the ContainerNode
107
+ # class to forbid addition of further nodes.
108
+ #
109
+ # ==== Parameters
110
+ # node:: A reference to the node to be added.
111
+ def store(node)
112
+ RTFError.fire("Table nodes cannot have nodes added to.")
113
+ end
114
+
115
+ # This method generates the RTF document text for a TableCellNode object.
116
+ def to_rtf
117
+ text = StringIO.new
118
+ size = 0
119
+
120
+ self.each do |row|
121
+ if size > 0
122
+ text << "\n"
123
+ else
124
+ size = 1
125
+ end
126
+ text << row.to_rtf
127
+ end
128
+
129
+ text.string.sub(/\\row(?!.*\\row)/m, "\\lastrow\n\\row")
130
+ end
131
+
132
+ alias :column_shading_color :column_shading_colour
133
+ alias :row_shading_color :row_shading_colour
134
+ alias :shading_color :shading_colour
135
+ end # End of the TableNode class.
136
+ end
@@ -0,0 +1,92 @@
1
+ module RRTF
2
+ # This class represents a row within an RTF table. The TableRowNode is a
3
+ # specialised container node that can hold only TableCellNodes and, once
4
+ # created, cannot be resized. Its also not possible to change the parent
5
+ # of a TableRowNode object.
6
+ class TableRowNode < ContainerNode
7
+ # This is the constructor for the TableRowNode class.
8
+ #
9
+ # ===== Parameters
10
+ # table:: A reference to table that owns the row.
11
+ # cells:: The number of cells that the row will contain.
12
+ # widths:: One or more integers specifying the widths for the table
13
+ # columns
14
+ def initialize(table, cells, *widths)
15
+ super(table) do
16
+ entries = []
17
+ cells.times do |index|
18
+ entries.push(TableCellNode.new(self, widths[index]))
19
+ end
20
+ entries
21
+ end
22
+ end
23
+
24
+ # Attribute accessors
25
+ def length
26
+ entries.size
27
+ end
28
+
29
+ # This method assigns a border width setting to all of the sides on all
30
+ # of the cells within a table row.
31
+ #
32
+ # ==== Parameters
33
+ # width:: The border width setting to apply. Negative values are ignored
34
+ # and zero switches the border off.
35
+ def border_width=(width)
36
+ self.each {|cell| cell.border_width = width}
37
+ end
38
+
39
+ # This method overloads the parent= method inherited from the Node class
40
+ # to forbid the alteration of the cells parent.
41
+ #
42
+ # ==== Parameters
43
+ # parent:: A reference to the new node parent.
44
+ def parent=(parent)
45
+ RTFError.fire("Table row nodes cannot have their parent changed.")
46
+ end
47
+
48
+ # This method sets the shading colour for a row.
49
+ #
50
+ # ==== Parameters
51
+ # colour:: A reference to the Colour object that represents the new
52
+ # shading colour. Set to nil to switch shading off.
53
+ def shading_colour=(colour)
54
+ self.each {|cell| cell.shading_colour = colour}
55
+ end
56
+
57
+ # This method overloads the store method inherited from the ContainerNode
58
+ # class to forbid addition of further nodes.
59
+ #
60
+ # ==== Parameters
61
+ # node:: A reference to the node to be added.
62
+ #def store(node)
63
+ # RTFError.fire("Table row nodes cannot have nodes added to.")
64
+ #end
65
+
66
+ # This method generates the RTF document text for a TableCellNode object.
67
+ def to_rtf
68
+ text = StringIO.new
69
+ temp = StringIO.new
70
+ offset = 0
71
+
72
+ text << "\\trowd\\tgraph#{parent.cell_margin}"
73
+ self.each do |entry|
74
+ widths = entry.border_widths
75
+ colour = entry.shading_colour
76
+
77
+ text << "\n"
78
+ text << "\\clbrdrt\\brdrw#{widths[0]}\\brdrs" if widths[0] != 0
79
+ text << "\\clbrdrl\\brdrw#{widths[3]}\\brdrs" if widths[3] != 0
80
+ text << "\\clbrdrb\\brdrw#{widths[2]}\\brdrs" if widths[2] != 0
81
+ text << "\\clbrdrr\\brdrw#{widths[1]}\\brdrs" if widths[1] != 0
82
+ text << "\\clcbpat#{root.colours.index(colour)}" if colour != nil
83
+ text << "\\cellx#{entry.width + offset}"
84
+ temp << "\n#{entry.to_rtf}"
85
+ offset += entry.width
86
+ end
87
+ text << "#{temp.string}\n\\row"
88
+
89
+ text.string
90
+ end
91
+ end # End of the TableRowNode class.
92
+ end