prawn 2.1.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/GPLv2 +20 -21
  5. data/Gemfile +3 -9
  6. data/Rakefile +20 -23
  7. data/lib/prawn.rb +36 -49
  8. data/lib/prawn/document.rb +180 -133
  9. data/lib/prawn/document/bounding_box.rb +41 -29
  10. data/lib/prawn/document/column_box.rb +7 -7
  11. data/lib/prawn/document/internals.rb +8 -6
  12. data/lib/prawn/document/span.rb +21 -16
  13. data/lib/prawn/encoding.rb +69 -68
  14. data/lib/prawn/errors.rb +12 -7
  15. data/lib/prawn/font.rb +102 -69
  16. data/lib/prawn/font_metric_cache.rb +14 -8
  17. data/lib/prawn/{font → fonts}/afm.rb +102 -68
  18. data/lib/prawn/{font → fonts}/dfont.rb +5 -11
  19. data/lib/prawn/fonts/otf.rb +11 -0
  20. data/lib/prawn/fonts/ttc.rb +36 -0
  21. data/lib/prawn/{font → fonts}/ttf.rb +87 -68
  22. data/lib/prawn/graphics.rb +119 -81
  23. data/lib/prawn/graphics/blend_mode.rb +9 -8
  24. data/lib/prawn/graphics/cap_style.rb +3 -3
  25. data/lib/prawn/graphics/color.rb +27 -25
  26. data/lib/prawn/graphics/dash.rb +23 -11
  27. data/lib/prawn/graphics/join_style.rb +9 -3
  28. data/lib/prawn/graphics/patterns.rb +190 -96
  29. data/lib/prawn/graphics/transformation.rb +15 -9
  30. data/lib/prawn/graphics/transparency.rb +17 -13
  31. data/lib/prawn/grid.rb +48 -47
  32. data/lib/prawn/image_handler.rb +5 -5
  33. data/lib/prawn/images.rb +39 -30
  34. data/lib/prawn/images/image.rb +2 -1
  35. data/lib/prawn/images/jpg.rb +28 -22
  36. data/lib/prawn/images/png.rb +65 -62
  37. data/lib/prawn/measurement_extensions.rb +10 -9
  38. data/lib/prawn/measurements.rb +19 -15
  39. data/lib/prawn/outline.rb +97 -77
  40. data/lib/prawn/repeater.rb +14 -10
  41. data/lib/prawn/security.rb +81 -61
  42. data/lib/prawn/security/arcfour.rb +2 -2
  43. data/lib/prawn/soft_mask.rb +26 -26
  44. data/lib/prawn/stamp.rb +20 -13
  45. data/lib/prawn/text.rb +68 -52
  46. data/lib/prawn/text/box.rb +11 -8
  47. data/lib/prawn/text/formatted.rb +5 -5
  48. data/lib/prawn/text/formatted/arranger.rb +53 -32
  49. data/lib/prawn/text/formatted/box.rb +134 -100
  50. data/lib/prawn/text/formatted/fragment.rb +11 -14
  51. data/lib/prawn/text/formatted/line_wrap.rb +122 -63
  52. data/lib/prawn/text/formatted/parser.rb +139 -117
  53. data/lib/prawn/text/formatted/wrap.rb +43 -31
  54. data/lib/prawn/transformation_stack.rb +7 -5
  55. data/lib/prawn/utilities.rb +7 -22
  56. data/lib/prawn/version.rb +2 -2
  57. data/lib/prawn/view.rb +17 -7
  58. data/manual/basic_concepts/adding_pages.rb +6 -7
  59. data/manual/basic_concepts/basic_concepts.rb +31 -22
  60. data/manual/basic_concepts/creation.rb +10 -11
  61. data/manual/basic_concepts/cursor.rb +4 -5
  62. data/manual/basic_concepts/measurement.rb +6 -7
  63. data/manual/basic_concepts/origin.rb +5 -6
  64. data/manual/basic_concepts/other_cursor_helpers.rb +11 -12
  65. data/manual/basic_concepts/view.rb +22 -16
  66. data/manual/bounding_box/bounding_box.rb +29 -24
  67. data/manual/bounding_box/bounds.rb +11 -12
  68. data/manual/bounding_box/canvas.rb +4 -5
  69. data/manual/bounding_box/creation.rb +6 -7
  70. data/manual/bounding_box/indentation.rb +14 -15
  71. data/manual/bounding_box/nesting.rb +24 -17
  72. data/manual/bounding_box/russian_boxes.rb +14 -13
  73. data/manual/bounding_box/stretchy.rb +12 -13
  74. data/manual/contents.rb +28 -22
  75. data/manual/cover.rb +33 -28
  76. data/manual/document_and_page_options/background.rb +11 -13
  77. data/manual/document_and_page_options/document_and_page_options.rb +25 -20
  78. data/manual/document_and_page_options/metadata.rb +18 -16
  79. data/manual/document_and_page_options/page_margins.rb +18 -20
  80. data/manual/document_and_page_options/page_size.rb +13 -12
  81. data/manual/document_and_page_options/print_scaling.rb +17 -15
  82. data/manual/example_helper.rb +5 -4
  83. data/manual/graphics/blend_mode.rb +12 -9
  84. data/manual/graphics/circle_and_ellipse.rb +4 -5
  85. data/manual/graphics/color.rb +7 -9
  86. data/manual/graphics/common_lines.rb +7 -8
  87. data/manual/graphics/fill_and_stroke.rb +4 -5
  88. data/manual/graphics/fill_rules.rb +9 -10
  89. data/manual/graphics/gradients.rb +27 -21
  90. data/manual/graphics/graphics.rb +48 -40
  91. data/manual/graphics/helper.rb +12 -9
  92. data/manual/graphics/line_width.rb +8 -7
  93. data/manual/graphics/lines_and_curves.rb +7 -8
  94. data/manual/graphics/polygon.rb +6 -8
  95. data/manual/graphics/rectangle.rb +4 -5
  96. data/manual/graphics/rotate.rb +6 -7
  97. data/manual/graphics/scale.rb +14 -15
  98. data/manual/graphics/soft_masks.rb +3 -4
  99. data/manual/graphics/stroke_cap.rb +6 -7
  100. data/manual/graphics/stroke_dash.rb +11 -12
  101. data/manual/graphics/stroke_join.rb +5 -6
  102. data/manual/graphics/translate.rb +9 -10
  103. data/manual/graphics/transparency.rb +7 -8
  104. data/manual/how_to_read_this_manual.rb +6 -6
  105. data/manual/images/absolute_position.rb +6 -7
  106. data/manual/images/fit.rb +7 -8
  107. data/manual/images/horizontal.rb +9 -10
  108. data/manual/images/images.rb +28 -24
  109. data/manual/images/plain_image.rb +5 -6
  110. data/manual/images/scale.rb +9 -10
  111. data/manual/images/vertical.rb +13 -14
  112. data/manual/images/width_and_height.rb +10 -11
  113. data/manual/layout/boxes.rb +5 -6
  114. data/manual/layout/content.rb +7 -8
  115. data/manual/layout/layout.rb +18 -16
  116. data/manual/layout/simple_grid.rb +6 -7
  117. data/manual/outline/add_subsection_to.rb +20 -21
  118. data/manual/outline/insert_section_after.rb +15 -16
  119. data/manual/outline/outline.rb +21 -17
  120. data/manual/outline/sections_and_pages.rb +17 -18
  121. data/manual/repeatable_content/alternate_page_numbering.rb +21 -17
  122. data/manual/repeatable_content/page_numbering.rb +17 -16
  123. data/manual/repeatable_content/repeatable_content.rb +25 -19
  124. data/manual/repeatable_content/repeater.rb +14 -15
  125. data/manual/repeatable_content/stamp.rb +14 -15
  126. data/manual/security/encryption.rb +9 -10
  127. data/manual/security/permissions.rb +19 -14
  128. data/manual/security/security.rb +19 -16
  129. data/manual/table.rb +3 -3
  130. data/manual/text/alignment.rb +16 -17
  131. data/manual/text/color.rb +12 -11
  132. data/manual/text/column_box.rb +9 -10
  133. data/manual/text/fallback_fonts.rb +25 -21
  134. data/manual/text/font.rb +11 -12
  135. data/manual/text/font_size.rb +13 -14
  136. data/manual/text/font_style.rb +7 -8
  137. data/manual/text/formatted_callbacks.rb +25 -21
  138. data/manual/text/formatted_text.rb +33 -25
  139. data/manual/text/free_flowing_text.rb +20 -21
  140. data/manual/text/inline.rb +18 -19
  141. data/manual/text/kerning_and_character_spacing.rb +14 -15
  142. data/manual/text/leading.rb +7 -8
  143. data/manual/text/line_wrapping.rb +37 -18
  144. data/manual/text/paragraph_indentation.rb +13 -14
  145. data/manual/text/positioned_text.rb +15 -16
  146. data/manual/text/registering_families.rb +20 -21
  147. data/manual/text/rendering_and_color.rb +9 -10
  148. data/manual/text/right_to_left_text.rb +26 -19
  149. data/manual/text/rotation.rb +28 -23
  150. data/manual/text/single_usage.rb +8 -9
  151. data/manual/text/text.rb +57 -52
  152. data/manual/text/text_box_excess.rb +20 -17
  153. data/manual/text/text_box_extensions.rb +18 -15
  154. data/manual/text/text_box_overflow.rb +18 -19
  155. data/manual/text/utf8.rb +11 -12
  156. data/manual/text/win_ansi_charset.rb +21 -19
  157. data/prawn.gemspec +44 -31
  158. data/spec/extensions/encoding_helpers.rb +3 -3
  159. data/spec/prawn/document/bounding_box_spec.rb +546 -0
  160. data/spec/prawn/document/column_box_spec.rb +75 -0
  161. data/spec/prawn/document/security_spec.rb +176 -0
  162. data/spec/prawn/document_annotations_spec.rb +76 -0
  163. data/spec/prawn/document_destinations_spec.rb +15 -0
  164. data/spec/prawn/document_grid_spec.rb +99 -0
  165. data/spec/prawn/document_reference_spec.rb +27 -0
  166. data/spec/prawn/document_span_spec.rb +36 -0
  167. data/spec/prawn/document_spec.rb +802 -0
  168. data/spec/prawn/font_metric_cache_spec.rb +54 -0
  169. data/spec/prawn/font_spec.rb +542 -0
  170. data/spec/prawn/graphics/blend_mode_spec.rb +63 -0
  171. data/spec/prawn/graphics/transparency_spec.rb +81 -0
  172. data/spec/prawn/graphics_spec.rb +837 -0
  173. data/spec/prawn/graphics_stroke_styles_spec.rb +229 -0
  174. data/spec/{image_handler_spec.rb → prawn/image_handler_spec.rb} +14 -14
  175. data/spec/prawn/images/jpg_spec.rb +20 -0
  176. data/spec/prawn/images/png_spec.rb +283 -0
  177. data/spec/prawn/images_spec.rb +224 -0
  178. data/spec/prawn/measurements_extensions_spec.rb +24 -0
  179. data/spec/prawn/outline_spec.rb +412 -0
  180. data/spec/prawn/repeater_spec.rb +165 -0
  181. data/spec/prawn/soft_mask_spec.rb +74 -0
  182. data/spec/prawn/stamp_spec.rb +172 -0
  183. data/spec/prawn/text/box_spec.rb +1112 -0
  184. data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
  185. data/spec/prawn/text/formatted/box_spec.rb +846 -0
  186. data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
  187. data/spec/prawn/text/formatted/line_wrap_spec.rb +494 -0
  188. data/spec/prawn/text/formatted/parser_spec.rb +697 -0
  189. data/spec/prawn/text_draw_text_spec.rb +149 -0
  190. data/spec/prawn/text_rendering_mode_spec.rb +48 -0
  191. data/spec/prawn/text_spacing_spec.rb +95 -0
  192. data/spec/prawn/text_spec.rb +603 -0
  193. data/spec/prawn/text_with_inline_formatting_spec.rb +35 -0
  194. data/spec/{transformation_stack_spec.rb → prawn/transformation_stack_spec.rb} +22 -19
  195. data/spec/prawn/view_spec.rb +63 -0
  196. data/spec/prawn_manual_spec.rb +35 -0
  197. data/spec/spec_helper.rb +18 -19
  198. metadata +144 -180
  199. metadata.gz.sig +4 -0
  200. data/data/images/16bit.alpha +0 -0
  201. data/data/images/16bit.color +0 -0
  202. data/data/images/16bit.png +0 -0
  203. data/data/images/arrow.png +0 -0
  204. data/data/images/arrow2.png +0 -0
  205. data/data/images/blend_modes_bottom_layer.jpg +0 -0
  206. data/data/images/blend_modes_top_layer.jpg +0 -0
  207. data/data/images/dice.alpha +0 -0
  208. data/data/images/dice.color +0 -0
  209. data/data/images/dice.png +0 -0
  210. data/data/images/dice_interlaced.png +0 -0
  211. data/data/images/fractal.jpg +0 -0
  212. data/data/images/indexed_color.dat +0 -0
  213. data/data/images/indexed_color.png +0 -0
  214. data/data/images/indexed_transparency.png +0 -0
  215. data/data/images/indexed_transparency_alpha.dat +0 -0
  216. data/data/images/indexed_transparency_color.dat +0 -0
  217. data/data/images/letterhead.jpg +0 -0
  218. data/data/images/license.md +0 -8
  219. data/data/images/page_white_text.alpha +0 -0
  220. data/data/images/page_white_text.color +0 -0
  221. data/data/images/page_white_text.png +0 -0
  222. data/data/images/pigs.jpg +0 -0
  223. data/data/images/prawn.png +0 -0
  224. data/data/images/ruport.png +0 -0
  225. data/data/images/ruport_data.dat +0 -0
  226. data/data/images/ruport_transparent.png +0 -0
  227. data/data/images/ruport_type0.png +0 -0
  228. data/data/images/stef.jpg +0 -0
  229. data/data/images/tru256.bmp +0 -0
  230. data/data/images/web-links.dat +0 -1
  231. data/data/images/web-links.png +0 -0
  232. data/data/pdfs/complex_template.pdf +0 -0
  233. data/data/pdfs/contains_ttf_font.pdf +0 -0
  234. data/data/pdfs/encrypted.pdf +0 -0
  235. data/data/pdfs/form.pdf +1 -819
  236. data/data/pdfs/hexagon.pdf +0 -61
  237. data/data/pdfs/indirect_reference.pdf +0 -86
  238. data/data/pdfs/multipage_template.pdf +0 -127
  239. data/data/pdfs/nested_pages.pdf +0 -118
  240. data/data/pdfs/page_without_mediabox.pdf +0 -193
  241. data/data/pdfs/resources_as_indirect_object.pdf +0 -83
  242. data/data/pdfs/two_hexagons.pdf +0 -90
  243. data/data/pdfs/version_1_6.pdf +0 -61
  244. data/data/shift_jis_text.txt +0 -1
  245. data/spec/acceptance/png_spec.rb +0 -35
  246. data/spec/annotations_spec.rb +0 -67
  247. data/spec/blend_mode_spec.rb +0 -71
  248. data/spec/bounding_box_spec.rb +0 -501
  249. data/spec/column_box_spec.rb +0 -59
  250. data/spec/destinations_spec.rb +0 -13
  251. data/spec/document_spec.rb +0 -738
  252. data/spec/font_metric_cache_spec.rb +0 -52
  253. data/spec/font_spec.rb +0 -475
  254. data/spec/formatted_text_arranger_spec.rb +0 -452
  255. data/spec/formatted_text_box_spec.rb +0 -716
  256. data/spec/formatted_text_fragment_spec.rb +0 -299
  257. data/spec/graphics_spec.rb +0 -705
  258. data/spec/grid_spec.rb +0 -95
  259. data/spec/images_spec.rb +0 -167
  260. data/spec/inline_formatted_text_parser_spec.rb +0 -568
  261. data/spec/jpg_spec.rb +0 -23
  262. data/spec/line_wrap_spec.rb +0 -366
  263. data/spec/measurement_units_spec.rb +0 -22
  264. data/spec/outline_spec.rb +0 -409
  265. data/spec/png_spec.rb +0 -257
  266. data/spec/reference_spec.rb +0 -25
  267. data/spec/repeater_spec.rb +0 -154
  268. data/spec/security_spec.rb +0 -151
  269. data/spec/soft_mask_spec.rb +0 -78
  270. data/spec/span_spec.rb +0 -43
  271. data/spec/stamp_spec.rb +0 -179
  272. data/spec/stroke_styles_spec.rb +0 -208
  273. data/spec/text_at_spec.rb +0 -142
  274. data/spec/text_box_spec.rb +0 -1042
  275. data/spec/text_rendering_mode_spec.rb +0 -45
  276. data/spec/text_spacing_spec.rb +0 -93
  277. data/spec/text_spec.rb +0 -543
  278. data/spec/text_with_inline_formatting_spec.rb +0 -35
  279. data/spec/transparency_spec.rb +0 -91
  280. data/spec/view_spec.rb +0 -42
