1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# encoding: utf-8
# dash.rb : Implements stroke dashing
#
# Contributed by Daniel Nelson. October, 2009
#
# This is free software. Please see the LICENSE and COPYING files for details.
#
module Prawn
module Graphics
module Dash
# Sets the dash pattern for stroked lines and curves
#
# length is the length of the dash. If options is not present,
# or options[:space] is nil, then length is also the length of
# the space between dashes
#
# options may contain :space and :phase
# :space is the space between the dashes
# :phase is where in the cycle to begin dashing. For
# example, a phase of 0 starts at the beginning of
# the dash; whereas, if the phase is equal to the
# length of the dash, then stroking will begin at
# the beginning of the space. Default is 0
#
# integers or floats may be used for length and the options
#
# dash units are in PDF points ( 1/72 in )
#
def dash(length=nil, options={})
return current_dash_state || undash_hash if length.nil?
self.current_dash_state = { :dash => length,
:space => options[:space] || length,
:phase => options[:phase] || 0 }
write_stroke_dash
end
alias_method :dash=, :dash
# Stops dashing, restoring solid stroked lines and curves
#
def undash
self.current_dash_state = undashed_setting
write_stroke_dash
end
# Returns when stroke is dashed, false otherwise
#
def dashed?
current_dash_state != undashed_setting
end
def write_stroke_dash
add_content dash_setting
end
private
def undashed_setting
{ :dash => nil, :space => nil, :phase => 0 }
end
private
def current_dash_state=(dash_options)
graphic_state.dash = dash_options
end
def current_dash_state
graphic_state.dash
end
def dash_setting
graphic_state.dash_setting
end
end
end
end
|