File: dash.rb

package info (click to toggle)
ruby-rghost 0.9.9-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,188 kB
  • sloc: ruby: 3,374; makefile: 6; sh: 1
file content (56 lines) | stat: -rw-r--r-- 1,527 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Sets the dash pattern on border lines. It accepts an array of
# non-negative numbers with atleast one non-zero. Samples:
# [2,1]     #=> 2 turn on and 1 off, 2 turn on and 1 off ...
# [3,1,2,5] #=> 3 on, 1 off, 2 on, 5 off ... repeating until end
#
#
#===Examples using dash as border parameter
# d=Document.new
# d.horizontal_line(:bottom, :border=>{:dash => 1, :width => 2 })
# link:images/dash01.png
#
# d=Document.new
# d.horizontal_line(:bottom, :border=>{:dash => [1,1], :width => 2 })
# link:images/dash01.png
#
# d=Document.new
# d.horizontal_line(:bottom, :border=>{:dash => [1,2,1], :width => 2 })
# link:images/dash03.png
#
# d=Document.new
# d.horizontal_line(:bottom, :border=>{:dash => [2,10,5], :width => 2 })
# link:images/dash04.png
#
# d=Document.new
# d.horizontal_line(:bottom, :border=>{:dash => [1,1,3,1,5,1,7,1,9,1,10], :width => 4 })
# link:images/dash05.png
#
#===Examples using Dash class
# d=Document.new
# d.scale(1,8)
# d.set Dash.new([1,1,2,1,2,1,3])
# d.line_width 3
# d.lineto :x => :limit_right, :y => :Y
# link:images/dash06.png

class RGhost::Dash < RGhost::PsObject
  include RGhost::RubyToPs
  DEFAULT_OPTIONS = {
    style: [1, 2, 3],
    offset: 0
  }

  def initialize(options = {})
    super("") {}
    @options = if options.is_a?(Numeric) || options.is_a?(Array)
      DEFAULT_OPTIONS.dup.merge(style: options)
    else
      DEFAULT_OPTIONS.dup.merge(options)
    end
  end

  def ps
    ary = to_array([@options[:style]].flatten)
    "#{ary}#{@options[:offset]} setdash"
  end
end