prawn 1.0.0.rc2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +9 -0
  3. data/COPYING +2 -2
  4. data/Gemfile +8 -15
  5. data/LICENSE +1 -1
  6. data/Rakefile +25 -16
  7. data/data/images/16bit.alpha +0 -0
  8. data/data/images/16bit.color +0 -0
  9. data/data/images/dice.alpha +0 -0
  10. data/data/images/dice.color +0 -0
  11. data/data/images/indexed_color.dat +0 -0
  12. data/data/images/indexed_color.png +0 -0
  13. data/data/images/license.md +8 -0
  14. data/data/images/page_white_text.alpha +0 -0
  15. data/data/images/page_white_text.color +0 -0
  16. data/lib/prawn.rb +85 -23
  17. data/lib/prawn/document.rb +134 -116
  18. data/lib/prawn/document/bounding_box.rb +33 -4
  19. data/lib/prawn/document/column_box.rb +18 -6
  20. data/lib/prawn/document/graphics_state.rb +11 -74
  21. data/lib/prawn/document/internals.rb +24 -23
  22. data/lib/prawn/document/span.rb +12 -10
  23. data/lib/prawn/encoding.rb +8 -9
  24. data/lib/prawn/errors.rb +13 -32
  25. data/lib/prawn/font.rb +137 -105
  26. data/lib/prawn/font/afm.rb +76 -32
  27. data/lib/prawn/font/dfont.rb +4 -3
  28. data/lib/prawn/font/ttf.rb +33 -25
  29. data/lib/prawn/font_metric_cache.rb +47 -0
  30. data/lib/prawn/graphics.rb +177 -57
  31. data/lib/prawn/graphics/cap_style.rb +4 -3
  32. data/lib/prawn/graphics/color.rb +5 -4
  33. data/lib/prawn/graphics/dash.rb +53 -31
  34. data/lib/prawn/graphics/join_style.rb +9 -7
  35. data/lib/prawn/graphics/patterns.rb +4 -15
  36. data/lib/prawn/graphics/transformation.rb +10 -9
  37. data/lib/prawn/graphics/transparency.rb +3 -1
  38. data/lib/prawn/{layout/grid.rb → grid.rb} +72 -54
  39. data/lib/prawn/image_handler.rb +42 -0
  40. data/lib/prawn/images.rb +58 -54
  41. data/lib/prawn/images/image.rb +6 -22
  42. data/lib/prawn/images/jpg.rb +20 -14
  43. data/lib/prawn/images/png.rb +58 -121
  44. data/lib/prawn/layout.rb +12 -15
  45. data/lib/prawn/measurement_extensions.rb +10 -6
  46. data/lib/prawn/measurements.rb +27 -21
  47. data/lib/prawn/outline.rb +108 -147
  48. data/lib/prawn/repeater.rb +10 -8
  49. data/lib/prawn/security.rb +59 -40
  50. data/lib/prawn/security/arcfour.rb +52 -0
  51. data/lib/prawn/soft_mask.rb +4 -4
  52. data/lib/prawn/stamp.rb +5 -3
  53. data/lib/prawn/table.rb +83 -60
  54. data/lib/prawn/table/cell.rb +17 -21
  55. data/lib/prawn/table/cell/image.rb +2 -3
  56. data/lib/prawn/table/cell/in_table.rb +8 -2
  57. data/lib/prawn/table/cell/span_dummy.rb +5 -0
  58. data/lib/prawn/table/cell/subtable.rb +3 -2
  59. data/lib/prawn/table/cell/text.rb +14 -12
  60. data/lib/prawn/table/cells.rb +58 -14
  61. data/lib/prawn/table/column_width_calculator.rb +61 -0
  62. data/lib/prawn/text.rb +27 -26
  63. data/lib/prawn/text/box.rb +12 -6
  64. data/lib/prawn/text/formatted.rb +5 -4
  65. data/lib/prawn/text/formatted/arranger.rb +290 -0
  66. data/lib/prawn/text/formatted/box.rb +85 -57
  67. data/lib/prawn/text/formatted/fragment.rb +11 -11
  68. data/lib/prawn/text/formatted/line_wrap.rb +266 -0
  69. data/lib/prawn/text/formatted/parser.rb +11 -4
  70. data/lib/prawn/text/formatted/wrap.rb +156 -0
  71. data/lib/prawn/utilities.rb +5 -3
  72. data/manual/document_and_page_options/document_and_page_options.rb +2 -1
  73. data/manual/document_and_page_options/metadata.rb +3 -3
  74. data/manual/document_and_page_options/page_size.rb +2 -2
  75. data/manual/document_and_page_options/print_scaling.rb +20 -0
  76. data/manual/example_file.rb +2 -7
  77. data/manual/example_helper.rb +62 -81
  78. data/manual/graphics/common_lines.rb +2 -0
  79. data/manual/graphics/helper.rb +11 -4
  80. data/manual/graphics/stroke_dash.rb +19 -14
  81. data/manual/manual/cover.rb +16 -0
  82. data/manual/manual/manual.rb +1 -5
  83. data/manual/text/fallback_fonts.rb +4 -4
  84. data/manual/text/formatted_text.rb +5 -5
  85. data/manual/text/inline.rb +2 -4
  86. data/manual/text/registering_families.rb +12 -12
  87. data/manual/text/single_usage.rb +4 -4
  88. data/manual/text/text.rb +0 -2
  89. data/prawn.gemspec +21 -13
  90. data/spec/acceptance/png.rb +23 -0
  91. data/spec/annotations_spec.rb +16 -32
  92. data/spec/bounding_box_spec.rb +22 -5
  93. data/spec/cell_spec.rb +49 -5
  94. data/spec/column_box_spec.rb +32 -0
  95. data/spec/destinations_spec.rb +5 -5
  96. data/spec/document_spec.rb +112 -118
  97. data/spec/extensions/encoding_helpers.rb +5 -2
  98. data/spec/font_metric_cache_spec.rb +52 -0
  99. data/spec/font_spec.rb +121 -120
  100. data/spec/formatted_text_arranger_spec.rb +24 -24
  101. data/spec/formatted_text_box_spec.rb +31 -32
  102. data/spec/formatted_text_fragment_spec.rb +2 -2
  103. data/spec/graphics_spec.rb +63 -45
  104. data/spec/grid_spec.rb +24 -13
  105. data/spec/image_handler_spec.rb +54 -0
  106. data/spec/images_spec.rb +34 -21
  107. data/spec/inline_formatted_text_parser_spec.rb +69 -20
  108. data/spec/jpg_spec.rb +3 -3
  109. data/spec/line_wrap_spec.rb +25 -14
  110. data/spec/measurement_units_spec.rb +5 -5
  111. data/spec/outline_spec.rb +68 -64
  112. data/spec/png_spec.rb +15 -18
  113. data/spec/reference_spec.rb +2 -82
  114. data/spec/repeater_spec.rb +1 -1
  115. data/spec/security_spec.rb +41 -9
  116. data/spec/soft_mask_spec.rb +0 -40
  117. data/spec/span_spec.rb +6 -11
  118. data/spec/spec_helper.rb +20 -2
  119. data/spec/stamp_spec.rb +19 -20
  120. data/spec/stroke_styles_spec.rb +31 -13
  121. data/spec/table/span_dummy_spec.rb +17 -0
  122. data/spec/table_spec.rb +268 -43
  123. data/spec/text_at_spec.rb +13 -27
  124. data/spec/text_box_spec.rb +35 -30
  125. data/spec/text_spec.rb +56 -40
  126. data/spec/transparency_spec.rb +5 -5
  127. metadata +214 -217
  128. data/README.md +0 -98
  129. data/data/fonts/Action Man.dfont +0 -0
  130. data/data/fonts/Activa.ttf +0 -0
  131. data/data/fonts/Chalkboard.ttf +0 -0
  132. data/data/fonts/DejaVuSans.ttf +0 -0
  133. data/data/fonts/Dustismo_Roman.ttf +0 -0
  134. data/data/fonts/comicsans.ttf +0 -0
  135. data/data/fonts/gkai00mp.ttf +0 -0
  136. data/data/images/16bit.dat +0 -0
  137. data/data/images/barcode_issue.png +0 -0
  138. data/data/images/dice.dat +0 -0
  139. data/data/images/page_white_text.dat +0 -0
  140. data/data/images/rails.dat +0 -0
  141. data/data/images/rails.png +0 -0
  142. data/lib/prawn/compatibility.rb +0 -87
  143. data/lib/prawn/core.rb +0 -87
  144. data/lib/prawn/core/annotations.rb +0 -61
  145. data/lib/prawn/core/byte_string.rb +0 -9
  146. data/lib/prawn/core/destinations.rb +0 -90
  147. data/lib/prawn/core/document_state.rb +0 -79
  148. data/lib/prawn/core/literal_string.rb +0 -16
  149. data/lib/prawn/core/name_tree.rb +0 -177
  150. data/lib/prawn/core/object_store.rb +0 -320
  151. data/lib/prawn/core/page.rb +0 -212
  152. data/lib/prawn/core/pdf_object.rb +0 -125
  153. data/lib/prawn/core/reference.rb +0 -119
  154. data/lib/prawn/core/text.rb +0 -268
  155. data/lib/prawn/core/text/formatted/arranger.rb +0 -294
  156. data/lib/prawn/core/text/formatted/line_wrap.rb +0 -288
  157. data/lib/prawn/core/text/formatted/wrap.rb +0 -153
  158. data/lib/prawn/document/page_geometry.rb +0 -136
  159. data/lib/prawn/document/snapshot.rb +0 -89
  160. data/manual/manual/foreword.rb +0 -13
  161. data/manual/templates/full_template.rb +0 -23
  162. data/manual/templates/page_template.rb +0 -47
  163. data/manual/templates/templates.rb +0 -26
  164. data/manual/text/group.rb +0 -29
  165. data/spec/name_tree_spec.rb +0 -112
  166. data/spec/object_store_spec.rb +0 -170
  167. data/spec/pdf_object_spec.rb +0 -172
  168. data/spec/snapshot_spec.rb +0 -186
  169. data/spec/template_spec.rb +0 -351
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # cap_style.rb : Implements stroke cap styling
4
4
  #
