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d?d?d?d?dBdBdBdBdBdBdBddBdBdBdBdBdCdCdEdEdEdEdEdEdEdBdadadadadad8d8d8d8dEd:dEdEdEdEdEddEd:d:d:d:dadEdadT e8d< 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]d]d]d]d]d]d]d>ddEdEdFdDdd>d>dEdd]d>d]d8dEdEdEdEdEdEdEdEdEdEd>d>ddddEddCdCd<dBdCdCdBdBd>dad<d:dFd<dBdCdBdCdEd:dBdCdFdCd:d:d?d8d?ddEd>dEdEdadEdad8dEdEd8d8dad8dBdEdEdEdEd?d?d8dEdad<dadad?dPddPddLdEdLd>dEd:d;dEdEd>dMdEd>dGdLd:dLdLd>d>d:d:dLdEd;d>dd?d>d<dLd?d:d]d?dEdEdEdEddEd>dddEdd>dd>dPdddd>dEdd]d>dddEdwdwdwdEdCdCdCdCdCdCd;d<dCdCdCdCd>d>d>d>dBd<dBdBdBdBdBddBdBdBdBdBd:dCdEdEdEdEdEdEdEd<dadadadadad8d8d8d8dEdEdEdEdEdEdEddEdEdEdEdEdadEdadT e8d< ddddddddddddddddddddddddddddddddd8dddddddddjddd_dddddddddddddcddddoddQddddddddddddddFdddddddddddgddddddddddddddddd^dddddddddddddddddddddddddddddddddddJdJdddddddddddddddddddddddd<ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddSdddddddddddddddddddddddd dd dddddddT e8d< dS (  a0  
Font-related classes & constants.
Includes the definition of the character widths of all PDF standard fonts.

The contents of this module are internal to fpdf2, and not part of the public API.
They may change at any time without prior warning or any deprecation period,
in non-backward-compatible ways.
    N)bisect_left)defaultdict)	dataclassreplace)	lru_cache)OptionalTupleUnion)ttLib)
TTGlyphPenc                   @   s   e Zd ZdZdd ZdS )HarfBuzzFontz%uharfbuzz.Font than can be deepcopiedc                 C   s   | S N )selfZ_memor   r   ./tmp/pip-unpacked-wheel-dvf6lv8i/fpdf/fonts.py__deepcopy__   s    zHarfBuzzFont.__deepcopy__N)__name__
__module____qualname____doc__r   r   r   r   r   r      s   r      )get_stack_level)convert_to_device_color
DeviceGray	DeviceRGB)FontDescriptorFlagsTextEmphasisAlign)Name	PDFObjectescape_parensc                   @   s   e Zd ZU dZdZee ed< ee ed< ee	 ed< ee
eef  ed< ee
eef  ed< dd	d
ZeZedd Zedd ZdS )FontFacez
    Represent basic font styling properties.
    This is a subset of `fpdf.graphics_state.GraphicsStateMixin` properties.
    familyemphasissize_ptcolor
fill_colorr$   r%   r&   r'   r(   Nc                 C   sT   || _ |d krd nt|| _|| _|d kr0d nt|| _|d krFd nt|| _d S r   )r$   r   coercer%   r&   r   r'   r(   )r   r$   r%   r&   r'   r(   r   r   r   __init__D   s    zFontFace.__init__c                 C   s   |dkr| S |S )z;Override the current value if an override value is providedNr   )Zcurrent_valueZoverride_valuer   r   r   	_overrideU   s    zFontFace._overridec              	   C   s   |dkr| S | dkr|S t |ts4tdt| t | tsPtdt|  tt| j|jt| j|jt| j|jt| j|jt| j	|j	dS )a  
        Create a combined FontFace with all the supplied features of the two styles. When both
        the default and override styles provide a feature, prefer the override style.
        Override specified FontFace style features
        Override this FontFace's values with the values of `other`.
        Values of `other` that are None in this FontFace will be kept unchanged.
        NzCannot combine FontFace with r#   )

isinstancer"   	TypeErrortyper+   r$   r%   r&   r'   r(   )Zdefault_styleZoverride_styler   r   r   combineZ   s*    	

 zFontFace.combine)NNNNN)r   r   r   r   	__slots__r   str__annotations__r   intr	   r   r   r*   r   staticmethodr+   r/   r   r   r   r   r"   -   s$   
         

