3
ݸW_                 @   sl  d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZ dd	lmZmZ ejd
Zd8ddZedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zed d! Zed"d# Zed$d% Zed&d' Zed(d) Zed*d+ Z ed,d- Z!ed.d/ Z"ed0d1 Z#ed2d3 Z$ed4d5 Z%ed6d7 Z&dS )9z
    weasyprint.tests.test_text
    --------------------------

    Test the text layout.

    :copyright: Copyright 2011-2014 Simon Sapin and contributors, see AUTHORS.
    :license: BSD, see LICENSE for details.

    )divisionunicode_literals   )	StyleDict)INITIAL_VALUES)split_first_line   )parsebody_children)FONTSassert_no_logsz, Nc             K   s.   t dddddgitj|}t| |d|ddS )	z4Wrapper for split_first_line() creating a StyleDict.font_familyzNimbus Mono LzLiberation MonoZFreeMonoZ	monospaceFN)Zhinting	max_width
line_width)r   r   Zupdated_copyr   )textwidthstyle r   Z/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/weasyprint/tests/test_text.py	make_text   s    r   c              C   sZ   xTdD ]L\} }d}t || tdd\}}}}}}||d |ksBt|d	 |kstqW dS )z2Test the line break for various fixed-width lines.d   text for test-   is a text for testzThis is a text for test   )r   	font_sizeNr   r   r   r   r   )r   r   )r   r   AssertionError)r   	remainingr   _length	resume_atr   r   r   test_line_content#   s    r#   c              C   s8   t d\} } } }} } t d\} } } }} } ||k s4tdS )z!Test the auto-fit width of lines.z	some textzsome text some textN)r   r   )r    width_1width_2r   r   r   test_line_with_any_width/   s    r&   c              C   s   d} t | ddd\}}}}}}|dks*tt | ddd\}}}}}}| |d dksXtt | dtdd	\}}}}}}| |d d
kstdS )zTest the line breaking.zThis is a text for testZ   r   )r   Nr   zis a text for testr   )r   r   ztext for test)r   r   r   )stringr    r"   r   r   r   test_line_breaking7   s    r)   c              C   sP   d} t | ddd\}}}}}}t | ddd\}}}}}}|| || k sLtdS )z0Test the font size impact on the text dimension.z3This is a text for test. This is a test for text.py      )r      N)r   r   )r(   r    r$   Zheight_1r%   Zheight_2r   r   r   test_text_dimensionH   s    r-   c              C   sH   t d\} t| \}|j\}|j s(t|jdks6t|jdksDtdS )z&Test a text with a font size set to 0.zi
        <style>
            p { font-size: 0; }
        </style>
        <p>test font size zero</p>
    r   N)r	   r
   childrenr   height)page	paragraphliner   r   r   test_text_font_size_zeroR   s    
r3   c              C   s   t d\} t| \}|j\}|j\}}}}}|jdks:t|jdksHt|jdksVt|jdksdt|j\}}}	|j\}|	j\}	|jdkst|jdkst|jdkst|	jdkst|j\}
|
jdkstd	S )
z.Test a text with inlines separated by a space.zE
        <p>start <i><b>bi1</b> <b>bi2</b></i> <b>b1</b> end</p>
    zstart  r   z endbi1bi2b1N)r	   r
   r.   r   r   r   )r0   r1   r2   startispacebendr5   r6   r7   r   r   r   test_text_spaced_inlinesc   s$    
r=   c              C   sL   t d\} | j\}|j\}|j\}|j\}}|jdks:t|jdksHtdS )zTest the left text alignment.z
        <style>
            @page { size: 200px }
        </style>
        <body>
            <img src="pattern.png" style="width: 40px"
            ><img src="pattern.png" style="width: 60px">r   (   N)r	   r.   
position_xr   )r0   htmlbodyr2   img_1img_2r   r   r   test_text_align_left}   s    
rD   c              C   sL   t d\} | j\}|j\}|j\}|j\}}|jdks:t|jdksHtdS )zTest the right text alignment.z
        <style>
            @page { size: 200px }
            body { text-align: right }
        </style>
        <body>
            <img src="pattern.png" style="width: 40px"
            ><img src="pattern.png" style="width: 60px">r      N)r	   r.   r?   r   )r0   r@   rA   r2   rB   rC   r   r   r   test_text_align_right   s    