@@ -9,6 +9,7 @@
9
9
  module Prawn
10
10
  module Graphics
11
11
  module CapStyle
12
+ # @group Stable API
12
13
 
13
14
  CAP_STYLES = { :butt => 0, :round => 1, :projecting_square => 2 }
14
15
 
@@ -30,11 +31,11 @@ module Prawn
30
31
 
31
32
  private
32
33
 
33
- def current_cap_style
34
+ def current_cap_style
34
35
  graphic_state.cap_style
35
36
  end
36
37
 
37
- def current_cap_style=(style)
38
+ def current_cap_style=(style)
38
39
  graphic_state.cap_style = style
39
40
  end
40
41
 
@@ -9,6 +9,7 @@
9
9
  module Prawn
10
10
  module Graphics
11
11
  module Color
12
+ # @group Stable API
12
13
 
13
14
  # Sets or returns the fill color.
14
15
  #
@@ -166,7 +167,7 @@ module Prawn
166
167
  if options[:pattern]
167
168
  set_color_space type, :Pattern
168
169
  add_content "/#{color} #{operator}"
169
- else
170
+ else
170
171
  set_color_space type, color_space(color)
171
172
  color = color_to_s(color)
172
173
  write_color(color, operator)
@@ -174,7 +175,7 @@ module Prawn
174
175
  end
