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,83 +0,0 @@
1
- %PDF-1.3
2
- %����
3
- 1 0 obj
4
- << /Creator (Prawn)
5
- /Producer (Prawn)
6
- >>
7
- endobj
8
- 2 0 obj
9
- << /Type /Pages
10
- /Count 1
11
- /Kids [5 0 R]
12
- >>
13
- endobj
14
- 3 0 obj
15
- << /Type /Catalog
16
- /Pages 2 0 R
17
- >>
18
- endobj
19
- 4 0 obj
20
- << /Length 275
21
- >>
22
- stream
23
- 0.000 0.000 0.000 rg
24
- 0.000 0.000 0.000 RG
25
- q
26
- 0.000 0.000 1.000 rg
27
-
28
- BT
29
- 36 733.024 Td
30
- /F1.0 32 Tf
31
- [<412073616d706c65205044462074686174206861732074686520706167650a>] TJ
32
- ET
33
-
34
-
35
- BT
36
- 36 696.032 Td
37
- /F1.0 32 Tf
38
- [<7265736f757263657320617320616e20696e646972656374206f626a656374>] TJ
39
- ET
40
-
41
- Q
42
-
43
- endstream
44
- endobj
45
- 5 0 obj
46
- << /Resources 6 0 R
47
- /Type /Page
48
- /Contents 4 0 R
49
- /MediaBox [0 0 612.0 792.0]
50
- /Parent 2 0 R
51
- >>
52
- endobj
53
- 6 0 obj
54
- << /ProcSet [/PDF /Text /ImageB /ImageC /ImageI]
55
- /Font << /F1.0 7 0 R
56
- >>
57
- >>
58
- endobj
59
- 7 0 obj
60
- << /Subtype /Type1
61
- /Type /Font
62
- /Encoding /WinAnsiEncoding
63
- /BaseFont /Helvetica
64
- >>
65
- endobj
66
- xref
67
- 0 8
68
- 0000000000 65535 f
69
- 0000000015 00000 n
70
- 0000000071 00000 n
71
- 0000000128 00000 n
72
- 0000000177 00000 n
73
- 0000000503 00000 n
74
- 0000000611 00000 n
75
- 0000000702 00000 n
76
- trailer
77
- << /Size 8
78
- /Info 1 0 R
79
- /Root 3 0 R
80
- >>
81
- startxref
82
- 799
83
- %%EOF
@@ -1,90 +0,0 @@
1
- %PDF-1.3
2
- %����
3
- 1 0 obj
4
- << /Creator (Prawn)
5
- /Producer (Prawn)
6
- >>
7
- endobj
8
- 2 0 obj
9
- << /Count 2
10
- /Kids [5 0 R 7 0 R]
11
- /Type /Pages
12
- >>
13
- endobj
14
- 3 0 obj
15
- << /Type /Catalog
16
- /Pages 2 0 R
17
- >>
18
- endobj
19
- 4 0 obj
20
- << /Length 195
21
- >>
22
- stream
23
- 0.000 0.000 0.000 rg
24
- 0.000 0.000 0.000 RG
25
- q
26
- 1.000 0.000 0.000 rg
27
- 136.000 286.000 m
28
- 236.000 336.000 l
29
- 336.000 286.000 l
30
- 336.000 186.000 l
31
- 236.000 136.000 l
32
- 136.000 186.000 l
33
- 136.000 286.000 l
34
- f
35
- Q
36
-
37
- endstream
38
- endobj
39
- 5 0 obj
40
- << /Contents 4 0 R
41
- /Parent 2 0 R
42
- /MediaBox [0 0 612.0 792.0]
43
- /Type /Page
44
- >>
45
- endobj
46
- 6 0 obj
47
- << /Length 195
48
- >>
49
- stream
50
- 1.000 0.000 0.000 rg
51
- 0.000 0.000 0.000 RG
52
- q
53
- 1.000 0.000 0.000 rg
54
- 136.000 286.000 m
55
- 236.000 336.000 l
56
- 336.000 286.000 l
57
- 336.000 186.000 l
58
- 236.000 136.000 l
59
- 136.000 186.000 l
60
- 136.000 286.000 l
61
- f
62
- Q
63
-
64
- endstream
65
- endobj
66
- 7 0 obj
67
- << /Contents 6 0 R
68
- /Parent 2 0 R
69
- /MediaBox [0 0 612.0 792.0]
70
- /Type /Page
71
- >>
72
- endobj
73
- xref
74
- 0 8
75
- 0000000000 65535 f
76
- 0000000015 00000 n
77
- 0000000071 00000 n
78
- 0000000134 00000 n
79
- 0000000183 00000 n
80
- 0000000429 00000 n
81
- 0000000520 00000 n
82
- 0000000766 00000 n
83
- trailer
84
- << /Info 1 0 R
85
- /Root 3 0 R
86
- /Size 8
87
- >>
88
- startxref
89
- 857
90
- %%EOF
@@ -1,61 +0,0 @@
1
- %PDF-1.6
2
- %????
3
- 1 0 obj
4
- << /Creator (Prawn)
5
- /Producer (Prawn)
6
- >>
7
- endobj
8
- 2 0 obj
9
- << /Kids [5 0 R]
10
- /Type /Pages
11
- /Count 1
12
- >>
13
- endobj
14
- 3 0 obj
15
- << /Type /Catalog
16
- /Pages 2 0 R
17
- >>
18
- endobj
19
- 4 0 obj
20
- << /Length 195
21
- >>
22
- stream
23
- 0.000 0.000 0.000 rg
24
- 0.000 0.000 0.000 RG
25
- q
26
- 1.000 0.000 0.000 rg
27
- 136.000 286.000 m
28
- 236.000 336.000 l
29
- 336.000 286.000 l
30
- 336.000 186.000 l
31
- 236.000 136.000 l
32
- 136.000 186.000 l
33
- 136.000 286.000 l
34
- f
35
- Q
36
-
37
- endstream
38
- endobj
39
- 5 0 obj
40
- << /Contents 4 0 R
41
- /Type /Page
42
- /MediaBox [0 0 612.0 792.0]
43
- /Parent 2 0 R
44
- >>
45
- endobj
46
- xref
47
- 0 6
48
- 0000000000 65535 f
49
- 0000000015 00000 n
50
- 0000000071 00000 n
51
- 0000000128 00000 n
52
- 0000000177 00000 n
53
- 0000000423 00000 n
54
- trailer
55
- << /Info 1 0 R
56
- /Size 6
57
- /Root 3 0 R
58
- >>
59
- startxref
60
- 514
61
- %%EOF
@@ -1 +0,0 @@
1
- ���C���y�[�W
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require_relative "../../lib/prawn"
4
-
5
- images = [
6
- ["Type 0", "#{Prawn::BASEDIR}/data/images/web-links.png"],
7
- ["Type 2", "#{Prawn::BASEDIR}/data/images/ruport.png"],
8
- ["Type 3", "#{Prawn::BASEDIR}/data/images/indexed_color.png"],
9
- ["Type 4", "#{Prawn::BASEDIR}/data/images/page_white_text.png"],
10
- ["Type 6", "#{Prawn::BASEDIR}/data/images/dice.png"]
11
- ]
12
-
13
- Prawn::Document.generate("png_types.pdf", :page_size => "A5") do
14
- images.each do |header, file|
15
- start_new_page unless header.include?("0")
16
-
17
- fill_color "FF0000"
18
-
19
- fill_rectangle bounds.top_left, bounds.width, bounds.height
20
- text header
21
-
22
- image file, :at => [50, 450]
23
- end
24
- end
@@ -1,67 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- describe "When creating annotations" do
6
- before(:each) { create_pdf }
7
-
8
- it "should append annotation to current page" do
9
- @pdf.start_new_page
10
- @pdf.annotate(:Rect => [0, 0, 10, 10], :Subtype => :Text, :Contents => "Hello world!")
11
- PDF::Reader.open(StringIO.new(@pdf.render)) do |pdf|
12
- expect(pdf.page(1).attributes[:Annots]).to be_nil
13
- expect(pdf.page(2).attributes[:Annots].size).to eq(1)
14
- end
15
- end
16
-
17
- it "should force :Type to be :Annot" do
18
- opts = @pdf.annotate(:Rect => [0, 0, 10, 10], :Subtype => :Text, :Contents => "Hello world!")
19
- expect(opts[:Type]).to eq(:Annot)
20
- opts = @pdf.annotate(:Type => :Bogus, :Rect => [0, 0, 10, 10], :Subtype => :Text, :Contents => "Hello world!")
21
- expect(opts[:Type]).to eq(:Annot)
22
- end
23
- end
24
-
25
- describe "When creating text annotations" do
26
- before(:each) do
27
- @rect = [0, 0, 10, 10]
28
- @content = "Hello, world!"
29
- create_pdf
30
- end
31
-
32
- it "should build appropriate annotation" do
33
- opts = @pdf.text_annotation(@rect, @content)
34
- expect(opts[:Type]).to eq(:Annot)
35
- expect(opts[:Subtype]).to eq(:Text)
36
- expect(opts[:Rect]).to eq(@rect)
37
- expect(opts[:Contents]).to eq(@content)
38
- end
39
-
40
- it "should merge extra options" do
41
- opts = @pdf.text_annotation(@rect, @content, :Open => true, :Subtype => :Bogus)
42
- expect(opts[:Subtype]).to eq(:Text)
43
- expect(opts[:Open]).to eq(true)
44
- end
45
- end
46
-
47
- describe "When creating link annotations" do
48
- before(:each) do
49
- @rect = [0, 0, 10, 10]
50
- @dest = "home"
51
- create_pdf
52
- end
53
-
54
- it "should build appropriate annotation" do
55
- opts = @pdf.link_annotation(@rect, :Dest => @dest)
56
- expect(opts[:Type]).to eq(:Annot)
57
- expect(opts[:Subtype]).to eq(:Link)
58
- expect(opts[:Rect]).to eq(@rect)
59
- expect(opts[:Dest]).to eq(@dest)
60
- end
61
-
62
- it "should merge extra options" do
63
- opts = @pdf.link_annotation(@rect, :Dest => @dest, :Subtype => :Bogus)
64
- expect(opts[:Subtype]).to eq(:Link)
65
- expect(opts[:Dest]).to eq(@dest)
66
- end
67
- end
@@ -1,501 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- describe "A bounding box" do
6
- before(:each) do
7
- @x = 100
8
- @y = 125
9
- @width = 50
10
- @height = 75
11
- @box = Prawn::Document::BoundingBox.new(nil,
12
- nil,
13
- [@x, @y],
14
- :width => @width,
15
- :height => @height)
16
- end
17
-
18
- it "should have an anchor at (x, y - height)" do
19
- expect(@box.anchor).to eq([@x, @y - @height])
20
- end
21
-
22
- it "should have a left boundary of 0" do
23
- expect(@box.left).to eq(0)
24
- end
25
-
26
- it "should have a right boundary equal to the width" do
27
- expect(@box.right).to eq(@width)
28
- end
29
-
30
- it "should have a top boundary of height" do
31
- expect(@box.top).to eq(@height)
32
- end
33
-
34
- it "should have a bottom boundary of 0" do
35
- expect(@box.bottom).to eq(0)
36
- end
37
-
38
- it "should have a top-left of [0,height]" do
39
- expect(@box.top_left).to eq([0, @height])
40
- end
41
-
42
- it "should have a top-right of [width,height]" do
43
- expect(@box.top_right).to eq([@width, @height])
44
- end
45
-
46
- it "should have a bottom-left of [0,0]" do
47
- expect(@box.bottom_left).to eq([0, 0])
48
- end
49
-
50
- it "should have a bottom-right of [width,0]" do
51
- expect(@box.bottom_right).to eq([@width, 0])
52
- end
53
-
54
- it "should have an absolute left boundary of x" do
55
- expect(@box.absolute_left).to eq(@x)
56
- end
57
-
58
- it "should have an absolute right boundary of x + width" do
59
- expect(@box.absolute_right).to eq(@x + @width)
60
- end
61
-
62
- it "should have an absolute top boundary of y" do
63
- expect(@box.absolute_top).to eq(@y)
64
- end
65
-
66
- it "should have an absolute bottom boundary of y - height" do
67
- expect(@box.absolute_bottom).to eq(@y - @height)
68
- end
69
-
70
- it "should have an absolute bottom-left of [x,y-height]" do
71
- expect(@box.absolute_bottom_left).to eq([@x, @y - @height])
72
- end
73
-
74
- it "should have an absolute bottom-right of [x+width,y-height]" do
75
- expect(@box.absolute_bottom_right).to eq([@x + @width , @y - @height])
76
- end
77
-
78
- it "should have an absolute top-left of [x,y]" do
79
- expect(@box.absolute_top_left).to eq([@x, @y])
80
- end
81
-
82
- it "should have an absolute top-right of [x+width,y]" do
83
- expect(@box.absolute_top_right).to eq([@x + @width, @y])
84
- end
85
-
86
- it "should require width to be set" do
87
- expect do
88
- Prawn::Document::BoundingBox.new(nil, nil, [100, 100])
89
- end.to raise_error(ArgumentError)
90
- end
91
-
92
- it "should raise_error an ArgumentError if a block is not passed" do
93
- pdf = Prawn::Document.new
94
- expect do
95
- pdf.bounding_box([0, 0], :width => 200)
96
- end.to raise_error(ArgumentError)
97
- end
98
- end
99
-
100
- describe "drawing bounding boxes" do
101
- before(:each) { create_pdf }
102
-
103
- it "should not stomp on the arguments to bounding_box" do
104
- pdf = Prawn::Document.new
105
- x = [100, 500]
106
- pdf.bounding_box x, :width => 100 do
107
- pdf.text "bork-bork-bork"
108
- end
109
- expect(x).to eq([100, 500])
110
- end
111
-
112
- it "should restore Document#bounds to the correct margin box on exit" do
113
- pdf = Prawn::Document.new(:margin => 200)
114
-
115
- # add a multi-page bounding box
116
- pdf.bounding_box([100, pdf.bounds.top], :width => 400) do
117
- pdf.text "The rain in spain falls mainly in the plains.\n" * 30
118
- end
119
-
120
- pdf.start_new_page(:margin => 0)
121
-
122
- x_min, y_min, x_max, y_max = pdf.page.dimensions
123
-
124
- expect(pdf.bounds.absolute_top_left).to eq([x_min, y_max])
125
- expect(pdf.bounds.absolute_bottom_right).to eq([x_max, y_min])
126
- end
127
-
128
- it "should restore the parent bounding box when calls are nested" do
129
- @pdf.bounding_box [100, 500], :width => 300, :height => 300 do
130
- expect(@pdf.bounds.absolute_top).to eq(500 + @pdf.margin_box.absolute_bottom)
131
- expect(@pdf.bounds.absolute_left).to eq(100 + @pdf.margin_box.absolute_left)
132
-
133
- parent_box = @pdf.bounds
134
-
135
- @pdf.bounding_box [50, 200], :width => 100, :height => 100 do
136
- expect(@pdf.bounds.absolute_top).to eq(200 + parent_box.absolute_bottom)
137
- expect(@pdf.bounds.absolute_left).to eq(50 + parent_box.absolute_left)
138
- end
139
-
140
- expect(@pdf.bounds.absolute_top).to eq(500 + @pdf.margin_box.absolute_bottom)
141
- expect(@pdf.bounds.absolute_left).to eq(100 + @pdf.margin_box.absolute_left)
142
- end
143
- end
144
-
145
- it "should calculate a height if none is specified" do
146
- @pdf.bounding_box([100, 500], :width => 100) do
147
- @pdf.text "The rain in Spain falls mainly on the plains."
148
- end
149
-
150
- expect(@pdf.y).to be_within(0.001).of(458.384)
151
- end
152
-
153
- it "should keep track of the max height the box was stretched to" do
154
- box = @pdf.bounding_box(@pdf.bounds.top_left, :width => 100) do
155
- @pdf.move_down 100
156
- @pdf.move_up 15
157
- end
158
-
159
- expect(box.height).to eq(100)
160
- end
161
-
162
- it "should advance the y-position by bbox.height by default" do
163
- orig_y = @pdf.y
164
- @pdf.bounding_box [0, @pdf.cursor], :width => @pdf.bounds.width, :height => 30 do
165
- @pdf.text "hello"
166
- end
167
- expect(@pdf.y).to be_within(0.001).of(orig_y - 30)
168
- end
169
-
170
- it "should not advance y-position if passed :hold_position => true" do
171
- orig_y = @pdf.y
172
- @pdf.bounding_box [0, @pdf.cursor], :width => @pdf.bounds.width, :hold_position => true do
173
- @pdf.text "hello"
174
- end
175
- # y only advances by height of one line ("hello")
176
- expect(@pdf.y).to be_within(0.001).of(orig_y - @pdf.height_of("hello"))
177
- end
178
-
179
- it "should not advance y-position of a stretchy bbox if it would stretch " \
180
- "the bbox further" do
181
- bottom = @pdf.y = @pdf.margin_box.absolute_bottom
182
- @pdf.bounding_box [0, @pdf.margin_box.top], :width => @pdf.bounds.width do
183
- @pdf.y = bottom
184
- @pdf.text "hello" # starts a new page
185
- end
186
- expect(@pdf.page_count).to eq(2)
187
-
188
- # Restoring the position (to the absolute bottom) would stretch the bbox to
189
- # the bottom of the page, which we don't want. This should be equivalent to
190
- # a bbox with :hold_position => true, where we only advance by the amount
191
- # that was actually drawn.
192
- expect(@pdf.y).to be_within(0.001).of(
193
- @pdf.margin_box.absolute_top - @pdf.height_of("hello")
194
- )
195
- end
196
- end
197
-
198
- describe "Indentation" do
199
- before(:each) { create_pdf }
200
-
201
- it "should temporarily shift the x coordinate and width" do
202
- @pdf.bounding_box([100, 100], :width => 200) do
203
- @pdf.indent(20) do
204
- expect(@pdf.bounds.absolute_left).to eq(120)
205
- expect(@pdf.bounds.width).to eq(180)
206
- end
207
- end
208
- end
209
-
210
- it "should restore the x coordinate and width after block exits" do
211
- @pdf.bounding_box([100, 100], :width => 200) do
212
- @pdf.indent(20) do
213
- # no-op
214
- end
215
- expect(@pdf.bounds.absolute_left).to eq(100)
216
- expect(@pdf.bounds.width).to eq(200)
217
- end
218
- end
219
-
220
- it "should restore the x coordinate and width on error" do
221
- @pdf.bounding_box([100, 100], :width => 200) do
222
- begin
223
- @pdf.indent(20) { fail }
224
- rescue
225
- expect(@pdf.bounds.absolute_left).to eq(100)
226
- expect(@pdf.bounds.width).to eq(200)
227
- end
228
- end
229
- end
230
-
231
- it "should maintain left indentation across a page break" do
232
- original_left = @pdf.bounds.absolute_left
233
-
234
- @pdf.indent(20) do
235
- expect(@pdf.bounds.absolute_left).to eq(original_left + 20)
236
- @pdf.start_new_page
237
- expect(@pdf.bounds.absolute_left).to eq(original_left + 20)
238
- end
239
-
240
- expect(@pdf.bounds.absolute_left).to eq(original_left)
241
- end
242
-
243
- it "should maintain right indentation across a page break" do
244
- original_width = @pdf.bounds.width
245
-
246
- @pdf.indent(0, 20) do
247
- expect(@pdf.bounds.width).to eq(original_width - 20)
248
- @pdf.start_new_page
249
- expect(@pdf.bounds.width).to eq(original_width - 20)
250
- end
251
-
252
- expect(@pdf.bounds.width).to eq(original_width)
253
- end
254
-
255
- it "optionally allows adjustment of the right bound as well" do
256
- @pdf.bounding_box([100, 100], :width => 200) do
257
- @pdf.indent(20, 30) do
258
- expect(@pdf.bounds.absolute_left).to eq(120)
259
- expect(@pdf.bounds.width).to eq(150)
260
- end
261
- expect(@pdf.bounds.absolute_left).to eq(100)
262
- expect(@pdf.bounds.width).to eq(200)
263
- end
264
- end
265
-
266
- describe "in a ColumnBox" do
267
- it "should subtract the given indentation from the available width" do
268
- @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :height => 200, :columns => 2, :spacer => 20) do
269
- width = @pdf.bounds.width
270
- @pdf.indent(20) do
271
- expect(@pdf.bounds.width).to be_within(0.01).of(width - 20)
272
- end
273
- end
274
- end
275
-
276
- it "should subtract right padding from the available width" do
277
- @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :height => 200, :columns => 2, :spacer => 20) do
278
- width = @pdf.bounds.width
279
- @pdf.indent(20, 30) do
280
- expect(@pdf.bounds.width).to be_within(0.01).of(width - 50)
281
- end
282
- end
283
- end
284
-
285
- it "should maintain the same left indentation across column breaks" do
286
- @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
287
- 3.times do |column|
288
- x = @pdf.bounds.left_side
289
- @pdf.indent(20) do
290
- expect(@pdf.bounds.left_side).to eq(x + 20)
291
- end
292
- @pdf.bounds.move_past_bottom
293
- end
294
- end
295
- end
296
-
297
- it "should not change the right margin if only left indentation is requested" do
298
- @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
299
- 3.times do |column|
300
- x = @pdf.bounds.right_side
301
- @pdf.indent(20) do
302
- expect(@pdf.bounds.right_side).to eq(x)
303
- end
304
- @pdf.bounds.move_past_bottom
305
- end
306
- end
307
- end
308
-
309
- it "should maintain the same right indentation across columns" do
310
- @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
311
- 3.times do |column|
312
- x = @pdf.bounds.right_side
313
- @pdf.indent(20, 10) do
314
- expect(@pdf.bounds.right_side).to eq(x - 10)
315
- end
316
- @pdf.bounds.move_past_bottom
317
- end
318
- end
319
- end
320
-
321
- it "should keep the right indentation after nesting indents" do
322
- @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
323
- 3.times do |column|
324
- # I am giving a right indent of 10...
325
- @pdf.indent(20, 10) do
326
- x = @pdf.bounds.right_side
327
- # ...and no right indent here...
328
- @pdf.indent(20) do
329
- # right indent is inherited from the parent!
330
- expect(@pdf.bounds.right_side).to eq(x)
331
- end
332
- end
333
- @pdf.bounds.move_past_bottom
334
- end
335
- end
336
- end
337
-
338
- it "should revert the right indentation if negative indent is given in nested indent" do
339
- @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
340
- 3.times do |column|
341
- x = @pdf.bounds.right_side
342
- @pdf.indent(20, 10) do
343
- # requesting a negative right-indent of equivalent size...
344
- @pdf.indent(20, -10) do
345
- # ...resets the right margin to that of the column!
346
- expect(@pdf.bounds.right_side).to eq(x)
347
- end
348
- end
349
- @pdf.bounds.move_past_bottom
350
- end
351
- end
352
- end
353
-
354
- it "should reduce the available column width by the sum of all nested indents" do
355
- @pdf.column_box([0, @pdf.cursor], :width => @pdf.bounds.width, :columns => 3, :spacer => 15) do
356
- 3.times do |column|
357
- w = @pdf.bounds.width
358
- @pdf.indent(20, 10) do
359
- @pdf.indent(20, 10) do
360
- expect(@pdf.bounds.width).to eq(w - 60)
361
- end
362
- end
363
- @pdf.bounds.move_past_bottom
364
- end
365
- end
366
- end
367
- end
368
- end
369
-
370
- describe "A canvas" do
371
- before(:each) { create_pdf }
372
-
373
- it "should use whatever the last set y position is" do
374
- @pdf.canvas do
375
- @pdf.bounding_box([100, 500], :width => 200) { @pdf.move_down 50 }
376
- end
377
- expect(@pdf.y).to eq(450)
378
- end
379
-
380
- it "should restore the original ypos after execution", :issue => 523 do
381
- doc = Prawn::Document.new(:skip_page_creation => true)
382
- doc.start_new_page
383
-
384
- original_ypos = doc.y
385
-
386
- doc.canvas {}
387
-
388
- expect(doc.y).to eq(original_ypos)
389
- end
390
- end
391
-
392
- describe "Deep-copying" do
393
- it "should create a new object that does not copy @document" do
394
- Prawn::Document.new do |pdf|
395
- orig = pdf.bounds
396
- copy = orig.deep_copy
397
-
398
- expect(copy).not_to eq(pdf.bounds)
399
- expect(copy.document).to be_nil
400
- end
401
- end
402
-
403
- it "should deep-copy parent bounds" do
404
- Prawn::Document.new do |pdf|
405
- outside = pdf.bounds
406
- pdf.bounding_box [100, 100], :width => 100 do
407
- copy = pdf.bounds.deep_copy
408
-
409
- # the parent bounds should have the same parameters
410
- expect(copy.parent.width).to eq(outside.width)
411
- expect(copy.parent.height).to eq(outside.height)
412
-
413
- # but should not be the same object
414
- expect(copy.parent).not_to eq(outside)
415
- end
416
- end
417
- end
418
- end
419
-
420
- describe "Prawn::Document#reference_bounds" do
421
- before(:each) { create_pdf }
422
-
423
- it "should return self for non-stretchy bounds" do
424
- @pdf.bounding_box([0, @pdf.cursor], :width => 100, :height => 100) do
425
- expect(@pdf.reference_bounds).to eq(@pdf.bounds)
426
- end
427
- end
428
-
429
- it "should return the parent bounds if in a stretchy box" do
430
- @pdf.bounding_box([0, @pdf.cursor], :width => 100, :height => 100) do
431
- correct_bounds = @pdf.bounds
432
- @pdf.bounding_box([0, @pdf.cursor], :width => 100) do
433
- expect(@pdf.reference_bounds).to eq(correct_bounds)
434
- end
435
- end
436
- end
437
-
438
- it "should find the non-stretchy box through 2 levels" do
439
- @pdf.bounding_box([0, @pdf.cursor], :width => 100, :height => 100) do
440
- correct_bounds = @pdf.bounds
441
- @pdf.bounding_box([0, @pdf.cursor], :width => 100) do
442
- @pdf.bounding_box([0, @pdf.cursor], :width => 100) do
443
- expect(@pdf.reference_bounds).to eq(correct_bounds)
444
- end
445
- end
446
- end
447
- end
448
-
449
- it "should return the margin box if there's no explicit bbox" do
450
- expect(@pdf.reference_bounds).to eq(@pdf.margin_box)
451
-
452
- @pdf.bounding_box([0, @pdf.cursor], :width => 100) do
453
- expect(@pdf.reference_bounds).to eq(@pdf.margin_box)
454
- end
455
- end
456
-
457
- it "should return the canvas box if we're in a canvas" do
458
- @pdf.canvas do
459
- canvas_box = @pdf.bounds
460
-
461
- expect(@pdf.reference_bounds).to eq(canvas_box)
462
-
463
- @pdf.bounding_box([0, @pdf.cursor], :width => 100) do
464
- expect(@pdf.reference_bounds).to eq(canvas_box)
465
- end
466
- end
467
- end
468
- end
469
-
470
- describe "BoundingBox#move_past_bottom" do
471
- before(:each) { create_pdf }
472
-
473
- it "should ordinarily start a new page" do
474
- @pdf.bounds.move_past_bottom
475
- @pdf.text "Foo"
476
-
477
- pages = PDF::Inspector::Page.analyze(@pdf.render).pages
478
- expect(pages.size).to eq(2)
479
- expect(pages[0][:strings]).to eq([])
480
- expect(pages[1][:strings]).to eq(["Foo"])
481
- end
482
-
483
- it "should move to the top of the next page if it exists already" do
484
- # save away the y-position at the top of a page
485
- top_y = @pdf.y
486
-
487
- # create a blank page but go to the page before it
488
- @pdf.start_new_page
489
- @pdf.go_to_page 1
490
- @pdf.text "Foo"
491
-
492
- @pdf.bounds.move_past_bottom
493
- expect(@pdf.y).to be_within(0.001).of(top_y)
494
- @pdf.text "Bar"
495
-
496
- pages = PDF::Inspector::Page.analyze(@pdf.render).pages
497
- expect(pages.size).to eq(2)
498
- expect(pages[0][:strings]).to eq(["Foo"])
499
- expect(pages[1][:strings]).to eq(["Bar"])
500
- end
501
- end