prawn 2.0.2 → 2.3.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 (277) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/GPLv2 +20 -21
  5. data/Gemfile +3 -9
  6. data/Rakefile +20 -23
  7. data/lib/prawn.rb +37 -49
  8. data/lib/prawn/document.rb +181 -133
  9. data/lib/prawn/document/bounding_box.rb +41 -29
  10. data/lib/prawn/document/column_box.rb +7 -7
  11. data/lib/prawn/document/internals.rb +18 -8
  12. data/lib/prawn/document/span.rb +21 -16
  13. data/lib/prawn/encoding.rb +69 -68
  14. data/lib/prawn/errors.rb +12 -7
  15. data/lib/prawn/font.rb +115 -69
  16. data/lib/prawn/font_metric_cache.rb +14 -8
  17. data/lib/prawn/{font → fonts}/afm.rb +102 -68
  18. data/lib/prawn/{font → fonts}/dfont.rb +5 -11
  19. data/lib/prawn/fonts/otf.rb +11 -0
  20. data/lib/prawn/fonts/ttc.rb +36 -0
  21. data/lib/prawn/{font → fonts}/ttf.rb +87 -68
  22. data/lib/prawn/graphics.rb +120 -80
  23. data/lib/prawn/graphics/blend_mode.rb +65 -0
  24. data/lib/prawn/graphics/cap_style.rb +3 -3
  25. data/lib/prawn/graphics/color.rb +27 -25
  26. data/lib/prawn/graphics/dash.rb +23 -11
  27. data/lib/prawn/graphics/join_style.rb +9 -3
  28. data/lib/prawn/graphics/patterns.rb +197 -67
  29. data/lib/prawn/graphics/transformation.rb +17 -8
  30. data/lib/prawn/graphics/transparency.rb +17 -13
  31. data/lib/prawn/grid.rb +48 -47
  32. data/lib/prawn/image_handler.rb +5 -5
  33. data/lib/prawn/images.rb +39 -30
  34. data/lib/prawn/images/image.rb +2 -1
  35. data/lib/prawn/images/jpg.rb +28 -22
  36. data/lib/prawn/images/png.rb +107 -66
  37. data/lib/prawn/measurement_extensions.rb +10 -9
  38. data/lib/prawn/measurements.rb +19 -15
  39. data/lib/prawn/outline.rb +97 -77
  40. data/lib/prawn/repeater.rb +14 -10
  41. data/lib/prawn/security.rb +81 -61
  42. data/lib/prawn/security/arcfour.rb +2 -2
  43. data/lib/prawn/soft_mask.rb +26 -26
  44. data/lib/prawn/stamp.rb +20 -13
  45. data/lib/prawn/text.rb +68 -52
  46. data/lib/prawn/text/box.rb +11 -8
  47. data/lib/prawn/text/formatted.rb +5 -5
  48. data/lib/prawn/text/formatted/arranger.rb +78 -49
  49. data/lib/prawn/text/formatted/box.rb +134 -100
  50. data/lib/prawn/text/formatted/fragment.rb +11 -14
  51. data/lib/prawn/text/formatted/line_wrap.rb +121 -63
  52. data/lib/prawn/text/formatted/parser.rb +139 -117
  53. data/lib/prawn/text/formatted/wrap.rb +43 -31
  54. data/lib/prawn/transformation_stack.rb +44 -0
  55. data/lib/prawn/utilities.rb +7 -22
  56. data/lib/prawn/version.rb +2 -2
  57. data/lib/prawn/view.rb +17 -7
  58. data/manual/basic_concepts/adding_pages.rb +6 -7
  59. data/manual/basic_concepts/basic_concepts.rb +31 -22
  60. data/manual/basic_concepts/creation.rb +10 -11
  61. data/manual/basic_concepts/cursor.rb +4 -5
  62. data/manual/basic_concepts/measurement.rb +6 -7
  63. data/manual/basic_concepts/origin.rb +5 -6
  64. data/manual/basic_concepts/other_cursor_helpers.rb +11 -12
  65. data/manual/basic_concepts/view.rb +22 -16
  66. data/manual/bounding_box/bounding_box.rb +29 -24
  67. data/manual/bounding_box/bounds.rb +11 -12
  68. data/manual/bounding_box/canvas.rb +4 -5
  69. data/manual/bounding_box/creation.rb +6 -7
  70. data/manual/bounding_box/indentation.rb +14 -15
  71. data/manual/bounding_box/nesting.rb +24 -17
  72. data/manual/bounding_box/russian_boxes.rb +14 -13
  73. data/manual/bounding_box/stretchy.rb +12 -13
  74. data/manual/contents.rb +28 -22
  75. data/manual/cover.rb +33 -28
  76. data/manual/document_and_page_options/background.rb +11 -13
  77. data/manual/document_and_page_options/document_and_page_options.rb +25 -20
  78. data/manual/document_and_page_options/metadata.rb +18 -16
  79. data/manual/document_and_page_options/page_margins.rb +18 -20
  80. data/manual/document_and_page_options/page_size.rb +13 -12
  81. data/manual/document_and_page_options/print_scaling.rb +17 -15
  82. data/manual/example_helper.rb +5 -4
  83. data/manual/graphics/blend_mode.rb +52 -0
  84. data/manual/graphics/circle_and_ellipse.rb +4 -5
  85. data/manual/graphics/color.rb +7 -9
  86. data/manual/graphics/common_lines.rb +7 -8
  87. data/manual/graphics/fill_and_stroke.rb +4 -5
  88. data/manual/graphics/fill_rules.rb +9 -10
  89. data/manual/graphics/gradients.rb +27 -21
  90. data/manual/graphics/graphics.rb +48 -39
  91. data/manual/graphics/helper.rb +12 -9
  92. data/manual/graphics/line_width.rb +8 -7
  93. data/manual/graphics/lines_and_curves.rb +7 -8
  94. data/manual/graphics/polygon.rb +6 -8
  95. data/manual/graphics/rectangle.rb +4 -5
  96. data/manual/graphics/rotate.rb +6 -7
  97. data/manual/graphics/scale.rb +14 -15
  98. data/manual/graphics/soft_masks.rb +4 -5
  99. data/manual/graphics/stroke_cap.rb +6 -7
  100. data/manual/graphics/stroke_dash.rb +11 -12
  101. data/manual/graphics/stroke_join.rb +5 -6
  102. data/manual/graphics/translate.rb +9 -10
  103. data/manual/graphics/transparency.rb +7 -8
  104. data/manual/how_to_read_this_manual.rb +6 -6
  105. data/manual/images/absolute_position.rb +6 -7
  106. data/manual/images/fit.rb +7 -8
  107. data/manual/images/horizontal.rb +9 -10
  108. data/manual/images/images.rb +28 -24
  109. data/manual/images/plain_image.rb +5 -6
  110. data/manual/images/scale.rb +9 -10
  111. data/manual/images/vertical.rb +13 -14
  112. data/manual/images/width_and_height.rb +10 -11
  113. data/manual/layout/boxes.rb +5 -6
  114. data/manual/layout/content.rb +7 -8
  115. data/manual/layout/layout.rb +18 -16
  116. data/manual/layout/simple_grid.rb +6 -7
  117. data/manual/outline/add_subsection_to.rb +20 -21
  118. data/manual/outline/insert_section_after.rb +15 -16
  119. data/manual/outline/outline.rb +21 -17
  120. data/manual/outline/sections_and_pages.rb +17 -18
  121. data/manual/repeatable_content/alternate_page_numbering.rb +21 -17
  122. data/manual/repeatable_content/page_numbering.rb +17 -16
  123. data/manual/repeatable_content/repeatable_content.rb +25 -19
  124. data/manual/repeatable_content/repeater.rb +14 -15
  125. data/manual/repeatable_content/stamp.rb +14 -15
  126. data/manual/security/encryption.rb +9 -10
  127. data/manual/security/permissions.rb +19 -14
  128. data/manual/security/security.rb +19 -16
  129. data/manual/table.rb +3 -3
  130. data/manual/text/alignment.rb +16 -17
  131. data/manual/text/color.rb +12 -11
  132. data/manual/text/column_box.rb +9 -10
  133. data/manual/text/fallback_fonts.rb +25 -21
  134. data/manual/text/font.rb +11 -12
  135. data/manual/text/font_size.rb +13 -14
  136. data/manual/text/font_style.rb +7 -8
  137. data/manual/text/formatted_callbacks.rb +25 -21
  138. data/manual/text/formatted_text.rb +33 -25
  139. data/manual/text/free_flowing_text.rb +20 -21
  140. data/manual/text/inline.rb +18 -19
  141. data/manual/text/kerning_and_character_spacing.rb +14 -15
  142. data/manual/text/leading.rb +7 -8
  143. data/manual/text/line_wrapping.rb +37 -18
  144. data/manual/text/paragraph_indentation.rb +13 -14
  145. data/manual/text/positioned_text.rb +15 -16
  146. data/manual/text/registering_families.rb +20 -21
  147. data/manual/text/rendering_and_color.rb +9 -10
  148. data/manual/text/right_to_left_text.rb +26 -19
  149. data/manual/text/rotation.rb +28 -23
  150. data/manual/text/single_usage.rb +8 -9
  151. data/manual/text/text.rb +57 -52
  152. data/manual/text/text_box_excess.rb +20 -17
  153. data/manual/text/text_box_extensions.rb +18 -15
  154. data/manual/text/text_box_overflow.rb +18 -19
  155. data/manual/text/utf8.rb +11 -12
  156. data/manual/text/win_ansi_charset.rb +21 -19
  157. data/prawn.gemspec +45 -33
  158. data/spec/extensions/encoding_helpers.rb +3 -3
  159. data/spec/prawn/document/bounding_box_spec.rb +546 -0
  160. data/spec/prawn/document/column_box_spec.rb +75 -0
  161. data/spec/prawn/document/security_spec.rb +176 -0
  162. data/spec/prawn/document_annotations_spec.rb +76 -0
  163. data/spec/prawn/document_destinations_spec.rb +15 -0
  164. data/spec/prawn/document_grid_spec.rb +99 -0
  165. data/spec/prawn/document_reference_spec.rb +27 -0
  166. data/spec/prawn/document_span_spec.rb +36 -0
  167. data/spec/prawn/document_spec.rb +802 -0
  168. data/spec/prawn/font_metric_cache_spec.rb +54 -0
  169. data/spec/prawn/font_spec.rb +542 -0
  170. data/spec/prawn/graphics/blend_mode_spec.rb +63 -0
  171. data/spec/prawn/graphics/transparency_spec.rb +81 -0
  172. data/spec/prawn/graphics_spec.rb +837 -0
  173. data/spec/prawn/graphics_stroke_styles_spec.rb +229 -0
  174. data/spec/prawn/image_handler_spec.rb +53 -0
  175. data/spec/prawn/images/jpg_spec.rb +20 -0
  176. data/spec/prawn/images/png_spec.rb +283 -0
  177. data/spec/prawn/images_spec.rb +224 -0
  178. data/spec/prawn/measurements_extensions_spec.rb +24 -0
  179. data/spec/prawn/outline_spec.rb +412 -0
  180. data/spec/prawn/repeater_spec.rb +165 -0
  181. data/spec/prawn/soft_mask_spec.rb +74 -0
  182. data/spec/prawn/stamp_spec.rb +172 -0
  183. data/spec/prawn/text/box_spec.rb +1112 -0
  184. data/spec/prawn/text/formatted/arranger_spec.rb +466 -0
  185. data/spec/prawn/text/formatted/box_spec.rb +846 -0
  186. data/spec/prawn/text/formatted/fragment_spec.rb +343 -0
  187. data/spec/prawn/text/formatted/line_wrap_spec.rb +494 -0
  188. data/spec/prawn/text/formatted/parser_spec.rb +697 -0
  189. data/spec/prawn/text_draw_text_spec.rb +149 -0
  190. data/spec/prawn/text_rendering_mode_spec.rb +48 -0
  191. data/spec/prawn/text_spacing_spec.rb +95 -0
  192. data/spec/prawn/text_spec.rb +603 -0
  193. data/spec/prawn/text_with_inline_formatting_spec.rb +35 -0
  194. data/spec/prawn/transformation_stack_spec.rb +66 -0
  195. data/spec/prawn/view_spec.rb +63 -0
  196. data/spec/prawn_manual_spec.rb +35 -0
  197. data/spec/spec_helper.rb +19 -23
  198. metadata +145 -185
  199. metadata.gz.sig +4 -0
  200. data/data/images/16bit.alpha +0 -0
  201. data/data/images/16bit.color +0 -0
  202. data/data/images/16bit.png +0 -0
  203. data/data/images/arrow.png +0 -0
  204. data/data/images/arrow2.png +0 -0
  205. data/data/images/dice.alpha +0 -0
  206. data/data/images/dice.color +0 -0
  207. data/data/images/dice.png +0 -0
  208. data/data/images/dice_interlaced.png +0 -0
  209. data/data/images/fractal.jpg +0 -0
  210. data/data/images/indexed_color.dat +0 -0
  211. data/data/images/indexed_color.png +0 -0
  212. data/data/images/letterhead.jpg +0 -0
  213. data/data/images/license.md +0 -8
  214. data/data/images/page_white_text.alpha +0 -0
  215. data/data/images/page_white_text.color +0 -0
  216. data/data/images/page_white_text.png +0 -0
  217. data/data/images/pal_bk.png +0 -0
  218. data/data/images/pigs.jpg +0 -0
  219. data/data/images/prawn.png +0 -0
  220. data/data/images/ruport.png +0 -0
  221. data/data/images/ruport_data.dat +0 -0
  222. data/data/images/ruport_transparent.png +0 -0
  223. data/data/images/ruport_type0.png +0 -0
  224. data/data/images/stef.jpg +0 -0
  225. data/data/images/tru256.bmp +0 -0
  226. data/data/images/web-links.dat +0 -1
  227. data/data/images/web-links.png +0 -0
  228. data/data/pdfs/complex_template.pdf +0 -0
  229. data/data/pdfs/contains_ttf_font.pdf +0 -0
  230. data/data/pdfs/encrypted.pdf +0 -0
  231. data/data/pdfs/form.pdf +1 -819
  232. data/data/pdfs/hexagon.pdf +0 -61
  233. data/data/pdfs/indirect_reference.pdf +0 -86
  234. data/data/pdfs/multipage_template.pdf +0 -127
  235. data/data/pdfs/nested_pages.pdf +0 -118
  236. data/data/pdfs/page_without_mediabox.pdf +0 -193
  237. data/data/pdfs/resources_as_indirect_object.pdf +0 -83
  238. data/data/pdfs/two_hexagons.pdf +0 -90
  239. data/data/pdfs/version_1_6.pdf +0 -61
  240. data/data/shift_jis_text.txt +0 -1
  241. data/spec/acceptance/png.rb +0 -24
  242. data/spec/annotations_spec.rb +0 -67
  243. data/spec/bounding_box_spec.rb +0 -501
  244. data/spec/column_box_spec.rb +0 -59
  245. data/spec/destinations_spec.rb +0 -13
  246. data/spec/document_spec.rb +0 -742
  247. data/spec/extensions/mocha.rb +0 -45
  248. data/spec/font_metric_cache_spec.rb +0 -52
  249. data/spec/font_spec.rb +0 -475
  250. data/spec/formatted_text_arranger_spec.rb +0 -423
  251. data/spec/formatted_text_box_spec.rb +0 -716
  252. data/spec/formatted_text_fragment_spec.rb +0 -299
  253. data/spec/graphics_spec.rb +0 -666
  254. data/spec/grid_spec.rb +0 -95
  255. data/spec/image_handler_spec.rb +0 -53
  256. data/spec/images_spec.rb +0 -167
  257. data/spec/inline_formatted_text_parser_spec.rb +0 -568
  258. data/spec/jpg_spec.rb +0 -23
  259. data/spec/line_wrap_spec.rb +0 -366
  260. data/spec/measurement_units_spec.rb +0 -22
  261. data/spec/outline_spec.rb +0 -409
  262. data/spec/png_spec.rb +0 -235
  263. data/spec/reference_spec.rb +0 -25
  264. data/spec/repeater_spec.rb +0 -154
  265. data/spec/security_spec.rb +0 -151
  266. data/spec/soft_mask_spec.rb +0 -78
  267. data/spec/span_spec.rb +0 -43
  268. data/spec/stamp_spec.rb +0 -179
  269. data/spec/stroke_styles_spec.rb +0 -208
  270. data/spec/text_at_spec.rb +0 -142
  271. data/spec/text_box_spec.rb +0 -1038
  272. data/spec/text_rendering_mode_spec.rb +0 -45
  273. data/spec/text_spacing_spec.rb +0 -93
  274. data/spec/text_spec.rb +0 -549
  275. data/spec/text_with_inline_formatting_spec.rb +0 -35
  276. data/spec/transparency_spec.rb +0 -91
  277. data/spec/view_spec.rb +0 -42
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  # Implementation of the "ARCFOUR" algorithm ("alleged RC4 (tm)"). Implemented
4
4
  # as described at:
@@ -39,7 +39,7 @@ class Arcfour
39
39
  end
40
40
 
41
41
  def encrypt(string)
42
- string.unpack('c*').map{ |byte| byte ^ key_byte }.pack('c*')
42
+ string.unpack('c*').map { |byte| byte ^ key_byte }.pack('c*')
43
43
  end
44
44
 
45
45
  private
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # soft_mask.rb : Implements soft-masking
4
4
  #
5
5
  # Copyright September 2012, Alexander Mankuta. All Rights Reserved.
@@ -31,51 +31,51 @@ module Prawn
31
31
  renderer.min_version(1.4)
32
32
 
33
33
  group_attrs = ref!(
34
- :Type => :Group,
35
- :S => :Transparency,
36
- :CS => :DeviceRGB,
37
- :I => false,
38
- :K => false
34
+ Type: :Group,
35
+ S: :Transparency,
36
+ CS: :DeviceRGB,
37
+ I: false,
38
+ K: false
39
39
  )
40
40
 
41
41
  group = ref!(
42
- :Type => :XObject,
43
- :Subtype => :Form,
44
- :BBox => state.page.dimensions,
45
- :Group => group_attrs
42
+ Type: :XObject,
43
+ Subtype: :Form,
44
+ BBox: state.page.dimensions,
45
+ Group: group_attrs
46
46
  )