rF   c              C   sL   t d\} | j\}|j\}|j\}|j\}}|jdks:t|jdksHtdS )zTest the center text alignment.z
        <style>
            @page { size: 200px }
            body { text-align: center }
        </style>
        <body>
            <img src="pattern.png" style="width: 40px"
            ><img src="pattern.png" style="width: 60px">2   r'   N)r	   r.   r?   r   )r0   r@   rA   r2   rB   rC   r   r   r   test_text_align_center   s    
rH   c              C   sP  t d\} | j\}|j\}|j\}|j\}}|j\}}}|j\}	}
}}}|j\}|jdks^t|
jdkslt|jdkszt|jdkst|jdkst|jdkst|	jdkst|
jdkst|jdkst|jdkst|jd	kst|jd
kst|jdkstt d\} | j\}|j\}|j\}|j\}}|j\}|jdksLtdS )zTest justified text.a  
        <style>
            @page { size: 300px 1000px }
            body { text-align: justify }
        </style>
        <p><img src="pattern.png" style="width: 40px">
            <strong>
                <img src="pattern.png" style="width: 60px">
                <img src="pattern.png" style="width: 10px">
                <img src="pattern.png" style="width: 100px"
            ></strong><img src="pattern.png" style="width: 290px"
            ><!-- Last image will be on its own line. -->r4   r   r>   F            r*      z
        <style>
            body { text-align: justify; width: 50px }
        </style>
        <p>Supercalifragilisticexpialidocious bar</p>
    N)r	   r.   r   r   r?   r   )r0   r@   rA   r1   Zline_1Zline_2Zimage_1Zspace_1ZstrongZimage_2Zspace_2Zimage_3Zspace_3Zimage_4Zimage_5r   r   r   r   test_text_align_justify   s<    

rN   c              C   sl   t d\} | j\}|j\}|j\}|j\}t d\} | j\}|j\}|j\}|j\}|j|j dkshtdS )zTest word-spacing.zZ
        <style></style>
        <body><strong>Lorem ipsum dolor<em>sit amet</em></strong>zw
        <style>strong { word-spacing: 11px }</style>
        <body><strong>Lorem ipsum dolor<em>sit amet</em></strong>!   N)r	   r.   r   r   )r0   r@   rA   r2   strong_1strong_2r   r   r   test_word_spacing  s    rR   c        	      C   s  t d\} | j\}|j\}|j\}|j\}t d\} | j\}|j\}|j\}|j\}|j|j dkshtt d\} | j\}|j\}|j\}|j\}|j|jkstt d|jd d	d	f \} | j\}|j\}|j\}}|jd
 j|jd
 jkst|jd
 j|jks
tdS )zTest letter-spacing.zB
        <body><strong>Supercalifragilisticexpialidocious</strong>zy
        <style>strong { letter-spacing: 11px }</style>
        <body><strong>Supercalifragilisticexpialidocious</strong>"      z}
        <style>strong { letter-spacing: 11px }</style>
        <body><strong>Supercali<span>fragilistic</span>expialidociousz	</strong>z
        <style>strong { letter-spacing: 11px; max-width: %dpx }
               span { display: inline-block }</style>
        <body><strong>%s %s</strong>g      ?z6<span>Supercali<i>fragilistic</i>expialidocious</span>r   Niv  z
        <style>strong { letter-spacing: 11px }</style>
        <body><strong>Supercali<span>fragilistic</span>expialidocious</strong>)r	   r.   r   r   )	r0   r@   rA   r2   rP   rQ   Zstrong_3line1line2r   r   r   test_letter_spacing'  s>     
