§
    £”jE  ã                  óž   — d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
 ddlmZmZmZmZ  G d„ d¦  «        Zdd„Z G d„ d¦  «        ZdS )z¡Provides objects that can characterize image streams.

That characterization is as to content type and size, as a required step in including
them in a document.
é    )ÚannotationsN)ÚIOÚTuple)ÚUnrecognizedImageError)ÚEmuÚInchesÚLengthÚlazypropertyc                  ó|  ‡ — e Zd ZdZd%ˆ fd„Zed&d
„¦   «         Zed'd„¦   «         Zed„ ¦   «         Z	ed(d„¦   «         Z
ed„ ¦   «         Ze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	 d+d,d„Zed „ ¦   «         Ze	 d-d.d$„¦   «         Zˆ xZS )/ÚImagezgGraphical image stream such as JPEG, PNG, or GIF with properties and methods
    required by ImagePart.ÚblobÚbytesÚfilenameÚstrÚimage_headerÚBaseImageHeaderc                ó€   •— t          t          | ¦  «                             ¦   «          || _        || _        || _        d S ©N)Úsuperr   Ú__init__Ú_blobÚ	_filenameÚ_image_header)Úselfr   r   r   Ú	__class__s       €ú_/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/docx/image/image.pyr   zImage.__init__   s;   ø€ Ý�e�TÑÔ×#Ò#Ñ%Ô%Ð%ØˆŒ
Ø!ˆŒØ)ˆÔÐÐó    Úreturnc                óV   — t          j        |¦  «        }|                      ||¦  «        S )z`Return a new |Image| subclass instance parsed from the image binary contained
        in `blob`.)ÚioÚBytesIOÚ_from_stream)Úclsr   Ústreams      r   Ú	from_blobzImage.from_blob   s)   € õ ”˜DÑ!Ô!ˆØ×Ò ¨Ñ-Ô-Ð-r   Úimage_descriptorústr | IO[bytes]c                ó˜  — t          |t          ¦  «        rr|}t          |d¦  «        5 }|                     ¦   «         }t	          j        |¦  «        }ddd¦  «         n# 1 swxY w Y   t          j                             |¦  «        }n-|}| 	                    d¦  «         |                     ¦   «         }d}|  
                    |||¦  «        S )z‡Return a new |Image| subclass instance loaded from the image file identified
        by `image_descriptor`, a path or file-like object.ÚrbNr   )Ú
isinstancer   ÚopenÚreadr    r!   ÚosÚpathÚbasenameÚseekr"   )r#   r&   r.   Úfr   r$   r   s          r   Ú	from_filezImage.from_file#   sñ   € õ Ð&­Ñ,Ô,ð 
	Ø#ˆDÝ�d˜DÑ!Ô!ð * QØ—v’v‘x”x�Ýœ DÑ)Ô)�ð*ð *ð *ñ *ô *ð *ð *ð *ð *ð *ð *øøøð *ð *ð *ð *õ ”w×'Ò'¨Ñ-Ô-ˆHˆHà%ˆFØ�KŠK˜‰NŒNˆNØ—;’;‘=”=ˆDØˆHØ×Ò ¨¨hÑ7Ô7Ð7s   ¨)AÁA!Á$A!c                ó   — | j         S )zThe bytes of the image 'file'.)r   ©r   s    r   r   z
Image.blob4   s   € ð ŒzÐr   c                ó   — | j         j        S )zIMIME content type for this image, e.g. ``'image/jpeg'`` for a JPEG image.)r   Úcontent_typer4   s    r   r6   zImage.content_type9   s   € ð Ô!Ô.Ð.r   c                óf   — t           j                             | j        ¦  «        d         dd…         S )a  The file extension for the image.

        If an actual one is available from a load filename it is used. Otherwise a
        canonical extension is assigned based on the content type. Does not contain the
        leading period, e.g. 'jpg', not '.jpg'.
        é   N)r-   r.   Úsplitextr   r4   s    r   Úextz	Image.ext>   s*   € õ Œw×Ò ¤Ñ/Ô/°Ô2°1°2°2Ô6Ð6r   c                ó   — | j         S )zpOriginal image file name, if loaded from disk, or a generic filename if
        loaded from an anonymous stream.)r   r4   s    r   r   zImage.filenameH   s   € ð Œ~Ðr   Úintc                ó   — | j         j        S ©z,The horizontal pixel dimension of the image.)r   Úpx_widthr4   s    r   r?   zImage.px_widthN   s   € ð Ô!Ô*Ð*r   c                ó   — | j         j        S ©z*The vertical pixel dimension of the image.)r   Ú	px_heightr4   s    r   rB   zImage.px_heightS   s   € ð Ô!Ô+Ð+r   c                ó   — | j         j        S ©z‡Integer dots per inch for the width of this image.

        Defaults to 72 when not present in the file, as is often the case.
        )r   Úhorz_dpir4   s    r   rE   zImage.horz_dpiX   ó   € ð Ô!Ô*Ð*r   c                ó   — | j         j        S ©zˆInteger dots per inch for the height of this image.

        Defaults to 72 when not present in the file, as is often the case.
        )r   Úvert_dpir4   s    r   rI   zImage.vert_dpi`   rF   r   r   c                ó:   — t          | j        | j        z  ¦  «        S )z}A |Length| value representing the native width of the image, calculated from
        the values of `px_width` and `horz_dpi`.)r   r?   rE   r4   s    r   ÚwidthzImage.widthh   s   € õ �d”m d¤mÑ3Ñ4Ô4Ð4r   c                ó:   — t          | j        | j        z  ¦  «        S )zA |Length| value representing the native height of the image, calculated from
        the values of `px_height` and `vert_dpi`.)r   rB   rI   r4   s    r   ÚheightzImage.heightn   s   € õ �d”n t¤}Ñ4Ñ5Ô5Ð5r   NrK   úint | Length | NonerM   úTuple[Length, Length]c                ó^  — |€|€| j         | j        fS |€?|€J ‚t          |¦  «        t          | j        ¦  «        z  }t          | j         |z  ¦  «        }|€;t          |¦  «        t          | j         ¦  «        z  }t          | j        |z  ¦  «        }t	          |¦  «        t	          |¦  «        fS )a?  (cx, cy) pair representing scaled dimensions of this image.

        The native dimensions of the image are scaled by applying the following rules to
        the `width` and `height` arguments.

        * If both `width` and `height` are specified, the return value is (`width`,
        `height`); no scaling is performed.
        * If only one is specified, it is used to compute a scaling factor that is then
        applied to the unspecified dimension, preserving the aspect ratio of the image.
        * If both `width` and `height` are |None|, the native dimensions are returned.

        The native dimensions are calculated using the dots-per-inch (dpi) value
        embedded in the image, defaulting to 72 dpi if no value is specified, as is
        often the case. The returned values are both |Length| objects.
        )rK   rM   ÚfloatÚroundr   )r   rK   rM   Úscaling_factors       r   Úscaled_dimensionszImage.scaled_dimensionst   s¥   € ð$ ˆ=˜V˜^Ø”:˜tœ{Ð*Ð*àˆ=ØÐ%Ð%Ð%Ý" 6™]œ]­U°4´;Ñ-?Ô-?Ñ?ˆNÝ˜$œ* ~Ñ5Ñ6Ô6ˆEàˆ>Ý" 5™\œ\­E°$´*Ñ,=Ô,=Ñ=ˆNÝ˜4œ;¨Ñ7Ñ8Ô8ˆFå�5‰zŒz�3˜v™;œ;Ð&Ð&r   c                óX   — t          j        | j        ¦  «                             ¦   «         S )z#SHA1 hash digest of the image blob.)ÚhashlibÚsha1r   Ú	hexdigestr4   s    r   rW   z