47
47
 
48
48
  state.page.stamp_stream(group, &block)
49
49
 
50
50
  mask = ref!(
51
- :Type => :Mask,
52
- :S => :Luminosity,
53
- :G => group
51
+ Type: :Mask,
52
+ S: :Luminosity,
53
+ G: group
54
54
  )
55
55
 
56
56
  g_state = ref!(
57
- :Type => :ExtGState,
58
- :SMask => mask,
57
+ Type: :ExtGState,
58
+ SMask: mask,
59
59
 
60
- :AIS => false,
61
- :BM => :Normal,
62
- :OP => false,
63
- :op => false,
64
- :OPM => 1,
65
- :SA => true
60
+ AIS: false,
61
+ BM: :Normal,
62
+ OP: false,
63
+ op: false,
64
+ OPM: 1,
65
+ SA: true
66
66
  )
67
67
 
68
68
  registry_key = {
69
- :bbox => state.page.dimensions,
70
- :mask => [group.stream.filters.normalized, group.stream.filtered_stream],
71
- :page => state.page_count
69
+ bbox: state.page.dimensions,
70
+ mask: [group.stream.filters.normalized, group.stream.filtered_stream],
71
+ page: state.page_count
72
72
  }.hash
73
73
 
74
74
  if soft_mask_registry[registry_key]
