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
data/spec/png_spec.rb CHANGED
@@ -12,8 +12,8 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
12
12
  describe "When reading a greyscale PNG file (color type 0)" do
13
13
 
14
14
  before(:each) do
15
- @filename = "#{Prawn::DATADIR}/images/web-links.png"
16
- @data_filename = "#{Prawn::DATADIR}/images/web-links.dat"
15
+ @filename = "#{Prawn::BASEDIR}/data/images/web-links.png"
16
+ @data_filename = "#{Prawn::BASEDIR}/data/images/web-links.dat"
17
17
  @img_data = File.binread(@filename)
18
18
  end
19
19
 
@@ -31,7 +31,7 @@ describe "When reading a greyscale PNG file (color type 0)" do
31
31
 
32
32
  it "should read the image data chunk correctly" do
33
33
  png = Prawn::Images::PNG.new(@img_data)
34
- data = Zlib::Inflate.inflate(File.binread(@data_filename))
34
+ data = File.binread(@data_filename)
35
35
  png.img_data.should == data
36
36
  end
37
37
  end
@@ -39,7 +39,7 @@ end
39
39
  describe "When reading a greyscale PNG file with transparency (color type 0)" do
40
40
 
41
41
  before(:each) do
42
- @filename = "#{Prawn::DATADIR}/images/ruport_type0.png"
42
+ @filename = "#{Prawn::BASEDIR}/data/images/ruport_type0.png"
43
43
  @img_data = File.binread(@filename)
44
44
  end
45
45
 
@@ -56,8 +56,8 @@ end
56
56
  describe "When reading an RGB PNG file (color type 2)" do
57
57
 
58
58
  before(:each) do
59
- @filename = "#{Prawn::DATADIR}/images/ruport.png"
60
- @data_filename = "#{Prawn::DATADIR}/images/ruport_data.dat"
59
+ @filename = "#{Prawn::BASEDIR}/data/images/ruport.png"
60
+ @data_filename = "#{Prawn::BASEDIR}/data/images/ruport_data.dat"
61
61
  @img_data = File.binread(@filename)
62
62
  end
63
63
 
@@ -75,7 +75,7 @@ describe "When reading an RGB PNG file (color type 2)" do
75
75
 
76
76
  it "should read the image data chunk correctly" do
77
77
  png = Prawn::Images::PNG.new(@img_data)
78
- data = Zlib::Inflate.inflate(File.binread(@data_filename))
78
+ data = File.binread(@data_filename)
79
79
  png.img_data.should == data
80
80
  end
81
81
  end
@@ -83,7 +83,7 @@ end
83
83
  describe "When reading an RGB PNG file with transparency (color type 2)" do
84
84
 
85
85
  before(:each) do
86
- @filename = "#{Prawn::DATADIR}/images/arrow2.png"
86
+ @filename = "#{Prawn::BASEDIR}/data/images/arrow2.png"
87
87
  @img_data = File.binread(@filename)
88
88
  end
89
89
 
@@ -103,16 +103,16 @@ end
103
103
  describe "When reading an indexed color PNG file (color type 3)" do
104
104
 
105
105
  before(:each) do
106
- @filename = "#{Prawn::DATADIR}/images/indexed_color.png"
107
- @data_filename = "#{Prawn::DATADIR}/images/indexed_color.dat"
106
+ @filename = "#{Prawn::BASEDIR}/data/images/rails.png"
107
+ @data_filename = "#{Prawn::BASEDIR}/data/images/rails.dat"
108
108
  @img_data = File.binread(@filename)
109
109
  end
110
110
 
111
111
  it "should read the attributes from the header chunk correctly" do
112
112
  png = Prawn::Images::PNG.new(@img_data)
113
113
 
114
- png.width.should == 150
115
- png.height.should == 200
114
+ png.width.should == 50
115
+ png.height.should == 64
116
116
  png.bits.should == 8
117
117
  png.color_type.should == 3
118
118
  png.compression_method.should == 0
@@ -122,7 +122,7 @@ describe "When reading an indexed color PNG file (color type 3)" do
122
122
 
123
123
  it "should read the image data chunk correctly" do
124
124
  png = Prawn::Images::PNG.new(@img_data)
125
- data = Zlib::Inflate.inflate(File.binread(@data_filename))
125
+ data = File.binread(@data_filename)
126
126
  png.img_data.should == data
127
127
  end
128
128
  end
@@ -130,9 +130,9 @@ end
130
130
  describe "When reading a greyscale+alpha PNG file (color type 4)" do
131
131
 
132
132
  before(:each) do
133
- @filename = "#{Prawn::DATADIR}/images/page_white_text.png"
134
- @color_data_filename = "#{Prawn::DATADIR}/images/page_white_text.color"
135
- @alpha_data_filename = "#{Prawn::DATADIR}/images/page_white_text.alpha"
133
+ @filename = "#{Prawn::BASEDIR}/data/images/page_white_text.png"
134
+ @data_filename = "#{Prawn::BASEDIR}/data/images/page_white_text.dat"
135
+ @alpha_data_filename = "#{Prawn::BASEDIR}/data/images/page_white_text.alpha"
136
136
  @img_data = File.binread(@filename)
137
137
  end
138
138
 
@@ -151,7 +151,7 @@ describe "When reading a greyscale+alpha PNG file (color type 4)" do
151
151
  it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
152
152
  png = Prawn::Images::PNG.new(@img_data)
153
153
  png.split_alpha_channel!
154
- data = File.binread(@color_data_filename)
154
+ data = File.binread(@data_filename)
155
155
  png.img_data.should == data
156
156
  end
157
157
 
@@ -166,9 +166,9 @@ end
166
166
  describe "When reading an RGB+alpha PNG file (color type 6)" do
167
167
 
168
168
  before(:each) do
169
- @filename = "#{Prawn::DATADIR}/images/dice.png"
170
- @color_data_filename = "#{Prawn::DATADIR}/images/dice.color"
171
- @alpha_data_filename = "#{Prawn::DATADIR}/images/dice.alpha"
169
+ @filename = "#{Prawn::BASEDIR}/data/images/dice.png"
170
+ @data_filename = "#{Prawn::BASEDIR}/data/images/dice.dat"
171
+ @alpha_data_filename = "#{Prawn::BASEDIR}/data/images/dice.alpha"
172
172
  @img_data = File.binread(@filename)
173
173
  end
174
174
 
@@ -187,7 +187,7 @@ describe "When reading an RGB+alpha PNG file (color type 6)" do
187
187
  it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
188
188
  png = Prawn::Images::PNG.new(@img_data)
189
189
  png.split_alpha_channel!
190
- data = File.binread(@color_data_filename)
190
+ data = File.binread(@data_filename)
191
191
  png.img_data.should == data
192
192
  end
193
193
 
@@ -202,10 +202,10 @@ end
202
202
  describe "When reading a 16bit RGB+alpha PNG file (color type 6)" do
203
203
 
204
204
  before(:each) do
205
- @filename = "#{Prawn::DATADIR}/images/16bit.png"
206
- @color_data_filename = "#{Prawn::DATADIR}/images/16bit.color"
205
+ @filename = "#{Prawn::BASEDIR}/data/images/16bit.png"
206
+ @data_filename = "#{Prawn::BASEDIR}/data/images/16bit.dat"
207
207
  # alpha channel truncated to 8-bit
208
- @alpha_data_filename = "#{Prawn::DATADIR}/images/16bit.alpha"
208
+ @alpha_data_filename = "#{Prawn::BASEDIR}/data/images/16bit.alpha"
209
209
  @img_data = File.binread(@filename)
210
210
  end
211
211
 
@@ -224,7 +224,7 @@ describe "When reading a 16bit RGB+alpha PNG file (color type 6)" do
224
224
  it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
225
225
  png = Prawn::Images::PNG.new(@img_data)
226
226
  png.split_alpha_channel!
227
- data = File.binread(@color_data_filename)
227
+ data = File.binread(@data_filename)
228
228
  png.img_data.should == data
229
229
  end
230
230
 
@@ -3,10 +3,74 @@
3
3
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
4
 
5
5
  describe "A Reference object" do
