Module: Prawn::SVG::PDFMatrix

Included in:
GradientRenderer, TransformParser
Defined in:
lib/prawn/svg/pdfmatrix.rb

Instance Method Summary collapse

Instance Method Details

#load_matrix(matrix) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/prawn/svg/pdfmatrix.rb', line 2

def load_matrix(matrix)
  if matrix.is_a?(Matrix) && matrix.row_count == 3 && matrix.column_count == 3
    matrix
  elsif matrix.is_a?(Array) && matrix.length == 6
    Matrix[
      [matrix[0], matrix[2], matrix[4]],
      [matrix[1], matrix[3], matrix[5]],
      [0.0, 0.0, 1.0]
    ]
  else
    raise ArgumentError, 'unexpected matrix format'
  end
end

#matrix_for_pdf(matrix) ⇒ Object



16
17
18
# File 'lib/prawn/svg/pdfmatrix.rb', line 16

def matrix_for_pdf(matrix)
  matrix.to_a[0..1].transpose.flatten
end

#rotation_matrix(angle, space: :pdf) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/prawn/svg/pdfmatrix.rb', line 28

def rotation_matrix(angle, space: :pdf)
  dir = space == :svg ? 1.0 : -1.0

  Matrix[
    [Math.cos(angle), -dir * Math.sin(angle), 0],
    [dir * Math.sin(angle), Math.cos(angle), 0],
    [0, 0, 1]
  ]
end

#scale_matrix(x = 1, y = x) ⇒ Object



24
25
26
# File 'lib/prawn/svg/pdfmatrix.rb', line 24

def scale_matrix(x = 1, y = x)
  Matrix[[x.to_f, 0.0, 0.0], [0.0, y.to_f, 0.0], [0.0, 0.0, 1.0]]
end

#translation_matrix(x = 0, y = 0) ⇒ Object



20
21
22
# File 'lib/prawn/svg/pdfmatrix.rb', line 20

def translation_matrix(x = 0, y = 0)
  Matrix[[1.0, 0.0, x.to_f], [0.0, 1.0, y.to_f], [0.0, 0.0, 1.0]]
end