a
    V$c!                     @   s   d dl mZmZmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlZd dlmZmZmZ d dlm  mZ edddddddddddddddddddddddddddZded< d	d
 ZdddZdd ZG dd deZ dddZ!dS )    )divisionabsolute_importwith_statementprint_functionunicode_literals)PY2
basestringbchrbordchropenpystrrangeroundstrtobytesunicodeN)DISPLAYABLE	PARAGRAPHTAGTF)alphaaltartdoneimagepwfastbiuaplainfontcoloroutlinecolorsizenoaltnwsrtrbkcpsspacevspace c           	   
   C   sj  t t}tjj}|r|| tjj}|r<|t |d zt	t
| }W n. ty| } z|jd W  Y d}~S d}~0 0 g }|D ]\}}|tkrq|d dkrq|ddkr|d|d }|r|d dkr|sd|   S |d |d	d krd
||d f   S |  q||vr4d|   S || r|| q|rfdddd |D  S dS )z
    :doc: lint

    Checks the text tags in s for correctness. Returns an error string if there is
    an error, or None if there is no error.
    Fr   N#=/z4Close text tag '%s' does not match an open text tag.   z6Close text tag '%s' does not match open text tag '%s'.zText tag '%s' is not known.z?One or more text tags were left open at the end of the string: z, c                 S   s   g | ]}d | d  qS )' ).0r   r7   r7   renpy/text\extras.py
<listcomp>|       z#check_text_tags.<locals>.<listcomp>)dict	text_tagsrenpyconfigcustom_text_tagsupdateself_closing_custom_text_tagsfromkeystextsupporttokenizer   	Exceptionargsr   findpopappendjoin)	r)   all_tagscustom_tagsself_closing_custom_tagstokense	tag_stacktypetextr7   r7   r9   check_text_tagsF   sB    
 
rT   c                 C   s   |du r|du rt d|dur0|dur0t dtt| }g }|D ]\}}|tkrb|d qF|tkr|dd }|r|d dkr|dd }|dur||v r|d| d	  q||vr|d| d	  qF||dd
 qFd	|S )al  
    :doc: text_utility

    Returns a copy of `s` with the text tags filtered. Exactly one of the `allow` and `deny` keyword
    arguments must be given.

    `allow`
        A set of tags that are allowed. If a tag is not in this list, it is removed.

    `deny`
        A set of tags that are denied. If a tag is not in this list, it is kept in the string.
    NzUOnly one of the allow and deny keyword arguments should be given to filter_text_tags.
r2   r   r4   r5   {}z{{r0   )
rF   rD   rE   r   r   rJ   r   	partitionreplacerK   )r)   allowdenyrO   rv	tokentyperS   kindr7   r7   r9   filter_text_tags   s(    r_   c                 C   s   t t| }tjjs*tjjs*tjjdur:tjjj	
|}g }t }|D ]\}}|tkrd|d qH|tkr|dd }|dr|dd }d}nd}|tjjv r|r|| q|| qH|tkr||  qH|sH|| qHd	|S )
z
    Returns a copy of `s` with the contents of text tags that shouldn't be in
    alt text filtered. This returns just the text to say, with no text tags
    at all in it.
    NrU   r2   r   r4   r5   TFr0   )rD   rE   r   r>   r?   r@   rB   replace_textrS   Textapply_custom_tagssetr   rJ   r   rX   
startswithtts_filter_tagsdiscardaddr   _ttsrK   )r)   rO   r\   activer]   rS   r^   endr7   r7   r9   filter_alt_text   s.    
rk   c                   @   s&   e Zd ZdZd	ddZdZdd ZdS )
ParameterizedTexta  
    :name: ParameterizedText
    :doc: text

    This is a displayable that can be shown with an additional string
    parameter, which then shows that string as if it was an image.
    This is usually used as part of the pre-defined ``text`` image.

    For example, one can do::

        show text "Hello, World" at truecenter
        with dissolve
        pause 1
        hide text
        with dissolve

    You can use ParameterizedText directly to define similar images with
    different style properties. For example, one can write::

        image top_text = ParameterizedText(xalign=0.5, yalign=0.0)

        label start:
            show top_text "This text is shown at the center-top of the screen"
    defaultc                 K   s   || _ || _d S )N)style
properties)selfrn   ro   r7   r7   r9   __init__   s    zParameterizedText.__init__Tc                 C   sz   |j r"tjjjdd| ji| jS t|jdkrDtdd	|j
 d	|j}tj|}tjjj|fd| ji| jS )Nr0   rn   r   z%'%s' takes a single string parameter. )r0   )lintr>   rS   ra   rn   ro   lenrG   rF   rK   namepythonpy_eval)rp   rG   paramstringr7   r7   r9   
_duplicate   s    zParameterizedText._duplicateN)rm   )__name__
__module____qualname____doc__rq   _duplicatablerz   r7   r7   r7   r9   rl      s   
rl   N   c           	      C   s   ddl }g }t| D ]t}||}|dks2|dkr8d}n|dkrP|rJd}qTd}nd}t }t||_d|_d|_||_	||_
|| qt|dd	 tjj||d |d d t|S )
a  
    Wraps the unicode string `s`, and returns a list of strings.

    `width`
        The number of half-width characters that fit on a line.
    `asian`
        True if we should make ambiguous width characters full-width, as is
        done in Asian encodings.
    r   NFW   A
   F   )unicodedatar   east_asian_widthrD   Glyphord	characterascentline_spacingwidthadvancerJ   annotate_unicoder>   rS   texwraplinebreak_texlinebreak_list)	r)   r   asianr   glyphsceawgwidthgr7   r7   r9   textwrap  s*    

r   )NN)r   F)"
__future__r   r   r   r   r   renpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   r>   renpy.text.textsupportr   r   r   rS   rD   r<   r=   rT   r_   rk   objectrl   r   r7   r7   r7   r9   <module>   sL   8;
.+.