o
    7 hT!                     @  s   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZmZ er>dd	lmZ dd
lmZ G dd deZG dd deZdS )z=lxml custom element classes for picture-related XML elements.    )annotations)TYPE_CHECKINGcast)escape)	parse_xmlnsdecls)BaseShapeElement)BaseOxmlElementOneAndOnlyOne)CT_ShapeProperties)Lengthc                   @  s  e Zd ZU dZedZedZedZded< e	d:d	d
Z
dd Zdd Ze	dd Zedd Zedd Zed;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d/d0 Zed1d2 Zed3d4 Zed5d6 Zd7d8 Zd9S )<
CT_PicturezV`p:pic` element.

    Represents a picture shape (an image placement on a slide).
    z	p:nvPicPrz
p:blipFillzp:spPrr   spPrreturn
str | Nonec                 C  s$   | j j}|dur|jdur|jS dS )zWValue of `p:blipFill/a:blip/@r:embed`.

        Returns |None| if not present.
        N)blipFillbliprEmbed)selfr    r   `/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/pptx/oxml/shapes/picture.pyblip_rId   s   zCT_Picture.blip_rIdc                 C  s   | j | || dS )z
        Set cropping values in `p:blipFill/a:srcRect` such that an image of
        *image_size* will stretch to exactly fit *view_size* when its aspect
        ratio is preserved.
        N)r   crop_fill_cropping)r   
image_size	view_sizer   r   r   crop_to_fit'      zCT_Picture.crop_to_fitc                 C  s
   | j  S )zS
        Return the <a:ln> grandchild element, newly added if not present.
        )r   get_or_add_lnr   r   r   r   r   /   s   
zCT_Picture.get_or_add_lnc                 C  s   | j jS )zI
        ``<a:ln>`` grand-child element or |None| if not present
        )r   lnr    r   r   r   r!   5   s   zCT_Picture.lnc                 C  s   t |  ||||f S )zj
        Return a new `p:pic` placeholder element populated with the supplied
        parameters.
        )r   _pic_ph_tmpl)clsid_namedescrIdr   r   r   
new_ph_pic<   r   zCT_Picture.new_ph_picc	           	   
   C  s$   t |  ||t||||||f S )zFReturn new `<p:pic>` element tree configured with supplied parameters.)r   	_pic_tmplr   )	r#   shape_idr%   r&   r'   xycxcyr   r   r   new_picD   s   $zCT_Picture.new_picr*   int
shape_namestr	video_rId	media_rIdposter_frame_rIdr+   r   r,   r-   r.   c
           
      C  s(   t tt|  |||||||||	f	 S )z8Return a new `p:pic` populated with the specified video.)r   r   r   _pic_video_tmpl)
r#   r*   r1   r3   r4   r5   r+   r,   r-   r.   r   r   r   new_video_picI   s"   zCT_Picture.new_video_picc                 C  
   |  dS )z9Value of `p:blipFill/a:srcRect/@b` or 0.0 if not present.b
_srcRect_xr    r   r   r   	srcRect_bi      
zCT_Picture.srcRect_bc                 C     || j  _d S N)r   get_or_add_srcRectr9   r   valuer   r   r   r<   n      c                 C  r8   )z9Value of `p:blipFill/a:srcRect/@l` or 0.0 if not present.lr:   r    r   r   r   	srcRect_lr   r=   zCT_Picture.srcRect_lc                 C  r>   r?   )r   r@   rD   rA   r   r   r   rE   w   rC   c                 C  r8   )z9Value of `p:blipFill/a:srcRect/@r` or 0.0 if not present.rr:   r    r   r   r   	srcRect_r{   r=   zCT_Picture.srcRect_rc                 C  r>   r?   )r   r@   rF   rA   r   r   r   rG      rC   c                 C  r8   )z9Value of `p:blipFill/a:srcRect/@t` or 0.0 if not present.tr:   r    r   r   r   	srcRect_t   r=   zCT_Picture.srcRect_tc                 C  r>   r?   )r   r@   rH   rA   r   r   r   rI      rC   c                 C  sd   dd }|| }|| }||k rd||  d }|d|dfS ||kr0d||  d }d|d|fS dS )am  
        Return a (left, top, right, bottom) 4-tuple containing the cropping
        values required to display an image of *image_size* in *view_size*
        when stretched proportionately. Each value is a percentage expressed
        as a fraction of 1.0, e.g. 0.425 represents 42.5%. *image_size* and
        *view_size* are each (width, height) pairs.
        c                 S  s   | | S r?   r   )widthheightr   r   r   aspect_ratio   s   z/CT_Picture._fill_cropping.<locals>.aspect_ratiog      ?g       @        )rM   rM   rM   rM   r   )r   r   r   rL   Zar_viewZar_imager   r   r   r   r      s   	zCT_Picture._fill_croppingc                 C     dt ddd S )Na=  <p:pic %s>
  <p:nvPicPr>
    <p:cNvPr id="%%d" name="%%s" descr="%%s"/>
    <p:cNvPicPr>
      <a:picLocks noGrp="1" noChangeAspect="1"/>
    </p:cNvPicPr>
    <p:nvPr/>
  </p:nvPicPr>
  <p:blipFill>
    <a:blip r:embed="%%s"/>
    <a:stretch>
      <a:fillRect/>
    </a:stretch>
  </p:blipFill>
  <p:spPr/>
</p:pic>parF   r   r#   r   r   r   r"      s   
zCT_Picture._pic_ph_tmplc                 C  rN   )Na  <p:pic %s>
  <p:nvPicPr>
    <p:cNvPr id="%%d" name="%%s" descr="%%s"/>
    <p:cNvPicPr>
      <a:picLocks noChangeAspect="1"/>
    </p:cNvPicPr>
    <p:nvPr/>
  </p:nvPicPr>
  <p:blipFill>
    <a:blip r:embed="%%s"/>
    <a:stretch>
      <a:fillRect/>
    </a:stretch>
  </p:blipFill>
  <p:spPr>
    <a:xfrm>
      <a:off x="%%d" y="%%d"/>
      <a:ext cx="%%d" cy="%%d"/>
    </a:xfrm>
    <a:prstGeom prst="rect">
      <a:avLst/>
    </a:prstGeom>
  </p:spPr>
</p:pic>rP   rO   rF   r   rQ   r   r   r   r)      s   
zCT_Picture._pic_tmplc                 C  rN   )Na  <p:pic %s>
  <p:nvPicPr>
    <p:cNvPr id="%%d" name="%%s">
      <a:hlinkClick r:id="" action="ppaction://media"/>
    </p:cNvPr>
    <p:cNvPicPr>
      <a:picLocks noChangeAspect="1"/>
    </p:cNvPicPr>
    <p:nvPr>
      <a:videoFile r:link="%%s"/>
      <p:extLst>
        <p:ext uri="{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}">
          <p14:media xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" r:embed="%%s"/>
        </p:ext>
      </p:extLst>
    </p:nvPr>
  </p:nvPicPr>
  <p:blipFill>
    <a:blip r:embed="%%s"/>
    <a:stretch>
      <a:fillRect/>
    </a:stretch>
  </p:blipFill>
  <p:spPr>
    <a:xfrm>
      <a:off x="%%d" y="%%d"/>
      <a:ext cx="%%d" cy="%%d"/>
    </a:xfrm>
    <a:prstGeom prst="rect">
      <a:avLst/>
    </a:prstGeom>
  </p:spPr>
</p:pic>rP   rO   rF   r   rQ   r   r   r   r6      s   
!zCT_Picture._pic_video_tmplc                 C  s   | j j}|du r
dS t||S )zU
        Value of `p:blipFill/a:srcRect/@{attr_name}` or 0.0 if not present.
        NrM   )r   srcRectgetattr)r   	attr_namerR   r   r   r   r;      s   
zCT_Picture._srcRect_xN)r   r   )r*   r0   r1   r2   r3   r2   r4   r2   r5   r2   r+   r   r,   r   r-   r   r.   r   r   r   )__name__
__module____qualname____doc__r   ZnvPicPrr   r   __annotations__propertyr   r   r   r!   classmethodr(   r/   r7   r<   setterrE   rG   rI   r   r"   r)   r6   r;   r   r   r   r   r      sR   
 














&r   c                   @  s    e Zd ZdZedZedZdS )CT_PictureNonVisualz\
    ``<p:nvPicPr>`` element, containing non-visual properties for a picture
    shape.
    zp:cNvPrzp:nvPrN)rU   rV   rW   rX   r   cNvPrnvPrr   r   r   r   r]     s    r]   N)rX   
__future__r   typingr   r   Zxml.sax.saxutilsr   	pptx.oxmlr   pptx.oxml.nsr   pptx.oxml.shapes.sharedr	   pptx.oxml.xmlchemyr
   r   r   	pptx.utilr   r   r]   r   r   r   r   <module>   s     v