75
75
  renderer.add_content "/#{soft_mask_registry[registry_key]} gs"
76
76
  else
77
77
  masks = page.resources[:ExtGState] ||= {}
78
- id = masks.empty? ? 'GS1' : masks.keys.sort.last.succ
78
+ id = masks.empty? ? 'GS1' : masks.keys.max.succ
79
79
  masks[id] = g_state
80
80
 
81
81
  soft_mask_registry[registry_key] = id
@@ -1,5 +1,5 @@
1
- # encoding: utf-8
2
- #
1
+ # frozen_string_literal: true
2
+
3
3
  # stamp.rb : Implements a repeatable stamp
4
4
  #
5
5
  # Copyright October 2009, Daniel Nelson. All Rights Reserved.
@@ -92,9 +92,9 @@ module Prawn
92
92
  end
93
93
 
94
94
  def stamp_dictionary(name)
95
- fail Prawn::Errors::InvalidName if name.empty?
95
+ raise Prawn::Errors::InvalidName if name.empty?
96
96
  if stamp_dictionary_registry[name].nil?
97
- fail Prawn::Errors::UndefinedObjectName
97
+ raise Prawn::Errors::UndefinedObjectName
98
98
  end
99
99
 
100
100
  dict = stamp_dictionary_registry[name]
