prawn 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) 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 +2 -0
  6. data/Rakefile +10 -3
  7. data/lib/prawn.rb +9 -3
  8. data/lib/prawn/document.rb +40 -18
  9. data/lib/prawn/document/bounding_box.rb +9 -4
  10. data/lib/prawn/document/column_box.rb +2 -0
  11. data/lib/prawn/document/internals.rb +6 -4
  12. data/lib/prawn/document/span.rb +2 -0
  13. data/lib/prawn/encoding.rb +4 -1
  14. data/lib/prawn/errors.rb +2 -0
  15. data/lib/prawn/font.rb +34 -17
  16. data/lib/prawn/font_metric_cache.rb +8 -3
  17. data/lib/prawn/{font → fonts}/afm.rb +14 -7
  18. data/lib/prawn/{font → fonts}/dfont.rb +3 -1
  19. data/lib/prawn/fonts/otf.rb +11 -0
  20. data/lib/prawn/{font → fonts}/ttc.rb +3 -1
  21. data/lib/prawn/{font → fonts}/ttf.rb +23 -12
  22. data/lib/prawn/graphics.rb +24 -26
  23. data/lib/prawn/graphics/blend_mode.rb +2 -0
  24. data/lib/prawn/graphics/cap_style.rb +2 -0
  25. data/lib/prawn/graphics/color.rb +8 -3
  26. data/lib/prawn/graphics/dash.rb +3 -1
  27. data/lib/prawn/graphics/join_style.rb +2 -0
  28. data/lib/prawn/graphics/patterns.rb +7 -2
  29. data/lib/prawn/graphics/transformation.rb +5 -1
  30. data/lib/prawn/graphics/transparency.rb +2 -0
  31. data/lib/prawn/grid.rb +39 -38
  32. data/lib/prawn/image_handler.rb +2 -0
  33. data/lib/prawn/images.rb +21 -19
  34. data/lib/prawn/images/image.rb +2 -0
  35. data/lib/prawn/images/jpg.rb +2 -0
  36. data/lib/prawn/images/png.rb +9 -9
  37. data/lib/prawn/measurement_extensions.rb +2 -0
  38. data/lib/prawn/measurements.rb +5 -0
  39. data/lib/prawn/outline.rb +2 -0
  40. data/lib/prawn/repeater.rb +2 -0
  41. data/lib/prawn/security.rb +26 -24
  42. data/lib/prawn/security/arcfour.rb +2 -0
  43. data/lib/prawn/soft_mask.rb +3 -1
  44. data/lib/prawn/stamp.rb +4 -1
  45. data/lib/prawn/text.rb +14 -12
  46. data/lib/prawn/text/box.rb +3 -1
  47. data/lib/prawn/text/formatted.rb +2 -0
  48. data/lib/prawn/text/formatted/arranger.rb +12 -12
  49. data/lib/prawn/text/formatted/box.rb +23 -13
  50. data/lib/prawn/text/formatted/fragment.rb +2 -0
  51. data/lib/prawn/text/formatted/line_wrap.rb +10 -8
  52. data/lib/prawn/text/formatted/parser.rb +8 -10
  53. data/lib/prawn/text/formatted/wrap.rb +4 -2
  54. data/lib/prawn/transformation_stack.rb +5 -2
  55. data/lib/prawn/utilities.rb +2 -2
  56. data/lib/prawn/version.rb +3 -1
  57. data/lib/prawn/view.rb +15 -7
  58. data/manual/basic_concepts/adding_pages.rb +2 -0
  59. data/manual/basic_concepts/basic_concepts.rb +4 -2
  60. data/manual/basic_concepts/creation.rb +2 -0
  61. data/manual/basic_concepts/cursor.rb +2 -0
  62. data/manual/basic_concepts/measurement.rb +3 -1
  63. data/manual/basic_concepts/origin.rb +2 -0
  64. data/manual/basic_concepts/other_cursor_helpers.rb +2 -0
  65. data/manual/basic_concepts/view.rb +2 -0
  66. data/manual/bounding_box/bounding_box.rb +4 -2
  67. data/manual/bounding_box/bounds.rb +6 -4
  68. data/manual/bounding_box/canvas.rb +2 -0
  69. data/manual/bounding_box/creation.rb +2 -0
  70. data/manual/bounding_box/indentation.rb +2 -0
  71. data/manual/bounding_box/nesting.rb +2 -0
  72. data/manual/bounding_box/russian_boxes.rb +6 -4
  73. data/manual/bounding_box/stretchy.rb +2 -0
  74. data/manual/contents.rb +2 -0
  75. data/manual/cover.rb +10 -7
  76. data/manual/document_and_page_options/background.rb +2 -0
  77. data/manual/document_and_page_options/document_and_page_options.rb +4 -2
  78. data/manual/document_and_page_options/metadata.rb +2 -0
  79. data/manual/document_and_page_options/page_margins.rb +2 -0
  80. data/manual/document_and_page_options/page_size.rb +2 -0
  81. data/manual/document_and_page_options/print_scaling.rb +2 -0
  82. data/manual/example_helper.rb +5 -2
  83. data/manual/graphics/blend_mode.rb +6 -4
  84. data/manual/graphics/circle_and_ellipse.rb +2 -0
  85. data/manual/graphics/color.rb +2 -0
  86. data/manual/graphics/common_lines.rb +2 -0
  87. data/manual/graphics/fill_and_stroke.rb +2 -0
  88. data/manual/graphics/fill_rules.rb +2 -0
  89. data/manual/graphics/gradients.rb +2 -0
  90. data/manual/graphics/graphics.rb +4 -2
  91. data/manual/graphics/helper.rb +2 -0
  92. data/manual/graphics/line_width.rb +3 -0
  93. data/manual/graphics/lines_and_curves.rb +2 -0
  94. data/manual/graphics/polygon.rb +2 -0
  95. data/manual/graphics/rectangle.rb +2 -0
  96. data/manual/graphics/rotate.rb +2 -0
  97. data/manual/graphics/scale.rb +2 -0
  98. data/manual/graphics/soft_masks.rb +2 -0
  99. data/manual/graphics/stroke_cap.rb +3 -1
  100. data/manual/graphics/stroke_dash.rb +2 -0
  101. data/manual/graphics/stroke_join.rb +3 -1
  102. data/manual/graphics/translate.rb +2 -0
  103. data/manual/graphics/transparency.rb +2 -0
  104. data/manual/how_to_read_this_manual.rb +2 -0
  105. data/manual/images/absolute_position.rb +2 -0
  106. data/manual/images/fit.rb +2 -0
  107. data/manual/images/horizontal.rb +3 -1
  108. data/manual/images/images.rb +4 -2
  109. data/manual/images/plain_image.rb +2 -0
  110. data/manual/images/scale.rb +2 -0
  111. data/manual/images/vertical.rb +3 -1
  112. data/manual/images/width_and_height.rb +2 -0
  113. data/manual/layout/boxes.rb +2 -0
  114. data/manual/layout/content.rb +2 -0
  115. data/manual/layout/layout.rb +4 -2
  116. data/manual/layout/simple_grid.rb +2 -0
  117. data/manual/outline/add_subsection_to.rb +2 -0
  118. data/manual/outline/insert_section_after.rb +2 -0
  119. data/manual/outline/outline.rb +4 -2
  120. data/manual/outline/sections_and_pages.rb +2 -0
  121. data/manual/repeatable_content/alternate_page_numbering.rb +2 -0
  122. data/manual/repeatable_content/page_numbering.rb +2 -0
  123. data/manual/repeatable_content/repeatable_content.rb +4 -2
  124. data/manual/repeatable_content/repeater.rb +2 -0
  125. data/manual/repeatable_content/stamp.rb +2 -0
  126. data/manual/security/encryption.rb +2 -0
  127. data/manual/security/permissions.rb +2 -0
  128. data/manual/security/security.rb +4 -2
  129. data/manual/table.rb +2 -0
  130. data/manual/text/alignment.rb +2 -0
  131. data/manual/text/color.rb +2 -0
  132. data/manual/text/column_box.rb +4 -2
  133. data/manual/text/fallback_fonts.rb +4 -2
  134. data/manual/text/font.rb +2 -0
  135. data/manual/text/font_size.rb +2 -0
  136. data/manual/text/font_style.rb +4 -2
  137. data/manual/text/formatted_callbacks.rb +2 -0
  138. data/manual/text/formatted_text.rb +3 -1
  139. data/manual/text/free_flowing_text.rb +2 -0
  140. data/manual/text/inline.rb +2 -0
  141. data/manual/text/kerning_and_character_spacing.rb +2 -0
  142. data/manual/text/leading.rb +2 -0
  143. data/manual/text/line_wrapping.rb +4 -1
  144. data/manual/text/paragraph_indentation.rb +2 -0
  145. data/manual/text/positioned_text.rb +2 -0
  146. data/manual/text/registering_families.rb +4 -2
  147. data/manual/text/rendering_and_color.rb +2 -0
  148. data/manual/text/right_to_left_text.rb +2 -0
  149. data/manual/text/rotation.rb +3 -1
  150. data/manual/text/single_usage.rb +2 -0
  151. data/manual/text/text.rb +4 -3
  152. data/manual/text/text_box_excess.rb +2 -0
  153. data/manual/text/text_box_extensions.rb +2 -0
  154. data/manual/text/text_box_overflow.rb +3 -1
  155. data/manual/text/utf8.rb +3 -1
  156. data/manual/text/win_ansi_charset.rb +6 -3
  157. data/prawn.gemspec +14 -11
  158. data/spec/extensions/encoding_helpers.rb +4 -2
  159. data/spec/prawn/document/bounding_box_spec.rb +8 -8
  160. data/spec/prawn/document/column_box_spec.rb +2 -0
  161. data/spec/prawn/document/security_spec.rb +12 -9
  162. data/spec/prawn/document_annotations_spec.rb +2 -0
  163. data/spec/prawn/document_destinations_spec.rb +2 -0
  164. data/spec/prawn/document_grid_spec.rb +3 -0
  165. data/spec/prawn/document_reference_spec.rb +2 -0
  166. data/spec/prawn/document_span_spec.rb +2 -0
  167. data/spec/prawn/document_spec.rb +59 -14
  168. data/spec/prawn/font_metric_cache_spec.rb +2 -0
  169. data/spec/prawn/font_spec.rb +45 -16
  170. data/spec/prawn/graphics/blend_mode_spec.rb +4 -2
  171. data/spec/prawn/graphics/transparency_spec.rb +2 -0
  172. data/spec/prawn/graphics_spec.rb +40 -20
  173. data/spec/prawn/graphics_stroke_styles_spec.rb +2 -0
  174. data/spec/prawn/image_handler_spec.rb +2 -0
  175. data/spec/prawn/images/jpg_spec.rb +2 -0
  176. data/spec/prawn/images/png_spec.rb +2 -0
  177. data/spec/prawn/images_spec.rb +56 -2
  178. data/spec/prawn/measurements_extensions_spec.rb +2 -0
  179. data/spec/prawn/outline_spec.rb +6 -2
  180. data/spec/prawn/repeater_spec.rb +6 -4
  181. data/spec/prawn/soft_mask_spec.rb +2 -0
  182. data/spec/prawn/stamp_spec.rb +11 -7
  183. data/spec/prawn/text/box_spec.rb +26 -27
  184. data/spec/prawn/text/formatted/arranger_spec.rb +30 -28
  185. data/spec/prawn/text/formatted/box_spec.rb +78 -57
  186. data/spec/prawn/text/formatted/fragment_spec.rb +10 -8
  187. data/spec/prawn/text/formatted/line_wrap_spec.rb +8 -5
  188. data/spec/prawn/text/formatted/parser_spec.rb +32 -2
  189. data/spec/prawn/text_draw_text_spec.rb +5 -3
  190. data/spec/prawn/text_rendering_mode_spec.rb +7 -1
  191. data/spec/prawn/text_spacing_spec.rb +6 -4
  192. data/spec/prawn/text_spec.rb +9 -7
  193. data/spec/prawn/text_with_inline_formatting_spec.rb +3 -1
  194. data/spec/prawn/transformation_stack_spec.rb +2 -0
  195. data/spec/prawn/view_spec.rb +18 -0
  196. data/spec/{manual_spec.rb → prawn_manual_spec.rb} +6 -4
  197. data/spec/spec_helper.rb +9 -10
  198. metadata +86 -73
  199. metadata.gz.sig +4 -2
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # font_metric_cache.rb : The Prawn font class
2
4
  #