Image.sha1”   s"   € õ Œ|˜DœJÑ'Ô'×1Ò1Ñ3Ô3Ð3r   r$   ú	IO[bytes]ú
str | Nonec                óR   — t          |¦  «        }|€
d|j        z  } | |||¦  «        S )zhReturn an instance of the |Image| subclass corresponding to the format of the
        image in `stream`.Nzimage.%s)Ú_ImageHeaderFactoryÚdefault_ext)r#   r$   r   r   r   s        r   r"   zImage._from_stream™   s8   € õ +¨6Ñ2Ô2ˆØÐØ! LÔ$<Ñ<ˆHØˆs�4˜ <Ñ0Ô0Ð0r   )r   r   r   r   r   r   )r   r   r   r   )r&   r'   ©r   r   )r   r<   )r   r   )NN)rK   rN   rM   rN   r   rO   r   )r$   rY   r   r   r   rZ   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úclassmethodr%   r2   Úpropertyr   r6   r
   r:   r   r?   rB   rE   rI   rK   rM   rT   rW   r"   Ú__classcell__)r   s   @r   r   r      s  ø€ € € € € ðð ð*ð *ð *ð *ð *ð *ð ð.ð .ð .ñ „[ð.ð ð8ð 8ð 8ñ „[ð8ð  ðð ñ „Xðð ð/ð /ð /ñ „Xð/ð ð7ð 7ñ „\ð7ð ðð ñ „Xðð
 ð+ð +ð +ñ „Xð+ð ð,ð ,ð ,ñ „Xð,ð ð+ð +ð +ñ „Xð+ð ð+ð +ð +ñ „Xð+ð ð5ð 5ð 5ñ „Xð5ð
 ð6ð 6ð 6ñ „Xð6ð PTð'ð 'ð 'ð 'ð 'ð@ ð4ð 4ñ „\ð4ð ð
  $ð	1ð 1ð 1ð 1ñ „[ð1ð 1ð 1ð 1ð 1r   r   r$   rY   c                ó¾   — ddl m} dd„} || ¦  «        }|D ]?\  }}}|t          |¦  «        z   }|||…         }||k    r|                     | ¦  «        c S Œ@t          ‚)zRA |BaseImageHeader| subclass instance that can parse headers of image in `stream`.r   )Ú
