prawn 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (278) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +0 -0
  4. data/Gemfile +1 -9
  5. data/Rakefile +12 -22
  6. data/lib/prawn.rb +29 -48
  7. data/lib/prawn/document.rb +148 -123
  8. data/lib/prawn/document/bounding_box.rb +33 -26
  9. data/lib/prawn/document/column_box.rb +5 -7
  10. data/lib/prawn/document/internals.rb +6 -6
  11. data/lib/prawn/document/span.rb +20 -17
  12. data/lib/prawn/encoding.rb +65 -67
  13. data/lib/prawn/errors.rb +10 -7
  14. data/lib/prawn/font.rb +78 -62
  15. data/lib/prawn/font/afm.rb +93 -66
  16. data/lib/prawn/font/dfont.rb +2 -10
  17. data/lib/prawn/font/ttc.rb +34 -0
  18. data/lib/prawn/font/ttf.rb +73 -65
  19. data/lib/prawn/font_metric_cache.rb +9 -8
  20. data/lib/prawn/graphics.rb +110 -70
  21. data/lib/prawn/graphics/blend_mode.rb +7 -8
  22. data/lib/prawn/graphics/cap_style.rb +2 -4
  23. data/lib/prawn/graphics/color.rb +23 -26
  24. data/lib/prawn/graphics/dash.rb +22 -12
  25. data/lib/prawn/graphics/join_style.rb +8 -4
  26. data/lib/prawn/graphics/patterns.rb +185 -96
  27. data/lib/prawn/graphics/transformation.rb +11 -9
  28. data/lib/prawn/graphics/transparency.rb +15 -13
  29. data/lib/prawn/grid.rb +20 -20
  30. data/lib/prawn/image_handler.rb +4 -6
  31. data/lib/prawn/images.rb +22 -15
  32. data/lib/prawn/images/image.rb +0 -1
  33. data/lib/prawn/images/jpg.rb +26 -22
  34. data/lib/prawn/images/png.rb +60 -57
  35. data/lib/prawn/measurement_extensions.rb +8 -9
  36. data/lib/prawn/measurements.rb +14 -15
  37. data/lib/prawn/outline.rb +96 -78
  38. data/lib/prawn/repeater.rb +12 -10
  39. data/lib/prawn/security.rb +66 -48
  40. data/lib/prawn/security/arcfour.rb +1 -3
  41. data/lib/prawn/soft_mask.rb +23 -25
  42. data/lib/prawn/stamp.rb +16 -12
  43. data/lib/prawn/text.rb +59 -45
  44. data/lib/prawn/text/box.rb +9 -8
  45. data/lib/prawn/text/formatted.rb +4 -6
  46. data/lib/prawn/text/formatted/arranger.rb +51 -30
  47. data/lib/prawn/text/formatted/box.rb +112 -88
  48. data/lib/prawn/text/formatted/fragment.rb +10 -15
  49. data/lib/prawn/text/formatted/line_wrap.rb +118 -61
  50. data/lib/prawn/text/formatted/parser.rb +134 -110
  51. data/lib/prawn/text/formatted/wrap.rb +42 -32
  52. data/lib/prawn/transformation_stack.rb +3 -4
  53. data/lib/prawn/utilities.rb +6 -21
  54. data/lib/prawn/version.rb +1 -3
  55. data/lib/prawn/view.rb +4 -2
  56. data/manual/basic_concepts/adding_pages.rb +4 -7
  57. data/manual/basic_concepts/basic_concepts.rb +29 -22
  58. data/manual/basic_concepts/creation.rb +8 -11
  59. data/manual/basic_concepts/cursor.rb +2 -5
  60. data/manual/basic_concepts/measurement.rb +3 -6
  61. data/manual/basic_concepts/origin.rb +3 -6
  62. data/manual/basic_concepts/other_cursor_helpers.rb +9 -12
  63. data/manual/basic_concepts/view.rb +20 -16
  64. data/manual/bounding_box/bounding_box.rb +27 -24
  65. data/manual/bounding_box/bounds.rb +9 -12
  66. data/manual/bounding_box/canvas.rb +2 -5
  67. data/manual/bounding_box/creation.rb +4 -7
  68. data/manual/bounding_box/indentation.rb +12 -15
  69. data/manual/bounding_box/nesting.rb +22 -17
  70. data/manual/bounding_box/russian_boxes.rb +8 -9
  71. data/manual/bounding_box/stretchy.rb +10 -13
  72. data/manual/contents.rb +26 -22
  73. data/manual/cover.rb +22 -20
  74. data/manual/document_and_page_options/background.rb +9 -13
  75. data/manual/document_and_page_options/document_and_page_options.rb +23 -20
  76. data/manual/document_and_page_options/metadata.rb +16 -16
  77. data/manual/document_and_page_options/page_margins.rb +16 -20
  78. data/manual/document_and_page_options/page_size.rb +11 -12
  79. data/manual/document_and_page_options/print_scaling.rb +15 -15
  80. data/manual/example_helper.rb +2 -4
  81. data/manual/graphics/blend_mode.rb +10 -9
  82. data/manual/graphics/circle_and_ellipse.rb +2 -5
  83. data/manual/graphics/color.rb +5 -9
  84. data/manual/graphics/common_lines.rb +5 -8
  85. data/manual/graphics/fill_and_stroke.rb +2 -5
  86. data/manual/graphics/fill_rules.rb +7 -10
  87. data/manual/graphics/gradients.rb +25 -21
  88. data/manual/graphics/graphics.rb +49 -43
  89. data/manual/graphics/helper.rb +10 -9
  90. data/manual/graphics/line_width.rb +5 -7
  91. data/manual/graphics/lines_and_curves.rb +5 -8
  92. data/manual/graphics/polygon.rb +4 -8
  93. data/manual/graphics/rectangle.rb +2 -5
  94. data/manual/graphics/rotate.rb +4 -7
  95. data/manual/graphics/scale.rb +12 -15
  96. data/manual/graphics/soft_masks.rb +1 -4
  97. data/manual/graphics/stroke_cap.rb +3 -6
  98. data/manual/graphics/stroke_dash.rb +9 -12
  99. data/manual/graphics/stroke_join.rb +2 -5
  100. data/manual/graphics/translate.rb +7 -10
  101. data/manual/graphics/transparency.rb +5 -8
  102. data/manual/how_to_read_this_manual.rb +4 -6
  103. data/manual/images/absolute_position.rb +4 -7
  104. data/manual/images/fit.rb +5 -8
  105. data/manual/images/horizontal.rb +6 -9
  106. data/manual/images/images.rb +25 -23
  107. data/manual/images/plain_image.rb +3 -6
  108. data/manual/images/scale.rb +7 -10
  109. data/manual/images/vertical.rb +10 -13
  110. data/manual/images/width_and_height.rb +8 -11
  111. data/manual/layout/boxes.rb +3 -6
  112. data/manual/layout/content.rb +5 -8
  113. data/manual/layout/layout.rb +16 -16
  114. data/manual/layout/simple_grid.rb +4 -7
  115. data/manual/outline/add_subsection_to.rb +18 -21
  116. data/manual/outline/insert_section_after.rb +13 -16
  117. data/manual/outline/outline.rb +19 -17
  118. data/manual/outline/sections_and_pages.rb +15 -18
  119. data/manual/repeatable_content/alternate_page_numbering.rb +19 -17
  120. data/manual/repeatable_content/page_numbering.rb +15 -16
  121. data/manual/repeatable_content/repeatable_content.rb +23 -19
  122. data/manual/repeatable_content/repeater.rb +12 -15
  123. data/manual/repeatable_content/stamp.rb +12 -15
  124. data/manual/security/encryption.rb +7 -10
  125. data/manual/security/permissions.rb +17 -14
  126. data/manual/security/security.rb +17 -16
  127. data/manual/table.rb +2 -4
  128. data/manual/text/alignment.rb +14 -17
  129. data/manual/text/color.rb +10 -11
  130. data/manual/text/column_box.rb +5 -8
  131. data/manual/text/fallback_fonts.rb +23 -21
  132. data/manual/text/font.rb +9 -12
  133. data/manual/text/font_size.rb +11 -14
  134. data/manual/text/font_style.rb +4 -7
  135. data/manual/text/formatted_callbacks.rb +23 -21
  136. data/manual/text/formatted_text.rb +31 -25
  137. data/manual/text/free_flowing_text.rb +18 -21
  138. data/manual/text/inline.rb +16 -19
  139. data/manual/text/kerning_and_character_spacing.rb +12 -15
  140. data/manual/text/leading.rb +5 -8
  141. data/manual/text/line_wrapping.rb +33 -17
  142. data/manual/text/paragraph_indentation.rb +11 -14
  143. data/manual/text/positioned_text.rb +13 -16
  144. data/manual/text/registering_families.rb +16 -19
  145. data/manual/text/rendering_and_color.rb +7 -10
  146. data/manual/text/right_to_left_text.rb +24 -19
  147. data/manual/text/rotation.rb +26 -23
  148. data/manual/text/single_usage.rb +6 -9
  149. data/manual/text/text.rb +56 -52
  150. data/manual/text/text_box_excess.rb +18 -17
  151. data/manual/text/text_box_extensions.rb +16 -15
  152. data/manual/text/text_box_overflow.rb +15 -18
  153. data/manual/text/utf8.rb +9 -12
  154. data/manual/text/win_ansi_charset.rb +18 -19
  155. data/prawn.gemspec +37 -27
  156. data/spec/extensions/encoding_helpers.rb +0 -2
  157. data/spec/manual_spec.rb +33 -0
  158. data/spec/prawn/document/bounding_box_spec.rb +546 -0
  159. data/spec/prawn/document/column_box_spec.rb +73 -0
  160. data/spec/prawn/document/security_spec.rb +173 -0
  161. data/spec/prawn/document_annotations_spec.rb +74 -0
  162. data/spec/prawn/document_destinations_spec.rb +13 -0
  163. data/spec/prawn/document_grid_spec.rb +96 -0
  164. data/spec/prawn/document_reference_spec.rb +25 -0
  165. data/spec/prawn/document_span_spec.rb +34 -0
  166. data/spec/prawn/document_spec.rb +751 -0
  167. data/spec/prawn/font_metric_cache_spec.rb +52 -0
  168. data/spec/prawn/font_spec.rb +513 -0
  169. data/spec/prawn/graphics/blend_mode_spec.rb +61 -0
  170. data/spec/prawn/graphics/transparency_spec.rb +79 -0
  171. data/spec/prawn/graphics_spec.rb +817 -0
  172. data/spec/prawn/graphics_stroke_styles_spec.rb +227 -0
  173. data/spec/{image_handler_spec.rb → prawn/image_handler_spec.rb} +13 -15
  174. data/spec/prawn/images/jpg_spec.rb +18 -0
  175. data/spec/prawn/images/png_spec.rb +281 -0
  176. data/spec/prawn/images_spec.rb +170 -0
  177. data/spec/prawn/measurements_extensions_spec.rb +22 -0
  178. data/spec/prawn/outline_spec.rb +408 -0
  179. data/spec/prawn/repeater_spec.rb +163 -0
  180. data/spec/prawn/soft_mask_spec.rb +72 -0
  181. data/spec/prawn/stamp_spec.rb +168 -0
  182. data/spec/prawn/text/box_spec.rb +1113 -0
  183. data/spec/prawn/text/formatted/arranger_spec.rb +464 -0
  184. data/spec/prawn/text/formatted/box_spec.rb +825 -0
  185. data/spec/prawn/text/formatted/fragment_spec.rb +341 -0
  186. data/spec/prawn/text/formatted/line_wrap_spec.rb +491 -0
  187. data/spec/prawn/text/formatted/parser_spec.rb +667 -0
  188. data/spec/prawn/text_draw_text_spec.rb +147 -0
  189. data/spec/prawn/text_rendering_mode_spec.rb +42 -0
  190. data/spec/prawn/text_spacing_spec.rb +93 -0
  191. data/spec/prawn/text_spec.rb +601 -0
  192. data/spec/prawn/text_with_inline_formatting_spec.rb +33 -0
  193. data/spec/{transformation_stack_spec.rb → prawn/transformation_stack_spec.rb} +21 -20
  194. data/spec/prawn/view_spec.rb +45 -0
  195. data/spec/spec_helper.rb +16 -16
  196. metadata +96 -151
  197. metadata.gz.sig +1 -0
  198. data/data/images/16bit.alpha +0 -0
  199. data/data/images/16bit.color +0 -0
  200. data/data/images/16bit.png +0 -0
  201. data/data/images/arrow.png +0 -0
  202. data/data/images/arrow2.png +0 -0
  203. data/data/images/blend_modes_bottom_layer.jpg +0 -0
  204. data/data/images/blend_modes_top_layer.jpg +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/indexed_transparency.png +0 -0
  213. data/data/images/indexed_transparency_alpha.dat +0 -0
  214. data/data/images/indexed_transparency_color.dat +0 -0
  215. data/data/images/letterhead.jpg +0 -0
  216. data/data/images/license.md +0 -8
  217. data/data/images/page_white_text.alpha +0 -0
  218. data/data/images/page_white_text.color +0 -0
  219. data/data/images/page_white_text.png +0 -0
  220. data/data/images/pigs.jpg +0 -0
  221. data/data/images/prawn.png +0 -0
  222. data/data/images/ruport.png +0 -0
  223. data/data/images/ruport_data.dat +0 -0
  224. data/data/images/ruport_transparent.png +0 -0
  225. data/data/images/ruport_type0.png +0 -0
  226. data/data/images/stef.jpg +0 -0
  227. data/data/images/tru256.bmp +0 -0
  228. data/data/images/web-links.dat +0 -1
  229. data/data/images/web-links.png +0 -0
  230. data/data/pdfs/complex_template.pdf +0 -0
  231. data/data/pdfs/contains_ttf_font.pdf +0 -0
  232. data/data/pdfs/encrypted.pdf +0 -0
  233. data/data/pdfs/form.pdf +1 -819
  234. data/data/pdfs/hexagon.pdf +0 -61
  235. data/data/pdfs/indirect_reference.pdf +0 -86
  236. data/data/pdfs/multipage_template.pdf +0 -127
  237. data/data/pdfs/nested_pages.pdf +0 -118
  238. data/data/pdfs/page_without_mediabox.pdf +0 -193
  239. data/data/pdfs/resources_as_indirect_object.pdf +0 -83
  240. data/data/pdfs/two_hexagons.pdf +0 -90
  241. data/data/pdfs/version_1_6.pdf +0 -61
  242. data/data/shift_jis_text.txt +0 -1
  243. data/spec/acceptance/png_spec.rb +0 -35
  244. data/spec/annotations_spec.rb +0 -67
  245. data/spec/blend_mode_spec.rb +0 -71
  246. data/spec/bounding_box_spec.rb +0 -501
  247. data/spec/column_box_spec.rb +0 -59
  248. data/spec/destinations_spec.rb +0 -13
  249. data/spec/document_spec.rb +0 -738
  250. data/spec/font_metric_cache_spec.rb +0 -52
  251. data/spec/font_spec.rb +0 -475
  252. data/spec/formatted_text_arranger_spec.rb +0 -452
  253. data/spec/formatted_text_box_spec.rb +0 -716
  254. data/spec/formatted_text_fragment_spec.rb +0 -299
  255. data/spec/graphics_spec.rb +0 -705
  256. data/spec/grid_spec.rb +0 -95
  257. data/spec/images_spec.rb +0 -167
  258. data/spec/inline_formatted_text_parser_spec.rb +0 -568
  259. data/spec/jpg_spec.rb +0 -23
  260. data/spec/line_wrap_spec.rb +0 -366
  261. data/spec/measurement_units_spec.rb +0 -22
  262. data/spec/outline_spec.rb +0 -409
  263. data/spec/png_spec.rb +0 -257
  264. data/spec/reference_spec.rb +0 -25
  265. data/spec/repeater_spec.rb +0 -154
  266. data/spec/security_spec.rb +0 -151
  267. data/spec/soft_mask_spec.rb +0 -78
  268. data/spec/span_spec.rb +0 -43
  269. data/spec/stamp_spec.rb +0 -179
  270. data/spec/stroke_styles_spec.rb +0 -208
  271. data/spec/text_at_spec.rb +0 -142
  272. data/spec/text_box_spec.rb +0 -1042
  273. data/spec/text_rendering_mode_spec.rb +0 -45
  274. data/spec/text_spacing_spec.rb +0 -93
  275. data/spec/text_spec.rb +0 -543
  276. data/spec/text_with_inline_formatting_spec.rb +0 -35
  277. data/spec/transparency_spec.rb +0 -91
  278. data/spec/view_spec.rb +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e103cb901b7728d21af3dfe412f3072063a86835
