prawn 1.1.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  # graphics.rb : Implements PDF drawing primitives
4
4
  #
@@ -6,17 +6,16 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
-
10
- require_relative "graphics/color"
11
- require_relative "graphics/dash"
12
- require_relative "graphics/cap_style"
13
- require_relative "graphics/join_style"
14
- require_relative "graphics/transparency"
15
- require_relative "graphics/transformation"
16
- require_relative "graphics/patterns"
9
+ require_relative 'graphics/blend_mode'
10
+ require_relative 'graphics/color'
11
+ require_relative 'graphics/dash'
12
+ require_relative 'graphics/cap_style'
13
+ require_relative 'graphics/join_style'
14
+ require_relative 'graphics/transparency'
15
+ require_relative 'graphics/transformation'
16
+ require_relative 'graphics/patterns'
17
17
 
18
18
  module Prawn
19
-
20
19
  # Implements the drawing facilities for Prawn::Document.
21
20
  # Use this to draw the most beautiful imaginable things.
22
21
  #
@@ -24,7 +23,7 @@ module Prawn
24
23
  # ruby-pdf.rubyforge.org
25
24
  #
26
25
  module Graphics
27
-
26
+ include BlendMode
28
27
  include Color
29
28
  include Dash
30
29
  include CapStyle
@@ -46,8 +45,8 @@ module Prawn
46
45
  # pdf.move_to(100,50)
47
46
  #
48
47
  def move_to(*point)
49
- x,y = map_to_absolute(point)
50
- add_content("%.3f %.3f m" % [ x, y ])
48
+ xy = PDF::Core.real_params(map_to_absolute(point))
49
+ renderer.add_content("#{xy} m")
51
50
  end
52
51
 
53
52
  # Draws a line from the current drawing position to the specified point.
@@ -57,8 +56,8 @@ module Prawn
57
56
  # pdf.line_to(50,50)
58
57
  #
59
58
  def line_to(*point)
60
- x,y = map_to_absolute(point)
61
- add_content("%.3f %.3f l" % [ x, y ])
59
+ xy = PDF::Core.real_params(map_to_absolute(point))
60
+ renderer.add_content("#{xy} l")
62
61
  end
63
62
 
64
63
  # Draws a Bezier curve from the current drawing position to the
@@ -66,14 +65,18 @@ module Prawn
66
65
  #
67
66
  # pdf.curve_to [100,100], :bounds => [[90,90],[75,75]]
68
67
  #
69
- def curve_to(dest,options={})
70
- options[:bounds] or raise Prawn::Errors::InvalidGraphicsPath,
71
- "Bounding points for bezier curve must be specified "+
72
- "as :bounds => [[x1,y1],[x2,y2]]"
68
+ def curve_to(dest, options = {})
69
+ options[:bounds] || raise(
70
+ Prawn::Errors::InvalidGraphicsPath,
71
+ 'Bounding points for bezier curve must be specified ' \
72
+ 'as :bounds => [[x1,y1],[x2,y2]]'
73
+ )
73
74
 
74
- curve_points = (options[:bounds] << dest).map { |e| map_to_absolute(e) }
75
- add_content("%.3f %.3f %.3f %.3f %.3f %.3f c" %
76
- curve_points.flatten )
75
+ curve_points = PDF::Core.real_params(
76
+ (options[:bounds] << dest).flat_map { |e| map_to_absolute(e) }
77
+ )
78
+
79
+ renderer.add_content("#{curve_points} c")
77
80
  end
78
81
 
79
82
  # Draws a rectangle given <tt>point</tt>, <tt>width</tt> and
@@ -81,9 +84,11 @@ module Prawn
81
84
  #
82
85
  # pdf.rectangle [300,300], 100, 200
83
86
  #
84
- def rectangle(point,width,height)
85
- x,y = map_to_absolute(point)
86
- add_content("%.3f %.3f %.3f %.3f re" % [ x, y - height, width, height ])
87
+ def rectangle(point, width, height)
88
+ x, y = map_to_absolute(point)
89
+ box = PDF::Core.real_params([x, y - height, width, height])
90
+
91
+ renderer.add_content("#{box} re")
87
92
  end
88
93
 
89
94
  # Draws a rounded rectangle given <tt>point</tt>, <tt>width</tt> and
@@ -92,12 +97,13 @@ module Prawn
92
97
  #
