o
    e                     @  s6   d Z ddlmZ ddlmZmZmZ G dd dZdS )zPDF content matrix support.    )annotations)cospisinc                   @  s   e Zd ZdZdd Zedd Zdd Zdd	 Zd
d Z	dd Z
edd Zedd Zedd Zedd Zedd Zedd Zedd Zdd Zdd Zd d! Zd"S )#	PdfMatrixa  
    Support class for PDF content stream matrices.

    PDF content stream matrices are 3x3 matrices summarized by a shorthand
    ``(a, b, c, d, e, f)`` which correspond to the first two column vectors.
    The final column vector is always ``(0, 0, 1)`` since this is using
    `homogenous coordinates <https://en.wikipedia.org/wiki/Homogeneous_coordinates>`_.

    PDF uses row vectors.  That is, ``vr @ A'`` gives the effect of transforming
    a row vector ``vr=(x, y, 1)`` by the matrix ``A'``.  Most textbook
    treatments use ``A @ vc`` where the column vector ``vc=(x, y, 1)'``.

    (``@`` is the Python matrix multiplication operator.)

    Addition and other operations are not implemented because they're not that
    meaningful in a PDF context (they can be defined and are mathematically
    meaningful in general).

    PdfMatrix objects are immutable. All transformations on them produce a new
    matrix.

    c                 G  s$  |sd| _ d S t|dkr)tt|\}}}}}}||df||df||dff| _ d S t|d tr8|d j | _ d S t|d dkr^tt|d \}}}}}}||df||df||dff| _ d S t|d dkrt|d d dkrt|d d t|d d t|d d f| _ d S tdt| )N))   r   r   )r   r   r   )r   r   r      r   r         zinvalid arguments: )	valueslenmapfloat
isinstancer   tuple
ValueErrorrepr)selfargsabcdef r   ED:\Projects\ConvertPro\env\Lib\site-packages\pikepdf/models/matrix.py__init__#   s,   


$
zPdfMatrix.__init__c                   C  s   t  S )z*Constructs and returns an identity matrix.r   r   r   r   r   identity;   s   zPdfMatrix.identityc                   s"   | j }|j  t fdd|D S )zeMultiply this matrix by another matrix.

        Can be used to concatenate transformations.
        c                   s"   g | ]  fd dt  D qS )c                   s$   g | ]}t d d t |D qS )c                 s  s$    | ]\}}t |t | V  qd S )N)r   ).0ijr   r   r   	<genexpr>I   s   " z=PdfMatrix.__matmul__.<locals>.<listcomp>.<listcomp>.<genexpr>)sumzip)r    colrowr   r   
<listcomp>I   s   $ z3PdfMatrix.__matmul__.<locals>.<listcomp>.<listcomp>)r%   )r    r   r'   r   r)   H   s    z(PdfMatrix.__matmul__.<locals>.<listcomp>)r   r   )r   otherr   r   r*   r   
__matmul__@   s   
zPdfMatrix.__matmul__c                 C  s   | t |dd|ddf S )z-Concatenates a scaling matrix on this matrix.r   r   r   xyr   r   r   scaledN      zPdfMatrix.scaledc                 C  s8   |d t  }t|t|}}| t||| |ddf S )z.Concatenates a rotation matrix on this matrix.g     f@r   )r   r   r   r   )r   Zangle_degrees_ccwZangler   sr   r   r   rotatedR   s   zPdfMatrix.rotatedc                 C  s   | t dddd||f S )zTranslates this matrix.r   r   r   r-   r   r   r   
translatedX   r1   zPdfMatrix.translatedc                 C  s   | j | j| j| j| j| jfS )z<Return the 6-tuple (a,b,c,d,e,f) that describes this matrix.)r   r   r   r   r   r   r   r   r   r   	shorthand\   s   zPdfMatrix.shorthandc                 C     | j d d S )Return matrix this value.r   r   r5   r   r   r   r   a      zPdfMatrix.ac                 C     | j d d S )r8   r   r   r9   r5   r   r   r   r   f   r:   zPdfMatrix.bc                 C  r;   )r8   r   r   r9   r5   r   r   r   r   k   r:   zPdfMatrix.cc                 C  r7   )r8   r   r9   r5   r   r   r   r   p   r:   zPdfMatrix.dc                 C  r;   )z_Return matrix this value.

        Typically corresponds to translation on the x-axis.
        r
   r   r9   r5   r   r   r   r   u      zPdfMatrix.ec                 C  r;   )z_Return matrix this value.

        Typically corresponds to translation on the y-axis.
        r
   r   r9   r5   r   r   r   r   }   r<   zPdfMatrix.fc                 C  s   t |tr| j|jkS dS )NF)r   r   r6   )r   r+   r   r   r   __eq__   s   
zPdfMatrix.__eq__c                 C  s$   d | j| j| j| j| j| j S )z=Encode this matrix in binary suitable for including in a PDF.z){:.6f} {:.6f} {:.6f} {:.6f} {:.6f} {:.6f})formatr   r   r   r   r   r   encoder5   r   r   r   r?      s
   zPdfMatrix.encodec                 C  s   dt | j dS )Nzpikepdf.PdfMatrix())r   r   r5   r   r   r   __repr__   s   zPdfMatrix.__repr__N)__name__
__module____qualname____doc__r   staticmethodr   r,   r0   r3   r4   propertyr6   r   r   r   r   r   r   r=   r?   rA   r   r   r   r   r      s4    







r   N)rE   
__future__r   mathr   r   r   r   r   r   r   r   <module>   s   