prawn 0.15.0 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. data/COPYING +2 -2
  2. data/LICENSE +1 -1
  3. data/README.md +96 -0
  4. data/Rakefile +27 -30
  5. data/data/fonts/Action Man.dfont +0 -0
  6. data/data/fonts/Activa.ttf +0 -0
  7. data/data/fonts/Chalkboard.ttf +0 -0
  8. data/data/fonts/DejaVuSans.ttf +0 -0
  9. data/data/fonts/Dustismo_Roman.ttf +0 -0
  10. data/data/fonts/comicsans.ttf +0 -0
  11. data/data/fonts/gkai00mp.ttf +0 -0
  12. data/data/images/16bit.alpha +0 -0
  13. data/data/images/16bit.dat +0 -0
  14. data/data/images/dice.alpha +0 -0
  15. data/data/images/dice.dat +0 -0
  16. data/data/images/page_white_text.alpha +0 -0
  17. data/data/images/page_white_text.dat +0 -0
  18. data/data/images/rails.dat +0 -0
  19. data/data/images/rails.png +0 -0
  20. data/data/pdfs/nested_pages.pdf +13 -13
  21. data/lib/prawn.rb +21 -85
  22. data/lib/prawn/compatibility.rb +51 -0
  23. data/lib/prawn/core.rb +85 -0
  24. data/lib/prawn/core/annotations.rb +61 -0
  25. data/lib/prawn/core/byte_string.rb +9 -0
  26. data/lib/prawn/core/destinations.rb +90 -0
  27. data/lib/prawn/core/document_state.rb +78 -0
  28. data/lib/prawn/core/literal_string.rb +16 -0
  29. data/lib/prawn/core/name_tree.rb +177 -0
  30. data/lib/prawn/core/object_store.rb +264 -0
  31. data/lib/prawn/core/page.rb +215 -0
  32. data/lib/prawn/core/pdf_object.rb +108 -0
  33. data/lib/prawn/core/reference.rb +115 -0
  34. data/lib/prawn/core/text.rb +268 -0
  35. data/lib/prawn/core/text/formatted/arranger.rb +294 -0
  36. data/lib/prawn/core/text/formatted/line_wrap.rb +273 -0
  37. data/lib/prawn/core/text/formatted/wrap.rb +153 -0
  38. data/lib/prawn/document.rb +122 -155
  39. data/lib/prawn/document/bounding_box.rb +7 -36
  40. data/lib/prawn/document/column_box.rb +10 -38
  41. data/lib/prawn/document/graphics_state.rb +74 -11
  42. data/lib/prawn/document/internals.rb +23 -24
  43. data/lib/prawn/document/page_geometry.rb +136 -0
  44. data/lib/prawn/document/snapshot.rb +6 -7
  45. data/lib/prawn/document/span.rb +10 -12
  46. data/lib/prawn/encoding.rb +10 -9
  47. data/lib/prawn/errors.rb +30 -15
  48. data/lib/prawn/font.rb +104 -136
  49. data/lib/prawn/font/afm.rb +44 -46
  50. data/lib/prawn/font/dfont.rb +3 -4
  51. data/lib/prawn/font/ttf.rb +50 -31
  52. data/lib/prawn/graphics.rb +57 -302
  53. data/lib/prawn/graphics/cap_style.rb +3 -4
  54. data/lib/prawn/graphics/color.rb +5 -13
  55. data/lib/prawn/graphics/dash.rb +31 -53
  56. data/lib/prawn/graphics/gradient.rb +84 -0
  57. data/lib/prawn/graphics/join_style.rb +7 -9
  58. data/lib/prawn/graphics/transformation.rb +9 -10
  59. data/lib/prawn/graphics/transparency.rb +1 -3
  60. data/lib/prawn/images.rb +59 -69
  61. data/lib/prawn/images/image.rb +22 -6
  62. data/lib/prawn/images/jpg.rb +14 -20
  63. data/lib/prawn/images/png.rb +118 -61
  64. data/lib/prawn/layout.rb +15 -10
  65. data/lib/prawn/layout/grid.rb +54 -66
  66. data/lib/prawn/measurement_extensions.rb +6 -10
  67. data/lib/prawn/measurements.rb +21 -27
  68. data/lib/prawn/outline.rb +308 -6
  69. data/lib/prawn/repeater.rb +8 -10
  70. data/lib/prawn/security.rb +33 -55
  71. data/lib/prawn/security/arcfour.rb +0 -1
  72. data/lib/prawn/stamp.rb +3 -5
  73. data/lib/prawn/table.rb +60 -188
  74. data/lib/prawn/table/cell.rb +44 -272
  75. data/lib/prawn/table/cell/image.rb +3 -2
  76. data/lib/prawn/table/cell/in_table.rb +2 -4
  77. data/lib/prawn/table/cell/subtable.rb +2 -2
  78. data/lib/prawn/table/cell/text.rb +18 -41
  79. data/lib/prawn/table/cells.rb +48 -142
  80. data/lib/prawn/text.rb +25 -32
  81. data/lib/prawn/text/box.rb +6 -12
  82. data/lib/prawn/text/formatted.rb +4 -5
  83. data/lib/prawn/text/formatted/box.rb +59 -96
  84. data/lib/prawn/text/formatted/fragment.rb +23 -34
  85. data/lib/prawn/text/formatted/parser.rb +5 -15
  86. data/prawn.gemspec +13 -24
  87. data/spec/annotations_spec.rb +32 -16
  88. data/spec/bounding_box_spec.rb +17 -119
  89. data/spec/cell_spec.rb +42 -112
  90. data/spec/destinations_spec.rb +5 -5
  91. data/spec/document_spec.rb +111 -155
  92. data/spec/extensions/mocha.rb +0 -1
  93. data/spec/font_spec.rb +99 -149
  94. data/spec/formatted_text_arranger_spec.rb +43 -43
  95. data/spec/formatted_text_box_spec.rb +44 -43
  96. data/spec/formatted_text_fragment_spec.rb +8 -8
  97. data/spec/graphics_spec.rb +68 -151
  98. data/spec/grid_spec.rb +15 -26
  99. data/spec/images_spec.rb +30 -51
  100. data/spec/inline_formatted_text_parser_spec.rb +20 -69
  101. data/spec/jpg_spec.rb +4 -4
  102. data/spec/line_wrap_spec.rb +28 -28
  103. data/spec/measurement_units_spec.rb +6 -6
  104. data/spec/name_tree_spec.rb +112 -0
  105. data/spec/object_store_spec.rb +106 -17
  106. data/spec/outline_spec.rb +63 -103
  107. data/spec/pdf_object_spec.rb +170 -0
  108. data/spec/png_spec.rb +25 -25
  109. data/spec/reference_spec.rb +65 -8
  110. data/spec/repeater_spec.rb +10 -10
  111. data/spec/security_spec.rb +12 -44
  112. data/spec/snapshot_spec.rb +7 -7
  113. data/spec/span_spec.rb +15 -10
  114. data/spec/spec_helper.rb +8 -32
  115. data/spec/stamp_spec.rb +30 -29
  116. data/spec/stroke_styles_spec.rb +18 -36
  117. data/spec/table_spec.rb +111 -706
  118. data/spec/template_spec.rb +297 -0
  119. data/spec/text_at_spec.rb +33 -19
  120. data/spec/text_box_spec.rb +64 -100
  121. data/spec/text_rendering_mode_spec.rb +5 -5
  122. data/spec/text_spacing_spec.rb +4 -4
  123. data/spec/text_spec.rb +64 -84
  124. data/spec/transparency_spec.rb +5 -5
  125. metadata +290 -463
  126. checksums.yaml +0 -7
  127. data/.yardopts +0 -10
  128. data/Gemfile +0 -11
  129. data/data/images/16bit.color +0 -0
  130. data/data/images/dice.color +0 -0
  131. data/data/images/indexed_color.dat +0 -0
  132. data/data/images/indexed_color.png +0 -0
  133. data/data/images/page_white_text.color +0 -0
  134. data/lib/prawn/font_metric_cache.rb +0 -47
  135. data/lib/prawn/graphics/patterns.rb +0 -138
  136. data/lib/prawn/image_handler.rb +0 -36
  137. data/lib/prawn/soft_mask.rb +0 -96
  138. data/lib/prawn/table/cell/span_dummy.rb +0 -93
  139. data/lib/prawn/table/column_width_calculator.rb +0 -61
  140. data/lib/prawn/text/formatted/arranger.rb +0 -290
  141. data/lib/prawn/text/formatted/line_wrap.rb +0 -266
  142. data/lib/prawn/text/formatted/wrap.rb +0 -150
  143. data/lib/prawn/utilities.rb +0 -46
  144. data/manual/basic_concepts/adding_pages.rb +0 -27
  145. data/manual/basic_concepts/basic_concepts.rb +0 -34
  146. data/manual/basic_concepts/creation.rb +0 -39
  147. data/manual/basic_concepts/cursor.rb +0 -33
  148. data/manual/basic_concepts/measurement.rb +0 -25
  149. data/manual/basic_concepts/origin.rb +0 -38
  150. data/manual/basic_concepts/other_cursor_helpers.rb +0 -40
  151. data/manual/bounding_box/bounding_box.rb +0 -39
  152. data/manual/bounding_box/bounds.rb +0 -49
  153. data/manual/bounding_box/canvas.rb +0 -24
  154. data/manual/bounding_box/creation.rb +0 -23
  155. data/manual/bounding_box/indentation.rb +0 -46
  156. data/manual/bounding_box/nesting.rb +0 -45
  157. data/manual/bounding_box/russian_boxes.rb +0 -40
  158. data/manual/bounding_box/stretchy.rb +0 -31
  159. data/manual/document_and_page_options/background.rb +0 -27
  160. data/manual/document_and_page_options/document_and_page_options.rb +0 -32
  161. data/manual/document_and_page_options/metadata.rb +0 -23
  162. data/manual/document_and_page_options/page_margins.rb +0 -38
  163. data/manual/document_and_page_options/page_size.rb +0 -34
  164. data/manual/document_and_page_options/print_scaling.rb +0 -20
  165. data/manual/example_file.rb +0 -111
  166. data/manual/example_helper.rb +0 -411
  167. data/manual/example_package.rb +0 -53
  168. data/manual/example_section.rb +0 -46
  169. data/manual/graphics/circle_and_ellipse.rb +0 -22
  170. data/manual/graphics/color.rb +0 -24
  171. data/manual/graphics/common_lines.rb +0 -30
  172. data/manual/graphics/fill_and_stroke.rb +0 -42
  173. data/manual/graphics/fill_rules.rb +0 -37
  174. data/manual/graphics/gradients.rb +0 -37
  175. data/manual/graphics/graphics.rb +0 -58
  176. data/manual/graphics/helper.rb +0 -24
  177. data/manual/graphics/line_width.rb +0 -35
  178. data/manual/graphics/lines_and_curves.rb +0 -41
  179. data/manual/graphics/polygon.rb +0 -29
  180. data/manual/graphics/rectangle.rb +0 -21
  181. data/manual/graphics/rotate.rb +0 -28
  182. data/manual/graphics/scale.rb +0 -41
  183. data/manual/graphics/soft_masks.rb +0 -46
  184. data/manual/graphics/stroke_cap.rb +0 -31
  185. data/manual/graphics/stroke_dash.rb +0 -48
  186. data/manual/graphics/stroke_join.rb +0 -30
  187. data/manual/graphics/translate.rb +0 -29
  188. data/manual/graphics/transparency.rb +0 -35
  189. data/manual/images/absolute_position.rb +0 -23
  190. data/manual/images/fit.rb +0 -21
  191. data/manual/images/horizontal.rb +0 -25
  192. data/manual/images/images.rb +0 -40
  193. data/manual/images/plain_image.rb +0 -18
  194. data/manual/images/scale.rb +0 -22
  195. data/manual/images/vertical.rb +0 -28
  196. data/manual/images/width_and_height.rb +0 -25
  197. data/manual/layout/boxes.rb +0 -27
  198. data/manual/layout/content.rb +0 -25
  199. data/manual/layout/layout.rb +0 -28
  200. data/manual/layout/simple_grid.rb +0 -23
  201. data/manual/manual/cover.rb +0 -36
  202. data/manual/manual/foreword.rb +0 -85
  203. data/manual/manual/how_to_read_this_manual.rb +0 -41
  204. data/manual/manual/manual.rb +0 -34
  205. data/manual/outline/add_subsection_to.rb +0 -61
  206. data/manual/outline/insert_section_after.rb +0 -47
  207. data/manual/outline/outline.rb +0 -32
  208. data/manual/outline/sections_and_pages.rb +0 -67
  209. data/manual/repeatable_content/page_numbering.rb +0 -54
  210. data/manual/repeatable_content/repeatable_content.rb +0 -31
  211. data/manual/repeatable_content/repeater.rb +0 -55
  212. data/manual/repeatable_content/stamp.rb +0 -41
  213. data/manual/security/encryption.rb +0 -31
  214. data/manual/security/permissions.rb +0 -38
  215. data/manual/security/security.rb +0 -28
  216. data/manual/syntax_highlight.rb +0 -52
  217. data/manual/table/basic_block.rb +0 -53
  218. data/manual/table/before_rendering_page.rb +0 -26
  219. data/manual/table/cell_border_lines.rb +0 -24
  220. data/manual/table/cell_borders_and_bg.rb +0 -31
  221. data/manual/table/cell_dimensions.rb +0 -30
  222. data/manual/table/cell_text.rb +0 -38
  223. data/manual/table/column_widths.rb +0 -30
  224. data/manual/table/content_and_subtables.rb +0 -39
  225. data/manual/table/creation.rb +0 -27
  226. data/manual/table/filtering.rb +0 -36
  227. data/manual/table/flow_and_header.rb +0 -17
  228. data/manual/table/image_cells.rb +0 -33
  229. data/manual/table/position.rb +0 -29
  230. data/manual/table/row_colors.rb +0 -20
  231. data/manual/table/span.rb +0 -30
  232. data/manual/table/style.rb +0 -22
  233. data/manual/table/table.rb +0 -52
  234. data/manual/table/width.rb +0 -27
  235. data/manual/text/alignment.rb +0 -44
  236. data/manual/text/color.rb +0 -24
  237. data/manual/text/column_box.rb +0 -32
  238. data/manual/text/fallback_fonts.rb +0 -37
  239. data/manual/text/font.rb +0 -41
  240. data/manual/text/font_size.rb +0 -45
  241. data/manual/text/font_style.rb +0 -23
  242. data/manual/text/formatted_callbacks.rb +0 -60
  243. data/manual/text/formatted_text.rb +0 -54
  244. data/manual/text/free_flowing_text.rb +0 -51
  245. data/manual/text/group.rb +0 -31
  246. data/manual/text/inline.rb +0 -43
  247. data/manual/text/kerning_and_character_spacing.rb +0 -39
  248. data/manual/text/leading.rb +0 -25
  249. data/manual/text/line_wrapping.rb +0 -41
  250. data/manual/text/paragraph_indentation.rb +0 -26
  251. data/manual/text/positioned_text.rb +0 -38
  252. data/manual/text/registering_families.rb +0 -48
  253. data/manual/text/rendering_and_color.rb +0 -37
  254. data/manual/text/right_to_left_text.rb +0 -43
  255. data/manual/text/rotation.rb +0 -43
  256. data/manual/text/single_usage.rb +0 -37
  257. data/manual/text/text.rb +0 -75
  258. data/manual/text/text_box_excess.rb +0 -32
  259. data/manual/text/text_box_extensions.rb +0 -45
  260. data/manual/text/text_box_overflow.rb +0 -44
  261. data/manual/text/utf8.rb +0 -28
  262. data/manual/text/win_ansi_charset.rb +0 -59
  263. data/spec/acceptance/png.rb +0 -23
  264. data/spec/column_box_spec.rb +0 -65
  265. data/spec/extensions/encoding_helpers.rb +0 -9
  266. data/spec/font_metric_cache_spec.rb +0 -52
  267. data/spec/image_handler_spec.rb +0 -54
  268. data/spec/soft_mask_spec.rb +0 -117
  269. data/spec/table/span_dummy_spec.rb +0 -17
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # cell.rb: Table cell drawing.
4
4
  #