r"   c                       s   e Zd ZdZdee ee ee eeef eeef e	ee eee ee
 ee f ee d	 fddZ fddZdd	d
Z  ZS )	TextStylezU
    Subclass of `FontFace` that allows to specify vertical & horizontal spacing
    NF)	font_family
font_stylefont_size_ptr'   r(   	underlinet_marginl_marginb_marginc
           
         sj   t  ||r|pdd n|||| |p*d| _t|ttfrD|| _n|rVt|| _nd| _|	pbd| _	d S )N Ur   )
superr*   r:   r,   r3   floatr;   r   r)   r<   )
r   r6   r7   r8   r'   r(   r9   r:   r;   r<   	__class__r   r   r*   ~   s    
zTextStyle.__init__c                    s0   t   d d d| j d| j d| j d S )Nz, t_margin=z, l_margin=z, b_margin=))r?   __repr__r:   r;   r<   r   rA   r   r   rE      s    zTextStyle.__repr__c	          	   
   C   sj   t |p
| j|dkr| jn|j|p$| j|p,| j|p4| j|dkrB| jn||dkrR| jn||dkrb| j	n|dS )z
        Create a new TextStyle instance, with new values for some attributes.
        Same as `dataclasses.replace()`
        N)r6   r7   r8   r'   r(   r:   r;   r<   )
r5   r$   r%   styler&   r'   r(   r:   r;   r<   )	r   r6   r%   r8   r'   r(   r:   r;   r<   r   r   r   r      s    zTextStyle.replace)	NNNNNFNNN)NNNNNNNN)r   r   r   r   r   r1   r3   r	   tupleboolr   r*   rE   r   __classcell__r   r   rA   r   r5   y   s>            


        r5   c                       s   e Zd Z fddZ  ZS )
TitleStylec                    s$   t jdtt d t j|| d S )NzRfpdf.TitleStyle is deprecated since 2.8.0. It has been replaced by fpdf.TextStyle.)
stacklevel)warningswarnDeprecationWarningr   r?   r*   )r   argskwargsrA   r   r   r*      s    zTitleStyle.__init__r   r   r   r*   rJ   r   r   rA   r   rK      s   rK   Fc                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )CoreFont)
ir.   namespssuputcwfontkeyr%   c                 C   sX   t |jd | _d| _t| | _d| _d| _d| _d| _	t
| | _|| _t|| _d S )Nr   core   2   i)lenfontsrT   r.   
CORE_FONTSrU   rV   rW   rX   rY   CORE_FONTS_CHARWIDTHSrZ   r[   r   r)   r%   )r   fpdfr[   rG   r   r   r   r*      s    

zCoreFont.__init__c                    s&   t |t fdd|D | d fS )Nc                 3   s   | ]} j | V  qd S r   )rZ   .0crF   r   r   	<genexpr>   s     z*CoreFont.get_text_width.<locals>.<genexpr>MbP?)r_   sum)r   textr8   _r   rF   r   get_text_width   s    zCoreFont.get_text_widthc                 C   s   dt | dS )N() Tjr    )r   rj   r   r   r   encode_text   s    zCoreFont.encode_textc                 C   s   d| j  d| j dS )NzCoreFont(i=
, fontkey=rD   rT   r[   rF   r   r   r   rE      s    zCoreFont.__repr__N)r   r   r   r0   r*   rl   ro   rE   r   r   r   r   rS      s
   rS   c                   @   sP   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdS )TTFFont)rT   r.   rU   desc	glyph_idshbfontrV   rW   rX   rY   rZ   ttffiler[   r%   scalesubsetcmapttfontmissing_glyphsc                    s  t |jd | _d| _|| _|| _tj| jdddd| _d| jd j	 | _
d	| jkrjd
| jd	 krjtd| j | jd j| jd j| jd j| jd jf\}}}}t| jd	 }	|	||f |	||f |	||f |	||f |	  |	||f |	||f |	  |	||f |	||f |	  |	 | jd	 d
< || || f| jd d
< t| j
| jd jd
 d   | jd }
| jd }z
|
j}W n" tk
r   | jd j}Y nX tj}|jr|tjO }|jdkr|tj O }|
j!dkr|tj"O }t#t| jd j| j
 t| jd j$| j
 t|| j
 |d| jd j| j
 dd| jd j| j
 dd| jd j| j
 dd| jd j| j
 dd	t%|jtdt%t&|