4
- data.tar.gz: 132ff9e3bf2aeeeb1e9b574e5b84115192e576dc
3
+ metadata.gz: ef80196a96c2bf246a6032cff415fc6f35b255dd
4
+ data.tar.gz: d7cd7663853aa67831661ed57a6efb4a0a54c183
5
5
  SHA512:
6
- metadata.gz: 0cad684b3b096da6cdceb69e47b78c5629251687d28c8a3ab4f824fc64b842daa11e2f62122033d9b27f1cd4afe809bfad1c3cc2c150e909cae09f5480a442ec
7
- data.tar.gz: 5ea7ffa1b819a00d71897150c87afd0a7b7cc08e1afc8c4b41a425fd262f5276c961e969ea0e6e0178dde6f74ded16842076674abe39afbc5ca9bfaf513d5aab
6
+ metadata.gz: 20e137ad1d41f8e42e75fc817e82d12fba4a827eaec23e216f164b1ec738a64b1ced7870cbb65f2fd792d0809a6c347add74a9ed8ed99af30bdfc06f7f5d270b
7
+ data.tar.gz: fac5c7cb9096d1e12f65fb9901901af46401fe33ab27af9406ac1ba4b50f64ca9eed5fdc6b0560cc2dec193ec9757ef209f74a24240b32c0a69db6bd3891dd28
@@ -0,0 +1,2 @@
1
+ #O����ԧ�u]�P�q��_��j=�@A�OI�JQ��Q(�8���m�Y���{���� �V�[�*(���iGWA�ZBl���͌�fׅ�T���%�,9��|�K@BL7�#f��� ٖ����&z�g�AD"D��ھ���2�����P�5fx� �&5�%6�ٻ;��|-J���!i�O��@0���
2
+ �M'��:j�bBEY�a��V��l*1^0,f;>�T@=�u�n�!��t�
Binary file
data/Gemfile CHANGED
@@ -1,11 +1,3 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- if ENV["CI"]
6
- platforms :rbx do
7
- gem "rubysl-singleton", "~> 2.0"
8
- gem "rubysl-digest", "~> 2.0"
9
- gem "rubysl-enumerator", "~> 2.0"
10
- end
11
- end
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- require "bundler"
1
+ require 'bundler'
2
2
  Bundler.setup
