prawn 2.3.0 → 2.5.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 (203) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/prawn/document/bounding_box.rb +223 -143
  4. data/lib/prawn/document/column_box.rb +61 -26
  5. data/lib/prawn/document/internals.rb +25 -16
  6. data/lib/prawn/document/span.rb +21 -18
  7. data/lib/prawn/document.rb +273 -182
  8. data/lib/prawn/encoding.rb +2 -5
  9. data/lib/prawn/errors.rb +23 -34
  10. data/lib/prawn/font.rb +254 -139
  11. data/lib/prawn/font_metric_cache.rb +18 -16
  12. data/lib/prawn/fonts/afm.rb +99 -57
  13. data/lib/prawn/fonts/dfont.rb +7 -1
  14. data/lib/prawn/fonts/otf.rb +4 -1
  15. data/lib/prawn/fonts/to_unicode_cmap.rb +151 -0
  16. data/lib/prawn/fonts/ttc.rb +7 -2
  17. data/lib/prawn/fonts/ttf.rb +345 -107
  18. data/lib/prawn/fonts.rb +14 -0
  19. data/lib/prawn/graphics/blend_mode.rb +25 -28
  20. data/lib/prawn/graphics/cap_style.rb +9 -12
  21. data/lib/prawn/graphics/color.rb +75 -50
  22. data/lib/prawn/graphics/dash.rb +45 -42
  23. data/lib/prawn/graphics/join_style.rb +18 -12
  24. data/lib/prawn/graphics/patterns.rb +239 -110
  25. data/lib/prawn/graphics/transformation.rb +51 -44
  26. data/lib/prawn/graphics/transparency.rb +16 -40
  27. data/lib/prawn/graphics.rb +370 -260
  28. data/lib/prawn/grid.rb +219 -57
  29. data/lib/prawn/image_handler.rb +27 -10
  30. data/lib/prawn/images/image.rb +8 -10
  31. data/lib/prawn/images/jpg.rb +46 -20
  32. data/lib/prawn/images/png.rb +94 -42
  33. data/lib/prawn/images.rb +70 -81
  34. data/lib/prawn/measurement_extensions.rb +39 -8
  35. data/lib/prawn/measurements.rb +60 -5
  36. data/lib/prawn/outline.rb +120 -113
  37. data/lib/prawn/repeater.rb +52 -36
  38. data/lib/prawn/security/arcfour.rb +4 -4
  39. data/lib/prawn/security.rb +106 -98
  40. data/lib/prawn/soft_mask.rb +42 -30
  41. data/lib/prawn/stamp.rb +38 -42
  42. data/lib/prawn/text/box.rb +156 -105
  43. data/lib/prawn/text/formatted/arranger.rb +121 -41
  44. data/lib/prawn/text/formatted/box.rb +239 -163
  45. data/lib/prawn/text/formatted/fragment.rb +130 -14
  46. data/lib/prawn/text/formatted/line_wrap.rb +49 -38
  47. data/lib/prawn/text/formatted/parser.rb +116 -74
  48. data/lib/prawn/text/formatted/wrap.rb +25 -26
  49. data/lib/prawn/text/formatted.rb +75 -0
  50. data/lib/prawn/text.rb +456 -211
  51. data/lib/prawn/transformation_stack.rb +29 -10
  52. data/lib/prawn/utilities.rb +13 -13
  53. data/lib/prawn/version.rb +2 -1
  54. data/lib/prawn/view.rb +69 -54
  55. data/lib/prawn.rb +24 -18
  56. data.tar.gz.sig +0 -0
  57. metadata +55 -262
  58. metadata.gz.sig +3 -4
  59. data/.yardopts +0 -10
  60. data/Gemfile +0 -5
  61. data/Rakefile +0 -54
  62. data/manual/absolute_position.pdf +0 -0
  63. data/manual/basic_concepts/adding_pages.rb +0 -26
  64. data/manual/basic_concepts/basic_concepts.rb +0 -43
  65. data/manual/basic_concepts/creation.rb +0 -38
  66. data/manual/basic_concepts/cursor.rb +0 -32
  67. data/manual/basic_concepts/measurement.rb +0 -24
  68. data/manual/basic_concepts/origin.rb +0 -37
  69. data/manual/basic_concepts/other_cursor_helpers.rb +0 -39
  70. data/manual/basic_concepts/view.rb +0 -48
  71. data/manual/bounding_box/bounding_box.rb +0 -41
  72. data/manual/bounding_box/bounds.rb +0 -48
  73. data/manual/bounding_box/canvas.rb +0 -23
  74. data/manual/bounding_box/creation.rb +0 -22
  75. data/manual/bounding_box/indentation.rb +0 -45
  76. data/manual/bounding_box/nesting.rb +0 -52
  77. data/manual/bounding_box/russian_boxes.rb +0 -40
  78. data/manual/bounding_box/stretchy.rb +0 -29
  79. data/manual/contents.rb +0 -35
  80. data/manual/cover.rb +0 -43
  81. data/manual/document_and_page_options/background.rb +0 -25
  82. data/manual/document_and_page_options/document_and_page_options.rb +0 -34
  83. data/manual/document_and_page_options/metadata.rb +0 -25
  84. data/manual/document_and_page_options/page_margins.rb +0 -36
  85. data/manual/document_and_page_options/page_size.rb +0 -34
  86. data/manual/document_and_page_options/print_scaling.rb +0 -22
  87. data/manual/example_helper.rb +0 -8
  88. data/manual/graphics/blend_mode.rb +0 -52
  89. data/manual/graphics/circle_and_ellipse.rb +0 -21
  90. data/manual/graphics/color.rb +0 -22
  91. data/manual/graphics/common_lines.rb +0 -29
  92. data/manual/graphics/fill_and_stroke.rb +0 -41
  93. data/manual/graphics/fill_rules.rb +0 -37
  94. data/manual/graphics/gradients.rb +0 -43
  95. data/manual/graphics/graphics.rb +0 -64
  96. data/manual/graphics/helper.rb +0 -27
  97. data/manual/graphics/line_width.rb +0 -36
  98. data/manual/graphics/lines_and_curves.rb +0 -40
  99. data/manual/graphics/polygon.rb +0 -27
  100. data/manual/graphics/rectangle.rb +0 -20
  101. data/manual/graphics/rotate.rb +0 -25
  102. data/manual/graphics/scale.rb +0 -42
  103. data/manual/graphics/soft_masks.rb +0 -44
  104. data/manual/graphics/stroke_cap.rb +0 -30
  105. data/manual/graphics/stroke_dash.rb +0 -47
  106. data/manual/graphics/stroke_join.rb +0 -29
  107. data/manual/graphics/translate.rb +0 -28
  108. data/manual/graphics/transparency.rb +0 -33
  109. data/manual/how_to_read_this_manual.rb +0 -39
  110. data/manual/images/absolute_position.rb +0 -22
  111. data/manual/images/fit.rb +0 -20
  112. data/manual/images/horizontal.rb +0 -24
  113. data/manual/images/images.rb +0 -41
  114. data/manual/images/plain_image.rb +0 -17
  115. data/manual/images/scale.rb +0 -21
  116. data/manual/images/vertical.rb +0 -27
  117. data/manual/images/width_and_height.rb +0 -24
  118. data/manual/layout/boxes.rb +0 -26
  119. data/manual/layout/content.rb +0 -24
  120. data/manual/layout/layout.rb +0 -27
  121. data/manual/layout/simple_grid.rb +0 -22
  122. data/manual/outline/add_subsection_to.rb +0 -60
  123. data/manual/outline/insert_section_after.rb +0 -46
  124. data/manual/outline/outline.rb +0 -33
  125. data/manual/outline/sections_and_pages.rb +0 -66
  126. data/manual/repeatable_content/alternate_page_numbering.rb +0 -36
  127. data/manual/repeatable_content/page_numbering.rb +0 -55
  128. data/manual/repeatable_content/repeatable_content.rb +0 -35
  129. data/manual/repeatable_content/repeater.rb +0 -54
  130. data/manual/repeatable_content/stamp.rb +0 -40
  131. data/manual/security/encryption.rb +0 -28
  132. data/manual/security/permissions.rb +0 -41
  133. data/manual/security/security.rb +0 -28
  134. data/manual/table.rb +0 -16
  135. data/manual/text/alignment.rb +0 -43
  136. data/manual/text/color.rb +0 -24
  137. data/manual/text/column_box.rb +0 -30
  138. data/manual/text/fallback_fonts.rb +0 -41
  139. data/manual/text/font.rb +0 -40
  140. data/manual/text/font_size.rb +0 -44
  141. data/manual/text/font_style.rb +0 -22
  142. data/manual/text/formatted_callbacks.rb +0 -65
  143. data/manual/text/formatted_text.rb +0 -58
  144. data/manual/text/free_flowing_text.rb +0 -50
  145. data/manual/text/inline.rb +0 -40
  146. data/manual/text/kerning_and_character_spacing.rb +0 -38
  147. data/manual/text/leading.rb +0 -24
  148. data/manual/text/line_wrapping.rb +0 -60
  149. data/manual/text/paragraph_indentation.rb +0 -32
  150. data/manual/text/positioned_text.rb +0 -37
  151. data/manual/text/registering_families.rb +0 -51
  152. data/manual/text/rendering_and_color.rb +0 -36
  153. data/manual/text/right_to_left_text.rb +0 -54
  154. data/manual/text/rotation.rb +0 -47
  155. data/manual/text/single_usage.rb +0 -36
  156. data/manual/text/text.rb +0 -75
  157. data/manual/text/text_box_excess.rb +0 -35
  158. data/manual/text/text_box_extensions.rb +0 -48
  159. data/manual/text/text_box_overflow.rb +0 -49
  160. data/manual/text/utf8.rb +0 -27
  161. data/manual/text/win_ansi_charset.rb +0 -62
  162. data/prawn.gemspec +0 -57
  163. data/spec/data/curves.pdf +0 -66
  164. data/spec/extensions/encoding_helpers.rb +0 -11
  165. data/spec/prawn/document/bounding_box_spec.rb +0 -546
  166. data/spec/prawn/document/column_box_spec.rb +0 -75
  167. data/spec/prawn/document/security_spec.rb +0 -176
  168. data/spec/prawn/document_annotations_spec.rb +0 -76
  169. data/spec/prawn/document_destinations_spec.rb +0 -15
  170. data/spec/prawn/document_grid_spec.rb +0 -99
  171. data/spec/prawn/document_reference_spec.rb +0 -27
  172. data/spec/prawn/document_span_spec.rb +0 -36
  173. data/spec/prawn/document_spec.rb +0 -802
  174. data/spec/prawn/font_metric_cache_spec.rb +0 -54
  175. data/spec/prawn/font_spec.rb +0 -542
  176. data/spec/prawn/graphics/blend_mode_spec.rb +0 -63
  177. data/spec/prawn/graphics/transparency_spec.rb +0 -81
  178. data/spec/prawn/graphics_spec.rb +0 -837
  179. data/spec/prawn/graphics_stroke_styles_spec.rb +0 -229
  180. data/spec/prawn/image_handler_spec.rb +0 -53
  181. data/spec/prawn/images/jpg_spec.rb +0 -20
  182. data/spec/prawn/images/png_spec.rb +0 -283
  183. data/spec/prawn/images_spec.rb +0 -224
  184. data/spec/prawn/measurements_extensions_spec.rb +0 -24
  185. data/spec/prawn/outline_spec.rb +0 -412
  186. data/spec/prawn/repeater_spec.rb +0 -165
  187. data/spec/prawn/soft_mask_spec.rb +0 -74
  188. data/spec/prawn/stamp_spec.rb +0 -172
  189. data/spec/prawn/text/box_spec.rb +0 -1112
  190. data/spec/prawn/text/formatted/arranger_spec.rb +0 -466
  191. data/spec/prawn/text/formatted/box_spec.rb +0 -846
  192. data/spec/prawn/text/formatted/fragment_spec.rb +0 -343
  193. data/spec/prawn/text/formatted/line_wrap_spec.rb +0 -494
  194. data/spec/prawn/text/formatted/parser_spec.rb +0 -697
  195. data/spec/prawn/text_draw_text_spec.rb +0 -149
  196. data/spec/prawn/text_rendering_mode_spec.rb +0 -48
  197. data/spec/prawn/text_spacing_spec.rb +0 -95
  198. data/spec/prawn/text_spec.rb +0 -603
  199. data/spec/prawn/text_with_inline_formatting_spec.rb +0 -35
  200. data/spec/prawn/transformation_stack_spec.rb +0 -66
  201. data/spec/prawn/view_spec.rb +0 -63
  202. data/spec/prawn_manual_spec.rb +0 -35
  203. data/spec/spec_helper.rb +0 -48
