o
    7 h0                     @  s   U d Z ddlmZ ddlmZmZmZmZ ddlm	Z	m
Z
 er?ddlmZ ddlmZmZmZmZmZ ddlmZ ddlmZ d	Zd
ed< dZd
ed< G dd dee ZG dd deZG dd deZG dd deZG dd deZdS )z3Objects related to construction of freeform shapes.    )annotations)TYPE_CHECKINGIterableIteratorSequence)Emulazyproperty)	TypeAlias)	CT_Path2DCT_Path2DCloseCT_Path2DLineToCT_Path2DMoveToCT_Shape)_BaseGroupShapes)Lengthz2CT_Path2DClose | CT_Path2DLineTo | CT_Path2DMoveTor	   CT_DrawingOperationz_LineSegment | _MoveTo | _CloseDrawingOperationc                      s   e Zd ZdZdM fd
dZdNddZdOddZdd ZedPddZ	dQdRddZ
ed ed fdSd#d$ZdTd'd(ZedUd)d*ZedUd+d,Zd-d. ZdSd/d0ZdVd2d3ZedWd5d6ZedUd7d8ZedUd9d:Zed;d< Zed=d> ZdXdBdCZdYdGdHZedIdJ ZedKdL Z  ZS )ZFreeformBuilderaP  Allows a freeform shape to be specified and created.

    The initial pen position is provided on construction. From there, drawing proceeds using
    successive calls to draw line segments. The freeform shape may be closed by calling the
    :meth:`close` method.

    A shape may have more than one contour, in which case overlapping areas are "subtracted". A
    contour is a sequence of line segments beginning with a "move-to" operation. A move-to
    operation is automatically inserted in each new freeform; additional move-to ops can be
    inserted with the `.move_to()` method.
    shapesr   start_xr   start_yx_scalefloaty_scalec                   s0   t t|   || _|| _|| _|| _|| _d S N)superr   __init___shapes_start_x_start_y_x_scale_y_scale)selfr   r   r   r   r   	__class__ \/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/pptx/shapes/freeform.pyr   '   s   
zFreeformBuilder.__init__idxintreturnr   c                 C  s   | j |S r   )_drawing_operations__getitem__)r"   r'   r%   r%   r&   r+   6   s   zFreeformBuilder.__getitem__Iterator[DrawingOperation]c                 C  
   | j  S r   )r*   __iter__r"   r%   r%   r&   r.   ;      
zFreeformBuilder.__iter__c                 C  r-   r   )r*   __len__r/   r%   r%   r&   r1   >   r0   zFreeformBuilder.__len__c                 C  s(   | |t tt|t tt|||S )zReturn a new |FreeformBuilder| object.

        The initial pen location is specified (in local coordinates) by
        (`start_x`, `start_y`).
        r   r(   round)clsr   r   r   r   r   r%   r%   r&   newA   s   (zFreeformBuilder.newTverticesIterable[tuple[float, float]]closeboolc                 C  s*   |D ]
\}}|  || q|r|   | S )a  Add a straight line segment to each point in `vertices`.

        `vertices` must be an iterable of (x, y) pairs (2-tuples). Each x and y value is rounded
        to the nearest integer before use. The optional `close` parameter determines whether the
        resulting contour is `closed` or left `open`.

        Returns this |FreeformBuilder| object so it can be used in chained calls.
        )_add_line_segment
_add_close)r"   r6   r8   xyr%   r%   r&   add_line_segmentsQ   s
   	z!FreeformBuilder.add_line_segmentsr   origin_xorigin_yc                 C  s6   |  ||}| |}| D ]}|| q| j|S )a  Return new freeform shape positioned relative to specified offset.

        `origin_x` and `origin_y` locate the origin of the local coordinate system in slide
        coordinates (EMU), perhaps most conveniently by use of a |Length| object.

        Note that this method may be called more than once to add multiple shapes of the same
        geometry in different locations on the slide.
        )_add_freeform_sp_start_pathapply_operation_tor   _shape_factory)r"   r?   r@   sppathdrawing_operationr%   r%   r&   convert_to_shape`   s
   	
z FreeformBuilder.convert_to_shaper<   r=   c                 C  s   | j t| || | S )zMove pen to (x, y) (local coordinates) without drawing line.

        Returns this |FreeformBuilder| object so it can be used in chained calls.
        )r*   append_MoveTor5   r"   r<   r=   r%   r%   r&   move_too   s   zFreeformBuilder.move_toc                 C  0   | j }| D ]}t|trqt||j}qt|S )a  Return x distance of shape origin from local coordinate origin.

        The returned integer represents the leftmost extent of the freeform shape, in local
        coordinates. Note that the bounding box of the shape need not start at the local origin.
        )r   
isinstance_Closeminr<   r   )r"   min_xrG   r%   r%   r&   shape_offset_xw      
zFreeformBuilder.shape_offset_xc                 C  rM   )a  Return y distance of shape origin from local coordinate origin.

        The returned integer represents the topmost extent of the freeform shape, in local
        coordinates. Note that the bounding box of the shape need not start at the local origin.
        )r   rN   rO   rP   r=   r   )r"   min_yrG   r%   r%   r&   shape_offset_y   rS   zFreeformBuilder.shape_offset_yc                 C  s   | j t  dS )z7Add a close |_Close| operation to the drawing sequence.N)r*   rI   rO   r5   r/   r%   r%   r&   r;      s   zFreeformBuilder._add_closec                 C  s(   | j j}||| j || j | j| jS )zAdd a freeform `p:sp` element having no drawing elements.

        `origin_x` and `origin_y` are specified in slide coordinates, and represent the location
        of the local coordinates origin on the slide.
        )r   _spTreeadd_freeform_sp_left_top_width_height)r"   r?   r@   spTreer%   r%   r&   rA      s   z FreeformBuilder._add_freeform_spNonec                 C  s   | j t| || dS )z7Add a |_LineSegment| operation to the drawing sequence.N)r*   rI   _LineSegmentr5   rK   r%   r%   r&   r:      s   z!FreeformBuilder._add_line_segmentlist[DrawingOperation]c                 C  s   g S )z>Return the sequence of drawing operation objects for freeform.r%   r/   r%   r%   r&   r*      s   z#FreeformBuilder._drawing_operationsc                 C  D   | j  }}| D ]}t|trqt||j}t||j}qt|| S )z1Return width of this shape's path in local units.)r   rN   rO   rP   r<   maxr   )r"   rQ   max_xrG   r%   r%   r&   _dx      