3
5
  # Copyright Dec 2012, Kenneth Kalmer. All Rights Reserved.
@@ -35,9 +37,12 @@ module Prawn
35
37
 
36
38
  length = @cache[key]
37
39
 
38
- length +
39
- (@document.character_spacing *
40
- @document.font.character_count(encoded_string))
40
+ character_count = @document.font.character_count(encoded_string)
41
+ if character_count.positive?
42
+ length += @document.character_spacing * (character_count - 1)
43
+ end
44
+
45
+ length
41
46
  end
42
47
  end
43
48
  end
@@ -1,4 +1,6 @@
1
- # prawn/font/afm.rb : Implements AFM font support for Prawn
1
+ # frozen_string_literal: true
2
+
3
+ # Implements AFM font support for Prawn
2
4
  #
3
5
  # Copyright May 2008, Gregory Brown / James Healy. All Rights Reserved.
4
6
  #
@@ -7,7 +9,7 @@
7
9
  require_relative '../encoding'
8
10
 
9
11
  module Prawn
10
- class Font
12
+ module Fonts
11
13
  # @private
12
14
 
13
15
  class AFM < Font
@@ -49,14 +51,16 @@ module Prawn
49
51
  end
50
52
 
51
53
  def initialize(document, name, options = {}) #:nodoc:
