a
    [Xh                     @   s^   d 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mZ G dd	 d	Zd
d ZdS )z
Draw text.    )cosinfradianssin   )Matrix   )extend_bounding_box)	normalizesizec                   @   s$   e Zd ZdZdd Zedd ZdS )TextBoxz!Dummy text box used to draw text.c                 C   s   || _ || _d S N)pango_layoutstyle)selfr   r    r   X/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/site-packages/weasyprint/svg/text.py__init__   s    zTextBox.__init__c                 C   s   | j jS r   )r   text)r   r   r   r   r      s    zTextBox.textN)__name__
__module____qualname____doc__r   propertyr   r   r   r   r   r   
   s   r   c           %         s  ddl m} ddlm}m} ddlm} | }dd |dd	d	D |d
< |dd|d< |dd|d< |d< |d dkrd|d< nF|d dkrd|d< n0zt
|d |d< W n ty   d|d< Y n0 ||j|jtd\}}	}	}
}}	g g g g dgf\ d|jv rBfddt|jd  	dD d|jv rvfddt|jd  	dD d|jv rfddt|jd  	dD  d|jv rއfddt|jd  	dD d|jv rdd t|jd  	dD d  } fd!d|jD }|d"}|d#}d$}|r|jrt|jd$ }t|jd%d&kr|
||  }||| 9 }|||  }||
 }n|r||
 | }|}
d' d(  }}d}|d)}|d*|d+}|d,kr| d }nZ|d-kr"nN|d.kr4| }n<|d/v rP|| d | }n |d0v r`|}n|d1v rp| }|jsrd njd rd njd$  r d nd rȈd nd   f_d2S j  j  g }t|D ]\}\\ }}r*djd< r:djd$< jd   pLd7  < jd$  pdd7  < |||jtd\}}	}	}
}}	d2u rjd nd2u rjd$ n|
|9 }
|rΈ|7 |
 f_jd  }jd$  | }|d2u r
|n|}||f||
 || ff} t|j| |_|| j|d3d4 t|d ||d5}!|rt|t | }"}#t|"|# |#|"|! }!|jt!||d6d6|!}$|"|$f qj#  j$  |D ] \}$|j|$ qd2S )7zDraw text node.r   )INITIAL_VALUES)draw_emojisdraw_first_line)split_first_linec                 S   s   g | ]}| d qS )z"')strip).0fontr   r   r   
<listcomp>   s   ztext.<locals>.<listcomp>zfont-familyz
sans-serif,Zfont_familyz
font-stylenormalZ
font_stylezfont-weighti  Zfont_weight	font_sizeZboldi  r   xc                    s   g | ]}t | jqS r   r   Zinner_widthr   ir$   svgr   r   r!   3   s    yc                    s   g | ]}t | jqS r   r   Zinner_heightr'   r)   r   r   r!   6   s   dxc                    s   g | ]}t | jqS r   r&   r'   r)   r   r   r!   9   s   dyc                    s   g | ]}t | jqS r   r-   r'   r)   r   r   r!   <   s   rotatec                 S   s    g | ]}|rt t|nd qS )r   )r   floatr'   r   r   r   r!   ?   s   c                    s(   g | ] }d d  fD |fqS )c                 S   s   g | ]}|r| d ndqS )r   N)pop)r   plr   r   r   r!   C       z#text.<locals>.<listcomp>.<listcomp>r   )r   char)r.   r/   r0   r%   r,   r   r   r!   B   s   zletter-spacing
textLengthr   lengthAdjustZspacingAndGlyphsg?g?zdisplay-anchorzdominant-baselinezalignment-baselinemiddletopbottom)Zcentralr9   )ztext-before-edgeZbefore_edger:   Zhangingztext-top)ztext-after-edgeZ
after_edger;   ztext-bottomNT)r   )adefnone)%Zcss.propertiesr   Z	draw.textr   r   Ztext.line_breakr   copygetsplitint
ValueErrorr   contextr   attribr
   r   lengthlenZcursor_positionstreamZ
push_stateZ
begin_text	enumerateZcursor_d_positionr	   Ztext_bounding_boxZ
reactivateZfill_stroker   r   r   r   appendZend_textZ	pop_state)%r*   noder$   r   r   r   r   r   Zlayout_widthheightZlast_rZletters_positionsZletter_spacingZtext_lengthZscale_xZspaces_countZwidth_with_spacingZspaceless_text_lengthZascentZdescentZy_alignZdisplay_anchorZalignment_baselineZemoji_linesr(   rletterZ
x_positionZ
y_positionZangleZpointsmatrixr<   cZemojisr   )r.   r/   r$   r0   r*   r%   r,   r   r      s    













 




r   N)r   mathr   r   r   r   rS   r   Zbounding_boxr	   utilsr
   r   r   r   r   r   r   r   <module>   s   