
    JՁj                       d dl mZ d dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
 d dlm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 ddlmZ ddlmZmZ ddlmZmZm Z m!Z! ddl"m#Z# ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z, ddl-m.Z.m/Z/ erd dl0m1Z1 ddlm2Z2 	 d dl3Z3d dl4m5Z5 dZ6dZ8dZ9e G d d             Z: G d de&      Z; G d de      Z< G d d e      Z= G d! d"e;      Z>y# e7$ r dZ6Y Iw xY w)#    )annotationsN)	dataclassfield)IntEnum)BytesIO)
attrgetter)TYPE_CHECKINGAny
NamedTuplecast   )!encoding_dict_from_named_encoding)CORE_FONT_METRICS)Font)Transformation)is_char_rtllogger_warning)AnnotationDictionaryAttributesBorderStylesFieldDictionaryAttributesPageAttributes)PdfReadError)ArrayObjectDecodedStreamObjectDictionaryObjectFloatObjectIndirectObject
NameObjectNumberObjectRectangleObject)ByteStringObjectTextStringObject)	PdfWriter)
PageObject)get_displayTF   i  c                  n    e Zd ZU dZ ed       Zded<   dZded<   ej                  Z
d	ed
<   dZded<   y)BaseStreamConfigzBA container representing the basic layout of an appearance stream.c                     t        d      S )N)        r*   r*   r*   )r         G/tmp/pip-target-jj2dfcxx/lib/python/pypdf/generic/_appearance_stream.py<lambda>zBaseStreamConfig.<lambda>4   s    Oc?d r,   )default_factoryr    	rectangle   intborder_widthstrborder_styler   rotationN)__name__
__module____qualname____doc__r   r0   __annotations__r3   r   SOLIDr5   r6   r+   r,   r-   r(   r(   1   s9    L!&7d!eIeL#$**L#*Hcr,   r(   c                  ,     e Zd ZdZddZd fdZ xZS )BaseStreamAppearancez^A class representing the very base of an appearance stream, that is, a rectangle and a border.c                   t               j                  |      }| j                  j                  j                  df}d| j                  j                  j
                  f}| j                  j                  j                  | j                  j                  j
                  f}|j                  |      }|j                  |      }|j                  |      }t        d|d   |d   |d          }	t        d|d   |d   |d          }
|j                  |	|
      }t        |j                  D cg c]  }t        t        |d             c}      | t        d      <   y c c}w )Nr*   r   r1      z/Matrix)r   rotate_layoutr0   widthheightapply_onmin	translater   ctmr   roundr   )selfr6   matrixbottom_right_cornertop_left_cornertop_right_cornerrotated_bottom_right_cornerrotated_top_left_cornerrotated_top_right_cornertranslation_x_offsettranslation_y_offsetis               r-   _add_matrixz BaseStreamAppearance._add_matrix=   sK   
  !((2#||55;;SA 6 6 = => LL2288$,,:P:P:W:WX&,oo6I&J#"(///"B#)??3C#D  #,Q/1H1KMefgMh!
  
 !$,Q/1H1KMefgMh!
  
 !!"68LM&1U[U_U_2`PQ;uQ{3K2`&aZ	"#2`s   &Ec                B   t         |           |xs
 t               | _        t	        d      | t	        d      <   t	        d      | t	        d      <   | j                  j
                  | t	        d      <   | j                  j                  dz  }|r| j                  |       yy)z
        Takes the appearance stream layout as an argument.

        Args:
            layout: The basic layout parameters.
        z/XObject/Typez/Form/Subtype/BBoxih  N)super__init__r(   rB   r   r0   r6   rU   )rJ   layoutr6   	__class__s      r-   r[   zBaseStreamAppearance.__init__R   s     	3!1!3$.z$:Z !'1'':Z
#$$(LL$:$:Z ! <<((3.X& r,   )r6   r2   returnNone)r\   BaseStreamConfig | Noner^   r_   )r7   r8   r9   r:   rU   r[   __classcell__r]   s   @r-   r>   r>   :   s    hb*' 'r,   r>   c                      e Zd ZdZdZdZdZy)TextAlignmentzODefines the alignment options for text within a form field's appearance stream.r   r1   r   N)r7   r8   r9   r:   LEFTCENTERRIGHTr+   r,   r-   rd   rd   e   s    YDFEr,   rd   c                  0    e Zd ZU dZded<   ded<   ded<   y)WidthWordGlyphszgA tuple of the unscaled width of a word (unencoded text) and the font-encoded glyphs that represent it.floatrC   r4   wordglyphsN)r7   r8   r9   r:   r;   r+   r,   r-   ri   ri   m   s    qL
IKr,   ri   c                      e Zd ZdZ	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddddej                  ddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdd	dddddddej                  ddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd
Ze		 	 	 	 	 	 	 	 	 	 dd       Z
e		 d	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z xZS )TextStreamAppearanceaH  
    A class representing the appearance stream for a text-based form field.

    This class generates the content stream (the `ap_stream_data`) that dictates
    how text is rendered within a form field's bounding box. It handles properties
    like font, font size, color, multiline text, and text selection highlighting.
    c	                   g }	g }