54
+ name ||= options[:family]
52
55
  unless BUILT_INS.include?(name)
53
- raise Prawn::Errors::UnknownFont, "#{name} is not a known font."
56
+ raise Prawn::Errors::UnknownFont,
57
+ "#{name} (#{options[:style] || 'normal'}) is not a known font."
54
58
  end
55
59
 
56
60
  super
57
61
 
58
62
  file_name = @name.dup
59
- file_name << '.afm' unless file_name =~ /\.afm$/
63
+ file_name << '.afm' unless /\.afm$/.match?(file_name)
60
64
  file_name = file_name[0] == '/' ? file_name : find_font(file_name)
61
65
 
62
66
  font_data = self.class.font_data[file_name] ||= parse_afm(file_name)
@@ -93,9 +97,11 @@ module Prawn
93
97
 
94
98
  # Returns true if the font has kerning data, false otherwise
95
99
  #
100
+ # rubocop: disable Naming/PredicateName
96
101
  def has_kerning_data?
97
102
  @kern_pairs.any?
98
103
  end
104
+ # rubocop: enable Naming/PredicateName
99
105
 
100
106
  # built-in fonts only work with winansi encoding, so translate the
101
107
  # string. Changes the encoding in-place, so the argument itself
@@ -109,8 +115,8 @@ module Prawn
109
115
  raise Prawn::Errors::IncompatibleStringEncoding,
