B
    `ÊæT  ã               @   s|   d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
 G dd„ deƒZG dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZdS )z5
Custom element classes related to text runs (CT_R).
é   )Úqn)Ú
ST_BrClearÚ	ST_BrType)ÚBaseOxmlElementÚOptionalAttributeÚ
ZeroOrMoreÚ	ZeroOrOnec               @   s$   e Zd ZdZedeƒZedeƒZdS )ÚCT_BrzP
    ``<w:br>`` element, indicating a line, page, or column break in a run.
    zw:typezw:clearN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Útyper   Úclear© r   r   úD/var/www/html/venv/lib/python3.7/site-packages/docx/oxml/text/run.pyr	      s   
r	   c               @   s”   e Zd ZdZedƒZedƒZedƒZedƒZ	edƒZ
edƒZdd	„ Zd
d„ Zdd„ Zdd„ Zedd„ ƒZejdd„ ƒZedd„ ƒZejdd„ ƒZdS )ÚCT_RzJ
    ``<w:r>`` element, containing the properties and text for a run.
    zw:rPrzw:tzw:brzw:crzw:tabz	w:drawingc             C   s   |   d|¡ |S )Né    )Úinsert)ÚselfÚrPrr   r   r   Ú_insert_rPr!   s    zCT_R._insert_rPrc             C   s4   | j |d}t| ¡ ƒt|ƒk r0| tdƒd¡ |S )zK
        Return a newly added ``<w:t>`` element containing *text*.
        )Útextz	xml:spaceZpreserve)Z_add_tÚlenÚstripÚsetr   )r   r   Útr   r   r   Úadd_t%   s    z
CT_R.add_tc             C   s   |   ¡ }| |¡ |S )zˆ
        Return a newly appended ``CT_Drawing`` (``<w:drawing>``) child
        element having *inline_or_anchor* as its child.
        )Z_add_drawingÚappend)r   Zinline_or_anchorÚdrawingr   r   r   Úadd_drawing.   s    
zCT_R.add_drawingc             C   s>   | j dk	r| dd… n
| dd… }x|D ]}|  |¡ q(W dS )zV
        Remove all child elements except the ``<w:rPr>`` element if present.
        Né   )r   Úremove)r   Zcontent_child_elmsÚchildr   r   r   Úclear_content7   s    "
zCT_R.clear_contentc             C   s   | j }|dkrdS |jS )z
        String contained in w:val attribute of <w:rStyle> grandchild, or
        |None| if that element is not present.
        N)r   Ústyle)r   r   r   r   r   r%   ?   s    z
CT_R.stylec             C   s   |   ¡ }||_dS )z
        Set the character style of this <w:r> element to *style*. If *style*
        is None, remove the style element.
        N)Zget_or_add_rPrr%   )r   r%   r   r   r   r   r%   J   s    c             C   sv   d}xl| D ]d}|j tdƒkr8|j}||dk	r0|nd7 }q
|j tdƒkrP|d7 }q
|j tdƒtdƒfkr
|d7 }q
W |S )	z­
        A string representing the textual content of this run, with content
        child elements like ``<w:tab/>`` translated to their Python
        equivalent.
        Ú zw:tNzw:tabú	zw:brzw:crÚ
)Útagr   r   )r   r   r#   Zt_textr   r   r   r   S   s    

z	CT_R.textc             C   s   |   ¡  t | |¡ d S )N)r$   Ú_RunContentAppenderÚappend_to_run_from_text)r   r   r   r   r   r   e   s    N)r
   r   r   r   r   r   r   r   ÚbrZcrÚtabr   r   r   r    r$   Úpropertyr%   Úsetterr   r   r   r   r   r      s   			r   c               @   s   e Zd ZdZdS )ÚCT_TextzN
    ``<w:t>`` element, containing a sequence of characters within a run.
    N)r
   r   r   r   r   r   r   r   r0   k   s   r0   c               @   s<   e Zd ZdZdd„ Zedd„ ƒZdd„ Zdd	„ Zd
d„ Z	dS )r*   a¢  
    Service object that knows how to translate a Python string into run
    content elements appended to a specified ``<w:r>`` element. Contiguous
    sequences of regular characters are appended in a single ``<w:t>``
    element. Each tab character ('	') causes a ``<w:tab/>`` element to be
    appended. Likewise a newline or carriage return character ('
', '')
    causes a ``<w:cr>`` element to be appended.
    c             C   s   || _ g | _d S )N)Ú_rÚ_bfr)r   Úrr   r   r   Ú__init__z   s    z_RunContentAppender.__init__c             C   s   | |ƒ}|  |¡ dS )zº
        Create a "one-shot" ``_RunContentAppender`` instance and use it to
        append the run content elements corresponding to *text* to the
        ``<w:r>`` element *r*.
        N)Úadd_text)Úclsr3   r   Zappenderr   r   r   r+   ~   s    z+_RunContentAppender.append_to_run_from_textc             C   s$   x|D ]}|   |¡ qW |  ¡  dS )z|
        Append the run content elements corresponding to *text* to the
        ``<w:r>`` element of this instance.
        N)Úadd_charÚflush)r   r   Úcharr   r   r   r5   ˆ   s    
z_RunContentAppender.add_textc             C   sH   |dkr|   ¡  | j ¡  n(|dkr8|   ¡  | j ¡  n| j |¡ dS )aX  
        Process the next character of input through the translation finite
        state maching (FSM). There are two possible states, buffer pending
        and not pending, but those are hidden behind the ``.flush()`` method
        which must be called at the end of text to ensure any pending
        ``<w:t>`` element is written.
        r'   z
N)r8   r1   Zadd_tabZadd_brr2   r   )r   r9   r   r   r   r7   ‘   s    z_RunContentAppender.add_charc             C   s,   d  | j¡}|r| j |¡ | jd d …= d S )Nr&   )Újoinr2   r1   r   )r   r   r   r   r   r8   ¢   s    z_RunContentAppender.flushN)
r
   r   r   r   r4   Úclassmethodr+   r5   r7   r8   r   r   r   r   r*   q   s   
	r*   N)r   Únsr   Zsimpletypesr   r   Zxmlchemyr   r   r   r   r	   r   r0   Úobjectr*   r   r   r   r   Ú<module>   s   U