Class: PDF::Reader::TransformationMatrix

### Home Classes Methods

### In Files

- lib/pdf/reader/transformation_matrix.rb

### Parent

Object

### Methods

- ::new
- #horizontal_displacement_multiply!
- #inspect
- #multiply!
- #to_a

### Files

- MIT-LICENSE
- README.rdoc
- TODO
- mac_expert.txt
- mac_roman.txt
- pdf_doc.txt
- standard.txt
- symbol.txt
- win_ansi.txt
- zapf_dingbats.txt
- glyphlist.txt

### Class/Module Index

Quicksearch

- PDF
- PDF::Reader
- PDF::Reader::Buffer
- PDF::Reader::CidWidths
- PDF::Reader::EncryptedPDFError
- PDF::Reader::Filter
- PDF::Reader::Filter::Ascii85
- PDF::Reader::Filter::AsciiHex
- PDF::Reader::Filter::Depredict
- PDF::Reader::Filter::Flate
- PDF::Reader::Filter::Lzw
- PDF::Reader::Filter::Null
- PDF::Reader::Filter::RunLength
- PDF::Reader::Font
- PDF::Reader::FontDescriptor
- PDF::Reader::FormXObject
- PDF::Reader::InvalidObjectError
- PDF::Reader::MalformedPDFError
- PDF::Reader::ObjectCache
- PDF::Reader::ObjectHash
- PDF::Reader::PageLayout
- PDF::Reader::PageState
- PDF::Reader::PageTextReceiver
- PDF::Reader::Parser
- PDF::Reader::PrintReceiver
- PDF::Reader::Reference
- PDF::Reader::RegisterReceiver
- PDF::Reader::ResourceMethods
- PDF::Reader::StandardSecurityHandler
- PDF::Reader::Stream
- PDF::Reader::SynchronizedCache
- PDF::Reader::TextReceiver
- PDF::Reader::TextRun
- PDF::Reader::TransformationMatrix
- PDF::Reader::UnsupportedFeatureError
- PDF::Reader::WidthCalculator
- PDF::Reader::WidthCalculator::BuiltIn
- PDF::Reader::WidthCalculator::Composite
- PDF::Reader::WidthCalculator::TrueType
- PDF::Reader::WidthCalculator::TypeOneOrThree
- PDF::Reader::WidthCalculator::TypeZero
- PDF::Reader::XRef
- AFM
- AFM::Font

No matching classes.

# PDF::Reader::TransformationMatrix

co-ordinate systems in PDF files are specified using a 3x3 matrix that looks something like this:

    [ a b 0 ]
    [ c d 0 ]
    [ e f 1 ]

Because the final column never changes, we can represent each matrix using only 6 numbers. This is important to save CPU time, memory and GC pressure caused by allocating too many unnecessary objects.

### Attributes

a[R]
b[R]
c[R]
d[R]
e[R]
f[R]

### Public Class Methods

new(a, b, c, d, e, f) click to toggle source

    # File lib/pdf/reader/transformation_matrix.rb, line 16
    def initialize(a, b, c, d, e, f)
      @a, @b, @c, @d, @e, @f = a, b, c, d, e, f
    end

### Public Instance Methods

horizontal_displacement_multiply!(e2) click to toggle source

Optimised method for when the second matrix in the calculation is a simple horizontal displacement.

Like this:

    [ 1 2 0 ]   [ 1  0 0 ]
    [ 3 4 0 ] x [ 0  1 0 ]
    [ 5 6 1 ]   [ e2 0 1 ]

    # File lib/pdf/reader/transformation_matrix.rb, line 90
    def horizontal_displacement_multiply!(e2)
      @e = @e + e2
    end

inspect() click to toggle source

    # File lib/pdf/reader/transformation_matrix.rb, line 20
    def inspect
      "#{a}, #{b}, 0,\n#{c}, #{d}, #{0},\n#{e}, #{f}, 1"
    end

multiply!(a,b=nil,c=nil, d=nil,e=nil,f=nil) click to toggle source

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

    # File lib/pdf/reader/transformation_matrix.rb, line 51
    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

to_a() click to toggle source

    # File lib/pdf/reader/transformation_matrix.rb, line 24
    def to_a
      [@a,@b,0,
       @c,@d,0,
       @e,@f,1]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.