3
3
 
4
4
  require 'rake'
@@ -7,43 +7,33 @@ require 'yard'
7
7
  require 'rubygems/package_task'
8
8
  require 'rubocop/rake_task'
9
9
 
10
- task :default => [:spec, :rubocop]
10
+ task default: [:spec, :rubocop]
11
11
 
12
- desc "Run all rspec files"
13
- RSpec::Core::RakeTask.new("spec") do |c|
14
- c.rspec_opts = "-t ~unresolved"
15
- end
16
-
17
- desc "Show library's code statistics"
18
- task :stats do
19
- require 'code_statistics/code_statistics'
20
- puts CodeStatistics::CodeStatistics.new(
21
- [
22
- ["Prawn", "lib"],
23
- ["Specs", "spec"]
24
- ]
25
- ).to_s
12
+ desc 'Run all rspec files'
13
+ RSpec::Core::RakeTask.new('spec') do |c|
14
+ c.rspec_opts = '-t ~unresolved'
26
15
  end
27
16
 
28
17
  YARD::Rake::YardocTask.new do |t|
29
18
  t.options = ['--output-dir', 'doc/html']
30
19
  end
31
- task :docs => :yard
20
+ task docs: :yard
32
21
 
33
22
  desc "Generate the 'Prawn by Example' manual"