@@ -1,41 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # blend_mode.rb : Implements blend modes
4
- #
5
- # Contributed by John Ford. October, 2015
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
- #
9
-
10
3
  module Prawn
11
4
  module Graphics
12
- # The Prawn::BlendMode module is used to change the way
13
- # two layers are blended together.
14
- #
15
- # Passing an array of blend modes is allowed. PDF viewers should
16
- # blend layers based on the first recognized blend mode.
17
- #
18
- # Valid blend modes in v1.4 of the PDF spec include :Normal, :Multiply,
19
- # :Screen, :Overlay, :Darken, :Lighten, :ColorDodge, :ColorBurn, :HardLight,
20
- # :SoftLight, :Difference, :Exclusion, :Hue, :Saturation, :Color, and
21
- # :Luminosity.
22
- #
23
- # Example:
24
- # pdf.fill_color('0000ff')
25
- # pdf.fill_rectangle([x, y+25], 50, 50)
26
- # pdf.blend_mode(:Multiply) do
27
- # pdf.fill_color('ff0000')
28
- # pdf.fill_circle([x, y], 25)
29
- # end
30
- #
5
+ # The {Prawn::BlendMode} module is used to change the way two graphic
6
+ # objects are blended together.
31
7
  module BlendMode
32
8
  # @group Stable API
