
    Mi7                         S SK Jr  S SKJrJr  S SKJrJrJr  S SK	J
r
JrJr  SSKJr  SSKJr  SSKJr  SS	KJr  \" S
S9 " S S5      5       r\" S
S9 " S S5      5       r\ " S S5      5       rg)    )Sequence)	dataclassfield)AnyUnioncast)ArrayObjectDictionaryObject
NameObject   )get_encodingadobe_glyphs)logger_warning)	FontFlagsT)frozenc                       \ rS rSr% SrSr\\S'   Sr\\S'   Sr	\\S'   Sr
\\S'   S	r\\S
'   Sr\\S'   Sr\\S'   Sr\\S'   Sr\\S'   \" S S9r\\\\\4   \S'   Srg)FontDescriptor   z
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namefamilyweightg     @ascent      idescentg     @
cap_heightg     @@x_height        italic_angle    flagsc                      g)N)g      Yr   g     @@g      @ r$       e/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/pypdf/_font.py<lambda>FontDescriptor.<lambda>!   s    Lkr%   default_factorybboxr$   N)__name__
__module____qualname____firstlineno____doc__r   str__annotations__r   r   r   floatr   r   r   r    r"   intr   r+   tuple__static_attributes__r$   r%   r&   r   r      s     D#FCFCFEGUJHeL%E3O.3Dk.lD%ueU*
+lr%   r   c                   4    \ rS rSr% \\S'   \\\4   \S'   Sr	g)CoreFontMetrics$   font_descriptorcharacter_widthsr$   N)
r,   r-   r.   r/   r   r2   dictr1   r4   r6   r$   r%   r&   r8   r8   $   s    ##38n$r%   r8   c                      \ rS rSr% Sr\\S'   \\\\	\4   4   \S'   \
" \S9r\\\4   \S'   Sr\\S'   \
" \S9r\\S	'   \
" S
 S9r\\\	4   \S'   Sr\\\	4   \S'   Sr\\S'   \S\S\\\4   S\\\\	\4   4   S\\\	4   SS4
