prawn 1.1.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (309) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/.yardopts +1 -0
  4. data/GPLv2 +20 -21
  5. data/Gemfile +3 -9
  6. data/Rakefile +9 -40
  7. data/lib/prawn/document/bounding_box.rb +54 -40
  8. data/lib/prawn/document/column_box.rb +8 -10
  9. data/lib/prawn/document/internals.rb +39 -146
  10. data/lib/prawn/document/span.rb +23 -17
  11. data/lib/prawn/document.rb +217 -182
  12. data/lib/prawn/encoding.rb +69 -101
  13. data/lib/prawn/errors.rb +47 -43
  14. data/lib/prawn/font.rb +124 -104
  15. data/lib/prawn/font_metric_cache.rb +23 -21
  16. data/lib/prawn/fonts/afm.rb +292 -0
  17. data/lib/prawn/{font → fonts}/dfont.rb +5 -12
  18. data/lib/prawn/fonts/otf.rb +11 -0
  19. data/lib/prawn/fonts/ttc.rb +36 -0
  20. data/lib/prawn/{font → fonts}/ttf.rb +140 -88
  21. data/lib/prawn/graphics/blend_mode.rb +65 -0
  22. data/lib/prawn/graphics/cap_style.rb +5 -5
  23. data/lib/prawn/graphics/color.rb +46 -44
  24. data/lib/prawn/graphics/dash.rb +27 -11
  25. data/lib/prawn/graphics/join_style.rb +11 -6
  26. data/lib/prawn/graphics/patterns.rb +220 -78
  27. data/lib/prawn/graphics/transformation.rb +20 -12
  28. data/lib/prawn/graphics/transparency.rb +20 -18
  29. data/lib/prawn/graphics.rb +153 -115
  30. data/lib/prawn/grid.rb +93 -50
  31. data/lib/prawn/image_handler.rb +4 -4
  32. data/lib/prawn/images/image.rb +3 -2
  33. data/lib/prawn/images/jpg.rb +31 -24
  34. data/lib/prawn/images/png.rb +101 -68
  35. data/lib/prawn/images.rb +64 -56
  36. data/lib/prawn/measurement_extensions.rb +10 -9
  37. data/lib/prawn/measurements.rb +20 -23
  38. data/lib/prawn/outline.rb +96 -75
  39. data/lib/prawn/repeater.rb +16 -16
  40. data/lib/prawn/security/arcfour.rb +2 -2
  41. data/lib/prawn/security.rb +100 -85
  42. data/lib/prawn/soft_mask.rb +37 -38
  43. data/lib/prawn/stamp.rb +28 -13
  44. data/lib/prawn/text/box.rb +24 -29
  45. data/lib/prawn/text/formatted/arranger.rb +108 -63
  46. data/lib/prawn/text/formatted/box.rb +187 -124
  47. data/lib/prawn/text/formatted/fragment.rb +24 -20
  48. data/lib/prawn/text/formatted/line_wrap.rb +133 -73
  49. data/lib/prawn/text/formatted/parser.rb +147 -127
  50. data/lib/prawn/text/formatted/wrap.rb +48 -35
  51. data/lib/prawn/text/formatted.rb +5 -5
  52. data/lib/prawn/text.rb +103 -68
  53. data/lib/prawn/transformation_stack.rb +44 -0
  54. data/lib/prawn/utilities.rb +10 -22
  55. data/lib/prawn/version.rb +5 -0
  56. data/lib/prawn/view.rb +101 -0
  57. data/lib/prawn.rb +39 -54
  58. data/manual/basic_concepts/adding_pages.rb +6 -7
  59. data/manual/basic_concepts/basic_concepts.rb +34 -25
  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 +8 -9
  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 +48 -0
  66. data/manual/bounding_box/bounding_box.rb +30 -28
  67. data/manual/bounding_box/bounds.rb +12 -13
  68. data/manual/bounding_box/canvas.rb +7 -8
  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 +25 -18
  72. data/manual/bounding_box/russian_boxes.rb +18 -18
  73. data/manual/bounding_box/stretchy.rb +12 -14
  74. data/manual/contents.rb +28 -22
  75. data/manual/cover.rb +33 -32
  76. data/manual/document_and_page_options/background.rb +15 -13
  77. data/manual/document_and_page_options/document_and_page_options.rb +24 -22
  78. data/manual/document_and_page_options/metadata.rb +20 -18
  79. data/manual/document_and_page_options/page_margins.rb +18 -20
  80. data/manual/document_and_page_options/page_size.rb +13 -13
  81. data/manual/document_and_page_options/print_scaling.rb +18 -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 +5 -6
  88. data/manual/graphics/fill_rules.rb +12 -11
  89. data/manual/graphics/gradients.rb +27 -21
  90. data/manual/graphics/graphics.rb +46 -40
  91. data/manual/graphics/helper.rb +19 -9
  92. data/manual/graphics/line_width.rb +8 -7
  93. data/manual/graphics/lines_and_curves.rb +8 -9
  94. data/manual/graphics/polygon.rb +6 -8
  95. data/manual/graphics/rectangle.rb +4 -5
  96. data/manual/graphics/rotate.rb +6 -9
  97. data/manual/graphics/scale.rb +14 -13
  98. data/manual/graphics/soft_masks.rb +4 -6
  99. data/manual/graphics/stroke_cap.rb +7 -8
  100. data/manual/graphics/stroke_dash.rb +15 -16
  101. data/manual/graphics/stroke_join.rb +6 -7
  102. data/manual/graphics/translate.rb +10 -10
  103. data/manual/graphics/transparency.rb +7 -9
  104. data/manual/how_to_read_this_manual.rb +8 -9
  105. data/manual/images/absolute_position.rb +6 -7
  106. data/manual/images/fit.rb +7 -8
  107. data/manual/images/horizontal.rb +10 -11
  108. data/manual/images/images.rb +28 -27
  109. data/manual/images/plain_image.rb +5 -6
  110. data/manual/images/scale.rb +9 -10
  111. data/manual/images/vertical.rb +16 -14
  112. data/manual/images/width_and_height.rb +10 -11
  113. data/manual/layout/boxes.rb +10 -11
  114. data/manual/layout/content.rb +9 -10
  115. data/manual/layout/layout.rb +17 -18
  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 +22 -21
  120. data/manual/outline/sections_and_pages.rb +17 -18
  121. data/manual/repeatable_content/alternate_page_numbering.rb +36 -0
  122. data/manual/repeatable_content/page_numbering.rb +17 -16
  123. data/manual/repeatable_content/repeatable_content.rb +27 -23
  124. data/manual/repeatable_content/repeater.rb +15 -16
  125. data/manual/repeatable_content/stamp.rb +14 -15
  126. data/manual/security/encryption.rb +8 -11
  127. data/manual/security/permissions.rb +20 -15
  128. data/manual/security/security.rb +18 -18
  129. data/manual/table.rb +16 -0
  130. data/manual/text/alignment.rb +16 -17
  131. data/manual/text/color.rb +12 -12
  132. data/manual/text/column_box.rb +9 -11
  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 +10 -8
  137. data/manual/text/formatted_callbacks.rb +33 -23
  138. data/manual/text/formatted_text.rb +36 -25
  139. data/manual/text/free_flowing_text.rb +22 -23
  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 +15 -10
  145. data/manual/text/positioned_text.rb +16 -17
  146. data/manual/text/registering_families.rb +27 -24
  147. data/manual/text/rendering_and_color.rb +9 -10
  148. data/manual/text/right_to_left_text.rb +30 -19
  149. data/manual/text/rotation.rb +33 -24
  150. data/manual/text/single_usage.rb +8 -9
  151. data/manual/text/text.rb +56 -54
  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 +24 -17
  155. data/manual/text/utf8.rb +12 -13
  156. data/manual/text/win_ansi_charset.rb +28 -25
  157. data/prawn.gemspec +45 -50
  158. data/spec/extensions/encoding_helpers.rb +3 -3
  159. data/spec/prawn/document/bounding_box_spec.rb +550 -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 +44 -0
  167. data/spec/prawn/document_spec.rb +805 -0
  168. data/spec/prawn/font_metric_cache_spec.rb +54 -0
  169. data/spec/prawn/font_spec.rb +544 -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 +872 -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 +229 -0
  178. data/spec/prawn/measurements_extensions_spec.rb +24 -0
  179. data/spec/prawn/outline_spec.rb +512 -0
  180. data/spec/prawn/repeater_spec.rb +166 -0
  181. data/spec/prawn/soft_mask_spec.rb +74 -0
  182. data/spec/prawn/stamp_spec.rb +173 -0
  183. data/spec/prawn/text/box_spec.rb +1110 -0
  184. data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
  185. data/spec/prawn/text/formatted/box_spec.rb +849 -0
  186. data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
  187. data/spec/prawn/text/formatted/line_wrap_spec.rb +495 -0
  188. data/spec/prawn/text/formatted/parser_spec.rb +697 -0
  189. data/spec/prawn/text_draw_text_spec.rb +150 -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 -25
  198. data.tar.gz.sig +0 -0
  199. metadata +113 -276
  200. metadata.gz.sig +0 -0
  201. data/data/encodings/win_ansi.txt +0 -29
  202. data/data/images/16bit.alpha +0 -0
  203. data/data/images/16bit.color +0 -0
  204. data/data/images/16bit.png +0 -0
  205. data/data/images/arrow.png +0 -0
  206. data/data/images/arrow2.png +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/letterhead.jpg +0 -0
  215. data/data/images/license.md +0 -8
  216. data/data/images/page_white_text.alpha +0 -0
  217. data/data/images/page_white_text.color +0 -0
  218. data/data/images/page_white_text.png +0 -0
  219. data/data/images/pigs.jpg +0 -0
  220. data/data/images/prawn.png +0 -0
  221. data/data/images/ruport.png +0 -0
  222. data/data/images/ruport_data.dat +0 -0
  223. data/data/images/ruport_transparent.png +0 -0
  224. data/data/images/ruport_type0.png +0 -0
  225. data/data/images/stef.jpg +0 -0
  226. data/data/images/tru256.bmp +0 -0
  227. data/data/images/web-links.dat +0 -1
  228. data/data/images/web-links.png +0 -0
  229. data/data/pdfs/complex_template.pdf +0 -0
  230. data/data/pdfs/contains_ttf_font.pdf +0 -0
  231. data/data/pdfs/encrypted.pdf +0 -0
  232. data/data/pdfs/form.pdf +1 -819
  233. data/data/pdfs/hexagon.pdf +0 -61
  234. data/data/pdfs/indirect_reference.pdf +0 -86
  235. data/data/pdfs/multipage_template.pdf +0 -127
  236. data/data/pdfs/nested_pages.pdf +0 -118
  237. data/data/pdfs/page_without_mediabox.pdf +0 -193
  238. data/data/pdfs/resources_as_indirect_object.pdf +0 -83
  239. data/data/pdfs/two_hexagons.pdf +0 -90
  240. data/data/pdfs/version_1_6.pdf +0 -61
  241. data/data/shift_jis_text.txt +0 -1
  242. data/lib/prawn/document/graphics_state.rb +0 -73
  243. data/lib/prawn/font/afm.rb +0 -247
  244. data/lib/prawn/table/cell/image.rb +0 -69
  245. data/lib/prawn/table/cell/in_table.rb +0 -33
  246. data/lib/prawn/table/cell/span_dummy.rb +0 -93
  247. data/lib/prawn/table/cell/subtable.rb +0 -66
  248. data/lib/prawn/table/cell/text.rb +0 -154
  249. data/lib/prawn/table/cell.rb +0 -772
  250. data/lib/prawn/table/cells.rb +0 -255
  251. data/lib/prawn/table/column_width_calculator.rb +0 -182
  252. data/lib/prawn/table.rb +0 -644
  253. data/manual/table/basic_block.rb +0 -53
  254. data/manual/table/before_rendering_page.rb +0 -26
  255. data/manual/table/cell_border_lines.rb +0 -24
  256. data/manual/table/cell_borders_and_bg.rb +0 -31
  257. data/manual/table/cell_dimensions.rb +0 -30
  258. data/manual/table/cell_text.rb +0 -38
  259. data/manual/table/column_widths.rb +0 -30
  260. data/manual/table/content_and_subtables.rb +0 -39
  261. data/manual/table/creation.rb +0 -27
  262. data/manual/table/filtering.rb +0 -36
  263. data/manual/table/flow_and_header.rb +0 -17
  264. data/manual/table/image_cells.rb +0 -33
  265. data/manual/table/position.rb +0 -29
  266. data/manual/table/row_colors.rb +0 -20
  267. data/manual/table/span.rb +0 -30
  268. data/manual/table/style.rb +0 -22
  269. data/manual/table/table.rb +0 -52
  270. data/manual/table/width.rb +0 -27
  271. data/spec/acceptance/png.rb +0 -25
  272. data/spec/annotations_spec.rb +0 -74
  273. data/spec/bounding_box_spec.rb +0 -510
  274. data/spec/cell_spec.rb +0 -629
  275. data/spec/column_box_spec.rb +0 -65
  276. data/spec/destinations_spec.rb +0 -15
  277. data/spec/document_spec.rb +0 -730
  278. data/spec/extensions/mocha.rb +0 -46
  279. data/spec/font_metric_cache_spec.rb +0 -52
  280. data/spec/font_spec.rb +0 -449
  281. data/spec/formatted_text_arranger_spec.rb +0 -421
  282. data/spec/formatted_text_box_spec.rb +0 -639
  283. data/spec/formatted_text_fragment_spec.rb +0 -298
  284. data/spec/graphics_spec.rb +0 -669
  285. data/spec/grid_spec.rb +0 -96
  286. data/spec/image_handler_spec.rb +0 -54
  287. data/spec/images_spec.rb +0 -153
  288. data/spec/inline_formatted_text_parser_spec.rb +0 -564
  289. data/spec/jpg_spec.rb +0 -25
  290. data/spec/line_wrap_spec.rb +0 -344
  291. data/spec/measurement_units_spec.rb +0 -25
  292. data/spec/outline_spec.rb +0 -430
  293. data/spec/png_spec.rb +0 -237
  294. data/spec/reference_spec.rb +0 -25
  295. data/spec/repeater_spec.rb +0 -160
  296. data/spec/security_spec.rb +0 -158
  297. data/spec/soft_mask_spec.rb +0 -79
  298. data/spec/span_spec.rb +0 -44
  299. data/spec/stamp_spec.rb +0 -160
  300. data/spec/stroke_styles_spec.rb +0 -211
  301. data/spec/table/span_dummy_spec.rb +0 -17
  302. data/spec/table_spec.rb +0 -1527
  303. data/spec/text_at_spec.rb +0 -115
  304. data/spec/text_box_spec.rb +0 -1034
  305. data/spec/text_rendering_mode_spec.rb +0 -45
  306. data/spec/text_spacing_spec.rb +0 -93
  307. data/spec/text_spec.rb +0 -437
  308. data/spec/text_with_inline_formatting_spec.rb +0 -35
  309. data/spec/transparency_spec.rb +0 -91
