prawn 2.0.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) 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 +37 -49
  8. data/lib/prawn/document.rb +181 -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 +18 -8
  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 +115 -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 +120 -80
  23. data/lib/prawn/graphics/blend_mode.rb +65 -0
  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 +197 -67
  29. data/lib/prawn/graphics/transformation.rb +17 -8
  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 +107 -66
  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 +78 -49
  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 +121 -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 +44 -0
  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 +52 -0
  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 -39
  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 +4 -5
  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 +45 -33
  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/prawn/image_handler_spec.rb +53 -0
  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/prawn/transformation_stack_spec.rb +66 -0
  195. data/spec/prawn/view_spec.rb +63 -0
  196. data/spec/prawn_manual_spec.rb +35 -0
  197. data/spec/spec_helper.rb +19 -23
  198. metadata +145 -185
  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/dice.alpha +0 -0
  206. data/data/images/dice.color +0 -0
  207. data/data/images/dice.png +0 -0
  208. data/data/images/dice_interlaced.png +0 -0
  209. data/data/images/fractal.jpg +0 -0
  210. data/data/images/indexed_color.dat +0 -0
  211. data/data/images/indexed_color.png +0 -0
  212. data/data/images/letterhead.jpg +0 -0
  213. data/data/images/license.md +0 -8
  214. data/data/images/page_white_text.alpha +0 -0
  215. data/data/images/page_white_text.color +0 -0
  216. data/data/images/page_white_text.png +0 -0
  217. data/data/images/pal_bk.png +0 -0
  218. data/data/images/pigs.jpg +0 -0
  219. data/data/images/prawn.png +0 -0
  220. data/data/images/ruport.png +0 -0
  221. data/data/images/ruport_data.dat +0 -0
  222. data/data/images/ruport_transparent.png +0 -0
  223. data/data/images/ruport_type0.png +0 -0
  224. data/data/images/stef.jpg +0 -0
  225. data/data/images/tru256.bmp +0 -0
  226. data/data/images/web-links.dat +0 -1
  227. data/data/images/web-links.png +0 -0
  228. data/data/pdfs/complex_template.pdf +0 -0
  229. data/data/pdfs/contains_ttf_font.pdf +0 -0
  230. data/data/pdfs/encrypted.pdf +0 -0
  231. data/data/pdfs/form.pdf +1 -819
  232. data/data/pdfs/hexagon.pdf +0 -61
  233. data/data/pdfs/indirect_reference.pdf +0 -86
  234. data/data/pdfs/multipage_template.pdf +0 -127
  235. data/data/pdfs/nested_pages.pdf +0 -118
  236. data/data/pdfs/page_without_mediabox.pdf +0 -193
  237. data/data/pdfs/resources_as_indirect_object.pdf +0 -83
  238. data/data/pdfs/two_hexagons.pdf +0 -90
  239. data/data/pdfs/version_1_6.pdf +0 -61
  240. data/data/shift_jis_text.txt +0 -1
  241. data/spec/acceptance/png.rb +0 -24
  242. data/spec/annotations_spec.rb +0 -67
  243. data/spec/bounding_box_spec.rb +0 -501
  244. data/spec/column_box_spec.rb +0 -59
  245. data/spec/destinations_spec.rb +0 -13
  246. data/spec/document_spec.rb +0 -742
  247. data/spec/extensions/mocha.rb +0 -45
  248. data/spec/font_metric_cache_spec.rb +0 -52
  249. data/spec/font_spec.rb +0 -475
  250. data/spec/formatted_text_arranger_spec.rb +0 -423
  251. data/spec/formatted_text_box_spec.rb +0 -716
  252. data/spec/formatted_text_fragment_spec.rb +0 -299
  253. data/spec/graphics_spec.rb +0 -666
  254. data/spec/grid_spec.rb +0 -95
  255. data/spec/image_handler_spec.rb +0 -53
  256. data/spec/images_spec.rb +0 -167
  257. data/spec/inline_formatted_text_parser_spec.rb +0 -568
  258. data/spec/jpg_spec.rb +0 -23
  259. data/spec/line_wrap_spec.rb +0 -366
  260. data/spec/measurement_units_spec.rb +0 -22
  261. data/spec/outline_spec.rb +0 -409
  262. data/spec/png_spec.rb +0 -235
  263. data/spec/reference_spec.rb +0 -25
  264. data/spec/repeater_spec.rb +0 -154
  265. data/spec/security_spec.rb +0 -151
  266. data/spec/soft_mask_spec.rb +0 -78
  267. data/spec/span_spec.rb +0 -43
  268. data/spec/stamp_spec.rb +0 -179
  269. data/spec/stroke_styles_spec.rb +0 -208
  270. data/spec/text_at_spec.rb +0 -142
  271. data/spec/text_box_spec.rb +0 -1038
  272. data/spec/text_rendering_mode_spec.rb +0 -45
  273. data/spec/text_spacing_spec.rb +0 -93
  274. data/spec/text_spec.rb +0 -549
  275. data/spec/text_with_inline_formatting_spec.rb +0 -35
  276. data/spec/transparency_spec.rb +0 -91
  277. data/spec/view_spec.rb +0 -42
