Ë
    F<kù¯  ã                  óî  — d dl m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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)m*Z*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0m1Z1 ddl2m3Z3 erd dl4m5Z5 ddlm6Z6 	 d dl7Z7d dl8m9Z9 dZ:dZ<dZ=e G d„ d«      «       Z> G d„ de$«      Z? G d„ d e«      Z@ G d!„ d"e«      ZA G d#„ d$e?«      ZBd&d%„ZCy# e;$ r dZ:Y ŒMw xY w)'é    )ÚannotationsN)Ú	dataclassÚfield)ÚIntEnum)ÚBytesIO)Ú
attrgetter)ÚTYPE_CHECKINGÚAnyÚ
NamedTupleÚcasté   )Ú!encoding_dict_from_named_encoding)ÚCORE_FONT_METRICS)ÚTransformation)Úis_char_rtlÚlogger_warning)ÚAnnotationDictionaryAttributesÚBorderStylesÚFieldDictionaryAttributesÚPageAttributes)ÚPdfReadError)
ÚArrayObjectÚContentStreamÚDecodedStreamObjectÚDictionaryObjectÚFloatObjectÚIndirectObjectÚ
NameObjectÚNumberObjectÚRectangleObjectÚStreamObject)ÚByteStringObjectÚTextStringObjecté   )ÚColorÚ
DeviceGray)ÚFont)Ú	PdfWriter)Ú
PageObject)Úget_displayTFé   iè  c                  óŠ   — 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<   d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    © ó    úc/var/www/tapir-food/flask_app/venv/lib/python3.12/site-packages/pypdf/generic/_appearance_stream.pyú<lambda>zBaseStreamConfig.<lambda>6   s   € ¼ÐOcÓ?d€ r1   )Údefault_factoryr    Ú	rectangler$   ÚintÚborder_widthÚstrÚborder_styleNúColor | NoneÚborder_colorÚbackground_colorr   Úrotation)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r5   Ú__annotations__r7   r   ÚSOLIDr9   r;   r<   r=   r0   r1   r2   r-   r-   3   sN   … áLÙ!&Ñ7dÔ!e€IˆÓeØ€L�#ÓØ$×*Ñ*€L�#Ó*Ø!%€L�,Ó%Ø%)Ð�lÓ)Ø€HˆcÔr1   r-   c                  ó4   ‡ — e Zd ZdZd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   r$   é   ú/Matrix)r   ÚrotateÚ_layoutr5   ÚwidthÚheightÚapply_onÚminÚ	translater   Úctmr   Úroundr   )Úselfr=   Ú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               r2   Ú_add_matrixz BaseStreamAppearance._add_matrixA   sK  € ô
  Ó!×(Ñ(¨Ó2ˆØ#Ÿ|™|×5Ñ5×;Ñ;¸SÐAÐØ §¡× 6Ñ 6× =Ñ =Ð>ˆØ ŸL™L×2Ñ2×8Ñ8¸$¿,¹,×:PÑ:P×:WÑ:WÐXÐØ&,§o¡oÐ6IÓ&JÐ#Ø"(§/¡/°/Ó"BÐØ#)§?¡?Ð3CÓ#DÐ Ü #ØÐ,¨QÑ/Ð1HÈÑ1KÐMeÐfgÑMhó!
ð  
Ðô !$ØÐ,¨QÑ/Ð1HÈÑ1KÐMeÐfgÑMhó!
ð  
Ðð ×!Ñ!Ð"6Ð8LÓMˆÜ&1ÐU[×U_ÑU_Ö2`ÐPQ´;¼uÀQÈ»{Õ3KÒ2`Ó&aˆŒZ˜	Ó"Ò#ùÒ2`s   Ä&Ec                óL   — | j                   j                  | j                   «      S )aƒ  Instantiate a blank object for ``clone()`` without running ``__init__``.

        ``BaseStreamAppearance`` inherits this method from ``DictionaryObject``.
        ``DictionaryObject._new_for_clone`` checks whether a subclass requires
        constructor arguments and skips ``__init__`` for those that do.
        ``TextStreamAppearance.__init__`` can be called without constructor
        arguments, but running it during ``clone()`` would populate default
        dictionary entries and a default content stream that pollute the clone.
        This override calls ``__new__`` directly so cloning starts from an empty
        object.
        )Ú	__class__Ú__new__)rR   s    r2   Ú_new_for_clonez#BaseStreamAppearance._new_for_cloneV   s   € ð �~‰~×%Ñ% d§n¡nÓ5Ð5r1   c                óÖ  •— t         ‰| �  «        |xs
 t        «       | _        t	        d«      | t	        d«      <   t	        d«      | t	        d«      <   | j                  j
                  | t	        d«      <   | j                  j                  dz  }|r| j                  |«       g }t        | j                  j                  t        «      ry|j                  d| j                  j
                  j                  › d| j                  j
                  j                  › d	| j                  j                  j                  «       › d
�«       | j                  j                  dkD  �rIt        | j                  j                   t        «      �r| j                  j                  dk7  r| j                  j                  › d�nd}|j                  | j                  j                  › d| j                  j                  › d| j                  j
                  j                  d| j                  j                  z  z
  › d| j                  j
                  j                  d| j                  j                  z  z
  › d	|› | j                  j                   j                  d¬«      › d�«       nd| j                  _        |r#|j#                  dd«       |j                  d«       dj%                  |«      j'                  «       | _        y)z„
        Takes the appearance stream layout as an argument.

        Args:
            layout: The basic layout parameters.
        z/XObjectú/Typez/Formú/Subtypeú/BBoxih  z0 0 ú z re