S j5       r\S\S\\\4   S\\\	4   SS4S j5       r\S\\\	4   S\	SS4S j5       r\S\S\\\4   4S j5       r\S\SS 4S j5       rS\4S jrS!S\S\4S jjrS rg)"Font*   a  
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   encodingr)   character_mapr   sub_typer:   c                  
    SS0$ )Ndefault  r$   r$   r%   r&   r'   Font.<lambda>C   s
    iQTEUr%   r;      space_widthTinterpretablepdf_font_dictchar_mapcurrent_widthsreturnNc                    [        [        U S   5      nU R                  SS5      n[        U[        5      (       dN  UR                  [        U5       VVs0 s H%  u  pgUR                  Xe-   [        Xe-   5      5      U_M'     snn5        g[        U5       HY  u  pgXe-   n[        U/5      R                  US5      n	UR                  U	5      n
U
(       a  [        U5      X:'   ML  [        U5      X9'   M[     gs  snnf )zcParses a TrueType or Type1 font's /Widths array from a font dictionary and updates character widths/Widthsz
/FirstCharr   Nsurrogatepass)r   r	   get
isinstancer1   update	enumeratechrbytesdecoder4   )rJ   rK   r@   rL   widths_array
first_charidxwidth	char_coderaw_charunicode_chars              r&   _collect_tt_t1_character_widths$Font._collect_tt_t1_character_widthsG   s     Ky)AB"&&|Q7
(C((!!"+L"9#"9JC S-s33C/DEuL"9#   $L1JC(Ii[)00?KH#<<1L/25z,+.u:( 2#s   ,C2
d_fontc                 |   UR                  5        VVs0 s H(  u  p4[        U[        5      (       d  M  [        U5      U_M*     nnnSnU R	                  S/ 5      n[        U5       GH  u  pU	R                  5       n	U(       a  US-  nM$  [        U	[        [        45      (       d  [        SU	 S3[        5        MU  XxS-      R                  5       n
[        U
[        5      (       as  XpUR                  [        [        [        [        U5      [        [        U5      [!        U5      -   S5      U5       VVs0 s H  u  pX;   d  M  X]   U_M     snn5        SnM  [        U
[        [        45      (       a  [        XxS-      R                  5       [        [        45      (       as  U	U
XxS-      R                  5       npUR                  [        [        [        U5      [        [        US-   5      S5       Vs0 s H  nX;   d  M
  X]   U_M     sn5        SnGM  [        SU	 S3[        5        GM     g	s  snnf s  snnf s  snf )
zRParses the /W array from a DescendantFont dictionary and updates character widths.r   z/Wr   z&Expected numeric value for width, got z. Ignoring it.   z-Invalid font width definition. Last element: .N)itemsrR   r1   ordrQ   rT   
get_objectr4   r3   r   r,   r   rS   zipranger   len)ra   rK   rL   _target
_surrogateord_map
skip_count_wrZ   w_entryw_next_entry	start_idx
width_list_cidx_widthstop_idxconst_widths                    r&   _collect_cid_character_widths"Font._collect_cid_character_widthsg   s:    (0~~'7
'7#'3' %CL*$'7 	 
 
ZZb!%bMLC((*Ga
gU|44 !GyP^_aijAg;113L,11(/:%% .1! $S) 4 $S) 4s: F !
 '..ME !+ /.. 
L3,77J7&&(3,= =  QwK**, &18
 %% &+ i0$sHqL2I1&&E !+	 43& 
 CG9ANg *
60s"   H-H-3H3	H31	H9
>	H9
r"   c                 `   U (       d  SU S'   g SU ;   aL  U S   S:w  aC  U[         R                  -  [         R                  :X  a	  U S   U S'   g [        SU S   -  5      U S'   g U R                  5        Vs/ s H  o"S:  d  M
  UPM     nnU(       a  [	        U5      [        U5      -  OSU S'   g s  snf )NrE   rD    r   rc   )r   FIXED_PITCHr4   valuessumrj   )rL   r"   wvalid_widthss       r&   _add_default_widthFont._add_default_width   s    (+N9%. ^C%8A%=	---)2G2GG,:3,?y)(+As0C,C(DN9% $2#8#8#:D#:a!e#:DNZC$5\9J$J`cy! Es   2	B+?B+font_descriptor_objc                     0 nS H  u  p#X ;   d  M  X   X'   M     SU;   a6  [        [        [        US   5      5      n[        U5      S:X  d   U5       eXAS'   U$ )N)
)z	/FontNamer   )z/FontFamilyr   )z/FontWeightr   )z/Ascentr   )z/Descentr   )z
/CapHeightr   )z/XHeightr   )z/ItalicAngler    )z/Flagsr"   )	/FontBBoxr+   r+      )r5   mapr3   rj   )r   font_descriptor_kwargs
source_key
target_key
bbox_tuples        r&   _parse_font_descriptorFont._parse_font_descriptor   sr    13'
"J 05H5T&2'
 ++s5*@*HIJJz?a'33'-76*%%r%   c                 N   SSK Jn  UR                  SS5      R                  S5      nUR                  SS5      R                  S5      n[	        U5      u  pVS n0 nSn	UR                  S5      S;   Ga;  US	:X  a0  S
U;  a*  [        S UR                  S5      =(       d    /  5       5      n	U	(       a  SU;   a  U R                  XXX5        O!X2;   a  X#   R                  nX#   R                  nSU;   an  UR                  S[        5       5      R                  5       n
SU
;   a$  [        [        U
S   R                  5       5      US'   [        S0 U R                  U
5      D6nGO'SU;   aI  [        [!        ["        [        [$        US   5      5      5      n['        U5      S:X  d   U5       e[        X;S9nO[)        [        [$        US   5      5       H  u  p[        [        UR                  5       5      nU[        [$        US   5      U'   U R+                  XU5        SU;   a$  [        [        US   R                  5       5      US'   UR                  S[        5       5      R                  5       n
[        S0 U R                  U
5      D6nM     U(       d	  [        US9nUR                  SS5      S:X  a  U R-                  XR.                  5        UR                  SS5      nUS:X  a=  UR.                  [0        R2                  -  [0        R2                  :X  a  US   nOUS   S-  nU " UUUUUUUU	S9$ )Nr   )CORE_FONT_METRICS	/BaseFontr   //SubtypeT)/Type1z/MMType1z	/TrueTypez/Type3Type3z
/ToUnicodec              3   4   #    U  H  nU[         ;   v   M     g 7f)Nr   ).0cnames     r&   	<genexpr>*Font.from_font_resource.<locals>.<genexpr>   s      $!F \)!Fs   z
/CharProcsrO   z/FontDescriptorz/MissingWidthrD   r   r   )r   r+   z/DescendantFontsz/DW)r   r{   rc   )r   rB   r@   r:   rA   r;   rH   rI   r$   )pypdf._codecs.core_font_metricsr   rQ   removeprefixr   allr_   r:   r;   r
   rg   r   r4   r   r   r5   r   r3   r	   rj   rT   rx   r   r"   r   r|   )clsrJ   r   r   rB   r@   rA   r:   r;   rI   r   r   
d_font_idxra   rH   s                  r&   from_font_resourceFont.from_font_resource   s#   
 	F   i8EEcJ $$Z;HHM".}"=+- Z(,YY
 7"|='H # $!.!2!2<!@!FB!F$ ! -77%h .&7&=&M&MO'8'>'O'O$$5*7*;*;<MO_Oa*b*m*m*o'&*==6:3@STc@d@o@o@q6r(3&4&gs7Q7QRe7f&gO M1!&s5${MR]D^2_'`!aJz?a/;;/&4$&PO '0[-0B"CD'"
 .0A0A0CDSY[-0B"CDZP11+; F?26sF5M<T<T<V2W$Y/&,jj1BDTDV&W&b&b&d#"0"c33M3MNa3b"c' ,$7O	1-2""#35J5JK&**32!%%	(=(==)BWBWW.y9.y9Q>+'-#'	
 		
r%   c                    [        [        S5      [        S5      [        S5      [        SU R                   35      [        S5      [        S5      [        S5      [        SU R                   35      [        S5      [        S	5      05      $ )
Nr   r   z/Namer   z/Typez/Fontr   z	/Encodingz/WinAnsiEncoding)r
   r   r   )selfs    r&   as_font_resourceFont.as_font_resource1  sv     :&
8(<7#Z!DII;%@7#Z%8;'a		{O)D;'4F)G 	
r%   textc           
          [        U Vs/ s H*  o R                  R                  X R                  S   5      PM,     snS5      $ s  snf )zDSum of character widths specified in PDF font for the supplied text.rD   r   )r~   r;   rQ   )r   r   chars      r&   
text_widthFont.text_width=  sD    [_`[_SW""&&t-B-B9-MN[_`be
 	
`s   1Ar$   ) ) r,   r-   r.   r/   r0   r1   r2   r   r<   r4   r   rA   r   rB   r   r:   r;   rH   r3   rI   boolstaticmethodr
   r_   rx   r   r   classmethodr   r   r   r6   r$   r%   r&   r>   r>   *   s   $ ICc3h'(($)$$?M4S>?Hc&+N&KO^K',=U'Vd38nV%(Kucz"(M46'6sCx.6 T#s(^+,6 S#X	6
 
6 6> F F,0cNFLPQTVYQYNF	F FP d4S> d# d$ d d$ &4D &cSVh & &. S
'S
 
S
 S
j

"2 


s 
E 
 
r%   r>   N)collections.abcr   dataclassesr   r   typingr   r   r   pypdf.genericr	   r
   r   _cmapr   _codecs.adobe_glyphsr   _utilsr   	constantsr   r   r8   r>   r$   r%   r&   <module>r      s~    $ ( # # C C  . "   $m m m, $% % %
 V
 V
 V
r%   