@@ -1,78 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- module SoftMaskHelper
6
- def make_soft_mask
7
- @pdf.save_graphics_state do
8
- @pdf.soft_mask do
9
- if block_given?
10
- yield
11
- else
12
- @pdf.fill_color '808080'
13
- @pdf.fill_rectangle [100, 100], 200, 200
14
- end
15
- end
16
-
17
- @pdf.fill_color '000000'
18
- @pdf.fill_rectangle [0, 0], 200, 200
19
- end
20
- end
21
- end
22
-
23
- describe "Document with soft masks" do
24
- include SoftMaskHelper
25
-
26
- it "should have PDF version at least 1.4" do
27
- create_pdf
28
- make_soft_mask
29
- str = @pdf.render
30
- expect(str[0, 8]).to eq("%PDF-1.4")
31
- end
32
-
33
- it "should create a new extended graphics state for each unique soft mask" do
34
- create_pdf
35
-
36
- make_soft_mask do
37
- @pdf.fill_color '808080'
38
- @pdf.fill_rectangle [100, 100], 200, 200
39
- end
40
-
41
- make_soft_mask do
42
- @pdf.fill_color '808080'
43
- @pdf.fill_rectangle [10, 10], 200, 200
44
- end
45
-
46
- extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates
47
- expect(extgstates.length).to eq(2)
48
- end
49
-
50
- it "a new extended graphics state should contain soft mask with drawing instructions" do
51
- create_pdf
52
-
53
- make_soft_mask do
54
- @pdf.fill_color '808080'
55
- @pdf.fill_rectangle [100, 100], 200, 200
56
- end
57
-
58
- extgstate = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates.first
59
- expect(extgstate[:soft_mask][:G].data).to eq("q\n/DeviceRGB cs\n0.000 0.000 0.000 scn\n/DeviceRGB CS\n0.000 0.000 0.000 SCN\n1 w\n0 J\n0 j\n[] 0 d\n/DeviceRGB cs\n0.502 0.502 0.502 scn\n100.0 -100.0 200.0 200.0 re\nf\nQ\n")
60
- end
61
-
62
- it "should not create duplicate extended graphics states" do
63
- create_pdf
64
-
65
- make_soft_mask do
66
- @pdf.fill_color '808080'
67
- @pdf.fill_rectangle [100, 100], 200, 200
68
- end
69
-
70
- make_soft_mask do
71
- @pdf.fill_color '808080'
72
- @pdf.fill_rectangle [100, 100], 200, 200
73
- end
74
-
75
- extgstates = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates
76
- expect(extgstates.length).to eq(1)
77
- end
78
- end
@@ -1,43 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- describe "drawing span" do
6
- before do
7
- Prawn.debug = false
8
- create_pdf
9
- end
10
-
11
- after do
12
- Prawn.debug = true
13
- end
14
-
15
- it "should only accept :position as option in debug mode" do
16
- Prawn.debug = true
17
- expect { @pdf.span(350, :x => 3) {} }.to raise_error(Prawn::Errors::UnknownOption)
18
- end
19
-
20
- it "should have raise an error if :position is invalid" do
21
- expect { @pdf.span(350, :position => :x) {} }.to raise_error(ArgumentError)
22
- end
23
-
24
- it "should restore the margin box when bounding box exits" do
25
- margin_box = @pdf.bounds
26
-
27
- @pdf.span(350, :position => :center) do
28
- @pdf.text "Here's some centered text in a 350 point column. " * 100
29
- end
30
-
31
- expect(@pdf.bounds).to eq(margin_box)
32
- end
33
-
34
- it "should do create a margin box" do
35
- y = @pdf.y
36
- margin_box = @pdf.span(350, :position => :center) do
37
- @pdf.text "Here's some centered text in a 350 point column. " * 100
38
- end
39
-
40
- expect(margin_box.top).to eq(792.0)
41
- expect(margin_box.bottom).to eq(0)
42
- end
43
- end
@@ -1,179 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- describe "create_stamp before any page is added" do
6
- it "should work with the font class" do
7
- @pdf = Prawn::Document.new(:skip_page_creation => true)
8
-
9
- # If anything goes wrong, Prawn::Errors::NotOnPage will be raised
10
- @pdf.create_stamp("my_stamp") do
11
- @pdf.font.height
12
- end
13
- end
14
-
15
- it "should work with setting color" do
16
- @pdf = Prawn::Document.new(:skip_page_creation => true)
17
-
18
- # If anything goes wrong, Prawn::Errors::NotOnPage will be raised
19
- @pdf.create_stamp("my_stamp") do
20
- @pdf.fill_color = 'ff0000'
21
- end
22
- end
23
- end
24
-
25
- describe "#stamp_at" do
26
- it "should work" do
27
- create_pdf
28
- @pdf.create_stamp("MyStamp")
29
- @pdf.stamp_at("MyStamp", [100, 200])
30
- # I had modified PDF::Inspector::XObject to receive the
31
- # invoke_xobject message and count the number of times it was
32
- # called, but it was only called once, so I reverted checking the
33
- # output with a regular expression
34
- expect(@pdf.render).to match(/\/Stamp1 Do.*?/m)
35
- end
36
- end
37
-
38
- describe "Document with a stamp" do
39
- it "should raise_error NameTaken error when attempt to create stamp " \
40
- "with same name as an existing stamp" do
41
- create_pdf
42
- @pdf.create_stamp("MyStamp")
43
- expect {
44
- @pdf.create_stamp("MyStamp")
45
- }.to raise_error(Prawn::Errors::NameTaken)
46
- end
47
-
48
- it "should raise_error InvalidName error when attempt to create " \
49
- "stamp with a blank name" do
50
- create_pdf
51
- expect {
52
- @pdf.create_stamp("")
53
- }.to raise_error(Prawn::Errors::InvalidName)
54
- end
55
-
56
- it "a new XObject should be defined for each stamp created" do
57
- create_pdf
58
- @pdf.create_stamp("MyStamp")
59
- @pdf.create_stamp("AnotherStamp")
60
- @pdf.stamp("MyStamp")
61
- @pdf.stamp("AnotherStamp")
62
-
63
- inspector = PDF::Inspector::XObject.analyze(@pdf.render)
64
- xobjects = inspector.page_xobjects.last
65
- expect(xobjects.length).to eq(2)
66
- end
67
-
68
- it "calling stamp with a name that does not match an existing stamp " \
69
- "should raise_error UndefinedObjectName" do
70
- create_pdf
71
- @pdf.create_stamp("MyStamp")
72
- expect {
73
- @pdf.stamp("OtherStamp")
74
- }.to raise_error(Prawn::Errors::UndefinedObjectName)
75
- end
76
-
77
- it "stamp should be drawn into the document each time stamp is called" do
78
- create_pdf
79
- @pdf.create_stamp("MyStamp")
80
- @pdf.stamp("MyStamp")
81
- @pdf.stamp("MyStamp")
82
- @pdf.stamp("MyStamp")
83
- # I had modified PDF::Inspector::XObject to receive the
84
- # invoke_xobject message and count the number of times it was
85
- # called, but it was only called once, so I reverted checking the
86
- # output with a regular expression
87
- expect(@pdf.render).to match(/(\/Stamp1 Do.*?){3}/m)
88
- end
89
-
90
- it "stamp should render clickable links" do
91
- create_pdf
92
- @pdf.create_stamp 'bar' do
93
- @pdf.text '<b>Prawn</b> <link href="http://github.com">GitHub</link>', inline_format: true
94
- end
95
- @pdf.stamp 'bar'
96
-
97
- output = @pdf.render
98
- objects = output.split("endobj")
99
-
100
- objects.each do |obj|
101
- if obj =~ /\/Type \/Page$/
102
- # The page object must contain the annotation reference
103
- # to render a clickable link
104
- expect(obj).to match(/^\/Annots \[\d \d .\]$/)
105
- end
106
- end
107
- end
108
-
109
- it "resources added during stamp creation should be added to the " \
110
- "stamp XObject, not the page" do
111
- create_pdf
112
- @pdf.create_stamp("MyStamp") do
113
- @pdf.transparent(0.5) { @pdf.circle([100, 100], 10) }
114
- end
115
- @pdf.stamp("MyStamp")
116
-
117
- # Inspector::XObject does not give information about resources, so
118
- # resorting to string matching
119
-
120
- output = @pdf.render
121
- objects = output.split("endobj")
122
- objects.each do |object|
123
- if object =~ /\/Type \/Page$/
124
- expect(object).not_to match(/\/ExtGState/)
125
- elsif object =~ /\/Type \/XObject$/
126
- expect(object).to match(/\/ExtGState/)
127
- end
128
- end
129
- end
130
-
131
- it "stamp stream should be wrapped in a graphic state" do
132
- create_pdf
133
- @pdf.create_stamp("MyStamp") do
134
- @pdf.text "This should have a 'q' before it and a 'Q' after it"
135
- end
136
- @pdf.stamp("MyStamp")
137
- stamps = PDF::Inspector::XObject.analyze(@pdf.render)
138
- expect(stamps.xobject_streams[:Stamp1].data.chomp).to match(/q(.|\s)*Q\Z/)
139
- end
140
-
141
- it "should not add to the page graphic state stack " do
142
- create_pdf
143
- expect(@pdf.state.page.stack.stack.size).to eq(1)
144
-
145
- @pdf.create_stamp("MyStamp") do
146
- @pdf.save_graphics_state
147
- @pdf.save_graphics_state
148
- @pdf.save_graphics_state
149
- @pdf.text "This should have a 'q' before it and a 'Q' after it"
150
- @pdf.restore_graphics_state
151
- end
152
- expect(@pdf.state.page.stack.stack.size).to eq(1)
153
- end
154
-
155
- it "should be able to change fill and stroke colors within the stamp stream" do
156
- create_pdf
157
- @pdf.create_stamp("MyStamp") do
158
- @pdf.fill_color(100, 100, 20, 0)
159
- @pdf.stroke_color(100, 100, 20, 0)
160
- end
161
- @pdf.stamp("MyStamp")
162
- stamps = PDF::Inspector::XObject.analyze(@pdf.render)
163
- stamp_stream = stamps.xobject_streams[:Stamp1].data
164
- expect(stamp_stream).to include("/DeviceCMYK cs\n1.000 1.000 0.200 0.000 scn")
165
- expect(stamp_stream).to include("/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN")
166
- end
167
-
168
- it "should save the color space even when same as current page color space" do
169
- create_pdf
170
- @pdf.stroke_color(100, 100, 20, 0)
171
- @pdf.create_stamp("MyStamp") do
172
- @pdf.stroke_color(100, 100, 20, 0)
173
- end
174
- @pdf.stamp("MyStamp")
175
- stamps = PDF::Inspector::XObject.analyze(@pdf.render)
176
- stamp_stream = stamps.xobject_streams[:Stamp1].data
177
- expect(stamp_stream).to include("/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN")
178
- end
179
- end
@@ -1,208 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- describe "When stroking with default settings" do
6
- before(:each) { create_pdf }
7
- it "cap_style should be :butt" do
8
- expect(@pdf.cap_style).to eq(:butt)
9
- end
10
-
11
- it "join_style should be :miter" do
12
- expect(@pdf.join_style).to eq(:miter)
13
- end
14
-
15
- it "dashed? should be_false" do
16
- expect(@pdf).not_to be_dashed
17
- end
18
- end
19
-
20
- describe "Cap styles" do
21
- before(:each) { create_pdf }
22
-
23
- it "should be able to use assignment operator" do
24
- @pdf.cap_style = :round
25
- expect(@pdf.cap_style).to eq(:round)
26
- end
27
-
28
- describe "#cap_style(:butt)" do
29
- it "rendered PDF should include butt style cap" do
30
- @pdf.cap_style(:butt)
31
- cap_style = PDF::Inspector::Graphics::CapStyle.analyze(@pdf.render).cap_style
32
- expect(cap_style).to eq(0)
33
- end
34
- end
35
-
36
- describe "#cap_style(:round)" do
37
- it "rendered PDF should include round style cap" do
38
- @pdf.cap_style(:round)
39
- cap_style = PDF::Inspector::Graphics::CapStyle.analyze(@pdf.render).cap_style
40
- expect(cap_style).to eq(1)
41
- end
42
- end
43
-
44
- describe "#cap_style(:projecting_square)" do
45
- it "rendered PDF should include projecting_square style cap" do
46
- @pdf.cap_style(:projecting_square)
47
- cap_style = PDF::Inspector::Graphics::CapStyle.analyze(@pdf.render).cap_style
48
- expect(cap_style).to eq(2)
49
- end
50
- end
51
-
52
- it "should carry the current cap style settings over to new pages" do
53
- @pdf.cap_style(:round)
54
- @pdf.start_new_page
55
- cap_styles = PDF::Inspector::Graphics::CapStyle.analyze(@pdf.render)
56
- expect(cap_styles.cap_style_count).to eq(2)
57
- expect(cap_styles.cap_style).to eq(1)
58
- end
59
- end
60
-
61
- describe "Join styles" do
62
- before(:each) { create_pdf }
63
-
64
- it "should be able to use assignment operator" do
65
- @pdf.join_style = :round
66
- expect(@pdf.join_style).to eq(:round)
67
- end
68
-
69
- describe "#join_style(:miter)" do
70
- it "rendered PDF should include miter style join" do
71
- @pdf.join_style(:miter)
72
- join_style = PDF::Inspector::Graphics::JoinStyle.analyze(@pdf.render).join_style
73
- expect(join_style).to eq(0)
74
- end
75
- end
76
-
77
- describe "#join_style(:round)" do
78
- it "rendered PDF should include round style join" do
79
- @pdf.join_style(:round)
80
- join_style = PDF::Inspector::Graphics::JoinStyle.analyze(@pdf.render).join_style
81
- expect(join_style).to eq(1)
82
- end
83
- end
84
-
85
- describe "#join_style(:bevel)" do
86
- it "rendered PDF should include bevel style join" do
87
- @pdf.join_style(:bevel)
88
- join_style = PDF::Inspector::Graphics::JoinStyle.analyze(@pdf.render).join_style
89
- expect(join_style).to eq(2)
90
- end
91
- end
92
-
93
- it "should carry the current join style settings over to new pages" do
94
- @pdf.join_style(:round)
95
- @pdf.start_new_page
96
- join_styles = PDF::Inspector::Graphics::JoinStyle.analyze(@pdf.render)
97
- expect(join_styles.join_style_count).to eq(2)
98
- expect(join_styles.join_style).to eq(1)
99
- end
100
- end
101
-
102
- describe "Dashes" do
103
- before(:each) { create_pdf }
104
-
105
- it "should be able to use assignment operator" do
106
- @pdf.dash = 2
107
- expect(@pdf).to be_dashed
108
- end
109
-
110
- describe "setting a dash" do
111
- it "dashed? should be_true" do
112
- @pdf.dash(2)
113
- expect(@pdf).to be_dashed
114
- end
115
- it "rendered PDF should include a stroked dash" do
116
- @pdf.dash(2)
117
- dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
118
- expect(dashes.stroke_dash).to eq([[2, 2], 0])
119
- end
120
- end
121
-
122
- describe "setting a dash by passing a single argument" do
123
- it "space between dashes should be the same length as the dash in the rendered PDF" do
124
- @pdf.dash(2)
125
- dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
126
- expect(dashes.stroke_dash).to eq([[2, 2], 0])
127
- end
128
- end
129
-
130
- describe "with a space option that differs from the first argument" do
131
- it "space between dashes in the rendered PDF should be different length than the length of the dash" do
132
- @pdf.dash(2, :space => 3)
133
- dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
134
- expect(dashes.stroke_dash).to eq([[2, 3], 0])
135
- end
136
- end
137
-
138
- describe "with a non-zero phase option" do
139
- it "rendered PDF should include a non-zero phase" do
140
- @pdf.dash(2, :phase => 1)
141
- dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
142
- expect(dashes.stroke_dash).to eq([[2, 2], 1])
143
- end
144
- end
145
-
146
- describe "setting a dash by using an array" do
147
- it "dash and spaces should be set from the array" do
148
- @pdf.dash([1, 2, 3, 4])
149
- dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
150
- expect(dashes.stroke_dash).to eq([[1, 2, 3, 4], 0])
151
- end
152
- it "space options has to be ignored" do
153
- @pdf.dash([1, 2, 3, 4], :space => 3)
154
- dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
155
- expect(dashes.stroke_dash).to eq([[1, 2, 3, 4], 0])
156
- end
157
- it "phase options should be correctly used" do
158
- @pdf.dash([1, 2, 3, 4], :phase => 3)
159
- dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
160
- expect(dashes.stroke_dash).to eq([[1, 2, 3, 4], 3])
161
- end
162
- end
163
-
164
- describe "clearing stroke dash" do
165
- it "should restore solid line" do
166
- @pdf.dash(2)
167
- @pdf.undash
168
- dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
169
- expect(dashes.stroke_dash).to eq([[], 0])
170
- end
171
- end
172
-
173
- it "should carry the current dash settings over to new pages" do
174
- @pdf.dash(2)
175
- @pdf.start_new_page
176
- dashes = PDF::Inspector::Graphics::Dash.analyze(@pdf.render)
177
- expect(dashes.stroke_dash_count).to eq(2)
178
- expect(dashes.stroke_dash).to eq([[2, 2], 0])
179
- end
180
-
181
- describe "#dashed?" do
182
- it "an initial document should not be dashed" do
183
- expect(@pdf.dashed?).to eq(false)
184
- end
185
-
186
- it "should return true if any of the currently active settings are dashed" do
187
- @pdf.dash(2)
188
- @pdf.save_graphics_state
189
- expect(@pdf.dashed?).to eq(true)
190
- end
191
-
192
- it "should return false if the document was most recently undashed" do
193
- @pdf.dash(2)
194
- @pdf.save_graphics_state
195
- @pdf.undash
196
- @pdf.save_graphics_state
197
- expect(@pdf.dashed?).to eq(false)
198
- end
199
-
200
- it "should return true when restoring to a state that was dashed" do
201
- @pdf.dash(2)
202
- @pdf.save_graphics_state
203
- @pdf.undash
204
- @pdf.restore_graphics_state
205
- expect(@pdf.dashed?).to eq(true)
206
- end
207
- end
208
- end