33
9
 
10
+ # Set blend mode. If a block is passed blend mode is restored afterwards.
11
+ #
12
+ # Passing an array of blend modes is allowed. PDF viewers should blend
13
+ # layers based on the first recognized blend mode.
14
+ #
15
+ # Valid blend modes since PDF 1.4 include `:Normal`, `:Multiply`, `:Screen`,
16
+ # `:Overlay`, `:Darken`, `:Lighten`, `:ColorDodge`, `:ColorBurn`,
17
+ # `:HardLight`, `:SoftLight`, `:Difference`, `:Exclusion`, `:Hue`,
18
+ # `:Saturation`, `:Color`, and `:Luminosity`.
19
+ #
20
+ # @example
21
+ # pdf.fill_color('0000ff')
22
+ # pdf.fill_rectangle([x, y + 25], 50, 50)
23
+ # pdf.blend_mode(:Multiply) do
24
+ # pdf.fill_color('ff0000')
25
+ # pdf.fill_circle([x, y], 25)
26
+ # end
27
+ #
28
+ # @param blend_mode [Symbol, Array<Symbol>]
29
+ # @yield
30
+ # @return [void]
34
31
  def blend_mode(blend_mode = :Normal)
35
32
  renderer.min_version(1.4)
36
33
 
37
34
  save_graphics_state if block_given?