@@ -105,20 +105,27 @@ module Prawn
105
105
  end
106
106
 
107
107
  def create_stamp_dictionary(name)
108
- fail Prawn::Errors::InvalidName if name.empty?
109
- fail Prawn::Errors::NameTaken unless stamp_dictionary_registry[name].nil?
108
+ raise Prawn::Errors::InvalidName if name.empty?
109
+ raise Prawn::Errors::NameTaken unless stamp_dictionary_registry[name].nil?
110
+
110
111
  # BBox origin is the lower left margin of the page, so we need
111
112
  # it to be the full dimension of the page, or else things that
112
113
  # should appear near the top or right margin are invisible
113
- dictionary = ref!(:Type => :XObject,
114
- :Subtype => :Form,
115
- :BBox => [0, 0,
116
- state.page.dimensions[2], state.page.dimensions[3]])
114
+ dictionary = ref!(
115
+ Type: :XObject,
116
+ Subtype: :Form,
117
+ BBox: [
118
+ 0, 0,
119
+ state.page.dimensions[2], state.page.dimensions[3]
120
+ ]
121
+ )
117
122
 
118
123
  dictionary_name = "Stamp#{next_stamp_dictionary_id}"
119
124
 
120
- stamp_dictionary_registry[name] = { :stamp_dictionary_name => dictionary_name,
121
- :stamp_dictionary => dictionary }
125
+ stamp_dictionary_registry[name] = {
126
+ stamp_dictionary_name: dictionary_name,
127
+ stamp_dictionary: dictionary
128
+ }
122
129
  dictionary
123
130
  end
124
131
 
@@ -127,7 +134,7 @@ module Prawn
127
134
  # to the /Annot dictionary of the object that contains the
128
135
  # call to the stamp object.
129
136
  def update_annotation_references(annots)
130
- if annots && annots.any?
137
+ if annots&.any?
131
138
  state.page.dictionary.data[:Annots] ||= []
132
139
  state.page.dictionary.data[:Annots] |= annots
133
140
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  # text.rb : Implements PDF text primitives
4
4
  #
@@ -6,12 +6,10 @@
6
6
  #
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
 
9
- require "zlib"
9
+ require 'zlib'
10
10
 
