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
@@ -4,7 +4,7 @@
4
4
  # contents of palette and transparency to ensure they're correct.
5
5
  # Need to find files that have these sections first.
6
6
 
7
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
7
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
8
8
 
9
9
  describe "When reading a JPEG file" do
10
10
 
@@ -12,10 +12,10 @@ describe "When reading a JPEG file" do
12
12
  @filename = "#{Prawn::DATADIR}/images/pigs.jpg"
13
13
  @img_data = File.open(@filename, "rb") { |f| f.read }
14
14
  end
15
-
15
+
16
16
  it "should read the basic attributes correctly" do
17
17
  jpg = Prawn::Images::JPG.new(@img_data)
18
-
18
+
19
19
  jpg.width.should == 604
20
20
  jpg.height.should == 453
21
21
  jpg.bits.should == 8
@@ -5,8 +5,8 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
5
5
  describe "Core::Text::Formatted::LineWrap#wrap_line" do
6
6
  before(:each) do
7
7
  create_pdf
8
- @arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
9
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
8
+ @arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
9
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
10
10
  @one_word_width = 50
11
11
  end
12
12
  it "should strip leading and trailing spaces" do
@@ -113,11 +113,11 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
113
113
  :width => @one_word_width,
114
114
  :document => @pdf)
115
115
  expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
116
- expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
116
+ expected.force_encoding(Encoding::UTF_8)
117
117
  string.should == expected
118
118
 
119
119
  @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
120
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
120
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
121
121
 
122
122
  string = "hello#{Prawn::Text::SHY}world"
123
123
  array = [{ :text => string }]
@@ -138,7 +138,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
138
138
  string.should == "helloworld"
139
139
 
140
140
  @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
141
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
141
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
142
142
 
143
143
  string = "hello#{Prawn::Text::SHY}world"
144
144
  array = [{ :text => string }]
@@ -167,7 +167,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
167
167
  string.should == "hello"
168
168
 
169
169
  @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
170
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
170
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
171
171
  enough_width_for_hello_world = 68
172
172
 
173
173
  array = [{ :text => "hello world" }]
@@ -202,11 +202,11 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
202
202
  :width => @one_word_width,
203
203
  :document => @pdf)
204
204
  expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
205
- expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
205
+ expected.force_encoding(Encoding::UTF_8)
206
206
  string.should == expected
207
207
 
208
208
  @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
209
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
209
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
210
210
 
211
211
  string = "hello#{Prawn::Text::SHY}-"
212
212
  array = [{ :text => string }]
@@ -224,13 +224,24 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
224
224
  :document => @pdf)
225
225
  string.should == "hello#{Prawn::Text::SHY}"
226
226
  end
227
+
228
+ it "should process UTF-8 chars", :unresolved, :issue => 693 do
229
+ array = [{ :text => "Test" }]
230
+ @arranger.format_array = array
231
+
232
+ # Should not raise an encoding error
233
+ string = @line_wrap.wrap_line(:arranger => @arranger,
234
+ :width => 300,
235
+ :document => @pdf)
236
+ string.should == "Test"
237
+ end
227
238
  end
228
239
 
229
240
  describe "Core::Text::Formatted::LineWrap#space_count" do
230
241
  before(:each) do
231
242
  create_pdf
232
- @arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
233
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
243
+ @arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
244
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
234
245
  end
235
246
  it "should return the number of spaces in the last wrapped line" do
