o
    `TL                     @   sx   d 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 dd	lmZ G d
d deZG dd deZdS )z?
Run-related proxy objects for python-docx, Run in particular.
    )absolute_importprint_functionunicode_literals   )WD_STYLE_TYPE)WD_BREAK   )Font)InlineShape)Parentedc                       s   e Zd ZdZ fddZejfddZd ddZd	d
 Z	dd Z
edd Zejdd Zdd Zedd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Z  ZS )!RunaO  
    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.
    c                    s&   t t| | | | _ | _| _d S N)superr   __init___r_elementelement)selfrparent	__class__ =D:\Projects\ConvertPro\env\Lib\site-packages\docx\text\run.pyr      s   zRun.__init__c                 C   s^   t jdt jdt jdt jdt jdt jdi| \}}| j }|dur$||_	|dur-||_
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)Z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   Z
break_typetype_r"   brr   r   r   	add_break   s   

zRun.add_breakNc                 C   s$   | j |||}| j| t|S )a  
        Return an |InlineShape| instance containing the image identified by
        *image_path_or_stream*, 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   Zimage_path_or_streamwidthheightinliner   r   r   add_picture1   s   zRun.add_picturec                 C   s   | j   dS )zu
        Add a ``<w:tab/>`` element at the end of the run, which Word
        interprets as a tab character.
        N)r   Z_add_tabr   r   r   r   add_tabB   s   zRun.add_tabc                 C   s   | j |}t|S )a  
        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   texttr   r   r   add_textI   s   zRun.add_textc                 C      | j jS )zK
        Read/write. Causes the text of the run to appear in bold.
        fontboldr+   r   r   r   r4   S   s   zRun.boldc                 C      || j _d S r   r2   r   valuer   r   r   r4   Z      c                 C   s   | j   | S )zw
        Return reference to this run after removing all its content. All run
        formatting is preserved.
        )r   clear_contentr+   r   r   r   r"   ^   s   
z	Run.clearc                 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   r+   r   r   r   r3   f   s   
zRun.fontc                 C   r1   )zs
        Read/write tri-state value. When |True|, causes the text of the run
        to appear in italics.
        r3   italicr+   r   r   r   r;   n   s   z
Run.italicc                 C   r5   r   r:   r6   r   r   r   r;   v   r8   c                 C   s   | j j}| j|tjS )aj  
        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&   Z	get_styler   	CHARACTER)r   style_idr   r   r   r<   z   s   	z	Run.stylec                 C   s   | j |tj}|| j_d S r   )r&   Zget_style_idr   r=   r   r<   )r   Zstyle_or_namer>   r   r   r   r<      s   c                 C   r1   )a  
        String formed by concatenating the text equivalent of each run
        content child element into a Python string. 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. All ``<w:br>``
        elements translate to a single ``\n`` character regardless of their
        type. 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.   r+   r   r   r   r.      s   zRun.textc                 C   r5   r   r?   )r   r.   r   r   r   r.      r8   c                 C   r1   )a  
        The underline style for this |Run|, one of |None|, |True|, |False|,
        or a value from :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.
        r3   	underliner+   r   r   r   rA      s   zRun.underlinec                 C   r5   r   r@   r6   r   r   r   rA      r8   r   )__name__
__module____qualname____doc__r   r   r    r%   r*   r,   r0   propertyr4   setterr"   r3   r;   r<   r.   rA   __classcell__r   r   r   r   r      s<    











r   c                       s    e Zd ZdZ fddZ  ZS )r-   z2
    Proxy object wrapping ``<w:t>`` element.
    c                    s   t t|   || _d S r   )r   r-   r   Z_t)r   Zt_elmr   r   r   r      s   
z_Text.__init__)rB   rC   rD   rE   r   rH   r   r   r   r   r-      s    r-   N)rE   Z
__future__r   r   r   Z
enum.styler   Z	enum.textr   r3   r	   shaper
   sharedr   r   objectr-   r   r   r   r   <module>   s    *