6
+ it "should produce a PDF reference on #to_s call" do
7
+ ref = Prawn::Core::Reference(1,true)
8
+ ref.to_s.should == "1 0 R"
9
+ end
10
+
11
+ it "should allow changing generation number" do
12
+ ref = Prawn::Core::Reference(1,true)
13
+ ref.gen = 1
14
+ ref.to_s.should == "1 1 R"
15
+ end
16
+
17
+ it "should generate a valid PDF object for the referenced data" do
18
+ ref = Prawn::Core::Reference(2,[1,"foo"])
19
+ ref.object.should == "2 0 obj\n#{Prawn::Core::PdfObject([1,"foo"])}\nendobj\n"
20
+ end
21
+
22
+ it "should automatically open a stream when #<< is used" do
23
+ ref = Prawn::Core::Reference(1, :Length => 41)
24
+ ref << "BT\n/F1 12 Tf\n72 712 Td\n( A stream ) Tj\nET"
25
+ ref.object.should == "1 0 obj\n<< /Length 41\n>>\nstream"+
26
+ "\nBT\n/F1 12 Tf\n72 712 Td\n( A stream ) Tj\nET" +
27
+ "\nendstream\nendobj\n"
28
+ end
29
+
30
+ it "should compress a stream upon request" do
31
+ ref = Prawn::Core::Reference(2,{})
32
+ ref << "Hi There " * 20
33
+
34
+ cref = Prawn::Core::Reference(2,{})
35
+ cref << "Hi There " * 20
36
+ cref.compress_stream
37
+
38
+ assert cref.stream.size < ref.stream.size,
39
+ "compressed stream expected to be smaller than source but wasn't"
40
+ cref.data[:Filter].should == :FlateDecode
41
+ end
42
+
43
+ it "should copy the data and stream from another ref on #replace" do
44
+ from = Prawn::Core::Reference(3, {:foo => 'bar'})
45
+ from << "has a stream too"
46
+
47
+ to = Prawn::Core::Reference(4, {:foo => 'baz'})
48
+ to.replace from
49
+
50
+ # should preserve identifier but copy data and stream
51
+ to.identifier.should == 4
52
+ to.data.should == from.data
53
+ to.stream.should == from.stream
54
+ end
55
+
56
+ it "should copy a compressed stream from a compressed ref on #replace" do
57
+ from = Prawn::Core::Reference(5, {:foo => 'bar'})
58
+ from << "has a stream too " * 20
59
+ from.compress_stream
60
+
61
+ to = Prawn::Core::Reference(6, {:foo => 'baz'})
62
+ to.replace from
63
+
64
+ to.identifier.should == 6
65
+ to.data.should == from.data
66
+ to.stream.should == from.stream
67
+ to.compressed?.should == true
68
+ end
69
+
6
70
  describe "generated via Prawn::Document" do
7
71
  it "should return a proper reference on ref!" do
8
72
  pdf = Prawn::Document.new
9
- pdf.ref!({}).is_a?(PDF::Core::Reference).should == true
73
+ pdf.ref!({}).is_a?(Prawn::Core::Reference).should == true
10
74
  end
11
75
 
12
76
  it "should return an identifier on ref" do
@@ -14,12 +78,5 @@ describe "A Reference object" do
14
78
  r = pdf.ref({})
15
79
  r.is_a?(Integer).should == true
16
80
  end
17
-
18
- it "should have :Length of stream if it has one when compression disabled" do
19
- pdf = Prawn::Document.new :compress => false
20
- ref = pdf.ref!({})
21
- ref << 'Hello'
22
- ref.stream.data[:Length].should == 5
23
- end
24
81
  end
25
82
  end
@@ -10,14 +10,14 @@ describe "Repeaters" do
10
10
 
11
11
  r = repeater(doc, :all) { :do_nothing }
12
12
 
13
- Prawn::Repeater.count.should == orig_count + 1
13
+ assert_equal orig_count + 1, Prawn::Repeater.count
14
14
  end
15
15
 
16
16
  it "must provide an :all filter" do
17
17
  doc = sample_document
18
18
  r = repeater(doc, :all) { :do_nothing }
19
19
 
20
- (1..doc.page_count).all? { |i| r.match?(i) }.should be_true
20
+ assert (1..doc.page_count).all? { |i| r.match?(i) }
21
21
  end
22
22
 
23
23
  it "must provide an :odd filter" do
@@ -26,29 +26,29 @@ describe "Repeaters" do
26
26
 
27
27
  odd, even = (1..doc.page_count).partition { |e| e % 2 == 1 }
28
28
 
29
- odd.all? { |i| r.match?(i) }.should be_true
30
- even.any? { |i| r.match?(i) }.should be_false
29
+ assert odd.all? { |i| r.match?(i) }
30
+ assert ! even.any? { |i| r.match?(i) }
31
31
  end
32
32
 
33
33
  it "must be able to filter by an array of page numbers" do
34
34
  doc = sample_document
35
35
  r = repeater(doc, [1,2,7]) { :do_nothing }
36
36
 
37
- (1..10).select { |i| r.match?(i) }.should == [1,2,7]
37
+ assert_equal [1,2,7], (1..10).select { |i| r.match?(i) }
38
38
  end
39
39
 
40
40
  it "must be able to filter by a range of page numbers" do