z
f
r   r$   z w
Ú r   T)Ústrokez
s
zq
zQ
N)ÚsuperÚ__init__r-   rJ   r   r5   r=   r]   Ú
isinstancer<   r%   ÚappendrK   rL   Úas_operatorr7   r;   ÚinsertÚjoinÚencodeÚ_ap_stream_data)rR   Úlayoutr=   Úap_stream_partsÚborder_width_stringr_   s        €r2   rj   zBaseStreamAppearance.__init__d   s^  ø€ ô 	‰ÑÔØÒ3Ô!1Ó!3ˆŒÜ$.¨zÓ$:ˆŒZ˜Ó Ñ!Ü'1°'Ó':ˆŒZ˜
Ó#Ñ$Ø$(§L¡L×$:Ñ$:ˆŒZ˜Ó Ñ!ð —<‘<×(Ñ(¨3Ñ.ˆÙØ×Ñ˜XÔ&àˆä�d—l‘l×3Ñ3´UÔ;Ø×"Ñ"Ø�t—|‘|×-Ñ-×3Ñ3Ð4°A°d·l±l×6LÑ6L×6SÑ6SÐ5TÐTYØ—<‘<×0Ñ0×<Ñ<Ó>Ð?ð @ðôð �<‰<×$Ñ$ qÓ(Ü˜$Ÿ,™,×3Ñ3´UÕ;ØLPÏLÉL×LeÑLeÐijÒLj¨¯©×)BÑ)BÐ(CÀ4Ñ&HÐprÐ#Ø×&Ñ&Ø—|‘|×0Ñ0Ð1°Ø—|‘|×0Ñ0Ð1°Ø—|‘|×-Ñ-×3Ñ3°a¸$¿,¹,×:SÑ:SÑ6SÑSÐTÐTUØ—|‘|×-Ñ-×4Ñ4°q¸4¿<¹<×;TÑ;TÑ7TÑTÐUÐUZØ*Ð+Ø—|‘|×0Ñ0×<Ñ<ÀDÐ<ÓIÐJð Kðõð -.�—‘Ô)ÙØ×"Ñ" 1 eÔ,Ø×"Ñ" 5Ô)Ø!Ÿw™w Ó7×>Ñ>Ó@ˆÕr1   )r=   r6   ÚreturnÚNone)ru   rE   )rr   úBaseStreamConfig | Noneru   rv   )r>   r?   r@   rA   r]   ra   rj   Ú__classcell__©r_   s   @r2   rE   rE   >   s   ø„ Ùhóbó*6÷/Añ /Ar1   rE   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   r$   r   N)r>   r?   r@   rA   ÚLEFTÚCENTERÚRIGHTr0   r1   r2   r{   r{   –   s   „ ÙYà€DØ€FØ�Er1   r{   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.ÚfloatrK   r8   ÚwordÚglyphsN)r>   r?   r@   rA   rB   r0   r1   r2   r€   r€   ž   s   … ÙqàƒLØ
ƒIØ„Kr1   r€   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„«       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   rf   r‚   rƒ   ©rK   r‚   rƒ   r$   )Úspace_widthÚ TEXT_SPACE_TO_GLYPH_SPACE_FACTORÚ	enumeraterK   rl   r€   ro   Úmapr   Ú
space_charr‚   rƒ   ÚlenÚ_scale_textrQ   )rR   ÚfontÚ	font_sizeÚleading_factorÚfield_widthÚfield_heightÚ
paragraphsÚmin_font_sizeÚfont_size_stepÚwrapped_linesÚcurrent_line_wordsÚcurrent_line_widthrˆ   Ú	paragraphr\   Úwidth_word_glyphsÚ
word_widthÚ
test_widthÚestimated_total_heightÚnew_font_sizes                       r2   rŽ   z TextStreamAppearance._scale_text¯   s0  € ð< ˆØ46ÐØ$%ÐØ×&Ñ&¨Ñ2Ô5UÑUˆØ#ó $	'ˆIÜ(1°)Ó(<ò 5Ñ$�Ð$Ø.×4Ñ4°yÑ@�
Ø/°*Ñ<ÉqÁÐVWÑX�
Ø Ò+Ñ0BØ!×(Ñ(Ü'Ø"4Ø!$§¡¬#¬j¸Ó.@ÐBTÓ*UÓ!VØ#'§?¡?×#7Ñ#7¼¼JÀxÓ<PÐRdÓ8eÓ#fôôð +<Ð)<Ð&Ø)3Ñ&Ù+°
¸[Ò0HØ!×(Ñ(Ü'Ø",Ø!2×!7Ñ!7Ø#4×#;Ñ#;ôôð *,Ð&Ø)*Ñ&á)Ø*¨kÑ9Ð*Ø&×-Ñ-Ð.?Ô@Ø&¨*Ñ4Ñ&ð75ó8 "Ø×$Ñ$¤_Ø,ØŸ™¤#¤j°Ó&8Ð:LÓ"MÓNØŸ?™?×/Ñ/´´J¸xÓ4HÐJ\Ó0]Ó^ô&ô ð
 &(Ð"Ø%&Ò"ðI$	'ðL "+¬c°-Ó.@À1Ñ.DÈÑ-VÐYbÑ-bÑ!bÐØ! LÒ0à%¨Ñ6ˆMØ Ò-Ø×'Ñ'ØØ!Ø"ØØ ØØ!Ø"ó	ð 	ð œe I¨qÓ1Ð1Ð1r1   ú/Helvr/   NFc                ó¾  — |xs
 t        «       }| j                  j                  }|j                  j                  d   |j                  j                  d   z
  t
        z  }| j                  j                  dv rdnd}| j                  j                  |z  }|j                  d|z  z
  }|j                  dt        |d«      z  z
  }|j                  «       \  }}d*d„}d+d„}|dk(  �r9d	}|rd
}|rÏt        }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t0        ||
¬«       g }t3        |«      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 |r*||z   |j                  j                  d   |z  t
        z  z
  }#n)|||j                  j4                  |z  t
        z  z
  dz  z   }#t7        |«      j9                  «       j;                  «       }$|$› d|› d|j=                  «       › �}%t?        «       }&|&ddt        |d«      z  › d|› dt)        |dt        |d«      z  z
  d«      › dt)        ||z
  d«      › d|%› d�jA                  «       z  }&d}'|r |djC                  |«      |«      nd}(t3        |«      D �].  \  })\  }*}+}|(rJ||(v rF|&dt)        |#|)|z  |z  z
  dz
  d«      › d|j                  dz
  › d|dz   › d|%› d�	jA                  «       z  }&d},|	r"|
