a
    Qh                     @   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   L/var/www/sistema_ama/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,font_familyz
font-stylenormal
font_stylezfont-weighti  font_weight	font_sizeboldi  r   xc                    s   g | ]}t | jqS r   r   inner_widthr   ir'   svgr   r   r!   3   s    yc                    s   g | ]}t | jqS r   r   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   r2   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)r4   r5   r6   r)   r1   r   r   r!   B   s   zletter-spacing
textLengthr   lengthAdjustZspacingAndGlyphsg?g?zdisplay-anchorzdominant-baselinezalignment-baselinemiddletopbottom)Zcentralr?   )ztext-before-edgeZbefore_edger@   Zhangingztext-top)ztext-after-edgeZ
after_edgerA   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lencursor_positionstream
push_state
begin_text	enumeratecursor_d_positionr	   text_bounding_box
reactivatefill_stroker   r   r   r   appendend_text	pop_state)%r/   noder'   r   r   r   r   r   layout_widthheightZlast_rZletters_positionsletter_spacingZtext_lengthscale_xZspaces_countZwidth_with_spacingZspaceless_text_lengthascentdescentZy_alignZdisplay_anchorZalignment_baselineZemoji_linesr-   rletter
x_position
y_positionanglepointsmatrixrB   cZemojisr   )r4   r5   r'   r6   r/   r)   r1   r   r      s    













 




r   N)r   mathr   r   r   r   rk   r   bounding_boxr	   utilsr
   r   r   r   r   r   r   r   <module>   s   