175
176
 
176
177
  def set_fill_color(color = nil)
177
- set_color :fill, color || current_fill_color
178
+ set_color :fill, color || current_fill_color
178
179
  end
179
180
 
180
181
  def set_stroke_color(color = nil)
@@ -192,7 +193,7 @@ module Prawn
192
193
  graphic_state.color_space[type]
193
194
  end
194
195
 
195
- def set_current_color_space(color_space, type)
196
+ def set_current_color_space(color_space, type)
196
197
  save_graphics_state if graphic_state.nil?
197
198
  graphic_state.color_space[type] = color_space
198
199
  end
@@ -201,7 +202,7 @@ module Prawn
201
202
  graphic_state.fill_color
202
203
  end
203
204
 
204
- def current_fill_color=(color)
205
+ def current_fill_color=(color)
205
206
  graphic_state.fill_color = color
206
207
  end
207
208
 
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # dash.rb : Implements stroke dashing
4
4
  #
@@ -9,35 +9,59 @@
9
9
  module Prawn
10
10
  module Graphics
11
11
  module Dash
12
+ # @group Stable API
12
13
 
13
- # Sets the dash pattern for stroked lines and curves
14
+ # Sets the dash pattern for stroked lines and curves or return the
15
+ # current dash pattern setting if +length+ is nil.
14
16
  #