38
- renderer.add_content "/#{blend_mode_dictionary_name(blend_mode)} gs"
35
+ renderer.add_content("/#{blend_mode_dictionary_name(blend_mode)} gs")
39
36
  if block_given?
40
37
  yield
41
38
  restore_graphics_state
@@ -54,7 +51,7 @@ module Prawn
54
51
 
55
52
  dictionary = blend_mode_dictionary_registry[dictionary_name] ||= ref!(
56
53
  Type: :ExtGState,
57
- BM: blend_mode
54
+ BM: blend_mode,
58
55
  )
59
56
 
60
57
  page.ext_gstates[dictionary_name] = dictionary
@@ -1,24 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # cap_style.rb : Implements stroke cap styling
4
- #
5
- # Contributed by Daniel Nelson. October, 2009
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
- #
9
3
  module Prawn
10
4
  module Graphics
5
+ # Implements stroke cap styling
11
6
  module CapStyle
12
7
  # @group Stable API
13
8
 
9
+ # @private
14
10
  CAP_STYLES = { butt: 0, round: 1, projecting_square: 2 }.freeze
15
11
 
16
- # Sets the cap style for stroked lines and curves
17
- #
18
- # style is one of :butt, :round, or :projecting_square
19
- #
20
- # NOTE: If this method is never called, :butt will be used by default.
12
+ # Sets the cap style for stroked lines and curves.
21
13
  #
