o
    	Ð'fé  ã                   @  s    d Z ddlmZ ddlmZmZ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rFddlmZ dd	lmZ dd
lmZ ddlmZ G dd„ deƒZdS )z |StoryPart| and related objects.é    )Úannotations)ÚIOÚTYPE_CHECKINGÚTuple)ÚRELATIONSHIP_TYPE)ÚXmlPart)Ú	CT_Inline)ÚLengthÚlazyproperty)ÚWD_STYLE_TYPE)ÚImage)ÚDocumentPart)Ú	BaseStylec                   @  sZ   e Zd ZdZd dd„Zd!dd„Zd"dd„Z		d#d$dd„Zed%dd„ƒZ	e
d&dd„ƒZdS )'Ú	StoryPartz÷Base class for story parts.

    A story part is one that can contain textual content, such as the document-part and
    header or footer parts. These all share content behaviors like `.paragraphs`,
    `.add_paragraph()`, `.add_table()` etc.
    Úimage_descriptorústr | IO[bytes]ÚreturnúTuple[str, Image]c                 C  s4   | j }|dus	J ‚| |¡}|  |tj¡}||jfS )a|  Return (rId, image) pair for image identified by `image_descriptor`.

        `rId` is the str key (often like "rId7") for the relationship between this story
        part and the image part, reused if already present, newly created if not.
        `image` is an |Image| instance providing access to the properties of the image,
        such as dimensions and image type.
        N)Ú_packageÚget_or_add_image_partÚ	relate_toÚRTÚIMAGEÚimage)Úselfr   ÚpackageÚ
image_partÚrId© r   úH/home/ubuntu/flask/venv/lib/python3.10/site-packages/docx/parts/story.pyÚget_or_add_image   s
   

zStoryPart.get_or_add_imageÚstyle_idú
str | NoneÚ
style_typer   r   c                 C  ó   | j  ||¡S )zÆReturn the style in this document matching `style_id`.

        Returns the default style for `style_type` if `style_id` is |None| or does not
        match a defined style of `style_type`.
        )Ú_document_partÚ	get_style)r   r!   r#   r   r   r   r&   )   s   zStoryPart.get_styleÚstyle_or_nameúBaseStyle | str | Nonec                 C  r$   )a2  Return str style_id for `style_or_name` of `style_type`.

        Returns |None| if the style resolves to the default style for `style_type` or if
        `style_or_name` is itself |None|. Raises if `style_or_name` is a style of the
        wrong type or names a style not present in the document.
        )r%   Úget_style_id)r   r'   r#   r   r   r   r)   1   s   	zStoryPart.get_style_idNÚwidthúLength | NoneÚheightr   c           
      C  s>   |   |¡\}}| ||¡\}}| j|j}}	t |||	||¡S )z¾Return a newly-created `w:inline` element.

        The element contains the image specified by `image_descriptor` and is scaled
        based on the values of `width` and `height`.
        )r    Úscaled_dimensionsÚnext_idÚfilenamer   Únew_pic_inline)
r   r   r*   r,   r   r   ÚcxÚcyÚshape_idr/   r   r   r   r0   <   s   zStoryPart.new_pic_inlineÚintc                 C  s.   | j  d¡}dd„ |D ƒ}|sdS t|ƒd S )aB  Next available positive integer id value in this story XML document.

        The value is determined by incrementing the maximum existing id value. Gaps in
        the existing id sequence are not filled. The id attribute value is unique in the
        document, without regard to the element type it appears on.
        z//@idc                 S  s   g | ]
}|  ¡ rt|ƒ‘qS r   )Úisdigitr4   )Ú.0Úid_strr   r   r   Ú
<listcomp>U   s    z%StoryPart.next_id.<locals>.<listcomp>é   )Ú_elementÚxpathÚmax)r   Ú
id_str_lstÚused_idsr   r   r   r.   L   s
   zStoryPart.next_idr   c                 C  s   | j }|dus	J ‚|jS )z'|DocumentPart| object for this package.N)r   Úmain_document_part)r   r   r   r   r   r%   Z   s   zStoryPart._document_part)r   r   r   r   )r!   r"   r#   r   r   r   )r'   r(   r#   r   r   r"   )NN)r   r   r*   r+   r,   r+   r   r   )r   r4   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    r&   r)   r0   Úpropertyr.   r
   r%   r   r   r   r   r      s    


ür   N)rC   Ú
__future__r   Útypingr   r   r   Údocx.opc.constantsr   r   Údocx.opc.partr   Údocx.oxml.shaper   Údocx.sharedr	   r
   Údocx.enum.styler   Údocx.image.imager   Údocx.parts.documentr   Údocx.styles.styler   r   r   r   r   r   Ú<module>   s    