Parent

Class/Module Index [+]

Quicksearch

Origami::PDF::Instruction

Attributes

operands[RW]
operator[R]

Public Class Methods

get_operands(operator) click to toggle source
# File lib/origami/graphics/instruction.rb, line 75
def get_operands(operator)
  @insns[operator][:operands]
end
get_render_proc(operator) click to toggle source
# File lib/origami/graphics/instruction.rb, line 71
def get_render_proc(operator)
  @insns[operator][:render]
end
has_op?(operator) click to toggle source
# File lib/origami/graphics/instruction.rb, line 67
def has_op?(operator)
  @insns.has_key? operator
end
insn(operator, *operands, &render_proc) click to toggle source
# File lib/origami/graphics/instruction.rb, line 61
def insn(operator, *operands, &render_proc)
  @insns[operator] = {}
  @insns[operator][:operands] = operands
  @insns[operator][:render] = render_proc || lambda{}
end
new(operator, *operands) click to toggle source
# File lib/origami/graphics/instruction.rb, line 36
def initialize(operator, *operands)
  @operator = operator
  @operands = operands.map!{|arg| arg.is_a?(Origami::Object) ? arg.value : arg}

  if self.class.has_op?(operator)
    opdef = self.class.get_operands(operator)

    if not opdef.include?('*') and opdef.size != operands.size
      raise InvalidPDFInstructionError, 
        "Numbers of operands mismatch for #{operator}: #{operands.inspect}"
    end
  end
end
parse(stream) click to toggle source
# File lib/origami/graphics/instruction.rb, line 79
def parse(stream)
  operands = []
  while type = Object.typeof(stream, true)
    operands.push type.parse(stream)
  end
  
  if not stream.eos?
    if stream.scan(@@regexp).nil?
      raise InvalidPDFInstructionError, 
        "Operator: #{(stream.peek(10) + '...').inspect}"
    end

    operator = stream[1]
    PDF::Instruction.new(operator, *operands)
  else
    if not operands.empty?
      raise InvalidPDFInstructionError,
        "No operator given for operands: #{operands.join}"
    end
  end
end

Public Instance Methods

render(canvas) click to toggle source
# File lib/origami/graphics/instruction.rb, line 50
def render(canvas)
  self.class.get_render_proc(@operator)[canvas, *@operands]

  self
end
to_s() click to toggle source
# File lib/origami/graphics/instruction.rb, line 56
def to_s
  "#{operands.map{|op| op.to_o.to_s}.join(' ')}#{' ' unless operands.empty?}#{operator}\n"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.