@@ -6,13 +6,10 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
- require 'date'
10
9
  module Prawn
11
10
  class Document
12
11
 
13
- # @group Experimental API
14
-
15
- # Instantiates and draws a cell on the document.
12
+ # Instantiates and draws a cell on the document.
16
13
  #
17
14
  # cell(:content => "Hello world!", :at => [12, 34])
18
15
  #
@@ -23,9 +20,9 @@ module Prawn
23
20
  cell.draw
24
21
  cell
25
22
  end
26
-
27
- # Set up, but do not draw, a cell. Useful for creating cells with
28
- # formatting options to be inserted into a Table. Call +draw+ on the
23
+
24
+ # Set up, but do not draw, a cell. Useful for creating cells with
25
+ # formatting options to be inserted into a Table. Call +draw+ on the
29
26
  # resulting Cell to ink it.
30
27
  #
31
28
  # See the documentation on Prawn::Cell for details on the arguments.
@@ -37,7 +34,7 @@ module Prawn
37
34
  end
38
35
 
39
36
  class Table
40
-
37
+
41
38
  # A Cell is a rectangular area of the page into which content is drawn. It
42
39
  # has a framework for sizing itself and adding padding and simple styling.
43
40
  # There are several standard Cell subclasses that handle things like text,
@@ -56,58 +53,20 @@ module Prawn
56
53
  #
