a
    ]øj*(  ã                   @  sú   d Z ddlmZ ddlmZ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 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 ddlmZ erØddlmZ ddlmZ ddl m!Z!m"Z" ddlm#Z# G dd„ deƒZ$G dd„ dƒZ%dS )z=Run-related proxy objects for python-docx, Run in particular.é    )Úannotations)ÚIOÚTYPE_CHECKINGÚIteratorÚcast)ÚDrawing)ÚWD_STYLE_TYPE)ÚWD_BREAK)Ú
CT_Drawing)ÚCT_LastRenderedPageBreak)ÚInlineShape)Ú
StoryChild)ÚCharacterStyle)ÚFont)ÚRenderedPageBreakN)ÚWD_UNDERLINE)ÚCT_RÚCT_Text)ÚLengthc                      sx  e Zd ZdZdddœ‡ fdd„Zejfddœd	d
„Zd>dddddœdd„Zddœdd„Z	ddœdd„Z
eddœdd„ƒZejddœdd„ƒZdd „ Zed!dœd"d#„ƒZed$dœd%d&„ƒZeddœd'd(„ƒZejddœd)d(„ƒZd*dœd+d,„Zd d-dd.œd/d0„Zed1dœd2d3„ƒZejd4d5œd6d3„ƒZeddœd7d8„ƒZejddœd9d8„ƒZed:dœd;d<„ƒZejd:dœd=d<„ƒZ‡  ZS )?ÚRunaI  Proxy object wrapping `<w:r>` element.

    Several of the properties on Run take a tri-state value, |True|, |False|, or |None|.
    |True| and |False| correspond to on and off respectively. |None| indicates the
    property is not specified directly on the run and its effective value is taken from
    the style hierarchy.
    r   zt.ProvidesStoryPart)ÚrÚparentc                   s"   t ƒ  |¡ | | _ | _| _d S ©N)ÚsuperÚ__init__Ú_rÚ_elementÚelement)Úselfr   r   ©Ú	__class__© úI/var/www/html/assistant/venv/lib/python3.9/site-packages/docx/text/run.pyr   "   s    zRun.__init__r	   )Ú
break_typec                 C  sZ   t jdt jdt jdt jdt jdt jdi| \}}| j ¡ }|durH||_	|durV||_
dS )a	  Add a break element of `break_type` to this run.

        `break_type` can take the values `WD_BREAK.LINE`, `WD_BREAK.PAGE`, and
        `WD_BREAK.COLUMN` where `WD_BREAK` is imported from `docx.enum.text`.
        `break_type` defaults to `WD_BREAK.LINE`.
        )NN)ÚpageN)ÚcolumnN)ÚtextWrappingÚleft)r&   Úright)r&   ÚallN)r	   ÚLINEZPAGEZCOLUMNZLINE_CLEAR_LEFTZLINE_CLEAR_RIGHTZLINE_CLEAR_ALLr   Zadd_brÚtypeÚclear)r   r#   Útype_r,   Úbrr!   r!   r"   Ú	add_break&   s    úù
zRun.add_breakNzstr | IO[bytes]zint | Length | Noner   )Úimage_path_or_streamÚwidthÚheightÚreturnc                 C  s$   | j  |||¡}| j |¡ t|ƒS )aÑ  Return |InlineShape| containing image identified by `image_path_or_stream`.

        The picture is added to the end of this run.

        `image_path_or_stream` can be a path (a string) or a file-like object containing
        a binary image.

        If neither width nor height is specified, the picture appears at
        its native size. 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. The native size of the picture is calculated using the dots-
        per-inch (dpi) value specified in the image file, defaulting to 72 dpi if no
        value is specified, as is often the case.
        )ÚpartZnew_pic_inliner   Zadd_drawingr   )r   r0   r1   r2   Úinliner!   r!   r"   Úadd_picture;   s    zRun.add_pictureÚNone)r3   c                 C  s   | j  ¡  dS )zcAdd a ``<w:tab/>`` element at the end of the run, which Word interprets as a
        tab character.N)r   Úadd_tab©r   r!   r!   r"   r8   S   s    zRun.add_tabÚstr)Útextc                 C  s   | j  |¡}t|ƒS )zþReturns a newly appended |_Text| object (corresponding to a new ``<w:t>``
        child element) to the run, containing `text`.

        Compare with the possibly more friendly approach of assigning text to the
        :attr:`Run.text` property.
        )r   Zadd_tÚ_Text)r   r;   Útr!   r!   r"   Úadd_textX   s    zRun.add_textzbool | Nonec                 C  s   | j jS )a  Read/write tri-state value.

        When |True|, causes the text of the run to appear in bold face. When |False|,
        the text unconditionally appears non-bold. When |None| the bold setting for this
        run is inherited from the style hierarchy.
        ©ÚfontÚboldr9   r!   r!   r"   rA   b   s    zRun.bold)Úvaluec                 C  s   || j _d S r   r?   ©r   rB   r!   r!   r"   rA   l   s    c                 C  s   | j  ¡  | S )zoReturn reference to this run after removing all its content.

        All run formatting is preserved.
        )r   Úclear_contentr9   r!   r!   r"   r,   p   s    
z	Run.clearÚboolc                 C  s   t | jjƒS )a¯  `True` when one or more rendered page-breaks occur in this run.

        Note that "hard" page-breaks inserted by the author are not included. A hard
        page-break gives rise to a rendered page-break in the right position so if those
        were included that page-break would be "double-counted".

        It would be very rare for multiple rendered page-breaks to occur in a single
        run, but it is possible.
        )rE   r   ZlastRenderedPageBreaksr9   r!   r!   r"   Úcontains_page_breakx   s    zRun.contains_page_breakr   c                 C  s
   t | jƒS )z{The |Font| object providing access to the character formatting properties for
        this run, such as font name and size.)r   r   r9   r!   r!   r"   r@   …   s    zRun.fontc                 C  s   | j jS )a	  Read/write tri-state value.

        When |True|, causes the text of the run to appear in italics. When |False|, the
        text unconditionally appears non-italic. When |None| the italic setting for this
        run is inherited from the style hierarchy.
        ©r@   Úitalicr9   r!   r!   r"   rH   ‹   s    z
