Sha256: 5892e6ef7275493fc228af6c352be3e4e9275f391714f0d44ea1a0f9caafe473

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

# encoding: utf-8
#
# Stroke dashing can be applied to any line or curve

require File.expand_path(File.join(File.dirname(__FILE__),
                                   %w[.. example_helper]))

Prawn::Document.generate("stroke_dash.pdf") do
  self.line_width = 1
  base_y = bounds.top

  100.times do |i|
    length = i / 4 + 1
    # space between dashes same length as dash
    space = length
    # start with dash
    phase = 0
    case i % 4
    when 0
      base_y -= 10
    when 1
      # start with space between dashes
      phase = length
    when 2
      base_y -= 10
      # space between dashes half as long as dash
      space = length * 0.5
    when 3
      # space between dashes half as long as dash
      space = length * 0.5
      # start with space between dashes
      phase = length
    end
    dash(length, :space => space, :phase => phase)
    points = [bounds.left, base_y - 2 * i, bounds.right, base_y - 2 * i]
    stroke_line(points)
  end
  i = 100
  base_y -= 10
  undash
  points = [bounds.left, base_y - 2 * i, bounds.right, base_y - 2 * i]
  stroke_line(points)
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
prawn-0.11.1 examples/graphics/stroke_dash.rb
davebenvenuti-prawn-0.11.1.pre examples/graphics/stroke_dash.rb