41
41
  doc = sample_document
42
42
  r = repeater(doc, 2..4) { :do_nothing }
43
43
 
44
- (1..10).select { |i| r.match?(i) }.should == [2,3,4]
44
+ assert_equal [2,3,4], (1..10).select { |i| r.match?(i) }
45
45
  end
46
46
 
47
47
  it "must be able to filter by an arbitrary proc" do
48
48
  doc = sample_document
49
49
  r = repeater(doc, lambda { |x| x == 1 or x % 3 == 0 })
50
50
 
51
- (1..10).select { |i| r.match?(i) }.should == [1,3,6,9]
51
+ assert_equal [1,3,6,9], (1..10).select { |i| r.match?(i) }
52
52
  end
53
53
 
54
54
  it "must try to run a stamp if the page number matches" do
@@ -95,7 +95,7 @@ describe "Repeaters" do
95
95
  end
96
96
 
97
97
  text = PDF::Inspector::Text.analyze(doc.render)
98
- text.strings.should == (1..10).to_a.map{|p| "Page #{p}"}
98
+ assert_equal (1..10).to_a.map{|p| "Page #{p}"}, text.strings
99
99
  end
100
100
 
101
101
  it "must treat any block as a closure (Document.new instance_eval form)" do
@@ -110,7 +110,7 @@ describe "Repeaters" do
110
110
  end
111
111
 
112
112
  text = PDF::Inspector::Text.analyze(doc.render)
113
- text.strings.should == (1..10).to_a.map{|p| "Page #{p}"}
113
+ assert_equal (1..10).to_a.map{|p| "Page #{p}"}, text.strings
114
114
  end
115
115
 
116
116
  def sample_document
@@ -150,7 +150,7 @@ describe "Repeaters" do
150
150
  text.strings.include?("cap_style: round").should == false
151
151
  text.strings.include?("cap_style: butt").should == true
152
152
  end
153
-
153
+
154
154
  end
155
155
 
156
156
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "tempfile"
3
3
 
4
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
5
5
 
6
6
  describe "Document encryption" do
7
7
 
@@ -31,9 +31,9 @@ describe "Document encryption" do
31
31
  end
32
32
 
33
33
  end
34
-
34
+
35
35
  describe "Setting permissions" do
36
-
36
+
37
37
  def doc_with_permissions(permissions)
38
38
  pdf = Prawn::Document.new
39
39
 
@@ -66,10 +66,10 @@ describe "Document encryption" do
66
66
  should == 0b1111_1111_1111_1111_1111_1111_1101_1111
67
67
  end
68
68
 
69
- it "should raise_error ArgumentError if invalid option is provided" do
69
+ it "should raise ArgumentError if invalid option is provided" do
70
70
  lambda {
71
71
  doc_with_permissions(:modify_document => false)
72
- }.should raise_error(ArgumentError)
72
+ }.should.raise(ArgumentError)
73
73
  end
74
74
 
75
75
  end
@@ -89,7 +89,7 @@ describe "Document encryption" do
89
89
  end
90
90
 
91
91
  it "should calculate the correct owner hash" do
92
- @pdf.owner_password_hash.unpack("H*").first.should match(/^61CA855012/i)
92
+ @pdf.owner_password_hash.unpack("H*").first.should.match(/^61CA855012/i)
93
93
  end
94
94
 
95
95
  it "should calculate the correct user hash" do
@@ -106,53 +106,21 @@ describe "Document encryption" do
106
106
  describe "EncryptedPdfObject" do
107
107
 
108
108
  it "should delegate to PdfObject for simple types" do
109
- PDF::Core::EncryptedPdfObject(true, nil, nil, nil).should == "true"
110
- PDF::Core::EncryptedPdfObject(42, nil, nil, nil).should == "42"
109
+ Prawn::Core::EncryptedPdfObject(true, nil, nil, nil).should == "true"
110
+ Prawn::Core::EncryptedPdfObject(42, nil, nil, nil).should == "42"
111
111
  end
112
112
 
113
113
  it "should encrypt strings properly" do
