a
    ]øj³
  ã                   @  s|   d Z ddlm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 erhddlmZ dd	lmZ G d
d„ de	ƒZdS )z7The proxy class for an image part, and related objects.é    )ÚannotationsN)ÚTYPE_CHECKING)ÚImage)ÚPart)ÚEmuÚInches)Ú
OpcPackage)ÚPackURIc                      sœ   e Zd ZdZddddddœ‡ fdd	„Zed
d„ ƒZedd„ ƒZedd„ ƒZe	dddœdd„ƒZ
eddœdd„ƒZe	dddddœdd„ƒZedd„ ƒZ‡  ZS )Ú	ImagePartzlAn image part.

    Corresponds to the target part of a relationship with type RELATIONSHIP_TYPE.IMAGE.
    Nr	   ÚstrÚbyteszImage | None)ÚpartnameÚcontent_typeÚblobÚimagec                   s   t t| ƒ |||¡ || _d S ©N)Úsuperr
   Ú__init__Ú_image)Úselfr   r   r   r   ©Ú	__class__© úL/var/www/html/assistant/venv/lib/python3.9/site-packages/docx/parts/image.pyr      s    zImagePart.__init__c                 C  s    | j j}| j j}|| }t|ƒS )zkNative width of this image, calculated from its width in pixels and
        horizontal dots per inch (dpi).)r   Úpx_widthÚhorz_dpir   )r   r   r   Zwidth_in_inchesr   r   r   Ú
default_cx   s    zImagePart.default_cxc                 C  s,   | j j}| j j}ttd| | ƒƒ}t|ƒS )zkNative height of this image, calculated from its height in pixels and
        vertical dots per inch (dpi).iàó )r   Ú	px_heightr   ÚintÚroundr   )r   r   r   Zheight_in_emur   r   r   Ú
default_cy&   s    zImagePart.default_cyc                 C  s   | j dur| j jS d| jj S )a?  Filename from which this image part was originally created.

        A generic name, e.g. 'image.png', is substituted if no name is available, for
        example when the image was loaded from an unnamed stream. In that case a default
        extension is applied based on the detected MIME type of the image.
        Nzimage.%s)r   Úfilenamer   Úext©r   r   r   r   r!   /   s    
zImagePart.filenamer   )r   r   c                 C  s   t ||j|j|ƒS )zZReturn an |ImagePart| instance newly created from `image` and assigned
        `partname`.)r
   r   r   )Úclsr   r   r   r   r   Ú
from_image;   s    zImagePart.from_image)Úreturnc                 C  s   | j d u rt | j¡| _ | j S r   )r   r   Z	from_blobr   r#   r   r   r   r   A   s    
zImagePart.imager   )r   r   r   Úpackagec                 C  s   | |||ƒS )zCalled by ``docx.opc.package.PartFactory`` to load an image part from a
        package being opened by ``Document(...)`` call.r   )r$   r   r   r   r'   r   r   r   ÚloadG   s    zImagePart.loadc                 C  s   t  | j¡ ¡ S )z0SHA1 hash digest of the blob of this image part.)ÚhashlibÚsha1r   Ú	hexdigestr#   r   r   r   r*   M   s    zImagePart.sha1)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r    r!   Úclassmethodr%   r   r(   r*   Ú__classcell__r   r   r   r   r
      s"    ÿ


r
   )r/   Ú
__future__r   r)   Útypingr   Zdocx.image.imager   Zdocx.opc.partr   Zdocx.sharedr   r   Zdocx.opc.packager   Zdocx.opc.packurir	   r
   r   r   r   r   Ú<module>   s   