11
- require "pdf/core/text"
12
-
13
- require_relative "text/formatted"
14
- require_relative "text/box"
11
+ require_relative 'text/formatted'
12
+ require_relative 'text/box'
15
13
 
16
14
  module Prawn
17
15
  module Text
@@ -19,11 +17,11 @@ module Prawn
19
17
  include Prawn::Text::Formatted
20
18
 
21
19
  # No-Break Space
22
- Prawn::Text::NBSP = " "
20
+ NBSP = "\u00A0"
23
21
  # Zero Width Space (indicate word boundaries without a space)
24
- Prawn::Text::ZWSP = [8203].pack("U")
22
+ ZWSP = "\u200B"
25
23
  # Soft Hyphen (invisible, except when causing a line break)
26
- Prawn::Text::SHY = "­"
24
+ SHY = "\u00AD"
27
25
 
28
26
  # @group Stable API
29
27
 
@@ -139,9 +137,9 @@ module Prawn
139
137
  # each line is included below the last line;
140
138
  # otherwise, document.y is placed just below the
141
139
  # descender of the last line printed [true]
142
- # <tt>:mode</tt>:: The text rendering mode to use. Use this to specify if the
143
- # text should render with the fill color, stroke color or
144
- # both. See the comments to text_rendering_mode() to see
140
+ # <tt>:mode</tt>:: The text rendering mode to use. Use this to specify if
141
+ # the text should render with the fill color, stroke color
142
+ # or both. See the comments to text_rendering_mode() to see
145
143
  # a list of valid options. [0]
146
144
  #
147
145
  # == Exceptions
@@ -153,15 +151,17 @@ module Prawn
153
151
  #
154
152
  def text(string, options = {})
155
153
  return false if string.nil?
154
+
156
155
  # we modify the options. don't change the user's hash
157
156
  options = options.dup
158
157
 
159
- if p = options[:inline_format]
158
+ p = options[:inline_format]
159
+ if p
160
160
  p = [] unless p.is_a?(Array)
161
161
  options.delete(:inline_format)
162
- array = self.text_formatter.format(string, *p)
162
+ array = text_formatter.format(string, *p)
163
163
  else
164
- array = [{ :text => string }]
164
+ array = [{ text: string }]
165
165
  end
166
166
 
167
167
  formatted_text(array, options)
@@ -190,14 +190,15 @@ module Prawn
190
190
  def formatted_text(array, options = {})
191
191
  options = inspect_options_for_text(options.dup)
192
192
 
193
- if color = options.delete(:color)
193
+ color = options.delete(:color)
194
+ if color
194
195
  array = array.map do |fragment|
195
- fragment[:color] ? fragment : fragment.merge(:color => color)
196
+ fragment[:color] ? fragment : fragment.merge(color: color)
196
197
  end
197
198
  end
198
199
 
199
200
  if @indent_paragraphs
200
- self.text_formatter.array_paragraphs(array).each do |paragraph|
201
+ text_formatter.array_paragraphs(array).each do |paragraph|
201
202
  remaining_text = draw_indented_formatted_line(paragraph, options)
202
203
 
203
204
  if @no_text_printed
@@ -208,8 +209,10 @@ module Prawn
208
209
  end
209
210
  end
210
211
 
211
- remaining_text = fill_formatted_text_box(remaining_text, options)
212
- draw_remaining_formatted_text_on_new_pages(remaining_text, options)
212
+ unless @all_text_printed
213
+ remaining_text = fill_formatted_text_box(remaining_text, options)
214
+ draw_remaining_formatted_text_on_new_pages(remaining_text, options)
215
+ end
213
216
  end
214
217
  else
215
218
  remaining_text = fill_formatted_text_box(array, options)
@@ -236,7 +239,8 @@ module Prawn
236
239
  # == Rotation
237
240
  #
238
241
  # Text can be rotated before it is placed on the canvas by specifying the
239
- # <tt>:rotate</tt> option with a given angle. Rotation occurs counter-clockwise.
242
+ # <tt>:rotate</tt> option with a given angle. Rotation occurs
243
+ # counter-clockwise.
240
244
  #
241
245
  # == Encoding
242
246
  #
@@ -253,7 +257,8 @@ module Prawn
253
257
  #
254
258
  # == Options (default values marked in [])
255
259
  #
256
- # <tt>:at</tt>:: <tt>[x, y]</tt>(required). The position at which to start the text
260
+ # <tt>:at</tt>:: <tt>[x, y]</tt>(required). The position at which to start
261
+ # the text
257
262
  # <tt>:kerning</tt>:: <tt>boolean</tt>. Whether or not to use kerning (if it
258
263
  # is available with the current font)
259
264
  # [value of default_kerning?]
@@ -277,7 +282,7 @@ module Prawn
277
282
  text = text.to_s.dup