34
23
  task :manual do
35
- puts "Building manual..."
36
- require File.expand_path(File.join(File.dirname(__FILE__), %w[manual contents]))
37
- puts "The Prawn manual is available at manual.pdf. Happy Prawning!"
24
+ puts 'Building manual...'
25
+ require File.expand_path(File.join(__dir__, %w[manual contents]))
26
+ prawn_manual_document.render_file('manual.pdf')
27
+ puts 'The Prawn manual is available at manual.pdf. Happy Prawning!'
38
28
  end
39
29
 
40
- spec = Gem::Specification.load "prawn.gemspec"
30
+ spec = Gem::Specification.load 'prawn.gemspec'
41
31
  Gem::PackageTask.new(spec) do |pkg|
42
32
  pkg.need_zip = true
43
33
  pkg.need_tar = true
44
34
  end
45
35
 
46
- desc "Run a console with Prawn loaded"
36
+ desc 'Run a console with Prawn loaded'
47
37
  task :console do
48
38
  require 'irb'
49
39
  require 'irb/completion'
@@ -1,19 +1,15 @@
1
- # encoding: utf-8
2
-
3
1
  # Welcome to Prawn, the best PDF Generation library ever.
4
2
  # This documentation covers user level functionality.
5
3
  #
6
- require "set"
4
+ require 'set'
7
5
 
8
6
  require 'ttfunk'
9
- require "pdf/core"
7
+ require 'pdf/core'
10
8
 
11
9
  module Prawn
12
- extend self
13
-
14
10
  file = __FILE__
15
11
  file = File.readlink(file) if File.symlink?(file)
16
- dir = File.dirname(file)
12
+ dir = File.dirname(file)
17
13
 
18
14
  # The base source directory for Prawn as installed on the system
19
15
  #
@@ -33,58 +29,43 @@ module Prawn
33
29
  # Accepted options are: [:page_size, :page_layout, :left_margin, ...]
34
30
  #
35
31
  attr_accessor :debug # @private
32
+ module_function :debug, :debug=
36
33
 
37
34
  def verify_options(accepted, actual) # @private
38
35
  return unless debug || $DEBUG
39
36
  unless (act = Set[*actual.keys]).subset?(acc = Set[*accepted])
40
- fail Prawn::Errors::UnknownOption,
41
- "\nDetected unknown option(s): #{(act - acc).to_a.inspect}\n" \
42
- "Accepted options are: #{accepted.inspect}"
37
+ raise Prawn::Errors::UnknownOption,
38
+ "\nDetected unknown option(s): #{(act - acc).to_a.inspect}\n" \
39
+ "Accepted options are: #{accepted.inspect}"
43
40
  end
44
41
  yield if block_given?
45
42
  end
46
-
47
- module Configurable # @private
48
- def configuration(*args)
49
- @config ||= Marshal.load(Marshal.dump(default_configuration))
50
- if Hash === args[0]
51
- @config.update(args[0])
52
- elsif args.length > 1
53
- @config.values_at(*args)
54
- elsif args.length == 1
55
- @config[args[0]]
56
- else
57
- @config
58
- end
59
- end
60
-
61
- alias_method :C, :configuration
62
- end
43
+ module_function :verify_options
63
44
  end
64
45
 
65
- require_relative "prawn/version"
46
+ require_relative 'prawn/version'
66
47
 
