prawn 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +2 -2
  3. data/Gemfile +18 -0
  4. data/LICENSE +1 -1
  5. data/README.md +17 -4
  6. data/Rakefile +18 -22
  7. data/data/images/indexed_color.dat +0 -0
  8. data/data/images/indexed_color.png +0 -0
  9. data/data/pdfs/nested_pages.pdf +13 -13
  10. data/lib/pdf/core.rb +35 -0
  11. data/lib/{prawn → pdf}/core/annotations.rb +6 -7
  12. data/lib/{prawn → pdf}/core/byte_string.rb +1 -1
  13. data/lib/{prawn → pdf}/core/destinations.rb +23 -23
  14. data/lib/{prawn → pdf}/core/document_state.rb +8 -8
  15. data/lib/pdf/core/filter_list.rb +51 -0
  16. data/lib/pdf/core/filters.rb +36 -0
  17. data/lib/pdf/core/graphics_state.rb +68 -0
  18. data/lib/{prawn → pdf}/core/literal_string.rb +1 -1
  19. data/lib/{prawn → pdf}/core/name_tree.rb +14 -2
  20. data/lib/{prawn → pdf}/core/object_store.rb +80 -24
  21. data/lib/pdf/core/outline.rb +315 -0
  22. data/lib/{prawn → pdf}/core/page.rb +23 -26
  23. data/lib/{prawn/document → pdf/core}/page_geometry.rb +11 -21
  24. data/lib/{prawn → pdf}/core/pdf_object.rb +48 -32
  25. data/lib/{prawn → pdf}/core/reference.rb +35 -44
  26. data/lib/pdf/core/stream.rb +98 -0
  27. data/lib/{prawn → pdf}/core/text.rb +24 -17
  28. data/lib/prawn.rb +95 -17
  29. data/lib/prawn/compatibility.rb +66 -26
  30. data/lib/prawn/document.rb +48 -30
  31. data/lib/prawn/document/bounding_box.rb +3 -3
  32. data/lib/prawn/document/column_box.rb +46 -8
  33. data/lib/prawn/document/graphics_state.rb +10 -73
  34. data/lib/prawn/document/internals.rb +24 -23
  35. data/lib/prawn/document/snapshot.rb +6 -7
  36. data/lib/prawn/document/span.rb +10 -10
  37. data/lib/prawn/encoding.rb +7 -7
  38. data/lib/prawn/errors.rb +18 -29
  39. data/lib/prawn/font.rb +64 -28
  40. data/lib/prawn/font/afm.rb +32 -74
  41. data/lib/prawn/font/dfont.rb +2 -2
  42. data/lib/prawn/font/ttf.rb +28 -57
  43. data/lib/prawn/font_metric_cache.rb +45 -0
  44. data/lib/prawn/graphics.rb +307 -41
  45. data/lib/prawn/graphics/cap_style.rb +3 -3
  46. data/lib/prawn/graphics/color.rb +12 -5
  47. data/lib/prawn/graphics/dash.rb +52 -31
  48. data/lib/prawn/graphics/join_style.rb +7 -7
  49. data/lib/prawn/graphics/patterns.rb +137 -0
  50. data/lib/prawn/graphics/transformation.rb +9 -9
  51. data/lib/prawn/graphics/transparency.rb +1 -1
  52. data/lib/prawn/image_handler.rb +30 -0
  53. data/lib/prawn/images.rb +86 -105
  54. data/lib/prawn/images/image.rb +48 -0
  55. data/lib/prawn/images/jpg.rb +14 -10
  56. data/lib/prawn/images/png.rb +50 -37
  57. data/lib/prawn/layout.rb +2 -2
  58. data/lib/prawn/layout/grid.rb +51 -51
  59. data/lib/prawn/measurement_extensions.rb +5 -5
  60. data/lib/prawn/measurements.rb +25 -21
  61. data/lib/prawn/outline.rb +4 -308
  62. data/lib/prawn/repeater.rb +8 -8
  63. data/lib/prawn/security.rb +50 -36
  64. data/lib/prawn/soft_mask.rb +94 -0
  65. data/lib/prawn/stamp.rb +3 -3
  66. data/lib/prawn/table.rb +292 -118
  67. data/lib/prawn/table/cell.rb +272 -45
  68. data/lib/prawn/table/cell/image.rb +70 -0
  69. data/lib/prawn/table/cell/in_table.rb +2 -2
  70. data/lib/prawn/table/cell/span_dummy.rb +92 -0
  71. data/lib/prawn/table/cell/subtable.rb +2 -2
  72. data/lib/prawn/table/cell/text.rb +42 -24
  73. data/lib/prawn/table/cells.rb +137 -48
  74. data/lib/prawn/text.rb +35 -23
  75. data/lib/prawn/text/box.rb +18 -5
  76. data/lib/prawn/text/formatted.rb +5 -4
  77. data/lib/prawn/text/formatted/arranger.rb +292 -0
  78. data/lib/prawn/text/formatted/box.rb +52 -13
  79. data/lib/prawn/text/formatted/fragment.rb +37 -22
  80. data/lib/prawn/text/formatted/line_wrap.rb +286 -0
  81. data/lib/prawn/text/formatted/parser.rb +14 -6
  82. data/lib/prawn/text/formatted/wrap.rb +151 -0
  83. data/lib/prawn/utilities.rb +44 -0
  84. data/manual/basic_concepts/adding_pages.rb +27 -0
  85. data/manual/basic_concepts/basic_concepts.rb +34 -0
  86. data/manual/basic_concepts/creation.rb +39 -0
  87. data/manual/basic_concepts/cursor.rb +33 -0
  88. data/manual/basic_concepts/measurement.rb +25 -0
  89. data/manual/basic_concepts/origin.rb +38 -0
  90. data/manual/basic_concepts/other_cursor_helpers.rb +40 -0
  91. data/manual/bounding_box/bounding_box.rb +39 -0
  92. data/manual/bounding_box/bounds.rb +49 -0
  93. data/manual/bounding_box/canvas.rb +24 -0
  94. data/manual/bounding_box/creation.rb +23 -0
  95. data/manual/bounding_box/indentation.rb +46 -0
  96. data/manual/bounding_box/nesting.rb +45 -0
  97. data/manual/bounding_box/russian_boxes.rb +40 -0
  98. data/manual/bounding_box/stretchy.rb +31 -0
  99. data/manual/document_and_page_options/background.rb +27 -0
  100. data/manual/document_and_page_options/document_and_page_options.rb +31 -0
  101. data/manual/document_and_page_options/metadata.rb +23 -0
  102. data/manual/document_and_page_options/page_margins.rb +38 -0
  103. data/manual/document_and_page_options/page_size.rb +34 -0
  104. data/manual/example_file.rb +116 -0
  105. data/manual/example_helper.rb +411 -0
  106. data/manual/example_package.rb +53 -0
  107. data/manual/example_section.rb +46 -0
  108. data/manual/graphics/circle_and_ellipse.rb +22 -0
  109. data/manual/graphics/color.rb +24 -0
  110. data/manual/graphics/common_lines.rb +28 -0
  111. data/manual/graphics/fill_and_stroke.rb +42 -0
  112. data/manual/graphics/fill_rules.rb +37 -0
  113. data/manual/graphics/gradients.rb +37 -0
  114. data/manual/graphics/graphics.rb +58 -0
  115. data/manual/graphics/helper.rb +24 -0
  116. data/manual/graphics/line_width.rb +35 -0
  117. data/manual/graphics/lines_and_curves.rb +41 -0
  118. data/manual/graphics/polygon.rb +29 -0
  119. data/manual/graphics/rectangle.rb +21 -0
  120. data/manual/graphics/rotate.rb +28 -0
  121. data/manual/graphics/scale.rb +41 -0
  122. data/manual/graphics/soft_masks.rb +46 -0
  123. data/manual/graphics/stroke_cap.rb +31 -0
  124. data/manual/graphics/stroke_dash.rb +48 -0
  125. data/manual/graphics/stroke_join.rb +30 -0
  126. data/manual/graphics/translate.rb +29 -0
  127. data/manual/graphics/transparency.rb +35 -0
  128. data/manual/images/absolute_position.rb +23 -0
  129. data/manual/images/fit.rb +21 -0
  130. data/manual/images/horizontal.rb +25 -0
  131. data/manual/images/images.rb +40 -0
  132. data/manual/images/plain_image.rb +18 -0
  133. data/manual/images/scale.rb +22 -0
  134. data/manual/images/vertical.rb +28 -0
  135. data/manual/images/width_and_height.rb +25 -0
  136. data/manual/layout/boxes.rb +27 -0
  137. data/manual/layout/content.rb +25 -0
  138. data/manual/layout/layout.rb +28 -0
  139. data/manual/layout/simple_grid.rb +23 -0
  140. data/manual/manual/cover.rb +35 -0
  141. data/manual/manual/foreword.rb +85 -0
  142. data/manual/manual/how_to_read_this_manual.rb +41 -0
  143. data/manual/manual/manual.rb +35 -0
  144. data/manual/outline/add_subsection_to.rb +61 -0
  145. data/manual/outline/insert_section_after.rb +47 -0
  146. data/manual/outline/outline.rb +32 -0
  147. data/manual/outline/sections_and_pages.rb +67 -0
  148. data/manual/repeatable_content/page_numbering.rb +54 -0
  149. data/manual/repeatable_content/repeatable_content.rb +31 -0
  150. data/manual/repeatable_content/repeater.rb +55 -0
  151. data/manual/repeatable_content/stamp.rb +41 -0
  152. data/manual/security/encryption.rb +31 -0
  153. data/manual/security/permissions.rb +38 -0
  154. data/manual/security/security.rb +28 -0
  155. data/manual/syntax_highlight.rb +52 -0
  156. data/manual/table/basic_block.rb +53 -0
  157. data/manual/table/before_rendering_page.rb +26 -0
  158. data/manual/table/cell_border_lines.rb +24 -0
  159. data/manual/table/cell_borders_and_bg.rb +31 -0
  160. data/manual/table/cell_dimensions.rb +30 -0
  161. data/manual/table/cell_text.rb +38 -0
  162. data/manual/table/column_widths.rb +30 -0
  163. data/manual/table/content_and_subtables.rb +39 -0
  164. data/manual/table/creation.rb +27 -0
  165. data/manual/table/filtering.rb +36 -0
  166. data/manual/table/flow_and_header.rb +17 -0
  167. data/manual/table/image_cells.rb +33 -0
  168. data/manual/table/position.rb +29 -0
  169. data/manual/table/row_colors.rb +20 -0
  170. data/manual/table/span.rb +30 -0
  171. data/manual/table/style.rb +22 -0
  172. data/manual/table/table.rb +52 -0
  173. data/manual/table/width.rb +27 -0
  174. data/manual/templates/full_template.rb +25 -0
  175. data/manual/templates/page_template.rb +48 -0
  176. data/manual/templates/templates.rb +27 -0
  177. data/manual/text/alignment.rb +44 -0
  178. data/manual/text/color.rb +24 -0
  179. data/manual/text/column_box.rb +32 -0
  180. data/manual/text/fallback_fonts.rb +37 -0
  181. data/manual/text/font.rb +41 -0
  182. data/manual/text/font_size.rb +45 -0
  183. data/manual/text/font_style.rb +23 -0
  184. data/manual/text/formatted_callbacks.rb +60 -0
  185. data/manual/text/formatted_text.rb +54 -0
  186. data/manual/text/free_flowing_text.rb +51 -0
  187. data/manual/text/group.rb +29 -0
  188. data/manual/text/inline.rb +43 -0
  189. data/manual/text/kerning_and_character_spacing.rb +39 -0
  190. data/manual/text/leading.rb +25 -0
  191. data/manual/text/line_wrapping.rb +41 -0
  192. data/manual/text/paragraph_indentation.rb +26 -0
  193. data/manual/text/positioned_text.rb +38 -0
  194. data/manual/text/registering_families.rb +48 -0
  195. data/manual/text/rendering_and_color.rb +37 -0
  196. data/manual/text/right_to_left_text.rb +43 -0
  197. data/manual/text/rotation.rb +43 -0
  198. data/manual/text/single_usage.rb +37 -0
  199. data/manual/text/text.rb +75 -0
  200. data/manual/text/text_box_excess.rb +32 -0
  201. data/manual/text/text_box_extensions.rb +45 -0
  202. data/manual/text/text_box_overflow.rb +44 -0
  203. data/manual/text/utf8.rb +28 -0
  204. data/{examples/m17n → manual/text}/win_ansi_charset.rb +14 -10
  205. data/prawn.gemspec +18 -12
  206. data/spec/acceptance/png.rb +23 -0
  207. data/spec/annotations_spec.rb +16 -32
  208. data/spec/bounding_box_spec.rb +128 -15
  209. data/spec/cell_spec.rb +169 -38
  210. data/spec/column_box_spec.rb +33 -0
  211. data/spec/destinations_spec.rb +5 -5
  212. data/spec/document_spec.rb +150 -104
  213. data/spec/extensions/encoding_helpers.rb +10 -0
  214. data/spec/extensions/mocha.rb +1 -0
  215. data/spec/filters_spec.rb +34 -0
  216. data/spec/font_metric_cache_spec.rb +52 -0
  217. data/spec/font_spec.rb +183 -97
  218. data/spec/formatted_text_arranger_spec.rb +43 -43
  219. data/spec/formatted_text_box_spec.rb +30 -20
  220. data/spec/formatted_text_fragment_spec.rb +8 -8
  221. data/spec/graphics_spec.rb +158 -69
  222. data/spec/grid_spec.rb +15 -15
  223. data/spec/image_handler_spec.rb +42 -0
  224. data/spec/images_spec.rb +49 -24
  225. data/spec/inline_formatted_text_parser_spec.rb +73 -19
  226. data/spec/jpg_spec.rb +4 -4
  227. data/spec/line_wrap_spec.rb +26 -26
  228. data/spec/measurement_units_spec.rb +6 -6
  229. data/spec/name_tree_spec.rb +21 -21
  230. data/spec/object_store_spec.rb +39 -39
  231. data/spec/outline_spec.rb +93 -53
  232. data/spec/pdf_object_spec.rb +88 -86
  233. data/spec/png_spec.rb +31 -28
  234. data/spec/reference_spec.rb +32 -32
  235. data/spec/repeater_spec.rb +25 -11
  236. data/spec/security_spec.rb +44 -12
  237. data/spec/snapshot_spec.rb +8 -9
  238. data/spec/soft_mask_spec.rb +117 -0
  239. data/spec/span_spec.rb +10 -15
  240. data/spec/spec_helper.rb +25 -8
  241. data/spec/stamp_spec.rb +29 -30
  242. data/spec/stream_spec.rb +58 -0
  243. data/spec/stroke_styles_spec.rb +36 -18
  244. data/spec/table/span_dummy_spec.rb +17 -0
  245. data/spec/table_spec.rb +697 -105
  246. data/spec/template_spec.rb +108 -54
  247. data/spec/text_at_spec.rb +18 -17
  248. data/spec/text_box_spec.rb +111 -62
  249. data/spec/text_rendering_mode_spec.rb +5 -5
  250. data/spec/text_spacing_spec.rb +4 -4
  251. data/spec/text_spec.rb +57 -49
  252. data/spec/transparency_spec.rb +5 -5
  253. metadata +421 -213
  254. data/data/fonts/Action Man.dfont +0 -0
  255. data/data/fonts/Activa.ttf +0 -0
  256. data/data/fonts/Chalkboard.ttf +0 -0
  257. data/data/fonts/DejaVuSans.ttf +0 -0
  258. data/data/fonts/Dustismo_Roman.ttf +0 -0
  259. data/data/fonts/comicsans.ttf +0 -0
  260. data/data/fonts/gkai00mp.ttf +0 -0
  261. data/data/images/rails.dat +0 -0
  262. data/data/images/rails.png +0 -0
  263. data/examples/bounding_box/russian_boxes.rb +0 -37
  264. data/examples/example_helper.rb +0 -11
  265. data/examples/general/context_sensitive_headers.rb +0 -38
  266. data/examples/graphics/cmyk.rb +0 -13
  267. data/examples/graphics/gradient.rb +0 -23
  268. data/examples/graphics/png_types.rb +0 -23
  269. data/examples/graphics/remote_images.rb +0 -13
  270. data/examples/m17n/full_win_ansi_character_list.rb +0 -20
  271. data/examples/m17n/sjis.rb +0 -29
  272. data/examples/table/bill.rb +0 -54
  273. data/examples/table/header.rb +0 -15
  274. data/examples/text/font_calculations.rb +0 -92
  275. data/examples/text/hyphenation.rb +0 -45
  276. data/examples/text/indent_paragraphs.rb +0 -24
  277. data/lib/prawn/core.rb +0 -85
  278. data/lib/prawn/core/text/formatted/arranger.rb +0 -294
  279. data/lib/prawn/core/text/formatted/line_wrap.rb +0 -273
  280. data/lib/prawn/core/text/formatted/wrap.rb +0 -153
  281. data/lib/prawn/graphics/gradient.rb +0 -84
  282. data/lib/prawn/security/arcfour.rb +0 -51
