U
    :vh5F                    @   sR  d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZmZmZ ddlmZmZmZmZmZmZmZ dd	lmZmZ dd
lmZ ddiZdd Zedd Zeee ej!f Z"ee ej!fZ#e$dZ%e$dZ&e$dZ'e(dZ)dddddddddZ*G dd deZ+dd!d"Z,d#d$ Z-d%d& Z.G d'd( d(ed(d)e"fd*e"fd+e"fd,ee" fgZ/ded-< d.ed/< d0ed1< d2ed3< d4ed5< G d6d7 d7ed7d*e"fd,ee" fgZ0ded8< d9ed:< d4ed;< G d<d= d=ed=d>e"fd?e"fd@e"fdAe"fd,ee" fgZ1dedB< dCedD< dEedF< dGedH< dIedJ< d4edK< ddLdMZ2ddNdOZ3ddQdRZ4ddSdTZ5dUdV Z6dWdX Z7G dYdZ dZeZ8G d[d\ d\eZ9ded]< ded^< ded_< ded`< deda< dedb< G dcdd ddZ:dedf Z;dgdh Z<didj Z=G dkdl dleZ>G dmdn dneZ?G dodp dpeZ@G dqdr dreZAG dsdt dteZBG dudv dveZCG dwdx dxeZDG dydz dzeZEG d{d| d|eZFG d}d~ d~eZGG dd deZHG dd deZIG dd deZJG dd deZKG dd deZLG dd deZMG dd deZNG dd deZOG dd deZPG dd dZQG dd dZRG dd deRZSG dd dZTdS )a
  
Vector drawing: managing colors, graphics states, paths, transforms...

The contents of this module are internal to fpdf2, and not part of the public API.
They may change at any time without prior warning or any deprecation period,
in non-backward-compatible ways.
    N)OrderedDict)Sequence)contextmanager)Optional
NamedTupleUnion   )	BlendModeClippingPathIntersectionRuleIntersectionRulePathPaintRuleStrokeCapStyleStrokeJoinStylePDFStyleKeys)NameRaw)escape_parensforce_nodocumentFc                 C   s   dt | j< | S )zQA decorator that forces pdoc not to document the decorated item (class or method)F__pdoc____qualname__item r   0/tmp/pip-unpacked-wheel-dvf6lv8i/fpdf/drawing.pyr      s    
c                 C   s   dt | j< | S )zMA decorator that forces pdoc to document the decorated item (class or method)Tr   r   r   r   r   force_document%   s    
r   z 	
 z
z
()<>[]{}/%z[\n\r\t\b\f()\\]z\nz\rz\tz\bz\fz\(z\)z\\)
	()\c                   @   s   e Zd ZdZddddZdS )GraphicsStateDictRegistryzZ
    A container providing deduplication of graphics state dictionaries across a PDF.
    GraphicsStylestylec                 C   sN   |  }|sd S z
| | W S  tk
r.   Y nX tdt|  }|| |< |S )NZGS)	serializeKeyErrorr   len)selfr'   Zsdictnamer   r   r   register_styleK   s    
z(GraphicsStateDictRegistry.register_styleN)__name__
__module__r   __doc__r-   r   r   r   r   r$   F   s   r$                 ?c                 C   s4   ||   kr|ks0n t |  d| d| d| S )Nz not in range [z, ])
ValueError)valueZminimummaximumr   r   r   _check_range]   s    r7   c                 C   s   | d d dS )z
    Convert a decimal number to a minimal string representation (no trailing 0 or .).

    Args:
        number (Number): the number to be converted to a string.

    Returns:
        The number's string representation.
    z.4f0.)rstrip)numberr   r   r   number_to_strd   s    r<   c                 C   sB  t | tr| S tt| ddr*|  }n| dkr:d}n t | trVdt|  d}nt | trrd|   d}nt | t	rdd	g|  }nt | t
rt| }nt | ttfrd
ddd | D  d }npt | tr,g }|  D ]4\}}t |tstd|t|d t|  qdd| d }ntd| t|S )a  
    Render a Python value as a PDF primitive type.

    Container types (tuples/lists and dicts) are rendered recursively. This supports
    values of the type Name, str, bytes, numbers, booleans, list/tuple, and dict.

    Any custom type can be passed in as long as it provides a `serialize` method that
    takes no arguments and returns a string. The primitive object is returned directly
    if it is an instance of the `Raw` class. Otherwise, The existence of the `serialize`
    method is checked before any other type checking is performed, so, for example, a
    `dict` subclass with a `serialize` method would be converted using its `pdf_repr`
    method rather than the built-in `dict` conversion process.

    Args:
        primitive: the primitive value to convert to its PDF representation.

    Returns:
        Raw-wrapped str of the PDF representation.

    Raises:
        ValueError: if a dictionary key is not a Name.
        TypeError: if `primitive` does not have a known conversion to a PDF
            representation.
    r(   Nnullr!   r"   <>falsetrue[ c                 s   s   | ]}t |V  qd S N)render_pdf_primitive.0valr   r   r   	<genexpr>   s     z'render_pdf_primitive.<locals>.<genexpr>r3   zdict keys must be Namesz<< r   z >>z,cannot produce PDF representation for value )
isinstancer   callablegetattrr(   strr   byteshexboolNumberClassr<   listtuplejoindictitemsr   r4   appendrE   	TypeError)Z	primitiveoutputZ	item_listkeyrH   r   r   r   rE   t   s6    






rE   c                       sL   e Zd ZdZdZd fdd	Zedd Zedd	 Ze	d
ddZ
  ZS )	DeviceRGBz+A class representing a PDF DeviceRGB color.ZrgNc                    s0   |d k	rt | t | t |t |t ||S rD   r7   super__new__)clsrgba	__class__r   r   r^      s        zDeviceRGB.__new__c                 C   s   | dd S )zVThe color components as a tuple in order `(r, g, b)` with alpha omitted, in range 0-1.Nr   r+   r   r   r   colors   s    zDeviceRGB.colorsc                 C   s   t dd | jD S )XThe color components as a tuple in order `(r, g, b)` with alpha omitted, in range 0-255.c                 s   s   | ]}d | V  qdS    Nr   rG   vr   r   r   rI      s     z&DeviceRGB.colors255.<locals>.<genexpr>rS   rh   rg   r   r   r   	colors255   s    zDeviceRGB.colors255returnc                 C   s"   d dd | jD d| j  S )NrC   c                 s   s   | ]}t |V  qd S rD   r<   rF   r   r   r   rI      s     z&DeviceRGB.serialize.<locals>.<genexpr>rT   rh   OPERATORrg   r   r   r   r(      s    zDeviceRGB.serialize)Nr.   r/   r   r0   rt   r^   propertyrh   ro   rM   r(   __classcell__r   r   rd   r   r[      s   

r[   r`   ra   rb   rc   zDeviceRGB.OPERATORz8The red color component. Must be in the interval [0, 1].zDeviceRGB.rz:The green color component. Must be in the interval [0, 1].zDeviceRGB.gz9The blue color component. Must be in the interval [0, 1].zDeviceRGB.baD  
The alpha color component (i.e. opacity). Must be `None` or in the interval [0, 1].

An alpha value of 0 makes the color fully transparent, and a value of 1 makes it fully
opaque. If `None`, the color will be interpreted as not specifying a particular
transparency rather than specifying fully transparent or fully opaque.
zDeviceRGB.ac                       sL   e Zd ZdZdZd fdd	Zedd Zedd	 Ze	d
ddZ
  ZS )
DeviceGrayz,A class representing a PDF DeviceGray color.ra   Nc                    s$   |d k	rt | t | t ||S rD   r\   )r_   ra   rc   rd   r   r   r^     s    zDeviceGray.__new__c                 C   s   | j | j | j fS )zTThe color components as a tuple in order (r, g, b) with alpha omitted, in range 0-1.)ra   rg   r   r   r   rh     s    zDeviceGray.colorsc                 C   s   t dd | jD S )ri   c                 s   s   | ]}d | V  qdS rj   r   rl   r   r   r   rI     s     z'DeviceGray.colors255.<locals>.<genexpr>rn   rg   r   r   r   ro     s    zDeviceGray.colors255rp   c                 C   s   t | j d| j S )NrC   )r<   ra   rt   rg   r   r   r   r(     s    zDeviceGray.serialize)Nru   r   r   rd   r   rx      s   

rx   zDeviceGray.OPERATORz}
The gray color component. Must be in the interval [0, 1].

A value of 0 represents black and a value of 1 represents white.
zDeviceGray.gzDeviceGray.ac                       s@   e Zd ZdZdZd fdd	Zedd Zedd	d
Z	  Z
S )
DeviceCMYKz,A class representing a PDF DeviceCMYK color.kNc                    s6   |d k	rt | t | t |t |t |t ||S rD   r\   )r_   cmyrz   rc   rd   r   r   r^   <  s         zDeviceCMYK.__new__c                 C   s   | dd S )zWThe color components as a tuple in order (c, m, y, k) with alpha omitted, in range 0-1.Nrf   r   rg   r   r   r   rh   D  s    zDeviceCMYK.colorsrp   c                 C   s"   d dd | jD d| j  S )NrC   c                 s   s   | ]}t |V  qd S rD   rr   rF   r   r   r   rI   J  s     z'DeviceCMYK.serialize.<locals>.<genexpr>rs   rg   r   r   r   r(   I  s    zDeviceCMYK.serialize)N)r.   r/   r   r0   rt   r^   rv   rh   rM   r(   rw   r   r   rd   r   ry   +  s   
ry   r{   r|   r}   rz   zDeviceCMYK.OPERATORz9The cyan color component. Must be in the interval [0, 1].zDeviceCMYK.cz<The magenta color component. Must be in the interval [0, 1].zDeviceCMYK.mz;The yellow color component. Must be in the interval [0, 1].zDeviceCMYK.yz:The black color component. Must be in the interval [0, 1].zDeviceCMYK.kzDeviceCMYK.ac                 C   sP   |dkr.| |  kr|kr6n q6t | d S n|d }t| d |d |d |S )aP  
    Produce a DeviceRGB color from the given 8-bit RGB values.

    Args:
        r (Number): red color component. Must be in the interval [0, 255].
        g (Number): green color component. Must be in the interval [0, 255].
        b (Number): blue color component. Must be in the interval [0, 255].
        a (Optional[Number]): alpha component. Must be `None` or in the interval
            [0, 255]. 0 is fully transparent, 255 is fully opaque

    Returns:
        DeviceRGB color representation.

    Raises:
        ValueError: if any components are not in their valid interval.
    N     o@)rx   r[   )r`   ra   rb   rc   r   r   r   rgb8_  s
    r   c                 C   s   |dk	r|d }t | d |S )a  
    Produce a DeviceGray color from the given 8-bit gray value.

    Args:
        g (Number): gray color component. Must be in the interval [0, 255]. 0 is black,
            255 is white.
        a (Optional[Number]): alpha component. Must be `None` or in the interval
            [0, 255]. 0 is fully transparent, 255 is fully opaque

    Returns:
        DeviceGray color representation.

    Raises:
        ValueError: if any components are not in their valid interval.
    Nr~   )rx   )ra   rc   r   r   r   gray8y  s    r   rf   c                 C   s~   t | tttfr| S t | tr0| dr0t| S t | trD| \} }}| ||fdksZ|dkrft| d S t| d |d |d S )N#)r   r   r   rf   rk   )rJ   ry   rx   r[   rM   
