
    hi*(                       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e          Z$ G 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                      e Zd ZdZd3 fdZej        fd4d	Z	 	 d5d6dZd7dZ	d8dZ
ed9d            Zej        d:d            Zd Zed;d            Zed<d             Zed9d!            Zej        d:d"            Zd=d$Zd>d(Zed?d*            Zej        d@d-            ZedAd.            Zej        d8d/            ZedBd1            Zej        dCd2            Z xZS )D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.
    rr   parentt.ProvidesStoryPartc                t    t                                          |           |x| _        x| _        | _        d S N)super__init___r_elementelement)selfr   r   	__class__s      e/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/docx/text/run.pyr   zRun.__init__"   s4       1222$-$,,,    
break_typer
   c                   t           j        dt           j        dt           j        dt           j        dt           j        dt           j        di|         \  }}| j                                        }|||_	        |	||_
        dS 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
   LINEPAGECOLUMNLINE_CLEAR_LEFTLINE_CLEAR_RIGHTLINE_CLEAR_ALLr   add_brtypeclear)r"   r&   type_r7   brs        r$   	add_breakzRun.add_break&   s     M<M>O-$&>%'@#%<
 u W^^BGBHHH r%   Nimage_path_or_streamstr | IO[bytes]widthint | Length | Noneheightreturnr   c                    | 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.
        )partnew_pic_inliner   add_drawingr   )r"   r;   r=   r?   inlines        r$   add_picturezRun.add_picture;   sB    ( ))*>vNNF###6"""r%   Nonec                8    | 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"   s    r$   rI   zRun.add_tabS   s     	r%   textstrc                T    | j                             |          }t          |          S )zReturns 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   add_t_Text)r"   rK   ts      r$   add_textzRun.add_textX   s"     GMM$Qxxr%   bool | Nonec                    | 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boldrJ   s    r$   rV   zRun.boldb   s     y~r%   valuec                    || j         _        d S r   rT   r"   rW   s     r$   rV   zRun.boldl   s    	r%   c                8    | j                                          | S )zoReturn reference to this run after removing all its content.

        All run formatting is preserved.
        )r   clear_contentrJ   s    r$   r7   z	Run.clearp   s    
 	r%   boolc                4    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.
        )r\   r   lastRenderedPageBreaksrJ   s    r$   contains_page_breakzRun.contains_page_breakx   s     DG2333r%   r   c                *    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    rJ   s    r$   rU   zRun.font   s     DM"""r%   c                    | 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.
        rU   italicrJ   s    r$   rc   z
Run.italic   s     yr%   c                    || j         _        d S r   rb   rY   s     r$   rc   z
Run.italic   s     	r%   +Iterator[str | Drawing | RenderedPageBreak]c              #     K   | j         j        D ]k}t          |t                    r|V  t          |t                    rt          ||           V  Dt          |t                    rt          ||           V  ld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   inner_content_items
isinstancerL   r   r   r   r   )r"   items     r$   iter_inner_contentzRun.iter_inner_content   s       G/ 	* 	*D$$$ *



D":;; *'d333333D*-- *dD)))))	* 	*r%   last_run
comment_idintc                n    | j                             |           |j                             |           dS )zMark 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    insert_comment_range_start_above,insert_comment_range_end_and_reference_below)r"   rk   rl   s      r$   mark_comment_rangezRun.mark_comment_range   s8     	00<<< 	@@LLLLLr%   r   c                    | 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   rB   	get_styler	   	CHARACTER)r"   style_ids     r$   rs   z	Run.style   s2     7=NDI$7$7-BY$Z$Z[[[r%   style_or_namestr | CharacterStyle | Nonec                h    | j                             |t          j                  }|| j        _        d S r   )rB   get_style_idr	   ru   r   rs   )r"   rw   rv   s      r$   rs   z	Run.style   s)    9))-9PQQ r%   c                    | 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   rK   rJ   s    r$   rK   zRun.text   s      w|r%   c                    || j         _        d S r   r|   )r"   rK   s     r$   rK   zRun.text   s    r%   bool | WD_UNDERLINE | Nonec                    | 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.
        rU   	underlinerJ   s    r$   r   zRun.underline   s    $ y""r%   c                    || j         _        d S r   r   rY   s     r$   r   zRun.underline   s    #	r%   )r   r   r   r   )r&   r
   r(   )r;   r<   r=   r>   r?   r>   r@   r   )r@   rG   )rK   rL   )r@   rR   )rW   rR   )r@   r\   )r@   r   )r@   re   )rk   r   rl   rm   r@   rG   )r@   r   )rw   rx   )r@   rL   )r@   r~   )rW   r~   )__name__
__module____qualname____doc__r   r
   r/   r:   rF   rI   rQ   propertyrV   setterr7   r_   rU   rc   rj   rq   rs   rK   r   __classcell__r#   s   @r$   r   r      s{        3 3 3 3 3 3 08}     0 &*&*	# # # # #0   
       X 
[   [   
4 
4 
4 X
4 # # # X#
       X  ]! ! ! ]!* * * *.
M 
M 
M 
M 	\ 	\ 	\ X	\ \! ! ! \!    X" 
[   [ # # # X#& $ $ $ $ $ $ $ $r%   r   c                  $     e Zd ZdZd fdZ xZS )rO   z&Proxy object wrapping `<w:t>` element.t_elmr   c                d    t          t          |                                            || _        d S r   )r   rO   r   _t)r"   r   r#   s     r$   r   z_Text.__init__   s*    eT##%%%r%   )r   r   )r   r   r   r   r   r   r   s   @r$   rO   rO      sC        00         r%   rO   )&r   
__future__r   typingr   r   r   r   docx.drawingr   docx.enum.styler	   docx.enum.textr
   docx.oxml.drawingr   docx.oxml.text.pagebreakr   
docx.shaper   docx.sharedr   docx.styles.styler   docx.text.fontr   docx.text.pagebreakr   
docx.typestypesrP   r   docx.oxml.text.runr   r   r   r   rO    r%   r$   <module>r      s   C C " " " " " " 4 4 4 4 4 4 4 4 4 4 4 4             ) ) ) ) ) ) # # # # # # ( ( ( ( ( ( = = = = = = " " " " " " " " " " " " , , , , , ,       1 1 1 1 1 1 #++++++00000000""""""`$ `$ `$ `$ `$* `$ `$ `$F         r%   