Method: HexaPDF::Content::Canvas#transform

Defined in:
lib/hexapdf/content/canvas.rb

#transform(a, b, c, d, e, f) ⇒ Object

:call-seq:

canvas.transform(a, b, c, d, e, f)              => canvas
canvas.transform(a, b, c, d, e, f) { block }    => canvas

Transforms the coordinate system by applying the given matrix to the current transformation matrix and returns self.

If invoked with a block, the transformation is only active during the block by saving and restoring the graphics state.

The given values are interpreted as a matrix in the following way:

a b 0
c d 0
e f 1

Example:

#>pdf
canvas.transform(1, 0, 0, 1, 100, 100) do  # Translate origin to (100, 100)
  canvas.stroke_color("hp-blue").
    line(0, 0, 100, 50).stroke             # Actually from (100, 100) to (200, 150)
end
canvas.line(0, 0, 100, 50).stroke          # Really from (0, 0) to (100, 50)

See: PDF2.0 s8.3, s8.4.4



421
422
423
424
425
426
427
428
429
430
# File 'lib/hexapdf/content/canvas.rb', line 421

def transform(a, b, c, d, e, f)
  raise_unless_at_page_description_level
  save_graphics_state if block_given?
  invoke(:cm, a, b, c, d, e, f)
  if block_given?
    yield
    restore_graphics_state
  end
  self
end