startswithcolor_from_hex_stringr   )r`   ra   rb   r   r   r   convert_to_device_color  s    

r   c                 C   s0   |dk	r|d }t | d |d |d |d |S )a  
    Produce a DeviceCMYK color from the given 8-bit CMYK values.

    Args:
        c (Number): red color component. Must be in the interval [0, 255].
        m (Number): green color component. Must be in the interval [0, 255].
        y (Number): blue color component. Must be in the interval [0, 255].
        k (Number): blue color component. Must be in the interval [0, 255].
        a (Optional[Number]): alpha component. Must be `None` or in the interval
            [0, 255]. 0 is fully transparent, 255 is fully opaque

    Returns:
        DeviceCMYK color representation.

    Raises:
        ValueError: if any components are not in their valid interval.
    Nr~   )ry   )r{   r|   r}   rz   rc   r   r   r   cmyk8  s    r   c                    s   t  tst  d ds0t  dt }|dkr`tdd  dd D d	diS |d
krtdd  dd D  S |dkrt fddtd|dD d	diS |dkrt fddtd|dD  S t  ddS )a  
    Parse an RGB color from a css-style 8-bit hexadecimal color string.

    Args:
        hexstr (str): of the form `#RGB`, `#RGBA`, `#RRGGBB`, or `#RRGGBBAA` (case
            insensitive). Must include the leading octothorp. Forms omitting the alpha
            field are interpreted as not specifying the opacity, so it will not be
            explicitly set.

            An alpha value of `00` is fully transparent and `FF` is fully opaque.

    Returns:
        DeviceRGB representation of the color.
     is not of type strr   z does not start with #   c                 S   s   g | ]}t |d  ddqS       )baseintrG   charr   r   r   
<listcomp>  s     z)color_from_hex_string.<locals>.<listcomp>r   Nrc      c                 S   s   g | ]}t |d  ddqS r   r   r   r   r   r   r     s        c                    s$   g | ]}t  ||d   ddqS r   r   rG   idxhexstrr   r   r     s     r   	   c                    s$   g | ]}t  ||d   ddqS r   r   r   r   r   r   r     s     z0 could not be interpreted as a RGB(A) hex string)rJ   rM   rX   r   r4   r*   r   range)r   Zhlenr   r   r   r     s$    

 r   c                 C   s   t | tst|  d| dd} | dr8| dsFt|  d| dd } | d	}t|d
krt	dd |D ddiS t|dkrt	dd |D  S t|  ddS )z
    Parse an RGB color from a css-style rgb(R, G, B, A) color string.

    Args:
        rgbstr (str): of the form `rgb(R, G, B)` or `rgb(R, G, B, A)`.

    Returns:
        DeviceRGB representation of the color.
    r   rC    zrgb(r"   z- does not follow the expected rgb(...) formatr   rf   ,   c                 S   s   g | ]}t |qS r   r   rG   r{   r   r   r   r     s     z)color_from_rgb_string.<locals>.<listcomp>rc   Nc                 S   s   g | ]}t |qS r   r   r   r   r   r   r     s     z6 could not be interpreted as a rgb(R, G, B[, A]) color)
rJ   rM   rX   replacer   endswithr4   splitr*   r   )Zrgbstrrh   r   r   r   color_from_rgb_string  s    


r   c                   @   s   e Zd ZU dZeed< eed< 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Ze
dd Ze
dd Ze
dd Zdd ZdS )PointzM
    An x-y coordinate pair within the two-dimensional coordinate frame.
    xr}   c                 C   s   t | j dt | j S )z=Render the point to the string `"x y"` for emitting to a PDF.rC   r<   r   r}   rg   r   r   r   render  s    zPoint.renderc                 C   s0   t |tstd|| j|j | j|j  S )a(  
        Compute the dot product of two points.

        Args:
            other (Point): the point with which to compute the dot product.

        Returns:
            The scalar result of the dot product computation.

        Raises:
            TypeError: if `other` is not a `Point`.
        zcannot dot with )rJ   r   rX   r   r}   r+   otherr   r   r   dot
  s    
z	Point.dotc                 C   sj   t |tstd|| j|j | j|j  }|dk|dk  }|tt| || 	 |	   d S )a  
        Compute the angle between two points (interpreted as vectors from the origin).

        The return value is in the interval (-pi, pi]. Sign is dependent on ordering,
        with clockwise angle travel considered to be positive due to the orientation of
        the coordinate frame basis vectors (i.e. the angle between `(1, 0)` and `(0, 1)`
        is `+pi/2`, the angle between `(1, 0)` and `(0, -1)` is `-pi/2`, and the angle
        between `(0, -1)` and `(1, 0)` is `+pi/2`).

        Args:
            other (Point): the point to compute the angle sweep toward.

        Returns:
            The scalar angle between the two points **in radians**.

        Raises:
            TypeError: if `other` is not a `Point`.
        zcannot compute angle with r      )
rJ   r   rX   r   r}   mathacosroundr   mag)r+   r   Z	signifiersignr   r   r   angle  s
    
zPoint.anglec                 C   s   | j d | jd  d S )a  
        Compute the Cartesian distance from this point to the origin

        This is the same as computing the magnitude of the vector represented by this
        point.

        Returns:
            The scalar result of the distance computation.
        r         ?r   r}   rg   r   r   r   r   7  s    z	Point.magc                 C   s*   t |tr&t| j|j | j|j dS tS )an  
        Produce the sum of two points.

        Adding two points is the same as translating the source point by interpreting
        the other point's x and y coordinates as distances.

        Args:
            other (Point): right-hand side of the infix addition operation

        Returns:
            A Point which is the sum of the two source points.
        r   rJ   r   r   r}   NotImplementedr   r   r   r   __add__D  s    
zPoint.__add__c                 C   s*   t |tr&t| j|j | j|j dS tS )a0  
        Produce the difference between two points.

        Unlike addition, this is not a commutative operation!

        Args:
            other (Point): right-hand side of the infix subtraction operation

        Returns:
            A Point which is the difference of the two source points.
        r   r   r   r   r   r   __sub__W  s    
zPoint.__sub__c                 C   s   t | j | j dS )z
        Produce a point by negating this point's coordinates.

        Returns:
            A Point whose coordinates are this points coordinates negated.
        r   )r   r   r}   rg   r   r   r   __neg__i  s    zPoint.__neg__c                 C   s$   t |tr t| j| | j| S tS )a  
        Multiply a point by a scalar value.

        Args:
            other (Number): the scalar value by which to multiply the point's
                coordinates.

        Returns:
            A Point whose coordinates are the result of the multiplication.
        rJ   rQ   r   r   r}   r   r   r   r   r   __mul__s  s    
zPoint.__mul__c                 C   s$   t |tr t| j| | j| S tS )a  
        Divide a point by a scalar value.

        .. note::

            Because division is not commutative, `Point / scalar` is implemented, but
            `scalar / Point` is nonsensical and not implemented.

        Args:
            other (Number): the scalar value by which to divide the point's coordinates.

        Returns:
            A Point whose coordinates are the result of the division.
        r   r   r   r   r   __truediv__  s    
zPoint.__truediv__c                 C   s$   t |tr t| j| | j| S tS )a  
        Divide a point by a scalar value using integer division.

        .. note::

            Because division is not commutative, `Point // scalar` is implemented, but
            `scalar // Point` is nonsensical and not implemented.

        Args:
            other (Number): the scalar value by which to divide the point's coordinates.

        Returns:
            A Point whose coordinates are the result of the division.
        r   r   r   r   r   __floordiv__  s    
zPoint.__floordiv__c                 C   sN   t |trJt|j| j |j| j  |j |j| j |j	| j  |j
 dS tS )a  
        Transform a point with the given transform matrix.

        .. note::
            This operator is only implemented for Transforms. This transform is not
            commutative, so `Point @ Transform` is implemented, but `Transform @ Point`
            is not implemented (technically speaking, the current implementation is
            commutative because of the way points and transforms are represented, but
            if that representation were to change this operation could stop being
            commutative)

        Args:
            other (Transform): the transform to apply to the point

        Returns:
            A Point whose coordinates are the result of applying the transform.
        r   )rJ   	Transformr   rc   r   r{   r}   erb   dfr   r   r   r   r   
__matmul__  s    
zPoint.__matmul__c                 C   s   dt | j dt | j dS )Nz(x=z, y=r"   r   rg   r   r   r   __str__  s    zPoint.__str__N)r.   r/   r   r0   Number__annotations__r   r   r   r   r   r   r   r   r   __rmul__r   r   r   r   r   r   r   r   r     s.   



	



r   c                   @   s   e Zd ZU dZeed< eed< eed< eed< eed< eed< edd	 Zed
d Zed)ddZ	edd Z
edd Zed*ddZdd Zd+ddZdd Zdd Zd,ddZdd  Zed!d" ZeZed#d$ Zd%d& Zd'd( ZdS )-r   ax  
    A representation of an affine transformation matrix for 2D shapes.

    The actual matrix is:

    ```
                        [ a b 0 ]
    [x' y' 1] = [x y 1] [ c d 0 ]
                        [ e f 1 ]
    ```

    Complex transformation operations can be composed via a sequence of simple
    transformations by performing successive matrix multiplication of the simple
    transformations.

    For example, scaling a set of points around a specific center point can be
    represented by a translation-scale-translation sequence, where the first
    translation translates the center to the origin, the scale transform scales the
    points relative to the origin, and the second translation translates the points
    back to the specified center point. Transform multiplication is performed using
    python's dedicated matrix multiplication operator, `@`

    The semantics of this representation mean composed transformations are specified
    left-to-right in order of application (some other systems provide transposed
    representations, in which case the application order is right-to-left).

    For example, to rotate the square `(1,1) (1,3) (3,3) (3,1)` 45 degrees clockwise
    about its center point (which is `(2,2)`) , the translate-rotate-translate
    process described above may be applied:

    ```python
    rotate_centered = (
        Transform.translation(-2, -2)
        @ Transform.rotation_d(45)
        @ Transform.translation(2, 2)
    )
    ```

    Instances of this class provide a chaining API, so the above transform could also be
    constructed as follows:

    ```python
    rotate_centered = Transform.translation(-2, -2).rotate_d(45).translate(2, 2)
    ```

    Or, because the particular operation of performing some transformations about a
    specific point is pretty common,

    ```python
    rotate_centered = Transform.rotation_d(45).about(2, 2)
    ```

    By convention, this class provides class method constructors following noun-ish
    naming (`translation`, `scaling`, `rotation`, `shearing`) and instance method
    manipulations following verb-ish naming (`translate`, `scale`, `rotate`, `shear`).
    rc   rb   r{   r   r   r   c                 C   s   | ddddddS )zu
        Create a transform representing the identity transform.

        The identity transform is a no-op.
        r   r   r   )r_   r   r   r   identity  s    zTransform.identityc                 C   s   | dddd||S )aF  
        Create a transform that performs translation.

        Args:
            x (Number): distance to translate points along the x (horizontal) axis.
            y (Number): distance to translate points along the y (vertical) axis.

        Returns:
            A Transform representing the specified translation.
        r   r   r   r_   r   r}   r   r   r   translation"  s    zTransform.translationNc                 C   s   |dkr|}| |dd|ddS )a  
        Create a transform that performs scaling.

        Args:
            x (Number): scaling ratio in the x (horizontal) axis. A value of 1
                results in no scale change in the x axis.
            y (Number): optional scaling ratio in the y (vertical) axis. A value of 1
                results in no scale change in the y axis. If this value is omitted, it
                defaults to the value provided to the `x` argument.

        Returns:
            A Transform representing the specified scaling.
        Nr   r   r   r   r   r   scaling1  s    zTransform.scalingc                 C   s,   | t |t |t | t |ddS )a#  
        Create a transform that performs rotation.

        Args:
            theta (Number): the angle **in radians** by which to rotate. Positive
                values represent clockwise rotations.

        Returns:
            A Transform representing the specified rotation.

        r   )r   cossin)r_   thetar   r   r   rotationE  s      
   zTransform.rotationc                 C   s   |  t|S )a4  
        Create a transform that performs rotation **in degrees**.

        Args:
            theta_d (Number): the angle **in degrees** by which to rotate. Positive
                values represent clockwise rotations.

        Returns:
            A Transform representing the specified rotation.

        )r   r   radians)r_   theta_dr   r   r   