j!d d  d| _'t( fdd| _)| j* | _+| j+st,di | _-| j+D ]\}| j+| }| jd j| d }|dkr8d}t| j
| d | j)|< | j.|| j-|< qg | _/t01dd| jd  2 | _3t|j4| j
 | _5t|j6| j
 | _7t|
j8| j
 | _9t|
j:| j
 | _;t<=|| _>t?| | _@d S )!Nr   ZTTFFr   T)ZrecalcTimestampZ
fontNumberZlazy  headZglyf.notdefzSTrueType Font '%s' is missing the '.notdef' glyph. Fallback glyph will be provided.hmtxzOS/2postZhheaX  [z.0f ]r^   A      )ascentdescent
cap_heightflags
font_b_boxitalic_anglestem_vmissing_widthc                      s    S r   r   r   Zdefault_widthr   r   <lambda>_      z"TTFFont.__init__.<locals>.<lambda>zMFont not supported as it does not have a unicode cmap table - cf. issue #1396i  rh   z[ ()]r=   rU   )Ar_   r`   rT   r.   rv   r[   r
   ZTTFontrz   Z
unitsPerEmrw   LOGGERwarningxMinxMaxyMinyMaxr   ZmoveToZlineToZ	closePathglyphroundmetricsZ
sCapHeightAttributeErrorr   r   ZSYMBOLICZisFixedPitchZFIXED_PITCHZitalicAngleZITALICZusWeightClassZ
FORCE_BOLDPDFFontDescriptorr   r3   powrs   r   rZ   ZgetBestCmapry   NotImplementedErrorrt   Z
getGlyphIDr{   resubZgetBestFullNamerU   ZunderlinePositionrX   ZunderlineThicknessrY   ZyStrikeoutPositionrV   ZyStrikeoutSizerW   r   r)   r%   	SubsetMaprx   )r   rc   Zfont_file_pathr[   rG   r   r   r   r   ZpenZ	os2_tableZ
post_tabler   r   charr   wr   r   r   r*     s       	









\


zTTFFont.__init__c                 C   s   d| j  d| j dS )Nz
TTFFont(i=rp   rD   rq   rF   r   r   r   rE     s    zTTFFont.__repr__c                 C   s   | j   d | _d S r   )rz   closeru   rF   r   r   r   r     s    
zTTFFont.closec                    s8   |r  |||S t|t fdd|D | d fS )Nc                 3   s   | ]} j t| V  qd S r   )rZ   ordrd   rF   r   r   rg     s     z)TTFFont.get_text_width.<locals>.<genexpr>rh   )shaped_text_widthr_   ri   )r   rj   r8   text_shaping_paramsr   rF   r   rl     s    zTTFFont.get_text_widthc                 C   sX   |  |||\}}|dkrdS d}|D ]$}|t| j|j d | d 7 }q&t||fS )aF  
        When texts are shaped, the length of a string is not always the sum of all individual character widths
        This method will invoke harfbuzz to perform the text shaping and return the sum of "x_advance"
        and "x_offset" for each glyph. This method works for "left to right" or "right to left" texts.
        N)r   r   r   rh   )perform_harfbuzz_shapingr   rw   	x_advancer_   )r   rj   r8   r   rk   glyph_positions
text_widthposr   r   r   r     s      zTTFFont.shaped_text_widthc                 C   s   t | ds$tttj| j| _|| j_t	 }d|_
|d| |  |d }|d rn|d j|_|d r|d |_|d r|d |_t| j|| |j|jfS )zZ
        This method invokes Harfbuzz to perform text shaping of the input string
        ru   r   r=   featuresZfragment_directionscriptlanguage)hasattrr   hbZFaceZBlobZfrom_file_pathrv   ru   ZptemZBufferZcluster_levelZadd_strjoinZguess_segment_propertiesvalue	directionr   r   shapeglyph_infosr   )r   rj   r8   r   bufr   r   r   r   r     s     


z TTFFont.perform_harfbuzz_shapingc                 C   sF   d}|D ] }t |}|t| j|7 }qdt|dd dS )Nr=   rm   z	utf-16-bezlatin-1rn   )r   chrrx   pickr!   encodedecode)r   rj   Z
txt_mappedr   unir   r   r   ro     s
    zTTFFont.encode_textc              
      s  t  dkrg S |  ||\}}g }dd }ttdd |D }i }	tt  D ]0}