93
98
  # pdf.rounded_rectangle [300,300], 100, 200, 10
94
99
  #
95
- def rounded_rectangle(point,width,height,radius)
100
+ def rounded_rectangle(point, width, height, radius)
96
101
  x, y = point
97
- rounded_polygon(radius, point, [x + width, y], [x + width, y - height], [x, y - height])
102
+ rounded_polygon(
103
+ radius, point, [x + width, y], [x + width, y - height], [x, y - height]
104
+ )
98
105
  end
99
106
 
100
-
101
107
  ###########################################################
102
108
  # Higher level functions: May use relative coords #
103
109
  ###########################################################
@@ -117,7 +123,7 @@ module Prawn
117
123
  # pdf.line_width(5)
118
124
  # pdf.line_width #=> 5
119
125
  #
120
- def line_width(width=nil)
126
+ def line_width(width = nil)
121
127
  if width
122
128
  self.line_width = width
123
129
  else
@@ -132,7 +138,7 @@ module Prawn
132
138
  # pdf.line(100,100,200,250)
133
139
  #
134
140
  def line(*points)
135
- x0,y0,x1,y1 = points.flatten
141
+ x0, y0, x1, y1 = points.flatten
136
142
  move_to(x0, y0)
137
143
  line_to(x1, y1)
138
144
  end
@@ -143,14 +149,10 @@ module Prawn
143
149
  # # draw a line from [25, 75] to [100, 75]
144
150
  # horizontal_line 25, 100, :at => 75
145
151
  #
146
- def horizontal_line(x1,x2,options={})
147
- if options[:at]
148
- y1 = options[:at]
149
- else
150
- y1 = y - bounds.absolute_bottom
151
- end
152
+ def horizontal_line(x1, x2, options = {})
153
+ y1 = options[:at] || y - bounds.absolute_bottom
152
154
 
153
- line(x1,y1,x2,y1)
155
+ line(x1, y1, x2, y1)
154
156
  end
155
157
 
156
158
  # Draws a horizontal line from the left border to the right border of the
@@ -165,8 +167,8 @@ module Prawn
165
167
  # # draw a line from [25, 100] to [25, 300]
166
168
  # vertical_line 100, 300, :at => 25
167
169
  #
168
- def vertical_line(y1,y2,params)
169
- line(params[:at],y1,params[:at],y2)
170
+ def vertical_line(y1, y2, params)
171
+ line(params[:at], y1, params[:at], y2)
170
172
  end
171
173
 
172
174
  # Draws a Bezier curve between two points, bounded by two additional
@@ -174,9 +176,9 @@ module Prawn
174
176
  #
175
177
  # pdf.curve [50,100], [100,100], :bounds => [[90,90],[75,75]]
176
178
  #
177
- def curve(origin,dest, options={})
179
+ def curve(origin, dest, options = {})
178
180
  move_to(*origin)
179
- curve_to(dest,options)
181
+ curve_to(dest, options)
180
182
  end
181
183
 
182
184
  # This constant is used to approximate a symmetrical arc using a cubic
@@ -184,9 +186,9 @@ module Prawn
184
186
  #
185
187
  KAPPA = 4.0 * ((Math.sqrt(2) - 1.0) / 3.0)
186
188
 
187
- # Draws a circle of radius <tt>radius</tt> with the centre-point at <tt>point</tt>
188
- # as a complete subpath. The drawing point will be moved to the
189
- # centre-point upon completion of the drawing the circle.
189
+ # Draws a circle of radius <tt>radius</tt> with the centre-point at
190
+ # <tt>point</tt> as a complete subpath. The drawing point will be moved to
191
+ # the centre-point upon completion of the drawing the circle.
190
192
  #
191
193
  # pdf.circle [100,100], 25
192
194
  #
@@ -194,36 +196,36 @@ module Prawn
194
196
  ellipse(center, radius, radius)
195
197
  end
196
198
 
197
- # Draws an ellipse of +x+ radius <tt>r1</tt> and +y+ radius <tt>r2</tt>
198
- # with the centre-point at <tt>point</tt> as a complete subpath. The
199
- # drawing point will be moved to the centre-point upon completion of the
200
- # drawing the ellipse.
199
+ # Draws an ellipse of +x+ radius <tt>radius1</tt> and +y+ radius
200
+ # <tt>radius2</tt> with the centre-point at <tt>point</tt> as a complete
201
+ # subpath. The drawing point will be moved to the centre-point upon
202
+ # completion of the drawing the ellipse.
201
203
  #