rotation_dV  s    zTransform.rotation_dc                 C   s   |dkr|}| d||dddS )a  
        Create a transform that performs shearing (not of sheep).

        Args:
            x (Number): The amount to shear along the x (horizontal) axis.
            y (Number): Optional amount to shear along the y (vertical) axis. If omitted,
                this defaults to the value provided to the `x` argument.

        Returns:
            A Transform representing the specified shearing.

        Nr   r   r   r   r   r   r   shearinge  s    zTransform.shearingc                 C   s   | t || S )a  
        Produce a transform by composing the current transform with a translation.

        .. note::
            Transforms are immutable, so this returns a new transform rather than
            mutating self.

        Args:
            x (Number): distance to translate points along the x (horizontal) axis.
            y (Number): distance to translate points along the y (vertical) axis.

        Returns:
            A Transform representing the composed transform.
        r   r   r+   r   r}   r   r   r   	translatew  s    zTransform.translatec                 C   s   | t || S )a  
        Produce a transform by composing the current transform with a scaling.

        .. note::
            Transforms are immutable, so this returns a new transform rather than
            mutating self.

        Args:
            x (Number): scaling ratio in the x (horizontal) axis. A value of 1
                results in no scale change in the x axis.
            y (Number): optional scaling ratio in the y (vertical) axis. A value of 1
                results in no scale change in the y axis. If this value is omitted, it
                defaults to the value provided to the `x` argument.

        Returns:
            A Transform representing the composed transform.
        )r   r   r   r   r   r   scale  s    zTransform.scalec                 C   s   | t | S )a  
        Produce a transform by composing the current transform with a rotation.

        .. note::
            Transforms are immutable, so this returns a new transform rather than
            mutating self.

        Args:
            theta (Number): the angle **in radians** by which to rotate. Positive
                values represent clockwise rotations.

        Returns:
            A Transform representing the composed transform.
        )r   r   )r+   r   r   r   r   rotate  s    zTransform.rotatec                 C   s   | t | S )a  
        Produce a transform by composing the current transform with a rotation
        **in degrees**.

        .. note::
            Transforms are immutable, so this returns a new transform rather than
            mutating self.

        Args:
            theta_d (Number): the angle **in degrees** by which to rotate. Positive
                values represent clockwise rotations.

        Returns:
            A Transform representing the composed transform.
        )r   r   )r+   r   r   r   r   rotate_d  s    zTransform.rotate_dc                 C   s   | t || S )a%  
        Produce a transform by composing the current transform with a shearing.

        .. note::
            Transforms are immutable, so this returns a new transform rather than
            mutating self.

        Args:
            x (Number): The amount to shear along the x (horizontal) axis.
            y (Number): Optional amount to shear along the y (vertical) axis. If omitted,
                this defaults to the value provided to the `x` argument.

        Returns:
            A Transform representing the composed transform.
        )r   r   r   r   r   r   shear  s    zTransform.shearc                 C   s    t | | |  t || S )a  
        Bracket the given transform in a pair of translations to make it appear about a
        point that isn't the origin.

        This is a useful shorthand for performing a transform like a rotation around the
        center point of an object that isn't centered at the origin.

        .. note::
            Transforms are immutable, so this returns a new transform rather than
            mutating self.

        Args:
            x (Number): the point along the x (horizontal) axis about which to transform.
            y (Number): the point along the y (vertical) axis about which to transform.

        Returns:
            A Transform representing the composed transform.
        r   r   r   r   r   about  s    zTransform.aboutc                 C   sF   t |trBt| j| | j| | j| | j| | j| | j| dS t	S )z
        Multiply the individual transform parameters by a scalar value.

        Args:
            other (Number): the scalar value by which to multiply the parameters

        Returns:
            A Transform with the modified parameters.
        rc   rb   r{   r   r   r   )
rJ   rQ   r   rc   rb   r{   r   r   r   r   r   r   r   r   r     s    
	zTransform.__mul__c              	   C   s   t |tr| 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  |j dS t	S )z
        Compose two transforms into a single transform.

        Args:
            other (Transform): the right-hand side transform of the infix operator.

        Returns:
            A Transform representing the composed transform.
        r   )
rJ   r   re   rc   rb   r{   r   r   r   r   r   r   r   r   r      s    
	zTransform.__matmul__c                 C   sP   t | j dt | j dt | j dt | j dt | j dt | j d|fS )z
        Render the transform to its PDF output representation.

        Args:
            last_item: the last path element this transform applies to

        Returns:
            A tuple of `(str, last_item)`. `last_item` is returned unchanged.
        rC   z cmr<   rc   rb   r{   r   r   r   )r+   	last_itemr   r   r   r     s    JzTransform.renderc                 C   sN   dt | j dt | j dt | j dt | j dt | j dt | j dS )Nztransform: [rC   z 0; z 1]r   rg   r   r   r   r   (  s    LzTransform.__str__)N)N)N)N)r.   r/   r   r0   r   r   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s@   
9	







r   zTransform.azTransform.bzTransform.czTransform.dzTransform.ezTransform.fc                       s  e Zd ZdZdZdZejjej	jej
jfZdd eD Zei ejedhejedejhejedejhejeddejhejeddejhejiZedd	 Zd
d Zdd Z fddZedd Zej  fddZedd Z!e!j  fddZ!edd Z"e"j  fddZ"edd Z#e#j  fddZ#edd Z$e$j  fddZ$edd  Z%e%j  fd!d Z%ed"d# Z&e&j  fd$d#Z&ed%d& Z'e'j  fd'd&Z'ed(d) Z(e(j  fd*d)Z(ed+d, Z)e)j  fd-d,Z)ed.d/ Z*e*j  fd0d/Z*ed1d2 Z+e+j  fd3d2Z+ed4d5 Z,e,j  fd6d5Z,ed7d8 Z-e-j  fd9d8Z-ed:d; Z.e.j  fd<d;Z.d=d> Z/e0d?d@ Z1  Z2S )Ar%   a  
    A class representing various style attributes that determine drawing appearance.

    This class uses the convention that the global Python singleton ellipsis (`...`) is
    exclusively used to represent values that are inherited from the parent style. This
    is to disambiguate the value None which is used for several values to signal an
    explicitly disabled style. An example of this is the fill/stroke color styles,
    which use None as hints to the auto paint style detection code.
    .)
paint_ruleallow_transparency
auto_closeintersection_rule
fill_colorfill_opacitystroke_colorstroke_opacity
blend_modestroke_widthstroke_cap_stylestroke_join_stylestroke_miter_limitstroke_dash_patternstroke_dash_phasec                 c   s   | ]}|t jk	r|jV  qd S rD   )r   STROKE_DASH_PATTERNr5   )rG   rz   r   r   r   rI   d  s     
 zGraphicsStyle.<genexpr>strokefillc                 C   sJ   |  }| j D ]8}t||}|| jkr8t||t|| qt||| q|S )aA  
        Merge parent and child into a single GraphicsStyle.

        The result contains the properties of the parent as overridden by any properties
        explicitly set on the child. If both the parent and the child specify to
        inherit a given property, that property will preserve the inherit value.
        )MERGE_PROPERTIESrL   INHERITsetattr)r_   parentchildnewpropcvalr   r   r   mergev  s    	


zGraphicsStyle.mergec                 C   s|   | j | _| j | _| j | _| j | _| j | _| j | _| j | _| j | _| j | _	| j | _
| j | _| j | _| j | _| j | _| j | _d S rD   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rg   r   r   r   __init__  s    zGraphicsStyle.__init__c                 C   s*   |   }| jD ]}t||t| | q|S rD   )re   r   r   rL   )r+   memocopiedr   r   r   r   __deepcopy__  s    
zGraphicsStyle.__deepcopy__c                    s4   t | j|s"t| j d| dt || d S )Nz does not have style "z" (a typo?))hasattrre   AttributeErrorr]   __setattr__)r+   r,   r5   rd   r   r   r     s
    zGraphicsStyle.__setattr__c                 C   s   | j S rD   )_allow_transparencyrg   r   r   r   r     s    z GraphicsStyle.allow_transparencyc                    s   t  d|S )Nr   )r]   r   r+   r   rd   r   r   r     s    c                 C   s   | j S )z*The paint rule to use for this path/group.)_paint_rulerg   r   r   r   r     s    zGraphicsStyle.paint_rulec                    sL   |d krt  dtj n.|| jkr4t  d| nt  dt| d S )Nr   )r]   r   r   
DONT_PAINTr   coercer   rd   r   r   r     s
    
c                 C   s   | j S )zEIf True, unclosed paths will be automatically closed before stroking.)_auto_closerg   r   r   r   r     s    zGraphicsStyle.auto_closec                    s0   |dd| j hkrtd| t d| d S )NTFz/auto_close must be a bool or self.INHERIT, not r  )r   rX   r]   r   r   rd   r   r   r     s    c                 C   s   | j S )z2The desired intersection rule for this path/group.)_intersection_rulerg   r   r   r   r     s    zGraphicsStyle.intersection_rulec                    s2   || j krt d| nt dt| d S )Nr  )r   r]   r   r   r  r   rd   r   r   r     s    
c                 C   s   | j S )z
        The desired fill color for this path/group.

        When setting this property, if the color specifies an opacity value, that will
        be used to set the fill_opacity property as well.
        )_fill_colorrg   r   r   r   r     s    zGraphicsStyle.fill_colorc                    sx   t |trt|}t |tttfrDt d| |jd k	rt|j| _	n0|d ksV|| j
krft d| nt| dd S )Nr  " doesn't look like a drawing color)rJ   rM   r   r[   rx   ry   r]   r   rc   r   r   rX   r+   colorrd   r   r   r     s    


c                 C   s   t | tjjS )z-The desired fill opacity for this path/group.)rL   r   
FILL_ALPHAr5   rg   r   r   r   r     s    zGraphicsStyle.fill_opacityc                    s,   |d | j hkrt| t tjj| d S rD   )r   r7   r]   r   r   r  r5   r   rd   r   r   r     s    c                 C   s   | j S )z
        The desired stroke color for this path/group.

        When setting this property, if the color specifies an opacity value, that will
        be used to set the fill_opacity property as well.
        )_stroke_colorrg   r   r   r   r     s    zGraphicsStyle.stroke_colorc                    s   t |trt|}t |tttfrVt d| |jd k	rB|j| _	| j
| jkrd| _
n0|d ksh|| jkrxt d| nt| dd S )Nr	  r   r  )rJ   rM   r   r[   rx   ry   r]   r   rc   r   r   r   rX   r  rd   r   r   r     s    

c                 C   s   t | tjjS )z/The desired stroke opacity for this path/group.)rL   r   STROKE_ALPHAr5   rg   r   r   r   r     s    zGraphicsStyle.stroke_opacityc                    s,   |d | j hkrt| t tjj| d S rD   )r   r7   r]   r   r   r
  r5   r   rd   r   r   r   $  s    c                 C   s   t | tjjS )z+The desired blend mode for this path/group.)rL   r   
BLEND_MODEr5   rg   r   r   r   r   +  s    zGraphicsStyle.blend_modec                    s<   || j krt tjj| nt tjjt|j d S rD   )r   r]   r   r   r  r5   r	   r  r+   r5   rd   r   r   r   0  s    
 
c                 C   s   t | tjjS )z-The desired stroke width for this path/group.)rL   r   STROKE_WIDTHr5   rg   r   r   r   r   9  s    zGraphicsStyle.stroke_widthc                    sH   t |tttjtd t| jfs2tdt| t 	t
jj| d S )Nz#stroke_width must be a number, not )rJ   r   floatdecimalDecimaltyper   rX   r]   r   r   r  r5   )r+   widthrd   r   r   r   >  s    c                 C   s   t | tjjS )z1The desired stroke cap style for this path/group.)rL   r   STROKE_CAP_STYLEr5   rg   r   r   r   r   H  s    zGraphicsStyle.stroke_cap_stylec                    s:   || j krt tjj| nt tjjt| d S rD   )r   r]   r   r   r  r5   r   r  r  rd   r   r   r   M  s    
 c                 C   s   t | tjjS )z2The desired stroke join style for this path/group.)rL   r   STROKE_JOIN_STYLEr5   rg   r   r   r   r   V  s    zGraphicsStyle.stroke_join_stylec                    s:   || j krt tjj| nt tjjt| d S rD   )r   r]   r   r   r  r5   r   r  r  rd   r   r   r   [  s    
c                 C   s   t | tjjS )z3The desired stroke miter limit for this path/group.)rL   r   STROKE_MITER_LIMITr5   rg   r   r   r   r   e  s    z GraphicsStyle.stroke_miter_limitc                    s:   || j kst|tr(t tjj| nt| dd S )Nz is not a number)	r   rJ   rQ   r]   r   r   r  r5   rX   r  rd   r   r   r   j  s    c                 C   s   | j S )z4The desired stroke dash pattern for this path/group.)_stroke_dash_patternrg   r   r   r   r   q  s    z!GraphicsStyle.stroke_dash_patternc                    s   |d krd}n|| j kr|}nvt|tr0|f}ndz6g }|D ](}t|tsXtd| d|| q:W n& tk
r   td| dd Y nX |}t d| d S )Nr   zstroke_dash_pattern z sequence has non-numeric valuez( must be a number or sequence of numbersr  )r   rJ   rQ   rX   rW   r]   r   )r+   r5   resultaccumr   rd   r   r   r   v  s,    




c                 C   s   | j S )zAThe desired stroke dash pattern phase offset for this path/group.)_stroke_dash_phaserg   r   r   r   r     s    zGraphicsStyle.stroke_dash_phasec                    s4   || j kst|tr"t d|S t| dd S )Nr  z( isn't a number or GraphicsStyle.INHERIT)r   rJ   rQ   r]   r   rX   r  rd   r   r   r     s    c                 C   s   t  }| jD ],}t| || j}|| jk	r|dk	r|||< q| jr`| j| jk	r`| j| jg|tjj< | j	dkr| j
D ]}||krp||= qp|rtd}td||< |j|dd t|S dS )z
        Convert this style object to a PDF dictionary with appropriate style keys.

        Only explicitly specified values are emitted.
        NFTypeZ	ExtGState)last)r   PDF_STYLE_KEYSrL   r   r   r   r   r   r5   r   TRANSPARENCY_KEYSr   move_to_endrE   )r+   r  rZ   r5   	type_namer   r   r   r(     s&    



zGraphicsStyle.serializec                 C   s   | j tjkrt }| jdk	r0| jdk	r0|d | jdk	r^|d | jdk	sRt	|| j z| j
t| }W q tk
r   tj}Y qX n| j | jkrtj}n| j }|S )z
        Resolve `PathPaintRule.AUTO` to a real paint rule based on this style.

        Returns:
            the resolved `PathPaintRule`.
        Nr   r   )r   r   AUTOsetr   r   addr   r   AssertionError_PAINT_RULE_LOOKUP	frozensetr)   STROKE_FILL_NONZEROr   )r+   ZwantZruler   r   r   resolve_paint_rule  s     


z GraphicsStyle.resolve_paint_rule)3r.   r/   r   r0   r   r   r   r  r5   r
  r  r  r  r%  r   r   ZSTROKEr   NONZEROZFILL_NONZEROZEVENODDZFILL_EVENODDr&  ZSTROKE_FILL_EVENODDr$  r   r   r   r   r   rv   r   setterr   r   r   r   r   r   r   r   r   r   r   r   r   r   r(   r   r'  rw   r   r   rd   r   r%   9  s   
    








	

	


	

	


*r%   c                 C   s   |    dS )Nz mr   ptr   r   r   _render_move  s    r-  c                 C   s   |    dS )Nz lr*  r+  r   r   r   _render_line  s    r.  c                 C   s"   |    d|   d|   dS )NrC   z cr*  )ctrl1ctrl2endr   r   r   _render_curve  s    r2  c                   @   s>   e Zd ZU dZeed< edd Zedd Z	edd Z
d	S )
Movez
    A path move element.

    If a path has been created but not yet painted, this will create a new subpath.

    See: `PaintedPath.move_to`
    r,  c                 C   s   | j S z#The end point of this path element.r+  rg   r   r   r   	end_point  s    zMove.end_pointc                 C   s   t | j| | jfS a  
        Render this path element to its PDF representation.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command

        Returns:
            a tuple of `(str, new_last_item)`, where `new_last_item` is `self`
        )r-  r,  r+   gsd_registryr'   r   initial_pointr   r   r   r     s    zMove.renderc           	      C   s2   |  ||||\}}}|t| d  |||fS )a0  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `Move.render`.
        r   r   writerM   	r+   r8  r'   r   r9  debug_streampfxrenderedZresolvedr   r   r   render_debug  s       
zMove.render_debugNr.   r/   r   r0   r   r   rv   r5  r   r   r@  r   r   r   r   r3    s   


r3  c                   @   s2   e Zd ZU dZeed< edd Zedd ZdS )RelativeMovez
    A path move element with an end point relative to the end of the previous path
    element.

    If a path has been created but not yet painted, this will create a new subpath.

    See: `PaintedPath.move_relative`
    r,  c                 C   s   |j | j }t|t||fS )a  
        Render this path element to its PDF representation.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command

        Returns:
            a tuple of `(str, new_last_item)`, where `new_last_item` is the resolved
            `Move`
        )r5  r,  r-  r3  r+   r8  r'   r   r9  pointr   r   r   r   G  s    zRelativeMove.renderc           	      C   s6   |  ||||\}}}||  d| d |||fS )a8  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `RelativeMove.render`.
         resolved to r   r   r;  r<  r   r   r   r@  [  s       
zRelativeMove.render_debugN	r.   r/   r   r0   r   r   r   r   r@  r   r   r   r   rB  :  s   
	
rB  c                   @   s>   e Zd ZU dZeed< edd Zedd Z	edd Z
d	S )
Linez
    A path line element.

    This draws a straight line from the end point of the previous path element to the
    point specified by `pt`.

    See: `PaintedPath.line_to`
    r,  c                 C   s   | j S r4  r+  rg   r   r   r   r5    s    zLine.end_pointc                 C   s   t | j| |fS r6  )r.  r,  r7  r   r   r   r     s    zLine.renderc           	      C   s2   |  ||||\}}}|t| d  |||fS )a0  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `Line.render`.
        r   r:  r<  r   r   r   r@    s       
zLine.render_debugNrA  r   r   r   r   rH  {  s   
	

rH  c                   @   s2   e Zd ZU dZeed< edd Zedd ZdS )RelativeLinead  
    A path line element with an endpoint relative to the end of the previous element.

    This draws a straight line from the end point of the previous path element to the
    point specified by `last_item.end_point + pt`. The absolute coordinates of the end
    point are resolved during the rendering process.

    See: `PaintedPath.line_relative`
    r,  c                 C   s   |j | j }t|t||fS )  
        Render this path element to its PDF representation.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command

        Returns:
            a tuple of `(str, new_last_item)`, where `new_last_item` is the resolved
            `Line`.
        )r5  r,  r.  rH  rC  r   r   r   r     s    zRelativeLine.renderc           	      C   s6   |  ||||\}}}||  d| d |||fS )a8  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `RelativeLine.render`.
        rE  r   rF  r<  r   r   r   r@    s       
zRelativeLine.render_debugNrG  r   r   r   r   rI    s   


rI  c                   @   s2   e Zd ZU dZeed< edd Zedd ZdS )HorizontalLinez
    A path line element that takes its ordinate from the end of the previous element.

    See: `PaintedPath.horizontal_line_to`
    r   c                 C   s$   t | j|jjd}t|t||fS rJ  r   )r   r   r5  r}   r.  rH  r+   r8  r'   r   r9  r5  r   r   r   r     s    zHorizontalLine.renderc           	      C   s6   |  ||||\}}}||  d| d |||fS )a:  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `HorizontalLine.render`.
        rE  r   rF  r<  r   r   r   r@    s       
zHorizontalLine.render_debugN	r.   r/   r   r0   r   r   r   r   r@  r   r   r   r   rK    s   

rK  c                   @   s2   e Zd ZU dZeed< edd Zedd ZdS )RelativeHorizontalLinez
    A path line element that takes its ordinate from the end of the previous element and
    computes its abscissa offset from the end of that element.

    See: `PaintedPath.horizontal_line_relative`
    r   c                 C   s,   t |jj| j |jjd}t|t||fS rL  r   r5  r   r}   r.  rH  rM  r   r   r   r   M  s    zRelativeHorizontalLine.renderc           	      C   s6   |  ||||\}}}||  d| d |||fS )aB  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `RelativeHorizontalLine.render`.
        rE  r   rF  r<  r   r   r   r@  a  s       
z#RelativeHorizontalLine.render_debugNrN  r   r   r   r   rO  ?  s   

rO  c                   @   s2   e Zd ZU dZeed< edd Zedd ZdS )VerticalLinez
    A path line element that takes its abscissa from the end of the previous element.

    See: `PaintedPath.vertical_line_to`
    r}   c                 C   s$   t |jj| jd}t|t||fS rL  rP  rM  r   r   r   r     s    zVerticalLine.renderc           	      C   s6   |  ||||\}}}||  d| d |||fS )a8  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `VerticalLine.render`.
        rE  r   rF  r<  r   r   r   r@    s       
zVerticalLine.render_debugNrN  r   r   r   r   rQ    s   

rQ  c                   @   s2   e Zd ZU dZeed< edd Zedd ZdS )RelativeVerticalLinez
    A path line element that takes its abscissa from the end of the previous element and
    computes its ordinate offset from the end of that element.

    See: `PaintedPath.vertical_line_relative`
    r}   c                 C   s,   t |jj|jj| j d}t|t||fS rL  rP  rM  r   r   r   r     s    zRelativeVerticalLine.renderc           	      C   s6   |  ||||\}}}||  d| d |||fS )a@  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `RelativeVerticalLine.render`.
        rE  r   rF  r<  r   r   r   r@    s       
z!RelativeVerticalLine.render_debugNrN  r   r   r   r   rR    s   

rR  c                   @   sN   e Zd ZU dZeed< eed< eed< edd Zedd Z	ed	d
 Z
dS )BezierCurveu   
    A cubic Bézier curve path element.

    This draws a Bézier curve parameterized by the end point of the previous path
    element, two off-curve control points, and an end point.

    See: `PaintedPath.curve_to`
    c1c2r1  c                 C   s   | j S r4  r1  rg   r   r   r   r5    s    zBezierCurve.end_pointc                 C   s   t | j| j| j| |fS r6  )r2  rT  rU  r1  r7  r   r   r   r     s    zBezierCurve.renderc           	      C   s2   |  ||||\}}}|t| d  |||fS )a7  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `BezierCurve.render`.
        r   r:  r<  r   r   r   r@  )  s       
zBezierCurve.render_debugNrA  r   r   r   r   rS    s   
	

rS  c                   @   sB   e Zd ZU dZeed< eed< eed< edd Zedd Zd	S )
RelativeBezierCurveu   
    A cubic Bézier curve path element whose points are specified relative to the end
    point of the previous path element.

    See: `PaintedPath.curve_relative`
    rT  rU  r1  c           	      C   s@   |j }|| j }|| j }|| j }t|||t|||d|fS )a
  
        Render this path element to its PDF representation.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command

        Returns:
            a tuple of `(str, new_last_item)`, where `new_last_item` is the resolved
            `BezierCurve`.
        )rT  rU  r1  )r5  rT  rU  r1  r2  rS  )	r+   r8  r'   r   r9  
last_pointrT  rU  r1  r   r   r   r   \  s    



zRelativeBezierCurve.renderc           	      C   s6   |  ||||\}}}||  d| d |||fS )a?  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `RelativeBezierCurve.render`.
        rE  r   rF  r<  r   r   r   r@  y  s       
z RelativeBezierCurve.render_debugNrG  r   r   r   r   rW  I  s   

rW  c                   @   sN   e Zd ZU dZeed< eed< edd Zdd Ze	dd	 Z
e	d
d ZdS )QuadraticBezierCurveu   
    A quadratic Bézier curve path element.

    This draws a Bézier curve parameterized by the end point of the previous path
    element, one off-curve control point, and an end point.

    See: `PaintedPath.quadratic_curve_to`
    ctrlr1  c                 C   s   | j S r4  rV  rg   r   r   r   r5    s    zQuadraticBezierCurve.end_pointc                 C   s   | j }| j}t|jd|j|j  d  |jd|j|j  d  d}t|jd|j|j  d  |jd|j|j  d  d}t|||S )Nr   r   r   )rZ  r1  r   r   r}   rS  )r+   Zstart_pointrZ  r1  r/  r0  r   r   r   to_cubic_curve  s    z#QuadraticBezierCurve.to_cubic_curvec                 C   s"   |  |j||||d | |fS )a  
        Render this path element to its PDF representation.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command

        Returns:
            a tuple of `(str, new_last_item)`, where `new_last_item` is `self`.
        r   )r[  r5  r   r7  r   r   r   r     s       zQuadraticBezierCurve.renderc           	      C   s>   |  ||||\}}}||  d| |j d |||fS )a@  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `QuadraticBezierCurve.render`.
        rE  r   r   r;  r[  r5  r<  r   r   r   r@    s       
z!QuadraticBezierCurve.render_debugN)r.   r/   r   r0   r   r   rv   r5  r[  r   r   r@  r   r   r   r   rY    s   
	

rY  c                   @   s:   e Zd ZU dZeed< eed< edd Zedd ZdS )	RelativeQuadraticBezierCurveu   
    A quadratic Bézier curve path element whose points are specified relative to the end
    point of the previous path element.

    See: `PaintedPath.quadratic_curve_relative`
    rZ  r1  c           	      C   s6   |j }|| j }|| j }t||d}|||||S )a  
        Render this path element to its PDF representation.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command

        Returns:
            a tuple of `(str, new_last_item)`, where `new_last_item` is the resolved
            `QuadraticBezierCurve`.
        )rZ  r1  )r5  rZ  r1  rY  r   )	r+   r8  r'   r   r9  rX  rZ  r1  absoluter   r   r   r   	  s
    

z#RelativeQuadraticBezierCurve.renderc           	   	   C   sD   |  ||||\}}}||  d| d||j d |||fS )aH  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `RelativeQuadraticBezierCurve.render`.
        rE  z	 then to r   r\  r<  r   r   r   r@  	  s       
z)RelativeQuadraticBezierCurve.render_debugNrG  r   r   r   r   r]    s   

r]  c                   @   sj   e Zd ZU dZeed< eed< eed< eed< eed< ee	dd Z
d	d
 Ze	dd Ze	dd ZdS )Arcz
    An elliptical arc path element.

    The arc is drawn from the end of the current path element to its specified end point
    using a number of parameters to determine how it is constructed.

    See: `PaintedPath.arc_to`
    radiir   largesweepr1  c                 c   s   t | } | }tjd }t| | }| | }t|}t|}dt|d  }td|}t|||  |||  }	t||}
t|D ]6}| | }t	
|}|| |	| |
| fV  ||8 }qdS )uq  
        A generator that subdivides a swept angle into segments no larger than a quarter
        turn.

        Any sweep that is larger than a quarter turn is subdivided into as many equally
        sized segments as necessary to prevent any individual segment from being larger
        than a quarter turn.

        This is used for approximating a circular curve segment using cubic Bézier
        curves. This computes the parameters used for the Bézier approximation up
        front, as well as the transform necessary to place the segment in the correct
        position.

        Args:
            sweep_angle (Number): the angle to subdivide.

        Yields:
            A tuple of (ctrl1, ctrl2, end) representing the control and end points of
            the cubic Bézier curve approximating the segment as a unit circle centered
            at the origin.
        r   gUUUUUU?r   r   N)absr   piceilr   r   tanr   r   r   r   )Zsweep_angleZ
sweep_leftZquarterturnchunksZsweep_segmentZcos_tZsin_tkappar/  r0  r1  _offset	transformr   r   r   subdivde_sweepT	  s     





zArc.subdivde_sweepc                 C   s\  | j }t| j }t| j}|j| j d | }|j|j d |j|j d  }|dkr|t|d |j |d |j d}| j| j	k| j| j	k }|j|j d }|j|j d }	|j|j d }
|t
t||	 |
 d|	|
   t|j|j |j |j |j |j d }|| |j| j d  }t|j|j |j |j|j |j d}t|j |j |j |j |j |j d}tdd|}||}| j	dkr|dkr|t
j8 }n | j	dkr|dk r|t
j7 }|dk|dk  }tjd|d||j|j| j|j|j}g }| |D ]*\}}}|t|| || ||  q,|S )	z
        Approximate this arc with a sequence of `BezierCurve`.

        Args:
            last_item: the previous path element (used for its end point)

        Returns:
            a list of `BezierCurve`.
        r   r   r   r   r   r   FT)r`  r   r   r5  r1  r   r}   r   ra  rb  r   sqrtr   r   taur   r   r   r   rl  rW   rS  )r+   r   r`  reverseZforwardprimeZlam_dar   Zrxry2Zrxpy2Zrypx2ZcenterprimecenterZarcstartZarcendr   Z
deltathetaZ
sweep_signZfinal_tfcurvesr/  r0  r1  r   r   r   _approximate_arc	  sl    
  	

  zArc._approximate_arcc                    sP   |  |}|sd|fS d fddt|f|dd |D |d fS )  
        Render this path element to its PDF representation.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command

        Returns:
            a tuple of `(str, new_last_item)`, where `new_last_item` is a resolved
            `BezierCurve`.
        r   rC   c                 3   s&   | ]\}}|  |d  V  qdS r   Nr*  rG   prevcurver8  r9  r'   r   r   rI   	  s   zArc.render.<locals>.<genexpr>Nrf   )rs  rT   zip)r+   r8  r'   r   r9  rr  r   ry  r   r   	  s    
z
Arc.renderc           
         s   |  |}||  d |s4||d  d|fS |g}|dd D ]$}	||	 ||d|	 d  qF||d|d  d  d	 fd
dt||D |d fS )a/  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `Arc.render`.
         resolved to:
    └─ nothing
r   Nrf       ├─ r       └─ rC   c                 3   s&   | ]\}}|  |d  V  qdS ru  r*  rv  ry  r   r   rI   
  s   z#Arc.render_debug.<locals>.<genexpr>)rs  r;  rW   rT   rz  )
r+   r8  r'   r   r9  r=  r>  rr  previousrx  r   ry  r   r@  	  s     

zArc.render_debugN)r.   r/   r   r0   r   r   r   rP   staticmethodr   rl  rs  r   r@  r   r   r   r   r_  =	  s   
	-I
r_  c                   @   sR   e Zd ZU dZeed< eed< eed< eed< eed< edd Z	ed	d
 Z
dS )RelativeArcz
    An elliptical arc path element.

    The arc is drawn from the end of the current path element to its specified end point
    using a number of parameters to determine how it is constructed.

    See: `PaintedPath.arc_relative`
    r`  r   ra  rb  r1  c                 C   s,   t | j| j| j| j|j| j ||||S )rt  )r_  r`  r   ra  rb  r5  r1  r   r7  r   r   r   r   /
  s    
   zRelativeArc.renderc                 C   s@   | |  d t| j| j| j| j|j| j ||||||S )a7  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `RelativeArc.render`.
        rE  )	r;  r_  r`  r   ra  rb  r5  r1  r@  r+   r8  r'   r   r9  r=  r>  r   r   r   r@  G
  s    
     zRelativeArc.render_debugN)r.   r/   r   r0   r   r   r   rP   r   r   r@  r   r   r   r   r  
  s   
	
r  c                   @   s:   e Zd ZU dZeed< eed< edd Zedd ZdS )		RectanglezA pdf primitive rectangle.orgsizec                 C   s(   | j   d| j  dt| j |fS )a  
        Render this path element to its PDF representation.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command

        Returns:
            a tuple of `(str, new_last_item)`, where `new_last_item` is a `Line` back to
            the rectangle's origin.
        rC   z re)r  r   r  rH  r7  r   r   r   r   r
  s    zRectangle.renderc           	      C   s6   |  ||||\}}}||  d| d |||fS )a5  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `Rectangle.render`.
        rE  r   rF  r<  r   r   r   r@  
  s       
zRectangle.render_debugNrG  r   r   r   r   r  j
  s   

r  c                   @   sJ   e Zd ZU dZeed< eed< eed< dd Zedd Zed	d
 Z	dS )RoundedRectanglezM
    A rectangle with rounded corners.

    See: `PaintedPath.rectangle`
    r  r  corner_radiic                 C   sj  g }| j jdkr | j jdkr nF| j jdks8| j jdkrn|t| j |t| j| j   |t  n| jjdks| jjdkr|t	| j| j  n| j\}}| j \}}| j\}}| j jdk| j jdk  }| j jdk| j jdk  }	t
|t
|kr| j j}t
|t
|kr | j j}|t
| }|	t
| }t||}
|tt|| | |tt|| | | |t|
dddt|| ||  |tt|| || |  |t|
dddt|| | ||  |tt|| ||  |t|
dddt||| |  |tt|||  |t|
dddt|| | |t  |S Nr   FT)r  r   r}   rW   r3  r  rH  Closer  r  rc  r   r_  )r+   rV   r   r}   whrxryZ
sign_widthZsign_heightarc_radr   r   r   
_decompose
  s@    



$ ($ zRoundedRectangle._decomposec           	      C   sX   |   }|sd|fS g }|D ]$}|||||\}}}|| qd|t| j|fS )a  
        Render this path element to its PDF representation.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command

        Returns:
            a tuple of `(str, new_last_item)`, where `new_last_item` is a resolved
            `Line`.
        r   rC   )r  r   rW   rT   rH  r  	r+   r8  r'   r   r9  
componentsrender_listr   r?  r   r   r   r   
  s       
zRoundedRectangle.renderc                 C   s   |   }||  d |s2||d  d|fS g }|dd D ]:}	|	||||\}
}}||d|	 d  ||
 qB|d ||||\}
}}||d|d  d  ||
 d	|t| j|fS )
a<  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `RoundedRectangle.render`.
        r{  r|  r   Nrf   r}  r   r~  rC   )r  r;  r   rW   rT   rH  r  r+   r8  r'   r   r9  r=  r>  r  r  r   r?  r   r   r   r@  
  s0       
   

zRoundedRectangle.render_debugN
r.   r/   r   r0   r   r   r  r   r   r@  r   r   r   r   r  
  s   
)
r  c                   @   sB   e Zd ZU dZeed< eed< dd Zedd Zedd	 Z	d
S )Ellipsez5
    An ellipse.

    See: `PaintedPath.ellipse`
    r`  rq  c                 C   s   g }t | jj}t | jj}| j\}}t||}|dkr|dkr|tt|| | |t|dddt|||  |t|dddt|| | |t|dddt|||  |t|dddt|| | |t	  |S r  )
rc  r`  r   r}   rq  r   rW   r3  r_  r  )r+   rV   r  r  cxcyr  r   r   r   r  :  s    

    zEllipse._decomposec           	      C   sX   |   }|sd|fS g }|D ]$}|||||\}}}|| qd|t| j|fS )a  
        Render this path element to its PDF representation.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command

        Returns:
            a tuple of `(str, new_last_item)`, where `new_last_item` is a resolved
            `Move` to the center of the ellipse.
        r   rC   )r  r   rW   rT   r3  rq  r  r   r   r   r   O  s       
zEllipse.renderc                 C   s   |   }||  d |s2||d  d|fS g }|dd D ]:}	|	||||\}
}}||d|	 d  ||
 qB|d ||||\}
}}||d|d  d  ||
 d	|t| j|fS )
a3  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `Ellipse.render`.
        r{  r|  r   Nrf   r}  r   r~  rC   )r  r;  r   rW   rT   r3  rq  r  r   r   r   r@  m  s0       
   

zEllipse.render_debugNr  r   r   r   r   r  .  s   

r  c                   @   s(   e Zd ZdZedd Zedd ZdS )ImplicitClosezw
    A path close element that is conditionally rendered depending on the value of
    `GraphicsStyle.auto_close`.
    c                 C   s   |j rd||fS d||fS )  
        Render this path element to its PDF representation.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command

        Returns:
            a tuple of `(str, new_last_item)`, where `new_last_item` is whatever the old
            last_item was.
        r  r   )r   r7  r   r   r   r     s    
zImplicitClose.renderc           	      C   s6   |  ||||\}}}||  d| d |||fS )a9  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `ImplicitClose.render`.
        rE  r   rF  r<  r   r   r   r@    s       
zImplicitClose.render_debugNr.   r/   r   r0   r   r   r@  r   r   r   r   r    s
   
r  c                   @   s(   e Zd ZdZedd Zedd ZdS )r  z
    A path close element.

    Instructs the renderer to draw a straight line from the end of the last path element
    to the start of the current path.

    See: `PaintedPath.close`
    c                 C   s   dt ||fS )r  r  )r3  r7  r   r   r   r     s    zClose.renderc           	      C   s2   |  ||||\}}}|t| d  |||fS )a1  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `Close.render`.
        r   r:  r<  r   r   r   r@    s       
zClose.render_debugNr  r   r   r   r   r    s
   

r  c                   @   s>   e Zd ZdZdd ZdddZedd Zd	d
 Zdd Z	dS )DrawingContextz
    Base context for a drawing in a PDF

    This context is not stylable and is mainly responsible for transforming path
    drawing coordinates into user coordinates (i.e. it ensures that the output drawing
    is correctly scaled).
    c                 C   s
   g | _ d S rD   )	_subitemsrg   r   r   r   r      s    zDrawingContext.__init__Tc                 C   s:   t |ttfst| d|r*t|}| j| dS )a  
        Append an item to this drawing context

        Args:
            item (GraphicsContext, PaintedPath): the item to be appended.
            _copy (bool): if true (the default), the item will be copied before being
                appended. This prevents modifications to a referenced object from
                "retroactively" altering its style/shape and should be disabled with
                caution.
        z# doesn't belong in a DrawingContextN)rJ   GraphicsContextPaintedPathrX   copydeepcopyr  rW   r+   r   _copyr   r   r   add_item#  s
    
zDrawingContext.add_itemc                 C   s\   d| _ tj| _tj| _t|}tj	dddj
d|d d||\}}d|g}|| |fS )NTr   rf   r   r   r   q)r   r   r   r   r   r(  r   r3  r   r   r   r   r   )r'   first_pointr   heightr   r  r   r   r   _setup_render_prereqs7  s     z$DrawingContext._setup_render_prereqsc                 C   s   | j s
dS | ||||\}}}| j D ](}	|	||||\}
}}|
r&||
 q&t|dkr`dS ||}|dk	r|dt| d |dt|jdt	|j
 d  |d d|S )	a  
        Render the drawing context to PDF format.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the parent document's graphics
                state registry.
            first_point (Point): the starting point to use if the first path element is
                a relative element.
            scale (Number): the scale factor to convert from PDF pt units into the
                document's semantic units (e.g. mm or in).
            height (Number): the page height. This is used to remap the coordinates to
                be from the top-left corner of the page (matching fpdf's behavior)
                instead of the PDF native behavior of bottom-left.
            starting_style (GraphicsStyle): the base style for this drawing context,
                derived from the document's current style defaults.

        Returns:
            A string composed of the PDF representation of all the paths and groups in
            this context (an empty string is returned if there are no paths or groups)
        r   r   N gsr   rC    dQ)r  r  r   rW   r*   r-   insertrE   r   r<   r   rT   )r+   r8  r  r   r  starting_styler  r'   r   r   r?  style_dict_namer   r   r   r   I  s<       

   


zDrawingContext.renderc                 C   s  |  ||||\}}}	|d | jdd D ]2}
|d |
|||	|d\}}	|r.|| q.| jr|d | jd |||	||d\}}	}|r|| t|dkrd	S ||}|dk	r|dt| d
 |dt|j	dt
|j d  |d d|S d	S )a  
        Render the drawing context to PDF format.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the parent document's graphics
                state registry.
            first_point (Point): the starting point to use if the first path element is
                a relative element.
            scale (Number): the scale factor to convert from PDF pt units into the
                document's semantic units (e.g. mm or in).
            height (Number): the page height. This is used to remap the coordinates to
                be from the top-left corner of the page (matching fpdf's behavior)
                instead of the PDF native behavior of bottom-left.
            starting_style (GraphicsStyle): the base style for this drawing context,
                derived from the document's current style defaults.
            debug_stream (TextIO): a text stream to which a debug representation of the
                drawing structure will be written.

        Returns:
            A string composed of the PDF representation of all the paths and groups in
            this context (an empty string is returned if there are no paths or groups)
        zROOT
Nrf   r}      │  r~      r   r   r  r   rC   r  r  )r  r;  r  r@  rW   r*   r-   r  rE   r   r<   r   rT   )r+   r8  r  r   r  r  r=  r  r'   r   r   r?  r  r   r   r   r@  ~  sX       


    

     




zDrawingContext.render_debugN)T)
r.   r/   r   r0   r   r  r  r  r   r@  r   r   r   r   r    s   

5r  c                   @   sn  e Zd ZdZdIddZdd Zedd Zed	d
 Zej	dd
 Zedd Z
e
j	dd Z
edd Zej	dd Zedd Zej	dd ZedJddZedd ZdKddZdd ZdLddZd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dMdEdFZ%dGdH Z&dDS )Nr  ab  
    A path to be drawn by the PDF renderer.

    A painted path is defined by a style and an arbitrary sequence of path elements,
    which include the primitive path elements (`Move`, `Line`, `BezierCurve`, ...) as
    well as arbitrarily nested `GraphicsContext` containing their own sequence of
    primitive path elements and `GraphicsContext`.
    r   c                 C   s2   t  | _| j| _d| _| j| _tt||| _d S )NT)r  _root_graphics_context_graphics_context_closed_close_contextr3  r   _starter_mover   r   r   r   r     s
    zPaintedPath.__init__c                 C   sP   | j | jk	rtd|  d|  }t| j||_|j|_ | j|_|j |_|S )Nzcannot copy path z while it is being modified)r  r  RuntimeErrorre   r  r  r  r  r+   r   r   r   r   r   r     s    zPaintedPath.__deepcopy__c                 C   s   | j jS )z9The `GraphicsStyle` applied to all elements of this path.)r  r'   rg   r   r   r   r'     s    zPaintedPath.stylec                 C   s   | j jS )zAThe `Transform` that applies to all of the elements of this path.r  rk  rg   r   r   r   rk    s    zPaintedPath.transformc                 C   s   || j _d S rD   r  r+   tfr   r   r   rk    s    c                 C   s   | j jS )zDIf true, the path should automatically close itself before painting.r'   r   rg   r   r   r   r     s    zPaintedPath.auto_closec                 C   s   || j _d S rD   r  )r+   Zshouldr   r   r   r     s    c                 C   s   | j jS )zCManually specify the `PathPaintRule` to use for rendering the path.r'   r   rg   r   r   r   r     s    zPaintedPath.paint_rulec                 C   s   || j _d S rD   r  )r+   r'   r   r   r   r     s    c                 C   s   | j jS )z$Set the clipping path for this path.r  clipping_pathrg   r   r   r   r    s    zPaintedPath.clipping_pathc                 C   s   || j _d S rD   r  r+   Znew_clipathr   r   r   r    s    Tc                 c   s8   | j }t }|| _ z|V  |r(|| W 5 || _ X d S rD   )r  r  r  )r+   Z_attachZold_graphics_contextZnew_graphics_contextr   r   r   _new_graphics_context  s    z!PaintedPath._new_graphics_contextc              	   c   s$   |   }||_| V  W 5 Q R X dS )zY
        Apply the provided `Transform` to all points added within this context.
        N)r  rk  )r+   rk  Zctxtr   r   r   transform_group  s    
