B
    ÞÏÞTl
  ã               @   s`   d Z ddlmZmZmZmZ ddlZddlmZ ddl	m
Z
 ddlmZmZ G dd„ de
ƒZdS )	z9
The proxy class for an image part, and related objects.
é    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literalsN)ÚImage)ÚPart)ÚEmuÚInchesc                   sv   e Zd ZdZd‡ fdd„	Zedd„ ƒZedd„ ƒZed	d
„ ƒZe	dd„ ƒZ
edd„ ƒZe	dd„ ƒZedd„ ƒZ‡  ZS )Ú	ImagePartzp
    An image part. Corresponds to the target part of a relationship with type
    RELATIONSHIP_TYPE.IMAGE.
    Nc                s   t t| ƒ |||¡ || _d S )N)Úsuperr
   Ú__init__Ú_image)ÚselfÚpartnameÚcontent_typeÚblobÚimage)Ú	__class__© úB/var/www/html/venv/lib/python3.7/site-packages/docx/parts/image.pyr      s    zImagePart.__init__c             C   s    | j j}| j j}|| }t|ƒS )z}
        Native 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}d| | }t|ƒS )z}
        Native height of this image, calculated from its height in pixels and
        vertical dots per inch (dpi).
        iàó )r   Ú	px_heightr   r   )r   r   r   Zheight_in_emur   r   r   Ú
default_cy&   s    zImagePart.default_cyc             C   s   | j dk	r| j jS d| jj S )aO  
        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   1   s    	
zImagePart.filenamec             C   s   t ||j|j|ƒS )zl
        Return an |ImagePart| instance newly created from *image* and
        assigned *partname*.
        )r
   r   r   )Úclsr   r   r   r   r   Ú
from_image>   s    zImagePart.from_imagec             C   s   | j d krt | j¡| _ | j S )N)r   r   Z	from_blobr   )r   r   r   r   r   F   s    
zImagePart.imagec             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   Úpackager   r   r   ÚloadL   s    zImagePart.loadc             C   s   t  | j¡ ¡ S )zB
        SHA1 hash digest of the blob of this image part.
        )ÚhashlibÚsha1Z_blobÚ	hexdigest)r   r   r   r   r"   T   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   r   r   r!   Zdocx.image.imager   Zdocx.opc.partr   Zdocx.sharedr   r	   r
   r   r   r   r   Ú<module>   s   