67
- require_relative "prawn/errors"
48
+ require_relative 'prawn/errors'
68
49
 
69
- require_relative "prawn/utilities"
70
- require_relative "prawn/text"
71
- require_relative "prawn/graphics"
72
- require_relative "prawn/images"
73
- require_relative "prawn/images/image"
74
- require_relative "prawn/images/jpg"
75
- require_relative "prawn/images/png"
76
- require_relative "prawn/stamp"
77
- require_relative "prawn/soft_mask"
78
- require_relative "prawn/security"
79
- require_relative "prawn/transformation_stack"
80
- require_relative "prawn/document"
81
- require_relative "prawn/font"
82
- require_relative "prawn/measurements"
83
- require_relative "prawn/repeater"
84
- require_relative "prawn/outline"
85
- require_relative "prawn/grid"
86
- require_relative "prawn/view"
87
- require_relative "prawn/image_handler"
50
+ require_relative 'prawn/utilities'
51
+ require_relative 'prawn/text'
52
+ require_relative 'prawn/graphics'
53
+ require_relative 'prawn/images'
54
+ require_relative 'prawn/images/image'
55
+ require_relative 'prawn/images/jpg'
56
+ require_relative 'prawn/images/png'
57
+ require_relative 'prawn/stamp'
58
+ require_relative 'prawn/soft_mask'
59
+ require_relative 'prawn/security'
60
+ require_relative 'prawn/transformation_stack'
61
+ require_relative 'prawn/document'
62
+ require_relative 'prawn/font'
63
+ require_relative 'prawn/measurements'
64
+ require_relative 'prawn/repeater'
65
+ require_relative 'prawn/outline'
66
+ require_relative 'prawn/grid'
67
+ require_relative 'prawn/view'
68
+ require_relative 'prawn/image_handler'
88
69
 
89
70
  Prawn.image_handler.register(Prawn::Images::PNG)
90
71
  Prawn.image_handler.register(Prawn::Images::JPG)
@@ -1,26 +1,24 @@
1
- # encoding: utf-8
2
-
3
1
  # document.rb : Implements PDF document generation for Prawn
4
2
  #
5
3
  # Copyright April 2008, Gregory Brown. All Rights Reserved.
6
4
  #
7
5
  # This is free software. Please see the LICENSE and COPYING files for details.
8
6
 
9
- require "stringio"
7
+ require 'stringio'
10
8
 
11
- require_relative "document/bounding_box"
12
- require_relative "document/column_box"
13
- require_relative "document/internals"
14
- require_relative "document/span"
9
+ require_relative 'document/bounding_box'
10
+ require_relative 'document/column_box'
11
+ require_relative 'document/internals'
12
+ require_relative 'document/span'
15
13
 
16
14
  module Prawn
17
15
  # The Prawn::Document class is how you start creating a PDF document.
18
16
  #
19
17
  # There are three basic ways you can instantiate PDF Documents in Prawn, they
20
- # are through assignment, implicit block or explicit block. Below is an exmple
21
- # of each type, each example does exactly the same thing, makes a PDF document
22
- # with all the defaults and puts in the default font "Hello There" and then
23
- # saves it to the current directory as "example.pdf"
18
+ # are through assignment, implicit block or explicit block. Below is an
19
+ # example of each type, each example does exactly the same thing, makes a PDF
20
+ # document with all the defaults and puts in the default font "Hello There"
21
+ # and then saves it to the current directory as "example.pdf"
24
22
  #
25
23
  # For example, assignment can be like this:
26
24
  #
@@ -42,8 +40,8 @@ module Prawn
42
40
  # pdf.text words
43
41
  # end
44
42
  #
45
- # Usually, the block forms are used when you are simply creating a PDF document
46
- # that you want to immediately save or render out.
43
+ # Usually, the block forms are used when you are simply creating a PDF
44
+ # document that you want to immediately save or render out.
47
45
  #
48
46
  # See the new and generate methods for further details on the above.
49
47
  #
@@ -64,10 +62,12 @@ module Prawn
64
62
  # NOTE: We probably need to rethink the options validation system, but this
65
63
  # constant temporarily allows for extensions to modify the list.
66
64
 
67
- VALID_OPTIONS = [:page_size, :page_layout, :margin, :left_margin,
68
- :right_margin, :top_margin, :bottom_margin, :skip_page_creation,
69
- :compress, :background, :info,
70
- :text_formatter, :print_scaling]
65
+ VALID_OPTIONS = [
66
+ :page_size, :page_layout, :margin, :left_margin,
67
+ :right_margin, :top_margin, :bottom_margin, :skip_page_creation,
68
+ :compress, :background, :info,
69
+ :text_formatter, :print_scaling
70
+ ].freeze
71
71
 
72
72
  # Any module added to this array will be included into instances of
73
73
  # Prawn::Document at the per-object level. These will also be inherited by
@@ -153,15 +153,22 @@ module Prawn
153
153
  # <tt>:right_margin</tt>:: Sets the right margin in points [0.5 inch]
154
154
  # <tt>:top_margin</tt>:: Sets the top margin in points [0.5 inch]
155
155
  # <tt>:bottom_margin</tt>:: Sets the bottom margin in points [0.5 inch]
156
- # <tt>:skip_page_creation</tt>:: Creates a document without starting the first page [false]
157
- # <tt>:compress</tt>:: Compresses content streams before rendering them [false]
158
- # <tt>:background</tt>:: An image path to be used as background on all pages [nil]
156
+ # <tt>:skip_page_creation</tt>:: Creates a document without starting the
157
+ # first page [false]
158
+ # <tt>:compress</tt>:: Compresses content streams before rendering them
159
+ # [false]
160
+ # <tt>:background</tt>:: An image path to be used as background on all pages
161
+ # [nil]
159
162
  # <tt>:background_scale</tt>:: Backgound image scale [1] [nil]
