Skip to content

Instantly share code, notes, and snippets.

@henrik
Created October 8, 2009 08:07
Show Gist options
  • Save henrik/204854 to your computer and use it in GitHub Desktop.
Save henrik/204854 to your computer and use it in GitHub Desktop.
Basic stroke_dashed_horizontal_line to draw dashed lines/dotted lines in Prawn.
module Prawn::Graphics
# E.g. stroke_dashed_horizontal_line(0, 5.cm, :at => 10.cm, :line_length => 1.cm, :space_length => 1.mm)
# Currently rounds up line/space periods: 1 cm line length + 1 mm space as a 3 cm line would be "- - -", 3.2 cm total.
def stroke_dashed_horizontal_line(x1,x2,options={})
options = options.dup
line_length = options.delete(:line_length) || 0.5.mm
space_length = options.delete(:space_length) || line_length
period_length = line_length + space_length
total_length = x2 - x1
(total_length/period_length).ceil.times do |i|
left_bound = x1 + i * period_length
stroke_horizontal_line(left_bound, left_bound + line_length, options)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment