
    ,h*                         d Z ddlmZmZmZmZ ddlmZ ddlm	Z	  G d de      Z
 G d de      Z G d	 d
e      Z G d de      Z G d de      Zy)z3Objects related to construction of freeform shapes.    )absolute_importdivisionprint_functionunicode_literals)Sequence)lazypropertyc                       e Zd ZdZ fdZd Zd Zd Zed        Z	ddZ
ddZd	 Zed
        Zed        Zd Zd Zd Zed        Zed        Zed        Zed        Zed        Zd Zd Zed        Zed        Z xZS )FreeformBuilderaT  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.
    c                 p    t         t        |           || _        || _        || _        || _        || _        y N)superr
   __init___shapes_start_x_start_y_x_scale_y_scale)selfshapesstart_xstart_yx_scaley_scale	__class__s         V/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/pptx/shapes/freeform.pyr   zFreeformBuilder.__init__   s3    ot-/    c                 8    | j                   j                  |      S r   )_drawing_operations__getitem__)r   idxs     r   r   zFreeformBuilder.__getitem__!   s    ''33C88r   c                 6    | j                   j                         S r   )r   __iter__r   s    r   r"   zFreeformBuilder.__iter__$   s    ''0022r   c                 6    | j                   j                         S r   )r   __len__r#   s    r   r%   zFreeformBuilder.__len__'   s    ''//11r   c           	      b     | |t        t        |            t        t        |            ||      S )zReturn a new |FreeformBuilder| object.

        The initial pen location is specified (in local coordinates) by
        (*start_x*, *start_y*).
        intround)clsr   r   r   r   r   s         r   newzFreeformBuilder.new*   s)     63uW~.E'N0CWgVVr   c                 b    |D ]  \  }}| j                  ||        |r| j                          | 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   verticesclosexys        r   add_line_segmentsz!FreeformBuilder.add_line_segments3   s9      	)DAq""1a(	)OOr   c                     | j                  ||      }| j                  |      }| D ]  }|j                  |        | j                  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   origin_xorigin_ysppathdrawing_operations         r   convert_to_shapez FreeformBuilder.convert_to_shapeD   sY     ""8X6#!% 	7006	7||**2..r   c                 f    | j                   j                  t        j                  | ||             | 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_MoveTor+   r   r1   r2   s      r   move_tozFreeformBuilder.move_toT   s*     	  ''D!Q(?@r   c                 r    | j                   }| D ]%  }t        |d      st        ||j                        }' |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.
        r1   )r   hasattrminr1   )r   min_xr=   s      r   shape_offset_xzFreeformBuilder.shape_offset_x]   B     !% 	8(#.E#4#6#67	8 r   c                 r    | j                   }| D ]%  }t        |d      st        ||j                        }' |S )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.
        r2   )r   rE   rF   r2   )r   min_yr=   s      r   shape_offset_yzFreeformBuilder.shape_offset_yk   rI   r   c                 ^    | j                   j                  t        j                                y)z7Add a close |_Close| operation to the drawing sequence.N)r   r@   _Closer+   r#   s    r   r.   zFreeformBuilder._add_closey   s      ''

5r   c                     | j                   j                  }|j                  || j                  z   || j                  z   | 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   r9   r:   spTrees       r   r5   z FreeformBuilder._add_freeform_sp}   sI     %%%%tzz!8dii#7dll
 	
r   c                 d    | j                   j                  t        j                  | ||             y)z7Add a |_LineSegment| operation to the drawing sequence.N)r   r@   _LineSegmentr+   rB   s      r   r-   z!FreeformBuilder._add_line_segment   s%      ''(8(8q!(DEr   c                     g S )z>Return the sequence of drawing operation objects for freeform. r#   s    r   r   z#FreeformBuilder._drawing_operations   s	     	r   c                     | j                   x}}| D ];  }t        |d      st        ||j                        }t	        ||j                        }= ||z
  S )z9Return integer width of this shape's path in local units.r1   )r   rE   rF   r1   max)r   rG   max_xr=   s       r   _dxzFreeformBuilder._dx   _     %!% 	8(#.E#4#6#67E#4#6#67	8 u}r   c                     | j                   x}}| D ];  }t        |d      st        ||j                        }t	        ||j                        }= ||z
  S )z:Return integer height of this shape's path in local units.r2   )r   rE   rF   r2   r\   )r   rK   max_yr=   s       r   _dyzFreeformBuilder._dy   r_   r   c                 X    t        t        | j                  | j                  z              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(   r)   rb   r   r#   s    r   rU   zFreeformBuilder._height   !     5DMM1233r   c                 X    t        t        | j                  | j                  z              S )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(   r)   rH   r   r#   s    r   rR   zFreeformBuilder._left   #     5,,t}}<=>>r   c                 >    || j                   z
  || j                  z
  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.
        )rH   rL   )r   local_xlocal_ys      r   _local_to_shapezFreeformBuilder._local_to_shape   s%     $---w9L9L/LMMr   c                     |j                  | j                  | j                        } |j                  | 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_pathr^   rb   