160
- # <tt>:info</tt>:: Generic hash allowing for custom metadata properties [nil]
161
- # <tt>:text_formatter</tt>: The text formatter to use for <tt>:inline_format</tt>ted text [Prawn::Text::Formatted::Parser]
163
+ # <tt>:info</tt>:: Generic hash allowing for custom metadata properties
164
+ # [nil]
165
+ # <tt>:text_formatter</tt>: The text formatter to use for
166
+ # <tt>:inline_format</tt>ted text
167
+ # [Prawn::Text::Formatted::Parser]
162
168
  #
163
- # Setting e.g. the :margin to 100 points and the :left_margin to 50 will result in margins
164
- # of 100 points on every side except for the left, where it will be 50.
169
+ # Setting e.g. the :margin to 100 points and the :left_margin to 50 will
170
+ # result in margins of 100 points on every side except for the left, where
171
+ # it will be 50.
165
172
  #
166
173
  # The :margin can also be an array much like CSS shorthand:
167
174
  #
@@ -172,8 +179,8 @@ module Prawn
172
179
  # # Top is 10, right is 20, bottom is 30, left is 40.
173
180
  # :margin => [10, 20, 30, 40]
174
181
  #
175
- # Additionally, :page_size can be specified as a simple two value array giving
176
- # the width and height of the document you need in PDF Points.
182
+ # Additionally, :page_size can be specified as a simple two value array
183
+ # giving the width and height of the document you need in PDF Points.
177
184
  #
178
185
  # Usage:
179
186
  #
@@ -181,13 +188,15 @@ module Prawn
181
188
  # pdf = Prawn::Document.new
182
189
  #
183
190
  # # New document, A4 paper, landscaped
184
- # pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
191
+ # pdf = Prawn::Document.new(page_size: "A4", page_layout: :landscape)
185
192
  #
186
193
  # # New document, Custom size
187
- # pdf = Prawn::Document.new(:page_size => [200, 300])
194
+ # pdf = Prawn::Document.new(page_size: [200, 300])
188
195
  #
189
196
  # # New document, with background
190
- # pdf = Prawn::Document.new(:background => "#{Prawn::DATADIR}/images/pigs.jpg")
197
+ # pdf = Prawn::Document.new(
198
+ # background: "#{Prawn::DATADIR}/images/pigs.jpg"
199
+ # )
191
200
  #
192
201
  def initialize(options = {}, &block)
193
202
  options = options.dup
@@ -199,21 +208,22 @@ module Prawn
199
208
 
200
209
  self.class.extensions.reverse_each { |e| extend e }
201
210
  self.state = PDF::Core::DocumentState.new(options)
202
- self.state.populate_pages_from_store(self)
211
+ state.populate_pages_from_store(self)
203
212
  renderer.min_version(state.store.min_version) if state.store.min_version
204
213
 
205
214
  renderer.min_version(1.6) if options[:print_scaling] == :none
206
215
 
207
216
  @background = options[:background]
208
217
  @background_scale = options[:background_scale] || 1
209
- @font_size = 12
218
+ @font_size = 12
210
219
 
211
- @bounding_box = nil
212
- @margin_box = nil
220
+ @bounding_box = nil
221
+ @margin_box = nil
213
222
 
214
223
  @page_number = 0
215
224
 
216
- @text_formatter = options.delete(:text_formatter) || Text::Formatted::Parser
225
+ @text_formatter = options.delete(:text_formatter) ||
226
+ Text::Formatted::Parser
217
227
 
218
228
  options[:size] = options.delete(:page_size)
219
229
  options[:layout] = options.delete(:page_layout)
@@ -240,24 +250,28 @@ module Prawn
240
250
  # pdf.start_new_page(:margin => 100)
241
251
  #
242
252
  def start_new_page(options = {})
243
- if last_page = state.page
244
- last_page_size = last_page.size
245
- last_page_layout = last_page.layout
253
+ last_page = state.page
254
+ if last_page
255
+ last_page_size = last_page.size
256
+ last_page_layout = last_page.layout
246
257
  last_page_margins = last_page.margins.dup
247
258
  end
248
259
 
249
260
  page_options = {
250
- :size => options[:size] || last_page_size,
251
- :layout => options[:layout] || last_page_layout,
252
- :margins => last_page_margins
261
+ size: options[:size] || last_page_size,
262
+ layout: options[:layout] || last_page_layout,
263
+ margins: last_page_margins
253
264
  }
254
265
  if last_page
255
- new_graphic_state = last_page.graphic_state.dup if last_page.graphic_state
266
+ if last_page.graphic_state
267
+ new_graphic_state = last_page.graphic_state.dup
268
+ end
256
269
 
257
- # erase the color space so that it gets reset on new page for fussy pdf-readers
270
+ # erase the color space so that it gets reset on new page for fussy
271
+ # pdf-readers
258
272
  new_graphic_state.color_space = {} if new_graphic_state
259
273
 
260
- page_options.merge!(:graphic_state => new_graphic_state)
274
+ page_options[:graphic_state] = new_graphic_state
261
275
  end
262
276
 
263
277
  state.page = PDF::Core::Page.new(self, page_options)
@@ -277,7 +291,11 @@ module Prawn
277
291
  state.insert_page(state.page, @page_number)
278
292
  @page_number += 1
279
293
 
280
- canvas { image(@background, :scale => @background_scale, :at => bounds.top_left) } if @background
294
+ if @background
295
+ canvas do
296
+ image(@background, scale: @background_scale, at: bounds.top_left)
297
+ end
298
+ end
281
299
  @y = @bounding_box.absolute_top
282
300
 
283
301
  float do
@@ -365,7 +383,7 @@ module Prawn
365
383
  # pdf.render_file "foo.pdf"
366
384
  #
367
385
  def render_file(filename)
368
- File.open(filename, "wb") { |f| render(f) }
386
+ File.open(filename, 'wb') { |f| render(f) }
369
387
  end
370
388
 
371
389
  # The bounds method returns the current bounding box you are currently in,
@@ -374,14 +392,15 @@ module Prawn
374
392
  # block, the box defined by that call will be returned instead of the