57
54
  attr_reader :padding
58
55
 
59
- # If provided, the minimum width that this cell in its column will permit.
60
- #
61
- def min_width_ignoring_span
56
+ # If provided, the minimum width that this cell will permit.
57
+ #
58
+ def min_width
62
59
  set_width_constraints
63
60
  @min_width
64
61
  end
65
-
66
- # Minimum width of the entire span group this cell controls.
67
- #
68
- def min_width
69
- return min_width_ignoring_span if @colspan == 1
70
-
71
- # Sum up the largest min-width from each column, including myself.
72
- min_widths = Hash.new(0)
73
- dummy_cells.each do |cell|
74
- min_widths[cell.column] =
75
- [min_widths[cell.column], cell.min_width].max
76
- end
77
- min_widths[column] = [min_widths[column], min_width_ignoring_span].max
78
- min_widths.values.inject(0, &:+)
79
- end
80
-
81
- # Min-width of the span divided by the number of columns.
82
- #
83
- def avg_spanned_min_width
84
- min_width.to_f / colspan
85
- end
86
-
87
- # If provided, the maximum width that this cell can be drawn in, within
88
- # its column.
62
+
63
+ # If provided, the maximum width that this cell can be drawn in.
89
64
  #
90
- def max_width_ignoring_span
65
+ def max_width
91
66
  set_width_constraints