110
116
  "Your document includes text that's not compatible with the " \
111
117
  "Windows-1252 character set.\n" \
112
- "If you need full UTF-8 support, use TTF fonts instead of PDF's " \
113
- "built-in fonts.\n"
118
+ 'If you need full UTF-8 support, use external fonts instead of ' \
119
+ "PDF's built-in fonts.\n"
114
120
  end
115
121
 
116
122
  def to_utf8(text)
@@ -194,13 +200,14 @@ module Prawn
194
200
 
195
201
  case section
196
202
  when %w[FontMetrics CharMetrics]
197
- next unless line =~ /^CH?\s/
203
+ next unless /^CH?\s/.match?(line)
198
204
 
199
205
  name = line[/\bN\s+(\.?\w+)\s*;/, 1]
200
206
  data[:glyph_widths][name] = line[/\bWX\s+(\d+)\s*;/, 1].to_i
201
207
  data[:bounding_boxes][name] = line[/\bB\s+([^;]+);/, 1].to_s.rstrip
202
208
  when %w[FontMetrics KernData KernPairs]
203
209
  next unless line =~ /^KPX\s+(\.?\w+)\s+(\.?\w+)\s+(-?\d+)/
210
+
204
211
  data[:kern_pairs][[Regexp.last_match(1), Regexp.last_match(2)]] =
205
212
  Regexp.last_match(3).to_i
206
213
  when %w[FontMetrics KernData TrackKern],
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'ttf'
2
4
 
3
5
  module Prawn
4
- class Font
6
+ module Fonts
5
7
  # @private
6
8
  class DFont < TTF
