a
    �˜ëj#  ã                   @   s2   d Z ddlZddlZddlmZ G dd„ dƒZdS ))Ú	PdfMatrixé    Nc                   @   s–   e Zd ZdZd$dd„Zdd„ Zdd	„ Zed
d„ ƒZdd„ Z	e
dd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zd%dd„Zdd„ Zd&dd„Zdd „ Zd!d"„ Zd#S )'r   a¯  
    PDF transformation matrix helper class.
    
    See the PDF 1.7 specification, Section 8.3.3 ("Common Transformations").
    
    Note:
        * The PDF format uses row vectors.
        * Transformations operate from the origin of the coordinate system
          (PDF coordinates: commonly bottom left, but can be any corner in principle. Device coordinates: top left).
        * Matrix calculations are implemented independently in Python.
        * Matrix objects are immutable, so transforming methods return a new matrix.
        * Matrix objects implement ctypes auto-conversion to ``FS_MATRIX`` for easy use as C function parameter.
    
    Attributes:
        a (float): Matrix value [0][0].
        b (float): Matrix value [0][1].
        c (float): Matrix value [1][0].
        d (float): Matrix value [1][1].
        e (float): Matrix value [2][0] (X translation).
        f (float): Matrix value [2][1] (Y translation).
    é   r   c                 C   s,   ||||||f\| _ | _| _| _| _| _d S ©N©ÚaÚbÚcÚdÚeÚf)Úselfr   r   r   r	   r
   r   © r   úX/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pypdfium2/_helpers/matrix.pyÚ__init__&   s    zPdfMatrix.__init__c                 C   s   d|   ¡ › �S )Nr   )Úget©r   r   r   r   Ú__repr__)   s    zPdfMatrix.__repr__c                 C   s$   t | ƒt |ƒurdS |  ¡ | ¡ kS )NF)Útyper   ©r   Úotherr   r   r   Ú__eq__,   s    zPdfMatrix.__eq__c                 C   s   t  |  ¡ ¡S r   )ÚctypesÚbyrefÚto_rawr   r   r   r   Ú_as_parameter_1   s    zPdfMatrix._as_parameter_c                 C   s   | j | j| j| j| j| jfS )zI
        Get the matrix as tuple of the form (a, b, c, d, e, f).
        r   r   r   r   r   r   6   s    zPdfMatrix.getc                 C   s   | |j |j|j|j|j|jƒS )zR
        Load a :class:`.PdfMatrix` from a raw :class:`FS_MATRIX` object.
        r   )ÚclsÚrawr   r   r   Úfrom_raw=   s    zPdfMatrix.from_rawc                 C   s   t j|  ¡ Ž S )zH
        Convert the matrix to a raw :class:`FS_MATRIX` object.
        )Úpdfium_cZ	FS_MATRIXr   r   r   r   r   r   E   s    zPdfMatrix.to_rawc              	   C   s˜   t | j|j | j|j  | j|j | j|j  | j|j | j|j  | j|j | j|j  | j|j | j|j  |j | j|j | j|j  |j d�S )zf
        Multiply this matrix by another :class:`.PdfMatrix`, to concatenate transformations.
        r   )r   r   r   r   r	   r
   r   r   r   r   r   ÚmultiplyL   s    ùzPdfMatrix.multiplyc              	   C   s   |   tdddd||ƒ¡S )zƒ
        Parameters:
            x (float): Horizontal shift (<0: left, >0: right).
            y (float): Vertical shift.
        r   r   ©r   r   ©r   ÚxÚyr   r   r   Ú	translate_   s    zPdfMatrix.translatec                 C   s   |   t|dd|ƒ¡S )z£
        Parameters:
            x (float): A factor to scale the X axis (<1: compress, >1: stretch).
            y (float): A factor to scale the Y axis.
        r   r    r!   r   r   r   Úscalei   s    zPdfMatrix.scaleFc                 C   sN   |st  |¡}t  |¡t  |¡ }}|  |r<t||| |ƒnt|| ||ƒ¡S )zÙ
        Parameters:
            angle (float): Angle by which to rotate the matrix.
            ccw (bool): If True, rotate counter-clockwise.
            rad (bool): If True, interpret the angle as radians.
        )ÚmathÚradiansÚcosÚsinr   r   )r   ZangleZccwÚradr   Úsr   r   r   Úrotates   s    
zPdfMatrix.rotatec                 C   s   | j |rdnd|rdndd�S )a‚  
        Parameters:
            invert_x (bool): If True, invert X coordinates (horizontal transform). Corresponds to flipping around the Y axis.
            invert_y (bool): If True, invert Y coordinates (vertical transform). Corresponds to flipping around the X axis.
        Note:
            Flipping around a vertical axis leads to a horizontal transform, and vice versa.
        éÿÿÿÿr   )r"   r#   )r%   )r   Zinvert_xZinvert_yr   r   r   Úmirror€   s    zPdfMatrix.mirrorc                 C   s8   |st  |¡}t  |¡}|  tdt  |¡t  |¡dƒ¡S )zÙ
        Parameters:
            x_angle (float): Inner angle to skew the X axis.
            y_angle (float): Inner angle to skew the Y axis.
            rad (bool): If True, interpret the angles as radians.
        r   )r&   r'   r   r   Útan)r   Zx_angleZy_angler*   r   r   r   Úskew‹   s    

zPdfMatrix.skewc                 C   s4   | j | | j|  | j | j| | j|  | j fS )zI
        Returns:
            (float, float): Transformed point.
        )r   r   r
   r   r	   r   r!   r   r   r   Úon_point˜   s    þzPdfMatrix.on_pointc                 C   sp   |   ||¡|   ||¡|   ||¡|   ||¡f}tdd„ |D ƒƒtdd„ |D ƒƒtdd„ |D ƒƒtdd„ |D ƒƒfS )z[
        Returns:
            (float, float, float, float): Transformed rectangle.
        c                 s   s   | ]}|d  V  qdS ©r   Nr   ©Ú.0Úpr   r   r   Ú	<genexpr>°   ó    z$PdfMatrix.on_rect.<locals>.<genexpr>c                 s   s   | ]}|d  V  qdS ©r   Nr   r3   r   r   r   r6   ±   r7   c                 s   s   | ]}|d  V  qdS r2   r   r3   r   r   r   r6   ²   r7   c                 s   s   | ]}|d  V  qdS r8   r   r3   r   r   r   r6   ³   r7   )r1   ÚminÚmax)r   ÚleftZbottomÚrightÚtopZpointsr   r   r   Úon_rect¤   s    



üüzPdfMatrix.on_rectN)r   r   r   r   r   r   )FF)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Úpropertyr   r   Úclassmethodr   r   r   r$   r%   r,   r.   r0   r1   r>   r   r   r   r   r      s$   






r   )Ú__all__r&   r   Zpypdfium2.rawr   r   r   r   r   r   r   Ú<module>   s   