14
+ # @overload cap_style(style)
15
+ # @param style [:butt, :round, :projecting_square] (:butt)
16
+ # @return [void]
17
+ # @overload cap_style()
18
+ # @return [Symbol]
22
19
  def cap_style(style = nil)
23
20
  return current_cap_style || :butt if style.nil?
24
21
 
@@ -40,7 +37,7 @@ module Prawn
40
37
  end
41
38
 
42
39
  def write_stroke_cap_style
43
- renderer.add_content "#{CAP_STYLES[current_cap_style]} J"
40
+ renderer.add_content("#{CAP_STYLES[current_cap_style]} J")
44
41
  end
45
42
  end
46
43
  end
@@ -1,30 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # color.rb : Implements color handling
4
- #
5
- # Copyright June 2008, Gregory Brown. All Rights Reserved.
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
-
9
3
  module Prawn
10
4
  module Graphics
5
+ # Implements color handling.
11
6
  module Color
12
7
  # @group Stable API
13
8
 
14
9
  # Sets or returns the fill color.
15
10
  #
16
- # When called with no argument, it returns the current fill color.
11
+ # @overload fill_color
12
+ # Returns the current fill color.
13
+ #
14
+ # @return [String, Array<Number>]
17
15
  #
18
- # If a single argument is provided, it should be a 6 digit HTML color
19
- # code.
16
+ # @overload fill_color(color)
17
+ # Sets the fill color.
20
18
  #
19
+ # If a single argument is provided, it should be a 6 digit HTML color
20
+ # code.
21
+ #
22
+ # ```ruby
21
23
  # pdf.fill_color "f0ffc1"
24
+ # ```
22
25
  #
23
- # If 4 arguments are provided, the color is assumed to be a CMYK value
24
- # Values range from 0 - 100.
26
+ # If 4 arguments are provided, the color is assumed to be a CMYK value.
27
+ # Values range is 0100.
25
28
  #
29
+ # ```ruby
26
30
  # pdf.fill_color 0, 99, 95, 0
31
+ # ```
27
32
  #
33
+ # @param color [String, Array<Number>]
34
+ # @return [void]
28
35
  def fill_color(*color)
29
36
  return current_fill_color if color.empty?
30
37
 
@@ -36,18 +43,27 @@ module Prawn
36
43
 
37
44
  # Sets or returns the line stroking color.
38
45
  #
39
- # When called with no argument, it returns the current stroking color.
46
+ # @overload stroke_color
47
+ # When called with no argument, it returns the current stroking color.
40
48
  #
41
- # If a single argument is provided, it should be a 6 digit HTML color
42
- # code.
49
+ # @return [String, Array<Number>]
43
50
  #
44
- # pdf.stroke_color "f0ffc1"
51
+ # @overload stroke_color(color)
52
+ # Sets the stroking color.
45
53
  #
46
- # If 4 arguments are provided, the color is assumed to be a CMYK value
47
- # Values range from 0 - 100.
54
+ # @param color [String, Array<Number>] new stroking color:
55
+ # - In String form it should be a 6 digit HTML color code.
48
56
  #
49
- # pdf.stroke_color 0, 99, 95, 0
57
+ # ```ruby
58
+ # pdf.stroke_color "f0ffc1"
59
+ # ```
60
+ # - If 4 arguments are provided, the color is assumed to be a CMYK
61
+ # value. Values range from 0 to 100.
50
62
  #
63
+ # ```ruby
64
+ # pdf.stroke_color 0, 99, 95, 0
65
+ # ```
66
+ # @return [void]
51
67
  def stroke_color(*color)