7
9
  # Returns a list of the names of all named fonts in the given dfont file.
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'ttf'
4
+
5
+ module Prawn
6
+ module Fonts
7
+ # @private
8
+ class OTF < TTF
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'ttf'
2
4
 
3
5
  module Prawn
4
- class Font
6
+ module Fonts
5
7
  # @private
6
8
  class TTC < TTF
7
9
  # Returns a list of the names of all named fonts in the given ttc file.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # prawn/font/ttf.rb : Implements AFM font support for Prawn
2
4
  #
3
5
  # Copyright May 2008, Gregory Brown / James Healy / Jamis Buck
@@ -9,7 +11,7 @@ require 'ttfunk'
9
11
  require 'ttfunk/subset_collection'
10
12
 
11
13
  module Prawn
12
- class Font
14
+ module Fonts
13
15
  # @private
14
16
  class TTF < Font
15
17
  attr_reader :ttf, :subsets
@@ -23,6 +25,7 @@ module Prawn
23
25
 
24
26
  @ttf = read_ttf_file
25
27
  @subsets = TTFunk::SubsetCollection.new(@ttf)
28
+ @italic_angle = nil
26
29
 
27
30
  @attributes = {}
28
31
  @bounding_boxes = {}
@@ -59,9 +62,12 @@ module Prawn
59
62
  end
60
63
 
61
64
  # Returns true if the font has kerning data, false otherwise
65
+ #
66
+ # rubocop: disable Naming/PredicateName
62
67
  def has_kerning_data?
63
68
  @has_kerning_data
64
69
  end
70
+ # rubocop: enable Naming/PredicateName
65
71
 
66
72
  # Perform any changes to the string that need to happen
67
73
  # before it is rendered to the canvas. Returns an array of
@@ -109,7 +115,7 @@ module Prawn
109
115
  end
110
116
 
111
117
  # not sure how to compute this for true-type fonts...
112
- def stemV # rubocop: disable Style/MethodName
118
+ def stem_v
113
119
  0
114
120
  end
115
121
 
@@ -155,7 +161,7 @@ module Prawn
155
161
  end
156
162
 
157
163
  def pdf_flags
158
- @flags ||= begin
164
+ @pdf_flags ||= begin
159
165
  flags = 0
160
166
  flags |= 0x0001 if @ttf.postscript.fixed_pitch?
161
167
  flags |= 0x0002 if serif?
@@ -168,7 +174,7 @@ module Prawn
168
174
 
169
175
  def normalize_encoding(text)
170
176
  text.encode(::Encoding::UTF_8)
171
- rescue => e
177
+ rescue StandardError => e
172
178
  puts e
173
179
  raise Prawn::Errors::IncompatibleStringEncoding, 'Encoding ' \
174
180
  "#{text.encoding} can not be transparently converted to UTF-8. " \
@@ -182,7 +188,7 @@ module Prawn
182
188
 
183
189
  def glyph_present?(char)
184
190
  code = char.codepoints.first
185
- cmap[code] > 0
191
+ cmap[code].positive?
186
192
  end
187
193
 
188
194
  # Returns the number of characters in +str+ (a UTF-8-encoded string).
@@ -220,7 +226,7 @@ module Prawn
220
226
  end
221
227
 
222
228
  def kern_pairs_table
223
- @kerning_data ||=
229
+ @kern_pairs_table ||=
224
230
  if has_kerning_data?
225
231
  @ttf.kerning.tables.first.pairs
226
232
  else
@@ -243,7 +249,7 @@ module Prawn
243
249
  end
244
250
 
245
251
  def scale_factor
246
- @scale ||= 1000.0 / @ttf.header.units_per_em
252
+ @scale_factor ||= 1000.0 / @ttf.header.units_per_em
247
253
  end
248
254
 
249
255
  def register(subset)
@@ -281,7 +287,7 @@ module Prawn
281
287
  FontFile2: fontfile,
282
288
  FontBBox: bbox,
283
289
  Flags: pdf_flags,
284
- StemV: stemV,
290
+ StemV: stem_v,
285
291
  ItalicAngle: italic_angle,
286
292
  Ascent: @ascender,
287
293
  Descent: @descender,
@@ -310,13 +316,18 @@ module Prawn
310
316
  map.keys.sort.inject('') do |_s, code|