|||
}||	krz|	| |
 qT|
g|	|< qTt|D ] \}}g }|j|	krʇ fdd|	|j D }|	|j | j	
|j}t| j| j	d j| d  }| jj|jt|||d	}d
}||| jksT|| jdksT|| jdksT|| jdkrXd}|| j||| j|| j|| j|| j|d q|S )z
        This method will invoke harfbuzz for text shaping, include the mapping code
        of the glyphs on the subset and map input characters to the cluster codes
        r   c                 S   sF   t | |}|dkr| d S |t| ks2| | |kr>| |d  S | | S )Nr   r   )r   r_   )cluster_listindexr   r   r   r   get_cluster_from_text_index  s    
z7TTFFont.shape_text.<locals>.get_cluster_from_text_indexc                 s   s   | ]}t |jV  qd S r   )r3   cluster)re   gir   r   r   rg     s     z%TTFFont.shape_text.<locals>.<genexpr>c                    s   g | ]}t  | qS r   )r   re   rT   rj   r   r   
<listcomp>  s     z&TTFFont.shape_text.<locals>.<listcomp>r   )r   unicode
glyph_nameglyph_widthFT)Zmapped_charr   	y_advancex_offsety_offsetforce_positioning)r_   r   listsortedrangeappend	enumerater   poprz   ZgetGlyphName	codepointr   rw   r   rx   	get_glyphrH   r   r   r   r   
pick_glyph)r   rj   r8   r   r   r   Z	text_infor   r   Zcluster_mappingrT   ZclZcluster_seqr   r   gnameZgwidthr   r   r   r   r   
shape_text  sb      



zTTFFont.shape_textN)r   r   r   r0   r*   rE   r   rl   r   r   ro   r   r   r   r   r   rr      s   z	rr   c                       s   e Zd Z fddZ  ZS )r   c	           	         sN   t    td| _|| _|| _|| _|| _|| _|| _	|| _
|| _d | _d S )NZFontDescriptor)r?   r*   r   r.   r   r   r   r   r   r   r   r   Z	font_name)	r   r   r   r   r   r   r   r   r   rA   r   r   r*     s    

zPDFFontDescriptor.__init__rR   r   r   rA   r   r     s   r   T)orderc                   @   s>   e Zd ZU dZdZeed< eed< eed< eed< dd Z	d	S )
Glyphz
    This represents one glyph on the font
    Unicode is a tuple because ligatures or character substitution
    can map a sequence of unicode characters to a single glyph
    )glyph_idr   r   r   r   r   r   r   c                 C   s   | j S r   )r   rF   r   r   r   __hash__7  s    zGlyph.__hash__N)
r   r   r   r   r0   r3   r2   r   r1   r   r   r   r   r   r   (  s   
r   c                       s   e Zd ZdZed fddZdd Zdd Zd	d
 Ze	dde
dddZdd Ze	dddedddZdd Z  ZS )r   a  
    Holds a mapping of used characters and their position in the font's subset

    Characters that must be mapped on their actual unicode must be part of the
    `identities` list during object instantiation. These non-negative values should
    only appear once in the list. `pick()` can be used to get the characters
    corresponding position in the subset. If it's not yet part of the object, a new
    position is acquired automatically. This implementation always tries to return
    the lowest possible representation.
    )fontc                    sT   t    || _d| _ddg| _i | _| jD ]"}| j|d}|r,t|| j|< q,d S )Nr       r   )r?   r*   r   _next	_reserved_char_id_per_glyphr   r3   )r   r   xr   rA   r   r   r*   G  s    


zSubsetMap.__init__c              	   C   s&   d| j  d| j d| j d| j d	S )NzSubsetMap(font=z, _next=z, _reserved=z, _char_id_per_glyph=rD   )r   r   r   r   rF   r   r   r   rE   V  s    $zSubsetMap.__repr__c                 C   s
   t | jS r   )r_   r   rF   r   r   r   __len__\  s    zSubsetMap.__len__c                 c   s"   | j  D ]\}}||fV  q
d S r   )r   itemsr   r   Zchar_idr   r   r   r   _  s    zSubsetMap.itemsN)maxsizer   c                 C   s8   | j |d}|d kr.|| jjkr.| jj| | |S )Nr   )r   r   r{   r   r   )r   r   r   r   r   r   r   d  s    zSubsetMap.pickc                 C   sn   | j |}|rj|d krj| j| jkrL|  jd7  _| j| jd kr| jd= q| j}|| j |< |  jd7  _|S )Nr   r   )r   getr   r   r   r   r   r   r   k  s    