Run.italicc                 C  s   || j _d S r   rG   rC   r!   r!   r"   rH   •   s    z+Iterator[str | Drawing | RenderedPageBreak]c                 c  sR   | j jD ]D}t|tƒr|V  qt|tƒr6t|| ƒV  qt|tƒrt|| ƒV  qdS )a'  Generate the content-items in this run in the order they appear.

        NOTE: only content-types currently supported by `python-docx` are generated. In
        this version, that is text and rendered page-breaks. Drawing is included but
        currently only provides access to its XML element (CT_Drawing) on its
        `._drawing` attribute. `Drawing` attributes and methods may be expanded in
        future releases.

        There are a number of element-types that can appear inside a run, but most of
        those (w:br, w:cr, w:noBreakHyphen, w:t, w:tab) have a clear plain-text
        equivalent. Any contiguous range of such elements is generated as a single
        `str`. Rendered page-break and drawing elements are generated individually. Any
        other elements are ignored.
        N)r   Zinner_content_itemsÚ
isinstancer:   r   r   r
   r   )r   Úitemr!   r!   r"   Úiter_inner_content™   s    


zRun.iter_inner_contentÚint)Úlast_runÚ
comment_idr3   c                 C  s   | j  |¡ |j  |¡ dS )zªMark the range of runs from this run to `last_run` (inclusive) as belonging to a comment.

        `comment_id` identfies the comment that references this range.
        N)r   Z insert_comment_range_start_aboveZ,insert_comment_range_end_and_reference_below)r   rM   rN   r!   r!   r"   Úmark_comment_range°   s    zRun.mark_comment_ranger   c                 C  s   | j j}tt| j |tj¡ƒS )aa  Read/write.

        A |CharacterStyle| object representing the character style applied to this run.
        The default character style for the document (often `Default Character Font`) is
        returned if the run has no directly-applied character style. Setting this
        property to |None| removes any directly-applied character style.
        )r   Ústyler   r   r4   Ú	get_styler   Ú	CHARACTER)r   Ústyle_idr!   r!   r"   rP   ¼   s    	z	Run.stylezstr | CharacterStyle | None)Ústyle_or_namec                 C  s   | j  |tj¡}|| j_d S r   )r4   Zget_style_idr   rR   r   rP   )r   rT   rS   r!   r!   r"   rP   È   s    c                 C  s   | j jS )a"  String formed by concatenating the text equivalent of each run.

        Each `<w:t>` element adds the text characters it contains. A `<w:tab/>` element
        adds a `\t` character. A `<w:cr/>` or `<w:br>` element each add a `\n`
        character. Note that a `<w:br>` element can indicate a page break or column
        break as well as a line break. Only line-break `<w:br>` elements translate to
        a `\n` character. Others are ignored. All other content child elements, such as
        `<w:drawing>`, are ignored.

        Assigning text to this property has the reverse effect, translating each `\t`
        character to a `<w:tab/>` element and each `\n` or `\r` character to a
        `<w:cr/>` element. Any existing run content is replaced. Run formatting is
        preserved.
        ©r   r;   r9   r!   r!   r"   r;   Í   s    zRun.textc                 C  s   || j _d S r   rU   )r   r;   r!   r!   r"   r;   ß   s    zbool | WD_UNDERLINE | Nonec                 C  s   | j jS )a«  The underline style for this |Run|.

        Value is one of |None|, |True|, |False|, or a member of :ref:`WdUnderline`.

        A value of |None| indicates the run has no directly-applied underline value and
        so will inherit the underline value of its containing paragraph. Assigning
        |None| to this property removes any directly-applied underline value.

        A value of |False| indicates a directly-applied setting of no underline,
        overriding any inherited value.

        A value of |True| indicates single underline.

        The values from :ref:`WdUnderline` are used to specify other outline styles such
        as double, wavy, and dotted.
        ©r@   Ú	underliner9   r!   r!   r"   rW   ã   s    zRun.underlinec                 C  s   || j _d S r   rV   rC   r!   r!   r"   rW   ÷   s    )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   r*   r/   r6   r8   r>   ÚpropertyrA   Úsetterr,   rF   r@   rH   rK   rO   rP   r;   rW   Ú__classcell__r!   r!   r   r"   r      sF     ü
		r   c                      s&   e Zd ZdZddœ‡ fdd„Z‡  ZS )r<   z&Proxy object wrapping `<w:t>` element.r   )Út_elmc                   s   t t| ƒ ¡  || _d S r   )r   r<   r   Z_t)r   r_   r   r!   r"   r   ÿ   s    z_Text.__init__)rX   rY   rZ   r[   r   r^   r!   r!   r   r"   r<   ü   s   r<   )&r[   Ú
__future__r   Útypingr   r   r   r   Zdocx.drawingr   Zdocx.enum.styler   Zdocx.enum.textr	   Zdocx.oxml.drawingr
   Zdocx.oxml.text.pagebreakr   Z
docx.shaper   Zdocx.sharedr   Zdocx.styles.styler   Zdocx.text.fontr   Zdocx.text.pagebreakr   Z
docx.typesÚtypesr=   r   Zdocx.oxml.text.runr   r   r   r   r<   r!   r!   r!   r"   Ú<module>   s(    d