278
283
  save_font do
279
284
  process_text_options(options)
280
- font.normalize_encoding!(text)
285
+ text = font.normalize_encoding(text)
281
286
  font_size(options[:size]) { draw_text!(text, options) }
282
287
  end
283
288
  end
@@ -289,9 +294,9 @@ module Prawn
289
294
  unless font.unicode? || font.class.hide_m17n_warning || text.ascii_only?
290
295
  warn "PDF's built-in fonts have very limited support for " \
291
296
  "internationalized text.\nIf you need full UTF-8 support, " \
292
- "consider using a TTF font instead.\n\nTo disable this " \
297
+ "consider using an external font instead.\n\nTo disable this " \
293
298
  "warning, add the following line to your code:\n" \
294
- "Prawn::Font::AFM.hide_m17n_warning = true\n"
299
+ "Prawn::Fonts::AFM.hide_m17n_warning = true\n"
295
300
 
296
301
  font.class.hide_m17n_warning = true
297
302
  end
@@ -317,7 +322,7 @@ module Prawn
317
322
  # any text
318
323
  #
319
324
  def height_of(string, options = {})
320
- height_of_formatted([{ :text => string }], options)
325
+ height_of_formatted([{ text: string }], options)
321
326
  end
322
327
 
323
328
  # Gets height of formatted text in PDF points.
@@ -332,15 +337,15 @@ module Prawn
332
337
  #
333
338
  def height_of_formatted(array, options = {})
334
339
  if options[:indent_paragraphs]
335
- fail NotImplementedError, ":indent_paragraphs option not available" \
336
- "with height_of"
340
+ raise NotImplementedError, ':indent_paragraphs option not available' \
341
+ 'with height_of'
337
342
  end
338
343
  process_final_gap_option(options)
339
344
  box = Text::Formatted::Box.new(
340
345
  array,
341
- options.merge(:height => 100000000, :document => self)
346
+ options.merge(height: 100_000_000, document: self)
342
347
  )
343
- box.render(:dry_run => true)
348
+ box.render(dry_run: true)
344
349
 
345
350
  height = box.height
346
351
  height += box.line_gap + box.leading if @final_gap
@@ -350,7 +355,7 @@ module Prawn
350
355
  private
351
356
 
352
357
  def draw_remaining_formatted_text_on_new_pages(remaining_text, options)
353
- while remaining_text.length > 0
358
+ until remaining_text.empty?
354
359
  @bounding_box.move_past_bottom
355
360
  previous_remaining_text = remaining_text
356
361
  remaining_text = fill_formatted_text_box(remaining_text, options)
@@ -359,14 +364,14 @@ module Prawn
359
364
  end
360
365
 
361
366
  def draw_indented_formatted_line(string, options)
362
- if options.fetch(:direction, text_direction) == :ltr
363
- gap = [@indent_paragraphs, 0]
364
- else
365
- gap = [0, @indent_paragraphs]
366
- end
367
+ gap = if options.fetch(:direction, text_direction) == :ltr
368
+ [@indent_paragraphs, 0]
369
+ else
370
+ [0, @indent_paragraphs]
371
+ end
367
372
 
368
373
  indent(*gap) do
369
- fill_formatted_text_box(string, options.dup.merge(:single_line => true))
374
+ fill_formatted_text_box(string, options.dup.merge(single_line: true))
370
375
  end
371
376
  end
372
377
 
@@ -384,33 +389,40 @@ module Prawn
384
389
  end
385
390
 
386
391
  def merge_text_box_positioning_options(options)
387
- bottom = @bounding_box.stretchy? ? @margin_box.absolute_bottom :
388
- @bounding_box.absolute_bottom
392
+ bottom =
393
+ if @bounding_box.stretchy?
394
+ @margin_box.absolute_bottom
395
+ else
396
+ @bounding_box.absolute_bottom
397
+ end
389
398
 
390
399
  options[:height] = y - bottom
391
400
  options[:width] = bounds.width
392
- options[:at] = [@bounding_box.left_side - @bounding_box.absolute_left,
393
- y - @bounding_box.absolute_bottom]
401
+ options[:at] = [
402
+ @bounding_box.left_side - @bounding_box.absolute_left,
403
+ y - @bounding_box.absolute_bottom
404
+ ]
394
405
  end
395
406
 
396
407
  def inspect_options_for_draw_text(options)
397
408
  if options[:at].nil?
398
- fail ArgumentError, "The :at option is required for draw_text"
409
+ raise ArgumentError, 'The :at option is required for draw_text'
399
410
  elsif options[:align]
400
- fail ArgumentError, "The :align option does not work with draw_text"
411
+ raise ArgumentError, 'The :align option does not work with draw_text'
401
412
  end