@@ -1,46 +1,46 @@
1
1
  # encoding: utf-8
2
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
2
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
3
3
 
4
4
  describe "A document's grid" do
5
5
  before do
6
6
  @pdf = Prawn::Document.new
7
7
  end
8
-
8
+
9
9
  it "should allow definition of a grid" do
10
10
  @pdf.define_grid(:columns => 5, :rows => 8, :gutter => 0.1)
11
11
  @pdf.grid.columns.should == 5
12
12
  @pdf.grid.rows.should == 8
13
13
  @pdf.grid.gutter.should == 0.1
14
14
  end
15
-
15
+
16
16
  describe "when a grid is defined" do
17
17
  before do
18
18
  @num_columns = 5
19
19
  @num_rows = 8
20
20
  @gutter = 10.0
21
21
  @pdf.define_grid(
22
- :columns => @num_columns,
23
- :rows => @num_rows,
22
+ :columns => @num_columns,
23
+ :rows => @num_rows,
24
24
  :gutter => @gutter
25
25
  )
26
26
  end
27
-
27
+
28
28
  it "should compute the column width" do
29
- (@pdf.grid.column_width * @num_columns.to_f +
29
+ (@pdf.grid.column_width * @num_columns.to_f +
30
30
  @gutter * (@num_columns - 1).to_f).should == @pdf.bounds.width
31
31
  end
32
-
32
+
33
33
  it "should compute the row height" do
34
- (@pdf.grid.row_height * @num_rows.to_f +
34
+ (@pdf.grid.row_height * @num_rows.to_f +
35
35
  @gutter * (@num_rows - 1).to_f).should == @pdf.bounds.height
36
36
  end
37
37
 
38
38
  it "should give the edges of a grid box" do
39
- grid_width = (@pdf.bounds.width.to_f -
39
+ grid_width = (@pdf.bounds.width.to_f -
40
40
  (@gutter * (@num_columns - 1).to_f )) / @num_columns.to_f
41
- grid_height = (@pdf.bounds.height.to_f -
41
+ grid_height = (@pdf.bounds.height.to_f -
42
42
  (@gutter * (@num_rows - 1).to_f ))/ @num_rows.to_f
43
-
43
+
44
44
  exp_tl_x = (grid_width + @gutter.to_f) * 4.0
45
45
  exp_tl_y = @pdf.bounds.height.to_f - (grid_height + @gutter.to_f)
46
46
 
@@ -62,9 +62,9 @@ describe "A document's grid" do
62
62
  @pdf.grid.show_all('cccccc')
63
63
 
64
64
  colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
65
- colors.fill_color.should.not == [0.8,0.8,0.8]
66
- colors.stroke_color.should.not == [0.8,0.8,0.8]
67
-
65
+ colors.fill_color.should_not == [0.8,0.8,0.8]
66
+ colors.stroke_color.should_not == [0.8,0.8,0.8]
67
+
68
68
  # Hardcoded default color as I haven't been able to come up with a stable converter
69
69
  # between fill_color without lots code.
70
70
  #colors.fill_color.should == [0.0,0.0,0.0]
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
+
5
+ describe "ImageHandler" do
6
+ let(:image_handler) { Prawn::ImageHandler.new }
7
+
8
+ let(:handler_a) { mock("Handler A") }
9
+ let(:handler_b) { mock("Handler B") }
10
+
11
+ it "finds the image handler for an image" do
12
+ handler_a.expects(:can_render? => true)
13
+
14
+ image_handler.register(handler_a)
15
+ image_handler.register(handler_b)
16
+
17
+ handler = image_handler.find("arbitrary blob")
18
+ handler.should == handler_a
19
+ end
20
+
21
+ it "can prepend handlers" do
22
+ handler_b.expects(:can_render? => true)
23
+
24
+ image_handler.register(handler_a)
25
+ image_handler.register!(handler_b)
26
+
27
+ handler = image_handler.find("arbitrary blob")
28
+ handler.should == handler_b
29
+ end
30
+
31
+ it "raises an error when no matching handler is found" do
32
+ handler_a.expects(:can_render? => false)
33
+ handler_b.expects(:can_render? => false)
34
+
35
+ image_handler.register(handler_a)
36
+ image_handler.register(handler_b)
37
+
38
+ expect { image_handler.find("arbitrary blob") }.
39
+ to(raise_error(Prawn::Errors::UnsupportedImageType))
40
+ end
41
+
42
+ end
@@ -1,40 +1,48 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
4
  require 'set'
5
5
  require 'pathname'
6
6
 
7
7
  describe "the image() function" do
8
8
 
9
9
  before(:each) do
10
- @filename = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
10
+ @filename = "#{Prawn::DATADIR}/images/pigs.jpg"
11
11
  create_pdf
12
12
  end
13
13
 
14
14
  it "should only embed an image once, even if it's added multiple times" do
15
15
  @pdf.image @filename, :at => [100,100]
16
16
  @pdf.image @filename, :at => [300,300]
17
-
17
+
18
18
  output = @pdf.render
19
19
  images = PDF::Inspector::XObject.analyze(output)
20
20
  # there should be 2 images in the page resources
21
21
  images.page_xobjects.first.size.should == 2
22
22
  # but only 1 image xobject
23
23
  output.scan(/\/Type \/XObject/).size.should == 1
24
- end
25
-
24
+ end
25
+
26
26
  it "should return the image info object" do
27
27
  info = @pdf.image(@filename)
28
-
29
- info.should.be.kind_of(Prawn::Images::JPG)
30
-
28
+
29
+ info.should be_a_kind_of(Prawn::Images::JPG)
30
+
31
31
  info.height.should == 453
32
32
  end
33
-
33
+
34
34
  it "should accept IO objects" do
35
35
  file = File.open(@filename, "rb")
36
36
  info = @pdf.image(file)
37
-
37
+
38
+ info.height.should == 453
39
+ end
40
+
41
+ it "rewinds IO objects to be able to embed them multiply" do
42
+ file = File.open(@filename, "rb")
43
+
44
+ @pdf.image(file)
45
+ info = @pdf.image(file)
38
46
  info.height.should == 453
39
47
  end
40
48
 
@@ -43,18 +51,35 @@ describe "the image() function" do
43
51
  info.height.should == 453
44
52
  end
45
53
 
46
- it "should raise an UnsupportedImageType if passed a BMP" do
47
- filename = "#{Prawn::BASEDIR}/data/images/tru256.bmp"
48
- lambda { @pdf.image filename, :at => [100,100] }.should.raise(Prawn::Errors::UnsupportedImageType)
54
+ context "setting the length of the bytestream" do
55
+ it "should correctly work with images from Pathname objects" do
56
+ info = @pdf.image(Pathname.new(@filename))
57
+ expect(@pdf).to have_parseable_xobjects
58
+ end
59
+
60
+ it "should correctly work with images from IO objects" do
61
+ info = @pdf.image(File.open(@filename, 'rb'))
62
+ expect(@pdf).to have_parseable_xobjects
63
+ end
64
+
65
+ it "should correctly work with images from IO objects not set to mode rb" do
66
+ info = @pdf.image(File.open(@filename, 'r'))
67
+ expect(@pdf).to have_parseable_xobjects
68
+ end
69
+ end
70
+
71
+ it "should raise_error an UnsupportedImageType if passed a BMP" do
72
+ filename = "#{Prawn::DATADIR}/images/tru256.bmp"
73
+ lambda { @pdf.image filename, :at => [100,100] }.should raise_error(Prawn::Errors::UnsupportedImageType)
49
74
  end
50
75
 
51
- it "should raise an UnsupportedImageType if passed an interlaced PNG" do
52
- filename = "#{Prawn::BASEDIR}/data/images/dice_interlaced.png"
53
- lambda { @pdf.image filename, :at => [100,100] }.should.raise(Prawn::Errors::UnsupportedImageType)
76
+ it "should raise_error an UnsupportedImageType if passed an interlaced PNG" do
77
+ filename = "#{Prawn::DATADIR}/images/dice_interlaced.png"
78
+ lambda { @pdf.image filename, :at => [100,100] }.should raise_error(Prawn::Errors::UnsupportedImageType)
54
79
  end
55
80
 
56
81
  it "should bump PDF version to 1.5 or greater on embedding 16-bit PNGs" do
57
- @pdf.image "#{Prawn::BASEDIR}/data/images/16bit.png"
82
+ @pdf.image "#{Prawn::DATADIR}/images/16bit.png"
58
83
  @pdf.state.version.should >= 1.5
59
84
  end
60
85
 
@@ -63,31 +88,31 @@ describe "the image() function" do
63
88
  # or anything. OS X Preview handles those files just fine.
64
89
  #
65
90
  it "should embed 8-bit alpha channels for 16-bit PNGs" do
66
- @pdf.image "#{Prawn::BASEDIR}/data/images/16bit.png"
91
+ @pdf.image "#{Prawn::DATADIR}/images/16bit.png"
67
92
 
68
93
  output = @pdf.render
69
94
  output.should =~ /\/BitsPerComponent 16/
70
95
  output.should =~ /\/BitsPerComponent 8/
71
96
  end
72
-
97
+
73
98
  it "should flow an image to a new page if it will not fit on a page" do
74
99
  @pdf.image @filename, :fit => [600, 600]
75
100
  @pdf.image @filename, :fit => [600, 600]
76
101
  output = StringIO.new(@pdf.render, 'r+')
77
102
  hash = PDF::Reader::ObjectHash.new(output)
78
103
  pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
79
- pages.size.should == 2
104
+ pages.size.should == 2
80
105
  hash[pages[0]][:Resources][:XObject].keys.should == [:I1]
81
106
  hash[pages[1]][:Resources][:XObject].keys.should == [:I2]
82
- end
83
-
107
+ end
108
+
84
109
  it "should not flow an image to a new page if it will fit on one page" do
85
110
  @pdf.image @filename, :fit => [400, 400]
86
111
  @pdf.image @filename, :fit => [400, 400]
87
112
  output = StringIO.new(@pdf.render, 'r+')
88
113
  hash = PDF::Reader::ObjectHash.new(output)
89
114
  pages = hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
90
- pages.size.should == 1
115
+ pages.size.should == 1
91
116
  Set.new(hash[pages[0]][:Resources][:XObject].keys).should ==
92
117
  Set.new([:I1, :I2])
93
118
  end
@@ -98,7 +123,7 @@ describe "the image() function" do
98
123
  @pdf.image @filename
99
124
  end
100
125
  end
101
-
126
+
102
127
  describe ":fit option" do
103
128
  it "should fit inside the defined constraints" do
104
129
  info = @pdf.image @filename, :fit => [100,400]
@@ -1,135 +1,159 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
3
3
 
4
- describe "Text::Formatted::Parser#to_array" do
4
+ describe "Text::Formatted::Parser#format" do
5
5
  it "should handle sup" do
6
6
  string = "<sup>superscript</sup>"
7
- array = Prawn::Text::Formatted::Parser.to_array(string)
7
+ array = Prawn::Text::Formatted::Parser.format(string)
8
8
  array[0].should == { :text => "superscript",
9
9
  :styles => [:superscript],
10
10
  :color => nil,
11
11
  :link => nil,
12
12
  :anchor => nil,
13
+ :local => nil,
13
14
  :font => nil,
14
15
  :size => nil,
15
16
  :character_spacing => nil }
16
17
  end
17
18
  it "should handle sub" do
18
19
  string = "<sub>subscript</sub>"
19
- array = Prawn::Text::Formatted::Parser.to_array(string)
20
+ array = Prawn::Text::Formatted::Parser.format(string)
20
21
  array[0].should == { :text => "subscript",
21
22
  :styles => [:subscript],
22
23
  :color => nil,
23
24
  :link => nil,
24
25
  :anchor => nil,
26
+ :local => nil,
25
27
  :font => nil,
26
28
  :size => nil,
27
29
  :character_spacing => nil }
28
30
  end
29
31
  it "should handle rgb" do
30
32
  string = "<color rgb='#ff0000'>red text</color>"
31
- array = Prawn::Text::Formatted::Parser.to_array(string)
33
+ array = Prawn::Text::Formatted::Parser.format(string)
32
34
  array[0].should == { :text => "red text",
33
35
  :styles => [],
34
36
  :color => "ff0000",
35
37
  :link => nil,
36
38
  :anchor => nil,
39
+ :local => nil,
37
40
  :font => nil,
38
41
  :size => nil,
39
42
  :character_spacing => nil }
40
43
  end
41
44
  it "# should be optional in rgb" do
42
45
  string = "<color rgb='ff0000'>red text</color>"
43
- array = Prawn::Text::Formatted::Parser.to_array(string)
46
+ array = Prawn::Text::Formatted::Parser.format(string)
44
47
  array[0].should == { :text => "red text",
45
48
  :styles => [],
46
49
  :color => "ff0000",
47
50
  :link => nil,
48
51
  :anchor => nil,
52
+ :local => nil,
49
53
  :font => nil,
50
54
  :size => nil,
51
55
  :character_spacing => nil }
52
56
  end
53
57
  it "should handle cmyk" do
54
58
  string = "<color c='0' m='100' y='0' k='0'>magenta text</color>"
55
- array = Prawn::Text::Formatted::Parser.to_array(string)
59
+ array = Prawn::Text::Formatted::Parser.format(string)
56
60
  array[0].should == { :text => "magenta text",
57
61
  :styles => [],
58
62
  :color => [0, 100, 0, 0],
59
63
  :link => nil,
60
64
  :anchor => nil,
65
+ :local => nil,
61
66
  :font => nil,
62
67
  :size => nil,
63
68
  :character_spacing => nil }
64
69
  end
65
70
  it "should handle fonts" do
66
71
  string = "<font name='Courier'>Courier text</font>"
67
- array = Prawn::Text::Formatted::Parser.to_array(string)
72
+ array = Prawn::Text::Formatted::Parser.format(string)
68
73
  array[0].should == { :text => "Courier text",
69
74
  :styles => [],
70
75
  :color => nil,
71
76
  :link => nil,
72
77
  :anchor => nil,
78
+ :local => nil,
73
79
  :font => "Courier",
74
80
  :size => nil,
75
81
  :character_spacing => nil }
76
82
  end
77
83
  it "should handle size" do
78
84
  string = "<font size='14'>14 point text</font>"
79
- array = Prawn::Text::Formatted::Parser.to_array(string)
85
+ array = Prawn::Text::Formatted::Parser.format(string)
80
86
  array[0].should == { :text => "14 point text",
81
87
  :styles => [],
82
88
  :color => nil,
83
89
  :link => nil,
84
90
  :anchor => nil,
91
+ :local => nil,
85
92
  :font => nil,
86
93
  :size => 14,
87
94
  :character_spacing => nil }
88
95
  end
89
96
  it "should handle character_spacing" do
90
97
  string = "<font character_spacing='2.5'>extra character spacing</font>"
91
- array = Prawn::Text::Formatted::Parser.to_array(string)
98
+ array = Prawn::Text::Formatted::Parser.format(string)
92
99
  array[0].should == { :text => "extra character spacing",
93
100
  :styles => [],
94
101
  :color => nil,
95
102
  :link => nil,
96
103
  :anchor => nil,
104
+ :local => nil,
97
105
  :font => nil,
98
106
  :size => nil,
99
107
  :character_spacing => 2.5 }
100
108
  end
101
109
  it "should handle links" do
102
110
  string = "<link href='http://example.com'>external link</link>"
103
- array = Prawn::Text::Formatted::Parser.to_array(string)
111
+ array = Prawn::Text::Formatted::Parser.format(string)
104
112
  array[0].should == { :text => "external link",
105
113
  :styles => [],
106
114
  :color => nil,
107
115
  :link => "http://example.com",
108
116
  :anchor => nil,
117
+ :local => nil,
118
+ :font => nil,
119
+ :size => nil,
120
+ :character_spacing => nil }
121
+ end
122
+ it "should handle local links" do
123
+ string = "<link local='/home/example/foo.bar'>local link</link>"
124
+ array = Prawn::Text::Formatted::Parser.format(string)
125
+ array[0].should == { :text => "local link",
126
+ :styles => [],
127
+ :color => nil,
128
+ :link => nil,
129
+ :anchor => nil,
130
+ :local => "/home/example/foo.bar",
109
131
  :font => nil,
110
132
  :size => nil,
111
133
  :character_spacing => nil }
112
134
  end
113
135
  it "should handle anchors" do
114
136
  string = "<link anchor='ToC'>internal link</link>"
115
- array = Prawn::Text::Formatted::Parser.to_array(string)
137
+ array = Prawn::Text::Formatted::Parser.format(string)
116
138
  array[0].should == { :text => "internal link",
117
139
  :styles => [],
118
140
  :color => nil,
119
141
  :link => nil,
120
142
  :anchor => "ToC",
143
+ :local => nil,
121
144
  :font => nil,
122
145
  :size => nil,
123
146
  :character_spacing => nil }
124
147
  end
125
148
  it "should handle higher order characters properly" do
126
149
  string = "<b>©\n©</b>"
127
- array = Prawn::Text::Formatted::Parser.to_array(string)
150
+ array = Prawn::Text::Formatted::Parser.format(string)
128
151
  array[0].should == { :text => "©",
129
152
  :styles => [:bold],
130
153
  :color => nil,
131
154
  :link => nil,
132
155
  :anchor => nil,
156
+ :local => nil,
133
157
  :font => nil,
134
158
  :size => nil,
135
159
  :character_spacing => nil }
@@ -138,6 +162,7 @@ describe "Text::Formatted::Parser#to_array" do
138
162
  :color => nil,
139
163
  :link => nil,
140
164
  :anchor => nil,
165
+ :local => nil,
141
166
  :font => nil,
142
167
  :size => nil,
143
168
  :character_spacing => nil }
@@ -146,55 +171,60 @@ describe "Text::Formatted::Parser#to_array" do
146
171
  :color => nil,
147
172
  :link => nil,
148
173
  :anchor => nil,
174
+ :local => nil,
149
175
  :font => nil,
150
176
  :size => nil,
151
177
  :character_spacing => nil }
152
178
  end
153
179
  it "should convert &lt; &gt;, and &amp; to <, >, and &, respectively" do
154
180
  string = "hello <b>&lt;, &gt;, and &amp;</b>"
155
- array = Prawn::Text::Formatted::Parser.to_array(string)
181
+ array = Prawn::Text::Formatted::Parser.format(string)
156
182
  array[1].should == { :text => "<, >, and &",
157
183
  :styles => [:bold],
158
184
  :color => nil,
159
185
  :link => nil,
160
186
  :anchor => nil,
187
+ :local => nil,
161
188
  :font => nil,
162
189
  :size => nil,
163
190
  :character_spacing => nil }
164
191
  end
165
192
  it "should handle double qoutes around tag attributes" do
166
193
  string = 'some <font size="14">sized</font> text'
167
- array = Prawn::Text::Formatted::Parser.to_array(string)
194
+ array = Prawn::Text::Formatted::Parser.format(string)
168
195
  array[1].should == { :text => "sized",
169
196
  :styles => [],
170
197
  :color => nil,
171
198
  :link => nil,
172
199
  :anchor => nil,
200
+ :local => nil,
173
201
  :font => nil,
174
202
  :size => 14,
175
203
  :character_spacing => nil }
176
204
  end
177
205
  it "should handle single qoutes around tag attributes" do
178
206
  string = "some <font size='14'>sized</font> text"
179
- array = Prawn::Text::Formatted::Parser.to_array(string)
207
+ array = Prawn::Text::Formatted::Parser.format(string)
180
208
  array[1].should == { :text => "sized",
181
209
  :styles => [],
182
210
  :color => nil,
183
211
  :link => nil,
184
212
  :anchor => nil,
213
+ :local => nil,
185
214
  :font => nil,
186
215
  :size => 14,
187
216
  :character_spacing => nil }
188
217
  end
189
218
  it "should construct a formatted text array from a string" do
190
219
  string = "hello <b>world\nhow <i>are</i></b> you?"
191
- array = Prawn::Text::Formatted::Parser.to_array(string)
220
+ array = Prawn::Text::Formatted::Parser.format(string)
192
221
 
193
222
  array[0].should == { :text => "hello ",
194
223
  :styles => [],
195
224
  :color => nil,
196
225
  :link => nil,
197
226
  :anchor => nil,
227
+ :local => nil,
198
228
  :font => nil,
199
229
  :size => nil,
200
230
  :character_spacing => nil }
@@ -203,6 +233,7 @@ describe "Text::Formatted::Parser#to_array" do
203
233
  :color => nil,
204
234
  :link => nil,
205
235
  :anchor => nil,
236
+ :local => nil,
206
237
  :font => nil,
207
238
  :size => nil,
208
239
  :character_spacing => nil }
@@ -211,6 +242,7 @@ describe "Text::Formatted::Parser#to_array" do
211
242
  :color => nil,
212
243
  :link => nil,
213
244
  :anchor => nil,
245
+ :local => nil,
214
246
  :font => nil,
215
247
  :size => nil,
216
248
  :character_spacing => nil }