52
68
  return current_stroke_color if color.empty?
53
69
 
@@ -60,21 +76,28 @@ module Prawn
60
76
 
61
77
  module_function
62
78
 
63
- # Converts RGB value array to hex string suitable for use with fill_color
64
- # and stroke_color
79
+ # Converts RGB value array to hex string suitable for use with
80
+ # {fill_color} and {stroke_color}.
65
81
  #
66
- # >> Prawn::Graphics::Color.rgb2hex([255,120,8])
67
- # => "ff7808"
82
+ # @example
83
+ # Prawn::Graphics::Color.rgb2hex([255, 120, 8])
84
+ # #=> "ff7808"
68
85
  #
86
+ # @param rgb [Array(Number, Number, Number)]
87
+ # Each component has to be in the range from 0 to 255.
88
+ # @return [String]
69
89
  def rgb2hex(rgb)
70
- rgb.map { |e| format '%<value>02x', value: e }.join
90
+ rgb.map { |e| format('%<value>02x', value: e) }.join
71
91
  end
72
92
 
73
- # Converts hex string into RGB value array:
93
+ # Converts hex string into RGB value array.
74
94
  #
75
- # >> Prawn::Graphics::Color.hex2rgb("ff7808")
76
- # => [255, 120, 8]
95
+ # @example
96
+ # Prawn::Graphics::Color.hex2rgb("ff7808")
97
+ # #=> [255, 120, 8]
77
98
  #
99
+ # @param hex [String] must be 6-digits long.
100
+ # @return [Array(Integer, Integer, Integer)]
78
101
  def hex2rgb(hex)
79
102
  r = hex[0..1]
80
103
  g = hex[2..3]
@@ -127,7 +150,7 @@ module Prawn
127
150
  end
128
151
 
129
152
  def color_to_s(color)
130
- PDF::Core.real_params normalize_color(color)
153
+ PDF::Core.real_params(normalize_color(color))
131
154
  end
132
155
 
133
156
  def color_space(color)
@@ -154,44 +177,46 @@ module Prawn
154
177
  raise ArgumentError, "unknown color space: '#{color_space}'"
155
178
  end
156
179
 
157
- operator = case type
158
- when :fill
159
- 'cs'
160
- when :stroke
161
- 'CS'
162
- else
163
- raise ArgumentError, "unknown type '#{type}'"
164
- end
180
+ operator =
181
+ case type
182
+ when :fill
183
+ 'cs'
184
+ when :stroke
185
+ 'CS'
186
+ else
187
+ raise ArgumentError, "unknown type '#{type}'"
188
+ end
165
189
 
166
- renderer.add_content "/#{color_space} #{operator}"
190
+ renderer.add_content("/#{color_space} #{operator}")
167
191
  end
168
192
 
169
193
  def set_color(type, color, options = {})
170
- operator = case type
171
- when :fill
172
- 'scn'
173
- when :stroke
174
- 'SCN'
175
- else
176
- raise ArgumentError, "unknown type '#{type}'"
177
- end
194
+ operator =
195
+ case type
196
+ when :fill
197
+ 'scn'
198
+ when :stroke
199
+ 'SCN'
200
+ else
201
+ raise ArgumentError, "unknown type '#{type}'"
202
+ end
178
203
 
179
204
  if options[:pattern]
180
- set_color_space type, :Pattern
181
- renderer.add_content "/#{color} #{operator}"
205
+ set_color_space(type, :Pattern)
206
+ renderer.add_content("/#{color} #{operator}")
182
207
  else
183
- set_color_space type, color_space(color)
208
+ set_color_space(type, color_space(color))
184
209
  color = color_to_s(color)
185
210
  write_color(color, operator)
186
211
  end
187
212
  end
188
213
 
189
214
  def set_fill_color(color = nil)
190
- set_color :fill, color || current_fill_color
215
+ set_color(:fill, color || current_fill_color)
191
216
  end
192
217
 
193
218
  def set_stroke_color(color = nil)
