File: ps_object.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,093 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
# Postscript wrapper class
class RGhost::PsObject
  # Creates new instance of PsObject. Example
  #   PsObject.new("/my_proc { 33 45 2 10 sub mul div} bind def")
  # Or by block code
  #   PsObject.new do
  #     set PsObject.new("(A test) show")
  #     raw "(Other Test in raw) show "
  #   end
  def initialize(body = "", &block)
    @body = if body.is_a? RGhost::PsObject
      body.ps
    else
      "#{body} "
    end

    instance_eval(&block) if block
  end

  # Alias for ps.
  def to_s
    ps
  end

  # Gets postscript code.
  def ps
    @body.to_s
  end

  # Pushes elements on the stack.
  def raw(*value)
    @body << "#{value.join(" ")} "
  end

  # Freezes graphic state
  def graphic_scope
    "beging #{self} endg "
  end

  # Sets PsObject into this object.
  def set(value)
    raise TypeError.new("can't convert #{value.class} into PsObject") unless value.is_a? RGhost::PsObject
    @body << "#{value.ps} "
    value
  end

  # Alias for set
  def <<(value)
    set value
  end

  # Call operator in the stack
  def call(name)
    set RGhost::PsObject.new(name)
  end
end