@@ -219,6 +251,7 @@ describe "Text::Formatted::Parser#to_array" do
219
251
  :color => nil,
220
252
  :link => nil,
221
253
  :anchor => nil,
254
+ :local => nil,
222
255
  :font => nil,
223
256
  :size => nil,
224
257
  :character_spacing => nil }
@@ -227,6 +260,7 @@ describe "Text::Formatted::Parser#to_array" do
227
260
  :color => nil,
228
261
  :link => nil,
229
262
  :anchor => nil,
263
+ :local => nil,
230
264
  :font => nil,
231
265
  :size => nil,
232
266
  :character_spacing => nil }
@@ -235,19 +269,21 @@ describe "Text::Formatted::Parser#to_array" do
235
269
  :color => nil,
236
270
  :link => nil,
237
271
  :anchor => nil,
272
+ :local => nil,
238
273
  :font => nil,
239
274
  :size => nil,
240
275
  :character_spacing => nil }
241
276
  end
242
277
  it "should accept <strong> as an alternative to <b>" do
243
278
  string = "<strong>bold</strong> not bold"
244
- array = Prawn::Text::Formatted::Parser.to_array(string)
279
+ array = Prawn::Text::Formatted::Parser.format(string)
245
280
 
246
281
  array[0].should == { :text => "bold",
247
282
  :styles => [:bold],
248
283
  :color => nil,
249
284
  :link => nil,
250
285
  :anchor => nil,
286
+ :local => nil,
251
287
  :font => nil,
252
288
  :size => nil,
253
289
  :character_spacing => nil }