data/spec/cell_spec.rb DELETED
@@ -1,629 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
- require_relative "../lib/prawn/table"
5
-
6
- module CellHelpers
7
-
8
- # Build, but do not draw, a cell on @pdf.
9
- def cell(options={})
10
- at = options[:at] || [0, @pdf.cursor]
11
- Prawn::Table::Cell::Text.new(@pdf, at, options)
12
- end
13
-
14
- end
15
-
16
- describe "Prawn::Table::Cell" do
17
- before(:each) do
18
- @pdf = Prawn::Document.new
19
- end
20
-
21
- describe "Prawn::Document#cell" do
22
- include CellHelpers
23
-
24
- it "should draw the cell" do
25
- Prawn::Table::Cell::Text.any_instance.expects(:draw).once
26
- @pdf.cell(:content => "text")
27
- end
28
-
29
- it "should return a Cell" do
30
- @pdf.cell(:content => "text").should be_a_kind_of Prawn::Table::Cell
31
- end
32
-
33
- it "accepts :content => nil in a hash" do
34
- @pdf.cell(:content => nil).should be_a_kind_of(Prawn::Table::Cell::Text)
35
- @pdf.make_cell(:content => nil).should be_a_kind_of(Prawn::Table::Cell::Text)
36
- end
37
-
38
- it "should convert nil, Numeric, and Date values to strings" do
39
- [nil, 123, 123.45, Date.today].each do |value|
40
- c = @pdf.cell(:content => value)
41
- c.should be_a_kind_of Prawn::Table::Cell::Text
42
- c.content.should == value.to_s
43
- end
44
- end
45
-
46
- it "should allow inline styling with a hash argument" do
47
- # used for table([[{:text => "...", :font_style => :bold, ...}, ...]])
48
- c = Prawn::Table::Cell.make(@pdf,
49
- {:content => 'hello', :font_style => :bold})
50
- c.should be_a_kind_of Prawn::Table::Cell::Text
51
- c.content.should == "hello"
52
- c.font.name.should == 'Helvetica-Bold'
53
- end
54
-
55
- it "should draw text at the given point plus padding, with the given " +
56
- "size and style" do
57
- @pdf.expects(:bounding_box).yields
58
- @pdf.expects(:move_down)
59
- @pdf.expects(:draw_text!).with { |text, options| text == "hello world" }
60
-
61
- @pdf.cell(:content => "hello world",
62
- :at => [10, 20],
63
- :padding => [30, 40],
64
- :size => 7,
65
- :font_style => :bold)
66
- end
67
- end
68
-
69
- describe "Prawn::Document#make_cell" do
70
- it "should not draw the cell" do
71
- Prawn::Table::Cell::Text.any_instance.expects(:draw).never
72
- @pdf.make_cell("text")
73
- end
74
-
75
- it "should return a Cell" do
76
- @pdf.make_cell("text", :size => 7).should be_a_kind_of Prawn::Table::Cell
77
- end
78
- end
79
-
80
- describe "#style" do
81
- include CellHelpers
82
-
83
- it "should set each property in turn" do
84
- c = cell(:content => "text")
85
-
86
- c.expects(:padding=).with(50)
87
- c.expects(:size=).with(7)
88
-
89
- c.style(:padding => 50, :size => 7)
90
- end
91
-
92
- it "ignores unknown properties" do
93
- c = cell(:content => 'text')
94
-
95
- c.style(:foobarbaz => 'frobnitz')
96
- end
97
- end
98
-
99
- describe "cell width" do
100
- include CellHelpers
101
-
102
- it "should be calculated for text" do
103
- c = cell(:content => "text")
104
- c.width.should == @pdf.width_of("text") + c.padding[1] + c.padding[3]
105
- end
106
-
107
- it "should be overridden by manual :width" do
108
- c = cell(:content => "text", :width => 400)
109
- c.width.should == 400
110
- end
111
-
112
- it "should incorporate padding when specified" do
113
- c = cell(:content => "text", :padding => [1, 2, 3, 4])
114
- c.width.should be_within(0.01).of(@pdf.width_of("text") + 6)
115
- end
116
-
117
- it "should allow width to be reset after it has been calculated" do
118
- # to ensure that if we memoize width, it can still be overridden
119
- c = cell(:content => "text")
120
- c.width
121
- c.width = 400
122
- c.width.should == 400
123
- end
124
-
125
- it "should return proper width with size set" do
126
- text = "text " * 4
127
- c = cell(:content => text, :size => 7)
128
- c.width.should ==
129
- @pdf.width_of(text, :size => 7) + c.padding[1] + c.padding[3]
130
- end
131
-
132
- it "content_width should exclude padding" do
133
- c = cell(:content => "text", :padding => 10)
134
- c.content_width.should == @pdf.width_of("text")
135
- end
136
-
137
- it "content_width should exclude padding even with manual :width" do
138
- c = cell(:content => "text", :padding => 10, :width => 400)
139
- c.content_width.should be_within(0.01).of(380)
140
- end
141
-
142
- it "should have a reasonable minimum width that can fit @content" do
143
- c = cell(:content => "text", :padding => 10)
144
- min_content_width = c.min_width - c.padding[1] - c.padding[3]
145
-
146
- @pdf.height_of("text", :width => min_content_width).should be <
147
- (5 * @pdf.height_of("text"))
148
- end
149
-
150
- it "should defer min_width's evaluation of padding" do
151
- c = cell(:content => "text", :padding => 100)
152
- c.padding = 0
153
-
154
- # Make sure we use the new value of padding in calculating min_width
155
- c.min_width.should be < 100
156
- end
157
-
158
- it "should defer min_width's evaluation of size" do
159
- c = cell(:content => "text", :size => 50)
160
- c.size = 8
161
- c.padding = 0
162
- c.min_width.should be < 10
163
- end
164
-
165
- end
166
-
167
- describe "cell height" do
168
- include CellHelpers
169
-
170
- it "should be calculated for text" do
171
- c = cell(:content => "text")
172
- c.height.should ==
173
- @pdf.height_of("text", :width => @pdf.width_of("text")) +
174
- c.padding[0] + c.padding[3]
175
- end
176
-
177
- it "should be overridden by manual :height" do
178
- c = cell(:content => "text", :height => 400)
179
- c.height.should == 400
180
- end
181
-
182
- it "should incorporate :padding when specified" do
183
- c = cell(:content => "text", :padding => [1, 2, 3, 4])
184
- c.height.should be_within(0.01).of(1 + 3 +
185
- @pdf.height_of("text", :width => @pdf.width_of("text")))
186
- end
187
-
188
- it "should allow height to be reset after it has been calculated" do
189
- # to ensure that if we memoize height, it can still be overridden
190
- c = cell(:content => "text")
191
- c.height
192
- c.height = 400
193
- c.height.should == 400
194
- end
195
-
196
- it "should return proper height for blocks of text" do
197
- content = "words " * 10
198
- c = cell(:content => content, :width => 100)
199
- c.height.should == @pdf.height_of(content, :width => 100) +
200
- c.padding[0] + c.padding[2]
201
- end
202
-
203
- it "should return proper height for blocks of text with size set" do
204
- content = "words " * 10
205
- c = cell(:content => content, :width => 100, :size => 7)
206
-
207
- correct_content_height = nil
208
- @pdf.font_size(7) do
209
- correct_content_height = @pdf.height_of(content, :width => 100)
210
- end
211
-
212
- c.height.should == correct_content_height + c.padding[0] + c.padding[2]
213
- end
214
-
215
- it "content_height should exclude padding" do
216
- c = cell(:content => "text", :padding => 10)
217
- c.content_height.should == @pdf.height_of("text")
218
- end
219
-
220
- it "content_height should exclude padding even with manual :height" do
221
- c = cell(:content => "text", :padding => 10, :height => 400)
222
- c.content_height.should be_within(0.01).of(380)
223
- end
224
- end
225
-
226
- describe "cell padding" do
227
- include CellHelpers
228
-
229
- it "should default to zero" do
230
- c = cell(:content => "text")
231
- c.padding.should == [5, 5, 5, 5]
232
- end
233
-
234
- it "should accept a numeric value, setting all padding" do
235
- c = cell(:content => "text", :padding => 10)
236
- c.padding.should == [10, 10, 10, 10]
237
- end
238
-
239
- it "should accept [v,h]" do
240
- c = cell(:content => "text", :padding => [20, 30])
241
- c.padding.should == [20, 30, 20, 30]
242
- end
243
-
244
- it "should accept [t,h,b]" do
245
- c = cell(:content => "text", :padding => [10, 20, 30])
246
- c.padding.should == [10, 20, 30, 20]
247
- end
248
-
249
- it "should accept [t,l,b,r]" do
250
- c = cell(:content => "text", :padding => [10, 20, 30, 40])
251
- c.padding.should == [10, 20, 30, 40]
252
- end
253
-
254
- it "should reject other formats" do
255
- lambda{
256
- cell(:content => "text", :padding => [10])
257
- }.should raise_error(ArgumentError)
258
- end
259
- end
260
-
261
- describe "background_color" do
262
- include CellHelpers
263
-
264
- it "should fill a rectangle with the given background color" do
265
- @pdf.stubs(:mask).yields
266
- @pdf.expects(:mask).with(:fill_color).yields
267
-
268
- @pdf.stubs(:fill_color)
269
- @pdf.expects(:fill_color).with('123456')
270
- @pdf.expects(:fill_rectangle).checking do |(x, y), w, h|
271
- x.should be_within(0.01).of(0)
272
- y.should be_within(0.01).of(@pdf.cursor)
273
- w.should be_within(0.01).of(29.344)
274
- h.should be_within(0.01).of(23.872)
275
- end
276
- @pdf.cell(:content => "text", :background_color => '123456')
277
- end
278
-
279
- it "should draw the background in the right place if cell is drawn at a " +
280
- "different location" do
281
- @pdf.stubs(:mask).yields
282
- @pdf.expects(:mask).with(:fill_color).yields
283
-
284
- @pdf.stubs(:fill_color)
285
- @pdf.expects(:fill_color).with('123456')
286
- @pdf.expects(:fill_rectangle).checking do |(x, y), w, h|
287
- x.should be_within(0.01).of(12.0)
288
- y.should be_within(0.01).of(34.0)
289
- w.should be_within(0.01).of(29.344)
290
- h.should be_within(0.01).of(23.872)
291
- end
292
- c = @pdf.make_cell(:content => "text", :background_color => '123456')
293
- c.draw([12.0, 34.0])
294
- end
295
- end
296
-
297
- describe "color" do
298
- it "should set fill color when :text_color is provided" do
299
- pdf = Prawn::Document.new
300
- pdf.stubs(:fill_color)
301
- pdf.expects(:fill_color).with('555555')
302
- pdf.cell :content => 'foo', :text_color => '555555'
303
- end
304
-
305
- it "should reset the fill color to the original one" do
306
- pdf = Prawn::Document.new
307
- pdf.fill_color = '333333'
308
- pdf.cell :content => 'foo', :text_color => '555555'
309
- pdf.fill_color.should == '333333'
310
- end
311
- end
312
-
313
- describe "Borders" do
314
- it "should draw all borders by default" do
315
- @pdf.expects(:stroke_line).times(4)
316
- @pdf.cell(:content => "text")
317
- end
318
-
319
- it "should draw all borders when requested" do
320
- @pdf.expects(:stroke_line).times(4)
321
- @pdf.cell(:content => "text", :borders => [:top, :right, :bottom, :left])
322
- end
323
-
324
- # Only roughly verifying the integer coordinates so that we don't have to
325
- # do any FP closeness arithmetic. Can plug in that math later if this goes
326
- # wrong.
327
- it "should draw top border when requested" do
328
- @pdf.expects(:stroke_line).checking do |from, to|
329
- @pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 756]
330
- @pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 756]
331
- end
332
- @pdf.cell(:content => "text", :borders => [:top])
333
- end
334
-
335
- it "should draw bottom border when requested" do
336
- @pdf.expects(:stroke_line).checking do |from, to|
337
- @pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 732]
338
- @pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 732]
339
- end
340
- @pdf.cell(:content => "text", :borders => [:bottom])
341
- end
342
-
343
- it "should draw left border when requested" do
344
- @pdf.expects(:stroke_line).checking do |from, to|
345
- @pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 756]
346
- @pdf.map_to_absolute(to).map{|x| x.round}.should == [36, 732]
347
- end
348
- @pdf.cell(:content => "text", :borders => [:left])
349
- end
350
-
351
- it "should draw right border when requested" do
352
- @pdf.expects(:stroke_line).checking do |from, to|
353
- @pdf.map_to_absolute(from).map{|x| x.round}.should == [65, 756]
354
- @pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 732]
355
- end
356
- @pdf.cell(:content => "text", :borders => [:right])
357
- end
358
-
359
- it "should draw borders at the same location when in or out of bbox" do
360
- @pdf.expects(:stroke_line).checking do |from, to|
361
- @pdf.map_to_absolute(from).map{|x| x.round}.should == [36, 756]
362
- @pdf.map_to_absolute(to).map{|x| x.round}.should == [65, 756]
363
- end
364
- @pdf.bounding_box([0, @pdf.cursor], :width => @pdf.bounds.width) do
365
- @pdf.cell(:content => "text", :borders => [:top])
366
- end
367
- end
368
-
369
- it "should set border color with :border_..._color" do
370
- @pdf.ignores(:stroke_color=).with("000000")
371
- @pdf.expects(:stroke_color=).with("ff0000")
372
-
373
- c = @pdf.cell(:content => "text", :border_top_color => "ff0000")
374
- c.border_top_color.should == "ff0000"
375
- c.border_colors[0].should == "ff0000"
376
- end
377
-
378
- it "should set border colors with :border_color" do
379
- @pdf.ignores(:stroke_color=).with("000000")
380
- @pdf.expects(:stroke_color=).with("ff0000")
381
- @pdf.expects(:stroke_color=).with("00ff00")
382
- @pdf.expects(:stroke_color=).with("0000ff")
383
- @pdf.expects(:stroke_color=).with("ff00ff")
384
-
385
- c = @pdf.cell(:content => "text",
386
- :border_color => %w[ff0000 00ff00 0000ff ff00ff])
387
-
388
- c.border_colors.should == %w[ff0000 00ff00 0000ff ff00ff]
389
- end
390
-
391
- it "border_..._width should return 0 if border not selected" do
392
- c = @pdf.cell(:content => "text", :borders => [:top])
393
- c.border_bottom_width.should == 0
394
- end
395
-
396
- it "should set border width with :border_..._width" do
397
- @pdf.ignores(:line_width=).with(1)
398
- @pdf.expects(:line_width=).with(2)
399
-
400
- c = @pdf.cell(:content => "text", :border_bottom_width => 2)
401
- c.border_bottom_width.should == 2
402
- c.border_widths[2].should == 2
403
- end
404
-
405
- it "should set border widths with :border_width" do
406
- @pdf.ignores(:line_width=).with(1)
407
- @pdf.expects(:line_width=).with(2)
408
- @pdf.expects(:line_width=).with(3)
409
- @pdf.expects(:line_width=).with(4)
410
- @pdf.expects(:line_width=).with(5)
411
-
412
- c = @pdf.cell(:content => "text",
413
- :border_width => [2, 3, 4, 5])
414
- c.border_widths.should == [2, 3, 4, 5]
415
- end
416
-
417
- it "should set default border lines to :solid" do
418
- c = @pdf.cell(:content => "text")
419
- c.border_top_line.should == :solid
420
- c.border_right_line.should == :solid
421
- c.border_bottom_line.should == :solid
422
- c.border_left_line.should == :solid
423
- c.border_lines.should == [:solid] * 4
424
- end
425
-
426
- it "should set border line with :border_..._line" do
427
- c = @pdf.cell(:content => "text", :border_bottom_line => :dotted)
428
- c.border_bottom_line.should == :dotted
429
- c.border_lines[2].should == :dotted
430
- end
431
-
432
- it "should set border lines with :border_lines" do
433
- c = @pdf.cell(:content => "text",
434
- :border_lines => [:solid, :dotted, :dashed, :solid])
435
- c.border_lines.should == [:solid, :dotted, :dashed, :solid]
436
- end
437
- end
438
-
439
-
440
-
441
-
442
-
443
-
444
- describe "Text cell attributes" do
445
- include CellHelpers
446
-
447
- it "should pass through text options like :align to Text::Box" do
448
- c = cell(:content => "text", :align => :right)
449
-
450
- box = Prawn::Text::Box.new("text", :document => @pdf)
451
-
452
- Prawn::Text::Box.expects(:new).checking do |text, options|
453
- text.should == "text"
454
- options[:align].should == :right
455
- end.at_least_once.returns(box)
456
-
457
- c.draw
458
- end
459
-
460
- it "should use font_style for Text::Box#style" do
461
- c = cell(:content => "text", :font_style => :bold)
462
-
463
- box = Prawn::Text::Box.new("text", :document => @pdf)
464
-
465
- Prawn::Text::Box.expects(:new).checking do |text, options|
466
- text.should == "text"
467
- options[:style].should == :bold
468
- end.at_least_once.returns(box)
469
-
470
- c.draw
471
- end
472
-
473
- it "supports variant styles of the current font" do
474
- font_path = "#{Prawn::BASEDIR}/data/fonts/Panic+Sans.dfont"
475
- @pdf.font_families.merge!("Panic Sans" => {
476
- :normal => { :file => font_path, :font => "PanicSans" },
477
- :bold => { :file => font_path, :font => "PanicSans-Bold" },
478
- })
479
- @pdf.font "Panic Sans"
480
-
481
- c = cell(:content => "text", :font_style => :bold)
482
-
483
- box = Prawn::Text::Box.new("text", :document => @pdf)
484
- Prawn::Text::Box.expects(:new).checking do |text, options|
485
- text.should == "text"
486
- options[:style].should == :bold
487
- @pdf.font.family.should == 'Panic Sans'
488
- end.at_least_once.returns(box)
489
-
490
- c.draw
491
- end
492
-
493
-
494
- it "uses the style of the current font if none given" do
495
- font_path = "#{Prawn::BASEDIR}/data/fonts/Panic+Sans.dfont"
496
- @pdf.font_families.merge!("Panic Sans" => {
497
- :normal => { :file => font_path, :font => "PanicSans" },
498
- :bold => { :file => font_path, :font => "PanicSans-Bold" },
499
- })
500
- @pdf.font "Panic Sans", :style => :bold
501
-
502
- c = cell(:content => "text")
503
-
504
- box = Prawn::Text::Box.new("text", :document => @pdf)
505
- Prawn::Text::Box.expects(:new).checking do |text, options|
506
- text.should == "text"
507
- @pdf.font.family.should == 'Panic Sans'
508
- @pdf.font.options[:style].should == :bold
509
- end.at_least_once.returns(box)
510
-
511
- c.draw
512
- end
513
-
514
- it "should allow inline formatting in cells" do
515
- c = cell(:content => "foo <b>bar</b> baz", :inline_format => true)
516
-
517
- box = Prawn::Text::Formatted::Box.new([], :document => @pdf)
518
-
519
- Prawn::Text::Formatted::Box.expects(:new).checking do |array, options|
520
- array[0][:text].should == "foo "
521
- array[0][:styles].should == []
522
-
523
- array[1][:text].should == "bar"
524
- array[1][:styles].should == [:bold]
525
-
526
- array[2][:text].should == " baz"
527
- array[2][:styles].should == []
528
- end.at_least_once.returns(box)
529
-
530
- c.draw
531
- end
532
-
533
- end
534
-
535
- describe "Font handling" do
536
- include CellHelpers
537
-
538
- it "should allow only :font_style to be specified, defaulting to the " +
539
- "document's font" do
540
- c = cell(:content => "text", :font_style => :bold)
541
- c.font.name.should == 'Helvetica-Bold'
542
- end
543
-
544
- it "should accept a font name for :font" do
545
- c = cell(:content => "text", :font => 'Helvetica-Bold')
546
- c.font.name.should == 'Helvetica-Bold'
547
- end
548
-
549
- it "should allow style to be changed after initialize" do
550
- c = cell(:content => "text")
551
- c.font_style = :bold
552
- c.font.name.should == 'Helvetica-Bold'
553
- end
554
-
555
- it "should default to the document's font, if none is specified" do
556
- c = cell(:content => "text")
557
- c.font.should == @pdf.font
558
- end
559
-
560
- it "should use the metrics of the selected font (even if it is a variant " +
561
- "of the document's font) to calculate width" do
562
- c = cell(:content => "text", :font_style => :bold)
563
- font = @pdf.find_font('Helvetica-Bold')
564
- c.content_width.should == font.compute_width_of("text")
565
- end
566
-
567
- it "should properly calculate inline-formatted text" do
568
- c = cell(:content => "<b>text</b>", :inline_format => true)
569
- font = @pdf.find_font('Helvetica-Bold')
570
- c.content_width.should == font.compute_width_of("text")
571
- end
572
- end
573
- end
574
-
575
- describe "Image cells" do
576
- before(:each) do
577
- create_pdf
578
- end
579
-
580
- describe "with default options" do
581
- before(:each) do
582
- @cell = Prawn::Table::Cell.make(@pdf,
583
- :image => "#{Prawn::DATADIR}/images/prawn.png")
584
- end
585
-
586
- it "should create a Cell::Image" do
587
- @cell.should be_a_kind_of(Prawn::Table::Cell::Image)
588
- end
589
-
590
- it "should pull the natural width and height from the image" do
591
- @cell.natural_content_width.should == 141
592
- @cell.natural_content_height.should == 142
593
- end
594
- end
595
-
596
- describe "hash syntax" do
597
- before(:each) do
598
- @table = @pdf.make_table([[{
599
- :image => "#{Prawn::DATADIR}/images/prawn.png",
600
- :scale => 2,
601
- :fit => [100, 200],
602
- :image_width => 123,
603
- :image_height => 456,
604
- :position => :center,
605
- :vposition => :center
606
- }]])
607
- @cell = @table.cells[0, 0]
608
- end
609
-
610
-
611
- it "should create a Cell::Image" do
612
- @cell.should be_a_kind_of(Prawn::Table::Cell::Image)
613
- end
614
-
615
- it "should pass through image options" do
616
- @pdf.expects(:embed_image).checking do |_, _, options|
617
- options[:scale].should == 2
618
- options[:fit].should == [100, 200]
619
- options[:width].should == 123
620
- options[:height].should == 456
621
- options[:position].should == :center
622
- options[:vposition].should == :center
623
- end
624
-
625
- @table.draw
626
- end
627
- end
628
-
629
- end
@@ -1,65 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- describe "A column box" do
6
- it "has sensible left and right values" do
7
- create_pdf
8
- @pdf.column_box [0, @pdf.cursor], :width => @pdf.bounds.width,
9
- :height => 200, :columns => 3, :spacer => 25 do
10
- left = @pdf.bounds.left
11
- right = @pdf.bounds.right
12
-
13
- @pdf.bounds.move_past_bottom # next column
14
-
15
- @pdf.bounds.left.should be > left
16
- @pdf.bounds.left.should be > right
17
- @pdf.bounds.right.should be > @pdf.bounds.left
18
- end
19
- end
20
-
21
- it "includes spacers between columns but not at the end" do
22
- create_pdf
23
- @pdf.column_box [0, @pdf.cursor], :width => 500,
24
- :height => 200, :columns => 3, :spacer => 25 do
25
- @pdf.bounds.width.should == 150 # (500 - (25 * 2)) / 3
26
-
27
- @pdf.bounds.move_past_bottom
28
- @pdf.bounds.move_past_bottom
29
-
30
- @pdf.bounds.right.should == 500
31
- end
32
- end
33
-
34
- it "does not reset the top margin on a new page by default" do
35
- create_pdf
36
- page_top = @pdf.cursor
37
- @pdf.move_down 50
38
- init_column_top = @pdf.cursor
39
- @pdf.column_box [0, @pdf.cursor], :width => 500,
40
- :height => 200, :columns => 2 do
41
-
42
- @pdf.bounds.move_past_bottom
43
- @pdf.bounds.move_past_bottom
44
-
45
- @pdf.bounds.absolute_top.should == init_column_top
46
- @pdf.bounds.absolute_top.should_not == page_top
47
- end
48
- end
49
-
50
- it "does reset the top margin when reflow_margins is set" do
51
- create_pdf
52
- page_top = @pdf.cursor
53
- @pdf.move_down 50
54
- init_column_top = @pdf.cursor
55
- @pdf.column_box [0, @pdf.cursor], :width => 500, :reflow_margins => true,
56
- :height => 200, :columns => 2 do
57
-
58
- @pdf.bounds.move_past_bottom
59
- @pdf.bounds.move_past_bottom
60
-
61
- @pdf.bounds.absolute_top.should == page_top
62
- @pdf.bounds.absolute_top.should_not == init_column_top
63
- end
64
- end
65
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
-
5
- describe "When creating destinations" do
6
-
7
- before(:each) { create_pdf }
8
-
9
- it "should add entry to Dests name tree" do
10
- @pdf.dests.data.empty?.should == true
11
- @pdf.add_dest "candy", "chocolate"
12
- @pdf.dests.data.size.should == 1
13
- end
14
-
15
- end