
    є jX                       d dl mZ d dlmZ d dlmZmZ d dlmZm	Z	m
Z
 d dlmZmZmZmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ erd dlmZ d dlmZ d dlm Z  d dl!m"Z" 	 d dl#m$Z$ dZ%n# e&$ r dZ%Y nw xY wdZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ. ed           G d d                      Z/ ed           G d d                      Z0e G d d                       Z1d!S )"    )annotations)Sequence)	dataclassfield)TYPE_CHECKINGAnycast)ArrayObjectDictionaryObject
NameObjectNumberObjectStreamObject   )get_encodingadobe_glyphs)logger_warning)	FontFlags)PdfReadError)BytesIO)table__h_e_a_d)table__p_o_s_t)table_O_S_2f_2)TTFontTF            	   
      )frozenc                      e Zd ZU dZdZded<   dZded<   dZded<   dZded	<   d
Z	ded<   dZ
ded<   dZded<   dZded<   dZded<    ed           Zded<   dZded<   dS )FontDescriptorz
    Represents the FontDescriptor dictionary as defined in the PDF specification.
    This contains both descriptive and metric information.

    The defaults are derived from the mean values of the 14 core fonts, rounded
    to 100.
    Unknownstrnamefamilyweightg     @floatascent      idescentg     @
cap_heightg     @@x_height        italic_angle    intflagsc                     dS )N)g      Yr,        @@g      @ r7       _C:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\site-packages\pypdf/_font.py<lambda>zFontDescriptor.<lambda><   s    Lk r8   default_factoryz!tuple[float, float, float, float]bboxNzStreamObject | None	font_file)__name__
__module____qualname____doc__r'   __annotations__r(   r)   r+   r-   r.   r/   r1   r4   r   r=   r>   r7   r8   r9   r$   r$   (   s           DFFFGJHLEOOOO.3eDkDk.l.l.lDllll%)I))))))r8   r$   c                  $    e Zd ZU ded<   ded<   dS )CoreFontMetricsr$   font_descriptordict[str, int]character_widthsN)r?   r@   rA   rC   r7   r8   r9   rE   rE   @   s*         ####$$$$$$r8   rE   c                     e Zd ZU dZded<   ded<    ee          Zded<   d	Zded
<    ee	          Z
ded<    ed           Zded<   dZded<   dZded<   ed7d            Zed8d            Zed9d!            Zed:d"            Zed;d%            Zed<d&            Zed=d-            Zed>d0            Zd?d1Zd@dAd5Zd6S )BFonta  
    A font object for use during text extraction and for producing
    text appearance streams.

    Attributes:
        name: Font name, derived from font["/BaseFont"]
        character_map: The font's character map
        encoding: Font encoding
        sub_type: The font type, such as Type1, TrueType, or Type3.
        font_descriptor: Font metrics, including a mapping of characters to widths
        character_widths: A mapping of characters to widths
        space_width: The width of a space, or an approximation
        interpretable: Default True. If False, the font glyphs cannot
            be translated to characters, e.g. Type3 fonts that do not define
            a '/ToUnicode' mapping.

    r&   r'   str | dict[int, str]encodingr;   dict[Any, Any]character_mapr%   sub_typer$   rF   c                 
    ddiS )Ndefault  r7   r7   r8   r9   r:   zFont.<lambda>_   s    iQTEU r8   rG   rH      zfloat | intspace_widthTboolinterpretablepdf_font_dictr   char_mapcurrent_widthsreturnNonec                  
 t          t          | d                   }|                     dd          
t          t                    s1|                    
fdt          |          D                        dS t          |          D ]j\  }}|
z   }t          |g                              d          }|                    |          }	|	rt          |          ||	<   Xt          |          ||<   kdS )zcParses a TrueType or Type1 font's /Widths array from a font dictionary and updates character widths/Widthsz
/FirstCharr   c           	     j    i | ]/\  }}                     |z   t          |z                       |0S r7   )getchr).0idxwidthrL   
first_chars      r9   
<dictcomp>z8Font._collect_tt_t1_character_widths.<locals>.<dictcomp>o   sO     # # #C S:-s33C/D/DEEu# # #r8   Nsurrogatepass)
r	   r
   r_   