@@ -1,95 +0,0 @@
1
- # encoding: utf-8
2
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
3
-
4
- describe "A document's grid" do
5
- before do
6
- @pdf = Prawn::Document.new
7
- end
8
-
9
- it "should allow definition of a grid" do
10
- @pdf.define_grid(:columns => 5, :rows => 8, :gutter => 0.1)
11
- expect(@pdf.grid.columns).to eq(5)
12
- expect(@pdf.grid.rows).to eq(8)
13
- expect(@pdf.grid.gutter).to eq(0.1)
14
- end
15
-
16
- it "should allow re-definition of a grid" do
17
- @pdf.define_grid(:columns => 5, :rows => 8, :gutter => 0.1)
18
- expect(@pdf.grid.columns).to eq(5)
19
- expect(@pdf.grid.rows).to eq(8)
20
- expect(@pdf.grid.gutter).to eq(0.1)
21
- @pdf.define_grid(:columns => 3, :rows => 6, :gutter => 0.1)
22
- expect(@pdf.grid.columns).to eq(3)
23
- expect(@pdf.grid.rows).to eq(6)
24
- expect(@pdf.grid.gutter).to eq(0.1)
25
- end
26
-
27
- describe "when a grid is defined" do
28
- before do
29
- @num_columns = 5
30
- @num_rows = 8
31
- @gutter = 10.0
32
- @pdf.define_grid(
33
- :columns => @num_columns,
34
- :rows => @num_rows,
35
- :gutter => @gutter
36
- )
37
- end
38
-
39
- it "should compute the column width" do
40
- expect(@pdf.grid.column_width * @num_columns.to_f +
41
- @gutter * (@num_columns - 1).to_f).to eq(@pdf.bounds.width)
42
- end
43
-
44
- it "should compute the row height" do
45
- expect(@pdf.grid.row_height * @num_rows.to_f +
46
- @gutter * (@num_rows - 1).to_f).to eq(@pdf.bounds.height)
47
- end
48
-
49
- it "should give the edges of a grid box" do
50
- grid_width = (@pdf.bounds.width.to_f -
51
- (@gutter * (@num_columns - 1).to_f)) / @num_columns.to_f
52
- grid_height = (@pdf.bounds.height.to_f -
53
- (@gutter * (@num_rows - 1).to_f)) / @num_rows.to_f
54
-
55
- exp_tl_x = (grid_width + @gutter.to_f) * 4.0
56
- exp_tl_y = @pdf.bounds.height.to_f - (grid_height + @gutter.to_f)
57
-
58
- expect(@pdf.grid(1, 4).top_left).to eq([exp_tl_x, exp_tl_y])
59
- expect(@pdf.grid(1, 4).top_right).to eq([exp_tl_x + grid_width, exp_tl_y])
60
- expect(@pdf.grid(1, 4).bottom_left).to eq([exp_tl_x, exp_tl_y - grid_height])
61
- expect(@pdf.grid(1, 4).bottom_right).to eq([exp_tl_x + grid_width, exp_tl_y - grid_height])
62
- end
63
-
64
- it "should give the edges of a multiple grid boxes" do
65
- # Hand verified. Cheating a bit. Don't tell.
66
- expect(@pdf.grid([1, 3], [2, 5]).top_left).to eq([330.0, 628.75])
67
- expect(@pdf.grid([1, 3], [2, 5]).top_right).to eq([650.0, 628.75])
68
- expect(@pdf.grid([1, 3], [2, 5]).bottom_left).to eq([330.0, 456.25])
69
- expect(@pdf.grid([1, 3], [2, 5]).bottom_right).to eq([650.0, 456.25])
70
- end
71
-
72
- it "should draw outlines without changing global default colors to grid color" do
73
- @pdf.grid.show_all('cccccc')
74
-
75
- colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
76
- expect(colors.fill_color).not_to eq([0.8, 0.8, 0.8])
77
- expect(colors.stroke_color).not_to eq([0.8, 0.8, 0.8])
78
-
79
- # Hardcoded default color as I haven't been able to come up with a stable converter
80
- # between fill_color without lots code.
81
- expect(colors.stroke_color).to eq([0.0, 0.0, 0.0])
82
- end
83
-
84
- it "should draw outlines without curent color settings" do
85
- @pdf.fill_color "ccff00"
86
- @pdf.stroke_color "ffcc00"
87
-
88
- @pdf.grid.show_all
89
-
90
- colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
91
- expect(colors.fill_color).to eq([0.8, 1.0, 0.0])
92
- expect(colors.stroke_color).to eq([1.0, 0.8, 0.0])
93
- end
94
- end
95
- end
@@ -1,167 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
- require 'set'
5
- require 'pathname'
6
-
7
- describe "the image() function" do
8
- before(:each) do
9
- @filename = "#{Prawn::DATADIR}/images/pigs.jpg"
10
- create_pdf
11
- end
12
-
13
- it "should only embed an image once, even if it's added multiple times" do
14
- @pdf.image @filename, :at => [100, 100]
15
- @pdf.image @filename, :at => [300, 300]
16
-
17
- output = @pdf.render
18
- images = PDF::Inspector::XObject.analyze(output)
19
- # there should be 2 images in the page resources
20
- expect(images.page_xobjects.first.size).to eq(2)
21
- # but only 1 image xobject
22
- expect(output.scan(/\/Type \/XObject/).size).to eq(1)
23
- end
24
-
25
- it "should return the image info object" do
26
- info = @pdf.image(@filename)
27
-
28
- expect(info).to be_a_kind_of(Prawn::Images::JPG)
29
-
30
- expect(info.height).to eq(453)
31
- end
32
-
33
- it "should accept IO objects" do
34
- file = File.open(@filename, "rb")
35
- info = @pdf.image(file)
36
-
37
- expect(info.height).to eq(453)
38
- end
39
-
40
- it "rewinds IO objects to be able to embed them multiply" do
41
- file = File.open(@filename, "rb")
42
-
43
- @pdf.image(file)
44
- info = @pdf.image(file)
45
- expect(info.height).to eq(453)
46
- end
47
-
48
- it "should accept Pathname objects" do
49
- info = @pdf.image(Pathname.new(@filename))
50
- expect(info.height).to eq(453)
51
- end
52
-
53
- context "setting the length of the bytestream" do
54
- it "should correctly work with images from Pathname objects" do
55
- info = @pdf.image(Pathname.new(@filename))
56
- expect(@pdf).to have_parseable_xobjects
57
- end
58
-
59
- it "should correctly work with images from IO objects" do
60
- info = @pdf.image(File.open(@filename, 'rb'))
61
- expect(@pdf).to have_parseable_xobjects
62
- end
63
-
64
- it "should correctly work with images from IO objects not set to mode rb" do
65
- info = @pdf.image(File.open(@filename, 'r'))
66
- expect(@pdf).to have_parseable_xobjects
67
- end
68
- end
69
-
70
- it "should raise_error an UnsupportedImageType if passed a BMP" do
71
- filename = "#{Prawn::DATADIR}/images/tru256.bmp"
72
- expect { @pdf.image filename, :at => [100, 100] }.to raise_error(Prawn::Errors::UnsupportedImageType)
73
- end
74
-
75
- it "should raise_error an UnsupportedImageType if passed an interlaced PNG" do
76
- filename = "#{Prawn::DATADIR}/images/dice_interlaced.png"
77
- expect { @pdf.image filename, :at => [100, 100] }.to raise_error(Prawn::Errors::UnsupportedImageType)
78
- end
79
-
80
- it "should bump PDF version to 1.5 or greater on embedding 16-bit PNGs" do
81
- @pdf.image "#{Prawn::DATADIR}/images/16bit.png"
82
- expect(@pdf.state.version).to be >= 1.5
83
- end
84
-
85
- it "should embed 16-bit alpha channels for 16-bit PNGs" do
86
- @pdf.image "#{Prawn::DATADIR}/images/16bit.png"
87
-
88
- output = @pdf.render
89
- expect(output).to match(/\/BitsPerComponent 16/)
90
- expect(output).not_to match(/\/BitsPerComponent 8/)
91
- end
92
-
93
- it "should flow an image to a new page if it will not fit on a page" do
94
- @pdf.image @filename, :fit => [600, 600]
95
- @pdf.image @filename, :fit => [600, 600]
96
- output = StringIO.new(@pdf.render, 'r+')
97
- hash = PDF::Reader::ObjectHash.new(output)
98
- pages = hash.values.find { |obj| obj.is_a?(Hash) && obj[:Type] == :Pages }[:Kids]
99
- expect(pages.size).to eq(2)
100
- expect(hash[pages[0]][:Resources][:XObject].keys).to eq([:I1])
101
- expect(hash[pages[1]][:Resources][:XObject].keys).to eq([:I2])
102
- end
103
-
104
- it "should not flow an image to a new page if it will fit on one page" do
105
- @pdf.image @filename, :fit => [400, 400]
106
- @pdf.image @filename, :fit => [400, 400]
107
- output = StringIO.new(@pdf.render, 'r+')
108
- hash = PDF::Reader::ObjectHash.new(output)
109
- pages = hash.values.find { |obj| obj.is_a?(Hash) && obj[:Type] == :Pages }[:Kids]
110
- expect(pages.size).to eq(1)
111
- expect(Set.new(hash[pages[0]][:Resources][:XObject].keys)).to eq(
112
- Set.new([:I1, :I2])
113
- )
114
- end
115
-
116
- it "should not start a new page just for a stretchy bounding box" do
117
- expect(@pdf).to_not receive(:start_new_page)
118
- @pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width) do
119
- @pdf.image @filename
120
- end
121
- end
122
-
123
- describe ":fit option" do
124
- it "should fit inside the defined constraints" do
125
- info = @pdf.image @filename, :fit => [100, 400]
126
- expect(info.scaled_width).to be <= 100
127
- expect(info.scaled_height).to be <= 400
128
-
129
- info = @pdf.image @filename, :fit => [400, 100]
130
- expect(info.scaled_width).to be <= 400
131
- expect(info.scaled_height).to be <= 100
132
-
133
- info = @pdf.image @filename, :fit => [604, 453]
134
- expect(info.scaled_width).to eq(604)
135
- expect(info.scaled_height).to eq(453)
136
- end
137
- it "should move text position" do
138
- @y = @pdf.y
139
- info = @pdf.image @filename, :fit => [100, 400]
140
- expect(@pdf.y).to be < @y
141
- end
142
- end
143
-
144
- describe ":at option" do
145
- it "should not move text position" do
146
- @y = @pdf.y
147
- info = @pdf.image @filename, :at => [100, 400]
148
- expect(@pdf.y).to eq(@y)
149
- end
150
- end
151
-
152
- describe ":width option without :height option" do
153
- it "scales the width and height" do
154
- info = @pdf.image @filename, :width => 225
155
- expect(info.scaled_height).to eq(168.75)
156
- expect(info.scaled_width).to eq(225.0)
157
- end
158
- end
159
-
160
- describe ":height option without :width option" do
161
- it "scales the width and height" do
162
- info = @pdf.image @filename, :height => 225
163
- expect(info.scaled_height).to eq(225.0)
164
- expect(info.scaled_width).to eq(300.0)
165
- end
166
- end
167
- end
@@ -1,568 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
3
-
4
- describe "Text::Formatted::Parser#format" do
5
- it "should handle sup" do
6
- string = "<sup>superscript</sup>"
7
- array = Prawn::Text::Formatted::Parser.format(string)
8
- expect(array[0]).to eq(:text => "superscript",
9
- :styles => [:superscript],
10
- :color => nil,
11
- :link => nil,
12
- :anchor => nil,
13
- :local => nil,
14
- :font => nil,
15
- :size => nil,
16
- :character_spacing => nil)
17
- end
18
- it "should handle sub" do
19
- string = "<sub>subscript</sub>"
20
- array = Prawn::Text::Formatted::Parser.format(string)
21
- expect(array[0]).to eq(:text => "subscript",
22
- :styles => [:subscript],
23
- :color => nil,
24
- :link => nil,
25
- :anchor => nil,
26
- :local => nil,
27
- :font => nil,
28
- :size => nil,
29
- :character_spacing => nil)
30
- end
31
- it "should handle rgb" do
32
- string = "<color rgb='#ff0000'>red text</color>"
33
- array = Prawn::Text::Formatted::Parser.format(string)
34
- expect(array[0]).to eq(:text => "red text",
35
- :styles => [],
36
- :color => "ff0000",
37
- :link => nil,
38
- :anchor => nil,
39
- :local => nil,
40
- :font => nil,
41
- :size => nil,
42
- :character_spacing => nil)
43
- end
44
- it "# should be optional in rgb" do
45
- string = "<color rgb='ff0000'>red text</color>"
46
- array = Prawn::Text::Formatted::Parser.format(string)
47
- expect(array[0]).to eq(:text => "red text",
48
- :styles => [],
49
- :color => "ff0000",
50
- :link => nil,
51
- :anchor => nil,
52
- :local => nil,
53
- :font => nil,
54
- :size => nil,
55
- :character_spacing => nil)
56
- end
57
- it "should handle cmyk" do
58
- string = "<color c='0' m='100' y='0' k='0'>magenta text</color>"
59
- array = Prawn::Text::Formatted::Parser.format(string)
60
- expect(array[0]).to eq(:text => "magenta text",
61
- :styles => [],
62
- :color => [0, 100, 0, 0],
63
- :link => nil,
64
- :anchor => nil,
65
- :local => nil,
66
- :font => nil,
67
- :size => nil,
68
- :character_spacing => nil)
69
- end
70
- it "should handle fonts" do
71
- string = "<font name='Courier'>Courier text</font>"
72
- array = Prawn::Text::Formatted::Parser.format(string)
73
- expect(array[0]).to eq(:text => "Courier text",
74
- :styles => [],
75
- :color => nil,
76
- :link => nil,
77
- :anchor => nil,
78
- :local => nil,
79
- :font => "Courier",
80
- :size => nil,
81
- :character_spacing => nil)
82
- end
83
- it "should handle size" do
84
- string = "<font size='14'>14 point text</font>"
85
- array = Prawn::Text::Formatted::Parser.format(string)
86
- expect(array[0]).to eq(:text => "14 point text",
87
- :styles => [],
88
- :color => nil,
89
- :link => nil,
90
- :anchor => nil,
91
- :local => nil,
92
- :font => nil,
93
- :size => 14,
94
- :character_spacing => nil)
95
- end
96
- it "should handle character_spacing" do
97
- string = "<font character_spacing='2.5'>extra character spacing</font>"
98
- array = Prawn::Text::Formatted::Parser.format(string)
99
- expect(array[0]).to eq(:text => "extra character spacing",
100
- :styles => [],
101
- :color => nil,
102
- :link => nil,
103
- :anchor => nil,
104
- :local => nil,
105
- :font => nil,
106
- :size => nil,
107
- :character_spacing => 2.5)
108
- end
109
- it "should handle links" do
110
- string = "<link href='http://example.com'>external link</link>"
111
- array = Prawn::Text::Formatted::Parser.format(string)
112
- expect(array[0]).to eq(:text => "external link",
113
- :styles => [],
114
- :color => nil,
115
- :link => "http://example.com",
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
- expect(array[0]).to eq(:text => "local link",
126
- :styles => [],
127
- :color => nil,
128
- :link => nil,
129
- :anchor => nil,
130
- :local => "/home/example/foo.bar",
131
- :font => nil,
132
- :size => nil,
133
- :character_spacing => nil)
134
- end
135
- it "should handle anchors" do
136
- string = "<link anchor='ToC'>internal link</link>"
137
- array = Prawn::Text::Formatted::Parser.format(string)
138
- expect(array[0]).to eq(:text => "internal link",
139
- :styles => [],
140
- :color => nil,
141
- :link => nil,
142
- :anchor => "ToC",
143
- :local => nil,
144
- :font => nil,
145
- :size => nil,
146
- :character_spacing => nil)
147
- end
148
- it "should handle higher order characters properly" do
149
- string = "<b>©\n©</b>"
150
- array = Prawn::Text::Formatted::Parser.format(string)
151
- expect(array[0]).to eq(:text => "©",
152
- :styles => [:bold],
153
- :color => nil,
154
- :link => nil,
155
- :anchor => nil,
156
- :local => nil,
157
- :font => nil,
158
- :size => nil,
159
- :character_spacing => nil)
160
- expect(array[1]).to eq(:text => "\n",
161
- :styles => [:bold],
162
- :color => nil,
163
- :link => nil,
164
- :anchor => nil,
165
- :local => nil,
166
- :font => nil,
167
- :size => nil,
168
- :character_spacing => nil)
169
- expect(array[2]).to eq(:text => "©",
170
- :styles => [:bold],
171
- :color => nil,
172
- :link => nil,
173
- :anchor => nil,
174
- :local => nil,
175
- :font => nil,
176
- :size => nil,
177
- :character_spacing => nil)
178
- end
179
- it "should convert &lt; &gt;, and &amp; to <, >, and &, respectively" do
180
- string = "hello <b>&lt;, &gt;, and &amp;</b>"
181
- array = Prawn::Text::Formatted::Parser.format(string)
182
- expect(array[1]).to eq(:text => "<, >, and &",
183
- :styles => [:bold],
184
- :color => nil,
185
- :link => nil,
186
- :anchor => nil,
187
- :local => nil,
188
- :font => nil,
189
- :size => nil,
190
- :character_spacing => nil)
191
- end
192
- it "should handle double qoutes around tag attributes" do
193
- string = 'some <font size="14">sized</font> text'
194
- array = Prawn::Text::Formatted::Parser.format(string)
195
- expect(array[1]).to eq(:text => "sized",
196
- :styles => [],
197
- :color => nil,
198
- :link => nil,
199
- :anchor => nil,
200
- :local => nil,
201
- :font => nil,
202
- :size => 14,
203
- :character_spacing => nil)
204
- end
205
- it "should handle single qoutes around tag attributes" do
206
- string = "some <font size='14'>sized</font> text"
207
- array = Prawn::Text::Formatted::Parser.format(string)
208
- expect(array[1]).to eq(:text => "sized",
209
- :styles => [],
210
- :color => nil,
211
- :link => nil,
212
- :anchor => nil,
213
- :local => nil,
214
- :font => nil,
215
- :size => 14,
216
- :character_spacing => nil)
217
- end
218
- it "should construct a formatted text array from a string" do
219
- string = "hello <b>world\nhow <i>are</i></b> you?"
220
- array = Prawn::Text::Formatted::Parser.format(string)
221
-
222
- expect(array[0]).to eq(:text => "hello ",
223
- :styles => [],
224
- :color => nil,
225
- :link => nil,
226
- :anchor => nil,
227
- :local => nil,
228
- :font => nil,
229
- :size => nil,
230
- :character_spacing => nil)
231
- expect(array[1]).to eq(:text => "world",
232
- :styles => [:bold],
233
- :color => nil,
234
- :link => nil,
235
- :anchor => nil,
236
- :local => nil,
237
- :font => nil,
238
- :size => nil,
239
- :character_spacing => nil)
240
- expect(array[2]).to eq(:text => "\n",
241
- :styles => [:bold],
242
- :color => nil,
243
- :link => nil,
244
- :anchor => nil,
245
- :local => nil,
246
- :font => nil,
247
- :size => nil,
248
- :character_spacing => nil)
249
- expect(array[3]).to eq(:text => "how ",
250
- :styles => [:bold],
251
- :color => nil,
252
- :link => nil,
253
- :anchor => nil,
254
- :local => nil,
255
- :font => nil,
256
- :size => nil,
257
- :character_spacing => nil)
258
- expect(array[4]).to eq(:text => "are",
259
- :styles => [:bold, :italic],
260
- :color => nil,
261
- :link => nil,
262
- :anchor => nil,
263
- :local => nil,
264
- :font => nil,
265
- :size => nil,
266
- :character_spacing => nil)
267
- expect(array[5]).to eq(:text => " you?",
268
- :styles => [],
269
- :color => nil,
270
- :link => nil,
271
- :anchor => nil,
272
- :local => nil,
273
- :font => nil,
274
- :size => nil,
275
- :character_spacing => nil)
276
- end
277
- it "should accept <strong> as an alternative to <b>" do
278
- string = "<strong>bold</strong> not bold"
279
- array = Prawn::Text::Formatted::Parser.format(string)
280
-
281
- expect(array[0]).to eq(:text => "bold",
282
- :styles => [:bold],
283
- :color => nil,
284
- :link => nil,
285
- :anchor => nil,
286
- :local => nil,
287
- :font => nil,
288
- :size => nil,
289
- :character_spacing => nil)
290
- expect(array[1]).to eq(:text => " not bold",
291
- :styles => [],
292
- :color => nil,
293
- :link => nil,
294
- :anchor => nil,
295
- :local => nil,
296
- :font => nil,
297
- :size => nil,
298
- :character_spacing => nil)
299
- end
300
- it "should accept <em> as an alternative to <i>" do
301
- string = "<em>italic</em> not italic"
302
- array = Prawn::Text::Formatted::Parser.format(string)
303
-
304
- expect(array[0]).to eq(:text => "italic",
305
- :styles => [:italic],
306
- :color => nil,
307
- :link => nil,
308
- :anchor => nil,
309
- :local => nil,
310
- :font => nil,
311
- :size => nil,
312
- :character_spacing => nil)
313
- expect(array[1]).to eq(:text => " not italic",
314
- :styles => [],
315
- :color => nil,
316
- :link => nil,
317
- :anchor => nil,
318
- :local => nil,
319
- :font => nil,
320
- :size => nil,
321
- :character_spacing => nil)
322
- end
323
- it "should accept <a> as an alternative to <link>" do
324
- string = "<a href='http://example.com'>link</a> not a link"
325
- array = Prawn::Text::Formatted::Parser.format(string)
326
-
327
- expect(array[0]).to eq(:text => "link",
328
- :styles => [],
329
- :color => nil,
330
- :link => "http://example.com",
331
- :anchor => nil,
332
- :local => nil,
333
- :font => nil,
334
- :size => nil,
335
- :character_spacing => nil)
336
- expect(array[1]).to eq(:text => " not a link",
337
- :styles => [],
338
- :color => nil,
339
- :link => nil,
340
- :anchor => nil,
341
- :local => nil,
342
- :font => nil,
343
- :size => nil,
344
- :character_spacing => nil)
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
- expect(array.map { |frag| frag[:text] }.join).to eq("hello\nbig\nworld")
350
- end
351
- end
352
-
353
- describe "Text::Formatted::Parser#to_string" do
354
- it "should handle sup" do
355
- string = "<sup>superscript</sup>"
356
- array = [{ :text => "superscript",
357
- :styles => [:superscript],
358
- :color => nil,
359
- :link => nil,
360
- :anchor => nil,
361
- :local => nil,
362
- :font => nil,
363
- :size => nil,
364
- :character_spacing => nil }]
365
- expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
366
- end
367
- it "should handle sub" do
368
- string = "<sub>subscript</sub>"
369
- array = [{ :text => "subscript",
370
- :styles => [:subscript],
371
- :color => nil,
372
- :link => nil,
373
- :anchor => nil,
374
- :local => nil,
375
- :font => nil,
376
- :size => nil,
377
- :character_spacing => nil }]
378
- expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
379
- end
380
- it "should handle rgb" do
381
- string = "<color rgb='ff0000'>red text</color>"
382
- array = [{ :text => "red text",
383
- :styles => [],
384
- :color => "ff0000",
385
- :link => nil,
386
- :anchor => nil,
387
- :local => nil,
388
- :font => nil,
389
- :size => nil,
390
- :character_spacing => nil }]
391
- expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
392
- end
393
- it "should handle cmyk" do
394
- string = "<color c='0' m='100' y='0' k='0'>magenta text</color>"
395
- array = [{ :text => "magenta text",
396
- :styles => [],
397
- :color => [0, 100, 0, 0],
398
- :link => nil,
399
- :anchor => nil,
400
- :local => nil,
401
- :font => nil,
402
- :size => nil,
403
- :character_spacing => nil }]
404
- expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
405
- end
406
- it "should handle fonts" do
407
- string = "<font name='Courier'>Courier text</font>"
408
- array = [{ :text => "Courier text",
409
- :styles => [],
410
- :color => nil,
411
- :link => nil,
412
- :anchor => nil,
413
- :local => nil,
414
- :font => "Courier",
415
- :size => nil,
416
- :character_spacing => nil }]
417
- expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
418
- end
419
- it "should handle size" do
420
- string = "<font size='14'>14 point text</font>"
421
- array = [{ :text => "14 point text",
422
- :styles => [],
423
- :color => nil,
424
- :link => nil,
425
- :anchor => nil,
426
- :local => nil,
427
- :font => nil,
428
- :size => 14,
429
- :character_spacing => nil }]
430
- expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
431
- end
432
- it "should handle character spacing" do
433
- string = "<font character_spacing='2.5'>2.5 extra character spacing</font>"
434
- array = [{ :text => "2.5 extra character spacing",
435
- :styles => [],
436
- :color => nil,
437
- :link => nil,
438
- :anchor => nil,
439
- :local => nil,
440
- :font => nil,
441
- :size => nil,
442
- :character_spacing => 2.5 }]
443
- expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
444
- end
445
- it "should handle links" do
446
- array = [{ :text => "external link",
447
- :styles => [],
448
- :color => nil,
449
- :link => "http://example.com",
450
- :anchor => nil,
451
- :local => nil,
452
- :font => nil,
453
- :size => nil,
454
- :character_spacing => nil }]
455
- string = "<link href='http://example.com'>external link</link>"
456
- expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
457
- end
458
- it "should handle anchors" do
459
- array = [{ :text => "internal link",
460
- :styles => [],
461
- :color => nil,
462
- :link => nil,
463
- :anchor => "ToC",
464
- :font => nil,
465
- :size => nil,
466
- :character_spacing => nil }]
467
- string = "<link anchor='ToC'>internal link</link>"
468
- expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
469
- end
470
- it "should convert <, >, and & to &lt; &gt;, and &amp;, respectively" do
471
- array = [
472
- {
473
- :text => "hello ",
474
- :styles => [],
475
- :color => nil,
476
- :link => nil,
477
- :font => nil,
478
- :size => nil,
479
- :character_spacing => nil
480
- },
481
- {
482
- :text => "<, >, and &",
483
- :styles => [:bold],
484
- :color => nil,
485
- :link => nil,
486
- :font => nil,
487
- :size => nil,
488
- :character_spacing => nil
489
- }
490
- ]
491
- string = "hello <b>&lt;, &gt;, and &amp;</b>"
492
- expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
493
- end
494
- it "should construct an HTML-esque string from a formatted text array" do
495
- array = [
496
- { :text => "hello ",
497
- :styles => [],
498
- :color => nil,
499
- :link => nil,
500
- :font => nil,
501
- :size => 14,
502
- :character_spacing => nil },
503
- { :text => "world",
504
- :styles => [:bold],
505
- :color => nil,
506
- :link => nil,
507
- :font => nil,
508
- :size => nil,
509
- :character_spacing => nil },
510
- { :text => "\n",
511
- :styles => [:bold],
512
- :color => nil,
513
- :link => nil,
514
- :font => nil,
515
- :size => nil,
516
- :character_spacing => nil },
517
- { :text => "how ",
518
- :styles => [:bold],
519
- :color => nil,
520
- :link => nil,
521
- :font => nil,
522
- :size => nil,
523
- :character_spacing => nil },
524
- { :text => "are",
525
- :styles => [:bold, :italic],
526
- :color => nil,
527
- :link => nil,
528
- :font => nil,
529
- :size => nil,
530
- :character_spacing => nil },
531
- { :text => " you?",
532
- :styles => [],
533
- :color => nil,
534
- :link => nil,
535
- :font => nil,
536
- :size => nil,
537
- :character_spacing => nil }
538
- ]
539
- string = "<font size='14'>hello </font><b>world</b><b>\n</b><b>how </b><b><i>are</i></b> you?"
540
- expect(Prawn::Text::Formatted::Parser.to_string(array)).to eq(string)
541
- end
542
- end
543
-
544
- describe "Text::Formatted::Parser#array_paragraphs" do
545
- it "should group fragments separated by newlines" do
546
- array = [{ :text => "\nhello\nworld" },
547
- { :text => "\n\n" },
548
- { :text => "how" },
549
- { :text => "are" },
550
- { :text => "you" }]
551
- target = [[{ :text => "\n" }],
552
- [{ :text => "hello" }],
553
- [{ :text => "world" }],
554
- [{ :text => "\n" }],
555
- [{ :text => "how" },
556
- { :text => "are" },
557
- { :text => "you" }]]
558
- expect(Prawn::Text::Formatted::Parser.array_paragraphs(array)).to eq(target)
559
- end
560
-
561
- it "should work properly if ending in an empty paragraph" do
562
- array = [{ :text => "\nhello\nworld\n" }]
563
- target = [[{ :text => "\n" }],
564
- [{ :text => "hello" }],
565
- [{ :text => "world" }]]
566
- expect(Prawn::Text::Formatted::Parser.array_paragraphs(array)).to eq(target)
567
- end
568
- end