92
67
  @max_width
93
68
  end
94
69
 
95
- # Maximum width of the entire span group this cell controls.
96
- #
97
- def max_width
98
- return max_width_ignoring_span if @colspan == 1
99
-
100
- # Sum the smallest max-width from each column in the group, including
101
- # myself.
102
- max_widths = Hash.new(0)
103
- dummy_cells.each do |cell|
104
- max_widths[cell.column] =
105
- [max_widths[cell.column], cell.max_width].min
106
- end
107
- max_widths[column] = [max_widths[column], max_width_ignoring_span].min
108
- max_widths.values.inject(0, &:+)
109
- end
110
-
111
70
  # Manually specify the cell's height.
112
71
  #
113
72
  attr_writer :height
@@ -125,15 +84,11 @@ module Prawn
125
84
  #
126
85
  attr_reader :border_colors
127
86
 
128
- # Line style
129
- #
130
- attr_reader :border_lines
131
-
132
87
  # Specifies the content for the cell. Must be a "cellable" object. See the
133
88
  # "Data" section of the Prawn::Table documentation for details on cellable
134
89
  # objects.
135
90
  #
136
- attr_accessor :content
91
+ attr_accessor :content
137
92
 
138
93
  # The background color, if any, for this cell. Specified in HTML RGB