402
- if options[:kerning].nil? then
413
+
414
+ if options[:kerning].nil?
403
415
  options[:kerning] = default_kerning?
404
416
  end
405
- valid_options = PDF::Core::Text::VALID_OPTIONS + [:at, :rotate]
417
+ valid_options = PDF::Core::Text::VALID_OPTIONS + %i[at rotate]
406
418
  Prawn.verify_options(valid_options, options)
407
419
  options
408
420
  end
409
421
 
410
422
  def inspect_options_for_text(options)
411
423
  if options[:at]
412
- fail ArgumentError, ":at is no longer a valid option with text." \
413
- "use draw_text or text_box instead"
424
+ raise ArgumentError, ':at is no longer a valid option with text.' \
425
+ 'use draw_text or text_box instead'
414
426
  end
415
427
  process_final_gap_option(options)
416
428
  process_indent_paragraphs_option(options)
@@ -428,13 +440,17 @@ module Prawn
428
440
  options.delete(:indent_paragraphs)
429
441
  end
430
442
 
431
- def move_text_position(dy)
432
- bottom = @bounding_box.stretchy? ? @margin_box.absolute_bottom :
433
- @bounding_box.absolute_bottom
443
+ def move_text_position(amount)
444
+ bottom =
445
+ if @bounding_box.stretchy?
446
+ @margin_box.absolute_bottom
447
+ else
448
+ @bounding_box.absolute_bottom
449
+ end
434
450
 
435
- @bounding_box.move_past_bottom if (y - dy) < bottom
451
+ @bounding_box.move_past_bottom if (y - amount) < bottom
436
452
 
437
- self.y -= dy
453
+ self.y -= amount
438
454
  end
439
455
  end
440
456
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  # text/rectangle.rb : Implements text boxes
4
4
  #
@@ -7,7 +7,7 @@
7
7
  # This is free software. Please see the LICENSE and COPYING files for details.
8
8
  #
9
9
 
10
- require_relative "formatted/box"
10
+ require_relative 'formatted/box'
11
11
 
12
12
  module Prawn
13
13
  module Text
@@ -52,7 +52,8 @@ module Prawn
52
52
  # <tt>[x, y]</tt>. The upper left corner of the box
53
53
  # [@document.bounds.left, @document.bounds.top]
54
54
  # <tt>:width</tt>::
55
- # <tt>number</tt>. The width of the box [@document.bounds.right - @at[0]]
55
+ # <tt>number</tt>. The width of the box
56
+ # [@document.bounds.right - @at[0]]
56
57
  # <tt>:height</tt>::
57
58
  # <tt>number</tt>. The height of the box [default_height()]
58
59
  # <tt>:direction</tt>::
@@ -60,7 +61,7 @@ module Prawn
60
61
  # or right-to-left) [value of document.text_direction]
61
62
  # <tt>:fallback_fonts</tt>::
62
63
  # An array of font names. Each name must be the name of an AFM font or
63
- # the name that was used to register a family of TTF fonts (see
64
+ # the name that was used to register a family of external fonts (see
64
65
  # Prawn::Document#font_families). If present, then each glyph will be
65
66
  # rendered using the first font that includes the glyph, starting with
66
67
  # the current font and then moving through :fallback_fonts from
@@ -82,7 +83,8 @@ module Prawn
82
83
  # <tt>number</tt>. Additional space between lines [value of
83
84
  # document.default_leading]
84
85
  # <tt>:single_line</tt>::
85
- # <tt>boolean</tt>. If true, then only the first line will be drawn [false]
86
+ # <tt>boolean</tt>. If true, then only the first line will be drawn
87
+ # [false]
86
88
  # <tt>:overflow</tt>::
87
89
  # <tt>:truncate</tt>, <tt>:shrink_to_fit</tt>, or <tt>:expand</tt>
88
90
  # This controls the behavior when the amount of text
@@ -105,9 +107,10 @@ module Prawn
105
107
  options = options.dup
106
108
  options[:document] = self
107
109
 
108
- box = if p = options.delete(:inline_format)
110
+ box = if options[:inline_format]
111
+ p = options.delete(:inline_format)
109
112
  p = [] unless p.is_a?(Array)
110
- array = self.text_formatter.format(string, *p)
113
+ array = text_formatter.format(string, *p)
111
114
  Text::Formatted::Box.new(array, options)
112
115
  else
113
116
  Text::Box.new(string, options)
@@ -126,7 +129,7 @@ module Prawn
126
129
  #
127
130
  class Box < Prawn::Text::Formatted::Box
128
131
  def initialize(string, options = {})
129
- super([{ :text => string }], options)
132
+ super([{ text: string }], options)
130
133
  end
131
134
 
132
135
  def render(flags = {})