375
393
  # document margin box.
376
394
  #
377
- # Another important point about bounding boxes is that all x and y measurements
378
- # within a bounding box code block are relative to the bottom left corner of the
379
- # bounding box.
395
+ # Another important point about bounding boxes is that all x and
396
+ # y measurements within a bounding box code block are relative to the bottom
397
+ # left corner of the bounding box.
380
398
  #
381
399
  # For example:
382
400
  #
383
401
  # Prawn::Document.new do
384
- # # In the default "margin box" of a Prawn document of 0.5in along each edge
402
+ # # In the default "margin box" of a Prawn document of 0.5in along each
403
+ # # edge
385
404
  #
386
405
  # # Draw a border around the page (the manual way)
387
406
  # stroke do
@@ -408,8 +427,8 @@ module Prawn
408
427
 
409
428
  # Sets Document#bounds to the BoundingBox provided. See above for a brief
410
429
  # description of what a bounding box is. This function is useful if you
411
- # really need to change the bounding box manually, but usually, just entering
412
- # and exiting bounding box code blocks is good enough.
430
+ # really need to change the bounding box manually, but usually, just
431
+ # entering and exiting bounding box code blocks is good enough.
413
432
  #
414
433
  def bounds=(bounding_box)
415
434
  @bounding_box = bounding_box
@@ -422,8 +441,8 @@ module Prawn
422
441
  self.y += n
423
442
  end
424
443
 
425
- # Moves down the document by n points relative to the current position inside
426
- # the current bounding box.
444
+ # Moves down the document by n points relative to the current position
445
+ # inside the current bounding box.
427
446
  #
428
447
  def move_down(n)
429
448
  self.y -= n
@@ -486,50 +505,54 @@ module Prawn
486
505
  bounds.indent(left, right, &block)
487
506
  end
488
507
 
489
- # Places a text box on specified pages for page numbering. This should be called
490
- # towards the end of document creation, after all your content is already in
491
- # place. In your template string, <page> refers to the current page, and
492
- # <total> refers to the total amount of pages in the document. Page numbering should
493
- # occur at the end of your Prawn::Document.generate block because the method iterates
494
- # through existing pages after they are created.
508
+ # Places a text box on specified pages for page numbering. This should be
509
+ # called towards the end of document creation, after all your content is
510
+ # already in place. In your template string, <page> refers to the current
511
+ # page, and <total> refers to the total amount of pages in the document.
512
+ # Page numbering should occur at the end of your Prawn::Document.generate
513
+ # block because the method iterates through existing pages after they are
514
+ # created.
495
515
  #
496
516
  # Parameters are:
497
517
  #
498
518
  # <tt>string</tt>:: Template string for page number wording.
499
519
  # Should include '<page>' and, optionally, '<total>'.
500
520
  # <tt>options</tt>:: A hash for page numbering and text box options.
501
- # <tt>:page_filter</tt>:: A filter to specify which pages to place page numbers on.
502
- # Refer to the method 'page_match?'
521
+ # <tt>:page_filter</tt>:: A filter to specify which pages to place page
522
+ # numbers on. Refer to the method 'page_match?'
503
523
  # <tt>:start_count_at</tt>:: The starting count to increment pages from.
504
- # <tt>:total_pages</tt>:: If provided, will replace <total> with the value given.
505
- # Useful to override the total number of pages when using
506
- # the start_count_at option.
524
+ # <tt>:total_pages</tt>:: If provided, will replace <total> with the
525
+ # value given. Useful to override the total
526
+ # number of pages when using the start_count_at
527
+ # option.
507
528
  # <tt>:color</tt>:: Text fill color.
508
529
  #
509
- # Please refer to Prawn::Text::text_box for additional options concerning text
510
- # formatting and placement.
511
- #
512
- # Example: Print page numbers on every page except for the first. Start counting from
513
- # five.
530
+ # Please refer to Prawn::Text::text_box for additional options
531
+ # concerning text formatting and placement.
514
532
  #
515
- # Prawn::Document.generate("page_with_numbering.pdf") do
516
- # number_pages "<page> in a total of <total>",
517
- # {:start_count_at => 5,
518
- # :page_filter => lambda{ |pg| pg != 1 },
519
- # :at => [bounds.right - 50, 0],
520
- # :align => :right,
521
- # :size => 14}
522
- # end
533
+ # Example:
534
+ # Print page numbers on every page except for the first. Start counting
535
+ # from five.
536
+ #
537
+ # Prawn::Document.generate("page_with_numbering.pdf") do
538
+ # number_pages "<page> in a total of <total>", {
539
+ # start_count_at: 5,
540
+ # page_filter: lambda { |pg| pg != 1 },
541
+ # at: [bounds.right - 50, 0],
542
+ # align: :right,
543
+ # size: 14
544
+ # }
545
+ # end
523
546
  #
524
547
  def number_pages(string, options = {})
525
548
  opts = options.dup
526
549
  start_count_at = opts.delete(:start_count_at).to_i
527
550
 
528
- if opts.key?(:page_filter)
529
- page_filter = opts.delete(:page_filter)
530
- else
531
- page_filter = :all
532
- end
551
+ page_filter = if opts.key?(:page_filter)
552
+ opts.delete(:page_filter)
553
+ else
554
+ :all
555
+ end
533
556
 
534
557
  total_pages = opts.delete(:total_pages)
535
558
  txtcolor = opts.delete(:color)
@@ -549,12 +572,14 @@ module Prawn
549
572
  end
550
573
  if page_match?(page_filter, p)
551
574
  go_to_page(p)
552
- # have to use fill_color here otherwise text reverts back to default fill color
575
+ # have to use fill_color here otherwise text reverts back to default
576
+ # fill color
553
577
  fill_color txtcolor unless txtcolor.nil?
554
578
  total_pages = total_pages.nil? ? page_count : total_pages