202
204
  # # draws an ellipse with x-radius 25 and y-radius 50
203
205
  # pdf.ellipse [100,100], 25, 50
204
206
  #
205
- def ellipse(point, r1, r2 = r1)
207
+ def ellipse(point, radius1, radius2 = radius1)
206
208
  x, y = point
207
- l1 = r1 * KAPPA
208
- l2 = r2 * KAPPA
209
+ l1 = radius1 * KAPPA
210
+ l2 = radius2 * KAPPA
209
211
 
210
- move_to(x + r1, y)
212
+ move_to(x + radius1, y)
211
213
 
212
214
  # Upper right hand corner
213
- curve_to [x, y + r2],
214
- :bounds => [[x + r1, y + l2], [x + l1, y + r2]]
215
+ curve_to [x, y + radius2],
216
+ bounds: [[x + radius1, y + l2], [x + l1, y + radius2]]
215
217
 
216
218
  # Upper left hand corner
217
- curve_to [x - r1, y],
218
- :bounds => [[x - l1, y + r2], [x - r1, y + l2]]
219
+ curve_to [x - radius1, y],
220
+ bounds: [[x - l1, y + radius2], [x - radius1, y + l2]]
219
221
 
220
222
  # Lower left hand corner
221
- curve_to [x, y - r2],
222
- :bounds => [[x - r1, y - l2], [x - l1, y - r2]]
223
+ curve_to [x, y - radius2],
224
+ bounds: [[x - radius1, y - l2], [x - l1, y - radius2]]
223
225
 
224
226
  # Lower right hand corner
225
- curve_to [x + r1, y],
226
- :bounds => [[x + l1, y - r2], [x + r1, y - l2]]
227
+ curve_to [x + radius1, y],
228
+ bounds: [[x + l1, y - radius2], [x + radius1, y - l2]]
227
229
 
228
230
  move_to(x, y)
229
231
  end
@@ -239,36 +241,47 @@ module Prawn
239
241
  line_to(*point)
240
242
  end
241
243
  # close the path
242
- add_content "h"
244
+ renderer.add_content 'h'
243
245
  end
244
246
 
245
- # Draws a rounded polygon from specified points using the radius to define bezier curves
247
+ # Draws a rounded polygon from specified points using the radius to define
248
+ # bezier curves
246
249
  #
247
- # # draws a rounded filled in polygon
248
- # pdf.fill_and_stroke_rounded_polygon(10, [100, 250], [200, 300], [300, 250],
249
- # [300, 150], [200, 100], [100, 150])
250
+ # # draws a rounded filled in polygon
251
+ # pdf.fill_and_stroke_rounded_polygon(
252
+ # 10, [100, 250], [200, 300], [300, 250], [300, 150], [200, 100],
253
+ # [100, 150]
254
+ # )
250
255
  def rounded_polygon(radius, *points)
251
256
  move_to point_on_line(radius, points[1], points[0])
252
257
  sides = points.size
253
258
  points << points[0] << points[1]
254
- (sides).times do |i|
259
+ sides.times do |i|
255
260
  rounded_vertex(radius, points[i], points[i + 1], points[i + 2])
256
261
  end
257
262
  # close the path
258
- add_content "h"
263
+ renderer.add_content 'h'
259
264
  end
260
265
 
261
-
262
- # Creates a rounded vertex for a line segment used for building a rounded polygon
263
- # requires a radius to define bezier curve and three points. The first two points define
264
- # the line segment and the third point helps define the curve for the vertex.
266
+ # Creates a rounded vertex for a line segment used for building a rounded
267
+ # polygon requires a radius to define bezier curve and three points. The
268
+ # first two points define the line segment and the third point helps define
269
+ # the curve for the vertex.
265
270
  def rounded_vertex(radius, *points)