SIGNATURESr$   rY   c                óV   — |                       d¦  «         |                      d¦  «        S )Nr   é    )r0   r,   )r$   s    r   Úread_32z$_ImageHeaderFactory.<locals>.read_32¬   s!   € Ø�Š�A‰ŒˆØ�{Š{˜2‰ŒÐr   N©r$   rY   )Ú
docx.imagerg   ÚlenÚfrom_streamr   )	r$   rg   rj   Úheaderr#   ÚoffsetÚsignature_bytesÚendÚfound_bytess	            r   r\   r\   ¨   s›   € à%Ð%Ð%Ð%Ð%Ð%ðð ð ð ð ˆW�V‰_Œ_€FØ(2ð +ð +Ñ$ˆˆV�_Ø•s˜?Ñ+Ô+Ñ+ˆØ˜V C˜ZÔ(ˆØ˜/Ò)Ð)Ø—?’? 6Ñ*Ô*Ð*Ð*Ð*ð *å
 Ð r   c                  ó¢   — e Zd ZdZdd„Zedd
„¦   «         Zedd„¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	ed„ ¦   «         Z
ed„ ¦   «         ZdS )r   z>Base class for image header subclasses like |Jpeg| and |Tiff|.r?   r<   rB   rE   rI   c                ó>   — || _         || _        || _        || _        d S r   )Ú	_px_widthÚ
_px_heightÚ	_horz_dpiÚ	_vert_dpi)r   r?   rB   rE   rI   s        r   r   zBaseImageHeader.__init__¼   s"   € Ø!ˆŒØ#ˆŒØ!ˆŒØ!ˆŒˆˆr   r   r   c                ó$   — d}t          |¦  «        ‚)zDAbstract property definition, must be implemented by all subclasses.zNcontent_type property must be implemented by all subclasses of BaseImageHeader©ÚNotImplementedError)r   Úmsgs     r   r6   zBaseImageHeader.content_typeÂ   s   € ð _ˆÝ! #Ñ&Ô&Ð&r   c                ó    — t          d¦  «        ‚)z�Default filename extension for images of this type.

        An abstract property definition, must be implemented by all subclasses.
        zMdefault_ext property must be implemented by all subclasses of BaseImageHeaderr{   r4   s    r   r]   zBaseImageHeader.default_extÈ   s   € õ "Ø[ñ
ô 
ð 	
r   c                ó   — | j         S r>   )rv   r4   s    r   r?   zBaseImageHeader.px_widthÒ   s   € ð Œ~Ðr   c                ó   — | j         S rA   )rw   r4   s    r   rB   zBaseImageHeader.px_height×   s   € ð ŒÐr   c                ó   — | j         S rD   )rx   r4   s    r   rE   zBaseImageHeader.horz_dpiÜ   ó   € ð Œ~Ðr   c                ó   — | j         S rH   )ry   r4   s    r   rI   zBaseImageHeader.vert_dpiä   r‚   r   N)r?   r<   rB   r<   rE   r<   rI   r<   r^   )r_   r`   ra   rb   r   rd   r6   r]   r?   rB   rE   rI   © r   r   r   r   ¹   sÚ   € € € € € ØHÐHð"ð "ð "ð "ð ð'ð 'ð 'ñ „Xð'ð
 ð
ð 
ð 
ñ „Xð
ð ðð ñ „Xðð ðð ñ „Xðð ðð ñ „Xðð ðð ñ „Xðð ð r   r   rk   )rb   Ú
__future__r   rV   r    r-   Útypingr   r   Údocx.image.exceptionsr   Údocx.sharedr   r   r	   r
   r   r\   r   r„   r   r   ú<module>r‰      s  ððð ð #Ð "Ð "Ð "Ð "Ð "à €€€Ø 	€	€	€	Ø 	€	€	€	Ø Ð Ð Ð Ð Ð Ð Ð à 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9ðS1ð S1ð S1ð S1ð S1ñ S1ô S1ð S1ðl!ð !ð !ð !ð"1ð 1ð 1ð 1ð 1ñ 1ô 1ð 1ð 1ð 1r   