isinstancer&   update	enumeratebytesdecoder3   )rW   rX   rL   rY   widths_arrayrb   rc   	char_coderaw_charunicode_charrd   s     `       @r9   _collect_tt_t1_character_widthsz$Font._collect_tt_t1_character_widthsc   s"    Ky)ABB"&&|Q77
(C(( 	!! # # # # #"+L"9"9# # #    F $L11 
	6 
	6JCj(Ii[))00?KKH#<<11L 6/25zz|,,+.u::x((
	6 
	6r8   d_fontc                |   d |                                 D             d}|                     dg           }t          |          D ]\  }}|                                }|r|dz  }"t	          |t
          t          f          st          d| dt                     X||dz                                            }t	          |t                    r|||}	}|
                    fdt          t          t          t
          |          t          t
          |          t          |	          z   d          |	          D                        d}t	          |t
          t          f          rt	          ||dz                                            t
          t          f          r||||dz                                            c}}
|
                    fd	t          t          t
          |          t          t
          |
dz             d          D                        d}t          d
| dt                     dS )zRParses the /W array from a DescendantFont dictionary and updates character widths.c                ^    i | ]*\  }}t          |t                    t          |          |+S r7   )rg   r&   ord)ra   _target
_surrogates      r9   re   z6Font._collect_cid_character_widths.<locals>.<dictcomp>   sD     
 
 
#'3''
LL*
 
 
r8   r   z/Wr   z&Expected numeric value for width, got z. Ignoring it.c                0    i | ]\  }}|v 	|         |S r7   r7   )ra   _cidx_widthord_maps      r9   re   z6Font._collect_cid_character_widths.<locals>.<dictcomp>   s@       )E6 !G+  r8   r   c                *    i | ]}|v |         S r7   r7   )ra   rx   const_widthrz   s     r9   re   z6Font._collect_cid_character_widths.<locals>.<dictcomp>   s<       ! !G+  r8   z-Invalid font width definition. Last element: .N)itemsr_   ri   
get_objectrg   r3   r*   r   r?   r   rh   zipranger	   len)rq   rX   rY   
skip_count_wrb   w_entryw_next_entry	start_idx
width_liststop_idxr|   rz   s              @@r9   _collect_cid_character_widthsz"Font._collect_cid_character_widths   s   

 
'/~~'7'7
 
 
 
ZZb!!%bMM 6	 6	LC((**G a
gU|44  ____aijjjcAg;1133L,11 *(/:	%%   -0! $S) 4 4 $S) 4 4s: F ! 
 '. .     

L3,77 J37&&((3,= =   sQwK**,, 1	8[
 %%    %* i00$sHqL2I2I1& &     

 NGNNN   g6	 6	r8   r4   r3   c                N   | sd| d<   d S d| v rS| d         dk    rG|t           j        z  t           j        k    r| d         | d<   d S t          d| d         z            | d<   d S d |                                 D             }|rt	          |          t          |          z  nd| d<   d S )NrR   rQ    r   r   c                    g | ]
}|d k    |S )r   r7   )ra   ws     r9   
<listcomp>z+Font._add_default_width.<locals>.<listcomp>   s!    DDDaa!eDDDDr8   )r   FIXED_PITCHr3   valuessumr   )rY   r4   valid_widthss      r9   _add_default_widthzFont._add_default_width   s     	(+N9%F.  	^C%8A%= 		--)2GG ,:3,?y)(+As0C,C(D(DN9%F ED>#8#8#:#:DDDNZ$cC$5$5\9J9J$J$J`cy!!!r8   c                    |                      dd          }|dk    r|S |t          j        z  t          j        k    r| d         S | d         dz  S )Nr   r   rQ   r   )r_   r   r   )rH   r4   rT   s      r9   _add_space_widthzFont._add_space_width   s]    &**322! 	I))i.CC 	/#I..	*a//r8   font_descriptor_objdict[str, Any]c           
        i }dD ]\  }}|| v r| |         ||<   d|v rJt          t          t          |d                             }t          |          dk    s