266
- radial_point_1 = point_on_line(radius, points[0], points[1])
267
- bezier_point_1 = point_on_line((radius - radius*KAPPA), points[0], points[1] )
268
- radial_point_2 = point_on_line(radius, points[2], points[1])
269
- bezier_point_2 = point_on_line((radius - radius*KAPPA), points[2], points[1])
270
- line_to(radial_point_1)
271
- curve_to(radial_point_2, :bounds => [bezier_point_1, bezier_point_2])
271
+ radial_point1 = point_on_line(radius, points[0], points[1])
272
+ bezier_point1 = point_on_line(
273
+ (radius - radius * KAPPA),
274
+ points[0],
275
+ points[1]
276
+ )
277
+ radial_point2 = point_on_line(radius, points[2], points[1])
278
+ bezier_point2 = point_on_line(
279
+ (radius - radius * KAPPA),
280
+ points[2],
281
+ points[1]
282
+ )
283
+ line_to(radial_point1)
284
+ curve_to(radial_point2, bounds: [bezier_point1, bezier_point2])
272
285
  end
273
286
 
274
287
  # Strokes the current path. If a block is provided, yields to the block
@@ -276,7 +289,7 @@ module Prawn
276
289
  #
277
290
  def stroke
278
291
  yield if block_given?
279
- add_content "S"
292
+ renderer.add_content 'S'
280
293
  end
281
294
 
282
295
  # Closes and strokes the current path. If a block is provided, yields to
@@ -284,7 +297,7 @@ module Prawn
284
297
  #
285
298
  def close_and_stroke
286
299
  yield if block_given?
287
- add_content "s"
300
+ renderer.add_content 's'
288
301
  end
289
302
 
290
303
  # Draws and strokes a rectangle represented by the current bounding box
@@ -319,38 +332,56 @@ module Prawn
319
332
  #
320
333
  def stroke_axis(options = {})
321
334
  options = {
322
- :at => [0,0],
323
- :height => bounds.height.to_i - (options[:at] || [0,0])[1],
324
- :width => bounds.width.to_i - (options[:at] || [0,0])[0],
325
- :step_length => 100,
326
- :negative_axes_length => 20,
327
- :color => "000000",
335
+ at: [0, 0],
336
+ height: bounds.height.to_i - (options[:at] || [0, 0])[1],
337
+ width: bounds.width.to_i - (options[:at] || [0, 0])[0],
338
+ step_length: 100,
339
+ negative_axes_length: 20,
340
+ color: '000000'
328
341
  }.merge(options)
329
342
 
330
- Prawn.verify_options([:at, :width, :height, :step_length,
331
- :negative_axes_length, :color], options)
343
+ Prawn.verify_options(
344
+ %i[at width height step_length negative_axes_length color],
345
+ options
346
+ )
332
347
 
333
348
  save_graphics_state do
334
349
  fill_color(options[:color])
335
350
  stroke_color(options[:color])
336
351
 
337
- dash(1, :space => 4)
338
- stroke_horizontal_line(options[:at][0] - options[:negative_axes_length],
339
- options[:at][0] + options[:width], :at => options[:at][1])
340
- stroke_vertical_line(options[:at][1] - options[:negative_axes_length],
341
- options[:at][1] + options[:height], :at => options[:at][0])
352
+ dash(1, space: 4)
353
+ stroke_horizontal_line(
354
+ options[:at][0] - options[:negative_axes_length],
355
+ options[:at][0] + options[:width],
356
+ at: options[:at][1]
357
+ )
358
+ stroke_vertical_line(
359
+ options[:at][1] - options[:negative_axes_length],
360
+ options[:at][1] + options[:height],
361
+ at: options[:at][0]
362
+ )
342
363
  undash
343
364
 
344
365
  fill_circle(options[:at], 1)
345
366
 
346
- (options[:step_length]..options[:width]).step(options[:step_length]) do |point|
367
+ (options[:step_length]..options[:width])
368
+ .step(options[:step_length]) do |point|
347
369
  fill_circle([options[:at][0] + point, options[:at][1]], 1)
348
- draw_text(point, :at => [options[:at][0] + point - 5, options[:at][1] - 10], :size => 7)
370
+ draw_text(
371
+ point,
372
+ at: [options[:at][0] + point - 5, options[:at][1] - 10],
373
+ size: 7
374
+ )
349
375
  end
350
376
 
351
- (options[:step_length]..options[:height]).step(options[:step_length]) do |point|
377
+ (options[:step_length]..options[:height])
378
+ .step(options[:step_length]) do |point|
352
379
  fill_circle([options[:at][0], options[:at][1] + point], 1)
353
- draw_text(point, :at => [options[:at][0] - 17, options[:at][1] + point - 2], :size => 7)
380
+ draw_text(
381
+ point,
382
+ at: [options[:at][0] - 17, options[:at][1] + point - 2],
383
+ size: 7
384
+ )
354
385
  end