311
317
  ranges << [] if ranges.last.length >= 100
312
318
  unicode = map[code]
313
- ranges.last << format('<%02x><%04x>', code, unicode)
319
+ ranges.last << format(
320
+ '<%<code>02x><%<unicode>04x>',
321
+ code: code,
322
+ unicode: unicode
323
+ )
314
324
  end
315
325
 
316
- range_blocks = ranges.inject('') do |s, list|
326
+ range_blocks = ranges.inject(+'') do |s, list|
317
327
  s << format(
318
- "%d beginbfchar\n%s\nendbfchar\n",
319
- list.length, list.join("\n")
328
+ "%<lenght>d beginbfchar\n%<list>s\nendbfchar\n",
329
+ lenght: list.length,
330
+ list: list.join("\n")
320
331
  )
321
332
  end
322
333
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # graphics.rb : Implements PDF drawing primitives
2
4
  #
3
5
  # Copyright April 2008, Gregory Brown. All Rights Reserved.
@@ -148,11 +150,7 @@ module Prawn
148
150
  # horizontal_line 25, 100, :at => 75
149
151
  #
150
152
  def horizontal_line(x1, x2, options = {})
151
- y1 = if options[:at]
152
- options[:at]
153
- else
154
- y - bounds.absolute_bottom
155
- end
153
+ y1 = options[:at] || y - bounds.absolute_bottom
156
154
 
157
155
  line(x1, y1, x2, y1)
158
156
  end
@@ -198,36 +196,36 @@ module Prawn
198
196
  ellipse(center, radius, radius)
199
197
  end
200
198
 
201
- # Draws an ellipse of +x+ radius <tt>r1</tt> and +y+ radius <tt>r2</tt>
202
- # with the centre-point at <tt>point</tt> as a complete subpath. The
203
- # drawing point will be moved to the centre-point upon completion of the
204
- # 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.
205
203
  #
206
204
  # # draws an ellipse with x-radius 25 and y-radius 50
207
205
  # pdf.ellipse [100,100], 25, 50
208
206
  #
209
- def ellipse(point, r1, r2 = r1)
207
+ def ellipse(point, radius1, radius2 = radius1)
210
208
  x, y = point
211
- l1 = r1 * KAPPA
212
- l2 = r2 * KAPPA
209
+ l1 = radius1 * KAPPA
210
+ l2 = radius2 * KAPPA
213
211
 
214
- move_to(x + r1, y)
212
+ move_to(x + radius1, y)
215
213
 
216
214
  # Upper right hand corner
217
- curve_to [x, y + r2],
218
- 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]]
219
217
 
220
218
  # Upper left hand corner
221
- curve_to [x - r1, y],
222
- 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]]
223
221
 
224
222
  # Lower left hand corner
225
- curve_to [x, y - r2],
226
- 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]]
227
225
 
228
226
  # Lower right hand corner
229
- curve_to [x + r1, y],
230
- 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]]
231
229
 
232
230
  move_to(x, y)
233
231
  end
@@ -343,9 +341,9 @@ module Prawn
343
341
  }.merge(options)
344
342
 
345
343
  Prawn.verify_options(
346
- [
347
- :at, :width, :height, :step_length,
348
- :negative_axes_length, :color
344
+ %i[
345
+ at width height step_length
346
+ negative_axes_length color
349
347
  ], options
350
348
  )
351
349
 
@@ -634,12 +632,12 @@ module Prawn
634
632
  ]
635
633
 
636
634
  ops.product(shapes).each do |operation, shape|
637
- class_eval <<-END
635
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
638
636
  def #{operation}_#{shape}(*args)
639
637
  #{shape}(*args)
640
638
  #{operation}
641
639
  end
642
- END
640
+ METHOD
643
641
  end
644
642
 
645
643
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # blend_mode.rb : Implements blend modes
2
4
  #
3
5
  # Contributed by John Ford. October, 2015
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # cap_style.rb : Implements stroke cap styling
2
4
  #
3
5
  # Contributed by Daniel Nelson. October, 2009
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # color.rb : Implements color handling
2
4
  #
3
5
  # Copyright June 2008, Gregory Brown. All Rights Reserved.
@@ -25,6 +27,7 @@ module Prawn
25
27
  #
