Module: Prawn::Graphics::Dash
- Included in:
- Prawn::Graphics
- Defined in:
- lib/prawn/graphics/dash.rb
Overview
Implements stroke dashing.
Stable API collapse
-
#dash ⇒ Hash{:dash => Number, Array<Number>, :space => Number, nil, :phase => Number}
#dash(length, options = {}) ⇒ void
(also: #dash=)
Get or set stroke dash pattern.
-
#dashed? ⇒ Boolean
Returns
true
when stroke is dashed,false
otherwise. -
#undash ⇒ void
Stops dashing, restoring solid stroked lines and curves.
Instance Method Details
#dash ⇒ Hash{:dash => Number, Array<Number>, :space => Number, nil, :phase => Number} #dash(length, options = {}) ⇒ void Also known as: dash=
Get or set stroke dash pattern.
Source Code
lib/prawn/graphics/dash.rb, line 59
59 | def dash(length = nil, options = {}) |
60 | return current_dash_state if length.nil? |
61 | |
62 | length = Array(length) |
63 | |
64 | if length.all?(&:zero?) |
65 | raise ArgumentError, |
66 | 'Zero length dashes are invalid. Call #undash to disable dashes.'
|
67 | elsif length.any?(&:negative?) |
68 | raise ArgumentError, |
69 | 'Negative numbers are not allowed for dash lengths.'
|
70 | end
|
71 | |
72 | length = length.first if length.length == 1 |
73 | |
74 | self.current_dash_state = { |
75 | dash: length, |
76 | space: length.is_a?(Array) ? nil : options[:space] || length, |
77 | phase: options[:phase] || 0, |
78 | }
|
79 | |
80 | write_stroke_dash
|
81 | end
|
#dashed? ⇒ Boolean
Returns true
when stroke is dashed, false
otherwise.
Source Code
lib/prawn/graphics/dash.rb, line 96
96 | def dashed? |
97 | current_dash_state != undashed_setting |
98 | end
|
#undash ⇒ void
This method returns an undefined value.
Stops dashing, restoring solid stroked lines and curves.
Source Code
lib/prawn/graphics/dash.rb, line 88
88 | def undash |
89 | self.current_dash_state = undashed_setting |
90 | write_stroke_dash
|
91 | end
|