zPaintedPath.transform_groupc                 C   sD   | j dk	r0d| _| jj| j dd | j| _d| _ | jj||d dS )a  
        Add the given element as a path item of this path.

        Args:
            item: the item to add to this path.
            _copy (bool): if true (the default), the item will be copied before being
                appended. This prevents modifications to a referenced object from
                "retroactively" altering its style/shape and should be disabled with
                caution.
        NFr  )r  r  r  r  r  r  r   r   r   add_path_element!  s    
zPaintedPath.add_path_elementc                 C   s   | j   d S rD   )r  remove_last_itemrg   r   r   r   remove_last_path_element4  s    z$PaintedPath.remove_last_path_elementc                 C   sF   |    | jtt||t||t||dd d| _| || | S )a  
        Append a rectangle as a closed subpath to the current path.

        If the width or the height are 0, the rectangle will be collapsed to a line
        (unless they're both 0, in which case it's collapsed to nothing).

        Args:
            x (Number): the abscissa of the starting corner of the rectangle.
            y (Number): the ordinate of the starting corner of the rectangle.
            w (Number): the width of the rectangle (if 0, the rectangle will be
                rendered as a vertical line).
            h (Number): the height of the rectangle (if 0, the rectangle will be
                rendered as a horizontal line).
            rx (Number): the x-radius of the rectangle rounded corner (if 0 the corners
                will not be rounded).
            ry (Number): the y-radius of the rectangle rounded corner (if 0 the corners
                will not be rounded).

        Returns:
            The path, to allow chaining method calls.
        Fr  T)_insert_implicit_close_if_openr  r  r   r  move_to)r+   r   r}   r  r  r  r  r   r   r   	rectangle7  s     zPaintedPath.rectanglec                 C   s   |  ||||S )a[  
        Append a circle as a closed subpath to the current path.

        Args:
            cx (Number): the abscissa of the circle's center point.
            cy (Number): the ordinate of the circle's center point.
            r (Number): the radius of the circle.

        Returns:
            The path, to allow chaining method calls.
        )ellipse)r+   r  r  r`   r   r   r   circleW  s    zPaintedPath.circlec                 C   s>   |    | jtt||t||dd d| _| || | S )a  
        Append an ellipse as a closed subpath to the current path.

        Args:
            cx (Number): the abscissa of the ellipse's center point.
            cy (Number): the ordinate of the ellipse's center point.
            rx (Number): the x-radius of the ellipse.
            ry (Number): the y-radius of the ellipse.

        Returns:
            The path, to allow chaining method calls.
        Fr  T)r  r  r  r   r  r  )r+   r  r  r  r  r   r   r   r  e  s
     zPaintedPath.ellipsec                 C   s   |    tt||| _| S )a  
        Start a new subpath or move the path starting point.

        If no path elements have been added yet, this will change the path starting
        point. If path elements have been added, this will insert an implicit close in
        order to start a new subpath.

        Args:
            x (Number): abscissa of the (sub)path starting point.
            y (Number): ordinate of the (sub)path starting point.

        Returns:
            The path, to allow chaining method calls.
        )r  r3  r   r  r   r   r   r   r  y  s    zPaintedPath.move_toc                 C   sF   |    | jdk	r2d| _| jj| jdd | j| _tt||| _| S )a  
        Start a new subpath or move the path start point relative to the previous point.

        If no path elements have been added yet, this will change the path starting
        point. If path elements have been added, this will insert an implicit close in
        order to start a new subpath.

        This will overwrite an absolute move_to as long as no non-move path items have
        been appended. The relative position is resolved from the previous item when
        the path is being rendered, or from 0, 0 if it is the first item.

        Args:
            x (Number): abscissa of the (sub)path starting point relative to the.
            y (Number): ordinate of the (sub)path starting point relative to the.
        NFr  )r  r  r  r  r  r  rB  r   r   r   r   r   move_relative  s    
zPaintedPath.move_relativec                 C   s   | j tt||dd | S )z
        Append a straight line to this path.

        Args:
            x (Number): abscissa the line's end point.
            y (Number): ordinate of the line's end point.

        Returns:
            The path, to allow chaining method calls.
        Fr  )r  rH  r   r   r   r   r   line_to  s    zPaintedPath.line_toc                 C   s   | j tt||dd | S )a  
        Append a straight line whose end is computed as an offset from the end of the
        previous path element.

        Args:
            x (Number): abscissa the line's end point relative to the end point of the
                previous path element.
            y (Number): ordinate of the line's end point relative to the end point of
                the previous path element.

        Returns:
            The path, to allow chaining method calls.
        Fr  )r  rI  r   )r+   dxdyr   r   r   line_relative  s    zPaintedPath.line_relativec                 C   s   | j t|dd | S )a.  
        Append a straight horizontal line to the given abscissa. The ordinate is
        retrieved from the end point of the previous path element.

        Args:
            x (Number): abscissa of the line's end point.

        Returns:
            The path, to allow chaining method calls.
        Fr  )r  rK  )r+   r   r   r   r   horizontal_line_to  s    zPaintedPath.horizontal_line_toc                 C   s   | j t|dd | S )a  
        Append a straight horizontal line to the given offset from the previous path
        element. The ordinate is retrieved from the end point of the previous path
        element.

        Args:
            x (Number): abscissa of the line's end point relative to the end point of
                the previous path element.

        Returns:
            The path, to allow chaining method calls.
        Fr  )r  rO  )r+   r  r   r   r   horizontal_line_relative  s    z$PaintedPath.horizontal_line_relativec                 C   s   | j t|dd | S )a,  
        Append a straight vertical line to the given ordinate. The abscissa is
        retrieved from the end point of the previous path element.

        Args:
            y (Number): ordinate of the line's end point.

        Returns:
            The path, to allow chaining method calls.
        Fr  )r  rQ  )r+   r}   r   r   r   vertical_line_to  s    zPaintedPath.vertical_line_toc                 C   s   | j t|dd | S )a  
        Append a straight vertical line to the given offset from the previous path
        element. The abscissa is retrieved from the end point of the previous path
        element.

        Args:
            y (Number): ordinate of the line's end point relative to the end point of
                the previous path element.

        Returns:
            The path, to allow chaining method calls.
        Fr  )r  rR  )r+   r  r   r   r   vertical_line_relative  s    z"PaintedPath.vertical_line_relativec           
      C   s8   t ||}t ||}t ||}	| jt|||	dd | S )u  
        Append a cubic Bézier curve to this path.

        Args:
            x1 (Number): abscissa of the first control point
            y1 (Number): ordinate of the first control point
            x2 (Number): abscissa of the second control point
            y2 (Number): ordinate of the second control point
            x3 (Number): abscissa of the end point
            y3 (Number): ordinate of the end point

        Returns:
            The path, to allow chaining method calls.
        Fr  )r   r  rS  )
r+   x1y1x2y2Zx3Zy3r/  r0  r1  r   r   r   curve_to  s
    


zPaintedPath.curve_toc           
      C   s8   t ||}t ||}t ||}	| jt|||	dd | S )u  
        Append a cubic Bézier curve whose points are expressed relative to the
        end point of the previous path element.

        E.g. with a start point of (0, 0), given (1, 1), (2, 2), (3, 3), the output
        curve would have the points:

        (0, 0) c1 (1, 1) c2 (3, 3) e (6, 6)

        Args:
            dx1 (Number): abscissa of the first control point relative to the end point
                of the previous path element
            dy1 (Number): ordinate of the first control point relative to the end point
                of the previous path element
            dx2 (Number): abscissa offset of the second control point relative to the
                end point of the previous path element
            dy2 (Number): ordinate offset of the second control point relative to the
                end point of the previous path element
            dx3 (Number): abscissa offset of the end point relative to the end point of
                the previous path element
            dy3 (Number): ordinate offset of the end point relative to the end point of
                the previous path element

        Returns:
            The path, to allow chaining method calls.
        Fr  )r   r  rW  )
r+   dx1dy1dx2dy2Zdx3Zdy3Zc1dZc2dr1  r   r   r   curve_relative  s
    


zPaintedPath.curve_relativec                 C   s,   t ||}t ||}| jt||dd | S )u  
        Append a cubic Bézier curve mimicking the specified quadratic Bézier curve.

        Args:
            x1 (Number): abscissa of the control point
            y1 (Number): ordinate of the control point
            x2 (Number): abscissa of the end point
            y2 (Number): ordinate of the end point

        Returns:
            The path, to allow chaining method calls.
        Fr  )r   r  rY  )r+   r  r  r  r  rZ  r1  r   r   r   quadratic_curve_to7  s    

zPaintedPath.quadratic_curve_toc                 C   s,   t ||}t ||}| jt||dd | S )u  
        Append a cubic Bézier curve mimicking the specified quadratic Bézier curve.

        Args:
            dx1 (Number): abscissa of the control point relative to the end point of
                the previous path element
            dy1 (Number): ordinate of the control point relative to the end point of
                the previous path element
            dx2 (Number): abscissa offset of the end point relative to the end point of
                the previous path element
            dy2 (Number): ordinate offset of the end point relative to the end point of
                the previous path element

        Returns:
            The path, to allow chaining method calls.
        Fr  )r   r  r]  )r+   r  r  r  r  rZ  r1  r   r   r   quadratic_curve_relativeI  s    

z$PaintedPath.quadratic_curve_relativec           
      C   sp   |dks|dkr|  ||S tt|t|}t|}t|}t|}t||}	| jt|||||	dd | S )u  
        Append an elliptical arc from the end of the previous path point to the
        specified end point.

        The arc is approximated using Bézier curves, so it is not perfectly accurate.
        However, the error is small enough to not be noticeable at any reasonable
        (and even most unreasonable) scales, with a worst-case deviation of around 3‱.

        Notes:
            - The signs of the radii arguments (`rx` and `ry`) are ignored (i.e. their
              absolute values are used instead).
            - If either radius is 0, then a straight line will be emitted instead of an
              arc.
            - If the radii are too small for the arc to reach from the current point to
              the specified end point (`x` and `y`), then they will be proportionally
              scaled up until they are big enough, which will always result in a
              half-ellipse arc (i.e. an 180 degree sweep)

        Args:
            rx (Number): radius in the x-direction.
            ry (Number): radius in the y-direction.
            rotation (Number): angle (in degrees) that the arc should be rotated
                clockwise from the principle axes. This parameter does not have
                a visual effect in the case that `rx == ry`.
            large_arc (bool): if True, the arc will cover a sweep angle of at least 180
                degrees. Otherwise, the sweep angle will be at most 180 degrees.
            positive_sweep (bool): if True, the arc will be swept over a positive angle,
                i.e. clockwise. Otherwise, the arc will be swept over a negative
                angle.
            x (Number): abscissa of the arc's end point.
            y (Number): ordinate of the arc's end point.
        r   Fr  )r  r   rc  rP   r   r   r  r_  )
r+   r  r  r   	large_arcpositive_sweepr   r}   r`  r1  r   r   r   arc_to_  s    "

 zPaintedPath.arc_toc           
      C   sp   |dks|dkr|  ||S tt|t|}t|}t|}t|}t||}	| jt|||||	dd | S )un  
        Append an elliptical arc from the end of the previous path point to an offset
        point.

        The arc is approximated using Bézier curves, so it is not perfectly accurate.
        However, the error is small enough to not be noticeable at any reasonable
        (and even most unreasonable) scales, with a worst-case deviation of around 3‱.

        Notes:
            - The signs of the radii arguments (`rx` and `ry`) are ignored (i.e. their
              absolute values are used instead).
            - If either radius is 0, then a straight line will be emitted instead of an
              arc.
            - If the radii are too small for the arc to reach from the current point to
              the specified end point (`x` and `y`), then they will be proportionally
              scaled up until they are big enough, which will always result in a
              half-ellipse arc (i.e. an 180 degree sweep)

        Args:
            rx (Number): radius in the x-direction.
            ry (Number): radius in the y-direction.
            rotation (Number): angle (in degrees) that the arc should be rotated
                clockwise from the principle axes. This parameter does not have
                a visual effect in the case that `rx == ry`.
            large_arc (bool): if True, the arc will cover a sweep angle of at least 180
                degrees. Otherwise, the sweep angle will be at most 180 degrees.
            positive_sweep (bool): if True, the arc will be swept over a positive angle,
                i.e. clockwise. Otherwise, the arc will be swept over a negative
                angle.
            dx (Number): abscissa of the arc's end point relative to the end point of
                the previous path element.
            dy (Number): ordinate of the arc's end point relative to the end point of
                the previous path element.
        r   Fr  )r  r   rc  rP   r   r   r  r  )