add_moveTorj   r   r   )r   r;   r<   s      r   r6   zFreeformBuilder._start_path   sF     {{TXX{2--dmmT]]KLr   c                 X    t        t        | j                  | j                  z              S )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(   r)   rL   r   r#   s    r   rS   zFreeformBuilder._top   rf   r   c                 X    t        t        | j                  | j                  z              S )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(   r)   r^   r   r#   s    r   rT   zFreeformBuilder._width   rd   r   )T)r   r   )__name__
__module____qualname____doc__r   r   r"   r%   classmethodr+   r3   r>   rC   propertyrH   rL   r.   r5   r-   r   r   r^   rb   rU   rR   rj   r6   rS   rT   __classcell__r   s   @r   r
   r
      s    932 W W"/     6	
F       4 4 ? ?N ? ? 4 4r   r
   c                   H     e Zd ZdZ fdZd Zed        Zed        Z xZ	S )_BaseDrawingOperationzBase class for freeform drawing operations.

    A drawing operation has at least one location (x, y) in local
    coordinates.
    c                 T    t         t        |           || _        || _        || _        y r   )r   r{   r   _freeform_builder_x_y)r   freeform_builderr1   r2   r   s       r   r   z_BaseDrawingOperation.__init__   s'    #T35!1r   c                     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   r<   s     r   r7   z(_BaseDrawingOperation.apply_operation_to   s    
 ""HIIr   c                     | j                   S )zReturn the horizontal (x) target location of this operation.

        The returned value is an integer in local coordinates.
        )r~   r#   s    r   r1   z_BaseDrawingOperation.x        wwr   c                     | j                   S )zReturn the vertical (y) target location of this operation.

        The returned value is an integer in local coordinates.
        )r   r#   s    r   r2   z_BaseDrawingOperation.y   r   r   )
rr   rs   rt   ru   r   r7   rw   r1   r2   rx   ry   s   @r   r{   r{      s;    J    r   r{   c                   &    e Zd ZdZed        Zd Zy)rN   z?Specifies adding a `<a:close/>` element to the current contour.c                      |        S )zReturn a new _Close object.rZ   )r*   s    r   r+   z
_Close.new  s     ur   c                 "    |j                         S )z Add `a:close` element to *path*.)	add_closer   s     r   r7   z_Close.apply_operation_to  s    ~~r   Nrr   rs   rt   ru   rv   r+   r7   rZ   r   r   rN   rN     s    I  r   rN   c                   &    e Zd ZdZed        Zd Zy)rX   z@Specifies a straight line segment ending at the specified point.c           	      ^     | |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.
        r'   r*   r   r1   r2   s       r   r+   z_LineSegment.new  $     #Sq]CaMBBr   c                     |j                  | j                  | j                  j                  z
  | j                  | j                  j
                  z
        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}   rH   r   rL   r   s     r   r7   z_LineSegment.apply_operation_to  sE    
 }}GGd,,;;;GGd,,;;;
 	
r   Nr   rZ   r   r   rX   rX     s    JC C
r   rX   c                   &    e Zd ZdZed        Zd Zy)rA   zSpecifies a new pen position.c           	      ^     | |t        t        |            t        t        |                  S )zReturn a new _MoveTo object for move to point *(x, y)*.

        Both *x* and *y* are rounded to the nearest integer before use.
        r'   r   s       r   r+   z_MoveTo.new*  r   r   c                     |j                  | j                  | j                  j                  z
  | j                  | j                  j
                  z
        S )z7Add `a:moveTo` element to *path* for this line segment.)ro   r~   r}   rH   r   rL   r   s     r   r7   z_MoveTo.apply_operation_to2  sC    GGd,,;;;GGd,,;;;
 	
r   Nr   rZ   r   r   rA   rA   '  s    'C C
r   rA   N)ru   
__future__r   r   r   r   pptx.compatr   	pptx.utilr   r
   objectr{   rN   rX   rA   rZ   r   r   <module>r      sX    : R R   "Q4h Q4h"F "J
 V 
 
( 
,
# 
r   