
    Z?iV.                        U d dl Z d dl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mZ ddlmZ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mZ e j8                  dd dk\  rd dlmZ nd dlmZ ee e f   Z!ee"d<   de#e!   defdZ$ G d dee      Z% G d de%      Z& G d de%      Z' G d de%      Z( G d de%      Z) G d de%      Z* G d de%      Z+ G d  d!e%      Z, G d" d#e%      Z-y)$    N)ABC)AnyLiteralOptionalUnion   )AnnotationFlag)ArrayObjectDictionaryObject)BooleanObjectFloatObjectIndirectObject
NameObjectNumberObjectTextStringObject)RectangleObject)
hex_to_rgb   )NO_FLAGSAnnotationDictionary)   
   )	TypeAliasVertexverticesreturnc                     | d   d   | d   d   }}| d   d   | d   d   }}| D ]5  \  }}t        ||      }t        ||      }t        ||      }t        ||      }7 t        ||||f      S )Nr   r   )minmaxr   )r   x_miny_minx_maxy_maxxys          [/var/www/html/qr/venv/lib/python3.12/site-packages/pypdf/annotations/_markup_annotations.py_get_bounding_rectangler'      s    A;q>8A;q>5EA;q>8A;q>5E 1E1E1E1E1	
 E5%788    c                   Z    e Zd ZdZddddddee   deeeef      de	d   d	ee   d
df
dZ
y)MarkupAnnotationa  
    Base class for all markup annotations.

    Args:
        title_bar: Text to be displayed in the title bar of the annotation;
            by convention this is the name of the author
        in_reply_to: The annotation that this annotation is "in reply to"
            (PDF 1.5). Can be either an annotation (previously added using
            :meth:`~pypdf.PdfWriter.add_annotation`) or a reference to the
            target annotation.
        reply_type: The relationship between this annotation and the one
            specified by ``in_reply_to``. Either ``"R"`` (a reply, default)
            or ``"Group"`` (grouped with the parent annotation). Raises
            ``ValueError`` if a non-default value is provided without
            ``in_reply_to``.
        annotation_name: A text string uniquely identifying this annotation
            among all annotations on its page. Automatically generated when
            ``in_reply_to`` is set and no name is provided. Raises
            ``ValueError`` if provided without ``in_reply_to``.

    NR)	title_barin_reply_to
reply_typeannotation_namer,   r-   r.   )r+   Groupr/   r   c                   |t        |      | t        d      <   ||t        d      |dk7  r|t        d      |t        |t              r|}n*t        |dd       }t        |t              st        d      |}|| t        d      <   t        d|       | t        d	      <   |t        t        j                               }t        |      | t        d
      <   y y )Nz/Tz9annotation_name is only supported when in_reply_to is setr+   z5reply_type is only meaningful when in_reply_to is setindirect_referencezUin_reply_to must be a registered annotation (added via writer.add_annotation() first)z/IRT/z/RTz/NM)	r   r   
ValueError
isinstancer   getattrstruuiduuid4)selfr,   r-   r.   r/   refindirect_refs          r&   __init__zMarkupAnnotation.__init__A   s      %5i%@DD!"&;+>K  !4G  "+~6&1&{4H$O!,?$D  #'*DF#$&01ZL1A&BDE"#&"%djjl"3&6&GDE"# #r(   )__name__
__module____qualname____doc__r   r7   r   r   r   r   r=    r(   r&   r*   r*   *   so    2 $(IM,/)-!H C=!H e$4n$DEF	!H
 L)!H "#!H 
!Hr(   r*   c                   \     e Zd ZdZdeddeeeeeeef   f   de	de
deded	d
f fdZ xZS )Textz
    A text annotation.

    Args:
        rect: array of four integers ``[xLL, yLL, xUR, yUR]``
            specifying the clickable rectangular area
        text: The text that is added to the document
        open:
        flags:

    F)openflagsrecttextrE   rF   kwargsr   Nc                
   t        |   di | t        d      | t        d      <   t        |      | t        d      <   t	        |      | t        d      <   t        |      | t        d      <   t        |      | t        d      <   y )Nz/Text/Subtype/Rect	/Contentsz/Openz/FlagsrB   )superr=   r   r   r   r   r   )r:   rG   rH   rE   rF   rI   	__class__s         r&   r=   zText.__init__r   sy     	"6"'1'':Z