rW   c        	      C   s   xdD ]} t dd| i \}|j\}|j\}|j\}|j}|d j\}|d j\}|d j\}|jdkslt|jd	kszt|jd	kstqW d
S )zTest the text-indent property.12px6%a  
            <style>
                @page { size: 220px }
                body { margin: 10px; text-indent: %(indent)s }
            </style>
            <p>Some text that is long enough that it take at least three line,
               but maybe more.
        indentr   r   r      
   N)rX   rY   )r	   r.   r?   r   )	rZ   r0   r@   rA   r1   linesZtext_1Ztext_2Ztext_3r   r   r   test_text_indentV  s    
r^   c              C   s4  t d\} | j\}|j\}|j}t|dks0t|d jd jjdsJtdjdd |D }|jdddksrtt d	\} | j\}|j\}|j}t|dkst|d jd jjd
stdjdd |D }|jd
ddkstt d\} | j\}|j\}|j}t|dkst|d jd jjds2tdjdd |D }|jddjdddksdtt d\} | j\}|j\}|j}t|dkstdjdd |D }|dkstt d\} | j\}|j\}|j}t|dkst|d jd jjdstdjdd |D }|jdddks0td S )Nu   <html style="width: 5em; font-family: ahem"><body style="-weasy-hyphens: auto;-weasy-hyphenate-character: '!'" lang=fr>hyphénationr   r   ! c             s   s   | ]}|j d  jV  qdS )r   N)r.   r   ).0r2   r   r   r   	<genexpr>z  s    z+test_hyphenate_character.<locals>.<genexpr>u   hyphénationu   <html style="width: 5em; font-family: ahem"><body style="-weasy-hyphens: auto;-weasy-hyphenate-character: 'à'" lang=fr>hyphénation   àc             s   s   | ]}|j d  jV  qdS )r   N)r.   r   )ra   r2   r   r   r   rb     s    u   <html style="width: 5em; font-family: ahem"><body style="-weasy-hyphens: auto;-weasy-hyphenate-character: 'ù ù'" lang=fr>hyphénationu   ù ùc             s   s   | ]}|j d  jV  qdS )r   N)r.   r   )ra   r2   r   r   r   rb     s    r4      ùu   <html style="width: 5em; font-family: ahem"><body style="-weasy-hyphens: auto;-weasy-hyphenate-character: ''" lang=fr>hyphénationc             s   s   | ]}|j d  jV  qdS )r   N)r.   r   )ra   r2   r   r   r   rb     s    u   <html style="width: 5em; font-family: ahem"><body style="-weasy-hyphens: auto;-weasy-hyphenate-character: '———'" lang=fr>hyphénationu	   ———c             s   s   | ]}|j d  jV  qdS )r   N)r.   r   )ra   r2   r   r   r   rb     s    u   —)r	   r.   lenr   r   endswithjoinreplace)r0   r@   rA   r]   	full_textr   r   r   test_hyphenate_charactern  sX    rj   c              C   s  xt dtdD ]} xdD ]}dd |  d d| d   }td||f \}|j\}|j\}|j}t|dksrt|d jd jj|std	jd
d |D }|j|d	|kstqW qW xt dtdD ]} xdD ]}dd |  d d| d   }td||f \}|j\}|j\}|j}t|dks2td	jdd |D }|j|d	}|d jd jj|rz||kstq|d jd jjdstt|dkr|d jd jj|stqW qW d S )Nr   u   hyphénationr_      ù ù   ­z{<html style="width: 5em; font-family: ahem"><body style="-weasy-hyphens: manual;-weasy-hyphenate-character: '%s'"lang=fr>%sr   r   r`   c             s   s    | ]}|j D ]}|jV  qqd S )N)r.   r   )ra   r2   childr   r   r   rb     s    z*test_manual_hyphenation.<locals>.<genexpr>u   hy phénation   c             s   s    | ]}|j D ]}|jV  qqd S )N)r.   r   )ra   r2   rm   r   r   r   rb     s    y)r_   rk   )r_   rk   )r   rn   )	rangere   r	   r.   r   r   rf   rg   rh   )r9   Zhyphenate_characterwordr0   r@   rA   r]   ri   r   r   r   test_manual_hyphenation  sB    

rr   c              C   s  t d\} | j\}|j\}|j}t|dks0t|d jd jjdsJtdjdd |D }|jdddksrtt d	\} | j\}|j\}|j}t|d
kst|d jd jjdstdjdd |D }|dkstt d\} | j\}|j\}|j}t|dkst|d jd jjds*tdjdd |D }|jdddksTtt d\} | j\}|j\}|j}t|d
kst|d jd jjdstdjdd |D }|dkstd S )Nu   <html style="width: 12em; font-family: ahem"><body style="-weasy-hyphens: auto;-weasy-hyphenate-limit-zone: 0" lang=fr>mmmmm hyphénationr   r   u   ‐r`   c             s   s   | ]}|j d  jV  qdS )r   N)r.   r   )ra   r2   r   r   r   rb     s    z,test_hyphenate_limit_zone.<locals>.<genexpr>u   mmmmm hyphénationu   <html style="width: 12em; font-family: ahem"><body style="-weasy-hyphens: auto;-weasy-hyphenate-limit-zone: 9em" lang=fr>mmmmm hyphénationr   mmc             s   s   | ]}|j d  jV  qdS )r   N)r.   r   )ra   r2   r   r   r   rb     s    u   mmmmmhyphénationu   <html style="width: 12em; font-family: ahem"><body style="-weasy-hyphens: auto;-weasy-hyphenate-limit-zone: 5%" lang=fr>mmmmm hyphénationc             s   s   | ]}|j d  jV  qdS )r   N)r.   r   )ra   r2   r   r   r   rb     s    u   <html style="width: 12em; font-family: ahem"><body style="-weasy-hyphens: auto;-weasy-hyphenate-limit-zone: 95%" lang=fr>mmmmm hyphénationc             s   s   | ]}|j d  jV  qdS )r   N)r.   r   )ra   r2   r   r   r   rb     s    )r	   r.   re   r   r   rf   rg   rh   )r0   r@   rA   r]   ri   r   r   r   test_hyphenate_limit_zone  sH    rt   c              C   s   dd } | ddkst | ddks(t | ddks8t | ddksHt | d	dksXt | d
dksht | ddksxt | ddkst | ddkst | ddkst | ddkst | ddkst | ddkst d S )Nc             S   s,   t d|  \}|j\}|j\}|j}t|S )Nz~<html style="width: 1em; font-family: ahem"><body style="-weasy-hyphens: auto;-weasy-hyphenate-limit-chars: %s" lang=en>hyphen)r	   r.   re   )Zlimit_charsr0   r@   rA   r]   r   r   r   
line_count  s    
z.test_hyphenate_limit_chars.<locals>.line_countautor   zauto auto 0z0 0 0z4 4 autor   z6 2 4zauto 1 autoz7 auto autoz6 auto autoz5 23z2 4 6zauto 4zauto 2)r   )ru   r   r   r   test_hyphenate_limit_chars  s    rx   c              C   s   dd } | dd}t |dks"tdjdd |D }|dksBt| d	d}t |dks\tdjd
d |D }|dks|t| dd}t |dkstdjdd |D }|dkst| dd}t |dkstdjdd |D }|dkstd S )Nc       	      S   sV   t d| |f \}|j\}|j\}g }x*|jD ] }|j\}|j\}|j|j q.W |S )Na  
            <style>
                body {width: 80px; overflow: hidden; font-family: ahem; }
                span {overflow-wrap: %s; white-space: normal; }
            </style>
            <body style="-weasy-hyphens: auto;" lang="en">
                <span>%s
        )r	   r.   appendr   )	wrapr   r0   r@   rA   Z