zFreeformBuilder._dxc                 C  r`   )z:Return integer height of this shape's path in local units.)r   rN   rO   rP   r=   ra   r   )r"   rT   max_yrG   r%   r%   r&   _dy   rd   zFreeformBuilder._dyc                 C     t t| j| j S )zReturn vertical size of this shape's path in slide coordinates.

        This value is based on the actual extents of the shape and does not include any
        positioning offset.
        )r(   r3   rf   r!   r/   r%   r%   r&   r[         zFreeformBuilder._heightc                 C  rg   )zReturn leftmost extent of this shape's path in slide coordinates.

        Note that this value does not include any positioning offset; it assumes the drawing
        (local) coordinate origin is at (0, 0) on the slide.
        )r(   r3   rR   r    r/   r%   r%   r&   rX      rh   zFreeformBuilder._leftlocal_xlocal_ytuple[Length, Length]c                 C  s   t || j t || j fS )a  Translate local coordinates point to shape coordinates.

        Shape coordinates have the same unit as local coordinates, but are offset such that the
        origin of the shape coordinate system (0, 0) is located at the top-left corner of the
        shape bounding box.
        )r   rR   rU   )r"   ri   rj   r%   r%   r&   _local_to_shape   s   zFreeformBuilder._local_to_shaperE   r   r
   c                 C  s,   |j | j| jd}|j| | j| j  |S )zReturn a newly created `a:path` element added to `sp`.

        The returned `a:path` element has an `a:moveTo` element representing the shape starting
        point as its only child.
        )wh)add_pathrc   rf   
add_moveTorl   r   r   )r"   rE   rF   r%   r%   r&   rB      s   zFreeformBuilder._start_pathc                 C  rg   )a  Return topmost extent of this shape's path in slide coordinates.

        Note that this value does not include any positioning offset; it assumes the drawing
        (local) coordinate origin is located at slide coordinates (0, 0) (top-left corner of
        slide).
        )r(   r3   rU   r!   r/   r%   r%   r&   rY      s   zFreeformBuilder._topc                 C  rg   )zReturn width of this shape's path in slide coordinates.

        This value is based on the actual extents of the shape path and does not include any
        positioning offset.
        )r(   r3   rc   r    r/   r%   r%   r&   rZ      rh   zFreeformBuilder._width)
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   )T)r6   r7   r8   r9   )r?   r   r@   r   )r<   r   r=   r   r)   r   )r<   r   r=   r   r)   r]   )r)   r_   )ri   r   rj   r   r)   rk   )rE   r   r)   r
   )__name__
__module____qualname____doc__r   r+   r.   r1   classmethodr5   r>   r   rH   rL   propertyrR   rU   r;   rA   r:   r   r*   rc   rf   r[   rX   rl   rB   rY   rZ   __classcell__r%   r%   r#   r&   r      sD    










	

	r   c                      sH   e Zd ZdZd fddZdddZedddZedddZ  Z	S )_BaseDrawingOperationzBase class for freeform drawing operations.

    A drawing operation has at least one location (x, y) in local coordinates.
    freeform_builderr   r<   r   r=   c                   s$   t t|   || _|| _|| _d S r   )r   ry   r   _freeform_builder_x_y)r"   rz   r<   r=   r#   r%   r&   r      s   
z_BaseDrawingOperation.__init__rF   r
   r)   r   c                 C  s   t d)zuAdd the XML element(s) implementing this operation to `path`.

        Must be implemented by each subclass.
        z$must be implemented by each subclass)NotImplementedErrorr"   rF   r%   r%   r&   rC     s   z(_BaseDrawingOperation.apply_operation_toc                 C     | j S )zReturn the horizontal (x) target location of this operation.

        The returned value is an integer in local coordinates.
        )r|   r/   r%   r%   r&   r<        z_BaseDrawingOperation.xc                 C  r   )zReturn the vertical (y) target location of this operation.

        The returned value is an integer in local coordinates.
        )r}   r/   r%   r%   r&   r=     r   z_BaseDrawingOperation.y)rz   r   r<   r   r=   r   )rF   r
   r)   r   rq   )
rr   rs   rt   ru   r   rC   rw   r<   r=   rx   r%   r%   r#   r&   ry      s    
ry   c                   @  s(   e Zd ZdZedddZddd	Zd
S )rO   z?Specifies adding a `<a:close/>` element to the current contour.r)   c                 C  s   |  S )zReturn a new _Close object.r%   )r4   r%   r%   r&   r5   !  s   z
_Close.newrF   r
   r   c                 C  s   |  S )z Add `a:close` element to `path`.)	add_closer   r%   r%   r&   rC   &  s   z_Close.apply_operation_toN)r)   rO   )rF   r
   r)   r   rr   rs   rt   ru   rv   r5   rC   r%   r%   r%   r&   rO     s
    rO   c                   @  (   e Zd ZdZeddd	ZdddZdS )r^   z@Specifies a straight line segment ending at the specified point.rz   r   r<   r   r=   r)   c                 C  $   | |t tt|t tt|S )zReturn a new _LineSegment object ending at point *(x, y)*.

        Both `x` and `y` are rounded to the nearest integer before use.
        r2   r4   rz   r<   r=   r%   r%   r&   r5   .     $z_LineSegment.newrF   r
   r   c                 C  (   | t| j| jj t| j| jj S )z}Add `a:lnTo` element to `path` for this line segment.

        Returns the `a:lnTo` element newly added to the path.
        )add_lnTor   r|   r{   rR   r}   rU   r   r%   r%   r&   rC   6  s   z_LineSegment.apply_operation_toN)rz   r   r<   r   r=   r   r)   r^   )rF   r
   r)   r   r   r%   r%   r%   r&   r^   +  
    r^   c                   @  r   )rJ   zSpecifies a new pen position.rz   r   r<   r   r=   r)   c                 C  r   )zReturn a new _MoveTo object for move to point `(x, y)`.

        Both `x` and `y` are rounded to the nearest integer before use.
        r2   r   r%   r%   r&   r5   D  r   z_MoveTo.newrF   r
   r   c                 C  r   )z7Add `a:moveTo` element to `path` for this line segment.)rp   r   r|   r{   rR   r}   rU   r   r%   r%   r&   rC   L  s   z_MoveTo.apply_operation_toN)rz   r   r<   r   r=   r   r)   rJ   )rF   r
   r)   r   r   r%   r%   r%   r&   rJ   A  r   rJ   N)ru   
__future__r   typingr   r   r   r   	pptx.utilr   r   typing_extensionsr	   pptx.oxml.shapes.autoshaper
   r   r   r   r   pptx.shapes.shapetreer   r   r   __annotations__r   r   objectry   rO   r^   rJ   r%   r%   r%   r&   <module>   s"     a$