zSubsetMap.pick_glyph)returnc                 C   s   |rt |t|||S | jj|}t|trV|d k	rVt ||f| jj| | jj| S |dkr|t	t
| jj}t |dddS d S )Nr   )r   r~   )r   rH   r   rt   r   r,   r3   ry   rZ   nextiter)r   r   r   r   r   r   r   r   r   r   x  s    

zSubsetMap.get_glyphc                 C   s   dd | j D S )Nc                 S   s   g | ]
}|j qS r   )r   )re   r   r   r   r   r     s     z1SubsetMap.get_all_glyph_names.<locals>.<listcomp>)r   rF   r   r   r   get_all_glyph_names  s    zSubsetMap.get_all_glyph_names)NNNN)r   r   r   r   rr   r*   rE   r   r   r   r3   r   r   r   r   r   rJ   r   r   rA   r   r   ;  s"          r   ZCourierzCourier-BoldzCourier-ObliquezCourier-BoldObliqueZ	HelveticazHelvetica-BoldzHelvetica-ObliquezHelvetica-BoldObliquezTimes-Romanz
Times-BoldzTimes-ItaliczTimes-BoldItalicZSymbolZZapfDingbats)couriercourierBcourierI	courierBI	helvetica
helveticaB
helveticaIhelveticaBItimestimesBtimesItimesBIsymbolzapfdingbatsc                 C   s   i | ]}t |d qS )r   )r   r   r   r   r   
<dictcomp>  s      r      )r   r   r   r   i  ic  i,  iy  i     iM  i  iH  i  i  ic  i
  i  iA  i  i     iN  i  i^  r|   i  ir  i  i  im  iB  (    	
r   !"#$%&'rm   rD   *+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTr>   VWXYZr   \r   ^rk   `abrf   defghrT   jklmnopqrstuvr   r   yz{|}~                                                                                                       ¡   ¢   £   ¤   ¥   ¦   §   ¨   ©   ª   «   ¬   ­   ®   ¯   °   ±   ²   ³   ´   µ   ¶   ·   ¸   ¹   º   »   ¼   ½   ¾   ¿   À   Á   Â   Ã   Ä   Å   Æ   Ç   È   É   Ê   Ë   Ì   Í   Î   Ï   Ð   Ñ   Ò   Ó   Ô   Õ   Ö   ×   Ø   Ù   Ú   Û   Ü   Ý   Þ   ß   à   á   â   ã   ä   å   æ   ç   è   é   ê   ë   ì   í   î   ï   ð   ñ   ò   ó   ô   õ   ö   ÷   ø   ù   ú   û   ü   ý   þ   ÿr   i     i  i  r   r   r   r]   i  i%  i  i  id  i  i[  iw  i  i   i  iP  i  i  i  i_  i  i  i	  i  iI  i@  i  i     i  il        i  i  i  i  i7  i  iz  i  i  i  r   i     i4  i  i  i  i  i  i,  i  i6  r   i+  i:  i  iE  i     i  i  i  iJ  r   i@  i\  i
  i^  r   i     i  i  i  i  i  r   i  i  i  i  i  i  i  iW  i  i  i  i  iN  i  i  i;  i  i  i  i(  iA  i  i  i  i  i0  iI  i?  i  i  i  i  i  i  i  i  i  i  i  i:  i/  i  i  i  i  i  ii  i|  i  i     i  i  i  i  i  i=  i  i     i  i   i  iS  i  ir  i~  iF  i  i  i  i  i  i  i  i<  i  i  i  is  iD  ic  ij  i  i  ia  ix  i  i  r   )9r   r   rM   loggingbisectr   collectionsr   dataclassesr   r   	functoolsr   typingr   r   r	   Z	fontToolsr
   ZfontTools.pens.ttGlyphPenr   Z	uharfbuzzr   ZFontr   ImportErrordeprecationr   Zdrawingr   r   r   enumsr   r   r   Zsyntaxr   r   utilr!   	getLoggerr   r   r"   r5   rK   Z__pdoc__rS   rr   r   r   r   ra   r   ZCOURIER_FONTrb   r   r   r   r   <module>   s  	

KG'  V                                                