15
- # length is the length of the dash. If options is not present,
16
- # or options[:space] is nil, then length is also the length of
17
- # the space between dashes
17
+ # There are two ways to set the dash pattern:
18
18
  #
19
- # options may contain :space and :phase
20
- # :space is the space between the dashes
21
- # :phase is where in the cycle to begin dashing. For
22
- # example, a phase of 0 starts at the beginning of
23
- # the dash; whereas, if the phase is equal to the
24
- # length of the dash, then stroking will begin at
25
- # the beginning of the space. Default is 0
19
+ # * If the parameter +length+ is an Integer/Float, it specifies
20
+ # the length of the dash and of the gap. The length of the gap
21
+ # can be customized by setting the :space option.
26
22
  #
27
- # integers or floats may be used for length and the options
23
+ # Examples:
28
24
  #
29
- # dash units are in PDF points ( 1/72 in )
30
- #
31
- def dash(length=nil, options={})
32
- return current_dash_state || undash_hash if length.nil?
25
+ # length = 3
26
+ # 3 on, 3 off, 3 on, 3 off, ...
27
+ # length = 3, :space =2
28
+ # 3 on, 2 off, 3 on, 2 off, ...
29
+ #
30
+ # * If the parameter +length+ is an array, it specifies the
31
+ # lengths of alternating dashes and gaps. The :space option is
32
+ # ignored in this case.
33
+ #
34
+ # Examples:
35
+ #
36
+ # length = [2, 1]
37
+ # 2 on, 1 off, 2 on, 1 off, ...
38
+ # length = [3, 1, 2, 3]
39
+ # 3 on, 1 off, 2 on, 3 off, 3 on, 1 off, ...
40
+ #
41
+ # Options may contain the keys :space and :phase
42
+ #
43
+ # :space:: The space between the dashes (only used when +length+
44
+ # is not an array)
45
+ #
46
+ # :phase:: The distance into the dash pattern at which to start
47
+ # the dash. For example, a phase of 0 starts at the
48
+ # beginning of the dash; whereas, if the phase is equal
49
+ # to the length of the dash, then stroking will begin at
50
+ # the beginning of the space. Default is 0.
51
+ #
52
+ # Integers or Floats may be used for length and the option values.
53
+ # Dash units are in PDF points (1/72 inch).
54
+ #
55
+ def dash(length=nil, options={})
56
+ return current_dash_state if length.nil?
33
57
 