J |            ||d<   dD ]r}|| v rld|v rt	          d|            	 | |                                         }||d<   =# t          $ r(}t          d|d|  d	| t                     Y d }~jd }~ww xY ws|S )
N)
)z	/FontNamer'   )z/FontFamilyr(   )z/FontWeightr)   )z/Ascentr+   )z/Descentr-   )z
/CapHeightr.   )z/XHeightr/   )z/ItalicAngler1   )z/Flagsr4   )	/FontBBoxr=   r=   r   )z	/FontFilez
/FontFile2z
/FontFile3r>   z!More than one /FontFile found in zFailed to get z in z: )tuplemapr*   r   r   r   r   r?   )r   font_descriptor_kwargs
source_key
target_key
bbox_tupler>   es          r9   _parse_font_descriptorzFont._parse_font_descriptor   sw   13'
 	U 	U"J
 00 U5H5T&z2++ 	8s5*@*HIIJJJz??a'33333-7"6* D 		l 		lJ00 l"88 b&'`K^'`'`aaal 3J ? J J L LI:C*;77# l l l"#`J#`#`FY#`#`]^#`#`bjkkkkkkkkll &%s   B''
C1CCc           
        ddl m} |                    dd                              d          }|                    dd                              d          }t	          |          \  }}d }i }d}	|                    d          dv rr|d	k    r2d
|vr.t          d |                    d          pg D                       }	|	r5d|v r|                     ||||           n||v r||         j        }||         j        }d|v r|                    dt                                
                                }
d|
v r0t          t          |
d         
                                          |d<   t          di |                     |
          }nd|v rit          t!          t"          t          t$          |d                                       }t'          |          dk    s
J |            t          ||          }nt)          t          t$          |d                             D ]\  }}t          t          |
                                          }|t          t$          |d                   |<   |                     |||           d|v r0t          t          |d         
                                          |d<   |                    dt                                
                                }
t          di |                     |
          }|st          |          }|                    dd          dk    r|                     ||j                   |                     ||j                  } | ||||||||	          S )Nr   )CORE_FONT_METRICS	/BaseFontr%   //SubtypeT)/Type1z/MMType1z	/TrueTypez/Type3Type3z
/ToUnicodec              3  (   K   | ]}|t           v V  d S )Nr   )ra   cnames     r9   	<genexpr>z*Font.from_font_resource.<locals>.<genexpr>$  s;       $ $ \)$ $ $ $ $ $r8   z
/CharProcsr]   z/FontDescriptorz/MissingWidthrQ   r   r   )r'   r=   z/DescendantFontsz/DW)r'   r'   rO   rL   rF   rN   rH   rT   rV   r7   )pypdf._codecs.core_font_metricsr   r_   removeprefixr   allrp   rF   rH   r   r   r	   r3   r$   r   r   r   r*   r
   r   ri   r   r   r4   r   )clsrW   r   r'   rO   rL   rN   rF   rH   rV   r   r   
d_font_idxrq   rT   s                  r9   from_font_resourcezFont.from_font_resource  s   
 	FEEEEE   i88EEcJJ $$Z;;HHMM".}"="=-+- Z((,YY -	d
 7" |='H  # $ $!.!2!2<!@!@!FB$ $ $ ! !  Q- P77%}h@P    .. P&7&=&MO'8'>'O$$5 	Q*7*;*;<MO_OaOa*b*b*m*m*o*o'&*== s6:3@STc@d@o@o@q@q6r6r(3&4&g&gs7Q7QRe7f7f&g&gOO M1 Q!&s5${MR]D^2_2_'`'`!a!aJz??a/;;;;;&4$Z&P&P&PO '0[-0B"CDD' ' d d"