#$$3D$9Z !(8(>Z$%$1$$7Z !%1%%8Z!"r(   )r>   r?   r@   rA   r   r   r   tuplefloatr7   boolintr   r=   __classcell__rO   s   @r&   rD   rD   e   sn    
" 9 OU5%+E%FFG9 	9
 9 9 9 
9 9r(   rD   c                        e Zd ZdZddddddddded	eeeeeeef   f   d
ede	de	dedede
e   de
e   deddf fdZ xZS )FreeTextzA FreeText annotation	HelveticaF14pt000000ffffff)fontbolditalic	font_size
font_colorborder_colorbackground_colorrH   rG   r\   r]   r^   r_   r`   ra   rb   rI   r   Nc       	            t        |   di |
 t        d      | t        d      <   t        |      | t        d      <   d}|r| d}n| d}|r| d}n| d}| | d| }| d	| }d
}|rt	        |      D ]	  }| | d} | d}| j                  t        d      t        d      t        d      t        |      t        d      t        |      t        d      t        |      t        d      t        |      i       |+t        t        d      t        d      i      | t        d      <   |	8t        t	        |	      D cg c]  }t        |       c}      | t        d      <   y y c c}w )Nz	/FreeTextrK   rL   zfont: zitalic znormal zbold  z;text-align:left;color:# rgrM   z/DSz/DAz/Wr   z/BS/CrB   )rN   r=   r   r   r   updater   r   r   r
   r   )r:   rH   rG   r\   r]   r^   r_   r`   ra   rb   rI   font_strdefault_appearance_stringstnrO   s                  r&   r=   zFreeText.__init__   s    	"6"'1+'>Z
#$$3D$9Z ! "7+H"7+H"5)H"7+HZ	{!D62Z7
|D$&! . P/H.I"Q,O)P+D*ER(H%:&
;(?7#_T%:;')9$)?5!#3H#=5!#34M#N		
 &6 t$l1o'DE"# '%0)34D)EFAQF&DD!" (Fs   E()r>   r?   r@   rA   r7   r   r   rP   rQ   rR   r   r   r=   rT   rU   s   @r&   rW   rW      s      "&.*2: : OU5%+E%FFG	:
 : : : : : sm: #3-: : 
: :r(   rW   c                   T     e Zd Z	 d	dededeeeeeeef   f   dede	ddf fdZ
 xZS )
Linep1p2rG   rH   rI   r   Nc                    t        |   di | | j                  t        d      t        d      t        d      t	        |      t        d      t        t        |d         t        |d         t        |d         t        |d         g      t        d      t        t        d      t        d      g      t        d	      t        t        d
      t        d
      t        d
      g      t        d      t        |      i       y )NrK   z/LinerL   z/Lr   r   z/LEz/None/ICg      ?rM   rB   )rN   r=   rh   r   r   r
   r   r   )r:   ro   rp   rG   rH   rI   rO   s         r&   r=   zLine.__init__   s     	"6":&
7(;7#_T%:4 +#BqE*#BqE*#BqE*#BqE*	# 5!;"7+"7+$ 5!;#C(#C(#C($ ;')9$)?1	
r(   )re   )r>   r?   r@   r   r   r   rP   rQ   r7   r   r=   rT   rU   s   @r&   rn   rn      sd     $
$
 $
 OU5%+E%FFG	$

 $
 $
 
$
 $
r(   rn   c                   2     e Zd Zdee   deddf fdZ xZS )PolyLiner   rI   r   Nc                    t        |   di | t        |      dk(  rt        d      g }|D ]9  \  }}|j	                  t        |             |j	                  t        |             ; | j                  t        d      t        d      t        d      t        |      t        d      t        t        |            i       y )Nr   z7A polyline needs at least 1 vertex with two coordinatesrK   z	/PolyLine	/VerticesrL   rB   rN   r=   lenr4   appendr   rh   r   r
   r   r'   r:   r   rI   
coord_listr$   r%   rO   s         r&   r=   zPolyLine.__init__   s    
 	"6"x=AVWW
 	/DAql1o.l1o.	/ 	:&
