Class: RubyPost::Clip

Inherits:
BaseDrawCommand show all
Defined in:
lib/draw.rb

Overview

This wraps the metapost clipping command. This needs to be used with a little care. It will clip everything that has been previously added to the picture when you add it. Anything that gets drawn after clipping, wont be clipped. This is in keeping with the way that metapost works, however most other objects in rubypost the order inwhich they are added has no effect (other than overlay). <br> Clip only kind of fits as a draw command. It’s doesn’t need colours and stuff. This is the best place to put it at the moment, but it probably should inheret something else.

Instance Attribute Summary collapse

Attributes inherited from BaseDrawCommand

#drawable

Instance Method Summary collapse

Methods inherited from BaseDrawCommand

#add_option, #color, #colour, #compile_options, #rotate, #scale, #set_drawable, #translate

Constructor Details

#initialize(path = nil, pic = 'currentpicture') ⇒ Clip

Returns a new instance of Clip.



127
128
129
130
131
# File 'lib/draw.rb', line 127

def initialize(path=nil, pic='currentpicture')
	super()
	@picture = pic
	@path = path
end

Instance Attribute Details

#path=(value) ⇒ Object (writeonly)

Sets the attribute path

Parameters:

  • value

    the value to set the attribute path to.



125
126
127
# File 'lib/draw.rb', line 125

def path=(value)
  @path = value
end

#picture=(value) ⇒ Object (writeonly)

Sets the attribute picture

Parameters:

  • value

    the value to set the attribute picture to.



125
126
127
# File 'lib/draw.rb', line 125

def picture=(value)
  @picture = value
end

Instance Method Details

#compileObject



143
144
145
# File 'lib/draw.rb', line 143

def compile
	"clip " + @picture.compile + " to " + @path.compile + ' ' + compile_options + ";\n"
end

#set_path(p) ⇒ Object

set the clipping path



134
135
136
# File 'lib/draw.rb', line 134

def set_path(p)
	@path = p
end

#set_picture(p = 'currentpicture') ⇒ Object

set the picture to clip. Defaults to ‘currentpicture’ see a metapost guide



139
140
141
# File 'lib/draw.rb', line 139

def set_picture(p='currentpicture')
	@picture = p
end