555
- str = string.gsub("<page>", "#{pseudopage}").gsub("<total>", "#{total_pages}")
579
+ str = string.gsub('<page>', pseudopage.to_s)
580
+ .gsub('<total>', total_pages.to_s)
556
581
  text_box str, opts
557
- start_count = true # increment page count as soon as first match found
582
+ start_count = true # increment page count as soon as first match found
558
583
  end
559
584
  pseudopage += 1 if start_count
560
585
  end
@@ -572,21 +597,21 @@ module Prawn
572
597
  # the current page or column.
573
598
  #
574
599
  # @private
575
- def group(*a, &b)
576
- fail NotImplementedError,
577
- "Document#group has been disabled because its implementation " \
578
- "lead to corrupted documents whenever a page boundary was " \
579
- "crossed. We will try to work on reimplementing it in a " \
580
- "future release"
600
+ def group(*_a)
601
+ raise NotImplementedError,
602
+ 'Document#group has been disabled because its implementation ' \
603
+ 'lead to corrupted documents whenever a page boundary was ' \
604
+ 'crossed. We will try to work on reimplementing it in a ' \
605
+ 'future release'
581
606
  end
582
607
 
583
608
  # @private
584
609
  def transaction
585
- fail NotImplementedError,
586
- "Document#transaction has been disabled because its implementation " \
587
- "lead to corrupted documents whenever a page boundary was " \
588
- "crossed. We will try to work on reimplementing it in a " \
589
- "future release"
610
+ raise NotImplementedError,
611
+ 'Document#transaction has been disabled because its implementation ' \
612
+ 'lead to corrupted documents whenever a page boundary was ' \
613
+ 'crossed. We will try to work on reimplementing it in a ' \
614
+ 'future release'
590
615
  end
591
616
 
592
617
  # Provides a way to execute a block of code repeatedly based on a
@@ -617,8 +642,8 @@ module Prawn
617
642
  # @private
618
643
 
619
644
  def mask(*fields)
620
- # Stores the current state of the named attributes, executes the block, and
621
- # then restores the original values after the block has executed.
645
+ # Stores the current state of the named attributes, executes the block,
646
+ # and then restores the original values after the block has executed.
622
647
  # -- I will remove the nodoc if/when this feature is a little less hacky
623
648
  stored = {}
624
649
  fields.each { |f| stored[f] = send(f) }
@@ -630,7 +655,7 @@ module Prawn
630
655
 
631
656
  def initialize_first_page(options)
632
657
  if options[:skip_page_creation]
633
- start_new_page(options.merge(:orphan => true))
658
+ start_new_page(options.merge(orphan: true))
634
659
  else
635
660
  start_new_page(options)
636
661
  end
@@ -648,11 +673,11 @@ module Prawn
648
673
 
649
674
  private
650
675
 
651
- # setting override_settings to true ensures that a new graphic state does not end up using
652
- # previous settings.
676
+ # setting override_settings to true ensures that a new graphic state does
677
+ # not end up using previous settings.
653
678
  def use_graphic_settings(override_settings = false)
654
- set_fill_color if current_fill_color != "000000" || override_settings
655
- set_stroke_color if current_stroke_color != "000000" || override_settings
679
+ set_fill_color if current_fill_color != '000000' || override_settings
680
+ set_stroke_color if current_stroke_color != '000000' || override_settings
656
681
  write_line_width if line_width != 1 || override_settings
657
682
  write_stroke_cap_style if cap_style != :butt || override_settings
658
683
  write_stroke_join_style if join_style != :miter || override_settings
@@ -661,14 +686,16 @@ module Prawn
661
686
 
662
687
  def generate_margin_box
663
688
  old_margin_box = @margin_box
664
- page = state.page
689
+ page = state.page
665
690
 
666
691
  @margin_box = BoundingBox.new(
667
692
  self,
668
- nil, # margin box has no parent
669
- [ page.margins[:left], page.dimensions[-1] - page.margins[:top] ] ,
670
- :width => page.dimensions[-2] - (page.margins[:left] + page.margins[:right]),
671
- :height => page.dimensions[-1] - (page.margins[:top] + page.margins[:bottom])
693
+ nil, # margin box has no parent
694
+ [page.margins[:left], page.dimensions[-1] - page.margins[:top]],
695
+ width: page.dimensions[-2] -
696
+ (page.margins[:left] + page.margins[:right]),
697
+ height: page.dimensions[-1] -
698
+ (page.margins[:top] + page.margins[:bottom])
672
699
  )
673
700
 
674
701
  # This check maintains indentation settings across page breaks
@@ -683,21 +710,19 @@ module Prawn
683
710
  end
684
711
 
685
712
  def apply_margin_options(options)
686
- if options[:margin]
687
- # Treat :margin as CSS shorthand with 1-4 values.
688
- margin = Array(options[:margin])
689
- positions = { 4 => [0, 1, 2, 3], 3 => [0, 1, 2, 1],
690
- 2 => [0, 1, 0, 1], 1 => [0, 0, 0, 0] }[margin.length]
691
-
692
- [:top, :right, :bottom, :left].zip(positions).each do |p, i|
693
- options[:"#{p}_margin"] ||= margin[i]
694
- end
695
- end
696
-
697
- [:left, :right, :top, :bottom].each do |side|
698
- if margin = options[:"#{side}_margin"]
699
- state.page.margins[side] = margin
700
- end
713
+ sides = [:top, :right, :bottom, :left]
714
+ margin = Array(options[:margin])
715
+
716
+ # Treat :margin as CSS shorthand with 1-4 values.
717
+ positions = {
718
+ 4 => [0, 1, 2, 3], 3 => [0, 1, 2, 1],
719
+ 2 => [0, 1, 0, 1], 1 => [0, 0, 0, 0],
720
+ 0 => []
721
+ }[margin.length]
722
+
723
+ sides.zip(positions).each do |side, pos|
724
+ new_margin = options["#{side}_margin"] || (margin[pos] if pos)
725
+ state.page.margins[side] = new_margin if new_margin
701
726
  end
702
727
  end
703
728