@@ -256,19 +292,21 @@ describe "Text::Formatted::Parser#to_array" do
256
292
  :color => nil,
257
293
  :link => nil,
258
294
  :anchor => nil,
295
+ :local => nil,
259
296
  :font => nil,
260
297
  :size => nil,
261
298
  :character_spacing => nil }
262
299
  end
263
300
  it "should accept <em> as an alternative to <i>" do
264
301
  string = "<em>italic</em> not italic"
265
- array = Prawn::Text::Formatted::Parser.to_array(string)
302
+ array = Prawn::Text::Formatted::Parser.format(string)
266
303
 
267
304
  array[0].should == { :text => "italic",
268
305
  :styles => [:italic],
269
306
  :color => nil,
270
307
  :link => nil,
271
308
  :anchor => nil,
309
+ :local => nil,
272
310
  :font => nil,
273
311
  :size => nil,
274
312
  :character_spacing => nil }
@@ -277,19 +315,21 @@ describe "Text::Formatted::Parser#to_array" do
277
315
  :color => nil,
278
316
  :link => nil,
279
317
  :anchor => nil,
318
+ :local => nil,
280
319
  :font => nil,
281
320
  :size => nil,
282
321
  :character_spacing => nil }
283
322
  end
284
323
  it "should accept <a> as an alternative to <link>" do
