File: line_width.rb

package info (click to toggle)
ruby-prawn 1.0.0~rc1%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,248 kB
  • sloc: ruby: 17,499; sh: 44; makefile: 17
file content (38 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download
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
# encoding: utf-8
#
# The <code>line_width=</code> method sets the stroke width for subsequent stroke calls.
#
# Since Ruby assumes that an unknown variable on the left hand side of an assignment is a local temporary,
# rather than a setter method, if you are using the block call to
# <code>Prawn::Document.generate</code> without passing params you will need to
# call <code>line_width</code> on self.
#
require File.expand_path(File.join(File.dirname(__FILE__),
                                   %w[.. example_helper]))

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::Example.generate(filename) do
  # Prawn::Document.generate() do
  stroke_axis
  
  y = 250
  
  3.times do |i|
    case i
    when 0; line_width = 10        # This call will have no effect
    when 1; self.line_width = 10
    when 2; self.line_width = 25
    end
    
    stroke do
      horizontal_line 50, 150, :at => y
      rectangle [275, y + 25], 50, 50
      circle [500, y], 25
    end
    
    y -= 100
  end
  
  # Return line_width back to normal
  self.line_width = 1
end