139
94
  # format, e.g., "ccffff". The background is drawn under the whole cell,
@@ -141,21 +96,6 @@ module Prawn
141
96
  #
142
97
  attr_accessor :background_color
143
98
 
144
- # Number of columns this cell spans. Defaults to 1.
145
- #
146
- attr_reader :colspan
147
-
148
- # Number of rows this cell spans. Defaults to 1.
149
- #
150
- attr_reader :rowspan
151
-
152
- # Array of SpanDummy cells (if any) that represent the other cells in
153
- # this span group. They know their own width / height, but do not draw
154
- # anything.
155
- #
156
- # @private
157
- attr_reader :dummy_cells
158
-
159
99
  # Instantiates a Cell based on the given options. The particular class of
160
100
  # cell returned depends on the :content argument. See the Prawn::Table
161
101
  # documentation under "Data" for allowable content types.
@@ -164,9 +104,9 @@ module Prawn
164
104
  at = options.delete(:at) || [0, pdf.cursor]
165
105
  content = content.to_s if content.nil? || content.kind_of?(Numeric) ||
166
106
  content.kind_of?(Date)
167
-
107
+
168
108
  if content.is_a?(Hash)
169
- if content[:image]
109
+ if img = content[:image]
170
110
  return Cell::Image.new(pdf, at, content)
171
111
  end
172
112
  options.update(content)
@@ -175,8 +115,6 @@ module Prawn
175
115
  options[:content] = content
176
116
  end
177
117
 
178
- options[:content] = content = "" if content.nil?
179
-
180
118
  case content
181
119
  when Prawn::Table::Cell
182
120
  content
@@ -215,14 +153,8 @@ module Prawn
215
153
  @borders = [:top, :bottom, :left, :right]
216
154
  @border_widths = [1] * 4
217
155
  @border_colors = ['000000'] * 4
218
- @border_lines = [:solid] * 4
219
- @colspan = 1
220
- @rowspan = 1
221
- @dummy_cells = []
222
156
 
223
157
  options.each { |k, v| send("#{k}=", v) }
224
-
225
- @initializer_run = true
226
158
  end
227
159
 
228
160
  # Supports setting multiple properties at once.
@@ -235,40 +167,19 @@ module Prawn
235
167
  # cell.border_width = 2
236
168
  #
237
169
  def style(options={}, &block)
238
- options.each do |k, v|
239
- send("#{k}=", v) if respond_to?("#{k}=")
240
- end
170
+ options.each { |k, v| send("#{k}=", v) }
241
171
 
242
172
  # The block form supports running a single block for multiple cells, as
243
173
  # in Cells#style.
244
174
  block.call(self) if block
245
175
  end
246
176
 
247
- # Returns the width of the cell in its first column alone, ignoring any
248
- # colspans.
177
+ # Returns the cell's width in points, inclusive of padding.
249
178
  #
250
- def width_ignoring_span
179
+ def width
251
180
  # We can't ||= here because the FP error accumulates on the round-trip
252
181
  # from #content_width.
253
- defined?(@width) && @width || (content_width + padding_left + padding_right)
254
- end
255
-
256
- # Returns the cell's width in points, inclusive of padding. If the cell is
257
- # the master cell of a colspan, returns the width of the entire span
258
- # group.
259
- #
260
- def width
261
- return width_ignoring_span if @colspan == 1 && @rowspan == 1
262
-
263
- # We're in a span group; get the maximum width per column (including
264
- # the master cell) and sum each column.
265
- column_widths = Hash.new(0)
266
- dummy_cells.each do |cell|
267
- column_widths[cell.column] =
268
- [column_widths[cell.column], cell.width].max
269
- end
270
- column_widths[column] = [column_widths[column], width_ignoring_span].max
271
- column_widths.values.inject(0, &:+)
182
+ @width || (content_width + padding_left + padding_right)
272
183
  end
273
184
 
274
185
  # Manually sets the cell's width, inclusive of padding.
@@ -280,120 +191,47 @@ module Prawn
280
191
  # Returns the width of the bare content in the cell, excluding padding.
281
192
  #
282
193
  def content_width
283
- if defined?(@width) && @width # manually set
194
+ if @width # manually set
284
195
  return @width - padding_left - padding_right
285
196
  end
286
197
 
287
198
  natural_content_width
288
199
  end
289
200
 
290
- # Width of the entire span group.
291
- #
292
- def spanned_content_width
293
- width - padding_left - padding_right
294
- end
295
-
296
201
  # Returns the width this cell would naturally take on, absent other
297
202
  # constraints. Must be implemented in subclasses.
298
203
  #
299
204
  def natural_content_width
300
- raise NotImplementedError,
205
+ raise NotImplementedError,
301
206
  "subclasses must implement natural_content_width"
302
207
  end
303
208
 
304
- # Returns the cell's height in points, inclusive of padding, in its first
305
- # row only.
209
+ # Returns the cell's height in points, inclusive of padding.
306
210
  #
307
- def height_ignoring_span
211
+ def height
308
212
  # We can't ||= here because the FP error accumulates on the round-trip
309
213
  # from #content_height.
310
- defined?(@height) && @height || (content_height + padding_top + padding_bottom)
311
- end
312
-
313
- # Returns the cell's height in points, inclusive of padding. If the cell
314
- # is the master cell of a rowspan, returns the width of the entire span
315
- # group.
316
- #
317
- def height
318
- return height_ignoring_span if @colspan == 1 && @rowspan == 1
319
-
320
- # We're in a span group; get the maximum height per row (including the
321
- # master cell) and sum each row.
322
- row_heights = Hash.new(0)
323
- dummy_cells.each do |cell|
324
- row_heights[cell.row] = [row_heights[cell.row], cell.height].max
325
- end
326
- row_heights[row] = [row_heights[row], height_ignoring_span].max
327
- row_heights.values.inject(0, &:+)
214
+ @height || (content_height + padding_top + padding_bottom)
328
215
  end
