o
    f	                     @   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: bottom left corner, Device coordinates: top left corner).
        * 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   R/home/ubuntu/webapp/venv/lib/python3.10/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__0   s   zPdfMatrix.__eq__c                 C   s   t |  S r   )ctypesbyrefto_rawr   r   r   r   _as_parameter_6   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   ;   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_rawB   s   zPdfMatrix.from_rawc                 C   s   t j|   S )zH
        Convert the matrix to a raw :class:`FS_MATRIX` object.
        )pdfium_c	FS_MATRIXr   r   r   r   r   r   J   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   multiplyQ   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   	translatec   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   scalem   s   zPdfMatrix.scaleFc                 C   sP   |st |}t |t |}}| |rt||| |S 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   angleccwradr   sr   r   r   rotatew   s   
,zPdfMatrix.rotatec                 C   s"   | j |rdnd|rddS ddS )z
        Parameters:
            v (bool): Whether to mirror vertically (at the Y axis).
            h (bool): Whether to mirror horizontall (at the X axis).
        r   )r#   r$   )r&   )r   vhr   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   x_angle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       | ]}|d  V  qdS r   Nr   .0pr   r   r   	<genexpr>       z$PdfMatrix.on_rect.<locals>.<genexpr>c                 s   r9   r   Nr   r;   r   r   r   r>      r?   c                 s   r9   r:   r   r;   r   r   r   r>      r?   c                 s   r9   r@   r   r;   r   r   r   r>      r?   )r8   minmax)r   leftbottomrighttop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/   r3   r7   r8   rH   r   r   r   r   r      s&    






	r   )__all__r'   r   pypdfium2.rawr   r   r   r   r   r   r   <module>   s
   