r |j                  |
z  }-|-|*z
  dz  }.|)|-z  |.z   },nh|tD        jF                  k(  r |j                  t        |d«      dz  z
  |*z
  },n5|tD        jH                  k(  r|j                  |*z
  dz  },nt        |d«      dz  },|,|'z
  }/d}0|)dk(  r|#}0n|	rd}0n| |z  }0|&t)        |/d«      › dt)        |0d«      › d�jA                  «       z  }&|,}'tK        d„ |D «       «      }1 |||«      }2|1rId|+jA                  d«      z   }3|3jM                  «       jO                  «       }4|&d|4› d�jA                  «       z  }&|jP                  dk(  r7|&ddjC                  |2«      jM                  «       jA                  «       z   d z   z  }&nLdjC                  |2«      jS                  d!d"«      jS                  d#d$«      jS                  d%d&«      }5|&d#|5z   d'z   z  }&|1s�Œ*|&d(z  }&�Œ1 |&d)z  }&tU        |&«      S ),aI  
        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 class Color
            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.

        rG   r$   >   ú/Bú/Ir   é   c                ó¼   ‡— t         r<t        j                  | «      }t        |d¬«      }dj	                  ˆfd„|D «       «      S dj	                  ˆfd„| D «       «      S )NÚL)Úbase_dirrg   c              3  óB   •K  — | ]  }‰j                  ||«      –— Œ y ­w©N©Úget©Ú.0ÚcharÚreverse_cmaps     €r2   ú	<genexpr>zfTextStreamAppearance._generate_appearance_stream_data.<locals>._unicode_to_glyph_id.<locals>.<genexpr>B  s   øè ø€ ÒTÀ˜|×/Ñ/°°d×;ÑTùó   ƒc              3  óB   •K  — | ]  }‰j                  ||«      –— Œ y ­wr©   rª   r¬   s     €r2   r°   zfTextStreamAppearance._generate_appearance_stream_data.<locals>._unicode_to_glyph_id.<locals>.<genexpr>D  s   øè ø€ ÒI¸D˜<×+Ñ+¨D°$×7ÑIùr±   )ÚHAS_RTL_SUPPORTÚarabic_reshaperÚreshaper*   ro   )Útextr¯   Úreshaped_textÚvisual_texts    `  r2   Ú_unicode_to_glyph_idzSTextStreamAppearance._generate_appearance_stream_data.<locals>._unicode_to_glyph_id=  sL   ø€ Ýä /× 7Ñ 7¸Ó =�Ü)¨-À#ÔF�Ø—w‘wÓTÈÔTÓTÐTà—7‘7ÓIÀDÔIÓIÐIr1   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)rƒ   Úencoding_cmapÚglyph_ids      r2   Ú_glyph_id_to_byteszQTextStreamAppearance._generate_appearance_stream_data.<locals>._glyph_id_to_bytesG  sM   € ð %ö&àð "×%Ñ%Ø´S¸³]ÀSÒ5Hœ%¤ X£Ð 0Ô1Èdõò &ð &ùò &s   …<Ar   g      @Fr/   rg   r‡   rf   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     r2   r°   zHTextStreamAppearance._generate_appearance_stream_data.<locals>.<genexpr>à  s   è ø€ Ò<¨tœ T×*Ñ<ùó   ‚s   þÿz	utf-16-bez/Span << /ActualText <z	> >> BDC
ÚType0ó   <r1   s   > Tj
ó   \s   \\ó   (s   \(ó   )s   \)s   ) Tj
s   EMC
s   ET
Q
EMC
Q
)r¶   r8   r¯   zdict[str, str]ru   r8   )rƒ   r8   r¿   zdict[str, bytes]ru   zlist[bytes])+r&   rJ   r5   Úfont_descriptorÚbboxr‰   r9   r7   rL   rK   ÚmaxÚ_get_typographic_mapsÚDEFAULT_FONT_SIZE_IN_MULTILINEÚ
splitlinesÚstriprl   r€   ÚsplitÚget_text_widthrŽ   rQ   rN   r�   r   r>   rŠ   Úascentr   ÚrenumberÚdecoderm   Ú	bytearrayrp   ro   r{   r~   r}   ÚanyÚhexÚupperÚsub_typeÚreplacer¾   )6rR   r¶   Ú	selectionr�   Ú	font_namer�   Ú
font_colorÚis_multilineÚ	alignmentÚis_combrÃ   r5   r‘   ÚfactorÚmarginr“   r’   r¯   r¿   r¹   rÁ   r•   r”   ÚlineÚline_by_widths_words_glyphsÚwordsr‚   Ú
glyph_wordÚlinesÚmax_vertical_sizerƒ   Útext_width_unscaledÚmax_horizontal_sizeÚindexr®   Úy_offsetÚescaped_font_nameÚdefault_appearanceÚ	ap_streamÚcurrent_x_posÚselection_glyphsÚ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_bytess6                                                         r2   Ú _generate_appearance_stream_dataz5TextStreamAppearance._generate_appearance_stream_data  s3  € ðN  Ò/¤:£<ˆ
Ø—L‘L×*Ñ*ˆ	à×!Ñ!×&Ñ& qÑ)¨D×,@Ñ,@×,EÑ,EÀaÑ,HÑHÔLlÑlð 	ð
 —l‘l×/Ñ/°<Ñ?‘ÀQˆØ—‘×*Ñ*¨VÑ3ˆØ ×'Ñ'¨!¨f©*Ñ4ˆØ—o‘o¨¬C°¸«NÑ(:Ñ:ˆà&*×&@Ñ&@Ó&BÑ#ˆ�mó	Jó	&ð ˜‹>ØˆMÙØ$�ÙÜ:�	ð ;=�
Ø ŸO™OÓ-ò C�DØŸ:™:œ<Ø"×)Ñ)¬?ÀÈ2ÐVXÔ+YÐ*ZÔ[Ø ØIKÐ/Ø ŸJ™J s›O�EØ %ò ˜Ù%9¸$ÀÓ%M˜
Ø3×:Ñ:Ü+Ø&*×&9Ñ&9¸$Ó&?ÔBbÑ&bØ%)Ø'1ôõðð ×%Ñ%Ð&AÕBðCð  $(×#3Ñ#3ØØØ"ØØ ØØ!ó$Ñ �’yð %1°>Ñ$AÐ!Ù-¨d°LÓA�Ø&*×&9Ñ&9¸&Ó&AÔDdÑ&dÐ#Ø&1Ð5HÒ5MÈAÑ&NÐ#Ü!¤#¤cÐ*;Ð=PÓ&QÐS`Ó"aÐcdÓe�	Ü(Ð/BÀYÑ/NÐUYÐbhÔiÐj‘ÙÙœc $›i¨*Ò4Üð5ô $ØØ)õð ˆEÜ(¨›ò 	‘��tØ˜JÒ3¬#¨d«)Ó4Ù1°$¸ÓE�FØ—L‘LÜ'Ø"&×"5Ñ"5°fÓ"=À	Ñ"IÔLlÑ"lØ!%Ø#)ôõñ	ð ˆEØŸ™Ó)ò �Ù-¨d°LÓA�Ø—‘Ü#Ø"×1Ñ1°&Ó9¸IÑEÔHhÑhØ!Ø%ôõðñ à˜vÑ%¨×(<Ñ(<×(AÑ(AÀ!Ñ(DÀyÑ(PÔSsÑ(sÑsñ ð Ø × 4Ñ 4× ;Ñ ;¸iÑ GÔJjÑ jÑjÐnoÑoñˆHô ' yÓ1×:Ñ:Ó<×CÑCÓEÐØ 1Ð2°!°I°;¸dÀ:×CYÑCYÓC[ÐB\Ð]Ðä“Kˆ	ØØØ”3�v˜q“>Ñ!Ð" ! F 8¨1Ü�[ 1¤s¨6°1£~Ñ#5Ñ5°qÓ9Ð:¸!¼EÀ,ÐQWÑBWÐYZÓ<[Ð;\ð ]Ø(Ð)¨ð-÷ ‰&‹(ñ	ˆ	ð  !ˆáU^Ñ/°·±¸	Ó0BÀLÔQÐdfÐÜ>GÈÓ>Nó B	&Ñ:ˆKÑ:˜* m°TÙ DÐ,<Ñ$<àØœ˜x¨;¸Ñ+BÀ^Ñ+SÑTÐWXÑXÐZ[Ó\Ð]Ð]^Ø —‘¨Ñ*Ð+¨1¨Y¸©]¨Oð <)Ø);Ð(<¸Bð@÷ ‘&“(ñ	�	ð *+ÐÙ™:à&Ÿ_™_¨zÑ9�
ð -7¸Ñ,CÀqÑ+HÐ(à'2°ZÑ'?ÐC[Ñ&[Ñ#Øœm×1Ñ1Ò1Ø&/§o¡o¼¸FÀA»ÈÑ8JÑ&JÈZÑ&WÑ#Øœm×2Ñ2Ò2Ø'0§¡¸Ñ'CÀqÑ&HÑ#ä&)¨&°!£n°qÑ&8Ð#ð /°Ñ>ˆLð #$ˆLØ˜aÒØ'‘ÙØ"‘à!*˜{¨^Ñ;�ð œE ,°Ó2Ð3°1´U¸<ÈÓ5KÐ4LÈEÐR×YÑYÓ[Ñ[ˆIð 0ˆMäÑ<°tÔ<Ó<ˆFá-¨d°MÓBˆLÙð '¨×)=Ñ)=¸kÓ)JÑJ�Ø$,§L¡L£N×$8Ñ$8Ó$:Ð!ØÐ5Ð6GÐ5HÈ
ÐS×ZÑZÓ\Ñ\�	Ø�}‰} Ò'Ø˜T S§X¡X¨lÓ%;×$@Ñ$@Ó$B×$IÑ$IÓ$KÑKÈiÑWÑW‘	ð —H‘H˜\Ó*ß‘W˜U GÓ,ß‘W˜T 6Ó*ß‘W˜T 6Ó*ð	 ð ˜T MÑ1°IÑ=Ñ=�	ÛØ˜XÑ%’	ðEB	&ðF 	Ð'Ñ'ˆ	ä�YÓÐr1   rg   c                ó
  •— t         ‰| �  |«       |r|s&d}t        j                  «       }|j	                  «       }| xj
                  | j                  ||||||xs
 t        «       |	|
||¬«
      z  c_        | j                  t        | j
                  «      «       t        t        | j
                  «      «      | t        d«      <   t        t        d«      t        t        |«      t        |d|«      i«      i«      | t        d«      <   y)a1  
        Initializes a TextStreamAppearance object.

        This constructor creates a new PDF stream object configured as an XObject
        of subtype Form. It uses the `_generate_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)ri   rj   r'   Úfrom_core_font_nameÚas_font_resourcerq   r  r&   Úset_datar"   r   r�   r   r   Úgetattr)rR   rr   r¶   rÞ   r�   Úfont_resourcerß   r�   rà   rá   râ   rã   rÃ   r_   s                €r2   rj   zTextStreamAppearance.__init__ú  sþ   ø€ ôP 	‰Ñ˜Ô á™=ØˆIÜ×+Ñ+Ó-ˆDØ ×1Ñ1Ó3ˆMà×Ò × EÑ EØØØØØØ!Ò1¤Z£\Ø%ØØØ!ð !Fó !
ñ 	
Õð 	�‰Ô& t×';Ñ';Ó<Ô=Ü&2´3°t×7KÑ7KÓ3LÓ&MˆŒZ˜	Ó"Ñ#ä)9Ü�wÓÔ!1Ü˜9Ó%¤w¨}Ð>RÐTaÓ'bð3ó "ð;
ó *ˆŒZ˜Ó%Ò&r1   c                óP  — t        t        |j                  d|j                  dt        «       «      «      «      }|j                  dt        «       «      }|j                  | d «      }|r$t	        j
                  |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 rët        |j*                     }
h d£}|D ]Ï  }t-        j,                  |«      }t/        |«      |_        |j                  |«      }|sŒ<|}|j2                  j5                  «        |j0                  j7                  «       D ]9  \  }}||
j2                  v sŒ|
j2                  |   |j2                  t9        |«      <   Œ; |
j2                  d   |j2                  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/PYPDF1z7Unable to use embedded font for encoding: %(exception)s)rÂ   Ú	exceptionÚType1>   Úcp1250Úcp1252Úcp1254Úcp1257Ú
iso8859_15Údefaultz¿Text 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Ú
get_objectÚremoveprefixr   r   r>   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                   r2   Ú_find_annotation_font_resourcez3TextStreamAppearance._find_annotation_font_resource?  s„  € ô $(ÜØ×$Ñ$ØØ—‘˜eÔ%5Ó%7Ó8óó$
Ðð $7×#:Ñ#:¸7ÔDTÓDVÓ#WÐ Ø0×4Ñ4°YÀÓEˆÙÜ×*Ñ*¨=×+CÑ+CÓ+EÓF‰Dð
 ×%Ñ% cÓ*Ô2CÑCäØ[Ü#Ø'õð
 )�	Ü×+Ñ+¨IÓ6ˆDð —O‘O DÓ)ˆ	âð ×#Ñ#×-Ò-°$·-±-À:Ò2Mð	Ø×7Ñ7¼À×@TÑ@T×@^Ñ@^×@gÑ@gÓ@iÓ8jÓk�DØ )�IØ $§¡°Ó 5’Ið —‘ 'Ò)¨d¯i©iÔ;LÑ.LÜ$5°d·i±iÑ$@Ð!ò"�ð !/ò �HÜ $§	¡	¨$£�IÜ)JÈ8Ó)T�IÔ&Ø )× 4Ñ 4°TÓ :�IÚ Ø(˜Ø×-Ñ-×3Ñ3Ô5Ø/8×/AÑ/A×/GÑ/GÓ/Iò q™O˜D )à(Ð,=×,NÑ,NÒNØCT×CeÑCeÐfoÑCp × 5Ñ 5´c¸$³iÒ @ðqð <M×;]Ñ;]Ð^gÑ;h˜×-Ñ-¨iÑ8Ø$-°Ñ$8˜	Ùðñ Üðkô $Øõð ˜$ˆÐøôW $¤\Ð2ò Ü"ØQÜ'Ø"+÷ò ûðús   ÄA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   r  Ú_add_to_writerr   r   Ú	RESOURCESr  )Úwriterrß   r�   Útarget_resource_dictÚpageÚtarget_fontsÚfont_resource_referenceÚpage_fonts_resources           r2   Ú&_sync_appearance_stream_font_resourcesz;TextStreamAppearance._sync_appearance_stream_font_resourcesš  sË   € ð ,×6Ñ6´zÀ'Ó7JÔL\ÓL^Ó_×jÑjÓlˆØ˜LÑ(Ø&*×&9Ñ&9ØØÜ˜9Ó%ó'Ñ#ð '3°9Ñ&=Ð#áÜ"&Ô'7¸¼n×>VÑ>VÑ9WÓ"X×"cÑ"cÜ˜7Ó#Ô%5Ó%7ó#ç‰j‹lð  ð Ð 3Ñ3Ü=DØ+Ð-AÐCZó>Ð#¤J¨yÓ$9Ñ:ð 'Ð&r1   c                óÄ  — t        dd«      }|j                  | j                  «       	 |j                  }d}d}d}|D ]Ž  \  }}|dk(  rZt        |«      dk(  sŒt        |d   t        «      sŒ.t        |d   t        t        f«      sŒHt        |d   «      t        |d   «      }}Œet        j                  ||j                  d«      «      x}€Œ�|}Œ� |||fS # t        $ r Y yw xY w)	aÿ  
        Read the font name, font size and font color from a default appearance string.

        A default appearance is a content stream fragment of graphics and text state operators, such as
        `/a1.0 gs 0 0 0 rg /Helv 10 Tf` (Section 12.7.4.3 "Variable text" of the PDF 2.0 specification).
        Where an operator occurs more than once, the last one is in effect. Operators other than `Tf` and
        the non-stroking color operators are ignored.

        Args:
            default_appearance: The /DA string of a variable text field.

        Returns:
            The font name and font size of the last complete Tf operator, or None and 0 if there is none,
            and the color of the last complete color operator, or None if there is none.
        N)Nr/   Nr/   s   Tfr   r   r$   zlatin-1)r   r  Úoriginal_bytesÚ
operationsr   r�   rk   r   r6   r�   r8   r%   Úfrom_normalized_valuesr×   )	rñ   ÚstreamrB  rß   r�   rà   ÚoperandsÚoperatorÚcolors	            r2   Ú_parse_default_appearancez.TextStreamAppearance._parse_default_appearance»  sö   € ô& ˜t TÓ*ˆØ�‰Ð*×9Ñ9Ô:ð	#Ø×*Ñ*ˆJð
 !%ˆ	Øˆ	Ø#'ˆ
Ø",ò 	#ÑˆH�hØ˜5Ò Ü�x“= AÓ%¬*°X¸a±[Ä*Õ*MÔR\Ð]eÐfgÑ]hÔknÔpuÐjvÕRwÜ+.¨x¸©{Ó+;¼UÀ8ÈAÁ;Ó=O˜y‘IÜ ×7Ñ7¸À(Ç/Á/ÐR[ÓB\Ó]Ð]�%ÑjØ"‘
ð	#ð ˜) ZÐ/Ð/øô ò 	#á"ð	#ús   ©C Ã	CÃC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 }| j'                  |«      \  }}}|€ t)        dt*        t-        |«      ¬«       d\  }}|r|}n|}|dkD  r|}| j/                  ||||«      \  }}||k7  r't        |j1                  ||«      «      |t3        d«      <   | j5                  ||||j7                  t3        d«      t9        «       «      |r|nd«      }d}d}|t        j                  j:                  z  rd}|j                  d«      }d}|t        j                  j<                  z  rd} |j                  dt>        j@                  «      }d}tB        jD                  }d|v rFt        t8        |d   «      j                  d|«      }t        t8        |d   «      j                  d|«      }d}d}d} |j                  dd«      }t#        |t8        «      rctG        |j                  dd«      «      }tI        jJ                  |j                  d«      «      }tI        jJ                  |j                  d«      «      }tM        |
|||||¬«      } | ||||||||||||¬«      } t        jN                  |v r©t        t8        |t        jN                     «      j                  d i «      jQ                  «       D ]g  \  }!}"|!d!v rŒ|!d"k(  rSd#|"vr$t9        «       |"j                  «       t3        d#«      <   tS        |d$|«      |"d#   j                  «       t3        |«      <   Œc|"| |!<   Œi | S )%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   rG   r$   r   Nz/Helv 0 Tf 0 gz/Txz/ChrÄ   z/Vrg   zsCould not read a complete Tf operator from the default appearance %(default_appearance)r; defaulting to /Helv 0 Tf.)rÂ   rñ   )r    r/   z/DAr  FTz/MaxLenz/Qz/BSz/Wz/Sz/MKz/Rz/BCz/BG)r5   r7   r9   r;   r<   r=   r  ú/N>   ú/Filterre   rc   r  rd   r  r  r  )*r   r    r   ÚRectr  ÚabsÚDAr«   r#   r  r   ÚFfÚFTÚFfBitsÚComboro   ÚOptrk   ÚlistrH  r   r>   r8   r4  rÝ   r   r?  r6  r   ÚCombÚ	Multiliner{   r|   r   rC   r6   r%   rC  r-   ÚAPr(  r  )#Úclsr9  r;  Úflattenr+  r   r*  Úuser_font_nameÚuser_font_sizeÚ
_rectangler5   rñ   Úfield_flagsr¶   rÞ   Úda_font_namer�   rà   rß   r�   r=  rã   rÃ   rá   râ   r7   r9   r=   r;   r<   Úappearance_characteristicsrr   Únew_appearance_streamÚkeyÚvalues#                                      r2   Úfrom_text_annotationz)TextStreamAppearance.from_text_annotationá  së  € ôL œ/¨:Ô6T×6YÑ6YÑ+ZÓ[ˆ
à×Ñ˜iÓ(¨IÑ5Ü'¨¨A¬s°:¸a±=À:ÈaÁ=Ñ3PÓ/QÔSVÐWaÐbcÑWdÐgqÐrsÑgtÑWtÓSuÐ(vÓw‰Iä'¨¨A¬s°:¸a±=À:ÈaÁ=Ñ3PÓ/QÔSVÐWaÐbcÑWdÐgqÐrsÑgtÑWtÓSuÐ(vÓwˆIð (×5Ñ5Ü*×-Ñ-Ø�M‰MÔ8×;Ñ;¸TÓBó
Ðñ "ä!1Ð2BÓ!CÑà!3×!>Ñ!>Ó!@Ðð  �e—i‘iÔ 9× <Ñ <¸aÓ@ˆà�—	‘	Ô3×6Ñ6¸Ó>À%ÒGØÔ7×>Ñ>×DÑDÑDÈÒIà—9‘9˜Z×5Ñ5Ô6O×6SÑ6SÐUWÓXÓYˆDØ!˜Ÿ	™	 $¨Ó+ˆIÜ˜i¬Ô.Ø&˜K‘	à�5—9‘9˜T 2Ó&ˆDØˆIð /2×.KÑ.KÐL^Ó._Ñ+ˆ�i ØÐÜð0ô  Ü#&Ð'9Ó#:õð '3Ñ#ˆL˜)áØ&‰Ià$ˆIà˜AÒØ&ˆIà×<Ñ<¸YÈ
ÐT]Ð_cÓd‰ˆ	�4ð ˜Ò$Ü,<Ð=O×=WÑ=WÐXdÐfoÓ=pÓ,qˆJ”z %Ó(Ñ)ð #&×"LÑ"LØØØØ× Ñ ¤¨EÓ!2Ô4DÓ4FÓGÙ‰D ó#
Ðð ˆØˆ
ØÔ2×9Ñ9×>Ñ>Ò>ØˆGØ#Ÿ™¨	Ó2ˆJØˆØÔ2×9Ñ9×CÑCÒCØˆLØ�E—I‘I˜d¤M×$6Ñ$6Ó7ˆ	ØˆÜ#×)Ñ)ˆØ�E‰>ÜÔ 0°%¸±,Ó?×CÑCÀDÈ,ÓWˆLÜÔ 0°%¸±,Ó?×CÑCÀDÈ,ÓWˆLàˆØ%)ˆØ)-ÐØ%8 U×%8Ñ%8¸ÀÓ%EÐ"ÜÐ0Ô2BÔCÜÐ5×9Ñ9¸$ÀÓBÓCˆHä ×7Ñ7Ð8R×8VÑ8VÐW\Ó8]Ó^ˆLÜ$×;Ñ;Ð<V×<ZÑ<ZÐ[`Ó<aÓbÐô "ØØ%Ø%Ø%Ø-Øô
ˆñ !$ØØØØØ#ØØØ!Ø%ØØØ!ô!
Ðô *×,Ñ,°
Ñ:äÔ% zÔ2P×2SÑ2SÑ'TÓU×YÑYÐZ^Ð`bÓc×iÑiÓkò7‘
��Uð ÐNÑNØà˜,Ò&Ø eÑ+ÜBRÓBT˜×(Ñ(Ó*¬:°gÓ+>Ñ?ÜIPØ/Ð1EÐG^óJ�E˜'‘N×-Ñ-Ó/´
¸9Ó0EÒFð 27Ð)¨#Ò.ð7ð %Ð$r1   )gš™™™™™É?)r�   r'   r�   r�   r‘   r�   r’   r�   r“   r�   r”   zlist[list[WidthWordGlyphs]]r•   r�   r–   r�   ru   z#tuple[list[WidthWordGlyphs], float])r¶   r8   rÞ   úlist[str] | Noner�   r'   rß   r8   r�   r�   rà   r:   rá   Úboolrâ   r{   rã   rg  rÃ   ú
int | Noneru   r¾   )rr   rw   r¶   r8   rÞ   rf  r�   zFont | Noner  z(DictionaryObject | IndirectObject | Nonerß   r8   r�   r�   rà   r:   rá   rg  râ   r{   rã   rg  rÃ   rh  ru   rv   )
rß   r8   r*  r   r+  r   r¶   r8   ru   ztuple[str, Font]r©   )r9  r(   rß   r8   r�   r'   r:  r   r;  zPageObject | Noneru   r   )rñ   z#TextStringObject | ByteStringObjectru   z&tuple[str | None, float, Color | None])rg   éÿÿÿÿ)r9  r(   r;  r)   r[  rg  r+  r   r   r   r*  r   r\  r8   r]  r�   ru   r…   )r>   r?   r@   rA   rŽ   r{   r|   r  rj   Ústaticmethodr4  r?  rH  Úclassmethodre  rx   ry   s   @r2   r…   r…   ¦   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ØØ!%ðp àðp ð $ðp ð ð	p ð
 ðp ð ðp ð !ðp ð ðp ð !ðp ð ðp ð ðp ð 
óp ðh +/ØØ&*Ø ØBFØ ØØ#'Ø"Ø#0×#5Ñ#5ØØ!%ðCà'ðCð ðCð $ð	Cð
 ðCð @ðCð ðCð ðCð !ðCð ðCð !ðCð ðCð ðCð 
õCðJ ðXØðXà(ðXð (ðXð ð	Xð
 òXó ðXðt ð #'ð'Øð'àð'ð ð'ð /ð	'ð
  ð'ð 
ò'ó ð'ð@ ð#0Ø?ð#0à	/ò#0ó ð#0ðJ ð !Ø "ðs%àðs%ð ðs%ð ð	s%ð
 $ðs%ð  ðs%ð %ðs%ð ðs%ð ðs%ð 
òs%ó ôs%r1   r…   c                ó´  — d| vryt        t        | d   «      }d|vry|d   }t        |t        «      r t        |t        «      s|j	                  «       n|g}|D ]~  }|j                  «       }t        |t        «      sŒ$t        |j                  dd«      «      }t        d„ t        |«      j                  |«      j                  D «       «      |t        d«      <   Œ€ y)aW  
    Compose `transformation` into an annotation's /AP /N appearance stream(s), in place.

    Repositioning/resizing an annotation's /Rect alone is not enough: per
    the appearance-stream algorithm (PDF 2.0, 12.5.5), a viewer fits the
    appearance's /BBox (as mapped by its own /Matrix) into /Rect using an
    axis-aligned scale, never a rotation. Left alone, rotating or shearing
    a page therefore stretches/skews the untouched appearance content into
    the new, differently-shaped /Rect instead of rotating it. Composing the
    transform into /Matrix (rather than overwriting it) keeps the rendered
    content consistent with the rest of the transformed page while
    preserving whatever the annotation already had. Handles both a single
    appearance stream and the multi-state /AP /N dict used by
    checkbox/radio-button widgets.
    z/APNrL  rH   )r$   r   r   r$   r   r   c              3  ó2   K  — | ]  }t        |«      –— Œ y ­wr©   )r   )r­   Úxs     r2   r°   z2transform_annotation_appearance.<locals>.<genexpr>¿  s   è ø€ ò 7