body_linesr2   ZboxZtextBoxr   r   r   	get_lines1  s    z%test_overflow_wrap.<locals>.get_linesz
break-wordZaaaaaaaar   r`   c             s   s   | ]
}|V  qd S )Nr   )ra   r2   r   r   r   rb   F  s    z%test_overflow_wrap.<locals>.<genexpr>normalc             s   s   | ]
}|V  qd S )Nr   )ra   r2   r   r   r   rb   L  s    Zhyphenationsrn   c             s   s   | ]
}|V  qd S )Nr   )ra   r2   r   r   r   rb   R  s    u   hy‐phen‐ationsz%A splitted word.  An hyphenated word.   c             s   s   | ]
}|V  qd S )Nr   )ra   r2   r   r   r   rb   Y  s    u%   Asplittedword.Anhy‐phen‐atedword.)re   r   rg   )r{   r]   ri   r   r   r   test_overflow_wrap/  s$    


r~   c              C   s  dd } | dd\}}}}|j \}|j \}|jdks8t|j \}|j \}|jdksVt|j \}	|	j \}
|
jdkstt|j \}|j \}|jdkst| dd	\}}|j \}|j \}|jd
kst|j \}|j \}|jdkst| dd\}|j \}|j \}|jdkst| dd\}}}}}|j \}|j \}|jdks<t|j \}|j \}|jdks\t|j \}	|	j \}
|
jdks|t|j \}|j \}|jdkst|j \}|j \}|jdkst| dd\}}}}|j \}|j \}|jdkst|j \}|j \}|jdkst|j \}	|	j \}
|
jdks.t|j \}|j \}|jdksNt| dd\}|j \}|j \}|jdkszt| dd	\}}|j \}|j \}|jd
kst|j \}|j \}|jdkst| dd\}|j \}|j \}|jdkst| dd\}}|j \}|j \}|jd
ks"t|j \}|j \}|jdksBt| dd\}}|j \}|j \}|jdkspt|j \}|j \}|jdkstdS )zTest the white-space property.c             S   s(   t d| |f \}|j\}|j\}|jS )Nz
            <style>
              body { font-size: 100px; width: %ipx }
              span { white-space: %s }
            </style>
            <body><span>This +    
    is text)r	   r.   )r   r:   r0   r@   rA   r   r   r   r]   `  s
    ztest_white_space.<locals>.linesr   r|   ZThis+isr   prez