F .0A0A0C0CDDSY[-0B"CDDZP11M+;   F? X26sF5M<T<T<V<V2W2W$Y/&,jj1BDTDVDV&W&W&b&b&d&d#"0"c"c33M3MNa3b3b"c"c 	8,$777O	1--2 	L""#3_5JKKK**+;_=RSSs+'-#'	
 	
 	
 		
r8   headerr   
postscriptr   os2r   c                t   |r|j         }|j        dz	  }d}| j        t          z  s|r|j        t
          z  r|t          j        z  }|r|j        }|dk    r|t          j        z  }|r|j	        t          k    s|r|j        dk    r|t          j        z  }|r*|t          k    s|j        t          k    r|t          j        z  }|r8d|j        cxk    rdk    sn d|cxk    rdk    sn |dk    r|t          j        z  }|r0|t&          k    s|j        t(          t*          hv r|t          j        z  }n|t          j        z  }|S )	N   r   r0   r   r    r   r      )panosesFamilyClassmacStyleHEADER_MACSTYLE_ITALICfsSelectionOS2_FSSELECTION_ITALICr   ITALICitalicAnglebProportion!OS2_PANOSE_BPROPORTION_MONOSPACEDisFixedPitchr   OS2_SFAMILYSCLASS_SCRIPTSbFamilyTypeOS2_PANOSE_BFAMILYTYPE_SCRIPTSCRIPTbSerifStyleSERIFOS2_SFAMILYSCLASS_SYMBOLIC!OS2_PANOSE_BFAMILYTYPE_DECORATIVE OS2_PANOSE_BFAMILYTYPE_PICTORIALSYMBOLICNONSYMBOLIC)r   r   r   r   family_classr4   r1   s          r9   %_font_flags_from_truetype_font_tablesz*Font._font_flags_from_truetype_font_tables`  s     	1ZF +q0L ?33 	& 	&Rh@h 	&Y%%E 	*%1Ls" *)) 	+'+LL	+	+&3a7	+ Y**E  	&55	&9?9KOl9l	& Y%%E  	%#	% 	% 	% 	%')	% 	% 	% 	%L	% 	% 	% 	%$%	% 	% 	% 	%)5):	% Y_$E  	+66	+#DFf"gg	+ Y''EEY**Er8   r>   r   c           
        t           st          d          t          |          5 }|d         }|d         }|d         j        }|                    dd           }|                    dd           }|j        }d|z  }	i }
|                    dd           }|rE|                                |
d<   |                                |
d	<   |                                |
d
<   t          t          |j        |	z  d                    |
d<   t          t          |j        |	z  d                    |
d<   |rb	 t          t          |j        |	z  d                    |
d<   t          t          |j        |	z  d                    |
d<   n# t          $ r Y nw xY w|                     |||          |
d<   t          |j        |	z  d          t          |j        |	z  d          t          |j        |	z  d          t          |j        |	z  d          f|
d<   t+                      }|                                }|                    |           |                    t3          d          t5          t7          |                    i           ||
d<   t9          di |
}d}i }i }|                                }|                    d          }|r|                                }t?          |          D ]\  }}|                    |          }|tA          |          }|!                    |          }|"                    dd          }|#                    dd          }|||<   t          t          ||         d         |	z  d                    ||<   ntI          d          | %                    ||
d                    | &                    ||
d                   }d d d            n# 1 swxY w Y    | |j'        d|||||d          S )NzDThe 'fontTools' library is required to use 'from_truetype_font_file'headhheahmtxpostzOS/2r6   r'   r(   r)   r   r+   r-   r.   r/   r4   r=   z/Length1r>   	utf_16_becmapr   bigz	utf-16-berf   z$Font file does not have a cmap tableTrueTypeTr   r7   )(HAS_FONTTOOLSImportErrorr   metricsr_   
unitsPerEmgetBestFullNamegetBestFamilyNamegetBestSubFamilyNamer3   roundr+   r-   
sCapHeightsxHeightAttributeErrorr   xMinyMinxMaxyMaxr   getvalueset_datarh   r   r   r   r$   getGlyphOrderbuildReversedMinri   r`   
getGlyphIDto_bytesrk   r   r   r   r'   )r   r>   tt_font_objectr   horizontal_headerr   r   r   units_per_emscale_factorr   namesfont_file_datafont_file_raw_bytesrF   rL   rH   rN   glyph_ordertt_font_cmap_tablereverse_cmapgidglyphrm   char	gid_bytesgid_key_stringrT   s                               r9   from_truetype_font_filezFont.from_truetype_font_file  s    	fdeeeI K	b.
 $F+F .v 6$V,4G (++FD99J $$VT22C ",L!L0L 68""&&vt44E P161F1F1H1H&v.383J3J3L3L&x0383M3M3O3O&x0/259J9QT`9`bc3d3d/e/e"8,03E:K:SVb:bde4f4f0g0g"9- ;>uS^VbEbde?f?f;g;g*<89<U3<R^C^`a=b=b9c9c*:66%   D /2.W.WX^`jlo.p.p"7+ fkL0!44fkL0!44fkL0!44fkL0!44	."6* *^^N"+"4"4"6"6##$7888!!:j#9#9<L_H`H`;a;a"bccc2@";/,FF/EFFO"H/1,.M(6688K "0!3!3F!;!;! K1BBDD"+K"8"8 
g 
gJC , 0 0 7 7I  ! y>>D(33E::C #Q 6 6I%.%5%5k?%S%SN48M.17:5PQARUaAacd;e;e7f7f$^44
g ##IJJJ""#35KG5TUUU../?AWX_A`aaKWK	b K	b K	b K	b K	b K	b K	b K	b K	b K	b K	b K	b K	b K	b K	bZ s %+'-#	
 	
 	
 		
s8   DO.AE?>O?
F	OFIOO!Oc                X   t          t          d          t          d          t          d          t          d| j                   t          d          t          d          t          d          t          d| j                   t          d          t          d	          i          S )
Nr   r   z/Namer   z/Typez/Fontr   z	/Encodingz/WinAnsiEncoding)r   r   r'   )selfs    r9   as_font_resourcezFont.as_font_resource  s     :&&
8(<(<7##ZDI%@%@7##Z%8%8;''O	OO)D)D;''4F)G)G  	
r8    textr*   c                <     t           fd|D             d          S )zDSum of character widths specified in PDF font for the supplied text.c                \    g | ](}j                             |j         d                    )S )rQ   )rH   r_   )ra   r   r  s     r9   r   z#Font.text_width.<locals>.<listcomp>   s5    ```SWT"&&tT-B9-MNN```r8   r0   )r   )r  r  s   ` r9   
text_widthzFont.text_width  s0    ````[_```be
 
 	
r8   N)
rW   r   rX   rM   rL   rK   rY   rG   rZ   r[   )rq   r   rX   rM   rY   rG   rZ   r[   )rY   rG   r4   r3   rZ   r[   )rH   rG   r4   r3   rZ   r3   )r   r   rZ   r   )rW   r   rZ   rJ   )r   r   r   r   r   r   rZ   r3   )r>   r   rZ   rJ   )rZ   r   )r  )r  r&   rZ   r*   )r?   r@   rA   rB   rC   r   dictrN   rO   r$   rF   rH   rT   rV   staticmethodrp   r   r   r   r   classmethodr   r   r   r  r  r7   r8   r9   rJ   rJ   F   s	         $ III""""$)E$$?$?$?M????H&+eN&K&K&KOKKKK',u=U=U'V'V'VVVVV"K""""M6 6 6 \6> F F F \FP d d d \d$ 0 0 0 \0 !& !& !& \!&F O
 O
 O
 [O
b 2 2 2 \2h Y
 Y
 Y
 [Y
v

 

 

 


 
 
 
 
 
 
r8   rJ   N)2
__future__r   collections.abcr   dataclassesr   r   typingr   r   r	   pypdf.genericr
   r   r   r   r   _cmapr   _codecs.adobe_glyphsr   _utilsr   	constantsr   errorsr   ior   fontTools.ttLib.tables._h_e_a_dr   fontTools.ttLib.tables._p_o_s_tr   fontTools.ttLib.tables.O_S_2f_2r   fontTools.ttLibr   r   r   r   r   r   r   r   r   r   r   r$   rE   rJ   r7   r8   r9   <module>r     ss   " " " " " " $ $ $ $ $ $ ( ( ( ( ( ( ( ( + + + + + + + + + + _ _ _ _ _ _ _ _ _ _ _ _ _ _       . . . . . . " " " " " "                         ?>>>>>>>>>>>>>>>>>>&&&&&&MM   MMM
    ! $% !#$  $% !   $* * * * * * * *. $% % % % % % % %
 z
 z
 z
 z
 z
 z
 z
 z
 z
 z
s   &A/ /A98A9