26
28
  def fill_color(*color)
27
29
  return current_fill_color if color.empty?
30
+
28
31
  self.current_fill_color = process_color(*color)
29
32
  set_fill_color
30
33
  end
@@ -47,6 +50,7 @@ module Prawn
47
50
  #
48
51
  def stroke_color(*color)
49
52
  return current_stroke_color if color.empty?
53
+
50
54
  color = process_color(*color)
51
55
  self.current_stroke_color = color
52
56
  set_stroke_color(color)
@@ -63,7 +67,7 @@ module Prawn
63
67
  # => "ff7808"
64
68
  #
65
69
  def rgb2hex(rgb)
66
- rgb.map { |e| format '%02x', e }.join
70
+ rgb.map { |e| format '%<value>02x', value: e }.join
67
71
  end
68
72
 
69
73
  # Converts hex string into RGB value array:
@@ -94,7 +98,7 @@ module Prawn
94
98
  def color_type(color)
95
99
  case color
96
100
  when String
97
- if color =~ /\A[0-F]{6}\z/i
101
+ if /\A\h{6}\z/.match?(color)
98
102
  :RGB
99
103
  else
100
104
  raise ArgumentError, "Unknown type of color: #{color.inspect}"
@@ -135,7 +139,7 @@ module Prawn
135
139
  end
136
140
  end
137
141
 
138
- COLOR_SPACES = [:DeviceRGB, :DeviceCMYK, :Pattern].freeze
142
+ COLOR_SPACES = %i[DeviceRGB DeviceCMYK Pattern].freeze
139
143
 
140
144
  def set_color_space(type, color_space)
141
145
  # don't set the same color space again
@@ -143,6 +147,7 @@ module Prawn
143
147
  !state.page.in_stamp_stream?
144
148
  return
145
149
  end
150
+
146
151
  set_current_color_space(color_space, type)
147
152
 
148
153
  unless COLOR_SPACES.include?(color_space)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # dash.rb : Implements stroke dashing
2
4
  #
3
5
  # Contributed by Daniel Nelson. October, 2009
@@ -61,7 +63,7 @@ module Prawn
61
63
  if length.all?(&:zero?)
62
64
  raise ArgumentError,
63
65
  'Zero length dashes are invalid. Call #undash to disable dashes.'
64
- elsif length.any? { |e| e < 0 }
66
+ elsif length.any?(&:negative?)
65
67
  raise ArgumentError,
66
68
  'Negative numbers are not allowed for dash lengths.'
67
69
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # join_style.rb : Implements stroke join styling
2
4
  #
3
5
  # Contributed by Daniel Nelson. October, 2009
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'digest/sha1'
2
4
 
3
5
  # patterns.rb : Implements axial & radial gradients
@@ -106,7 +108,8 @@ module Prawn
106
108
  renderer.add_content "/SP#{registry_key} #{operator}"
107
109
  end
108
110
 
109
- def parse_gradient_arguments( # rubocop: disable Metrics/ParameterLists
111
+ # rubocop: disable Metrics/ParameterLists
112
+ def parse_gradient_arguments(
110
113
  *arguments, from: nil, to: nil, r1: nil, r2: nil, stops: nil,
111
114
  apply_transformations: nil
112
115
  )
@@ -137,6 +140,7 @@ module Prawn
137
140
  unless (0..1).cover?(position)
138
141
  raise ArgumentError, 'position must be between 0 and 1'
139
142
  end
143
+
140
144
  GradientStop.new(position, normalize_color(color))
141
145
  end
142
146
 
@@ -159,6 +163,7 @@ module Prawn
159
163
  r1, r2
160
164
  )
161
165
  end
166
+ # rubocop: enable Metrics/ParameterLists
162
167
 
163
168
  def gradient_registry_key(gradient)
164
169
  _x1, _y1, x2, y2, transformation = gradient_coordinates(gradient)
@@ -171,7 +176,7 @@ module Prawn
171
176
  gradient.stops.length,
172
177
  gradient.stops.map { |s| [s.position, s.color] }
173
178
  ].flatten
174
- Digest::SHA1.hexdigest(key.pack('HC*'))
179
+ Digest::SHA1.hexdigest(key.join(','))
175
180
  end
176
181
 
177
182
  def gradient_registry