This +    z    is textZnowrapzThis + is textzpre-wrapzThis z+    z    zis zpre-linei@B zThis +zis textN)r.   r   r   )r]   rU   rV   line3line4Zbox1text1Zbox2text2Zbox3text3Zbox4text4line5Zbox5text5r   r   r   test_white_space]  s    r   c              C   sD   x>dD ]6\} }t d	|  \}t|\}|j\}|j|kstqW d
S )zTest the ``tab-size`` property.r}         P   3em@   25px)   z
            <style>
                pre { tab-size: %s; font-family: ahem }
            </style>
            <pre>a&#9;a</pre>
        Nr}   r   r   r   r   r   r   r   )r   r   r   r   )r	   r
   r.   r   r   )valuer   r0   r1   r2   r   r   r   test_tab_size  s       
r   c              C   s   t d\} t| \}}}}}|j\}|j\}|jdks:t|j\}|j\}	|	jdksXt|j\}
|
j\}|jdksvt|j\}|j\}|jdkst|j\}|j\}|jdkstdS )z!Test the text-transform property.uZ  
        <style>
            p { text-transform: capitalize }
            p+p { text-transform: uppercase }
            p+p+p { text-transform: lowercase }
            p+p+p+p { text-transform: full-width }
            p+p+p+p+p { text-transform: none }
        </style>
<p>hé lO1</p><p>hé lO1</p><p>hé lO1</p><p>hé lO1</p><p>hé lO1</p>
    u   Hé Lo1u   HÉ LO1u   hé lo1u   ｈé　ｌＯ１u   hé lO1N)r	   r
   r.   r   r   )r0   p1p2Zp3Zp4Zp5rU   r   rV   r   r   r   r   r   r   r   r   r   r   test_text_transform  s$    	r   )N)'__doc__
__future__r   r   cssr   Zcss.propertiesr   r   r   Ztest_layoutr	   r
   Ztesting_utilsr   r   splitr   r#   r&   r)   r-   r3   r=   rD   rF   rH   rN   rR   rW   r^   rj   rr   rt   rx   r~   r   r   r   r   r   r   r   <module>   s:   



5/C+7.k