329
216
 
330
217
  # Returns the height of the bare content in the cell, excluding padding.
331
218
  #
332
219
  def content_height
333
- if defined?(@height) && @height # manually set
220
+ if @height # manually set
334
221
  return @height - padding_top - padding_bottom
335
222
  end
336
-
223
+
337
224
  natural_content_height
338
225
  end
339
226
 
340
- # Height of the entire span group.
341
- #
342
- def spanned_content_height
343
- height - padding_top - padding_bottom
344
- end
345
-
346
227
  # Returns the height this cell would naturally take on, absent
347
228
  # constraints. Must be implemented in subclasses.
348
229
  #
349
230
  def natural_content_height
350
- raise NotImplementedError,
231
+ raise NotImplementedError,
351
232
  "subclasses must implement natural_content_height"
352
233
  end
353
234
 
354
- # Indicates the number of columns that this cell is to span. Defaults to
355
- # 1.
356
- #
357
- # This must be provided as part of the table data, like so:
358
- #
359
- # pdf.table([["foo", {:content => "bar", :colspan => 2}]])
360
- #
361
- # Setting colspan from the initializer block is invalid because layout
362
- # has already run. For example, this will NOT work:
363
- #
364
- # pdf.table([["foo", "bar"]]) { cells[0, 1].colspan = 2 }
365
- #
366
- def colspan=(span)
367
- if defined?(@initializer_run) && @initializer_run
368
- raise Prawn::Errors::InvalidTableSpan,
369
- "colspan must be provided in the table's structure, never in the " +
370
- "initialization block. See Prawn's documentation for details."
371
- end
372
-
373
- @colspan = span
374
- end
375
-
376
- # Indicates the number of rows that this cell is to span. Defaults to 1.
377
- #
378
- # This must be provided as part of the table data, like so:
379
- #
380
- # pdf.table([["foo", {:content => "bar", :rowspan => 2}], ["baz"]])
381
- #
382
- # Setting rowspan from the initializer block is invalid because layout
383
- # has already run. For example, this will NOT work:
384
- #
385
- # pdf.table([["foo", "bar"], ["baz"]]) { cells[0, 1].rowspan = 2 }
386
- #
387
- def rowspan=(span)
388
- if defined?(@initializer_run) && @initializer_run
389
- raise Prawn::Errors::InvalidTableSpan,
390
- "rowspan must be provided in the table's structure, never in the " +
391
- "initialization block. See Prawn's documentation for details."
392
- end
393
-
394
- @rowspan = span
395
- end
396
-
397
235
  # Draws the cell onto the document. Pass in a point [x,y] to override the
398
236
  # location at which the cell is drawn.
399
237
  #
@@ -402,7 +240,7 @@ module Prawn
402
240
  # content are all drawn in correct order so as not to overlap.
403
241
  #
404
242
  def draw(pt=[x, y])
405
- Prawn::Table::Cell.draw_cells([[self, pt]])
243
+ self.class.draw_cells([[self, pt]])
406
244
  end
407
245
 
408
246
  # Given an array of pairs [cell, pt], draws each cell at its
@@ -425,9 +263,9 @@ module Prawn
425
263
  #
426
264
  def draw_bounded_content(pt)
427
265
  @pdf.float do
428
- @pdf.bounding_box([pt[0] + padding_left, pt[1] - padding_top],
429
- :width => spanned_content_width + FPTolerance,
430
- :height => spanned_content_height + FPTolerance) do
266
+ @pdf.bounding_box([pt[0] + padding_left, pt[1] - padding_top],
267
+ :width => content_width + FPTolerance,
268
+ :height => content_height + FPTolerance) do
431
269
  draw_content
432
270
  end
433
271
  end
@@ -485,7 +323,7 @@ module Prawn
485
323
  def padding_top
486
324
  @padding[0]
487
325
  end
488
-
326
+
489
327
  def padding_top=(val)
490
328
  @padding[0] = val
491
329
  end
@@ -493,7 +331,7 @@ module Prawn
493
331
  def padding_right
494
332
  @padding[1]
495
333
  end
496
-
334
+
497
335
  def padding_right=(val)
498
336
  @padding[1] = val