194
- set_color :stroke, color || current_stroke_color
219
+ set_color(:stroke, color || current_stroke_color)
195
220
  end
196
221
 
197
222
  def update_colors
@@ -225,7 +250,7 @@ module Prawn
225
250
  end
226
251
 
227
252
  def write_color(color, operator)
228
- renderer.add_content "#{color} #{operator}"
253
+ renderer.add_content("#{color} #{operator}")
229
254
  end
230
255
  end
231
256
  end
@@ -1,60 +1,61 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # dash.rb : Implements stroke dashing
4
- #
5
- # Contributed by Daniel Nelson. October, 2009
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
- #
9
3
  module Prawn
10
4
  module Graphics
5
+ # Implements stroke dashing.
11
6
  module Dash
12
7
  # @group Stable API
13
8
 
14
- # Sets the dash pattern for stroked lines and curves or return the
15
- # current dash pattern setting if +length+ is nil.
9
+ # Get or set stroke dash pattern.
16
10
  #
17
- # There are two ways to set the dash pattern:
11
+ # @overload dash()
12
+ # Returns the current dash pattern.
18
13
  #
19
- # * If the parameter +length+ is an Integer/Float, it specifies
20
- # the length of the dash and of the gap. The length of the gap
21
- # can be customized by setting the :space option.
14
+ # @return [Hash{:dash => Number, Array<Number>, :space => Number, nil, :phase => Number}]
22
15
  #
23
- # Examples:
16
+ # @overload dash(length, options ={})
17
+ # Sets the dash pattern for stroked lines and curves.
24
18
  #
25
- # length = 3
26
- # 3 on, 3 off, 3 on, 3 off, ...
27
- # length = 3, :space =2
28
- # 3 on, 2 off, 3 on, 2 off, ...
19
+ # Integers or Floats may be used for length and the option values.
20
+ # Dash units are in PDF points (1/72 inch).
29
21
  #
30
- # * If the parameter +length+ is an array, it specifies the
31
- # lengths of alternating dashes and gaps. The numbers must be
32
- # non-negative and not all zero. The :space option is ignored
33
- # in this case.
22
+ # @param length [Number, Array<Number>]
23
+ # * If `length` is a Number (Integer or Float), it specifies the
24
+ # length of the dash and of the gap. The length of the gap can be
25
+ # customized by setting the `:space` option.
34
26
  #
35
- # Examples:
27
+ # Examples:
36
28
  #
37
- # length = [2, 1]
38
- # 2 on, 1 off, 2 on, 1 off, ...
39
- # length = [3, 1, 2, 3]
40
- # 3 on, 1 off, 2 on, 3 off, 3 on, 1 off, ...
41
- # length = [3, 0, 1]
42
- # 3 on, 0 off, 1 on, 3 off, 0 on, 1 off, ...
29
+ # length = 3
30
+ # : 3 on, 3 off, 3 on, 3 off, ...
43
31
  #
44
- # Options may contain the keys :space and :phase
32
+ # length = 3, :space = 2
33
+ # : 3 on, 2 off, 3 on, 2 off, ...
45
34
  #
46
- # :space:: The space between the dashes (only used when +length+
47
- # is not an array)
35
+ # * If `length` is an array, it specifies the lengths of alternating
36
+ # dashes and gaps. The numbers must be non-negative and not all
37
+ # zero. The `:space` option is ignored in this case.
48
38
  #
49
- # :phase:: The distance into the dash pattern at which to start
50
- # the dash. For example, a phase of 0 starts at the
51
- # beginning of the dash; whereas, if the phase is equal
52
- # to the length of the dash, then stroking will begin at
53
- # the beginning of the space. Default is 0.
39
+ # Examples:
54
40
  #
55
- # Integers or Floats may be used for length and the option values.
56
- # Dash units are in PDF points (1/72 inch).
41
+ # length = [2, 1]
42
+ # : 2 on, 1 off, 2 on, 1 off, ...
57
43
  #