d}|j                   |z  t        z  }|D ]v  }t        |      D ]  \  }}|j                  |z  }||z   |r|ndz   }||kD  rs|
rq|	j	                  t        |dj                  t        t        d      |
            |j                  j                  t        t        d      |
                         |g}
|}|
s;||kD  r6|	j	                  t        ||j                  |j                               g }
d}|
r||z  }|
j	                  |       ||z  } |
s|	j	                  t        |dj                  t        t        d      |
            |j                  j                  t        t        d      |
                         g }
d}y |t        |	      dz
  |z  |z  z   }||kD  r"||z
  }||k\  r| j                  ||||||||      S |	t        |d      fS )a  
        Takes a piece of text and scales it to field_width or field_height, given font_name
        and font_size. Wraps text where necessary.

        Args:
            font: The font to be used.
            font_size: The font size in points.
            leading_factor: The line distance.
            field_width: The width of the field in which to fit the text.
            field_height: The height of the field in which to fit the text.
            paragraphs: The list of text paragraphs to fit with the field, where each paragraph is a list
                of tuples of unscaled width, unencoded text, and glyphs (font-encoded text).
            min_font_size: The minimum font size at which to scale the text.
            font_size_step: The amount by which to decrement font size per step while scaling.

        Returns:
            The text in the form of list of tuples, each tuple containing the length of a line
            and its contents, and the font_size for these lines and lengths.
        r    rk   rl   rC   rk   rl   r1   )space_width TEXT_SPACE_TO_GLYPH_SPACE_FACTOR	enumeraterC   appendri   joinmapr   