285
324
  string = "<a href='http://example.com'>link</a> not a link"
286
- array = Prawn::Text::Formatted::Parser.to_array(string)
325
+ array = Prawn::Text::Formatted::Parser.format(string)
287
326
 
288
327
  array[0].should == { :text => "link",
289
328
  :styles => [],
290
329
  :color => nil,
291
330
  :link => "http://example.com",
292
331
  :anchor => nil,
332
+ :local => nil,
293
333
  :font => nil,
294
334
  :size => nil,
295
335
  :character_spacing => nil }
@@ -298,10 +338,16 @@ describe "Text::Formatted::Parser#to_array" do
298
338
  :color => nil,
299
339
  :link => nil,
300
340
  :anchor => nil,
341
+ :local => nil,
301
342
  :font => nil,
302
343
  :size => nil,
303
344
  :character_spacing => nil }
304
345
  end
346
+
347
+ it "should turn <br>, <br/> into newline" do
348
+ array = Prawn::Text::Formatted::Parser.format("hello<br>big<br/>world")
349
+ array.map { |frag| frag[:text] }.join.should == "hello\nbig\nworld"
350
+ end
305
351
  end
306
352
 
307
353
 
@@ -313,6 +359,7 @@ describe "Text::Formatted::Parser#to_string" do
313
359
  :color => nil,