34
- self.current_dash_state = { :dash => length,
35
- :space => options[:space] || length,
58
+ self.current_dash_state = { :dash => length,
59
+ :space => length.kind_of?(Array) ? nil : options[:space] || length,
36
60
  :phase => options[:phase] || 0 }
37
61
 
38
62
  write_stroke_dash
39
63
  end
40
-
64
+
41
65
  alias_method :dash=, :dash
42
66
 
43
67
  # Stops dashing, restoring solid stroked lines and curves
@@ -46,37 +70,35 @@ module Prawn
46
70
  self.current_dash_state = undashed_setting
47
71
  write_stroke_dash
48
72
  end
49
-
73
+
50
74
  # Returns when stroke is dashed, false otherwise
51
75
  #
52
76
  def dashed?
53
77
  current_dash_state != undashed_setting
54
78
  end
55
-
79
+
80
+ private
81
+
56
82
  def write_stroke_dash
57
83
  add_content dash_setting
58
84
  end
59
85
 
60
- private
61
-
62
86
  def undashed_setting
63
87
  { :dash => nil, :space => nil, :phase => 0 }
64
88
  end
65
-
66
- private
67
-
68
- def current_dash_state=(dash_options)
89
+
90
+ def current_dash_state=(dash_options)
69
91
  graphic_state.dash = dash_options
70
92
  end
71
-
93
+
72
94
  def current_dash_state
73
95
  graphic_state.dash
74
96
  end
75
-
97
+
76
98
  def dash_setting
77
99
  graphic_state.dash_setting
78
100
  end
79
-
101
+
80
102
  end
81
103
  end
82
104
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # encoding: utf-8
2
2
 
3
3
  # join_style.rb : Implements stroke join styling
4
4
  #
@@ -10,7 +10,9 @@ module Prawn
10
10
  module Graphics
11
11
  module JoinStyle
12
12
  JOIN_STYLES = { :miter => 0, :round => 1, :bevel => 2 }
13
-
13
+
14
+ # @group Stable API
15
+
14
16
  # Sets the join style for stroked lines and curves
15
17
  #
16
18
  # style is one of :miter, :round, or :bevel
@@ -25,19 +27,19 @@ module Prawn
25
27
 
26
28
  write_stroke_join_style
27
29
  end
28
-
30
+
29
31
  alias_method :join_style=, :join_style
30
32
 
31
33
  private
32
-
33
- def current_join_style
34
+
35
+ def current_join_style
34
36
  graphic_state.join_style
35
37
  end
36
38
 
37
- def current_join_style=(style)
39
+ def current_join_style=(style)
38
40
  graphic_state.join_style = style
39
41
  end
40
-
42
+
41
43
 
42
44
  def write_stroke_join_style
43
45
  add_content "#{JOIN_STYLES[current_join_style]} j"
@@ -10,19 +10,14 @@
10
10
  module Prawn
11
11
  module Graphics
12
12
  module Patterns
13
+ # @group Stable API
13
14
 
14
15
  # Sets the fill gradient from color1 to color2.
15
16
  # old arguments: point, width, height, color1, color2, options = {}
16
17
  # new arguments: from, to, color1, color1
17
18
  # or from, r1, to, r2, color1, color2
18
19
  def fill_gradient(*args)
19
- if args[1].is_a?(Array) || args[2].is_a?(Array)
20
- set_gradient(:fill, *args)
21
- else
22
- warn "[DEPRECATION] 'fill_gradient(point, width, height,...)' is deprecated in favor of 'fill_gradient(from, to,...)'. " +
23
- "Old arguments will be removed in release 1.1"
24
- set_gradient :fill, args[0], [args[0].first, args[0].last - args[2]], args[3], args[4]
25
- end
20
+ set_gradient(:fill, *args)
26
21
  end
27
22
 
28
23
  # Sets the stroke gradient from color1 to color2.
@@ -30,13 +25,7 @@ module Prawn
30
25
  # new arguments: from, to, color1, color2
31
26
  # or from, r1, to, r2, color1, color2
32
27
  def stroke_gradient(*args)
33
- if args[1].is_a?(Array) || args[2].is_a?(Array)
34
- set_gradient(:stroke, *args)
35
- else
36
- warn "[DEPRECATION] 'stroke_gradient(point, width, height,...)' is deprecated in favor of 'stroke_gradient(from, to,...)'. " +
37
- "Old arguments will be removed in release 1.1"
38
- set_gradient :stroke, args[0], [args[0].first, args[0].last - args[2]], args[3], args[4]
39
- end
28
+ set_gradient(:stroke, *args)
40
29
  end
41
30
 
42
31
  private
@@ -125,7 +114,7 @@ module Prawn
125
114
  :Extend => [true, true],
126
115
  })
127
116
 