r+   r  r  r   r  r  r  r  r`  r1  r   r   r   arc_relative  s    #

 zPaintedPath.arc_relativec                 C   s&   | j t dd d| _| dd dS )z9
        Explicitly close the current (sub)path.
        Fr  Tr   N)r  r  r  r  rg   r   r   r   close  s    zPaintedPath.closec                 C   s*   | j s&| jjt dd | j| _d| _ d S )NFr  T)r  r  r  r  r  rg   r   r   r   r    s    z*PaintedPath._insert_implicit_close_if_openNc           	      C   sT   |    | j||||||\}}}t|| j }|d|j d	|||fS )Nrf   rC   )
r  r  build_render_listr%   r   r'   r'  r  r5   rT   )	r+   r8  r'   r   r9  r=  r>  r  r   r   r   r   r     s          zPaintedPath.renderc                 C   s   |  ||||||S )a7  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `PaintedPath.render`.
        r*  r  r   r   r   r@    s         zPaintedPath.render_debug)r   r   )T)T)r   r   )NN)'r.   r/   r   r0   r   r   rv   r'   rk  r)  r   r   r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r@  r   r   r   r   r    sd   	
	











 "01   
r  c                       s4   e Zd ZdZd
 fdd	ZdddZdd	 Z  ZS )ClippingPatha3  
    The PaintedPath API but to be used to create clipping paths.

    .. warning::
        Unless you really know what you're doing, changing attributes of the clipping
        path style is likely to produce unexpected results. This is because the
        clipping path styles override implicit style inheritance of the `PaintedPath`
        it applies to.

        For example, `clippath.style.stroke_width = 2` can unexpectedly override
        `paintpath.style.stroke_width = GraphicsStyle.INHERIT` and cause the painted
        path to be rendered with a stroke of 2 instead of what it would have normally
        inherited. Because a `ClippingPath` can be painted like a normal `PaintedPath`,
        it would be overly restrictive to remove the ability to style it, so instead
        this warning is here.
    r   c                    s   t  j||d tj| _d S )Nr   )r]   r   r   r   r   r   rd   r   r   r     s    zClippingPath.__init__Nc              	   C   s   |r| d | jj||||||dd\}}}t|| j}|j}	|	|jkrTtj	}	n
t|	j
 }	| }
||	j ||
j d|||fS )Nz<ClippingPath> F_push_stackrC   )r;  r  r  r%   r   r'   r   r   r
   r(  r,   r'  rW   r5   rT   )r+   r8  r'   r   r9  r=  r>  r  merged_styler   r   r   r   r   r     s4    


zClippingPath.renderc                 C   s   |  ||||||S )a  
        Render this path element to its PDF representation and produce debug
        information.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).

        Returns:
            The same tuple as `ClippingPath.render`.
        r*  r  r   r   r   r@  H  s         zClippingPath.render_debug)r   r   )NN)r.   r/   r   r0   r   r   r@  rw   r   r   rd   r   r    s      
,r  c                   @   s   e Zd Zdd Zdd Zedd Zejdd Zedd	 Zejd
d	 ZdddZ	dd Z
dd ZedddZdedddZdedddZdS )r  c                 C   s   t  | _g | _d | _d | _d S rD   )r%   r'   
path_items
_transform_clipping_pathrg   r   r   r   r   c  s    zGraphicsContext.__init__c                 C   sL   |   }t| j||_t| j||_t| j||_t| j||_|S rD   )	re   r  r  r'   r  rk  r  r  r  r  r   r   r   r   j  s    zGraphicsContext.__deepcopy__c                 C   s   | j S rD   r  rg   r   r   r   rk  t  s    zGraphicsContext.transformc                 C   s
   || _ d S rD   r  r  r   r   r   rk  x  s    c                 C   s   | j S )z-The `ClippingPath` for this graphics context.r  rg   r   r   r   r  |  s    zGraphicsContext.clipping_pathc                 C   s
   || _ d S rD   r  r  r   r   r   r    s    Tc                 C   s   |rt |}| j| dS )a  
        Add a path element to this graphics context.

        Args:
            item: the path element to add. May be a primitive element or another
                `GraphicsContext` or a `PaintedPath`.
            _copy (bool): if true (the default), the item will be copied before being
                appended. This prevents modifications to a referenced object from
                "retroactively" altering its style/shape and should be disabled with
                caution.
        N)r  r  r  rW   r  r   r   r   r    s    
zGraphicsContext.add_itemc                 C   s   | j d= d S )Nrf   )r  rg   r   r   r   r    s    z GraphicsContext.remove_last_itemc                 C   s   | j |j  dS )z:Copy another `GraphicsContext`'s path items into this one.N)r  extend)r+   Zother_contextr   r   r   r     s    zGraphicsContext.mergeNc              
   C   s  g }| j r|dk	r$|| jj  |j|| j}	|dk	r| jrX|d| j d g }
|	jD ]L}t|	|}||	j	k	rbt| j||	j	krd}nd}|

| d| |  qb|
r|d |
D ]&}||d  || |d	 q||d
  n
|d	 d|	j	h}| j}|	j| jjkr8t| j}|	j|_|	j}|	j}||jks\||jkr|| jkrrt|}||_||_||f}nd}||}|dk	r|
t| d | jj}| jj}||kr|
|   ||kr|
|   |dk	r,|
t|d dt|d  d  |r| jdk	r|||d  | j||	||||d \}}}|r||
| | j dd D ]B}||d  |||	||||d \}}}|r|
| q||d  | j d ||	||||d \}}}|rz|
| nh| jdk	rF| j||	||\}}}|rF|
| | j D ],}|||	||\}}}|rL|
| qL| jdk	r|d| j|d  |r|dd |
d |||fS )a  
        Build a list composed of all all the individual elements rendered.

        This is used by `PaintedPath` and `ClippingPath` to reuse the `GraphicsContext`
        rendering process while still being able to inject some path specific items
        (e.g. the painting directive) before the render is collapsed into a single
        string.

        Args:
            gsd_registry (GraphicsStateDictRegistry): the owner's graphics state
                dictionary registry.
            style (GraphicsStyle): the current resolved graphics style
            last_item: the previous path element.
            initial_point: last position set by a "M" or "m" command
            debug_stream (io.TextIO): the stream to which the debug output should be
                written. This is not guaranteed to be seekable (e.g. it may be stdout or
                stderr).
            pfx (str): the current debug output prefix string (only needed if emitting
                more than one line).
            _push_stack (bool): if True, wrap the resulting render list in a push/pop
                graphics stack directive pair.

        Returns:
            `tuple[list[str], last_item]` where `last_item` is the past path element in
            this `GraphicsContext`
        Nr!   r"   z (inherited)r   z: z {
r  r   u   }┐
r  r   rC   r   r  r}  r  rf   r~  r  r  )r  r;  re   r.   r   r'   r  r   rL   r   rW   r   r  r  r   r   r-   rE   r   r   r(   lowerupperr<   r  r@  r   rk  r  )r+   r8  r'   r   r9  r=  r>  r  r  r  Z
styles_dbgattrrH   Z	inheritedZstyle_dbg_lineZNO_EMIT_SETZ
emit_styleZdash_patternZ
dash_phaseZ	emit_dashr  r   r   Zrendered_cpathri  __r   r?  r   r   r   r    s    %


















	

	   


   

z!GraphicsContext.build_render_listr&   c           	   	   C   s.   | j |||||||d\}}}d|||fS )Nr  rC   )r  rT   )	r+   r8  r'   r   r9  r=  r>  r  r  r   r   r   r   U  s    

zGraphicsContext.renderc              	   C   s   | j |||||||dS )Nr  r*  )r+   r8  r'   r   r9  r=  r>  r  r   r   r   r@  k  s    
zGraphicsContext.render_debug)T)NNT)NNT)T)r.   r/   r   r   r   rv   rk  r)  r  r  r  r   r   r  r  r   r@  r   r   r   r   r  b  s:   





    >    r  )r1   r2   )N)N)rf   rf   )N)Ur0   r  r  r   recollectionsr   collections.abcr   
contextlibr   typingr   r   r   enumsr	   r
   r   r   r   r   r   Zsyntaxr   r   utilr   r   r   r   r   r  r  r   rQ   r%  
WHITESPACEZ	EOL_CHARSZ
DELIMITERScompileZSTR_ESCZSTR_ESC_MAPr$   r7   r<   rE   r[   rx   ry   r   r   r   r   r   r   r   r   r%   r-  r.  r2  r3  rB  rH  rI  rK  rO  rQ  rR  rS  rW  rY  r]  r_  r  r  r  r  r  r  r  r  r  r  r   r   r   r   <module>   s   $	


C
/
	

"



( X  b   5CADB>B>BHP\H \R@ n=> +    ?f