314
360
  :link => nil,
315
361
  :anchor => nil,
362
+ :local => nil,
316
363
  :font => nil,
317
364
  :size => nil,
318
365
  :character_spacing => nil }]
@@ -325,6 +372,7 @@ describe "Text::Formatted::Parser#to_string" do
325
372
  :color => nil,
326
373
  :link => nil,
327
374
  :anchor => nil,
375
+ :local => nil,
328
376
  :font => nil,
329
377
  :size => nil,
330
378
  :character_spacing => nil }]
@@ -337,6 +385,7 @@ describe "Text::Formatted::Parser#to_string" do
337
385
  :color => "ff0000",
338
386
  :link => nil,
339
387
  :anchor => nil,
388
+ :local => nil,
340
389
  :font => nil,
341
390
  :size => nil,
342
391
  :character_spacing => nil }]
@@ -349,6 +398,7 @@ describe "Text::Formatted::Parser#to_string" do
349
398
  :color => [0, 100, 0, 0],
350
399
  :link => nil,
351
400
  :anchor => nil,
401
+ :local => nil,
352
402
  :font => nil,
353
403
  :size => nil,
354
404
  :character_spacing => nil }]
@@ -361,6 +411,7 @@ describe "Text::Formatted::Parser#to_string" do
361
411
  :color => nil,
362
412
  :link => nil,
363
413
  :anchor => nil,
414
+ :local => nil,
364
415
  :font => "Courier",
365
416
  :size => nil,
366
417
  :character_spacing => nil }]
@@ -373,6 +424,7 @@ describe "Text::Formatted::Parser#to_string" do
373
424
  :color => nil,
374
425
  :link => nil,
375
426
  :anchor => nil,
427
+ :local => nil,
376
428
  :font => nil,
377
429
  :size => 14,
378
430
  :character_spacing => nil }]
@@ -385,6 +437,7 @@ describe "Text::Formatted::Parser#to_string" do
385
437
  :color => nil,
386
438
  :link => nil,
387
439
  :anchor => nil,
440
+ :local => nil,
388
441
  :font => nil,
389
442
  :size => nil,
390
443
  :character_spacing => 2.5 }]
@@ -396,6 +449,7 @@ describe "Text::Formatted::Parser#to_string" do
396
449
  :color => nil,
397
450
  :link => "http://example.com",
398
451
  :anchor => nil,
452
+ :local => nil,
399
453
  :font => nil,
400
454
  :size => nil,
401
455
  :character_spacing => nil }]