499
337
  end
@@ -501,7 +339,7 @@ module Prawn
501
339
  def padding_bottom
502
340
  @padding[2]
503
341
  end
504
-
342
+
505
343
  def padding_bottom=(val)
506
344
  @padding[2] = val
507
345
  end
@@ -509,7 +347,7 @@ module Prawn
509
347
  def padding_left
510
348
  @padding[3]
511
349
  end
512
-
350
+
513
351
  def padding_left=(val)
514
352
  @padding[3] = val
515
353
  end
@@ -548,6 +386,14 @@ module Prawn
548
386
  @border_colors[0] = val
549
387
  end
550
388
 
389
+ def border_top_color
390
+ @border_colors[0]
391
+ end
392
+
393
+ def border_top_color=(val)
394
+ @border_colors[0] = val
395
+ end
396
+
551
397
  def border_right_color
552
398
  @border_colors[1]
553
399
  end
@@ -638,70 +484,10 @@ module Prawn
638
484
  @max_width ||= @pdf.bounds.width
639
485
  end
640
486
 
641
- # Sets border line style on this cell. The argument can be one of:
642
- #
643
- # Possible values are: :solid, :dashed, :dotted
644
- #
645
- # * one value (sets all lines)
646
- # * a two-element array [vertical, horizontal]
647
- # * a three-element array [top, horizontal, bottom]
648
- # * a four-element array [top, right, bottom, left]
649
- #
650
- def border_line=(line)
651
- @border_lines = case
652
- when line.nil?
653
- [:solid] * 4
654
- when line.length == 1 # all lines
655
- [line[0]] * 4
656
- when line.length == 2
657
- [line[0], line[1], line[0], line[1]]
658
- when line.length == 3
659
- [line[0], line[1], line[2], line[1]]
660
- when line.length == 4
661
- [line[0], line[1], line[2], line[3]]
662
- else
663
- raise ArgumentError, "border_line must be one of :solid, :dashed, "
664
- ":dotted or an array [v,h] or [t,r,b,l]"
665
- end
666
- end
667
- alias_method :border_lines=, :border_line=
668
-
669
- def border_top_line
670
- @borders.include?(:top) ? @border_lines[0] : 0
671
- end
672
-
673
- def border_top_line=(val)
674
- @border_lines[0] = val
675
- end
676
-
677
- def border_right_line
678
- @borders.include?(:right) ? @border_lines[1] : 0
679
- end
680
-
681
- def border_right_line=(val)
682
- @border_lines[1] = val
683
- end
684
-
685
- def border_bottom_line
686
- @borders.include?(:bottom) ? @border_lines[2] : 0
687
- end
688
-
689
- def border_bottom_line=(val)
690
- @border_lines[2] = val
691
- end
692
-
693
- def border_left_line
694
- @borders.include?(:left) ? @border_lines[3] : 0
695
- end
696
-
697
- def border_left_line=(val)
698
- @border_lines[3] = val
699
- end
700
-
701
487
  # Draws the cell's background color.
702
488
  #
703
489
  def draw_background(pt)
704
- if defined?(@background_color) && @background_color
490
+ if @background_color
705
491
  @pdf.mask(:fill_color) do
706
492
  @pdf.fill_color @background_color
707
493
  @pdf.fill_rectangle pt, width, height
@@ -722,7 +508,6 @@ module Prawn
722
508
  idx = {:top => 0, :right => 1, :bottom => 2, :left => 3}[border]
723
509
  border_color = @border_colors[idx]
724
510
  border_width = @border_widths[idx]
725
- border_line = @border_lines[idx]
726
511
 
727
512
  next if border_width <= 0
728
513
 
@@ -741,22 +526,9 @@ module Prawn
741
526
  [x+width, y - height - (border_bottom_width / 2.0)]]
742
527
  end
743
528
 
744
- case border_line
745
- when :dashed
746
- @pdf.dash border_width * 4
747
- when :dotted
748
- @pdf.dash border_width, :space => border_width * 2
749
- when :solid
750
- # normal line style
751
- else
752
- raise ArgumentError, "border_line must be :solid, :dotted or" +
753
- " :dashed"
754
- end
755
-
756
529
  @pdf.line_width = border_width
757
530
  @pdf.stroke_color = border_color
758
531
  @pdf.stroke_line(from, to)
759
- @pdf.undash
760
532
  end
761
533
  end
762
534
  end