44
+ # length = [3, 1, 2, 3]
45
+ # : 3 on, 1 off, 2 on, 3 off, 3 on, 1 off, ...
46
+ #
47
+ # length = [3, 0, 1]
48
+ # : 3 on, 0 off, 1 on, 3 off, 0 on, 1 off, ...
49
+ # @param options [Hash{Symbol => any}]
50
+ # @option options :space [Number]
51
+ # The space between the dashes (only used when `length` is not an
52
+ # array).
53
+ # @option options :phase [Number] (0)
54
+ # The distance into the dash pattern at which to start the dash. For
55
+ # example, a phase of 0 starts at the beginning of the dash; whereas,
56
+ # if the phase is equal to the length of the dash, then stroking will
57
+ # begin at the beginning of the space.
58
+ # @return [void]
58
59
  def dash(length = nil, options = {})
59
60
  return current_dash_state if length.nil?
60
61
 
@@ -73,7 +74,7 @@ module Prawn
73
74
  self.current_dash_state = {
74
75
  dash: length,
75
76
  space: length.is_a?(Array) ? nil : options[:space] || length,
76
- phase: options[:phase] || 0
77
+ phase: options[:phase] || 0,
77
78
  }
78
79
 
79
80
  write_stroke_dash
@@ -81,15 +82,17 @@ module Prawn
81
82
 
82
83
  alias dash= dash
83
84
 
84
- # Stops dashing, restoring solid stroked lines and curves
85
+ # Stops dashing, restoring solid stroked lines and curves.
85
86
  #
87
+ # @return [void]
86
88
  def undash
87
89
  self.current_dash_state = undashed_setting
88
90
  write_stroke_dash
89
91
  end
90
92
 
91
- # Returns when stroke is dashed, false otherwise
93
+ # Returns `true` when stroke is dashed, `false` otherwise.
92
94
  #
95
+ # @return [Boolean]
93
96
  def dashed?
94
97
  current_dash_state != undashed_setting
95
98
  end
@@ -97,7 +100,7 @@ module Prawn
97
100
  private
98
101
 
99
102
  def write_stroke_dash
100
- renderer.add_content dash_setting
103
+ renderer.add_content(dash_setting)
101
104
  end
102
105
 
103
106
  def undashed_setting
@@ -1,24 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # join_style.rb : Implements stroke join styling
4
- #
5
- # Contributed by Daniel Nelson. October, 2009
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
- #
9
3
  module Prawn
10
4
  module Graphics
5
+ # Implements stroke join styling.
11
6
  module JoinStyle
7
+ # @private
12
8
  JOIN_STYLES = { miter: 0, round: 1, bevel: 2 }.freeze
13
9
 
14
10
  # @group Stable API
15
11
 
16
- # Sets the join style for stroked lines and curves
12
+ # Get or set the join style for stroked lines and curves.
17
13
  #
18
- # style is one of :miter, :round, or :bevel
14
+ # @overload join_style
15
+ # Get current join style.
16
+ #
17
+ # @return [:miter, :round, :bevel]
18
+ #
19
+ # @overload join_style(style)
20
+ # Set join style.
21
+ #
22
+ # @note If this method is never called, `:miter` will be used for join
23
+ # style throughout the document.
24
+ #
25
+ # @param style [:miter, :round, :bevel]
26
+ # @return [void]
19
27
  #
20
- # NOTE: if this method is never called, :miter will be used for join style
21
- # throughout the document
22
28
  #
23
29
  def join_style(style = nil)
24
30
  return current_join_style || :miter if style.nil?
@@ -28,7 +34,7 @@ module Prawn
28
34
  unless JOIN_STYLES.key?(current_join_style)
29
35
  raise Prawn::Errors::InvalidJoinStyle,
30
36
  "#{style} is not a recognized join style. Valid styles are " +
31
- JOIN_STYLES.keys.join(', ')
37
+ JOIN_STYLES.keys.join(', ')
32
38
  end
33
39
 
34
40
  write_stroke_join_style
@@ -47,7 +53,7 @@ module Prawn
47
53
  end
48
54
 
49
55
  def write_stroke_join_style
50
- renderer.add_content "#{JOIN_STYLES[current_join_style]} j"
56
+ renderer.add_content("#{JOIN_STYLES[current_join_style]} j")
51
57
  end
52
58
  end
53
59
  end