128
- shading_pattern = ref!({
117
+ ref!({
129
118
  :PatternType => 2, # shading pattern
130
119
  :Shading => shading,
131
120
  :Matrix => [1, 0,
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  #
3
3
  # transformation.rb: Implements rotate, translate, skew, scale and a generic
4
- # transformation_matrix
4
+ # transformation_matrix
5
5
  #
6
6
  # Copyright January 2010, Michael Witrant. All Rights Reserved.
7
7
  #
@@ -10,7 +10,8 @@
10
10
  module Prawn
11
11
  module Graphics
12
12
  module Transformation
13
-
13
+ # @group Stable API
14
+
14
15
  # Rotate the user space. If a block is not provided, then you must save
15
16
  # and restore the graphics state yourself.
16
17
  #
@@ -22,7 +23,7 @@ module Prawn
22
23
  # provided, but no block is given
23
24
  #
24
25
  # Example without a block:
25
- #
26
+ #
26
27
  # save_graphics_state
27
28
  # rotate 30
28
29
  # text "rotated text"
@@ -62,7 +63,7 @@ module Prawn
62
63
  # and restore the graphics state yourself.
63
64
  #
64
65
  # Example without a block: move the text up and over 10
65
- #
66
+ #
66
67
  # save_graphics_state
67
68
  # translate(10, 10)
68
69
  # text "scaled text"
@@ -82,7 +83,7 @@ module Prawn
82
83
  def translate(x, y, &block)
83
84
  transformation_matrix(1, 0, 0, 1, x, y, &block)
84
85
  end
85
-
86
+
86
87
  # Scale the user space. If a block is not provided, then you must save
87
88
  # and restore the graphics state yourself.
88
89
  #
@@ -94,7 +95,7 @@ module Prawn
94
95
  # provided, but no block is given
95
96
  #
96
97
  # Example without a block:
97
- #
98
+ #
98
99
  # save_graphics_state
99
100
  # scale 1.5
100
101
  # text "scaled text"
@@ -126,7 +127,7 @@ module Prawn
126
127
  end
127
128
  end
128
129
  end
129
-
130
+
130
131
  # The following definition of skew would only work in a clearly
131
132
  # predicatable manner when if the document had no margin. don't provide
132
133
  # this shortcut until it behaves in a clearly understood manner
@@ -137,7 +138,7 @@ module Prawn
137
138
  # Math.tan(degree_to_rad(b)),
138
139
  # 1, 0, 0, &block)
139
140
  # end
140
-
141
+
141
142
  # Transform the user space (see notes for rotate regarding graphics state)
142
143
  # Generally, one would use the rotate, scale, translate, and skew
143
144
  # convenience methods instead of calling transformation_matrix directly
@@ -150,7 +151,7 @@ module Prawn
150
151
  restore_graphics_state
151
152
  end
152
153
  end
153
-
154
+
154
155
  end
155
156
  end
156
157
  end
@@ -30,6 +30,8 @@ module Prawn
30
30
  #
31
31
  module Transparency
32
32
 
33
+ # @group Stable API
34
+
33
35
  # Sets the <tt>opacity</tt> and <tt>stroke_opacity</tt> for all
34
36
  # the content within the <tt>block</tt>
35
37
  # If <tt>stroke_opacity</tt> is not provided, then it takes on
@@ -86,7 +88,7 @@ module Prawn
86
88
  )
87
89
 
88
90
  dictionary_name = "Tr#{next_opacity_dictionary_id}"
89
- opacity_dictionary_registry[key] = { :name => dictionary_name,
91
+ opacity_dictionary_registry[key] = { :name => dictionary_name,
90
92
  :obj => dictionary }
91
93
  end
92
94
 
@@ -1,15 +1,28 @@
1
+ # grid.rb: Provides a basic grid layout system for Prawn
2
+ #
3
+ # Contributed by Andrew O'Brien in March 2009
4
+ #
5
+ # This is free software. Please see the LICENSE and COPYING files for details.
6
+
1
7
  module Prawn
2
8
  class Document
3
-
4
- # Defines the grid system for a particular document. Takes the number of
5
- # rows and columns and the width to use for the gutter as the
9
+ # @group Experimental API
10
+
11
+ # Defines the grid system for a particular document. Takes the number of
12
+ # rows and columns and the width to use for the gutter as the
6
13
  # keys :rows, :columns, :gutter, :row_gutter, :column_gutter
7
14
  #
15
+ # Note that a completely new grid object is built each time define_grid()
16
+ # is called. This means that all subsequent calls to grid() will use
17
+ # the newly defined Grid object -- grids are not nestable like
18
+ # bounding boxes are.
19
+
8
20
  def define_grid(options = {})
21
+ @boxes = nil
9
22
  @grid = Grid.new(self, options)
10
23
  end
11
-
12
- # A method that can either be used to access a particular grid on the page
24
+
25
+ # A method that can either be used to access a particular grid on the page
13
26
  # or work with the grid system directly.
14
27
  #
15
28
  # @pdf.grid # Get the Grid directly
@@ -22,7 +35,7 @@ module Prawn
22
35
  @grid
23
36
  else
24
37
  g1, g2 = args
25
- if(g1.class == Array && g2.class == Array &&
38
+ if(g1.class == Array && g2.class == Array &&
26
39
  g1.length == 2 && g2.length == 2)
27
40
  multi_box(single_box(*g1), single_box(*g2))
28
41
  else
@@ -30,15 +43,17 @@ module Prawn
30
43
  end
31
44
  end
32
45
  end
33
-
34
- # A Grid represents the entire grid system of a Page and calculates
46
+
47
+ # A Grid represents the entire grid system of a Page and calculates
35
48
  # the column width and row height of the base box.
49
+ #
50
+ # @private
36
51
  class Grid
37
52
  attr_reader :pdf, :columns, :rows, :gutter, :row_gutter, :column_gutter
38
53
  def initialize(pdf, options = {}) # :nodoc:
39
54
  valid_options = [:columns, :rows, :gutter, :row_gutter, :column_gutter]
40
55
  Prawn.verify_options valid_options, options
41
-
56
+
42
57
  @pdf = pdf
43
58
  @columns = options[:columns]
44
59
  @rows = options[:rows]
@@ -49,7 +64,7 @@ module Prawn
49
64
  def column_width
50
65
  @column_width ||= subdivide(pdf.bounds.width, columns, column_gutter)
51
66
  end
52
-
67
+
53
68
  # Calculates the base height of boxes.
54
69
  def row_height
55
70
  @row_height ||= subdivide(pdf.bounds.height, rows, row_gutter)
@@ -65,11 +80,11 @@ module Prawn
65
80
  end
66
81
 
67
82
  private
68
-
83
+
69
84
  def subdivide(total, num, gutter)
70
85
  (total.to_f - (gutter * (num - 1).to_f)) / num.to_f
71
86
  end
72
-
87
+
73
88
  def set_gutter(options)
74
89
  if options.has_key?(:gutter)
75
90
  @gutter = options[:gutter].to_f
@@ -81,92 +96,93 @@ module Prawn
81
96
  end
82
97
  end
83
98
  end
84
-
85
- # A Box is a class that represents a bounded area of a page.
86
- # A Grid object has methods that allow easy access to the coordinates of
99
+
100
+ # A Box is a class that represents a bounded area of a page.
101
+ # A Grid object has methods that allow easy access to the coordinates of
87
102
  # its corners, which can be plugged into most existing prawnmethods.
88
103
  #
89
- class Box #:nodoc:
104
+ # @private
105
+ class GridBox
90
106
  attr_reader :pdf
91
-
107
+
92
108
  def initialize(pdf, i, j)
93
109
  @pdf = pdf
94
110
  @i = i
95
111
  @j = j
96
112
  end
97
-
98
- # Mostly diagnostic method that outputs the name of a box as
113
+
114
+ # Mostly diagnostic method that outputs the name of a box as
99
115
  # col_num, row_num
100
116
  #
101
117
  def name
102
118
  "#{@i.to_s},#{@j.to_s}"
103
119
  end
104
-
120
+
105
121
  # :nodoc
106
122
  def total_height
107
123
  pdf.bounds.height.to_f
108
124
  end
109
-
125
+
110
126
  # Width of a box
111
127
  def width
112
128
  grid.column_width.to_f
113
129
  end
114
-
130
+
115
131
  # Height of a box
116
132
  def height
117
133
  grid.row_height.to_f
118
134
  end
119
-
135
+
120
136
  # Width of the gutter
121
137
  def gutter
122
138
  grid.gutter.to_f
123
139
  end
124
-
140
+
125
141
  # x-coordinate of left side
126
142
  def left
127
143
  @left ||= (width + grid.column_gutter) * @j.to_f
128
144
  end
129
-
130
- # x-coordinate of right side
145
+
146
+ # x-coordinate of right side
131
147
  def right
132
148
  @right ||= left + width
133
149
  end
134
-
150
+
135
151
  # y-coordinate of the top
136
152
  def top
137
153
  @top ||= total_height - ((height + grid.row_gutter) * @i.to_f)
138
154
  end
139
-
155
+
140
156
  # y-coordinate of the bottom
141
157
  def bottom
142
158
  @bottom ||= top - height
143
159
  end
144
-
160
+
145
161
  # x,y coordinates of top left corner
146
162
  def top_left
147
163
  [left, top]
148
164
  end
149
-
150
- # x,y coordinates of top right corner
165
+
166
+ # x,y coordinates of top right corner
151
167
  def top_right
152
168
  [right, top]
153
169
  end
154
-
170
+
155
171
  # x,y coordinates of bottom left corner
156
172
  def bottom_left
157
173
  [left, bottom]
158
174
  end
159
-
175
+
160
176
  # x,y coordinates of bottom right corner
161
177
  def bottom_right
162
178
  [right, bottom]
163
179
  end
164
-
180
+
165
181
  # Creates a standard bounding box based on the grid box.
166
182
  def bounding_box(&blk)
167
183
  pdf.bounding_box(top_left, :width => width, :height => height, &blk)
168
184
  end
169
-
185
+
170
186
  # Diagnostic method
171
187
  def show(grid_color = "CCCCCC")
172
188
  self.bounding_box do
@@ -175,28 +191,30 @@ module Prawn
175
191
  pdf.stroke_color = grid_color
176
192
  pdf.text self.name
177
193
  pdf.stroke_bounds
178
-
194
+
179
195
  pdf.stroke_color = original_stroke_color
180
196
  end
181
197
  end
182
-
198
+
183
199
  private
184
200
  def grid
185
201
  pdf.grid
186
202
  end
187
203
  end
188
-
204
+
189
205
  # A MultiBox is specified by 2 Boxes and spans the areas between.
190
- class MultiBox < Box #:nodoc:
206
+ #
207
+ # @private
208
+ class MultiBox < GridBox #:nodoc:
191
209
  def initialize(pdf, b1, b2)
192
210
  @pdf = pdf
193
211
  @bs = [b1, b2]
194
212
  end
195
-
213
+
196
214
  def name
197
215
  @bs.map {|b| b.name}.join(":")
198
216
  end
199
-
217
+
200
218
  def total_height
201
219
  @bs[0].total_height
202
220
  end
@@ -204,54 +222,54 @@ module Prawn
204
222
  def width
205
223
  right_box.right - left_box.left
206
224
  end
207
-
225
+
208
226
  def height
209
227
  top_box.top - bottom_box.bottom
210
228
  end
211
-
229
+
212
230
  def gutter
213
231
  @bs[0].gutter
214
232
  end
215
-
233
+
216
234
  def left
217
235
  left_box.left
218
236
  end
219
-
237
+
220
238
  def right
221
239
  right_box.right
222
240
  end
223
-
241
+
224
242
  def top
225
243
  top_box.top
226
244
  end
227
-
245
+
228
246
  def bottom
229
247
  bottom_box.bottom
230
248
  end
231
-
249
+
232
250
  private
233
251
  def left_box
234
252
  @left_box ||= @bs.min {|a,b| a.left <=> b.left}
235
253
  end
236
-
254
+
237
255
  def right_box
238
256
  @right_box ||= @bs.max {|a,b| a.right <=> b.right}
239
257
  end
240
-
258
+
241
259
  def top_box
242
260
  @top_box ||= @bs.max {|a,b| a.top <=> b.top}
243
261
  end
244
-
262
+
245
263
  def bottom_box
246
264
  @bottom_box ||= @bs.min {|a,b| a.bottom <=> b.bottom}
247
265
  end
248
266
  end
249
-
267
+
250
268
  private
251
269
  def single_box(i, j)
252
- Box.new(self, i, j)
270
+ GridBox.new(self, i, j)
253
271
  end
254
-
272
+
255
273
  def multi_box(b1, b2)
256
274
  MultiBox.new(self, b1, b2)
257
275
  end