355
386
  end
356
387
  end
@@ -362,9 +393,9 @@ module Prawn
362
393
  # will be used. See the PDF reference, "Graphics -> Path Construction and
363
394
  # Painting -> Clipping Path Operators" for details on the difference.
364
395
  #
365
- def fill(options={})
396
+ def fill(options = {})
366
397
  yield if block_given?
367
- add_content(options[:fill_rule] == :even_odd ? "f*" : "f")
398
+ renderer.add_content(options[:fill_rule] == :even_odd ? 'f*' : 'f')
368
399
  end
369
400
 
370
401
  # Closes, fills, and strokes the current path. If a block is provided,
@@ -376,15 +407,15 @@ module Prawn
376
407
  # will be used. See the PDF reference, "Graphics -> Path Construction and
377
408
  # Painting -> Clipping Path Operators" for details on the difference.
378
409
  #
379
- def fill_and_stroke(options={})
410
+ def fill_and_stroke(options = {})
380
411
  yield if block_given?
381
- add_content(options[:fill_rule] == :even_odd ? "b*" : "b")
412
+ renderer.add_content(options[:fill_rule] == :even_odd ? 'b*' : 'b')
382
413
  end
383
414
 
384
415
  # Closes the current path.
385
416
  #
386
417
  def close_path
387
- add_content "h"
418
+ renderer.add_content 'h'
388
419
  end
389
420
 
390
421
  ##
@@ -593,12 +624,20 @@ module Prawn
593
624
  # :call-seq:
594
625
  # fill_and_stroke_rounded_polygon(radius, *points)
595
626
 
596
- ops = %w{fill stroke fill_and_stroke}
597
- shapes = %w{line_to curve_to rectangle rounded_rectangle line horizontal_line horizontal_rule vertical_line
598
- curve circle_at circle ellipse_at ellipse polygon rounded_polygon rounded_vertex}
627
+ ops = %w[fill stroke fill_and_stroke]
628
+ shapes = %w[
629
+ line_to curve_to rectangle rounded_rectangle line horizontal_line
630
+ horizontal_rule vertical_line curve circle_at circle ellipse_at ellipse
631
+ polygon rounded_polygon rounded_vertex
632
+ ]
599
633
 
600
- ops.product(shapes).each do |operation,shape|
601
- class_eval "def #{operation}_#{shape}(*args); #{shape}(*args); #{operation}; end"
634
+ ops.product(shapes).each do |operation, shape|
635
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
636
+ def #{operation}_#{shape}(*args) # def fill_polygon(*args)
637
+ #{shape}(*args) # polygon(*args)
638
+ #{operation} # fill
639
+ end # end
640
+ METHOD
602
641
  end
603
642
 
604
643
  private
@@ -612,11 +651,11 @@ module Prawn
612
651
  end
613
652
 
614
653
  def write_line_width
615
- add_content("#{current_line_width} w")
654
+ renderer.add_content("#{current_line_width} w")
616
655
  end
617
656
 
618
657
  def map_to_absolute(*point)
619
- x,y = point.flatten
658
+ x, y = point.flatten
620
659
  [@bounding_box.absolute_left + x, @bounding_box.absolute_bottom + y]
621
660
  end
622
661
 
@@ -625,19 +664,18 @@ module Prawn
625
664
  end
626
665
 
627
666
  def degree_to_rad(angle)
628
- angle * Math::PI / 180
667
+ angle * Math::PI / 180
629
668
  end
630
669
 
631
- # Returns the coordinates for a point on a line that is a given distance away from the second
632
- # point defining the line segement
670
+ # Returns the coordinates for a point on a line that is a given distance
671
+ # away from the second point defining the line segement
633
672
  def point_on_line(distance_from_end, *points)
634
- x0,y0,x1,y1 = points.flatten
673
+ x0, y0, x1, y1 = points.flatten
635
674
  length = Math.sqrt((x1 - x0)**2 + (y1 - y0)**2)
636
675
  p = (length - distance_from_end) / length
637
- xr = x0 + p*(x1 - x0)
638
- yr = y0 + p*(y1 - y0)
676
+ xr = x0 + p * (x1 - x0)
677
+ yr = y0 + p * (y1 - y0)
639
678
  [xr, yr]
640
679
  end
641
-
642
680
  end
643
681
  end