Method: PDF::Reader::TransformationMatrix#multiply!
- Defined in:
- lib/pdf/reader/transformation_matrix.rb
#multiply!(a, b = nil, c = nil, d = nil, e = nil, f = nil) ⇒ Object
multiply this matrix with another.
the second matrix is represented by the 6 scalar values that are changeable in a PDF transformation matrix.
WARNING: This mutates the current matrix to avoid allocating memory when
we don't need too. Matrices are multiplied ALL THE FREAKING TIME
so this is a worthwhile optimisation
NOTE: When multiplying matrices, ordering matters. Double check
the PDF spec to ensure you're multiplying things correctly.
NOTE: see Section 8.3.3, PDF 32000-1:2008, pp 119
NOTE: The if statements in this method are ordered to prefer optimisations
that allocate fewer objects
TODO: it might be worth adding an optimised path for vertical
displacement to speed up processing documents that use vertical
writing systems
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/pdf/reader/transformation_matrix.rb', line 54 def multiply!(a,b=nil,c=nil, d=nil,e=nil,f=nil) if a == 1 && b == 0 && c == 0 && d == 1 && e == 0 && f == 0 # the identity matrix, no effect self elsif @a == 1 && @b == 0 && @c == 0 && @d == 1 && @e == 0 && @f == 0 # I'm the identity matrix, so just copy values across @a = a @b = b @c = c @d = d @e = e @f = f elsif a == 1 && b == 0 && c == 0 && d == 1 && f == 0 # the other matrix is a horizontal displacement horizontal_displacement_multiply!(e) elsif @a == 1 && @b == 0 && @c == 0 && @d == 1 && @f == 0 # I'm a horizontal displacement horizontal_displacement_multiply_reversed!(a,b,c,d,e,f) elsif @a != 1 && @b == 0 && @c == 0 && @d != 1 && @e == 0 && @f == 0 # I'm a xy scale xy_scaling_multiply_reversed!(a,b,c,d,e,f) elsif a != 1 && b == 0 && c == 0 && d != 1 && e == 0 && f == 0 # the other matrix is an xy scale xy_scaling_multiply!(a,b,c,d,e,f) else faster_multiply!(a,b,c, d,e,f) end self end |