o
    Zh0h                     @   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   I/var/www/html/rh/venv/lib/python3.10/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rGd|d< n#|d dkrRd|d< nz
t
|d |d< W n tyi   d|d< Y nw ||j|jtd\}}	}	}
}}	g g g g dgf\ 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҇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$}|rc|jrct|jd$ }t|jd%d&krX|
||  }||| 9 }|||  }||
 }n	|ra||
 | }|}
d' d( }}d}|d)}|d*|d+}|d,kr| d }n-|d-krn'|d.kr| }n|d/v r|| d | }n|d0v r|}n|d1v r| }|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   p!d7  < jd$  p-d7  < |||jtd\}}	}	}
}}	d2u rIjd nd2u rUjd$ n|
|9 }
|rb|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                       g | ]	}t | jqS r   r   inner_widthr   ir'   svgr   r   r!   3        yc                    r*   r   r   inner_heightr-   r/   r   r   r!   6   r1   dxc                    r*   r   r+   r-   r/   r   r   r!   9   r1   dyc                    r*   r   r4   r-   r/   r   r   r!   <   r1   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   s    z#text.<locals>.<listcomp>.<listcomp>r   )r   char)r6   r7   r8   r)   r3   r   r   r!   B   s    zletter-spacing
textLengthr   lengthAdjustspacingAndGlyphsg?g?zdisplay-anchorzdominant-baselinezalignment-baselinemiddletopbottom)centralrA   )ztext-before-edgebefore_edgerB   hangingztext-top)ztext-after-edge
after_edgerC   ztext-bottomNT)r   )adefnone)%css.propertiesr   	draw.textr   r   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)%r0   noder'   r   r   r   r   r   layout_widthheightlast_rletters_positionsletter_spacingtext_lengthscale_xspaces_countwidth_with_spacingspaceless_text_lengthascentdescenty_aligndisplay_anchoralignment_baselineemoji_linesr.   rletter
x_position
y_positionanglepointsmatrixrH   cemojisr   )r6   r7   r'   r8   r0   r)   r3   r   r      s   






















r   N)r   mathr   r   r   r   r~   r   bounding_boxr	   utilsr
   r   r   r   r   r   r   r   <module>   s    