114
- PDF::Core::EncryptedPdfObject("foo", "12345", 123, 0).should == "<4ad6e3>"
115
- end
116
-
117
- it "should encrypt literal strings properly" do
118
- PDF::Core::EncryptedPdfObject(PDF::Core::LiteralString.new("foo"), "12345", 123, 0).should == bin_string("(J\xD6\xE3)")
119
- PDF::Core::EncryptedPdfObject(PDF::Core::LiteralString.new("lhfbqg3do5u0satu3fjf"), nil, 123, 0).should == bin_string("(\xF1\x8B\\(\b\xBB\xE18S\x130~4*#\\(%\x87\xE7\x8E\\\n)")
120
- end
121
-
122
- it "should encrypt time properly" do
123
- PDF::Core::EncryptedPdfObject(Time.utc(2050, 04, 26, 10, 17, 10), "12345", 123, 0).should == bin_string("(h\x83\xBE\xDC\xEC\x99\x0F\xD7\\)%\x13\xD4$\xB8\xF0\x16\xB8\x80\xC5\xE91+\xCF)")
114
+ Prawn::Core::EncryptedPdfObject("foo", "12345", 123, 0).should == "<4ad6e3>"
124
115
  end
125
116
 
126
117
  it "should properly handle compound types" do
127
- PDF::Core::EncryptedPdfObject({:Bar => "foo"}, "12345", 123, 0).should ==
118
+ Prawn::Core::EncryptedPdfObject({:Bar => "foo"}, "12345", 123, 0).should ==
128
119
  "<< /Bar <4ad6e3>\n>>"
129
- PDF::Core::EncryptedPdfObject(["foo", "bar"], "12345", 123, 0).should ==
120
+ Prawn::Core::EncryptedPdfObject(["foo", "bar"], "12345", 123, 0).should ==
130
121
  "[<4ad6e3> <4ed8fe>]"
131
122
  end
132
-
133
- end
134
-
135
- describe "Reference#encrypted_object" do
136
- it "should encrypt references properly" do
137
- ref = PDF::Core::Reference(1,["foo"])
138
- ref.encrypted_object(nil).should == "1 0 obj\n[<4fca3f>]\nendobj\n"
139
- end
140
-
141
- it "should encrypt references with streams properly" do
142
- ref = PDF::Core::Reference(1, {})
143
- ref << 'foo'
144
- result = bin_string("1 0 obj\n<< /Length 3\n>>\nstream\nO\xCA?\nendstream\nendobj\n")
145
- ref.encrypted_object(nil).should == result
146
- end
147
- end
148
-
149
- describe "String#encrypted_object" do
150
- it "should encrypt stream properly" do
151
- stream = PDF::Core::Stream.new
152
- stream << "foo"
153
- result = bin_string("stream\nO\xCA?\nendstream\n")
154
- stream.encrypted_object(nil, 1, 0).should == result
155
- end
123
+
156
124
  end
157
125
 
158
126
  end
@@ -23,7 +23,7 @@ describe "Prawn::Document#transaction" do
23
23
  end
24
24
  text = PDF::Inspector::Text.analyze(pdf.render)
25
25
  text.strings.should == []
26
- end
26
+ end
27
27
 
28
28
  it "should return true/false value indicating success of the transaction" do
29
29
  Prawn::Document.new do
@@ -34,7 +34,7 @@ describe "Prawn::Document#transaction" do
34
34
  success.should == false
35
35
  end
36
36
  end
37
-
37
+
38
38
  it "should support nested transactions" do
39
39
  pdf = Prawn::Document.new do
40
40
  transaction do
@@ -76,7 +76,7 @@ describe "Prawn::Document#transaction" do
76
76
  rescue Prawn::Errors::CannotGroup
77
77
  add_lines(pdf)
78
78
  end
79
- end.should_not raise_error#(Prawn::Document::Snapshot::RollbackTransaction)
79
+ end.should.not.raise#(Prawn::Document::Snapshot::RollbackTransaction)
80
80
  end
81
81
  end
82
82
 
@@ -141,10 +141,10 @@ describe "Prawn::Document#transaction" do
141
141
  Prawn::Document.new do |pdf|
142
142
  pdf.add_dest("dest", pdf.dest_fit_horizontally(pdf.cursor, pdf.page))
143
143
  pdf.text("Hello world")
144
- lambda { pdf.transaction{} }.should_not raise_error
144
+ lambda { pdf.transaction{} }.should.not.raise
145
145
  end
146
146
  end
147
-
147
+
148
148
  describe "with a stamp dictionary present" do
149
149
 
150
150
  it "should properly commit if no error is raised" do
@@ -166,8 +166,8 @@ describe "Prawn::Document#transaction" do
166
166
  rollback
167
167
  end
168
168
  end
169
- pdf.render.should_not =~ /\/Stamp1 Do/
170
- end
169
+ pdf.render.should.not =~ /\/Stamp1 Do/
170
+ end
171
171
 
172
172
  end
173
173