
    Ng	                     @    d Z ddlZddlZddlmZ  G d d          ZdS ))	PdfMatrix    Nc                       e Zd ZdZddZd Zd Zed             Zd Z	e
d	             Zd
 Zd Zd Zd ZddZd ZddZd Z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                 `    ||||||f\  | _         | _        | _        | _        | _        | _        d S Nabcdef)selfr	   r
   r   r   r   r   s          U/var/www/html/ai-engine/env/lib/python3.11/site-packages/pypdfium2/_helpers/matrix.py__init__zPdfMatrix.__init__(   s1    9:Aq!Q9I6    c                 0    d|                                   S )Nr   )getr   s    r   __repr__zPdfMatrix.__repr__,   s    '488::'''r   c                     t          |           t          |          urdS |                                 |                                k    S )NF)typer   r   others     r   __eq__zPdfMatrix.__eq__0   s9    ::T%[[((5

eiikk)*r   c                 N    t          j        |                                           S r   )ctypesbyrefto_rawr   s    r   _as_parameter_zPdfMatrix._as_parameter_6   s    |T[[]],,,r   c                 N    | 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   s    r   r   zPdfMatrix.get;   s#     ??r   c                 ^     | |j         |j        |j        |j        |j        |j                  S )zR
        Load a :class:`.PdfMatrix` from a raw :class:`FS_MATRIX` object.
        r   )clsraws     r   from_rawzPdfMatrix.from_rawB   s*    
 s35#%suce<<<r   c                 B    t          j        |                                  S )zH
        Convert the matrix to a raw :class:`FS_MATRIX` object.
        )pdfium_c	FS_MATRIXr   r   s    r   r   zPdfMatrix.to_rawJ   s     !488::..r   c           
         t          | j        |j        z  | j        |j        z  z   | j        |j        z  | j        |j        z  z   | j        |j        z  | j        |j        z  z   | j        |j        z  | j        |j        z  z   | j        |j        z  | j        |j        z  z   |j        z   | j        |j        z  | j        |j        z  z   |j        z             S )zf
        Multiply this matrix by another :class:`.PdfMatrix`, to concatenate transformations.
        r   )r   r	   r
   r   r   r   r   r   s     r   multiplyzPdfMatrix.multiplyQ   s     uw/uw/uw/uw/uw/%'9uw/%'9
 
 
 	
r   c           
      P    |                      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ys      r   	translatezPdfMatrix.translatec   s(     }}i1aAq99;;;r   c                 L    |                      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-   s      r   scalezPdfMatrix.scalem   s$     }}i1a33555r   Fc                     |st          j        |          }t          j        |          t          j        |          }}|                     |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   angleccwradr   ss         r   rotatezPdfMatrix.rotatew   sr      	(L''Ex1}}Wi1qb!4441qbRSUVAWAWYYYr   c                 @    |                      |rdnd|rdn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/   )r2   )r   vhs      r   mirrorzPdfMatrix.mirror   s*     zz1^RR!qazAAAr   c           	          |s(t          j        |          }t          j        |          }|                     t          dt          j        |          t          j        |          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   )r4   r5   r*   r   tan)r   x_angley_angler:   s       r   skewzPdfMatrix.skew   s_      	,l7++Gl7++G}}i48G+<+<dhw>O>OQRSSUUUr   c                 v    | j         |z  | j        |z  z   | j        z   | j        |z  | j        |z  z   | j        z   fS )zI
        Returns:
            (float, float): Transformed point.
        )r	   r   r   r
   r   r   r-   s      r   on_pointzPdfMatrix.on_point   sD     F1Htvax$&(F1Htvax$&(
 	
r   c                 r   |                      ||          |                      ||          |                      ||          |                      ||          f}t          d |D                       t          d |D                       t          d |D                       t          d |D                       fS )z[
        Returns:
            (float, float, float, float): Transformed rectangle.
        c              3   &   K   | ]}|d          V  dS r   N .0ps     r   	<genexpr>z$PdfMatrix.on_rect.<locals>.<genexpr>   &      %%!%%%%%%r   c              3   &   K   | ]}|d          V  dS r   NrL   rM   s     r   rP   z$PdfMatrix.on_rect.<locals>.<genexpr>   rQ   r   c              3   &   K   | ]}|d          V  dS rK   rL   rM   s     r   rP   z$PdfMatrix.on_rect.<locals>.<genexpr>   rQ   r   c              3   &   K   | ]}|d          V  dS rS   rL   rM   s     r   rP   z$PdfMatrix.on_rect.<locals>.<genexpr>   rQ   r   )rH   minmax)r   leftbottomrighttoppointss         r   on_rectzPdfMatrix.on_rect   s     MM$$$MM$''MM%%%MM%((	
 %%f%%%%%%%f%%%%%%%f%%%%%%%f%%%%%	
 	
r   N)r   r   r   r   r   r   )FF)F)__name__
__module____qualname____doc__r   r   r   propertyr    r   classmethodr%   r   r*   r0   r2   r<   rA   rF   rH   r]   rL   r   r   r   r      s8        0J J J J( ( (+ + + - - X-@ @ @ = = [=/ / /
 
 
$< < <6 6 6
Z 
Z 
Z 
ZB B B
V 
V 
V 
V	
 	
 	

 
 
 
 
r   r   )__all__r4   r   pypdfium2.rawr$   r'   r   rL   r   r   <module>rf      sl                  h
 h
 h
 h
 h
 h
 h
 h
 h
 h
r   