space_charrk   rl   len_scale_textrI   )rJ   font	font_sizeleading_factorfield_widthfield_height
paragraphsmin_font_sizefont_size_stepwrapped_linescurrent_line_wordscurrent_line_widthrr   	paragraphrT   width_word_glyphs
word_width
test_widthestimated_total_heightnew_font_sizes                       r-   rz   z TextStreamAppearance._scale_text~   s0   < 46$%&&25UU# $	'I(1)(< 5$$.44y@
/*<qVWX
+0B!(('"4!$#j.@BT*U!V#'??#7#7Jx<PRd8e#f +<)<&)3&+
[0H!(('",!2!7!7#4#;#; *,&)*&)*k9*&--.?@&*4&758 "$$_,#j&8:L"MN??//Jx4HJ\0]^& 
 &("%&"I$	'L "+c-.@1.D-VYb-b!b!L0%6M-''!" !"	 	 eIq111r,   /Helvr*   z0 gFNc                N   | j                   j                  }|j                  j                  d   |j                  j                  d   z
  t        z  }| j                   j
                  dv rdnd}t        | j                   j                  |z  d      }|j                  d|z  z
  }|j                  d|z  z
  }|j                         \  }}d*d}d+d}|dk(  r9d	}|rd
}|rt        }g }|j                         D ]  }|j                         s|j                  t        ddd      g       2g }|j!                  d      }|D ]>  } |||      }|j                  t        |j#                  |      t        z  ||             @ |j                  |        | j%                  |||||||      \  }}nE||z  } |||      }|j#                  |      t        z  }||xs dz  } t'        t        t)        ||       |      d      }t        ||z  ||      g}n|	r|
r!t+        |      |
kD  rt-        dt.        ||
       g }t1        |      D ]W  \  }!}"|!|
xs t+        |      k  s ||"|      }|j                  t        |j#                  |      |z  t        z  |"|             Y nVg }|j                         D ]A  } |||      }|j                  t        |j#                  |      |z  t        z  ||             C |r4|j                  |z   |j                  j                  d   |z  t        z  z
  }#n)|||j                  j2                  |z  t        z  z
  dz  z   }#| d| d| }$dd|z   d| d| d| d|$ dj5                         }%d}&t1        |      D ]  \  }'\  }(})}|rV| |dj7                  |      |      v r<|%d|#|'|z  |z  z
  dz
   d|j                  dz
   d|dz    d|$ d	j5                         z  }%d}*|	r"|
r |j                  |
z  }+|+|(z
  dz  },|'|+z  |,z   }*nT|t8        j:                  k(  r|j                  |dz  z
  |(z
  }*n+|t8        j<                  k(  r|j                  |(z
  dz  }*n|dz  }*|*|&z
  }-d}.|'dk(  r|#}.n|	rd}.n| |z  }.|%|- d|. dj5                         z  }%|*}&t?        d |D              }/ |||      }0|/rId|)j5                  d      z   }1|1jA                         jC                         }2|%d|2 dj5                         z  }%|jD                  dk(  r7|%ddj7                  |0      jA                         j5                         z   d z   z  }%nLdj7                  |0      jG                  d!d"      jG                  d#d$      jG                  d%d&      }3|%d#|3z   d'z   z  }%|/s|%d(z  }% |%d)z  }%|%S ),a  
        Generates the raw bytes of the PDF appearance stream for a text field.

        This private method assembles the PDF content stream operators to draw
        the provided text within the specified rectangle. It handles text positioning,
        font application, color, and special formatting like selected text.

        Args:
            text: The text to be rendered in the form field.
            selection: An optional list of strings that should be highlighted as selected.
            font: The font to use.
            font_name: The name of the font resource to use (e.g., "/Helv").
            font_size: The font size. If 0, it is automatically calculated
                based on whether the field is multiline or not.
            font_color: The color to apply to the font, represented as a PDF
                graphics state string (e.g., "0 g" for black).
            is_multiline: A boolean indicating if the text field is multiline.
            alignment: Text alignment, can be TextAlignment.LEFT, .RIGHT, or .CENTER.
            is_comb: Boolean that designates fixed-length fields, where every character
                fills one "cell", such as in a postcode.
            max_length: Used if is_comb is set. The maximum number of characters for a fixed-
                length field.

        Returns:
            A byte string containing the PDF content stream data.

        r@   r1   >   /B/Ir      c                    t         r<t        j                  |       }t        |d      }dj	                  fd|D              S dj	                  fd| D              S )NL)base_dir c              3  B   K   | ]  }j                  ||        y wNget.0charreverse_cmaps     r-   	<genexpr>zfTextStreamAppearance._generate_appearance_stream_data.<locals>._unicode_to_glyph_id.<locals>.<genexpr>  s     T|//d;T   c              3  B   K   | ]  }j                  ||        y wr   r   r   s     r-   r   zfTextStreamAppearance._generate_appearance_stream_data.<locals>._unicode_to_glyph_id.<locals>.<genexpr>  s     ID<++D$7Ir   )HAS_RTL_SUPPORTarabic_reshaperreshaper%   rv   )textr   reshaped_textvisual_texts    `  r-   _unicode_to_glyph_idzSTextStreamAppearance._generate_appearance_stream_data.<locals>._unicode_to_glyph_id  sL     / 7 7 =)-#FwwTTTT77IDIIIr,   c                    | D cg c]7  }|j                  |t        |      dk  rt        t        |      f      nd      9 c}S c c}w )N      ?)r   ordbytes)rl   encoding_cmapglyph_ids      r-   _glyph_id_to_byteszQTextStreamAppearance._generate_appearance_stream_data.<locals>._glyph_id_to_bytes  sM     %& "%%S]S5H%X 01d & & &s   <Ar   g      @Fr*   r   rq   rp   zZLength of text %(text)s exceeds maximum length (%(max_length)d) of field, input truncated.)sourcer   
max_lengthz Tf zq
/Tx BMC 
q
z	 re
W
BT

z1 z re
0.5 0.5 0.5 rg s
z Td
c              3  2   K   | ]  }t        |        y wr   )r   )r   r   s     r-   r   zHTextStreamAppearance._generate_appearance_stream_data.<locals>.<genexpr>  s     <tT*<s   s   z	utf-16-bez/Span << /ActualText <z	> >> BDC
Type0   <r,   s   > Tj
   \s   \\   (s   \(   )s   \)s   ) Tj
s   EMC
s   ET
Q
EMC
Q
)r   r4   r   zdict[str, str]r^   r4   )rl   r4   r   zdict[str, bytes]r^   zlist[bytes])$rB   r0   font_descriptorbboxrs   r5   maxr3   rD   rC   _get_typographic_mapsDEFAULT_FONT_SIZE_IN_MULTILINE
splitlinesstripru   ri   splitget_text_widthrz   rI   rF   ry   r   r7   rt   ascentencoderv   rd   rg   rf   anyhexuppersub_typereplace)4rJ   r   	selectionr{   	font_namer|   
font_coloris_multiline	alignmentis_combr   r0   r}   factormarginr   r~   r   r   r   r   r   r   lineline_by_widths_words_glyphswordsrk   
glyph_wordlinesmax_vertical_sizerl   text_width_unscaledmax_horizontal_sizeindexr   y_offsetdefault_appearance	ap_streamcurrent_x_posline_number
line_widthoriginal_textdesired_abs_x_start
cell_widthcentering_offset_in_cellx_rel_offsety_rel_offsetis_rtlencoded_linebom_texthex_original_textline_as_bytess4                                                       r-    _generate_appearance_stream_dataz5TextStreamAppearance._generate_appearance_stream_data   s   P LL**	!!&&q)D,@,@,E,Ea,HHLll 	
 ll//<?QT\\..7; ''!f*4ooF
2&*&@&@&B#m	J	& >M$:	 ;=
 OO- CD::<"))?2VX+Y*Z[ IK/ JJsOE % %9$%M
3::+&*&9&9$&?Bb&b%)'1 %%&ABC  $(#3#3" !$ y %1>$A!-dLA&*&9&9&&ADd&d#&15H5MA&N#!#c*;=P&QS`"acde	(/BY/NUYbhijc$i*45 $) E( 	tJ3#d)41$EFLL'"&"5"5f"=	"ILl"l!%#)	 E) -dLA#"11&9IEHhh!%   6)D,@,@,E,Ea,H9,TWw,ww   4 4 ; ;i GJj jjnooH !*{!I;d:,G q6zl!F81[M<. Q,-R1
&( 	  !>G>N B	&:K:*mTT%9"''):Ll%[[[9%<~%MNQRRSST *+1Y]O <));(<B@ &(		 *+:&__z9
 -7,Cq+H('2Z'?C[&[#m111&/oo
&BZ&O#m222'0'Cq&H#&,qj# />L #$La'"!*{^; L><.>EEGGI 0M<t<<F-dMBL ')=)=k)JJ$,LLN$8$8$:!56G5H
SZZ\\	}}'TSXXl%;$@$@$B$I$I$KKiWW	 HH\*WUG,WT6*WT6*	  TM1I==	X%	EB	&F 	''	r,   r   c                   t         |   |       |r|s&d}t        j                         }|j	                         }| j                  |||||||	|
||
      }| j                  t        |             t        t        |            | t        d      <   t        t        d      t        t        |      t        |d|      i      i      | t        d      <   y)a(  
        Initializes a TextStreamAppearance object.

        This constructor creates a new PDF stream object configured as an XObject
        of subtype Form. It uses the `_appearance_stream_data` method to generate
        the content for the stream.

        Args:
            layout: The basic layout parameters.
            text: The text to be rendered in the form field.
            selection: An optional list of strings that should be highlighted as selected.
            font: A Font object. Falls back to Type 1 Helvetica if not given.
            font_resource: An optional variable that represents a PDF font dictionary. Falls back
                to Type 1 Helvetica if not given.
            font_name: The name of the font resource, e.g., "/Helv".
            font_size: The font size. If 0, it's auto-calculated.
            font_color: The font color string.
            is_multiline: A boolean indicating if the text field is multiline.
            alignment: Text alignment, can be TextAlignment.LEFT, .RIGHT, or .CENTER.
            is_comb: Boolean that designates fixed-length fields, where every character
                fills one "cell", such as in a postcode.
            max_length: Used if is_comb is set. The maximum number of characters for a fixed-
                length field.

        r   r   r|   r   r   r   r   r   /Length/Fontindirect_reference
/ResourcesN)rZ   r[   r   from_core_font_nameas_font_resourcer   set_datar!   r   ry   r   r   getattr)rJ   r\   r   r   r{   font_resourcer   r|   r   r   r   r   r   ap_stream_datar]   s                 r-   r[   zTextStreamAppearance.__init__  s    P 	 =I++-D 113M>>!%! ? 
 	&~67&23~3F&GZ	"#)9w!19%w}>RTa'b3 ";
 *Z%&r,   c                4   t        t        |j                  d|j                  dt                                 }|j                  dt                     }|j                  | d       }|rt	        j
                  |      }n@| j                  d      t        vrt        dt        |        d} t	        j                  |       }|j                  |      }|s|j                  j                  ra|j                  dk(  rR	 |j                  t!        |j                  j                  j#                                     }d} |j                  |      }n|j                  dk(  r|j(                  t        v rt        |j(                     }
h d}|D ]  }t+        j*                  |      }t-        |      |_        |j                  |      }|s<|}|j0                  j3                          |j.                  j5                         D ]9  \  }}||
j0                  v s|
j0                  |   |j0                  t7        |      <   ; |
j0                  d   |j0                  d<   d|z   }  n |st        dt        |       | |fS # t$        t&        f$ r}	t        d	t        |	
       Y d }	~	>d }	~	ww xY w)N/DRr   /zEFont dictionary for %(font_name)s not found; defaulting to Helvetica.)r   r   z
/HelveticaTrueTypez/PYPDF1z/Unable to use embedded font for encoding: %(e)s)r   eType1>   cp1250cp1252cp1254cp1257
iso8859_15defaultzText string '%(text)s' contains characters not supported by font encoding. This may result in text corruption. Consider calling writer.update_page_form_field_values with auto_regenerate=True.)r   r   )r   r   get_inheritedr   r   from_font_resourceremoveprefixr   r   r7   r   
can_encoder   	font_filer   from_truetype_font_filer   get_dataImportErrorr   namecopyr   encodingcharacter_widthsclearitemschr)r   
annotation	acro_formr   acro_form_resourcesacro_form_font_resourcesr   r{   	encodabler   core_font_metricstest_encodingsr  	test_fontcode	characters                   r-   _find_annotation_font_resourcez3TextStreamAppearance._find_annotation_font_resource  sz    $($$e%5%78$
 $7#:#:7DTDV#W 044YE**=9D
 %%c*2CC[#'
 )	++I6D OOD)	 ##--$--:2Ml77@T@T@^@^@g@g@i8jkD )I $ 5I
 ')dii;L.L$5dii$@!" !/ H $		$I)J8)TI& ) 4 4T :I (--335/8/A/A/G/G/I qOD)(,=,N,NNCTCeCefoCp 5 5c$i @q <M;];]^g;h--i8$-$8	 k $ $O $\2 l"#T]eijkkls   7AI, ,J;JJc                   |j                  t        d      t                     j                         }||vr|j	                  | |t        |            }n||   }|rmt        t        |t        j                           j                  t        d      t                     j                         }||vrt        |d|      |t        |      <   |S )z
        Unified helper to sync fonts from an AP stream to a target resource dictionary (e.g., AcroForm /DR).
        Will sync to page resources as well when page is added to the arguments.
        r   r   )	
setdefaultr   r   
get_object_add_to_writerr   r   	RESOURCESr   )writerr   r{   target_resource_dictpagetarget_fontsfont_resource_referencepage_fonts_resources           r-   &_sync_appearance_stream_font_resourcesz;TextStreamAppearance._sync_appearance_stream_font_resources\  s     ,66z'7JL\L^_jjlL(&*&9&99%'# '39&=#"&'7n>V>V9W"X"c"c7#%5%7#jl    33=D+-ACZ>#Jy$9: '&r,   c	                	   t        t        |t        j                           }	|j	                  d      dv r4t        ddt        |	d   |	d   z
        t        |	d   |	d   z
        f      }
n3t        ddt        |	d   |	d   z
        t        |	d   |	d   z
        f      }
|j	                  t        j                  |j                  t        j                  d            }|st        d      }n|j                         } |j                  t        j                  d      } |j                  t        j                  d	      d
k(  rv|t        j                  j                  z  dk(  rVdj                  |j	                  t        j                   g             } |j                  dg       }t#        |t$              s|g}n |j                  dd      }g }t'        j(                  d|      D cg c]  }|s|	 }}|j+                  |j-                  d      dz
        }t/        |j+                  |j-                  d      dz
              }|j1                  d       dj                  |      }|r|}n|}|dkD  r|}| j3                  ||||      \  }}||k7  r't        |j5                  ||            |t7        d      <   | j9                  ||||j;                  t7        d      t=                     |r|nd      }d}d}|t        j                  j>                  z  rd}|j                  d      }d}|t        j                  j@                  z  rd} |j                  dtB        jD                        }d}tF        jH                  }d|v rFt        t<        |d         j                  d|      }t        t<        |d         j                  d|      }d} |j                  dd      }t#        |t<              rtK        |j                  dd            }tM        |
|||      } | ||||||||||||      } t        jN                  |v rt        t<        |t        jN                           j                  di       jQ                         D ]g  \  }!}"|!dv r|!d k(  rSd!|"vr$t=               |"j                         t7        d!      <   tS        |d"|      |"d!   j                         t7        |      <   c|"| |!<   i | S c c}w )#aE  
        Creates a TextStreamAppearance object from a text field annotation.

        This class method is a factory for creating a `TextStreamAppearance`
        instance by extracting all necessary information (bounding box, font,
        text content, etc.) from the PDF field and annotation dictionaries.
        It respects inheritance for properties like default appearance (`/DA`).

        Args:
            writer: The PdfWriter instance that we are creating text stream appearances for.
            page: The page that we are processing annotations for.
            flatten: Whether we flatten text annotations or not. If true, add new font resource
                to the page font resources. Otherwise, add them to the AcroForm resources.
            acro_form: The root AcroForm dictionary from the PDF catalog.
            field: The field dictionary object.
            annotation: The widget annotation dictionary object associated with the field.
            user_font_name: An optional user-provided font name to override the
                default. Defaults to an empty string.
            user_font_size: An optional user-provided font size to override the
                default. A value of -1 indicates no override.

        Returns:
            A new `TextStreamAppearance` instance configured for the given field.

        z/Rotate>     Z   r   r@   r1   r   Nz/Helv 0 Tf 0 gz/Txz/Chr   z/Vr   z\sTfrp   z/DAr   FTz/MaxLenz/Qz/BSz/Wz/Sz/MKz/R)r0   r3   r5   r6   r   z/N>   /FilterrY   rW   r   rX   r   r   r   )*r   r    r   Rectr  absDAr   r"   r  r   FfFTFfBitsComborv   Opt
isinstancelistrer   popr   rj   remover  r   r   r(  r  r   Comb	Multilinerd   re   r   r<   r2   r(   APr  r   )#clsr"  r$  flattenr  r   r  user_font_nameuser_font_size
_rectangler0   r   field_flagsr   r   propfont_propertiesda_font_namer|   r   r   r{   r&  r   r   r   r   r3   r5   r6   appearance_characteristicsr\   new_appearance_streamkeyvalues#                                      r-   from_text_annotationz)TextStreamAppearance.from_text_annotation}  s   L /:6T6Y6Y+Z[
i(I5'As:a=:a=3P/QSVWabcWdgqrsgtWtSu(vwI'As:a=:a=3P/QSVWabcWdgqrsgtWtSu(vwI (55*--MM8;;TB
 "!12B!C!3!>!>!@  eii 9 < <a@		366>%G7>>DDDI99Z556O6S6SUWXYD!		$+Ii.&K	599T2&DI -/HHU<N,OXDSW4XX&**?+@+@+F+JK/--o.C.CD.IA.MNO	t$XXo.
&I$IA&I<<Y
T]_cd	4 $,<=O=W=WXdfo=p,qJz%() #&"L"L  E!24D4FGD#
 
299>>>G#	2J299CCCLEIIdM$6$67	#))E> 0%,?CCD,WL 0%,?CCD,WL%8U%8%8%E"02BC599$BCH "%%	
 !$#!%!!
 *,,
:%z2P2S2S'TUYYZ^`bciik7
U NN,&e+BRBT((*:g+>?IP/1EG^JE'N--/
90EF 27)#.7 %$s Ys    S(S)g?)r{   r   r|   rj   r}   rj   r~   rj   r   rj   r   zlist[list[WidthWordGlyphs]]r   rj   r   rj   r^   z#tuple[list[WidthWordGlyphs], float])r   r4   r   list[str] | Noner{   r   r   r4   r|   rj   r   r4   r   boolr   rd   r   rM  r   
int | Noner^   r   )r\   r`   r   r4   r   rL  r{   zFont | Noner   z(DictionaryObject | IndirectObject | Noner   r4   r|   rj   r   r4   r   rM  r   rd   r   rM  r   rN  r^   r_   )
r   r4   r  r   r  r   r   r4   r^   ztuple[str, Font]r   )r"  r#   r   r4   r{   r   r#  r   r$  zPageObject | Noner^   r   )r   )r"  r#   r$  r$   r?  rM  r  r   r   r   r  r   r@  r4   rA  rj   r^   rn   )r7   r8   r9   r:   rz   rd   re   r   r[   staticmethodr  r(  classmethodrK  ra   rb   s   @r-   rn   rn   u   s   " !$W2W2 W2 	W2
 W2 W2 0W2 W2 W2 
-W2| !"#0#5#5!%gg $g 	g
 g g g g !g g g 
gV +/&* BF "#0#5#5!%C'C C $	C
 C @C C C C C !C C C 
CJ TT(T (T 	T
 T Tl  #'''' ' /	'
  ' 
' '@  ! "f%f% f% 	f%
 $f%  f% %f% f% f% 
f% f%r,   rn   )?
__future__r   r  r8  dataclassesr   r   enumr   ior   operatorr   typingr	   r
   r   r   _codecsr   _codecs.core_font_metricsr   _fontr   _pager   _utilsr   r   	constantsr   r   r   r   errorsr   genericr   r   r   r   r   r   r   r    generic._baser!   r"   pypdf._writerr#   r$   r   bidi.algorithmr%   r   r
  r   rs   r(   r>   rd   ri   rn   r+   r,   r-   <module>rc     s    "  	 (    7 7 7 9  " 0 o o !	 	 	 ?'"*O "$  $(     ('. ('VG j o
%/ o
%]  Os   C C('C(