;(?;'Z)@7#_5LX5V%W	
r(   )r>   r?   r@   listr   r   r=   rT   rU   s   @r&   rt   rt      s-    
v,
 
 
	
 
r(   rt   c            	       T     e Zd Zdddeeeeeeef   f   dee   de	ddf fdZ
 xZS )	RectangleNinterior_colorrG   r   rI   r   c          
      <   t        |   di | | j                  t        d      t        d      t        d      t        d      t        d      t	        |      i       |r8t        t        |      D cg c]  }t        |       c}      | t        d      <   y y c c}w )N/Type/AnnotrK   z/SquarerL   rr   rB   rN   r=   rh   r   r   r
   r   r   r:   rG   r   rI   rl   rO   s        r&   r=   zRectangle.__init__  s     	"6"7#Z%9:&
9(=7#_T%:	
 &1)3N)CDAQD'DE"# D   2Br>   r?   r@   r   r   rP   rQ   r   r7   r   r=   rT   rU   s   @r&   r~   r~     sT    
 )-	OU5%+E%FFG !	
  
 r(   r~   c                   X     e Zd Zddddeeeeeeef   f   dedede	de
d	d
f fdZ xZS )	Highlightff0000F)highlight_colorprintingrG   quad_pointsr   r   rI   r   Nc                N   t        |   di | | j                  t        d      t        d      t        d      t	        |      t        d      |t        d      t        t        |      D cg c]  }t        |       c}      i       |rt        j                  | _
        y y c c}w )NrK   z
/HighlightrL   z/QuadPointsrg   rB   )rN   r=   rh   r   r   r
   r   r   r	   PRINTrF   )r:   rG   r   r   r   rI   rl   rO   s          r&   r=   zHighlight.__init__  s     	"6":&
<(@7#_T%:=);4 +-7-HI[^I#			
 '--DJ 	 Js   +B")r>   r?   r@   r   r   rP   rQ   r
   r7   rR   r   r=   rT   rU   s   @r&   r   r     si      (. OU5%+E%FFG. !	.
 . . . 
. .r(   r   c            	       T     e Zd Zdddeeeeeeef   f   dee   de	ddf fdZ
 xZS )EllipseNr   rG   r   rI   r   c          
      <   t        |   di | | j                  t        d      t        d      t        d      t        d      t        d      t	        |      i       |r8t        t        |      D cg c]  }t        |       c}      | t        d      <   y y c c}w )Nr   r   rK   z/CirclerL   rr   rB   r   r   s        r&   r=   zEllipse.__init__2  s     	"6"7#Z%9:&
9(=7#_T%:	
 &1)3N)CDAQD'DE"# Dr   r   rU   s   @r&   r   r   1  sT    
 )-	OU5%+E%FFG !	
  
 r(   r   c                   <     e Zd Zdeeeef      deddf fdZ xZS )Polygonr   rI   r   Nc                    t        |   di | t        |      dk(  rt        d      g }|D ]9  \  }}|j	                  t        |             |j	                  t        |             ; | j                  t        d      t        d      t        d      t        d      t        d      t        |      t        d      t        d	      t        d
      t        t        |            i       y )Nr   z6A polygon needs at least 1 vertex with two coordinatesr   r   rK   z/Polygonrv   z/ITz/PolygonCloudrL   rB   rw   rz   s         r&   r=   zPolygon.__init__J  s    
 	"6"x=AUVV
 	/DAql1o.l1o.	/ 	7#Z%9:&
:(>;'Z)@5!:o#>7#_5LX5V%W	
r(   )	r>   r?   r@   r|   rP   rQ   r   r=   rT   rU   s   @r&   r   r   I  s7    
uUE\*+
 
 
	
 
r(   r   ).sysr8   abcr   typingr   r   r   r   	constantsr	   genericr
   r   generic._baser   r   r   r   r   r   generic._rectangler   generic._utilsr   _baser   r   version_infor   typing_extensionsrP   rQ   r   __annotations__r|   r'   r*   rD   rW   rn   rt   r~   r   r   r   rB   r(   r&   <module>r      s    
   0 0 & 3  1 ' 1BQ7"  , %,'	 '9d6l 9 98H+S 8Hv9 9<= =@%
 %
P
 
,  ..  .2 0
 
r(   