Ø ŒK˜�Nñ7
ùrÆ   )r   r   rk   r!   Úvaluesr  Útupler«   r   r   Ú	transformrP   r   )Úannotation_objÚtransformationÚapÚ	normal_apÚ	state_apsÚstate_apÚ	state_objÚ
old_matrixs           r2   Útransform_annotation_appearancerz  ˜  sÞ   € ð  �NÑ"ØÜ	Ô ¨uÑ 5Ó	6€BØ�2�~Øà�4‘€Iô �iÔ!1Ô2¼:ÀiÔQ]Ô;^ð 	×ÑÔàˆ[ð ð
 ò 	
ˆð ×'Ñ'Ó)ˆ	Ü˜)¤\Ô2ØÜ˜9Ÿ=™=¨Ð4FÓGÓHˆ
Ü+6ñ 7
Ü$2°:Ó$>×$HÑ$HÈÓ$X×$\Ñ$\ô7
ó ,
ˆ	”*˜YÓ'Ò(ñ	
r1   )rr  r   rs  r   ru   rv   )DÚ
__future__r   r$  Údataclassesr   r   Úenumr   Úior   rF  r   Útypingr	   r
   r   r   Ú_codecsr   Ú_codecs.core_font_metricsr   Ú_pager   Ú_utilsr   r   Ú	constantsr   r   r   r   Úerrorsr   Úgenericr   r   r   r   r   r   r   r   r    r!   Úgeneric._baser"   r#   Ú_colorr%   r&   Ú_fontr'   Úpypdf._writerr(   r)   r´   Úbidi.algorithmr*   r³   r"  rÐ   r‰   r-   rE   r{   r€   r…   rz  r0   r1   r2   ú<module>rŒ     sä   ðÝ "ã ß (Ý Ý Ý ß 7Ó 7å 7Ý 9Ý "ß 0ß oÓ oÝ !÷÷ ÷ ÷ ?ß %Ý áÝ'å"ðÛÝ*Ø€Oð "$Ð ð $(Ð  ð ÷ð ó ðôUAÐ.ô UAôp�Gô ô�jô ôo%Ð/ô o%ôd)
øð_ ò Ø‚Oðús   ÂC* Ã*C4Ã3C4