236
247
  array = [{ :text => "hello world, " },
@@ -255,7 +266,7 @@ end
255
266
  describe "Core::Text::Formatted::LineWrap" do
256
267
  before(:each) do
257
268
  create_pdf
258
- @arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
269
+ @arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
259
270
  array = [{ :text => "hello\nworld\n\n\nhow are you?" },
260
271
  { :text => "\n" },
261
272
  { :text => "\n" },
@@ -265,7 +276,7 @@ describe "Core::Text::Formatted::LineWrap" do
265
276
  { :text => "\n" },
266
277
  { :text => "" }]
267
278
  @arranger.format_array = array
268
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
279
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
269
280
  end
270
281
  it "should only return an empty string if nothing fit or there" +
271
282
  "was nothing to wrap" do
@@ -285,8 +296,8 @@ end
285
296
  describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
286
297
  before(:each) do
287
298
  create_pdf
288
- @arranger = Prawn::Core::Text::Formatted::Arranger.new(@pdf)
289
- @line_wrap = Prawn::Core::Text::Formatted::LineWrap.new
299
+ @arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
300
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
290
301
  @one_word_width = 50
291
302
  end
292
303
  it "should be_false when the last printed line is not the end of the paragraph" do
@@ -1,8 +1,8 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
2
2
  require "prawn/measurement_extensions"
3
3
 
4
4
  describe "Measurement units" do
5
-
5
+
6
6
  it "should convert units to PostScriptPoints" do
7
7
  1.mm.should be_within(0.000000001).of(2.834645669)
8
8
  1.mm.should == (72 / 25.4)
@@ -12,12 +12,12 @@ describe "Measurement units" do
12
12
  1.cm.should == 10 * 72 / 25.4
13
13
  1.dm.should == 100 * 72 / 25.4
14
14
  1.m.should == 1000 * 72 / 25.4
15
-
15
+
16
16
  1.in.should == 72
17
17
  1.ft.should == 72 * 12
18
18
  1.yd.should == 72 * 12 * 3
19
19
  1.pt.should == 1
20
20
  end
21
-
21
+
22
22
  end
23
-
23
+
@@ -16,20 +16,20 @@ describe "Outline" do
16
16
  end
17
17
  end
18
18
  end
19
- if RUBY_VERSION >= "1.9"
20
- describe "outline encoding" do
21
- it "should store all outline titles as UTF-16" do
22
- render_and_find_objects
23
- @hash.values.each do |obj|
24
- if obj.is_a?(Hash) && obj[:Title]
25
- title = obj[:Title].dup
26
- title.force_encoding("UTF-16LE")
27
- title.valid_encoding?.should == true
28
- end
19
+
20
+ describe "outline encoding" do
21
+ it "should store all outline titles as UTF-16" do
22
+ render_and_find_objects
23
+ @hash.values.each do |obj|
24
+ if obj.is_a?(Hash) && obj[:Title]
25
+ title = obj[:Title].dup
26
+ title.force_encoding(Encoding::UTF_16LE)
27
+ title.valid_encoding?.should == true
29
28
  end
30
29
  end
31
30
  end
32
31
  end
32
+
33
33
  describe "#generate_outline" do
34
34
  before(:each) do
35
35
  render_and_find_objects
@@ -87,6 +87,28 @@ describe "Outline" do
87
87
 
88
88
  end
89
89
 
90
+ describe "adding a custom destination" do
91
+ before(:each) do
92
+ @pdf.start_new_page
93
+ @pdf.text "Page 3 with a destination"
94
+ @pdf.add_dest('customdest', @pdf.dest_xyz(200, 200))
95
+ pdf = @pdf
96
+ @pdf.outline.update do
97
+ page :destination => pdf.dest_xyz(200, 200), :title => 'Custom Destination'
98
+ end
99
+ render_and_find_objects
100
+ end
101
+
102
+ it "should create an outline item" do
103
+ @custom_dest.should_not be_nil
104
+ end
105
+
106
+ it "should reference the custom destination" do
107
+ referenced_object(@custom_dest[:Dest].first).should == referenced_object(@pages.last)
108
+ end
109
+
110
+ end
111
+
90
112
  describe "addding a section later with outline#section" do
91
113
  before(:each) do
92
114
  @pdf.start_new_page
@@ -120,11 +142,11 @@ describe "Outline" do
120
142
  @outline_root[:Count].should == 5
121
143
  end
122
144
 
123
- end
124
-
125
- describe "#outline.add_subsection_to" do
145
+ end
146
+
147
+ describe "#outline.add_subsection_to" do
126
148
  context "positioned last" do
127
-
149
+
128
150
  before(:each) do
129
151
  @pdf.start_new_page
130
152
  @pdf.text "Page 3. An added subsection "
@@ -133,45 +155,45 @@ describe "Outline" do
133
155
  section 'Added SubSection', :destination => 3 do
134
156
  page :destination => 3, :title => 'Added Page 3'
135
157
  end
136
- end
158
+ end
137
159
  end
138
160
  render_and_find_objects
139
161
  end
140
-
162
+
141
163
  it "should add new outline items to document" do
142
164
  [@subsection, @added_page_3].each { |item| item.should_not be_nil}
143
165
  end
144
-
166
+
145
167
  it "should reset the last item for parent item dictionary" do
146
168
  referenced_object(@section_1[:First]).should == @page_1
147
169
  referenced_object(@section_1[:Last]).should == @subsection
148
170
  end
149
-
171
+
150
172
  it "should set the prev relation for the new subsection to its parent's old last item" do
151
173
  referenced_object(@subsection[:Prev]).should == @page_2
152
174
  end
153
-
154
-
175
+
176
+
155
177
  it "the subsection should become the next relation for its parent's old last item" do
156
178
  referenced_object(@page_2[:Next]).should == @subsection
157
179
  end
158
-
180
+
159
181
  it "should set the first relation for the new subsection" do
160
182
  referenced_object(@subsection[:First]).should == @added_page_3
161
183
  end
162
-
184
+
163
185
  it "should set the correct last relation of the added to section" do
164
186
  referenced_object(@subsection[:Last]).should == @added_page_3
165
187
  end
166
-
188
+
167
189
  it "should increase the count of root outline dictionary" do
168
190
  @outline_root[:Count].should == 5
169
191
  end
170
-
171
- end
172
-
192
+
193
+ end
194
+
173
195
  context "positioned first" do
174
-
196
+
175
197
  before(:each) do
176
198
  @pdf.start_new_page
177
199
  @pdf.text "Page 3. An added subsection "
@@ -193,7 +215,7 @@ describe "Outline" do
193
215
  referenced_object(@section_1[:First]).should == @subsection
194
216
  referenced_object(@section_1[:Last]).should == @page_2
195
217
  end
196
-
218
+
197
219
  it "should set the next relation for the new subsection to its parent's old first item" do
198
220
  referenced_object(@subsection[:Next]).should == @page_1
199
221
  end
@@ -215,7 +237,7 @@ describe "Outline" do
215
237
  end
216
238
 
217
239
  end
218
-
240
+
219
241
  it "should require an existing title" do
220
242
  lambda do
221
243
  @pdf.go_to_page 1
@@ -229,7 +251,7 @@ describe "Outline" do
229
251
  render_and_find_objects
230
252
  end.should raise_error(Prawn::Errors::UnknownOutlineTitle)
231
253
  end
232
- end
254
+ end
233
255
 
234
256
  describe "#outline.insert_section_after" do
235
257
  describe "inserting in the middle of another section" do
@@ -248,45 +270,45 @@ describe "Outline" do
248
270
  render_and_find_objects
249
271
  @inserted_page.should_not be_nil
250
272
  end
251
-
273
+
252
274
  it "should adjust the count of all ancestors" do
253
275
  render_and_find_objects
254
276
  @outline_root[:Count].should == 4
255
277
  @section_1[:Count].abs.should == 3
256
278
  end
257
-
279
+
258
280
  describe "#adjust_relations" do
259
-
281
+
260
282
  it "should reset the sibling relations of adjoining items to inserted item" do
261
283
  render_and_find_objects
262
284
  referenced_object(@page_1[:Next]).should == @inserted_page
263
285
  referenced_object(@page_2[:Prev]).should == @inserted_page
264
286
  end
265
-
287
+
266
288
  it "should set the sibling relation of added item to adjoining items" do
267
289
  render_and_find_objects
268
290
  referenced_object(@inserted_page[:Next]).should == @page_2
269
291
  referenced_object(@inserted_page[:Prev]).should == @page_1
270
292
  end
271
-
293
+
272
294
  it "should not affect the first and last relations of parent item" do
273
295
  render_and_find_objects
274
296
  referenced_object(@section_1[:First]).should == @page_1
275
297
  referenced_object(@section_1[:Last]).should == @page_2
276
298
  end
277
-
278
- end
279
-
280
-
281
- context "when adding another section afterwards" do
299
+
300
+ end
301
+
302
+
303
+ context "when adding another section afterwards" do
282
304
  it "should have reset the root position so that a new section is added at the end of root sections" do
283
305
  @pdf.start_new_page
284
306
  @pdf.text "Another Inserted Page"
285
307
  @pdf.outline.update do
286
308
  section 'Added Section' do
287
309
  page :destination => page_number, :title => "Inserted Page"
288
- end
289
- end
310
+ end
311
+ end
290
312
  render_and_find_objects
291
313
  referenced_object(@outline_root[:Last]).should == @section_2
292
314
  referenced_object(@section_1[:Next]).should == @section_2
@@ -305,7 +327,7 @@ describe "Outline" do
305
327
  @pdf.outline.update do
306
328
  insert_section_after 'Page 2' do
307
329
  page :destination => page_number, :title => "Inserted Page"
308
- end
330
+ end
309
331
  end
310
332
  render_and_find_objects
311
333
  end
@@ -357,7 +379,7 @@ describe "Outline" do
357
379
  end
358
380
  end
359
381
  end
360
-
382
+
361
383
  describe "foreign character encoding" do
362
384
  before(:each) do
363
385
  pdf = Prawn::Document.new() do
@@ -374,24 +396,6 @@ describe "foreign character encoding" do
374
396
  end
375
397
  end
376
398
 
377
- describe "with optimize_objects option" do
378
- before(:each) do
379
- @pdf = Prawn::Document.new(:optimize_objects => true) do
380
- outline.define do
381
- section 'Chapter 1', :destination => 1, :closed => true do
382
- page :destination => 1, :title => 'Page 1'
383
- end
384
- end
385
- end
386
- render_and_find_objects
387
- end
388
-
389
- it "should generate an outline" do
390
- @section_1.should_not be_nil
391
- @page_1.should_not be_nil
392
- end
393
- end
394
-
395
399
  def render_and_find_objects
396
400
  output = StringIO.new(@pdf.render, 'r+')
397
401
  @hash = PDF::Reader::ObjectHash.new(output)
@@ -402,9 +406,10 @@ def render_and_find_objects
402
406
  @page_2 = find_by_title('Page 2')
403
407
  @section_2 = find_by_title('Added Section')
404
408
  @page_3 = find_by_title('Page 3')
405
- @inserted_page = find_by_title('Inserted Page')
409
+ @inserted_page = find_by_title('Inserted Page')
406
410
  @subsection = find_by_title('Added SubSection')
407
411
  @added_page_3 = find_by_title('Added Page 3')
412
+ @custom_dest = find_by_title('Custom Destination')
408
413
  end
409
414
 
410
415
  # Outline titles are stored as UTF-16. This method accepts a UTF-8 outline title
@@ -423,4 +428,3 @@ end
423
428
  def referenced_object(reference)
424
429
  @hash[reference]
425
430
  end
426
-
@@ -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 = File.binread(@data_filename)
34
+ data = Zlib::Inflate.inflate(File.binread(@data_filename))
35
35
  png.img_data.should == data
36
36
  end
37
37
  end
@@ -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 = File.binread(@data_filename)
78
+ data = Zlib::Inflate.inflate(File.binread(@data_filename))
79
79
  png.img_data.should == data
80
80
  end
81
81
  end
@@ -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/rails.png"
107
- @data_filename = "#{Prawn::DATADIR}/images/rails.dat"
106
+ @filename = "#{Prawn::DATADIR}/images/indexed_color.png"
107
+ @data_filename = "#{Prawn::DATADIR}/images/indexed_color.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 == 50
115
- png.height.should == 64
114
+ png.width.should == 150
115
+ png.height.should == 200
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 = File.binread(@data_filename)
125
+ data = Zlib::Inflate.inflate(File.binread(@data_filename))
126
126
  png.img_data.should == data
127
127
  end
128
128
  end
@@ -131,7 +131,7 @@ describe "When reading a greyscale+alpha PNG file (color type 4)" do
131
131
 
132
132
  before(:each) do
133
133
  @filename = "#{Prawn::DATADIR}/images/page_white_text.png"
134
- @data_filename = "#{Prawn::DATADIR}/images/page_white_text.dat"
134
+ @color_data_filename = "#{Prawn::DATADIR}/images/page_white_text.color"
135
135
  @alpha_data_filename = "#{Prawn::DATADIR}/images/page_white_text.alpha"
136
136
  @img_data = File.binread(@filename)
137
137
  end
@@ -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(@data_filename)
154
+ data = File.binread(@color_data_filename)
155
155
  png.img_data.should == data
156
156
  end
157
157
 
@@ -167,7 +167,7 @@ describe "When reading an RGB+alpha PNG file (color type 6)" do
167
167
 
168
168
  before(:each) do
169
169
  @filename = "#{Prawn::DATADIR}/images/dice.png"
170
- @data_filename = "#{Prawn::DATADIR}/images/dice.dat"
170
+ @color_data_filename = "#{Prawn::DATADIR}/images/dice.color"
171
171
  @alpha_data_filename = "#{Prawn::DATADIR}/images/dice.alpha"
172
172
  @img_data = File.binread(@filename)
173
173
  end
@@ -187,18 +187,15 @@ 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(@data_filename)
191
- # compare decompressed rather than compressed image data
192
- # because JRuby's implementation of Zlib is different from MRI --
193
- # both generate valid gzipped data, but not bit-identical to each other
194
- Zlib::Inflate.inflate(png.img_data).should == Zlib::Inflate.inflate(data)
190
+ data = File.binread(@color_data_filename)
191
+ png.img_data.should == data
195
192
  end
196
193
 
197
194
  it "should correctly extract the alpha channel data from the image data chunk" do
198
195
  png = Prawn::Images::PNG.new(@img_data)
199
196
  png.split_alpha_channel!
200
197
  data = File.binread(@alpha_data_filename)
201
- Zlib::Inflate.inflate(png.alpha_channel).should == Zlib::Inflate.inflate(data)
198
+ png.alpha_channel.should == data
202
199
  end
203
200
  end
204
201
 
@@ -206,7 +203,7 @@ describe "When reading a 16bit RGB+alpha PNG file (color type 6)" do
206
203
 
207
204
  before(:each) do
208
205
  @filename = "#{Prawn::DATADIR}/images/16bit.png"
209
- @data_filename = "#{Prawn::DATADIR}/images/16bit.dat"
206
+ @color_data_filename = "#{Prawn::DATADIR}/images/16bit.color"
210
207
  # alpha channel truncated to 8-bit
211
208
  @alpha_data_filename = "#{Prawn::DATADIR}/images/16bit.alpha"
212
209
  @img_data = File.binread(@filename)
@@ -227,7 +224,7 @@ describe "When reading a 16bit RGB+alpha PNG file (color type 6)" do
227
224
  it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
228
225
  png = Prawn::Images::PNG.new(@img_data)
229
226
  png.split_alpha_channel!
230
- data = File.binread(@data_filename)
227
+ data = File.binread(@color_data_filename)
231
228
  png.img_data.should == data
232
229
  end
233
230