+
    ˧6jZ                   ,)  a 0 t $ R t^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt	^ RI
t
^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^RIHt RRRRRRRRRRR	RR
RRRRRRR/
R lt]! ]P6                  P9                  R4      ]P:                  R7      s]! ]P6                  P9                  R4      ]P:                  R7      s] ! 4       t!Rs"R t#R t$R t%RRRRRRRRRRR	RR
RRRRR/	R lt&RRRRRRRRRRR	RR
RRRRR/	R lt'ERfR lt(ERgR lt)R t*]+! ]PX                  R,           ]-! ^ 4      ,           4      t.R t/R t0]0! R^4      t1]/! R R!4      t2 ! R" R#4      t3]3! 4       t4Rt5R$]6R%&   R!s7R& t8R' t9]P6                  P9                  R(4      t:]:e   ](! ]; R)]:: R*24       ](! ]; R+]P6                  R,,           24       ]:R8X  d   ^ RI:t:M.^ RI	t	]	Px                  P{                  R-]:4      P}                  4       t:]:P~                  P                  P                  tAM8 ^R.IHAtA ]C! ]AR/4      '       d   ]AP                  ! 4        ]AP                  ! 4        R0 tF^R1IGHHtH ^R2IGHItI ^R3IGHJtJ ^R4IGHKtK ^R5IGHLtL ^R6IGHMtM ^R7IGHNtN ^R8IGHOtO ]AP                  tQRtR]S! ]QP                  R94       U u. uF  p ]F! V 4      NK  	  up 4      tU]U]AP                  ]AP                  ]AP                  38X  g1   Q R:]U: R;]AP                  ]AP                  ]AP                  3: 24       h]L]QR3tY]QtZ]Lt[Rt\R<R=/R> lt]]]t^ ]P                  t_]P                  ]_,          te]P                  ]f,          tg]P                  ]h,          ti]P                  ]kR3,          tl]P                  ]P                  ,          tn]P                  ]o,          tpR?tqR@trRAtsRBttRC tuERhRD ltvRE twERhRF ltxRG ty^ tz ! RH RI4      t{ ! RJ RK4      t| ! RL RM4      t} ! RN RO4      t~ ! RP RQ4      t ! RR RS4      t]2'       d   ]EP                  t ! RT RU4      t]t ! RV RW4      t ! RX RY4      t ! RZ R[4      t ! R\ R]4      t ! R^ R_4      t ! R` Ra]4      t]! 4       t ! Rb Rc4      t ! Rd Re4      t^RfIHt  ! Rg Rh4      tERiRi lt ! Rj Rk4      t ! Rl Rm4      t ! Rn Ro4      t ! Rp Rq4      t ! Rr Rs4      t ! Rt Ru4      t ! Rv Rw4      t ! Rx Ry4      t ! Rz R{4      t ! R| R}4      t ]EP6                  ],          t ]AEP<                  EP?                  4        FE  w  tt]EPE                  ERj4      '       g   K!  ]EPE                  R~4      '       d   K;  ]! ]]]4       KG  	  ^ ]AEPJ                  ,          ]AEPL                  ,          ]AEPN                  ,          ]AEPP                  ,          ]AEPR                  ,          ]AEPT                  ,          t]AEPX                  ^8X  g   Q h]]AEPZ                  8X  g   Q h]]AEP\                  8X  g   Q hAAA]EP^                  tERkt/ t] F  t]]]EPi                  4       &   K  	  R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   R]R&   RtRtERltRtRs. s^s^ s]AEPz                  t]AEP|                  t]AEP~                  t]AEP                  t]AEP                  t]AEP                  t]AEP                  t]AEP                  t^ t^t^t^ t^t^t^t^t^t^t^t^t^t^t^ t^@t^t^t^ t^t^t^t^t^t^t^t^t^	t^
t^t^t^t^ t^t^t^t^t^t^t^t^t^ t^t^t^t^t]AEP                  t]AEP                  t]AEP                  t]AEP                  t]AEP                  t]AEP                  t]AEP                  Et ]AEP                  Et]AEP                  Et]AEP
                  Et]AEP                  Et]AEP                  Et
]AEP                  Et]AEP                  Et]UERm8  d   ]AEP                  Et]UERn8  d   ]AEP"                  Et]AEP&                  Et]AEP*                  Et]AEP.                  Et]AEP2                  Et]AEP6                  Et]AEP:                  Et]AEP>                  Et E]Et!E]Et"^ ],          ],          E] ,          E],          Et#^ ],          ],          E] ,          E],          Et$^ ],          ],          E] ,          ],          E],          Et%E]%Et&^ ],          E] ,          ],          E],          Et'^ ],          ],          E] ,          ],          E],          Et(^ ],          ],          E] ,          ],          E],          Et)^ ],          ],          E] ,          E],          Et*^ ],          ],          E] ,          E],          Et+^ Et,^Et-^Et.^ Es/^Et0^Et1^Et2REt3REt4REt5REt6REt7REt8REt9REt:REt;REt<REt=REt>REt?REt@REtAREtBRR RR RR RR RR RR RR /EtC ! R RE]D4      EtE ! R RE]D4      EtF ! R RE]E4      EtG]~! E]04      EtH]~! E]14      EtI]~! E]24      EtJREtKREtLREtMREtNREtOREtPREtQREtRREtSREtTREtUREtVREtWREtXREtYREtZREt[REt\REt]REt^REt_REt`REtaREtbREtcREtdREteREtfREtgREthREtiREtjREtkREtlREtmREtnREtoREtpREtqREtrREtsREttREtuREtvREtwREtxREtyREtzREt{REt|REt}REt~REt ^ REIEHEtEHEt E]EP                  ! 4       EtE]EP                  4        F  EtE]E],          E]E],          R&   K  	  EAEAERoEtERpEtR EtR EtR EtR EtR EtR EtR EtR EtER  EtER EtER EtER EtER EtER EtER EtER EtER EtER	 EtER
 EtER ER lEtER ER lEtER EtER EtER EtER EtER EtER EtER EtER EtER EtER EtER EtER EtER EtER EtER EtER EtER EtER  EtER! EtER" EtER# EtER$ EtER% EtER& EtER' EtER( EtER) EtER* EtER+ EtER, EtER- EtER. EtER/ EtER0 EtER1 EtER2 EtER3 EtER4 EtER5 EtER6 ER7 lEtER8 ER9 lEtER: EtER; EtER< EtER= EtER> EtER? EtER@ EtERA EtERB EtERC EtERD EtERE EtERF EtERG EtERH EtERI EtERJ EtERK EtREsERL EtERM EtERN EtERO EtERP EtERQ EtERR EtERS EtERT EtERU EtERV EtERW EtERX EtERY EtERZ EtER[ EtER\ EtER] EtER^ EtER_ EtER` EtERa EtERb EtERc EtERd EtERe EtERf EtERg EtERh EtERi EtERj EtERk EtERl EtERm EtERn EtERo EtERp EtERq Et ERr EtERs EtERt EtERu EtERv EtERw EtERx EtERy EtERz Et	ER{ Et
ER| EtER} EtER~ EtER EtER EtER EtER EtER EtER EtER EtER EtER EtEREtEREtEREtEREtEREtEREtEREtEREtEREtEREt EREt!EREt"EREt#EREt$EREt%EREt&EREt'EREt(EREt)EREt*EREt+EREt,EREt-EREt.EREt/EREt0EREt1REt2EREt3ER Et4ERqER lEt5ER ER lEt6ER ER lEt7ER ER lEt8ER ER lEt9ER ER lEt:ER ER lEt;ER ER lEt<ER ER lEt=ER ER lEt>ER Et?ER Et@ER ER lEtAER EtBER EtCER EtDER EtEER ER lEtFER ER lEtGERrER lEtHERRERRRR/ER ER llEtIERsER ER llEtJER ER lEtKER EtLER EtMER EtNER EtOER EtPER EtQER EtRER EtSER EtTER EtUER EtVER EtWER EtXER EtYER EtZER Et[ER Et\ER Et]ER Et^ ! ER ER]AEP                  4      Et`ER EtaER EtbER EtcER EtdER EteER EtfER EtgER EthER EtiER EtjER EtkER EtlER EtmER EtnER EtoER ER lEtp ! ER ER]AEP                  4      Etr ! ER ER]AEP                  4      Ett ! ER ER]AEP                  4      EtvER Etw ! ER ER]AEP                  4      Etx ! ER ER]AEP                  4      EtyERtER ER llEtzER  ER lEt{ER ER lEt|ER ER lEt}ER Et~ER EtER EtER	 EtER
 EtER ER lEt ! ER ERE]4      EtER EtERuER ER llEtER ER lEtER EtERvER ER llEtER EtERRERRERRERRERRERR/ER lEtERRERRERRERRERRERR/ER lEtER  EtER! EtER" EtER# EtER$ EtER% EtER& EtER' EtER( EtER) EtER* EtER+ EtER, EtER- EtER. EtER/ EtER0 ER1 lEtER2 ER3 lEtER4 EtER5 EtERgER6 lEtER7 ER8 lEtER9 ER: lEtER; ER< lEtER= EtER> EtER? Et^Et^Et^Et^EtER@ ERA lEtERB EtERCERwERD]f! 4       ERERERFERwERG]f! 4       ERHRERIERJERKRERLR/	ERM lEtERHRERIERJERKRERNRERORRRERPRERQRERRRERLR/
ERS lEt ! ERT ERU4      Et]:'       g)   ]AEPd                  ! E]4       ]AEPf                  ! E]4       ERV Et]EPj                  ! E]4       ^ERWIEHEt E]EPl                  Et]f! 4       EtE] F=  w  EtEtEtEtE]^,          E]^,          E]^,          3E]E]EPi                  4       &   K?  	  ERX EtERY EtERhERZ lEt^ER[IEHEt E]EP                  EtE]EP                  EtE]EP                  EtE]EP                  EtE]EP                  Et^ER\IEHEt  ! ER] ER^E]4      EtER_ Et ][EtER`][ ERa]Z ERb]EP                  ^ ,           R9]EP                  ^,           ERc]EP                   ERd]EP                  ERx8  d   ^@M^  ERe2tR#   ]B d	    ^ RIAtA EL0i ; iu up i   ]` d    ]a]b,          ]c,          t_ EL;i ; i  E] d    / Et E	Li ; i(y  zk
PyMuPDF implemented on top of MuPDF Python bindings.

License:

    SPDX-License-Identifier: GPL-3.0-only
)annotationsN)extratextfdstreampathpath_append	pyloggingpylogging_loggerpylogging_levelpylogging_namedefaultc        
        |  aa V Ee1   V P                  R4      '       d   \        V R,          4      pEMV P                  R4      '       d   V R,          pMV P                  R4      '       d   V R,          pMV P                  R4      '       d   Rp\        4       p
V R	,          P                  R
4      pV FC  pV'       g   K  VP                  R^4      p\	        V4      ^8X  g   Q RV: R24       hVw  rWV&   KE  	  V
P                  R4      oSe   \        S4      oV
P                  RR4      pMQ RT : R24       hVe   \        P                  ! VRRR7      pV# Ve-   \        VR4      '       g   Q h\        VR4      '       g   Q hTpV# Ve   \        P                  ! VR4      pV# Ve   \        P                  ! VR4      pV#  Vf   Sf	   Sf   Vei   ^ RI	pSf   Vf   RpVP                  V4      o\        SVP                  4      '       g   Q hSf   SP                  4       o ! VV3R lR4      pV! 4       pV# T	pV# )a  
Returns a stream that writes to a specified destination, which can be a
file descriptor, a file, an existing stream or Python's `logging' system.

Args:
    text: text specification of destination.
        fd:<int> - write to file descriptor.
        path:<str> - write to file.
        path+:<str> - append to file.
        logging:<items> - write to Python `logging` module.
            items: comma-separated <name=value> pairs.
                level=<int>
                name=<str>.
            Other names are ignored.
    
    fd: an int file descriptor.
    stream: something with methods .write(text) and .flush().
        If specified we simply return <stream>.
    path: a file path.
        If specified we return a stream that writes to this file.
    path_append: a file path.
        If specified we return a stream that appends to this file.
    pylogging*:
        if any of these args is not None, we return a stream that writes to
        Python's `logging` module.
        
        pylogging:
            Unused other than to activate use of logging module.
        pylogging_logger:
            A logging.Logger; If None, set from <pylogging_name>.
        pylogging_level:
            An int log level, if None we use
            pylogging_logger.getEffectiveLevel().
        pylogging_name:
            Only used if <pylogging_logger> is None:
                If <pylogging_name> is None, we set it to 'pymupdf'.
                Then we do: pylogging_logger = logging.getLogger(pylogging_name)
Nzfd:   NNzpath:   NNzpath+zlogging:T:   NN,=zNeed `=` in item=.levelnamepymupdfz?Expected prefix `fd:`, `path:`. `path+:` or `logging:` in text=wF)modeclosefdwriteflushac                  ,   < ] tR t^tV V3R ltR tRtR# )_make_output.<locals>.Outc                	b   < VP                  R 4      pV'       d   SP                  SV4       R# R# )
N)rstriplog)selfr   r   r
   s   &&H/opt/hart-platform/venv/lib/python3.14/site-packages/pymupdf/__init__.pyr   _make_output.<locals>.Out.write   s+     {{4($(($?     c                	    R # N r&   s   &r'   r   _make_output.<locals>.Out.flush   s    r)   r,   N)__name__
__module____qualname____firstlineno__r   r   __static_attributes__)r   r
   s   r'   Outr!      s    @r)   r4   )
startswithintdictsplitlengetioopenhasattrlogging	getLogger
isinstanceLoggergetEffectiveLevel)r   r   r   r   r   r	   r
   r   r   r   items_ditemsitemnvnvretr>   r4   s   $$$$$$dd$$         r'   _make_outputrJ   .   sF   f ??5!!T"XB__W%%8D__W%%r(K__Z((IfGHNN3'EZZQ'2w!|<'9D7!%<<|
  &kk'2O*"%o"6$[[;N[XSWRYYZ[[1	~ggbsE2H JG 
	vw''''vw''''@ J? 
	ggdC < J; 
	 ggk3'8 J7 $+*)#%!*&00@*GNN;;;;".@@BO		 		 e J Jr)   PYMUPDF_MESSAGE)r   r   PYMUPDF_LOGFc                     \         # r+   _g_log_itemsr,   r)   r'   
_log_itemsrP      s    r)   c                
    V s R # r+   )_g_log_items_active)actives   &r'   _log_items_activerT      s     r)   c                     \         R  R# )NNNNrN   r,   r)   r'   _log_items_clearrW      s	    Qr)   c        	        8    \        V VVVVVVVV\        R7
      sR# )zG
Sets destination of PyMuPDF messages. See _make_output() for details.

r   r   r   r   r   r	   r
   r   r   r   N)rJ   _g_out_message	r   r   r   r   r   r	   r
   r   r   s	   $$$$$$$$$r'   set_messagesr\      s,      "#-+)"Nr)   c        	        8    \        V VVVVVVVV\        R7
      sR# )z\
Sets destination of PyMuPDF development/debugging logging. See
_make_output() for details.
rY   N)rJ   
_g_out_logr[   s	   $$$$$$$$$r'   set_logr_      s,    " #-+)Jr)    c                    \         P                  ! ^ R7      pW!,          p \        P                  P	                  VP
                  4      pVP                  pVP                  pV RV RV RV  2p ?\        '       d   \        P                  V 4       \        '       d   \        V \        ^R7       R# R#   \         d    TP
                  p Li ; i  \         d     Lmi ; i)z(
For development/debugging diagnostics.
)context:z(): filer   N)inspectstackosr   relpathfilename	ExceptionlinenofunctionStopIterationrR   rO   appendr^   print)r   callerrg   frame_recordrj   linerm   s   &&     r'   r%   r%      s    a( }	-ww|'<'<=H ""((1TF!H:T$8D!zd1-   	-#,,H	-  s"   C )B4 4CCCCc                F    \         '       d   \        V \         ^R7       R# R# )z
For user messages.
rd   N)rZ   rp   r   s   &r'   messagerv     s     ~dq1 r)   c                 V    ^ RI p \        R4       \        V P                  4       4       R# )    Nzexception_info:)	tracebackr%   
format_exc)ry   s    r'   exception_infor{     s    /	r)   z
()<>[]{}/%c                    \         P                  P                  V 4      pVf   TpM"VR8X  d   RpMVR8X  d   RpMQ RT  RT: 24       hW18w  d   \        RV  RV: 24       V# )q
Returns `True`, `False` or `default` depending on whether $<name> is '1',
'0' or unset. Otherwise assert-fails.
1T0FzUnrecognised value for : Using non-default setting from )rh   environr:   r%   r   r   rH   rI   s   &&  r'   get_env_boolr     sp    
 	

Ay	
c	
c9+D6A599q
~-dV2aU;<Jr)   c                    \         P                  P                  V 4      pVf   TpM\        V4      pW18w  d   \	        RV  RV 24       V# )r}   r   r   )rh   r   r:   r6   r%   r   s   &&  r'   get_env_intr   1  sI    
 	

Ay!f
~-dV2aS9:Jr)   PYMUPDF_EXCEPTIONS_VERBOSEPYMUPDF_USE_EXTRATc                      ] tR tRtR tRtR# )_GlobalsiK  c                	>    ^ V n         ^ V n        ^ V n        ^ V n        R# rx   N)no_device_cachingsmall_glyph_heightssubset_fontnamesskip_quad_correctionsr-   s   &r'   __init___Globals.__init__L  s"    !"#$  !%&"r)   )r   r   r   r   Nr/   r0   r1   r2   r   r3   r,   r)   r'   r   r   K  s    'r)   r   z typing.Optional[typing.Callable]_get_layoutc                 
    Rs R# )z:For users who never want to see the layout recommendation.FN)_recommend_layoutr,   r)   r'   no_recommend_layoutr   Z  s
     r)   c                     Rp  \         '       d^   \        fT   \        P                  ! R4      R8w  d7   \        P
                  P                  R4      '       g   \        V 4       Rs R# R# R# R# R# )z;Check if we should recommend installing the layout package.zVConsider using the pymupdf_layout package for a greatly improved page layout analysis.NPYMUPDF_SUGGEST_LAYOUT_ANALYZERr   zpymupdf.layoutF)r   r   rh   getenv	importlibutil	find_specrp   )msgs    r'   _warn_layout_oncer   `  sf    dC 	
 II78C? (()9::c
! ; @   r)   MUPDF_CPPYYz: $MUPDF_CPPYY=z% so attempting to import mupdf_cppyy.z: $PYTHONPATH=
PYTHONPATHmupdf_cppyy)mupdfinternal_check_ndebugc                R    V P                  R4      pV^ 8  d   V RV p \        V 4      # )z4
Converts string to int, ignoring trailing 'rc...'.
rcN)findr6   )r   r   s   & r'   _int_rcr     s-     
4B	QwCRyt9r)   )mupdf_location)pymupdf_git_branch)pymupdf_git_diff)pymupdf_git_sha)pymupdf_version)pymupdf_version_tuple)swig_version)swig_version_tupler   z8Inconsistent MuPDF version numbers: mupdf_version_tuple=zM != (mupdf.FZ_VERSION_MAJOR, mupdf.FZ_VERSION_MINOR, mupdf.FZ_VERSION_PATCH)=fmtz%gc                   \        V \        \        34      '       d2   RpV  F'  pV'       d
   VR,          pV\        W1R7      ,          pK)  	  V# \        P
                  ! W4      # )z
Returns `value` formatted with mupdf.fz_format_double() if available,
otherwise with Python's `%`.

If `value` is a list or tuple, we return a space-separated string of
formatted values.
r`    )r   )r@   listtuple	_format_gr   fz_format_double)valuer   rI   rH   s   &$  r'   r   r     sW     %$''As
9Q((C  
%%c11r)   matrix_like
point_like	quad_like	rect_likec                b   \        V \        4      '       d*   V P                  '       d   \        R4      hV P                  p \        V \
        P                  4      '       d   V # \        V \
        P                  4      '       d   V P                  4       # V f   Q R4       hQ R\        T 4      : 24       h)zn
Returns document as a mupdf.FzDocument, upcasting as required. Raises
'document closed' exception if closed.
document closeddocument is NoneUnrecognised type(document)=)
r@   Document	is_closed
ValueErrorthisr   
FzDocumentPdfDocumentsupertype)documents   &r'   _as_fz_documentr     s    
 (H%%.//==(E,,--	He//	0	0~~		%$%q31$x.!233qr)   c                   \        V \        4      '       d*   V P                  '       d   \        R4      hV P                  p \        V \
        P                  4      '       d   V # \        V \
        P                  4      '       d5   \
        P                  ! V 4      pV'       d   VP                  '       g   Q hV# V f   Q R4       hQ R\        T 4      : 24       h)z
Returns `document` downcast to a mupdf.PdfDocument. If downcast fails (i.e.
`document` is not actually a `PdfDocument`) then we assert-fail if `required`
is true (the default) else return a `mupdf.PdfDocument` with `.m_internal`
false.
r   r   r   )
r@   r   r   r   r   r   r   r   
m_internalr   )r   requiredrI   s   && r'   _as_pdf_documentr     s     (H%%.//==(E--..	He..	/	/)>>>!>
		%$%q31$x.!233qr)   c                (   \        V \        4      '       d   V P                  p \        V \        P                  4      '       d   V P                  4       # \        V \        P                  4      '       d   V # V f   Q R4       hQ R\        T 4      : 24       h)z8
Returns page as a mupdf.FzPage, upcasting as required.
page is NoneUnrecognised type(page)=)r@   Pager   r   PdfPager   FzPager   pages   &r'   _as_fz_pager     sr     $yy$&&zz|	D%,,	'	'	!L!q/-$t*//qr)   c                p   \        V \        4      '       d   V P                  p \        V \        P                  4      '       d   V # \        V \        P
                  4      '       d5   \        P                  ! V 4      pV'       d   VP                  '       g   Q hV# V f   Q R4       hQ R\        T 4      : 24       h)z
Returns `page` downcast to a mupdf.PdfPage. If downcast fails (i.e. `page`
is not actually a `PdfPage`) then we assert-fail if `required` is true (the
default) else return a `mupdf.PdfPage` with `.m_internal` false.
r   r   )	r@   r   r   r   r   r   pdf_page_from_fz_pager   r   )r   r   rI   s   && r'   _as_pdf_pager      s     $yy$&&	D%,,	'	'))$/>>>!>
	!L!q/-$t*//qr)   c                l    \         P                  ! V 4      pVP                  '       g   \        R4      hV# )a   
Wrapper for mupdf.pdf_annot_page() which raises an exception if <annot>
is not bound to a page instead of returning a mupdf.PdfPage with
`.m_internal=None`.

[Some other MuPDF functions such as pdf_update_annot()` already raise a
similar exception if a pdf_annot's .page field is null.]
Annot is not bound to a page)r   pdf_annot_pager   RuntimeError)annotr   s   & r'   _pdf_annot_pager   5  s.     &D???9::Kr)   c                     ] tR tRtR tR tR tR tR tR t	R t
RCR	 ltRDR lt]R 4       t]R 4       t]R 4       t]R 4       tRER lt]R 4       tR t]R 4       t]R 4       tR tR tR tRFR ltR tR tR tRGR lt]R 4       t]R 4       t ]R 4       t!]R  4       t"]R! 4       t#]R" 4       t$]R# 4       t%]R$ 4       t&]R% 4       t']R& 4       t(]R' 4       t)]R( 4       t*]R) 4       t+R* t,R+ t-R, t.RHR- lt/RIR. lt0R/ t1RJR0 lt2R1 t3RKR2 lt4R3 t5R4 t6RCR5 lt7R6 t8R7 t9R8 t:R9 t;RCR: lt<]R; 4       t=RLR< R= llt>RMR> lt?]@R? 4       tA]R@ 4       tB]RA 4       tCRBtDR
# )NAnnotiJ  c                	V    \        V\        P                  4      '       g   Q hWn        R # r+   )r@   r   PdfAnnotr   r&   r   s   &&r'   r   Annot.__init__L  s    5%..1111	r)   c                	,    \        V P                  4      # r+   )boolr   r-   s   &r'   __bool__Annot.__bool__P  s    DIIr)   c                	N    \        V R R4      pRV P                  ^,           RV 2# )parentz<>'z' annotation on )getattrr   )r&   r   s   & r'   __repr__Annot.__repr__S  s,    x.499Q<. 099r)   c                	"    V P                  4       # r+   )r   r-   s   &r'   __str__Annot.__str__W  s    }}r)   c                	>    \        V R R4      '       d
   RV n        R# R# )thisownFN)r   r   r-   s   &r'   _eraseAnnot._eraseZ  s    4E** DL +r)   c                	   V P                   p\        P                  ! V4      \        P                  8w  d   R # \	        4       p \        P
                  ! \        P                  ! V4      R4      pVP                  '       d*   \        R4       \        P                  ! V4      pWB\        &   \        P
                  ! \        P                  ! V4      R4      pVP                  '       d*   \        P                  ! V4      p\        V4      V\        &   M	RV\        &   \        P                  ! \        P                  ! V4      \        R4      4      p^ pVP                  '       d   \        P                   ! V4      pWb\"        &   TpT'       g   T# T P*                  TR&   \,        P/                  T 4      w  rp
YR&   YR&   YR	&   T P0                  R
,          pYR
&   T#   \$         d    \&        '       d   \)        4         R # i ; i)NROzIgnoring redaction key '/RO'.OverlayTextr`   Qrect
text_colorfontnamefontsizefill)r   r   pdf_annot_typePDF_ANNOT_REDACTr7   pdf_dict_getspdf_annot_objr   message_warning
pdf_to_numdictkey_xrefpdf_to_text_stringJM_UnicodeFromStrdictkey_textpdf_dict_getPDF_NAME
pdf_to_intdictkey_alignrk   g_exceptions_verboser{   r   TOOLS	_parse_dacolors)r&   r   valuesobjxrefr   alignvalr   r   r   r   s   &           r'   _get_redact_valuesAnnot._get_redact_values^  s   		&%*@*@@	%%e&9&9%&@$GC~~~ ?@'','+|$%%e&9&9%&@-PC~~~//4'8'>|$')|$$$U%8%8%?#OCE~~~((-$)=! JiiF).)>&
h&L"J"J{{6"F
  	##(8	s    B"G &BG G;-
G;:G;c                	|   \         '       dg   \        V P                  \        P                  4      '       g   Q h\
        P                  ! V P                  4      p\        V\        4      '       g   Q hV# R pR pV P                  p\        V\        P                  4      '       g   Q h\        P                  ! V4      p\        P                  ! V\        R4      \        R4      4      p\        P                  ! V4      '       d   \        P                  ! V4      pV'       d   VP                  '       d   \        V4      pV# )NAPN)g_use_extrar@   r   r   r   r   Annot_getAPbytesr  pdf_dict_getlr  pdf_is_streampdf_load_streamr   JM_BinFromBuffer)r&   rI   rresr   	annot_objaps   &      r'   _getAPAnnot._getAP  s    ;tyy%..9999##DII.CsE****JACIIEuenn5555++U3I$$i$#OB""B''++R0s~~~$S)Hr)   c                	    V P                   p\        P                  ! V4      p\        V4      p\        P                  ! V\        R 4      \        R4      4      pVP                  '       g   \        \        4      h\        P                  ! V4      '       g   \        \        4      h\        V4      pVP                  '       g   \        \        4      h\        VP                  4       Wg^4       V'       dD   \        P                  ! V\        R4      4      p\        P                   ! V\        R4      V4       R# R#   \"         d    \$        '       d   \'        4         R#  R# i ; i)r  r  RectBBoxN)r   r   r  r   r   r  r   r   MSG_BAD_APNr!  JM_BufferFromBytesr   MSG_BAD_BUFFERJM_update_streamdocpdf_dict_get_rectpdf_dict_put_rectrk   r  r{   )	r&   buffer_r   r   r&  r   apobjr%  bboxs	   &&&      r'   _setAPAnnot._setAP  s    	9IIE++U3I"5)D''HTNHSMRE###"K00&&.."K00$g.C>>> .11dhhj%a8..	8F;KL''0@$G   	9##(8#	9s   BD9 BD9 9E!
E! E!Nc                	
   V P                   pVP                  '       g   Q h\        P                  ! V4      p\	        V4      pVP                  4       p\        P                  ! V4      p	\        V4      w  r V
^ 8X  gS   V	\        P                  \        P                  \        P                  \        P                  \        P                  39  d"   \        P                  ! V\        R4      4       M V
^ 8  d   \        P                  ! W[RV
 4       V^ 8  d   ^M^ pV	\        P                   \        P                  \        P"                  \        P$                  \        P&                  \        P                  \        P                  \        P                  \        P                  \        P(                  \        P*                  39  d   ^ pV'       d"   \        P,                  ! V\        R4      V4       V	\        P"                  8X  d"   V
^ 8  d   \        P.                  ! W[RV
 4       M|V
^ 8  dv   \        P0                  ! VP                  4       V
4      p\3        V
4       F   p\        P4                  ! WV,          4       K"  	  \        P6                  ! V\        R4      V4       \        P8                  ! V4       \        P:                  ! V4       ^ Vn        T^ 8  g   T^8  d   T'       g   R#  \        PF                  ! \        P                  ! T4      \        R4      \        R4      4      pTP                  '       g   \I        \J        4      h\        PL                  ! T\        R4      4      pTP                  '       g"   \        PN                  ! T\        R4      ^4      p\        PP                  ! TP                  4       ^4      pT^ 8  dk   T^8  dd   \        PR                  ! T\        R	4      T4       \        PR                  ! T\        R
4      T4       \        PR                  ! T\        R	4      T4       T'       dC   \        PT                  ! T\        R4      T4       \        PT                  ! T\        R4      T4       \        PL                  ! T\        R4      4      pTP                  '       g"   \        PN                  ! T\        R4      ^4      p\        P6                  ! T\        R4      T4       R#   \>         d+   p\@        '       d   \C        4        \E        RT 24       h Rp?ii ; i  \>         d+   p\@        '       d   \C        4        \E        RT 24       h Rp?ii ; i)rx   ICNRotatezcannot update annot: Tr  r  	ResourcesCAcaBM	ExtGStateHz#cannot set opacity or blend mode
: )+r   r   r   r  r   r1  r  JM_color_FromSequencePDF_ANNOT_SQUAREPDF_ANNOT_CIRCLEPDF_ANNOT_LINEPDF_ANNOT_POLY_LINEPDF_ANNOT_POLYGONpdf_dict_delr  pdf_set_annot_interior_colorPDF_ANNOT_CARETPDF_ANNOT_FREE_TEXTPDF_ANNOT_FILE_ATTACHMENTPDF_ANNOT_INKPDF_ANNOT_STAMPPDF_ANNOT_TEXTpdf_dict_put_intpdf_set_annot_colorpdf_new_arrayrangepdf_array_push_realpdf_dict_putpdf_dirty_annotpdf_update_annotresynth_requiredrk   r  r{   rv   r   r   r-  r  pdf_dict_put_dictpdf_new_dictpdf_dict_put_realpdf_dict_put_name)r&   opacity
blend_mode
fill_colorrotater   r&  r   pdftype_nfcolfcol
insert_rotcolier'  	resourcesalp0extgs   &&&&&               r'   _update_appearanceAnnot._update_appearance  s   		''/	u%hhj$$e,+J71	 zU****((--+++  ""Ix~>22E<H$kqJ))**--33''((--++**))((  
&&y(82DfM 11119--e&5\B))$((*e<A--c7; '""9htncB!!%(""5)#$C  aK7a< 	$$''.TNSMB
 ==="K00**B0EFI'''!33R+9NPQR	%%txxz15D!|!''x~wG''x~wG''HTNGL''x~zJ''HTNJO%%y(;2GHD???..	8K;PRSThsmT: W  	## ,QC01		L  	##(8;A3?@	s@   6ES8 DS8 0ET0  B6T0 8T-%T((T-0U%;%U  U%c                2   \        V 4       V P                  p\        P                  ! V4      p\        P                  ! V\        R4      \        R4      4      pVP                  '       g9   \        \        P                  ! \        P                  P                  4      4      pM+\        P                  ! V\        R4      4      p\        V4      p\        V4      V P                  4       P                  ,          pW@P                  4       P                  ,          pV# )zannotation appearance bboxr  r  r,  )CheckParentr   r   r  r   r  r   JM_py_from_rectFzRectFixed_INFINITEr2  r+  
get_parenttransformation_matrixderotation_matrix)r&   r   r&  r'  r  r   s   &     r'   apn_bboxAnnot.apn_bbox  s     	D		''.	  HTNHSMJ}}}!%,,u||/J/J"KLC**2x/?@D!$'C3i$//+AAA 222
r)   c                ,    \        V 4       V P                  p\        V\        P                  4      '       g   Q h\        P
                  ! \        P                  ! V4      \        P                  \        P                  4      pVP                  '       g   \        \        P                  ! 4       4      # \        P                  ! V\        P                  4      p\        V4      p\        V4      pV#   \         d    \         '       d   \#        4        h i ; i)zannotation appearance matrix)ro  r   r@   r   r   r   r  PDF_ENUM_NAME_APPDF_ENUM_NAME_Nr   JM_py_from_matrixFzMatrixpdf_dict_get_matrixPDF_ENUM_NAME_MatrixMatrixrk   r  r{   )r&   r   r'  matr  s   &    r'   
apn_matrixAnnot.apn_matrix   s    	IIEeU^^4444$$''.**))B
 ===()9::++B0J0JKC#C(C+CJ 	##(8	s   BC0 C0 3<C0 0DDc           
        \        V 4       V P                  p\        P                  ! V4      p\        P                  ! V\        R4      4      pRpVP                  '       d"   \        \        P                  ! V4      4      pV# \        P                  ! V\        R4      \        R4      \        R4      \        R4      4      p\        P                  ! V4      '       d   \        P                  ! V4      p\        V4       F  p\        P                  ! W64      p\        P                  ! V4      '       g   K7  \        P                  ! V4      p\        V4       Fw  p	\        P                  ! Wy4      p
\        P                  ! V
\        R4      4      ^ 8X  g   K@  \        \        P                  ! \        P                  ! Wy4      4      4      pVu u # 	  K  	  V# )zannotation BlendModer?  Nr  r  r<  r@  )ro  r   r   r  r  r  r   r	  pdf_to_namer   pdf_is_dictpdf_dict_lenrS  pdf_dict_get_valpdf_dict_get_key
pdf_objcmp)r&   r   r&  r  r^  rG   rg  obj1mjobj2s   &          r'   	blendmodeAnnot.blendmode8  s]    	D		''.	  HTN;
>>>*5+<+<S+ABJ!!%% S!!""3'A1X--c5$$T****40A"1X$55d> ++D(4.AQF):5;L;LUMcMcdhMl;m)nJ#--	 &	  r)   c                   \        V 4       V P                  ^ ,          pV\        P                  \        P                  \        P
                  \        P                  \        P                  \        P                  \        P                  39  d   \        4       # \        P                  ! V P                  4      p\        V4      pV# )zBorder information.)ro  r   r   rD  rK  rM  rE  rF  rG  rC  r7   r  r   JM_annot_border)r&   atypeaorI   s   &   r'   borderAnnot.borderX  s     	D		!&&))##$$))''&&  6M  +b!
r)   c                    \        V 4       V P                  p\        P                  ! \        P                  ! V4      4      p\        ^^ ^ VR7      p\        P                  ! W2V4       R# )z!Clean appearance contents stream.)recurseinstance_formsasciisanitizeN)ro  r   r   pdf_get_bound_documentr  _make_PdfFilterOptionspdf_filter_annot_contents)r&   r  r   ra  filter_s   &&   r'   clean_contentsAnnot.clean_contentsk  sO    D		**5+>+>u+EF(1AX`a''G<r)   c                     \        V 4       V P                  p\        V\        P                  4      '       g   Q h\        \        P                  ! V4      4      #   \         d    \        '       d   \        4        h i ; i)zColor definitions.)
ro  r   r@   r   r   JM_annot_colorsr  rk   r  r{   r   s   & r'   r  Annot.colorss  sb    	IIEeU^^4444"5#6#6u#=>> 	##(8	s   AA A=1A=c                D   \        V 4       V P                  p\        P                  ! V4      p\	        V4      p \        V4      pV'       g   M\        P                  ! W44       K-  \        P                  ! V\        R4      4       \        P                  ! VP                  4       \        R4      4      p\        P                  ! V4      p^ p\        V^,
          RR4       F  p\        P                  ! WX4      p	\        P                  ! V	\        R4      4      p
V	P                  '       g   KM  \        P                  ! W4      '       d   Kk  \        P                   ! WX4       ^pK  	  V'       d2   \        P"                  ! VP                  4       \        R4      V4       R# R# )z*Delete 'Popup' and responding annotations.PopupAnnotsParentN)ro  r   r   r  r   JM_find_annot_irtpdf_delete_annotrH  r  r  r  pdf_array_lenrS  pdf_array_getr   r  pdf_array_deleterU  )r&   r   r&  r   	irt_annotannotsrG   foundrg  ops   &          r'   delete_responsesAnnot.delete_responses  s*   D		''.	u%)%0I""439hw&78##DHHJ0BC'qsB#A##F.A""1hx&89A<<<##A11&&v1 $ txxz8H+=vF r)   c                .   \        V 4       \        4       pRpRpRpV P                  p\        P                  ! V4      p\        P
                  ! V4      pV\        P                  8w  d   \        \        4      h\        P                  ! V\        R4      \        R4      \        R4      4      pVP                  '       g   \        R\        4       \        P                  ! V\        R4      4      p	\        P                  ! V	\        R4      4      p
V
P                  '       d   \        P                  ! V
4      pMH\        P                  ! V	\        R4      4      p
V
P                  '       d   \        P                  ! V
4      p\        P                  ! V	\        R4      4      p
V
P                  '       d   \        P                  ! V
4      p\        P                  ! V\        R4      4      p
V
P                  '       d   \        P                   ! V
4      p\        P                  ! V\        R	4      \        R
4      4      p
V
P                  '       d   \        P                   ! V
4      p\#        X4      V\$        &   \'        V4      V\(        &   W!\*        &   W1\,        &   V# )zAttached file information.NFSEFFbad PDF: file entry not foundUFDescLengthParamsSizer  )ro  r7   r   r   r  r  rL  	TypeErrorMSG_BAD_ANNOT_TYPEr   r  r   RAISEPYJM_Exc_FileDataErrorr  r  r  JM_EscapeStrFromStrdictkey_filenamer	  dictkey_descrdictkey_lengthdictkey_size)r&   r%  lengthsizedescr   r&  rb  r   fsr  rj   s   &           r'   	file_infoAnnot.file_info  s    	Df		''.	$$U+E333/00$$	    46JK	8D>:r8D>2<<<//2H""2x}5A||| 33A6r8F#34<<<++A.Dvx'9:<<<%%a(F(:HV<LM<<<##A&D!4X!>/5]%^!\
r)   c                \    \        V 4       V P                  p\        P                  ! V4      # )zFlags field.)ro  r   r   pdf_annot_flagsr   s   & r'   flagsAnnot.flags  s&     	D		$$U++r)   c                   \        V 4       V P                  p\        P                  ! V4      p\        P                  ! V4      pV\        P
                  8w  d   \        \        4      h\        P                  ! V\        R4      \        R4      \        R4      4      pVP                  '       g   \        R\        4       \        P                  ! V4      p\        V4      pV# )zRetrieve attached file content.r  r  r  r  )ro  r   r   r  r  rL  r  r  r   r  r   r  r  r"  r#  )r&   r   r&  r   r   bufr%  s   &      r'   get_fileAnnot.get_file  s    D		''.	##E*5222/00$$YPXY\P]^   46JK##F+s#
r)   c                    \        V 4       ^ pV P                  p\        P                  ! V4      p\        P                  ! V\        R4      4      pVP                  '       d   \        P                  ! V4      pV# )z*Get annotation optional content reference.OCro  r   r   r  r  r  r   r  )r&   ocr   r&  r  s   &    r'   get_ocAnnot.get_oc  s\    D		''.	  HTN;>>>!!#&B	r)   c                	.    \        V R 4      pV#   \         dz    \        T P                  4      p\	        T\
        P                  4      '       g   Q hTP                  '       d   \        TP                  4       4      MRp\        Y#4      pYn         T# i ; i)r   N)r   AttributeErrorr   r   r@   r   r   r   r   r1  r   r   )r&   rI   r   r   s   &   r'   rs  Annot.get_parent  s    	4*C 
  	"499-DtU]]333304x,THt&CK 
	s    AB$,BBc                   \        V 4       R\        R\        R\        /p\	        V4      \
        J d!   VP                  VP                  4       R4      pV'       d   \        V^H,          V^H,          4      p\        V4      pTpV'       g   \        P                  ! 4       p\        P                  ! V P                  Wg\        P                  ! ^ 4      V4      p\        V4      p	V'       d   V	P!                  W"4       V	# )zannotation PixmapgrayrgbcmykN)ro  csGRAYcsRGBcsCMYKr   strr:   lowerr  JM_matrix_from_pyr   fz_device_rgbpdf_new_pixmap_from_annotr   FzSeparationsPixmapset_dpi)
r&   matrixdpi
colorspacealphacspacesctmcspixrI   s
   &&&&&     r'   
get_pixmapAnnot.get_pixmap  s     	D65%@
s" Z%5%5%7>JC"HcBh/F'$$&B--dii%BUBUVWBXZ_`SkKK!
r)   c                   \        V 4       V P                  p\        P                  ! V4      p\        P                  ! V4      p\        P
                  ! V\        R4      4      pV\        P                  8w  g   VP                  '       g   \        \        4      h\        P
                  ! V\        R4      4      P                  '       d   \        R\        4       \        4       p\        P
                  ! V\        R4      4      pVP                  '       d   \        P                  ! V4      VR&   \        P
                  ! V\        R4      4      pVP                  '       d   \        P                  ! V4      VR&   \        P
                  ! V\        R4      4      pVP                  '       d   \        P                  ! V4      VR	&   \        P
                  ! V\        R
4      4      pVP                  '       d   \        P                   ! V4      VR&   \        P"                  ! VR4      pVP                  '       d   \        P                   ! V4      VR&   \        P$                  ! V4      p\'        V4      pWR&   V# )zRetrieve sound stream.Soundr  zunsupported sound streamRrateCchannelsBbpsEencodingCOcompressionr   )ro  r   r   r  r  r  r  PDF_ANNOT_SOUNDr   r  r  r  r  r7   pdf_to_realr  r  r  r"  r#  )	r&   r   r&  r   soundr%  r  r  r   s	   &        r'   	get_soundAnnot.get_sound  s   D		''.	##E*""9hw.?@5(((0@0@0@/00eXc]3>>>/1EFf  6>>>++C0CK  6>>>#..s3C
O  6>>>))#.CJ  6>>>#//4C
O!!%.>>>!&!2!23!7C##E*!#&H
r)   c                	6    \         P                  ! V .VO5/ VB # r+   utilsget_textr&   argskwargss   &*,r'   r  Annot.get_text2      ~~d4T4V44r)   c                	6    \         P                  ! V .VO5/ VB # r+   )r  get_textboxr  s   &*,r'   r  Annot.get_textbox5  s      7777r)   c                0   \        V 4       \        P                  ! V4      pV'       dm   \        \        R4      '       g   Q R\         R24       h\        V4      pVP                  4       Vn        V;P                  \        P                  ,          un        V P                  p\        P                  ! WS4      p\        V4      pV P                  4       p\        V\        P                   4      '       d	   Wn        V# \        P$                  ! V4      Vn        V# )zMake annotation TextPage.FZ_STEXT_CLIP_RECTzMuPDF-z% does not support FZ_STEXT_CLIP_RECT.)ro  r   FzStextOptionsr=   mupdf_versionJM_rect_from_pyinternalclipr  r  r   FzStextPageTextPagers  r@   weakref	ProxyTyper   proxy)	r&   r  r  optionsclip2r   	stextpagerI   r  s	   &&&      r'   get_textpageAnnot.get_textpage8  s    D&&u-5"677v6-Pu9vv7#D)E >>+GLMMU555M		%%e5	y!OOa**++J 
 !q)CJ
r)   c                    \        V 4       V P                  p\        P                  ! \        P                  ! V4      \        R4      4      pVP                  '       d   R# R# )z Check if annotation has a Popup.r  TF)ro  r   r   r  r  r  r   )r&   r   r  s   &  r'   	has_popupAnnot.has_popupK  sJ     	D		  !4!4U!;Xg=NO~~~t050r)   c                   \        V 4       V P                  p\        4       p\        \        P
                  ! V4      4      V\        &   \        P                  ! \        P                  ! V4      \        R4      4      p\        \        P                  ! V4      4      V\        &   \        P                  ! \        P                  ! V4      \        R4      4      p\        \        P                  ! V4      4      V\        &   \        P                  ! \        P                  ! V4      R4      p\        \        P                  ! V4      4      V\        &   \        P                  ! \        P                  ! V4      \        R4      4      p\        \        P                  ! V4      4      V\         &   \        P                  ! \        P                  ! V4      R4      p\        P                  ! V4      V\"        &   \        P                  ! \        P                  ! V4      R4      p\        \        P                  ! V4      4      V\$        &   V# )zVarious information details.NameTCreationDateMSubjNM)ro  r   r7   r	  r   pdf_annot_contentsdictkey_contentr  r  r  r  dictkey_namer  dictkey_titler  dictkey_creationDatedictkey_modDatedictkey_subject
dictkey_id)r&   r   r%  r  s   &   r'   info
Annot.infoS  s    	D		f01I1I%1PQOu22598F;KL-e.?.?.BCL u22598C=I.u/G/G/JKM  3 3E :NK$5e6N6Nq6Q$R ! u22598C=I01I1I!1LMO  3 3E :FC$77:O  3 3E :DA+E,D,DQ,GHJ
r)   c                    V P                   p\        P                  ! V4      p\        P                  ! V\	        R4      4      pVP
                  '       g   ^ # \        P                  ! V4      # )z
annotation IRT xref
IRT)r   r   r  r  r  r   r  )r&   r   r&  irts   &   r'   irt_xrefAnnot.irt_xrefu  sP    
 		''/	  )Xe_=~~~%%r)   c                X    \        V 4       \        P                  ! V P                  4      # )z-Get 'open' status of annotation or its Popup.)ro  r   pdf_annot_is_openr   r-   s   &r'   is_openAnnot.is_open  s!     	D&&tyy11r)   c                    V P                   p\        P                  ! V4      pV\        P                  8X  d   R# \	        \        R4      '       g   Q h\        P
                  ! V4      # )zannotation languageNfz_string_from_text_language2)r   r   pdf_annot_languageFZ_LANG_UNSETr=   rD  )r&   
this_annotlangs   &  r'   languageAnnot.language  sS     YY
''
35&&&u=>>>>22488r)   c                    \        V 4       V P                  p\        P                  ! V4      '       g   R# \        P                  ! V4      p\        P
                  ! V4      pW#3# )zLine end codes.N)ro  r   r    pdf_annot_has_line_ending_stylespdf_annot_line_start_stylepdf_annot_line_end_style)r&   r   lstartlends   &   r'   	line_endsAnnot.line_ends  sQ     	D		55e<<11%8--e4|r)   c                *   \        V 4       V P                  p\        V\        P                  4      '       g   Q hVP
                  '       g   Q h\        P                  ! V4      pV\        P                  8w  d   \        P                  ! V4      pM\        P                  ! V4      pVP
                  '       d   \        V4      MRpV'       g   R# RVn        VP                  4       P                  P                  4       V P                  4       P                  P                  4       8X  g   Q hWDP                  P                  \!        V4      &   VP"                  ^ ,          \        P                  8X  d"   \%        4       p\&        P)                  WE4       TpV# )zNext annotation.NT)ro  r   r@   r   r   r   r  PDF_ANNOT_WIDGETpdf_next_annotpdf_next_widgetr   r   rs  m_internal_valuer   _annot_refsidr   Widgetr  _fill_widget)r&   rG  rb  r   r  widgets   &     r'   next
Annot.next  s$    	DYY
*enn5555$$$$$$$Z0E***((4E))*5E#...eElD~~$$5574??;L;Q;Q;b;b;dddd*-

r#w'88A;%000XFs+C
r)   c                   \        V 4       V P                  pRp\        P                  ! \        P                  ! V4      \        P
                  4      p\        P                  ! V4      '       d   \        P                  ! V4      pV# )zOpacity.r  )ro  r   r   r  r  PDF_ENUM_NAME_CApdf_is_numberr  )r&   r   opyr>  s   &   r'   r]  Annot.opacity  sc     	D		!4!4U!;U=S=STr""##B'C
r)   c                
   \        V 4       \        P                  ! \        P                  P                  4      pV P                  p\        P
                  ! V4      p\        P                  ! V\        R4      4      pVP                  '       d!   \        P                  ! V\        R4      4      p\        V4      p\        V4      V P                  4       P                  ,          pWPP                  4       P                  ,          pV# )zannotation 'Popup' rectangler  r+  )ro  r   rq  rr  r   r  r  r  r   r2  rp  r+  rs  rt  ru  )r&   r   r   r&  r  r  s   &     r'   
popup_rectAnnot.popup_rect  s     	D||ELL778		''/	  )Xg->?>>>**30@ADd# 3i$//+AAA 222
r)   c                    \        V 4       ^ pV P                  p\        P                  ! V4      p\        P                  ! V\        R4      4      pVP                  '       d   \        P                  ! V4      pV# )zannotation 'Popup' xrefr  r  )r&   r  r   r&  r  s   &    r'   
popup_xrefAnnot.popup_xref  s_     	D		''.	  HW,=>>>>##C(Dr)   c                    \         '       d"   \        P                  ! V P                  4      pM \        P
                  ! V P                  4      p\        V4      pV P                  4       pWP                  ,          pV# )zannotation rectangle)	r  r   Annot_rect3r   r   pdf_bound_annotr+  rs  ru  )r&   r  r  s   &  r'   r   
Annot.rect  s]     ;##TYY/C''		2C3i OO 	"""
r)   c           	        \         P                  ! V P                  4      p\         P                  ! V\	        R4      4      p\         P
                  ! V4      ^8X  d   \         P                  ! \         P                  ! V^ 4      4      \         P                  ! \         P                  ! V^4      4      \         P                  ! \         P                  ! V^4      4      ) \         P                  ! \         P                  ! V^4      4      ) 3# R# )z&
annotation delta values to rectangle
RDN)r   r  r   r  r  r  r  r  )r&   r&  arrs   &  r'   
rect_deltaAnnot.rect_delta  s    
 ''		2	  )Xd^<$)%%u':':C'CD%%u':':C'CD&&(;(;S!(DEE&&(;(;S!(DEE	  *r)   c                    \        V 4       V P                  p\        P                  ! \        P                  ! V4      \        P
                  4      pVP                  '       g   R# \        P                  ! V4      # )zannotation rotationr  )ro  r   r   r  r  PDF_ENUM_NAME_Rotater   r  )r&   r   rotations   &  r'   ru  Annot.rotation  sZ     	D		%%u':':5'A5C]C]^"""I**r)   c                   \        V 4       V P                  4       pVP                  pVP                  pWV( ,          ,          pV P                  p\
        P                  ! V4      p\
        P                  ! V\        R4      \        R4      4      pVP                  '       g   \        \        4      h\        V4      p\
        P                  ! V\        R4      V4       R# )z!
Set annotation appearance bbox.
r  r  r,  N)ro  rs  rotation_matrixrt  r   r   r  r   r  r   r   r-  r  r3  )	r&   r6  r   rotr  r   r&  r'  r   s	   &&       r'   set_apn_bboxAnnot.set_apn_bbox  s     	D ""((sd
		''.	  HTNHSMJ}}},,t$HV$4d;r)   c                N   \        V 4       V P                  p\        P                  ! V4      p\        P                  ! V\        R4      \        R4      4      pVP                  '       g   \        \        4      h\        V4      p\        P                  ! V\        R4      V4       R# )z!Set annotation appearance matrix.r  r  r  N)ro  r   r   r  r   r  r   r   r-  r  pdf_dict_put_matrix)r&   r  r   r&  r'  r  s   &&    r'   set_apn_matrixAnnot.set_apn_matrix  st    D		''.	  HTNHSMJ}}},,'!!"hx&8#>r)   c                    \        V 4       V P                  p\        P                  ! V4      p\        P                  ! V\        R4      V4       R# )zSet annotation BlendMode.r?  Nro  r   r   r  r\  r  )r&   r^  r   r&  s   &&  r'   set_blendmodeAnnot.set_blendmode*  s9    D		''.		8D>:Fr)   c                B   \        V 4       V P                  R,          w  rgV\        P                  \        P                  \        P
                  \        P                  \        P                  \        P                  \        P                  39  d   \        RV R24       R# V\        P                  \        P                  \        P                  \        P                  39  d   V^ 8  d   \        RV R24       Rp\        V4      \        Jd   RVRVRVR	V/pVP                  RR4       VP                  RR4       VP                  RR4       VP                  R	R4       VR,          f   RVR&   VR	,          f   RVR	&   \        VR,          R
4      '       dC   \        VR,          4      VR&   VR,           F   p\        V\         4      '       d   K  RVR&    M	  V P"                  p	\        P$                  ! V	4      p
\        P&                  ! V
4      p\)        WV
4      # )zZSet border properties.

Either a dict, or direct arguments width, style, dashes or clouds.N   NzCannot set border for ''.NzCannot set cloudy border for 'widthstyledashesclouds__getitem__r  )ro  r   r   rD  rK  rM  rE  rF  rG  rC  rv   r7   
setdefaultr=   r   r@   r6   r   r  r  JM_annot_set_border)r&   r  r  r  r  r  r  atnamerE   r   r&  ra  s   &&&&&&      r'   
set_borderAnnot.set_border1  s    	D		"&&))##$$))''&&  -fXR89&&))''&&	  z8CD<t#uguhRXYF'2&'4((D)(B''?" F7O(#!F86(#]33$VH%56F8x((!$,,'+F8$ ) 		''/	**I6"F;;r)   c                   V P                   ^ ,          \        P                  8X  d   \        R4      h\	        V 4       V P                  4       P                  p\        V4      \        Jd   RVRV/pVP                  R4      pVP                  R4      p\        P                  \        P                  \        P                  \        P                  \        P                  \        P                  3pV. R39   d   VP                  V P                   RR4       MkVeh   \#        VR4      '       d   \%        V4      .p\'        V4       \)        V4      R9   g   Q hR\+        V4       R	2pVP                  V P                   RV4       V'       d;   V P                   ^ ,          V9  d#   \-        R
V P                   ^,           R24       R# V. R39   d    VP                  V P                   RR4       R# Vej   \#        VR4      '       d   \%        V4      .p\'        V4       \)        V4      R9   g   Q hR\+        V4       R	2pVP                  V P                   RV4       R# R# )zLSet 'stroke' and 'fill' colors.

Use either a dict or the direct arguments.
z'cannot be used for FreeText annotationsr   stroker  []N	__float__[]z,Warning: fill color ignored for annot type 'r  r:  r,      r      )r   r   rK  r   ro  rs  r   r7   r:   rD  rC  rE  rF  rG  r  xref_set_keyr  r=   float
CheckColorr9   r   rv   )r&   r  r  r   r1  fill_annotsss   &&&&   r'   
set_colorsAnnot.set_colors`  s   
 99Q<5444FGGDoo&&<t#dHf5Fzz&!H%--u/E/EuG[G[]b]v]vx}  yP  yP--0 b"XTYYT2v{++-vv;)+++If%&a(ATYYQ/DIIaL3B499Q<.PRSTB8TYYd3t[))d}tt9	)))IdO$A&ATYYa0 r)   c                `    \        V 4       V P                  p\        P                  ! W!4       R# )zSet annotation flags.N)ro  r   r   pdf_set_annot_flags)r&   r  r   s   && r'   	set_flagsAnnot.set_flags  s!    D		!!%/r)   c                R   \        V 4       \        V4      \        J d]   VP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pRpV P                  p\
        P                  ! V4      pV'       d   \
        P                  ! Wr4       V'       d   V'       d   \
        P                  ! Ws4       V'       d6   \
        P                  ! \
        P                  ! V4      \        R4      V4       V'       d6   \
        P                  ! \
        P                  ! V4      \        R4      V4       V'       dC   \
        P                  ! \
        P                  ! V4      R	\
        P                  ! V4      4       R# R# R# )
zSet various properties.contentNtitlecreationDatemodDatesubjectr,  r-  r.  )ro  r   r7   r:   r   r   pdf_annot_has_authorpdf_set_annot_contentspdf_set_annot_authorpdf_dict_put_text_stringr  r  pdf_dict_putspdf_new_text_string)	r&   r8  r  r  r  r  r  r   	is_markups	   &&&&&&&  r'   set_infoAnnot.set_info  s,   D:hhy$/GHHWd+E88ND9Lhhy$/Ghhy$/GD		..u5	((8**58..u/B/B5/I8TbKceqr..u/B/B5/I8TW=Zab##E$7$7$>HaHabiHjk  r)   c                ,   V P                   p\        P                  ! V4      p\        V4      pV^8  g*   V\        P                  ! VP                  4       4      8  d   \        \        4      h\        P                  ! VP                  4       V^ 4      p\        P                  ! V\        R4      4      p\        P                  ! \        P                  ! V4      4      pV^ 8  d   \        \        4      h\        P                  ! V\        R4      V4       R# )z
Set annotation IRT xref
Subtyper;  N)r   r   r  r   pdf_xref_lenr1  r   MSG_BAD_XREFpdf_new_indirectr  r  pdf_annot_type_from_stringr  MSG_IS_NO_ANNOTrU  )r&   r  r   r&  r   r<  subtirt_subts   &&      r'   set_irt_xrefAnnot.set_irt_xref  s     		''/	u%!8tu11488:>>l++$$dhhj$:!!3(;<33U5F5F5MNa<o..Ix<r)   c                    \        V 4       V P                  pV'       g   \        P                  pM\        P                  ! V4      p\        P
                  ! W#4       R# )zSet annotation language.N)ro  r   r   rF  fz_text_language_from_stringpdf_set_annot_language)r&   rI  rG  rH  s   &&  r'   set_languageAnnot.set_language  s?    DYY
&&D55h?D$$Z6r)   c                    \        V 4       V P                  p\        P                  ! V4      '       d   \        P                  ! W1V4       R# \        R4       R# )zSet line end codes.zbad annot type for line endsN)ro  r   r   rL   pdf_set_annot_line_ending_stylesr  )r&   startendr   s   &&& r'   set_line_endsAnnot.set_line_ends  s=    D		11%88225E:;r)   c                    \        V 4       V P                  p\        P                  ! V4      p\        P                  ! V\        R4      V4       R# )zSet /Name (icon) of annotation.r*  Nr  )r&   r   r   r&  s   &&  r'   set_nameAnnot.set_name  s:    D		''.		8F+;TBr)   c                    \        V 4       V P                  p\        P                  ! V4      pV'       g#   \        P                  ! V\        R4      4       R# \        \        P                  ! V4      W14       R# )z Set / remove annotation OC xref.r  N)ro  r   r   r  rH  r  JM_add_oc_objectr  )r&   r  r   r&  s   &&  r'   set_ocAnnot.set_oc  sO    D		''.	y(4.9U99)DiTr)   c                    \        V 4       V P                  p\        VRR4      '       g   \        P                  ! V^4       R# \        P                  ! W!4       VR8  d   \        V4      p^Vn        R# R# )zSet opacity.              ?N)ro  r   _INRANGEr   pdf_set_annot_opacityr   transparency)r&   r]  r   r   s   &&  r'   set_opacityAnnot.set_opacity  sa    D		c**''q1##E3S="5)D !D r)   c                `    \        V 4       V P                  p\        P                  ! W!4       R# )z-Set 'open' status of annotation or its Popup.N)ro  r   r   pdf_set_annot_is_open)r&   rA  r   s   && r'   set_openAnnot.set_open  s!    D		##E3r)   c                    \        V 4       V P                  p\        V4      p\        V4      p\        P
                  ! \        V4      V4      p\        P                  ! W%4       R# )z0
Create annotation 'Popup' or update rectangle.
N)ro  r   r   JM_rotate_page_matrixr   fz_transform_rectr  pdf_set_annot_popup)r&   r   r   pdfpagery  r$  s   &&    r'   	set_popupAnnot.set_popup  sN     	D		!%(#G,##OD$93?!!%+r)   c                   \        V 4       V P                  p\        V4      p\        V4      p\        P
                  ! \        V4      V4      p\        P                  ! V4      '       g   \        P                  ! V4      '       d   \        \        4      h \        P                  ! W%4       R#   \         d   p\        RT 24        Rp?R# Rp?ii ; i)zSet annotation rectangle.zcannot set rect: NF)ro  r   r   r  r   r  r  fz_is_empty_rectfz_is_infinite_rectr   MSG_BAD_RECTpdf_set_annot_rectrk   rv   )r&   r   r   r  ry  r$  rh  s   &&     r'   set_rectAnnot.set_rect  s    D		!%(#G,##OD$93?!!!$$(A(A!(D(Dl++	$$U. 	's+,	s   B. .C9CCc                   \        V 4       V P                  p\        P                  ! V4      pV\        P                  \        P
                  \        P                  \        P                  \        P                  \        P                  \        P                  \        P                  \        P                  \        P                  \        P                  39  d   R# TpV^ 8  d   VR,          pK  VR8  d   VR,          pK  V\        P                  8X  d   V^Z,          ^ 8w  d   ^ p\        P                  ! V4      p\        P                   ! V\#        R4      V4       R# )zSet annotation rotation.Nh  r;  )ro  r   r   r  rJ  rD  rK  rL  rM  rE  rF  rG  rC  rN  rO  r  rP  r  )r&   r`  r   r   ry  r&  s   &&    r'   set_rotationAnnot.set_rotation  s   D		##E*%%&&))//##$$))''&&%%$$  Ag3JCSj3JC5,,,rQC''.	y(8*<cBr)   c                   \        V 4       V P                  P                  '       g   R# \        P                  ! V P                  4      p\        P
                  ! V4      p\        P                  ! \        P                  ! V P                  4      R4      pVP                  '       d   \        P                  ! V4      '       d   W3# \        P                  ! V4      pWV3# )zannotation typenullIT)
ro  r   r   r   r  pdf_string_from_annot_typer  r  pdf_is_namer  )r&   rb  cr  its   &    r'   r   
Annot.type,  s     	Dyy###$$TYY/,,U3!4!4TYY!?F|||u0033:q!"~r)   c               <    V ^8  d   QhRRRRRRRRRR	R
R	RR	RRRR/	# )r  r^  OptStrr]  OptFloatr   r  r   r   OptSeqborder_colorr_  	cross_outr   r`  r6   r,   )formats   "r'   __annotate__Annot.__annotate__:  sm     {* {*{*{* {* 	{*
 {* !{* {* {* {*r)   c
                x   \         P                  ! V P                  4      p
V'       d4   \         P                  ! V
\	        R4      4      pV'       g   \        R4      h\        P                  4        \        V 4       R pV P                  ^ ,          pV P                  P                  RR4      pV P                  P                  RR'4      pV P                  R,          pVe   TpMV P                  R,          pRpV P                  pV	R'8w  dJ   V	^ 8  d   V	R	,          p	K  V	R	8  d   V	R	,          p	K  V\         P                  8X  d   V	^Z,          ^ 8w  d   ^ p	Vf   V P                  p\!        VR
4      '       g   V P"                  p^ Tu;8:  d   ^8  g   M V'       d   RpMRpV\         P                  8X  dp   \%        V4       \%        V4       \&        P)                  V 4      w  pppV^ 8:  d   ^pV'       d   TpV'       d   TpV^ 8  d   Tp\+        V \-        V4      VVV4       RpV P/                  VVVV	R7      pVRJ d   \1        R4      hV\         P                  8X  dU   V P3                  4       p^ Tu;8:  d   ^8  d4   M R# VP5                  R4      '       g   V P7                  RV,           4       R# V! VR4      pV! VR4      pV P9                  4       P:                  pV( pV'       d@   RRP=                  \?        \@        V4      4      ,           R,           pVPC                  R4      pMRpV PD                  '       d   V PD                  w  pp M^ ^ p pV P3                  4       pVPG                  4       p!Rp"V\         PH                  8X  Ed!   V'       dv   Rp"V!RR' p!V!w  p#p$p%p&p'V!PK                  V%4       V!PK                  V$4       V!PK                  V&4       V!PK                  V$4       V!PK                  V'4       V!PK                  R4       V^ 8  g   VR8w  d   Rp"V^ 8  d"   \M        V4      PC                  4       R,           .M. p(V! FP  p)V)PO                  R4      '       d   K  V)PO                  R4      '       d   VR8w  d   VRR' p)V(PK                  V)4       KR  	  T(p!RP=                  V!4      pV\         PP                  \         PR                  39   d   RP=                  V!RR' 4      R,           pRp"VR8w  dF   V\         PP                  8X  d   VV,           R,           pM\V\         PR                  8X  d
   VR,           pM=V\         PP                  8X  d   VR ,           pMV\         PR                  8X  d
   VR,           pVe   VV,           pVPU                  R!R"^4      pRp"V'       d   VPC                  R4      V,           pRp"R#V,           R$,           pVV ,           ^ 8  Ed   V\         PP                  \         PR                  39   Ed   R\&        PV                  \&        PX                  \&        PZ                  \&        P\                  \&        P^                  \&        P`                  \&        Pb                  \&        Pd                  \&        Pf                  3
p*\i        ^\-        V*4      4      p+^\k        ^V P                  R,          4      ,          p,V Pl                  V,) V,) V,V,3,           pRp"V Pn                  p-VV+9   d]   \q        V-^ ,          4      V,          p.\q        V-^,          4      V,          p/V*V,          ! V V.V/RV4      p0VV0PC                  4       ,          pV V+9   d]   \q        V-R(,          4      V,          p.\q        V-R',          4      V,          p/V*V ,          ! V V.V/RV4      p0VV0PC                  4       ,          pV"'       dA   V'       d&   V Ps                  V4       V P7                  V^R%7       MV P7                  V^ R%7       V\         Pt                  \         Pv                  \         Px                  \         Pz                  \         P|                  \         PR                  \         PP                  \         P~                  \         P                  \         P                  3
9  d   R# V P                  p1V1R'8X  d   R# V Pl                  P                  V Pl                  P                  ,           ^,          p2V1^ 8X  dy   \        V\        ^^4      ,
          4      R&8  d   R# V Pl                  P                  V2V( 4      p3V P                  V3Pl                  4       V P                  \        ^^4      4       R# \        V14      p4V Pl                  P                  V2V44      p3V Ps                  V3Pl                  4       V P                  VV4,          4       R# ))a  Update annot appearance.

Notes:
    Depending on the annot type, some parameters make no sense,
    while others are only available in this method to achieve the
    desired result. This is especially true for 'FreeText' annots.
Args:
    blend_mode: set the blend mode, all annotations.
    opacity: set the opacity, all annotations.
    fontsize: set fontsize, 'FreeText' only.
    fontname: set the font, 'FreeText' only.
    border_color: set border color, 'FreeText' only.
    text_color: set text color, 'FreeText' only.
    fill_color: set fill color, all annotations.
    cross_out: draw diagonal lines, 'Redact' only.
    rotate: set rotation, 'FreeText' and some others.
RC-cannot set border_color if rich_text is Falsec                Z    \        W4      pV'       g   R# VR,           P                  4       # )zHReturn valid PDF color operator for a given color sequence.
            r)   r#   )	ColorCodeencode)r  codeccs   && r'   color_string"Annot.update.<locals>.color_string^  s'     2$BI%%''r)   r  Nr  r  r   r  r  /H gs
r`   )r]  r^  r_  r`  FzError updating annotation.s   /H gss   /H gs
fr  r  r   z] 0 d
utf-8T   Sr)   s    w   ws   RG   
   b   ss   
S
s
   
S
[] 0 d
   q
s   
Q
r   h㈵>r  )Jr   r  r   r  r  r   r   update_timing_testro  r   r  r:   r  r  rK  r  r=   r]  r  r  r  JM_make_annot_DAr9   rl  r   r(  r5   r7  rs  rt  joinmapr  r  rQ  
splitlinesr  ro   r   endswithrG  rF  replace
_le_square
_le_circle_le_diamond_le_openarrow_le_closedarrow_le_butt_le_ropenarrow_le_rclosedarrow	_le_slashrS  maxr   verticesPointr  rJ  rD  rL  rM  rE  rC  rN  rO  ru  tlbrabsr  morphsetRectr~  )5r&   r^  r]  r   r   r   r  r_  r  r`  r&  is_rich_textr	  
annot_typedtbwidthr  r   r   apnmatopa_codetcolfnamefsizer  r'  bfillbstrokep_ctmimatr  line_end_leline_end_riap_tab
ap_updated_LLLRURULntabrs   le_funcsle_funcs_rangedpointsp1p2leftry  r-  quadr  s5   &&&&&&&&&&                                           r'   updateAnnot.update:  s   8 ''		2	 --i$HL !PQQ  "D	( YYq\
[[__Xt,"-X&!D;;v&DR<1*#C-#U6666B;!;K
 Jw,,llG!z HH222z"z"!&!6D% z! !| T3t9dE5AJ
 %%!	 & 
 %<;<<222BGa )+h(?(?JO,T3'vs+!77v388CRL11I=F]]7+FF>>>'+~~$K'(!K [[]
///!
$*!2r2rb!b!b!b!b!d#zW^!
?Ez	&)002U:;r"D}}T** }}U++3&s|KK% # F#B%1153L3LMMF3BK(50BJ|!8!88ed*B5#<#<<dB!8!88dB5#<#<<dB"BH&6:BJ)B.BJb[8# $q(ZE<S<SUZUnUn;o-oe..0@0@))5+>+>--u~~,,e.D.D	)H
 #1c(m4NC4;;w/00A99QB1~-DJ]]Fn,6!9%,6!9%,,T2r5*Mdkkm#n,6":&-6":&-,T2r4Ldkkm#d#BQ'BQ'
 %%&&//##$$))''&&%%$$  mm"9YY\\DIILL(A-!86F1aL()D099??1vg.DLL#q!-Skyyq#&dii FSL)r)   c                   \        V 4       V P                  p\        P                  ! V4      p\        P                  ! V4      p\        P
                  ! V4      pV\        P                  8w  d   \        \        4      h\        P                  ! V\        R4      \        R4      \        R4      4      p	V	P                  '       g   \        R\        4       \        P                  ! V\        R4      4      p
\        V4      pV'       d"   VP                  '       g   \!        \"        4      hV'       d   \%        WyV^4       \        P&                  ! V4      w  r\        P(                  ! V4      p\        P*                  ! V	\        R4      V4       \        P,                  ! W\        R4      \        R4      4       V'       d   \        P.                  ! V	\        R4      V4       \        P.                  ! V
\        R4      V4       \        P.                  ! V	\        R4      V4       \        P.                  ! V
\        R4      V4       \        P.                  ! V\        R	4      V4       V'       dC   \        P.                  ! V	\        R4      V4       \        P.                  ! V
\        R4      V4       V'       dE   \        P.                  ! V	\        R
4      V4       \        P.                  ! V
\        R
4      V4       R# R# )zUpdate attached file.r  r  r  bad PDF: no /EF objectDLr  r  r  Contentsr  N)ro  r   r   r  r  r  rL  r  r  r   r  r   r  r  r  r.  r   r/  r0  fz_buffer_storagepdf_new_intrU  pdf_dict_putlr  )r&   r4  rj   	ufilenamer  r   r&  ra  r   r   r  r%  r9   r@  ls   &&&&&          r'   update_fileAnnot.update_file7  s   D		''.	**95##E*5222/00$$YPXY\P]^   -/CD	8D>: !)3>>>n--S#q1,,S1FC!!#&Avx~q98H+=x?OP**68C=(K**2x}hG**68D>8L**2x~xH**9hz6JHU**68D>9M**2x~yI**68F3CTJ**2x/?F r)   c                 	>    ^ p \        R4       F  pW,          p K  	  V # )rx   i0u  )rS  )totalrg  s     r'   r  Annot.update_timing_testb  s!    AJE !r)   c           	     Z   \        V 4       V P                  p\        V\        P                  4      '       g   Q h\        P
                  ! V4      p\        V4      p\        P                  ! 4       p\        P                  ! 4       p\        P                  ! W5V4       \        V4      p\        P                  ! WF4      p\        P                  ! V\        R4      4      pVP                  '       g!   \        P                  ! V\        R4      4      pVP                  '       g!   \        P                  ! V\        R4      4      pVP                  '       g   \        P                  ! VR4      pVP                  '       d   . p\!        ^ \        P"                  ! V4      ^4       F  p	\        P$                  ! \        P&                  ! Wy4      4      p
\        P$                  ! \        P&                  ! Wy^,           4      4      p\        P(                  ! W4      p\        P*                  ! W4      pVP-                  VP.                  VP0                  34       K  	  V# \        P                  ! VR4      pVP                  '       Ed,   . p\!        \        P"                  ! V4      4       EF  p	. p\        P&                  ! Wy4      p\!        ^ \        P"                  ! V4      ^4       F  p\        P$                  ! \        P&                  ! W4      4      p
\        P$                  ! \        P&                  ! W^,           4      4      p\        P(                  ! W4      p\        P*                  ! W4      pVP-                  VP.                  VP0                  34       K  	  VP-                  V4       EK  	  V# R# )zannotation vertex pointsVerticesL
QuadPointsCLInkListN)ro  r   r@   r   r   r  r   r|  rq  pdf_page_transformJM_derotate_page_matrix	fz_concatr  r  r   r  rS  r  r  r  FzPointfz_transform_pointro   xy)r&   r   r&  r   page_ctmdummyderotr  r%  rg  ri  rj  pointres1o1r  s   &               r'   r(  Annot.verticesi  s    	D		%0000''.	u%>>#  h7'-??83 y(:*>?|||E$6$6y(3-$P|||E$6$6y(<BX$Y|||E$7$7	4$H<<< C1e11!4a8%%e&9&9!&?@%%e&9&9!qS&ABa+00A

UWWegg./ 9 J	95<<< C5..q12((.q%"5"5b"91=A))%*=*=b*DEA))%*=*=bA#*FGA!MM!/E!44UEEKK%''577!34 > 

4  3 J r)   c                    \        V 4       V P                  p\        P                  ! \        P                  ! V4      4      # )zannotation xref number)ro  r   r   r  r  r   s   & r'   r  
Annot.xref  s1     	D		 3 3E :;;r)   r   r   r   rx   )r  NNr  r  )NNNrx   Nrx   )Nr  NNr  NNNNNNNNNr+   )	NNrx   NNNNTr  NNNN)Er/   r0   r1   r2   r   r   r   r   r   r  r(  r7  rl  propertyrv  r  r  r  r  r  r  r  r  r  r  rs  r  r  r  r  r$  r'  r8  r=  rA  rI  rQ  r]  r]  re  rh  r   rq  ru  rz  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   rN  rY  staticmethodr  r(  r  r3   r,   r)   r'   r   r   J  s   :!%N&9(aF     .  >  $= 	 	G6 / /b , ,	(@58& 1 1  B 	& 	& 2 2
 9 9 	 	  2    $ 	 	  &   + +<"	?G-<^'1R0l<= 7<CU
"4	, C<  {*z)GV   3 3j < <r)   r   c                  z    ] tR tRtR tR tRR ltRR ltRR ltRR lt	RR	 lt
RR
 lt]R 4       tR tR tRtR# )Archivei  c                    \        4       V n        \        P                  ! 4       V n        V'       d   V P
                  ! V!   R# R# )z
Archive(dirname [, path]) - from folder
Archive(file [, path]) - from file name or object
Archive(data, name) - from memory item
Archive() - empty archive
Archive(archive [, path]) - from archive
N)r   _subarchivesr   fz_new_multi_archiver   addr&   r  s   &*r'   r   Archive.__init__  s2     !F..0	HHt r)   c                	2    R \        V P                  4       2# )zArchive, sub-archives: )r9   r  r-   s   &r'   r   Archive.__repr__  s    (T->->)?(@AAr)   Nc                	H    \         P                  ! V P                  W4       R # r+   )r   fz_mount_multi_archiver   )r&   subarchr   s   &&&r'   	_add_archArchive._add_arch  s    $$dii?r)   c                	t    \         P                  ! V4      p\         P                  ! V P                  W24       R # r+   )r   fz_open_directoryr  r   )r&   folderr   subs   &&& r'   _add_dirArchive._add_dir  s&    %%v.$$dii;r)   c                	    \        V4      p\        P                  ! \        P                  ! 4       4      p\        P                  ! WRV4       \        P
                  ! V P                  WS4       R # r+   )r.  r   fz_new_tree_archiveFzTreefz_tree_archive_add_bufferr  r   )r&   memoryr   r   buffr  s   &&&&  r'   _add_treeitemArchive._add_treeitem  sF    !6*''8((#T:$$dii;r)   c                	    V^8X  d   \         P                  ! V4      pM\         P                  ! V4      p\         P                  ! V P                  WC4       R# r  N)r   fz_open_zip_archivefz_open_tar_archiver  r   )r&   filepathrb  r   r  s   &&&& r'   _add_ziptarfileArchive._add_ziptarfile  s=    A:++X6C++X6C$$dii;r)   c                	    \        V4      p\        P                  ! V4      pV^8X  d   \        P                  ! V4      pM\        P                  ! V4      p\        P
                  ! V P                  Wc4       R# r  )r.  r   fz_open_bufferfz_open_zip_archive_with_streamfz_open_tar_archive_with_streamr  r   )r&   r  rb  r   r  r   r  s   &&&&   r'   _add_ziptarmemoryArchive._add_ziptarmemory  sW    !6*%%t,!877@C77@C$$dii;r)   c                N	  a  R pV 3R lp\        V\        P                  4      '       d   \        V4      p\        V\        4      '       Ed   \        P
                  P                  V4      '       d0   S P                  W4       V! \        P                  ! V4      VR4      # \        P
                  P                  V4      '       d   \        V\        4      '       d   VR8w  g   Q RV: R24       h\        P                  ! VR4      ;_uu_ 4       pVP                  4       pRRR4       S P                  XV4       V! V.RR	4      # \        R
V: 24      hV! V4      '       dA   \        V\        4      '       d   VRV: R28w  g   Q hS P                  W4       V! V.RR	4      # \        V\        P                   4      '       dk   \#        VRR4      pVf/   VP$                  P'                  4       pS P)                  V^V4       MS P+                  V^V4       V! VP-                  4       VR4      # \        V\.        P0                  4      '       d   \#        VP2                  RR4      pVf[   VP2                  p\        V\        P4                  4      '       g   VP2                  pS P)                  VP'                  4       ^ V4       MS P+                  V^ V4       V! VP7                  4       VR4      # \        V\8        4      '       d   S P;                  W4       V! . VR4      # \        V\<        4      '       Ed   \?        V4      ^8X  d   Vw  r\        V
\        4      '       g   Q R\A        V
4      : 24       hV! V	4      '       d   S P                  WVR7       M\        V	\        4      '       dr   \        P
                  P                  V	4      '       dL   \        P                  ! V	R4      ;_uu_ 4       pVP                  4       pRRR4       S P                  XWR7       MQ R\A        T	4      : R24       hV! V
.VR	4      # \C        VR4      '       d   V F  pS PE                  W4       K  	  R# \G        R\A        V4       R24      h  + '       g   i     ELj; i  + '       g   i     L; i)a9  
Add a sub-archive.

Args:
    content:
        The content to be added. May be one of:
            `str` - must be path of directory or file.
            `bytes`, `bytearray`, `io.BytesIO` - raw data.
            `zipfile.Zipfile`.
            `tarfile.TarFile`.
            `pymupdf.Archive`.
            A two-item tuple `(data, name)`.
            List or tuple (but not tuple with length 2) of the above.
    path: (str) a "virtual" path name, under which the elements
        of content can be retrieved. Use it to e.g. cope with
        duplicate element names.
c                L    \        V \        \        \        P                  34      # r+   )r@   r  	bytearrayr;   BytesIOri  s   &r'   is_binary_data#Archive.add.<locals>.is_binary_data  s    a%BJJ!?@@r)   c                  < \        W VR 7      pVR8w  g   SP                  . 8X  d   SP                  P                  V4       R# SP                  R,          pVR,          R8w  g   VR,          VR,          8w  d   SP                  P                  V4       R# VR,          P                  VR,          4       VSP                  R&   R# ))r   entriesr   treer   r   r  Nr  )r7   r  ro   extend)r  mountr   r  ltreer&   s   &&&  r'   make_subarch!Archive.add.<locals>.make_subarch  s    s%@Gf} 1 1R 7!!((1))"-<6)U6]gfo-M%%,,W5)$++GI,>?,1D%%b)r)   dirr`   z'Need name for binary content, but path=r   rbNr  zNot a file or directory: rj   zipr   tarmultizUnexpected type(name)=)r   zUnexpected type(data)=r  zUnrecognised type )$r@   pathlibPathr  rh   r   isdirr  listdirisfiler;   r<   readr  r   zipfileZipFiler   fpgetvaluer  r  namelisttarfileTarFilefileobjr  getnamesr~  r  r   r9   r   r=   r  r  )r&   r  r   r  r  r  ffrj   r  datar   rE   s   f&&         r'   r  Archive.add  s   $	A
	2 gw||,,'lGgs##ww}}W%%g,#BJJw$7uEE((!$,, FBTG1EF;WWWd++qB ,""2t,#TFD&99 #<WK!HIIG$$dC((T 6?9=q6B .B B Bw-f5511w
D9HZZ((*&&r1d3$$Xq$7 0 0 2D%@@11w=H__!"bjj11B&&r{{}a>$$Xq$7 0 0 2D%@@))NN7)D'22gu%%#g,!*; JDdC((E,CT
}*EE(d##""4D"9D#&&77>>$''t,,VVX -&&r4&;63T
}A66qf55Wm,,$   0gqABBw ,++Z -,s   R -R R	R$	c                    V P                   # )z
List of sub archives.
)r  r-   s   &r'   
entry_listArchive.entry_list>  s    
    r)   c                	D    \         P                  ! V P                  V4      # r+   )r   fz_has_archive_entryr   r&   r   s   &&r'   	has_entryArchive.has_entryE  s    ))499d;;r)   c                	Z    \         P                  ! V P                  V4      p\        V4      # r+   )r   fz_read_archive_entryr   r#  )r&   r   r  s   && r'   
read_entryArchive.read_entryH  s#    **DIIt<&&r)   )r  r   r+   )r/   r0   r1   r2   r   r   r  r  r  r  r  r  r{  r  r  r  r3   r,   r)   r'   r~  r~    sL    B@<<<<gR ! !<'r)   r~  c                  V   ] tR tRtR tR tR tR tR tR t	RJR	 lt
R
 tR tR tRKR ltR tRLR ltRJR ltR tRMR ltR tR tR tRJR ltRJR ltR tR tR tR tR t]R 4       tR t R t!R  t"R! t#R" t$]%R# 4       t&R$ t'R% t(R& t)R' t*R( t+]%R) 4       t,]%R* 4       t-]%R+ 4       t.]%R, 4       t/]%R- 4       t0R. t1R/ t2]%R0 4       t3R1 t4R2 t5R3 t6RNR4 lt7R5 t8R6 t9R7 t:R8 t;R9 t<RNR: lt=R; t>R< t?R= t@R> tAR? tBR@ tCRA tDRORB ltERC tFRPRD ltGRE tHRF tI]%RG 4       tJ]%RH 4       tK]
tL]
tM]
tNRItOR# )QXmliM  c                	    V # r+   r,   r-   s   &r'   	__enter__Xml.__enter__O      r)   c                	    R # r+   r,   r  s   &*r'   __exit__Xml.__exit__R      r)   c                	
   \        V\        P                  4      '       d	   Wn        R# \        V\        4      '       d4   \        P
                  ! V4      p\        P                  ! V4      V n        R# Q R\        T4       24       h)rx   zUnsupported type for rhs: N)r@   r   FzXmlr   r  fz_new_buffer_from_copied_datafz_parse_xml_from_html5r   )r&   rhsr  s   && r'   r   Xml.__init__U  s]    c5;;''IS!!77<D55d;DI>249+>>1r)   c                	.   a V3R  lo^ p. pS! WV4      pV# )c           	       < V e   V P                   '       d0   VP                  VRV P                   R234       V P                  p KE  VP                  VRV P                   234       V P                  4       P                  4        F  w  r4VP                  VRV RV R234       K!  	  V P                  pV'       d   S! WQV^,           4      pVP                  VRV P                   234       V P                  p K  V# )N"(r   z 'r   ))is_textro   r   r]  tagnameget_attributesrD   first_child)noderD   shiftkrH   child	show_nodes   &&&   r'   r  %Xml._get_node_tree.<locals>.show_node_  s    "<<<LL%1TYYKq)9!:;99Deq%789 //1779DALL%1QCr!A!78 :((%eEAI>Eeq%789yyLr)   r,   )r&   r  rD   r  s   &  @r'   _get_node_treeXml._get_node_tree^  s%    	  $u-r)   c                J    V P                  R4      pV P                  V4       V# )zAdd bulleted list ("ul" tag)ulcreate_elementappend_childr&   r  s   & r'   add_bullet_listXml.add_bullet_listt  %    ##D)% r)   c                    V P                  R4      pVe	   W9   d   V # V P                  R4       Vf   TpMVRV,           ,          pV P                  RV4       V # )z5Set some class via CSS. Replaces complete class spec.classr   get_attribute_valueremove_attributeset_attribute)r&   r   clss   && r'   	add_classXml.add_classz  s[    &&w/?t{Kg&;C3:C7C(r)   Nc                    V P                  R4      p\        V4      \        J d!   VP                  V P	                  V4      4       V P                  4       pVf   T pVP                  V4       V # )zAdd a "code" tagr  r  r   r  r  create_text_nodespan_bottomr&   r   r  prevs   &&  r'   add_codeXml.add_code  sb    ##F+:t44T:;!<D% r)   c                J    V P                  R4      pV P                  V4       V# )z!Add monospaced lines ("pre" node)prer  r  s   & r'   add_codeblockXml.add_codeblock  %    ##E*% r)   c                J    V P                  R4      pV P                  V4       V# )zAdd description list ("dl" tag)dlr  r  s   & r'   add_description_listXml.add_description_list  r  r)   c                J    V P                  R4      pV P                  V4       V# )zAdd "div" tagdivr  r  s   & r'   add_divisionXml.add_division  r  r)   c                    V\        ^^4      9  d   \        R4      hV P                  pRV 2pV P                  V4      pVR9  d   V P	                  V4       V# V P
                  P	                  V4       V# )zAdd header tagzHeader level must be in [1, 6]h)h1h2h3h4h5h6r  )rS  r   r  r  r  r   )r&   r   this_tagnew_tagr  s   &&   r'   
add_headerXml.add_header  ss    a#=>><<eW+##G,DDe$L  'r)   c                J    V P                  R4      pV P                  V4       V# )zAdd horizontal line ("hr" tag)hrr  r  s   & r'   add_horizontal_lineXml.add_horizontal_line  r  r)   c                ,   V P                  R4      pVe   VP                  RV 4       Ve   VP                  RV 4       Ve   VP                  RRV 24       Ve   VP                  RV 4       VP                  RV 4       V P                  V4       V# )zAdd image node (tag "img").imgr  heightr  zfloat: r  src)r  r  r  )r&   r   r  r3  imgfloatr  r  s   &&&&&& r'   	add_imageXml.add_image  s    ##E*E74VH678*)=>E74EdV-% r)   c                
   V P                  R4      p\        V\        4      '       g   TpVP                  RV4       VP	                  V P                  V4      4       V P                  4       pVf   T pVP	                  V4       V # )zAdd a hyperlink ("a" tag)r   href)r  r@   r  r  r  r  r  )r&   r9  r   r  r  s   &&&  r'   add_linkXml.add_link  sx    ##C($$$DFD)40067!<D% r)   c                    V P                   R9  d   \        RV P                   4      hV P                  R4      pV P                  V4       V# )z8Add item ("li" tag) under a (numbered or bulleted) list.zcannot add list item toli)olr  )r  r   r  r  r  s   & r'   add_list_itemXml.add_list_item  sC    <<|+6EE##D)% r)   c                    V P                  R4      pV^8  d   VP                  R\        V4      4       Ve   VP                  RV4       V P                  V4       V# )zAdd numbered list ("ol" tag)r>  r  r   )r  r  r  r  )r&   r  numtyper  s   &&& r'   add_number_listXml.add_number_list  sV    ##D)19U40% r)   c                    V P                  R4      pV P                  R8w  d   V P                  V4       V# V P                  P                  V4       V# )zAdd "p" tagr  )r  r  r  r   r  s   & r'   add_paragraphXml.add_paragraph  sL    ##C(<<3e$  KK$$U+r)   c                	J    V P                  R 4      pV P                  V4       V# spanr  r  s   & r'   add_spanXml.add_span  s%    ##F+% r)   c                    V P                  R4      pVe	   W9   d   V # V P                  R4       Vf   TpMVRV,           ,          pV P                  RV4       V # )z;Set some style via CSS style. Replaces complete style spec.r  ;r  )r&   r   r  s   && r'   	add_styleXml.add_style  s\    ((1Kg&=ES4ZE7E*r)   c                    V P                  R4      p\        V4      \        J d!   VP                  V P	                  V4      4       V P                  4       pVf   T pVP                  V4       V # )zAdd a subscript ("sub" tag)r  r  r  s   &&  r'   add_subscriptXml.add_subscript 	  b    ##E*:t44T:;!<D% r)   c                    V P                  R4      p\        V4      \        J d!   VP                  V P	                  V4      4       V P                  4       pVf   T pVP                  V4       V # )zAdd a superscript ("sup" tag)supr  r  s   &&  r'   add_superscriptXml.add_superscript	  rT  r)   c                .   VP                  4       p\        V4      pV P                  4       pVf   T p\        V4       FT  w  rVVP	                  V P                  V4      4       WS^,
          8  g   K4  VP	                  V P                  R4      4       KV  	  V # )z"Add text. Line breaks are honored.r+  )r  r9   r  	enumerater  r  r  )r&   r   lines
line_countr  rg  rs   s   &&     r'   add_textXml.add_text	  s    !Z
!<D 'GAd33D9:>!!!$"5"5d";< ( r)   c                	\    \         P                  ! V P                  VP                  4       R # r+   )r   fz_dom_append_childr   r  s   &&r'   r  Xml.append_child$	  s    !!499ejj9r)   c                	    V P                  R 4      pVP                  V4       V P                  4       pVf   T pVP                  V4       V# rI  )r  rO  r  r  )r&   r  rJ  r  s   &&  r'   append_styled_spanXml.append_styled_span'	  sI    ""6*u!<D$r)   c                	T    \        \        P                  ! V P                  4      4      # r+   )r  r   fz_dom_bodyr   r-   s   &r'   bodytagXml.bodytag0	  s    E%%tyy122r)   c                	X    \         P                  ! V P                  4      p\        V4      # r+   )r   fz_dom_cloner   r  r&   rI   s   & r'   clone	Xml.clone3	  s       $)),Cyr)   c                	    \        V 4      \        J d   V # \        V 4      \        J d   R \        V 4       R2# \        V 4      \        \
        39   d   R\	        V 4       2# V # )zrgb(r  r  )r   r  r6   sRGB_to_rgbr   r   )colors   &r'   
color_textXml.color_text7	  sZ    ;#L;#+e,-Q//;5$-'u''r)   c                	V    \        \        P                  ! V P                  V4      4      # r+   )r  r   fz_dom_create_elementr   )r&   tags   &&r'   r  Xml.create_elementA	  s    E//C@AAr)   c                	V    \        \        P                  ! V P                  V4      4      # r+   )r  r   fz_dom_create_text_noder   )r&   r   s   &&r'   r  Xml.create_text_nodeD	  s    E11499dCDDr)   c                    V P                  4       pV F:  p\        RV^ ,          ,          V^,          P                  RR4      ,           4       K<  	  R# )z)Print a list of the node tree below self.z  r#   \nN)r  rv   r  )r&   rD   rE   s   &  r'   debug	Xml.debugG	  s>    ##%DD47NT!W__T5%AAB r)   c                	    \         P                  ! V P                  WV4      pVP                  '       d   \	        V4      # R # r+   )r   fz_dom_findr   r   r  r&   ru  attmatchrI   s   &&&& r'   r   Xml.findM	  s2    Ce<>>>9 r)   c                	    \         P                  ! V P                  WV4      pVP                  '       d   \	        V4      # R # r+   )r   fz_dom_find_nextr   r   r  r  s   &&&& r'   	find_nextXml.find_nextR	  s2    $$dii5A>>>9 r)   c                	    \         P                  ! V P                  4      '       d   R # \         P                  ! V 4      pVP                  '       d   \        V4      # R # r+   )r   fz_xml_textr   fz_dom_first_childr   r  rk  s   & r'   r  Xml.first_childW	  sB    dii((&&->>>9 r)   c                	X    V'       g   Q h\         P                  ! V P                  V4      # r+   )r   fz_dom_attributer   r&   keys   &&r'   r  Xml.get_attribute_value`	  s     
s%%tyy#66r)   c                	    \         P                  ! V P                  4      '       d   R # \        4       p^ p \         P                  ! V P                  V4      w  r4V'       d	   V'       g    V# W1V&   V^,          pKF  r+   )r   r  r   r7   fz_dom_get_attribute)r&   resultrg  r  r  s   &    r'   r  Xml.get_attributesd	  sb    dii((11499a@HCc  CLFAr)   c                	\    \         P                  ! V P                  VP                  4       R # r+   )r   fz_dom_insert_afterr   r&   r  s   &&r'   insert_afterXml.insert_afterr	  s    !!499dii8r)   c                	\    \         P                  ! V P                  VP                  4       R # r+   )r   fz_dom_insert_beforer   r  s   &&r'   insert_beforeXml.insert_beforeu	  s    ""DIItyy9r)   c                	   VP                  4       p\        V4      p\        V4       FT  w  rEV P                  V P	                  V4      4       WC^,
          8  g   K4  V P                  V P                  R4      4       KV  	  V # )r  r+  )r  r9   rZ  r  r  r  )r&   r   r[  r\  rg  rs   s   &&    r'   insert_textXml.insert_textx	  sk    !Z
 'GAd33D9:>!!!$"5"5d";< ( r)   c                    V P                   RJ# )zCheck if this is a text node.Nru   r-   s   &r'   r  Xml.is_text	  s     yy$$r)   c                \    V P                   pVf   R#  VP                  pV'       g   V# TpK  )zReturn last child node.N)r  r]  )r&   r  r]  s   &  r'   
last_childXml.last_child	  s0       =::DEr)   c                	    \         P                  ! V P                  4      pVP                  '       d   \	        V4      # R # r+   )r   fz_dom_nextr   r   r  rk  s   & r'   r]  Xml.next	  s.    +>>>9 r)   c                	    \         P                  ! V P                  4      pVP                  '       d   \	        V4      # R # r+   )r   fz_dom_parentr   r   r  rk  s   & r'   r   
Xml.parent	  s.    !!499->>>9 r)   c                	    \         P                  ! V P                  4      pVP                  '       d   \	        V4      # R # r+   )r   fz_dom_previousr   r   r  rk  s   & r'   previousXml.previous	  s.    ##TYY/>>>9 r)   c                	F    \         P                  ! V P                  4       R # r+   )r   fz_dom_remover   r-   s   &r'   remove
Xml.remove	  s    TYY'r)   c                	\    V'       g   Q h\         P                  ! V P                  V4       R # r+   )r   fz_dom_remove_attributer   r  s   &&r'   r  Xml.remove_attribute	  s    
s%%tyy#6r)   c                	T    \        \        P                  ! V P                  4      4      # r+   )r  r   fz_xml_rootr   r-   s   &r'   rootXml.root	  s    E%%tyy122r)   c                    \        V\        4      '       d   TpMGV\        8X  d   RpM9V\        8X  d   RpM+V\        8X  d   RpMV\
        8X  d   RpM\        RV: 24      hV P                  RV 24       V # )z Set text alignment via CSS stylerL  centerrightjustifyzUnrecognised align=ztext-align: )r@   r  TEXT_ALIGN_LEFTTEXT_ALIGN_CENTERTEXT_ALIGN_RIGHTTEXT_ALIGN_JUSTIFYr   rO  )r&   r  ts   && r'   	set_alignXml.set_align	  sv    uc""Ao%A''A&&A((A3UH566aS)*r)   c                	\    V'       g   Q h\         P                  ! V P                  W4       R # r+   )r   fz_dom_add_attributer   )r&   r  r   s   &&&r'   r  Xml.set_attribute	  s    
s""DIIs:r)   c                L    V P                  RV P                  V4       24       V # )z"Set background color via CSS stylezbackground-color: )rO  rq  r&   rp  s   &&r'   set_bgcolorXml.set_bgcolor	  s%    +DOOE,B+CDEr)   c                H    V'       d   RpMRpV P                  RV 24       V # )zSet bold on / off via CSS styleboldnormalzfont-weight: rc  r&   r  s   &&r'   set_boldXml.set_bold	  s)    CC-u 56r)   c                L    V P                  RV P                  V4       24       V # )zSet text color via CSS stylezcolor: )rc  rq  r  s   &&r'   	set_colorXml.set_color	  s&    '$//%*@)A BCr)   c                .    V P                  RV 24       V # )z(Set number of text columns via CSS stylez	columns: r  )r&   colss   &&r'   set_columnsXml.set_columns	  s    )D6 23r)   c                .    V P                  RV 24       V # )z"Set font-family name via CSS stylezfont-family: r  )r&   fonts   &&r'   set_fontXml.set_font	  s    -v 67r)   c                f    \        V4      \        J d   RpMRpRV V 2pV P                  V4       V # )z Set font size name via CSS styler`   pxzfont-size: )r   r  rc  )r&   r   r  r   s   &&  r'   set_fontsizeXml.set_fontsize	  s;    >S BBXJrd+%r)   c                    V P                   pVP                  RRV4      '       d   \        RV R24      hV P                  RV4       V # )zSet a unique id.NrY  zid 'z' already exists)r  r   r   r  )r&   uniquer  s   && r'   set_id
Xml.set_id	  sJ     yy99T4((tF8+;<==4(r)   c                H    V'       d   RpMRpV P                  RV 24       V # )z!Set italic on / off via CSS styleitalicr  zfont-style: r  r  s   &&r'   
set_italicXml.set_italic	  s)    CC,se 45r)   c                .    V P                  RV 24       V # )z>Set inter-line spacing value via CSS style - block-level only.z-mupdf-leading: rO  )r&   leadings   &&r'   set_leadingXml.set_leading	  s    )'34r)   c                .    V P                  RV 24       V # )z,Set inter-letter spacing value via CSS stylezletter-spacing: r  r&   spacings   &&r'   set_letter_spacingXml.set_letter_spacing
  s    "27) <=r)   c                .    V P                  RV 24       V # )z6Set line height name via CSS style - block-level only.zline-height: r  )r&   
lineheights   &&r'   set_lineheightXml.set_lineheight
  s    zl34r)   c                .    V P                  RV 24       V # )zSet margin values via CSS stylez	margins: r  r  s   &&r'   set_marginsXml.set_margins
  s    )C5 12r)   c                .    V P                  RV 24       V # )zSet opacity via CSS stylez	opacity: r  )r&   r]  s   &&r'   r  Xml.set_opacity
  s    )G9 56r)   c                (    V P                  R4       V # )z$Insert a page break after this node.zpage-break-after: alwaysr  r-   s   &r'   set_pagebreak_afterXml.set_pagebreak_after
  s    12r)   c                (    V P                  R4       V # )z%Insert a page break before this node.zpage-break-before: alwaysr  r-   s   &r'   set_pagebreak_beforeXml.set_pagebreak_before
  s    23r)   c                d   V P                   pVP                  4       pVe   VP                  V4       Ve   VP                  V4       Ve   VP	                  V4       Ve   VP                  V4       Ve   VP                  V4       Ve   VP                  V4       Ve   VP                  V4       Ve   VP                  V4       V	e   VP                  V	4       V
e   VP                  V
4       Ve   VP                  V4       Ve   VP                  V4       Ve   VP                  V4       Ve   VP                  4        Ve   VP!                  4        Ve   VP#                  V4       Ve   V P%                  V4       Ve   V P'                  V4       . pVP)                  R4      pVe   VP+                  V4       VP,                  pV'       d/   VP+                  VP)                  R4      4       VP,                  pK6  V P/                  RRP1                  V4      4       VP3                  4        V # )zPSet any or all properties of a node.

To be used for existing nodes preferably.
r  rN  )r  r  r  r  r  r  r  r  r  set_text_indentr  r  r  r  r  r  r  set_word_spacingr  r
  r  ro   r  r  r  r  )r&   r  bgcolorr  rp  columnsr  r   indentr  r  letter_spacingr  marginspagebreak_afterpagebreak_beforeword_spacingunqidr	  r  tempstyles	top_styler  s   &&&&&&&&&&&&&&&&&&&     r'   set_propertiesXml.set_properties 
  s   2 yy  "NN5!W%MM$NN5!W%MM$h'  (OOF#W%%##N3!
+W%&$$&'%%'#!!,/KK?NN3,,W5	 MM)$  MM%33G<=%%E7CHHV$45r)   c                .    V P                  RV 24       V # )z;Set text indentation name via CSS style - block-level only.ztext-indent: r  )r&   r	  s   &&r'   r  Xml.set_text_indentl
  s    vh/0r)   c                	.    V P                  R V 24       V # )ztext-decoration: r  r  s   &&r'   set_underlineXml.set_underlineq
  s    "3C5 9:r)   c                .    V P                  RV 24       V # )z*Set inter-word spacing value via CSS stylezword-spacing: r  r  s   &&r'   r  Xml.set_word_spacingu
  s    .	 :;r)   c                X   T pV P                   pVf   R# VP                  '       d   VP                  pVe   K$   Ve   VP                  R8w  d   R#  Vf   V# VP                  R9   g   VP                  '       d   VP                  pK8  VP                  R8X  d   TpVP
                  pKY  V# )z$Find deepest level in stacked spans.NrJ  )r   r  rV  body)r  r  r  r  r]  r  )r&   r   r  s   &  r'   r  Xml.span_bottomz
  s    =mmmNNE}=EMMV3}}} 99U]]]

}}&))r)   c                	B    \         P                  ! V P                  4      # r+   )r   
fz_xml_tagr   r-   s   &r'   r  Xml.tagname
  s    ++r)   c                	B    \         P                  ! V P                  4      # r+   )r   r  r   r-   s   &r'   r   Xml.text
  s      $)),,r)   r   r+   rv  rz  r  T)NNNNNNNNNNNNNNNNNN)	underline)Pr/   r0   r1   r2   r  r  r   r  r   r
  r  r  r  r  r+  r/  r6  r:  r?  rC  rF  rK  rO  rR  rW  r]  r  rc  rg  rl  r|  rq  r  r  r|  r   r  r{  r  r  r  r  r  r  r  r  r]  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   add_varadd_sampadd_kbdr3   r,   r)   r'   r  r  M  s   ?,	
		:3  BEC

  79: % % 	 	  
  
  
(7 3 3";










JX

2 , , - - GHGr)   r  c                  H    ] tR tRtR tR tR t]R 4       t]R 4       t	Rt
R# )	
Colorspacei
  c                <   \        V\        P                  4      '       d	   Wn        R# V\        8X  d6   \        P                  ! \        P                  P
                  4      V n        R# V\        8X  d6   \        P                  ! \        P                  P                  4      V n        R# V\        8X  d6   \        P                  ! \        P                  P                  4      V n        R# \        P                  ! \        P                  P                  4      V n        R# )z!Supported are GRAY, RGB and CMYK.N)
r@   r   FzColorspacer   CS_GRAY
Fixed_GRAYCS_CMYK
Fixed_CMYKCS_RGB	Fixed_RGB)r&   rb  s   &&r'   r   Colorspace.__init__
  s    ue0011Ig**5+=+=+H+HIDIg**5+=+=+H+HIDIf_**5+=+=+G+GHDI**5+=+=+G+GHDIr)   c                	L    RV P                   ,          pRV RV P                   2# )r`   zColorspace(CS_z) - )r`   GRAYr`   RGBCMYK)rG   r   r&   ri  s   & r'   r   Colorspace.__repr__
  s'    +DFF3s$tyyk22r)   c                	B    \         P                  ! V P                  4      # r+   )r   fz_colorspace_namer   r-   s   &r'   _nameColorspace._name
  s    ''		22r)   c                B    \         P                  ! V P                  4      # )zSize of one pixel.)r   fz_colorspace_nr   r-   s   &r'   rG   Colorspace.n
       $$TYY//r)   c                "    V P                  4       # )zName of the Colorspace.r=  r-   s   &r'   r   Colorspace.name
  s     zz|r)   r$  N)r/   r0   r1   r2   r   r   r=  r{  rG   r   r3   r,   r)   r'   r+  r+  
  s:    I33 0 0  r)   r+  c                      ] tR tRtR tRtR# )DeviceWrapperi
  c                	   \        V\        P                  4      '       d   Vw  pW n        R # \        V\        R 4      '       d   Vw  r4\        V4      p\        P                  ! V4      '       d2   \        P                  ! \        P                  ! 4       V4      V n        R # \        P                  ! \        P                  ! 4       W54      V n        R # \        V\        P                  4      '       d"   Vw  p\        P                  ! V4      V n        R # \        V\        P                  R 4      '       d8   Vw  rx\        P                  ! V4      p	\        P                  ! Wy4      V n        R # \        RV: 24      h)Nz%Unrecognised args for DeviceWrapper: )
args_matchr   FzDevicer   r  JM_irect_from_pyfz_is_infinite_irectfz_new_draw_devicer|  fz_new_draw_device_with_bboxFzDisplayListfz_new_list_devicer  r  fz_new_stext_devicerk   )
r&   r  devicepmr  r6  r  tpr  optss
   &*        r'   r   DeviceWrapper.__init__
  s   tU^^,,GFIvt,,HB#T*D))400!44enn6FK	!>>@PRT[	u2233CB00"5DIu00$77IB''/D112<DIDTHMNNr)   r$  Nr   r,   r)   r'   rG  rG  
  s    Or)   rG  c                  L    ] tR tRtR tR tR
R ltRR lt]R 4       t	R t
R	tR# )DisplayListi
  c                	>    \        V 4      \        J g   R # RV n        R # NF)r   rX  r   r-   s   &r'   __del__DisplayList.__del__
  s    Dz[(&r)   c                	\   \        V4      ^8X  dL   \        V^ ,          \        P                  4      '       d%   \        P                  ! V^ ,          4      V n        R# \        V4      ^8X  d8   \        V^ ,          \        P                  4      '       d   V^ ,          V n        R# Q RT: 24       h)r  zUnrecognised args=N)r9   r@   r   rq  rO  r   r  s   &*r'   r   DisplayList.__init__
  su    t9>ja%,,??++DG4DIY!^
47E4G4G H HQDI-+dW--1r)   Nc                	    \        V\        4      '       d   VP                  pM.\        P                  ! \        P                  P
                  4      p\        V P                  WW4R 4      pRVn        V# )NT)r@   r+  r   r   r-  r3  JM_pixmap_from_display_listr   )r&   r  r  r  r  r  s   &&&&& r'   r  DisplayList.get_pixmap
  sU    j*--#J++E,>,>,H,HIJ)$))VVZ[
r)   c                    \         P                  ! 4       pWn        \         P                  ! V P                  V4      pRVn        V# )z#Make a TextPage from a DisplayList.T)r   r  r  r  r   r   )r&   r  stext_optionsr  s   &&  r'   r$  DisplayList.get_textpage
  s8    ,,.#		=9
r)   c                	n    \        \        P                  ! V P                  4      4      p\	        V4      pV# r+   )rp  r   fz_bound_display_listr   r+  r  s   & r'   r   DisplayList.rect
  s)    e99$))DE3i
r)   c                	    \         P                  ! V P                  VP                  \	        V4      \        V4      \         P                  ! 4       4       R # r+   )r   fz_run_display_listr   rR  r  r  FzCookie)r&   dwr  areas   &&&&r'   runDisplayList.run
  s8    !!				!!$% 	r)   r   r   )NNrx   Nr   )r/   r0   r1   r2   r[  r   r  r$  r{  r   rm  r3   r,   r)   r'   rX  rX  
  s/    .  
r)   rX  c                     ] tR tRtR R ltR R ltR tR t]P                  ERR R	 ll4       t
]P                  ER8  d+   ]P                  R
 R l4       t
]P                  R R l4       t
ERR lt
ERR ltR R ltR R ltR tR R ltR tR tR tERR R lltER	R R lltR tR  R! ltER
R" ltR# tR$ tR% tERR& ltR' tR( R) ltERR* R+ llt R, t!R- t"R. t#R/ t$R0 t%ERR1 lt&R2 t'R3 t(R4 t)ERR5 lt*R6 t+R7 t,R8 t-R9 t.ERR: lt/]0R; 4       t1ERR< lt2ERR= lt3R> t4R? t5R@RARBRA/RC RD llt6]0RE 4       t7RF t8RG t9ERRH lt:ERRI RJ llt;RK t<ERRL RM llt=RN t>ER
RO RP llt?RQ RR lt@RS RT ltARU RV ltBRW RX ltCRY RZ ltDERR[ R\ lltEERR] ltFR^ tGERR` ltHRa tIERRb ltJERRc Rd lltKERRe ltLRf tMRg tNRh Ri ltORj tPRk Rl ltQRm tRERRn Ro lltSERRp Rq lltTRr tUERRs ltVRtRRuRRvRRwRRxR_R@RA/Ry Rz lltWERR{ R| lltXR} R~ ltYR tZERR R llt[R t\R R lt]R R lt^R t_ERR lt`ERR R lltaRERRERRERRERR^R@^RB^R^ R^ R^RR/R ltb]0R 4       tc]0R 4       td]0R 4       te]0R 4       tf]0R 4       tg]0R 4       thR tiR tjR tkR tlR tmR tnR toR tpERR ltqR trR ts]0R 4       tt]0R 4       tuR tvERR ltwR txR tyR tz]0R R l4       t{ERR R llt|]0R 4       t}ERR lt~]0R 4       tERR R lltR tR t]0R 4       tR tR tR t]0R R l4       t]0R R l4       tER
R R lltR tERR lt]0R 4       tR tR R ltR tERR ltERR ltERR ltR tER R ltR tR tER!R R lltER"R R lltR tERR ltER#R ltERR ltR R ltERR R lltR R ltER$R R lltR R ltR R ltR tERR R lltER%R R lltR tER&R R lltERR ltERR ltER'R lt]0R 4       tER(R ltR t]0R 4       tRR/R R lltR tR tR tR tERR ltR tR tERR ltR tR tER  tER tER)t]0! ER 4      t]tERtR# (*  r   i	  c                   V ^8  d   QhRR/# )r  returnr   r,   )r  s   "r'   r  Document.__annotate__  s      4 r)   c                	~   \        V4      \        J d   WP                  8  d   R # R# \        V4      \        \        39  g   \        V4      ^8w  d   R# Vw  r# \        V\        4      '       d   V^ 8  g   W P                  8  d   R#  \        V\        4      '       d   V^ 8  g   W0P                  V4      8  d   R# R # )TF)	r   r6   
page_countr   r   r9   r@   chapter_countchapter_page_count)r&   locchapterpnos   &&  r'   __contains__Document.__contains__  s    9__$9UDM)SX]!'3//Q;000!#s++711'::r)   c                   V ^8  d   QhRR/# )r  rs  Noner,   )r  s   "r'   r  rt  !  s     ; ;d ;r)   c                	   V P                   '       g   \        R 4      h\        V4      \        J d   V P	                  V4      # \        V4      \
        \        \        39   d   V P                  V4      # \        V4      \        Jd   \        R4      hV P                  pVP                  '       d   VP                  M^ pVP                  '       d   VP                  MTpVP                  '       d   VP                  M^pV^ 8  d   W2,          pK  W28  d   \        R4      hV^ 8  d   WB,          pK  WB8  d   \        R4      hV P                  \        W4V4      4      # )	is no PDFzbad argument typebad page number(s))is_pdfr   r   r6   delete_pager   r   rS  delete_pagesslicerv  r  stopstep)r&   rg  pcr  r  r  s   &&    r'   __delitem__Document.__delitem__!  s   {{{[))7c>##A&&7tUE**$$Q''7%011__777qvvRqvvQaiKE;122QhJD9122  uD!9::r)   c                	    V # r+   r,   r-   s   &r'   r  Document.__enter__8  r  r)   c                	&    V P                  4        R # r+   closer  s   &*r'   r  Document.__exit__;      

r)   c                    V ^8  d   QhRRRR/# )r  rg  r6   rs  r   r,   )r  s   "r'   r  rt  ?  s      S  r)   c                	    R # r+   r,   r&   rg  s   &&r'   r  Document.__getitem__>  s    r)   c                    V ^8  d   QhRRRR/# )r  rg  r  rs  z
list[Page]r,   )r  s   "r'   r  rt  D  s     	 	 	: 	r)   c                	    R # r+   r,   r  s   &&r'   r  r  C      r)   c                    V ^8  d   QhRRRR/# )r  rg  ztuple[int, int]rs  r   r,   )r  s   "r'   r  rt  H  s     	 	 	T 	r)   c                	    R # r+   r,   r  s   &&r'   r  r  G  r  r)   c                	   \        V\        4      '       d8   \        VP                  \	        V 4      4      !   Uu. uF  q V,          NK  	  up# \        V\
        4      '       gm   \        V\        4      '       dK   \	        V4      ^8X  d;   \        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g   Q RV: R24       hW9  d   \        RV R24      hV P                  V4      # u upi )r  c              3  B   "   T F  p\        V\        4      x  K  	  R # 5ir+   )r@   r6   ).0ri  s   & r'   	<genexpr>'Document.__getitem__.<locals>.<genexpr>N  s      RqopjkS]^_adSeSeops   FTzInvalid item number: i=r   page z not in document)
r@   r  rS  indicesr9   r6   r   all
IndexError	load_page)r&   rg  r  s   && r'   r  r  K  s    a%*AIIc$i,@%AB%AGG%ABB!S!!jE&:&:s1v{ssRqopRqsssRqopRqOqOq 	.*t1-	.r=uQC'7899~~a   Cs   C6Nc                   \         p^ s  RV n        RV n        RV n        RV n        . V n        / V n        / V n        / V n        \        P                  ! 4       V n
        \        V\        P                  4      '       d   Tp	Wn        RV n         Vs R# Tp
Tp\!        V4      p\        P"                  ! V4      '       g;   VP$                  VP&                  ,
          p
VP(                  VP*                  ,
          pWn        W n        VEe+   Ve   Vf   Tp\        V\0        \2        34      '       d   Ml\        V\4        4      '       d   \1        V4      pMJ\        V\6        P8                  4      '       d   VP;                  4       pM\=        R\?        V4      : R24      hW n        \        V\0        \2        34      '       g   Q h\A        V4      ^ 8X  d   \C        R4      h\        PD                  ! \        PF                  ! V4      \A        V4      4      p \        PH                  ! V'       d   TMRV4      pEMV'       Edm   V'       d   Q h\        V\R        4      '       d   MZ\U        VR	4      '       d   \S        V4      pM<\U        VR
4      '       d   VPV                  pM\=        R\?        V4      : RV: R24      hWn        \X        PZ                  P]                  V4      '       g   \_        RV R24      h\X        PZ                  Pa                  V4      '       g   \Q        RV R24      h\X        PZ                  Pc                  V4      ^ 8X  d   \C        RV: R24      hV'       d0    \        Pd                  ! V4      p\        PH                  ! VV4      pMC \        Pf                  ! V4      pM+\        P                  ! 4       p\        Ph                  ! V4      pV
^ 8  d    V^ 8  d   \        Pj                  ! WW4       M5\        Pl                  ! V4      '       d   \        Pj                  ! VRR^4       Wn        RV n7        V Pn                  '       d   \p        Ps                  4       V n:        V Pv                  '       d	   RV n        MV Py                  4        V'       d&   VP{                  4       P}                  R4      '       g   V'       d'   RVP{                  4       9   d    V P                  4       p\        '       dg   \        V P                  \        P                  4      V n        V P                  '       d   \        P                  V nC        M\        P                  V nC        Vs R#   \J         d'   p\L        ^8  d   \O        4        \Q        R4      ThRp?ii ; i  \J         d0   p\L        ^8  d   \O        4        \Q        RT: RT: R24      ThRp?ii ; i  \J         d,   p\L        ^8  d   \O        4        \Q        RT: R24      ThRp?ii ; i  \J         d'   p\L        ^8  d   \O        4        \Q        R4      ThRp?ii ; i  Ts i ; i)a  Creates a document. Use 'open' as a synonym.

Notes:
    Basic usages:
    open() - new PDF document
    open(filename) - string or pathlib.Path, must have supported
            file extension.
    open(type, buffer) - type: valid extension, buffer: bytes object.
    open(stream=buffer, filetype=type) - keyword version of previous.
    open(filename, fileype=type) - filename with unrecognized extension.
    rect, width, height, fontsize: layout reflowable document
    on open (e.g. EPUB). Ignored if n/a.
FNTzbad stream: type(stream)=r   zCannot open empty stream.r`   zFailed to open streamabsoluter   zbad filename: type(filename)=z
 filename=zno such file: 'r   z' is no filez!Cannot open empty file: filename=zFailed to open file z	 as type i  iX  svgcannot open broken document)EJM_mupdf_show_errorsr   is_encryptedmetadata	FontInfos	Graftmaps
ShownPagesInsertedImagesr  WeakValueDictionary
_page_refsr@   r   r   r   this_is_pdfr  r  x1x0y1y0r=  r   r  
memoryviewr  r;   r  r  r  r   r9   EmptyFileErrorfz_open_memorypython_buffer_datafz_open_document_with_streamrk   r  r{   FileDataErrorr  r=   r   rh   r   existsFileNotFoundErrorr  getsizefz_open_filefz_open_documentr   fz_layout_documentfz_is_document_reflowabler   r  gen_id	_graft_id
needs_passinit_docr  r  convert_to_pdfr  r   page_count_pdfpage_count2page_count_fz)r&   rj   r   filetyper   r  r3  r   JM_mupdf_show_errors_oldpdf_documentr   r"  r$  stream2r1  rh  	fz_streamra  r@  s   &&&&&&&&           r'   r   Document.__init__T  s   $ $8  B	< %DN %D %D#DM!DN!DN!DO#%D&::<DO(E$5$566'(	#' h $< e AA%A,,Q//DD144KDD144K!J K!'H,<  (Hfuj&9::	22"6]F

33#__.F#&@4</$CDD$!&5**=>>>>v;!# ))DEE..u/G/G/OQTU[Q\]H<<XWY[bcC
 !!zh,,Xz22"8}HXv..'}}H#&DT(^4E[xkQR$STT%
 ww~~h//+ohZq,IJJ11'!H:\(BCCWW__X.!3(+MH;a)PQQn$)$6$6x$@	#@@9U
Y#44X> '')&&s+1uQ((=0055((c3;I  DL|||!&???(,D%MMO  0 9 9% @ @HQVZbZhZhZjQjR //1
 {#-tyy%:K:K#L ###',';';D$',':':D$#; ] ! H+a/N4D'(?@aGH> % n/!38H+.B8,iX`Wccd,eflmmn % Y/!38H+.B8,a,PQWXXY< % R/!38H+,IJPQQR $< s   BX< E<X< !U .
X< 9X< CX< A
X< -V X< W $A-X< A"X< 5X< $X< :X< X< X (X< 4A&X< V)!V

VX< W*WWX< X&X  XX< X9!X44X99X< <Y c                   V ^8  d   QhRR/# r  rs  r6   r,   )r  s   "r'   r  rt    s       r)   c                	    V P                   # r+   )rv  r-   s   &r'   __len__Document.__len__  s    r)   c                   V ^8  d   QhRR/# r  rs  r  r,   )r  s   "r'   r  rt    s     X X# Xr)   c                	    V P                   '       d   R MRpV P                  f7   V P                  R8X  d   V RV P                  R R2# V RV P                   R2# V RV P                   RV P                  R R2# )zclosed r`   zDocument(<new PDF, doc# rH  z>)z
Document('')z', <memory, doc# )r   r   r   r  )r&   r   s   & r'   r   Document.__repr__  s    !%IR	;;yyB#$<T^^A<NbQQ[
499+R88Jtyyk1B4>>RSBTTVWWr)   c           	     ,   V P                   '       g   V P                  '       d   \        R4      h\        V ^ R7      pVP                  '       g   R# \
        P                  ! \
        P                  ! V4      \        R4      \        R4      \        R4      \        R4      4      pVP                  '       d   \
        P                  ! V4      '       g   \        R4      h\
        P                  ! V4      p\        W24      p\
        P                  ! WEV4       R# )	zAdd new form font.document closed or encryptedr   NRootAcroFormDRFontzPDF has no form fonts yet)r   r  r   r   r   r   r   pdf_trailerr  r  r   pdf_new_nameJM_pdf_obj_from_strrU  )r&   r   r  ra  fontsr  rH   s   &&&    r'   _addFormFontDocument._addFormFont  s    >>>T...;<<ta0~~~##!!3' $  u'8'8%'@'@ ;<<%+Ea(r)   c                    V ^8  d   QhRRRR/# )r  idxr6   rs  r  r,   )r  s   "r'   r  rt    s     $ $$ $r)   c                V    V P                  4       V,          pV P                  V4       R# )z$Delete TOC / bookmark item by index.N)get_outline_xrefs_remove_toc_item)r&   r  r  s   && r'   del_toc_itemDocument.del_toc_item  s%    
 %%',d#r)   c                .   V P                   '       g   V P                  '       d   \        R4      h. p\        V ^ R7      pVP                  '       g   V# \
        P                  ! \
        P                  ! V4      \        R4      4      p\
        P                  ! V\        R4      4      pVP                  '       g   V# \
        P                  ! V\        R4      4      p\        WQ4      p\        V4      p\
        P                  ! V4      p\
        P                  ! W'4       \
        P                  ! V\        R4      4       \        V4       F&  p\        W4      w  r\
        P                  ! W*4       K(  	  VP!                  V4       TpV P#                  4        V# )zDelete the TOC.r  r  r  OutlinesFirst)r   r  r   r   r   r   r  r  r  JM_outline_xrefsr9   r  pdf_delete_objectrH  rS  JM_INT_ITEMro   r  )r&   xrefsra  r  olrootfirst
xref_countolroot_xrefrg  r@  r  r  s   &           r'   _delToCDocument._delToC  s2   >>>T...;<<ta0~~~L!!%"3"3C"8(6:JK##D(:*>?   L""68G+<= .Z
&&v.14*!56z"A!%+GA##C. # 	[!
r)   c                	    \        V 4      p\        P                  ! W!4       VP                  P                  '       d#   \        P
                  ! VP                  4       R # R # r+   )r   r   pdf_delete_pager   rev_page_mapll_pdf_drop_page_tree)r&   r{  ra  s   && r'   _delete_pageDocument._delete_page4  sA    t$s(>>&&&''8 'r)   c                    \        V 4      p\        V^\        P                  ! V4      ^,
          4      '       g   \	        \
        4      h\        P                  ! W!4       R# )zDelete object.N)r   r  r   r  r   r  r  r&   r  ra  s   && r'   _deleteObjectDocument._deleteObject:  sD    t$a!3!3C!8!:;;l++*r)   c               0    V ^8  d   QhRRRRRRRRRRRR	/# )
r  doc1
'Document'doc2	from_pager6   to_pagestart_atrs  r  r,   )r  s   "r'   r  rt  A  sT     C@ C@C@C@ C@ 	C@
 C@ C@r)   c                   R pV^ 8  d   ^ pM&W!P                   8  d   VP                   ^,
          pMTpV^ 8  g   W1P                   8  d   VP                   ^,
          pMTpV^ 8  d   \        R4      hTpWg8:  d   ^MRp	\        \        WgV	,           V	4      4      p
\        \	        V
4      4       Uu. uF  qV,           NK  	  pp. p. p\        \	        V
4      4       FW  pW,          pW,          pVP                  V4      pV P                  V4      pVP                  V4       VP                  V4       KY  	  \        \	        V4      4       EF'  pWV,          ,          pVP                  4       p\	        V4      ^ 8X  d   RpK7  WV,          ,          p\        P                  ! 4       p\        V4      p\        P                  ! V\        P                  ! ^ 4      V4       \        \        P                  ! V4      4      p. pV FJ  pVR,          \        8X  d   VR,          V
9  d   K%  V! VWV4      pV'       g   K9  VP                  V4       KL  	  V. 8w  g   EK  VP!                  \#        V4      4       EK*  	  R# u upi )zInsert links contained in copied page range into destination PDF.

Parameter values **must** equal those of method insert_pdf(), which must
have been previously executed.
c           	        V R,          V,          p\        \        V4      4      pV R,          \        8X  de   \        R,          pVP	                  V R,          4      pV R,          V,          pV! W,          VP
                  VP                  V R,          V4      p	V	# V R,          \        8X  d   V R,          ^ 8  d   \        R,          pV P                  R\        ^ ^ 4      4      p
\        V
4      \        Jd   \        ^ ^ 4      p
V! V R,          V
P
                  V
P                  V R,          V R,          V R,          V4      p	V	# \        R	,          p\        V R,          4      pV^R pV R,          pV! WV4      p	 V	# V R,          \        8X  d(   \        R
,          pV! V R,          V R,          V4      p	V	# V R,          \        8X  d    \        R,          pV! V R,          V4      p	V	# Rp	V	# )z5Create annotation object string for a passed-in link.fromkindgoto1r   tozoomgotor1re   gotor2launchurir`   r  )r   r   	LINK_GOTO
annot_skelindexri  rj  
LINK_GOTORr:   r)  r   get_pdf_strLINK_LAUNCHLINK_URI)lnkxref_dstpno_srcr  r$  r   txtr  r  r   pntr  r  s   &&&&         r'   	cre_annot%Document._do_links.<locals>.cre_annotQ  s    Fc!AU1X&D6{i' )mmCK0IOHM133S[$GF LC V
*v;!#$X.C''$a4CCy-#AqkFFFFE6 L# %X.C$SY/BAbBFAt,E L V+ *CKVd; L V( 'CJ-
 L Lr)   z'start_at' must be >= 0Nr  r   r  )rv  r   r   rS  r9   	page_xrefro   	get_linksr   r|  r   rd  rq  r  fz_invert_matrixr  _addAnnot_FromStringr   )r	  r  r  r  r  r&  r  rT  saincrr#  rg  pno_dstxref_srcr"  p_srcp_dstold_xrefnew_xrefpage_srclinkspage_dstr  page_src_pdf_documentictmlink_tabrX  
annot_texts   &&&&&                       r'   	_do_linksDocument._do_linksA  s    ,	b q=B//)1$BBQ;'__41$BBa<677Hq" uRdD12#(W#67#6a66#67 s7|$AJEJE~~e,H~~e,HOOH%OOH% % s8}%AAJ'H&&(E
 5zQAJ'H .."C$0$:!$$%:ELLOSQ%0056DHV9	)qy/G&q(TB
:OOJ/  2~--uX?A & 8s   1I9c               0    V ^8  d   QhRRRRRRRRRRRR	/# )
r  r  r
  r4  r  r6   r  r  rs  r  r,   )r  s   "r'   r  rt    sT     DP DPDPDP 	DP
 DP DP DPr)   c           	     `  a.a/a0 VP                   '       g   R# R o.R o0V/3R lo/V/3R lpRV.V03R llpR p	\        P                  ! V 4      p
\        P                  ! V4      pV P                   '       dp   V	! V 4      pVP                  \	        R4      4      pVP                  \	        R	4      4      pVP                  4       '       g   VP                  \	        R	4      ^4      pEM]\        P                  ! V	! V4      4      pVP                  \	        R4      4       VP                  \	        R4      ^4       VP                  \	        R	4      4       VP                  \	        R	4      ^4       \        P                  ! W,4      p\        P                  ! W4      pVP                  \	        R4      4      pVP                  \	        R	4      4      pVP                  4       p\        P                  ! V
V^ 4      p\        P                  ! \        P                  ! V
4      \	        R
4      4      pVP                  \	        R4      V4       W48:  d   \        W4^,           4      pM\        W4^,
          R4      p/ pV F  pVV,          pVP!                  4        UUUu. uF   w  pppV\        P"                  8X  g   K  VNK"  	  uppp FT  p\        P$                  ! VV4      pVP                  \	        R4      4       V! V4      w  ppV'       g   KI  R^ RVR. /VV&   KV  	  K  	  VP'                  4        F  p\        P$                  ! VV4      p\        P                  ! VV4      p\        P                  ! V
V4      p S/! V . 4      p!V P                  4       p"\        P                  ! V
V"^ 4      p#VP)                  V#4       V"VV,          R&   V!VV,          R&   K  	  \        \+        V4      4       EF  pWV,           ,          p$VVV,          ,          pVP!                  4        UUUu. uF   w  pppV\        P"                  8X  g   K  VNK"  	  p%pppV%'       g   Kk  \        P,                  ! V$4      p&\        P                  ! V&P/                  4       \	        R4      4      p'\        P
                  ! V'4      '       g0   \        P                  ! V&P/                  4       \	        R4      ^4      p'V% EF  p\        P$                  ! VV4      p\        P0                  ! \        P2                  ! VR4      4      p(\        P                  ! VP                  \	        R4      4      4      pV^ 8X  d    \        P                  ! VV4      p)\        P                  ! T
T)4      p+T+P                  4       p\        P                  ! T
T^ 4      p,\        P(                  ! T'T,4       \        P(                  ! TT,4       M`VV,          pVR,          P9                  V4      p-VR,          V-,          p\        P                  ! V
V^ 4      p,\        P(                  ! V'V,4       V('       g   EKl  \        P(                  ! VV,4       EK  	  EK  	  V! WVR7       R# u upppi u upppi   \4         d   p*\7        RT: RT* 24        Rp*?*EK  Rp*?*ii ; i)zInsert widgets of copied page range into target PDF.

Parameter values **must** equal those of method insert_pdf() which
must have been previously executed.
Nc                4   \        V P                  4       4       Fz  pV P                  V4      pVP                  \	        R4      4      p\        VP                  4       4       F/  pVP                  V4      pVP                  \	        R4      V4       K1  	  K|  	  R# )z2Make sure all kids have correct "Parent" pointers.Kidsr  N)rS  r  r  r  r  rU  )acro_fieldsrg  r   kidsr  kids   &     r'   clean_kid_parents/Document._do_widgets.<locals>.clean_kid_parents  s|    ;4467$2215**8F+;<t1134A,,Q/C$$Xh%7@ 5 8r)   c           	     p   R pR p\         P                  ! W4      p\         P                  ! W4      pVP                  \        R4      4      p	VP                  \        R4      4      p
V	P	                  4       '       d   V! WW)W:4       R# V
P	                  4       '       d   V! WW:W)4       R# V! WW'W8V4       R# )a  Called for each pair of widgets having the same name.

Args:
    pdf: target MuPDF document
    acro_fields: object Root/AcroForm/Fields
    xref1, xref2: widget xrefs having same names
    name: (str) the name

Result:
    Defined or updated widget parent that points to both widgets.
c                   \         P                  ! W^ 4      p\         P                  ! W^ 4      pVP                  V4      pVP                  V4       VP	                  4       '       g_   \         P
                  ! W4      p	V	P                  \        R4      4       V	P                  \        R4      V4       VP                  V4       R# \        VP                  4       4       Fe  p
VP                  V
4      pVP                  \        R4      V4       \         P                  ! WP                  4       ^ 4      pVP                  V4       Kg  	  R# )zMerge widget in xref2 into "Kids" list of widget xref1.

Args:
    xref1, kids1: target widget and its "Kids" array.
    xref2, kids2: source wwidget and its "Kids" array (may be empty).
r+  r  N)r   r  pdf_array_findr  pdf_is_arraypdf_load_objectrH  r  rU  pdf_array_pushrS  r  r  r  )ra  rA  xref1kids1xref2kids2w1_indw2_indr  r\  rg  rC  kid_inds   &&&&&&       r'   	re_target=Document._do_widgets.<locals>.join_widgets.<locals>.re_target  s    //A>//A>!008,,S1))++"223>F ''6''(:FC ((0"5#6#6#89#11!4((();VD"'"8"8nn>NPQ"R,,W5	 :r)   c                t   \         P                  ! V ^4      pVP                  \        R4      V4       VP	                  \        R4      ^4      p\         P
                  ! W4      p	V	P                  4       p
\         P                  ! W
^ 4      pVP                  \        R4      4      pVP                  \        R4      4       V	P                  \        R4      V4       VP                  \        R4      4      pVP                  \        R4      4       V	P                  \        R4      V4       VP                  \        R4      4       VP                  \        R4      V4       VP                  \        R4      4       VP                  \        R4      V4       \         P                  ! W^ 4      p\         P                  ! W^ 4      pVP                  V4       VP                  V4       VP                  V4      pVP                  V4       VP                  V4      pVP                  V4       VP                  V4       R# )a@  Make new "Parent" for two widgets with same name.

Args:
    xref1, w1: first widget
    xref2, w2: second widget
    name: field name

Result:
    Both widgets have no "Kids". We create a new object with the
    name and a "Kids" array containing the widgets.
    Original widgets must be removed from AcroForm/Fields.
r+  r@  FTAAr  N)r   rZ  r  r  pdf_dict_put_arraypdf_add_objectr  r  r  rH  rU  rK  rH  r  )ra  rA  rL  w1rN  w2r   newrB  new_objnew_obj_xrefnew_indftaaind1ind2r  s   &&&&&&&          r'   
new_target>Document._do_widgets.<locals>.join_widgets.<locals>.new_target  s    ((a0,,Xc]DA--hv.>B..s8&11300AF __Xd^4/$$Xd^R8__Xd^4/$$Xd^R8 . 2G<. 2G< --c!<--c!<##D)##D) "006,,S1!006,,S1**73r)   r@  N)r   rJ  r  r  rI  )ra  rA  rL  rN  r   rS  rd  rZ  r[  rM  rO  s   &&&&&      r'   join_widgets*Document._do_widgets.<locals>.join_widgets  s    6<04d &&s2B&&s2BOOHV$45EOOHV$45E !!###E%G##%%#E%G3U4Hr)   c           	       < \         P                  ! V \        R4      4      pVP                  4       '       g   V# \	        VP                  4       4       Fw  pVP                  V4      p\         P                  ! \         P                  ! V\        R4      4      4      '       d   S! WA4      pKX  VP                  VP                  4       4       Ky  	  V# )zFReturn xref list of leaf kids for a parent.

Call with an empty list.
r@  )
r   r  r  rI  rS  r  r  r  ro   r  )r   	kids_listrB  rg  rC  get_kidss   &&   r'   rj  &Document._do_widgets.<locals>.get_kidsK  s    
 %%fhv.>?D$$&&  4--/0((+$$U%7%7Xf=M%NOO ( 8I$$S^^%56 1 r)   c                   < . p\         P                  ! V \        R4      4      pVP                  4       pV^ 8X  d   W13# S! W!4      pW13# )z:Get the xref of top "Parent" and the list of leaf widgets.r  )r   r  r  r  )r\  ri  r   parent_xrefrj  s   &   r'   
kids_xrefs(Document._do_widgets.<locals>.kids_xrefs[  sQ    I''0BCF ++-Ka"-- 3I))r)   c                R  < / p\        \        P                  ! V4      4       Fp  p\        P                  ! W4      pVP	                  4       p\        P
                  ! V\        R4      4      pVP                  V. 4      pVP                  V4       WV&   Kr  	  VP                  4        Ft  w  r\        V4      ^8  d   K  VR,          w  rV'       d   S! WWV	4       K6  V	RV R2,           p\        P                  ! W4      pVP                  \        R4      V4       Kv  	  S! V4       R# )z6Handle any widget name duplicates caused by the merge.r+  r  z [r  N)rS  r   r  r  r  pdf_dict_get_text_stringr  r:   ro   rD   r9   rJ  r  )ra  rA  join_duplicatesnamesrg  wobjectr  r+  r  r   xref0rL  newnamerD  rf  s   &&&          r'   deduplicate_names/Document._do_widgets.<locals>.deduplicate_namese  s    E 5..{;<--k=))+ 227HSMJ		!R(T" a =  %{{}u:>$Ry" 5F"r%]2G#33C?G44Xc]GL  - k*r)   c                    \         P                  ! V 4      p\         P                  ! \         P                  ! V4      R4      # )z,Retrieve the AcroForm dictionary form a PDF.Root/AcroForm)r   pdf_document_from_fz_documentpdf_dict_getpr  )r1  ra  s   & r'   get_acroform*Document._do_widgets.<locals>.get_acroform  s0    55c:C&&u'8'8'=OOr)   Fieldsr  r  r  Pr3  old_kidsnew_kidsr  zAA/Cr  zcannot copy widget at xref=r   )rr  Fr  )is_form_pdfr   r{  r  r  rI  rX  pdf_deep_copy_objrH  pdf_graft_mapped_objectrY  r  r  r  rU  rS  annot_xrefsrT  rJ  keysrK  r9   r   r  r  r|  rk   r  r  )1r  r4  graftmapr  r  r  rr  rn  rw  r}  tarpdfsrcpdfacrorA  tar_co
acro_graftacro_tartar_xrefacro_tar_indr  	src_rangeparentsrg  src_pager  wtyper@  w_objrm  r  r   parent_graft
parent_tarkids_xrefs_newparent_xref_new
parent_indtar_pagew_xrefstar_page_pdf
tar_annotsis_aacw_obj_graftrh  	w_obj_tarw_obj_tar_indr  rD  rj  rf  s1   &&&&&&&                                       @@@r'   _do_widgetsDocument._do_widgets  s    	Ah	IT	 	*	+ 	+8	P 44S944S9???$D++HX,>?K&&x~6F&&((00$C **<+<=D hx01##HX$6:htn-##HTNA6 66xFJ ++F?H"//0BCK**8D>:F  **,H 11&(AFL%%e&7&7&?&AQRDhz2LAi15Ii1b9I A1vH '/&:&:&<&<ND%E222 &<
 --fd;""8C=1 )35(9%X;"A"H"B,GK( & LLND**648F 886JL--flCJ%j"5N(335O//KJ&&z2(7GDM*%(6GDM*% # s9~&Aa<(H 9Q<(H
 '/&:&:&<&<ND%E222 &<  
  !66x@L ++L,<,<,>@RSJ%%j11"55 $$&(:A
  --fd; **5+>+>uf+MN $..&&x'9: !#!&+&C&CHe&T !& 4 4V[ II(335H$)$:$:68Q$OM((]C((mD$[1F ,2248C%j1#6H$)$:$:68Q$OM((]C 6((?=  5 't 	&OmH> % !'*Fr!(MN !s0   Y6
0Y6
Y=
8Y=
ZZ-Z((Z-c           	     	   \        V 4      p\        P                  ! \        P                  ! V4      \	        R 4      \	        R4      \	        R4      \	        R4      4      p\        P
                  ! V^V,          ^,           4      p\        P                  ! V\	        R4      \	        R4      4      p\        P                  ! V4      p\        V4      pV# r  NamesEmbeddedFilesr  r  )r   r   r   r  r  r  r"  r#  )r&   r  ra  rs  entryfilespecr  conts   &&      r'   _embeddedFileGetDocument._embeddedFileGet  s    t$##!!#& !)! ##E1S573&&uhtnhsmL##H-$r)   c                    V ^8  d   QhRRRR/# )r  rE   typing.Union[int, str]rs  r6   r,   )r  s   "r'   r  rt    s      '= # r)   c                	    V P                  4       pW9   d   VP                  V4      pV# V\        \        V4      4      9   d   TpV# \	        R V R24      h)r   z' not in EmbeddedFiles array.)embfile_namesr  rS  r9   r   )r&   rE   	filenamesr  s   &&  r'   _embeddedFileIndexDocument._embeddedFileIndex  sa    &&(	//$'C
 
	 U3y>**C 
 q&CDEEr)   c           	     	j   \        V 4      p\        V4      pVP                  '       g   \        \        4      h\
        P                  ! \
        P                  ! V4      \        R 4      \        R4      \        R4      \        R4      4      p\
        P                  ! V4      '       g   \
        P                  ! \
        P                  ! V4      \        R 4      4      p	\
        P                  ! V^4      p\
        P                  ! V	V\        R4      \        R4      \        R4      4       \        WgW4V^4      p
\
        P                  ! \
        P                  ! V
\        R4      \        R4      4      4      p\
        P                  ! V\
        P                   ! V4      4       \
        P                  ! W4       V# r  )r   r.  r   r  r/  r   r   r  r  rI  r  rR  rV  JM_embed_filer  rK  r  )r&   r   r4  rj   rW  r  ra  r  rs  r  	fileentryr  s   &&&&&&      r'   _embfile_addDocument._embfile_add&  sG   t$!'*^,,##!!#& !)! !!%((%%e&7&7&<hv>NOD''Q/EW%_-W% "#X$J	##Ix~x}M 	UE$=$=d$CDU.r)   c           	     	&   \        V 4      p\        P                  ! \        P                  ! V4      \	        R 4      \	        R4      \	        R4      \	        R4      4      p\        P
                  ! W1^,           4       \        P
                  ! W14       R# )r  r  r  N)r   r   r   r  r  r  )r&   r  ra  rs  s   &&  r'   _embfile_delDocument._embfile_delE  sl    t$##!!#& !)! 	uAg.u*r)   c           	     	   \        V 4      p^ p^ p\        P                  ! V4      p\        P                  ! V\	        R4      \	        R4      \	        R4      \	        R4      4      p\        P
                  ! V^V,          ^,           4      p\        P                  ! V\	        R4      4      p	V	P                  '       d   \        P                  ! V	4      pWRR&   \        P                  ! \        P                  ! V\	        R4      4      4      p
\        V
4      V\        &   \        P                  ! \        P                  ! V\	        R4      4      4      p
\        V
4      V\        &   \        P                  ! \        P                  ! V\	        R4      4      4      p
\        V
4      V\        &   RpRp\        P                  ! V\	        R	4      \	        R4      4      p\        P                  ! V4      p\        P                  ! V\	        R
4      4      pVP                  '       d   \        P                  ! V4      p\        P                  ! V\	        R4      4      pVP                  '       d   \        P                  ! V4      pMR\        P                  ! V\	        R4      \	        R4      4      pVP                  '       d   \        P                  ! V4      pW\         &   W\"        &   V# )rx   r  r  r  CI
collectionr  r  r  r  r  rR  r  r  r  )r   r   r  r   r  r  r  r   r  r  r  r  dictkey_ufilenamer	  r  r  r  r  )r&   r  infodictra  r  ci_xreftrailerrs  r  cir   len_rR  r  s   &&&           r'   _embfile_infoDocument._embfile_infoQ  s    t$##C(## !)! quQw/8D>2===&&r*G!(''(:(:1hsm(LM%8%>!"''(:(:1htn(MN&9$&?"#''(:(:1hv>N(OP"3D"9''8D>8C=I		*y(8*<=<<<##A&Dy(4.9<<<!!!$B##Ix/A8FCSTA|||%%a(!##' r)   c           	        \        V 4      p\        P                  ! \        P                  ! V4      \	        R4      \	        R4      \	        R4      \	        R4      4      p\        P
                  ! V4      '       dq   \        P                  ! V4      p\        ^ V^4       FG  p\        \        P                  ! \        P                  ! W54      4      4      pVP                  V4       KI  	  R# R# )z Get list of embedded file names.r  r  r  N)r   r   r   r  r  rI  r  rS  r  r  r  ro   )r&   r  ra  rs  rG   rg  r  s   &&     r'   _embfile_namesDocument._embfile_names  s    t$##!!#& !)! e$$##E*A1a^)00!//9
 $ $ %r)   c           	     	   \        V 4      p^ p\        P                  ! \        P                  ! V4      \	        R4      \	        R4      \	        R4      \	        R4      4      p\        P
                  ! V^V,          ^,           4      p	\        P                  ! V	\	        R4      \	        R4      4      p
V
P                  '       g   \        R\        4       \        V4      pV'       d4   VP                  '       d"   VP                  '       g   \        \        4      hVP                  '       d   V'       d   VP                  '       d   \        WjV^4       \        P                  ! V4      w  r\        P                  ! V4      p\        P                  ! V
\	        R4      V4       \        P                   ! W\	        R4      \	        R	4      4       \        P"                  ! V
4      pV'       d"   \        P$                  ! V	\	        R4      V4       V'       d"   \        P$                  ! V	\	        R
4      V4       V'       d"   \        P$                  ! V	\	        R4      V4       V# )rx   r  r  r  r  r  rQ  rR  r  r  r  r  )r   r   r   r  r  r  r   r  r  r.  r  r/  r0  rT  rU  rU  rV  r  r  )r&   r  r4  rj   rW  r  ra  r  rs  r  r  r%  r9   r@  rX  s   &&&&&&         r'   _embfile_updDocument._embfile_upd  s   t$##!!#& !)! ##E1S573&&uhtnhsmL"""-/CD )w)))#...^,,>>>g'*<*<*<SC3,,S1FC!!#&Ax$;Xh-?&AQR)**5(3-J**5(4.)L**5(62BDIr)   c           	        V P                   '       d   \        R4      h\        '       d"   \        P                  ! V P
                  V4      # \        V 4      pRpRpRpRp\        P                  ! \        P                  ! V4      \        R4      4      pVP                  '       g   R# \        P                  ! V\        R4      4      pVP                  '       g   R# \        P                  ! V\        R	4      4      p	V	P                  '       g   R# . p
\        W4      p
\        V
4      p\        V4      pV'       g   R# W8w  d   \        R
4      h\        V4       EF  p\!        W,          4      pW,          pV^,          p\#        V\$        4      '       g   \        R4      hW,          V\&        &   \        P(                  ! W.4      p\        P*                  ! \        P                  ! V\        R4      4      4      pV^8X  d   RVV&   MV^8X  d   RVV&   MV^8X  d   RVV&   RVV&   \        P*                  ! \        P                  ! V\        R4      4      4      pV^ 8  d   RVV&   MV^ 8  d   RVV&   \        P                  ! V\        R4      4      p\        P,                  ! V4      '       d   \        P.                  ! V4      ^8X  d   \        P0                  ! \        P2                  ! V^ 4      4      \        P0                  ! \        P2                  ! V^4      4      \        P0                  ! \        P2                  ! V^4      4      3pVV\4        &   ^ p\        P                  ! V\        R4      4      pVP                  '       d   \        P,                  ! V4      '       g+   \        P6                  ! V\        R4      \        R4      4      p\        P,                  ! V4      '       dG   \        P.                  ! V4      ^8X  d,   \        P0                  ! \        P2                  ! V^4      4      p\9        V4      VV&   VV^&   WV&   EK  	  R# )z4Add color info to all items of an extended TOC list.r   r  r  r  collapser  Nr  r  z$internal error finding outline xrefszneed non-simple TOC formatr  TCountFr  DestAD)r   r   r  r   Document_extend_toc_itemsr   r   r   r  r  r  r   r  r9   r  rS  r6   r@   r7   r  rJ  r  rI  r  r  r  dictkey_colorr   r  )r&   rD   ra  r  r  r  r  r  r  r  r  rG   r  rg  r  rE   itemdictbmr  countrf  rp  zr  s   &&                      r'   _extend_toc_itemsDocument._extend_toc_items  sO   >>>.//;22DIIuEEt$!!%"3"3C"8(6:JK##D(:*>?   ""68G+<= .JJ6DEE qAux=D8DAwHh-- ">??%*XH\"&&s1B$$e&8&8Xc]&KLEz#' !!%!#' !%$$e&8&8Xg=N&OPEqy%)"%*"$$R#7C!!#&&5+>+>s+Cq+H))%*=*=c1*EF))%*=*=c1*EF))%*=*=c1*EF
 +0'A$$R&)9:C>>>););C)@)@))"hsmXc]K!!#&&5+>+>s+Cq+H%%e&9&9#q&AB"1XHTNDG!HK r)   c                   V ^8  d   QhRR/# r  r   r   r,   )r  s   "r'   r  rt    s     % % %r)   c                Z    \        V4      pW P                  9   d   V P                  V R# R# )z&Remove a page from document page dict.N)rY  r  )r&   r   pids   && r'   _forget_pageDocument._forget_page  s&    h//!$ "r)   c               0    V ^8  d   QhRRRRRRRRRRRR/# )	r  r  r6   bfnamer  extorderinglimitr  r,   )r  s   "r'   r  rt    s8      S # C 3 WZ ad r)   c                	   \        V 4      pTpVR 8  d   R pV^ 8  d4   \        P                  ! V4      w  rp\        P                  ! RWV^ 4      pM\        P                  ! V4      w  rV	'       d   \        P                  ! W)V
^ ^ 4      pME\        Wq4      pVP                  '       g   \        RVR R24      h\        P                  ! RW^ 4      p. p\        V4       Fi  p\        P                  ! W4      p\        P                  ! VV^ 4      pV^ 8  d   TpV^ 8  d   VP                  VV34       KV  VP                  VR34       Kk  	  V# )   Nzfont at xref rH  z is not supportedr  )r   r   fz_lookup_cjk_fontfz_new_font_from_memoryfz_lookup_base14_fontJM_get_fontbufferr   rk   fz_new_font_from_bufferrS  fz_encode_characterfz_advance_glyphro   )r&   r  r  r  r  r  r  ra  mylimitr  r  r  r  r  wlistrg  glyphadvs   &&&&&&&           r'   _get_char_widthsDocument._get_char_widths  s)   t$S=Gq= % 8 8 BD00t5!LD44V<JD44V4AN'2~~~#mD8;L$MNN44T3QGwA--d6E((ua8C1}qyucl+ucl+   r)   c           	     	   \        V 4      p. p\        P                  ! R 4      p\        P                  ! \        P                  ! V4      \        R4      V4      pVP                  '       g   V# \        P                  ! \        P                  ! V\        R4      4      4      pVP                  '       d   \        W%4       V# \        P                  ! \        P                  ! V\        R4      \        R4      4      4      pVP                  '       d   \        W%4       V# \        P                  ! \        P                  ! V\        R4      4      4      pVP                  '       d   \        P                  ! V4      '       g   V# \        P                  ! V4      p\        V4       FV  p\        P                  ! \        P                  ! \        P                  ! Wh4      \        R4      4      4      p\        W%4       KX  	  V# )
PageLabelsr  Numsr@  )r   r   r  r   r  r  r   pdf_resolve_indirectr  JM_get_page_labelsrI  r  rS  r  )	r&   ra  r   
pagelabelsr  numsrB  rG   rg  s	   &        r'   _get_page_labelsDocument._get_page_labels#  so   t$''5
!!5#4#4S#98F;KZX~~~I))5+=+=sHVDT+UV???r(I))5+>+>sHVDTV^_eVf+gh???r(I))5+=+=sHVDT+UVe&8&8&>&>I%qA--&&++D4 (D r(  	r)   c                     \         P                  ! V P                  V4      #   \         d    \        ^8  d   \        4         R# i ; i)zGet metadata.r`   )r   fz_lookup_metadata2r   rk   r  r{   r  s   &&r'   _getMetadataDocument._getMetadataC  s=    	,,dii== 	#a'N,<	s    #  AAc                   V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\        P
                  ! \        P                  ! V4      \        R4      4      p\        P
                  ! V\        R4      4      pVP                  '       g   \        P                  ! V^4      p\        P                  ! V\        R4      \        R4      4       \        P                  ! W4      p\        P                  ! V\        R4      V4       \        P
                  ! V\        R4      4      p\        P                  ! V4      # )z/Get xref of Outline Root, create it if missing.r  r  r  Type)r   r  r   r   r   r  r  r  r   rZ  rU  rY  r  )r&   ra  r  r  ind_objs   &    r'   _getOLRootNumberDocument._getOLRootNumberK  s    >>>T...;<<t$!!5#4#4c#:HV<LM##T8J+?@   ''a0F(8(::NO**C8Ghz&:GD''x
/CDF((r)   c                   \        V ^ R7      pVP                  '       g   R# . p\        P                  ! \        P                  ! V4      \        R4      4      pVP                  '       d|   \        P                  ! V4      p\        V4       FV  p\        P                  ! W54      p\        P                  ! V4      p\        P                  ! V4      pVP                  V4       KX  	  V# )zGet PDF file id.r  NID)r   r   r   r  r  r  r  rS  r  r  binasciihexlifyro   )	r&   ra  idlistidentityrG   rg  r  r   hex_s	   &        r'   _getPDFfileidDocument._getPDFfileid\  s    ta0~~~%%e&7&7&<htnM##H-A1X''4//2''-d#	 
 r)   c                8   V P                   '       g   V P                  '       d   \        R4      hV P                  p\	        V\
        P                  4      '       d   \
        P                  ! V4      M\
        P                  ! V4      pTpV^ 8  d   WT,          pK  WT8  d   \        \        4      h\        V 4      p\
        P                  ! We4      p\
        P                  ! V\
        P                  4      p. p	. p
VP                  '       d   \        WhW^ V
4       V	# )z,List fonts, images, XObjects used on a page.r  )r   r  r   r   r@   r   r   pdf_count_pagesfz_count_pagesMSG_BAD_PAGENOr   pdf_lookup_page_objpdf_dict_get_inheritablePDF_ENUM_NAME_Resourcesr   JM_scan_resources)r&   r{  whatr1  	pageCountrG   ra  pagerefrsrclistetracers   &&&        r'   _getPageInfoDocument._getPageInfol  s    >>>T...;<<ii2<S%BSBS2T2TE))#.Z_ZnZnorZs	!eNA>n--t$++C3--gu7T7TU???ca@r)   c                    \        V 4      pV'       g   V'       g   \        \        4      h\        VRW^ ^ ^ ^ ^ R4
      pV# )z+
Utility: insert font from file or binary.
Nr  )r   r   MSG_FILE_OR_BUFFERJM_insert_font)r&   fontfile
fontbufferra  r   s   &&&  r'   _insert_fontDocument._insert_font  s>     t$
011sD(1aArRr)   c                    V P                   p\        V\        P                  4      '       g   Q h \        P                  ! V4      p\        T4      #   \
         d    \        ^8  d   \        4         R# i ; i)zLoad first outline.N)	r   r@   r   r   fz_load_outlinerk   r  r{   Outline)r&   r1  r>  s   &  r'   _loadOutlineDocument._loadOutline  sf    ii3 0 01111	&&,B |  	#a'N,<	s   A  A54A5c                J    V P                   '       d   \        R4      hQ R4       h)z)Make an array page number -> page object.r   z_make_page_map() is no-op)r   r   r-   s   &r'   _make_page_mapDocument._make_page_map  s"    >>>.//.-.qr)   c                   \        V 4      p^ p\        WQ4      w  rxp	\        P                  ! V\	        R4      4      p
\        WR4      w  rp\        P                  ! V\	        R4      4      pV'       d   TpM	V^,           p\        P
                  ! W4      pV'       g)   V^ 8w  d"   \        P                  ! V\	        R4      V4       \        P                  ! WV4       V^ 8w  Ed   TpVP                  '       dk   \        P                  ! V\	        R4      4      p\        P                  ! V\	        R4      V^,           4       \        P                  ! V\	        R4      4      pK|  V'       g   \        P                  ! W4       TpVP                  '       dk   \        P                  ! V\	        R4      4      p\        P                  ! V\	        R4      V^,
          4       \        P                  ! V\	        R4      4      pK|  MV'       d   TpVP                  '       dk   \        P                  ! V\	        R4      4      p\        P                  ! V\	        R4      V^,           4       \        P                  ! V\	        R4      4      pK|  M:W8  d   \        P                  ! W4       M\        P                  ! W^,           4       VP                  P                  '       d!   \        P                  ! VP                  4       V P                  4        R# )z"Move or copy a PDF page reference.r@  r  r  N)r   pdf_lookup_page_locr   r  r  r  rU  pdf_array_insertr   pdf_dict_get_intrP  r  r   r  _reset_page_refs)r&   r{  nbbeforecopyra  samepage1parent1i1rM  page2parent2i2rO  posr   r  s   &&&&&             r'   _move_copy_pageDocument._move_copy_page  s8   t$ 1#;""GXf-=>0#:""GXf-=>Cq&C . 	x'97Cc219F###..8IJ&&0A519M++VXh5GH&&2 '''!22FHW<MNE**FHW4EuqyQ"//(9KLF '''!22FHW<MNE**FHW4EuqyQ"//(9KLF (
 8**E6**E6:>>&&&''8r)   c                Z   V P                   '       g   V P                  '       d   \        R4      h\        '       d$   \        P
                  ! V P                  WV4       M\        V 4      p\        P                  ! \        P                  P                  4      pW%n        W5n        \        P                  ! 4       pVR8  d   \        \        4      h\        P                  ! V^4      p\        P                   ! WE^ Wv4      p\        P"                  ! WAV4       V P%                  4        W,          # )zMake a new PDF page.r  r  )r   r  r   r  r   _newPager   r   r   rq  
Fixed_UNITr  r  FzBufferr  pdf_add_new_dictpdf_add_pagepdf_insert_pager5  )	r&   r{  r  r3  ra  mediaboxcontentsri  page_objs	   &&&&     r'   rD  Document._newPage  s    >>>T...;<<;NNDIIs6:"4(C||ELL$;$;<HK K~~'HRx .11 ..sA6I))3!YQH!!3X6 	yr)   c                	2    \        V 4      p\        W!4       R # r+   )r   _remove_dest_range)r&   numbersra  s   && r'   _remove_links_toDocument._remove_links_to  s    t$3(r)   c                	   \        V 4      p\        P                  ! W!^ 4      p\        P                  ! V\	        R4      4       \        P                  ! V\	        R4      4       \        P
                  ! V^4      p\        ^4       F  p\        P                  ! VR4       K  	  \        P                  ! V\	        R4      V4       R# )rx   r  r  皙?r  N)	r   r   r  rH  r  rR  rS  rT  rU  )r&   r  ra  rE   rp  rg  s   &&    r'   r  Document._remove_toc_item  s    t$%%c3D(6"23D(3-0##S!,qA%%uc2 D(3-7r)   c                   \        V RR4      '       d   R# V P                  P                  4        Uu. uF  qNK  	  ppV F  pV'       g   K  VP                  4        RpK!  	  V P                  P	                  4        R# u upi )z,Invalidate all pages in document dictionary.r   TN)r   r  r  r   clear)r&   r  pagesr   s   &   r'   r5  Document._reset_page_refs  sk    4d++ OO22454q45Dt  	 6s   
A?c                	   \        V 4      p\        P                  ! R 4      p\        P                  ! \        P                  ! V4      \        R4      4      p\        P                  ! WC4       \        P                  ! V\        P                  ! V^ 4      V\        R4      4       V P                  4       pV P                  VRR7      pVP                  RRV R24      pV P                  WV4       R# )	r  r  r  T
compressedz/Nums[]z/Nums[r  N)r   r   r  r  r  r  rH  rV  rR  pdf_catalogxref_objectr  update_object)r&   labelsra  r  r  r  r   s   &&     r'   _set_page_labelsDocument._set_page_labels  s    t$''5
!!%"3"3C"8(6:JK4,D%"5"5c1"=z8TZK[\!6||Ixq'9:4&r)   c                   \        V 4      p\        P                  ! Wq^ 4      pV'       d"   \        P                  ! V\	        R4      V4       V'       dM   \        P
                  ! V\	        R4      4       \        Wr4      p	\        P                  ! V\	        R4      V	4       \        P                  ! V\	        R4      V4       V'       dj   \        P                  ! V^4      p
\        ^4       F!  pWk,          p\        P                  ! W4       K#  	  \        P                  ! V\	        R4      V
4       M$Ve!   \        P
                  ! V\	        R4      4       Ve   \        P                  ! V\	        R4      4      P                  '       dk   \        P                  ! V\	        R4      4      pV^ 8  d   VRJ g   V^ 8  d5   VR	J d-   VR
,          p\        P                  ! V\	        R4      V4       R# R# R# R# R# )z2
"update" bookmark by letting it point to nowhere
Titler  r  r  r  Nr  FTr  )r   r   r  r  r  rH  r  rU  rP  rR  rS  rT  r  r   r4  )r&   r  actionr  r  r  rp  ra  rE   r  r  rg  r  s   &&&&&&&      r'   _update_toc_itemDocument._update_toc_item  s|    t$%%s!4**D(72CUKhv&67%s3ChsmS9hsmU;##S!,A1XH))10  hsmQ7hsm4!!4'):;FFF**D(72CDEh%/QUx4?ORA**D(72CQG @PU G  r)   c           	     4   \        V ^ R7      pVP                  '       g   R# \        P                  ! \        P                  ! V4      \        R4      \        R4      \        R4      \        R4      4      p\        4       pVP                  '       d   \        P                  ! V4      '       dm   \        P                  ! V4      p\        V4       FG  p\        P                  ! W%4      pVP                  \        \        P                  ! V4      4      4       KI  	  V# )z&Get list of field font resource names.r  Nr  r  r  r  )r   r   r   r   r  r  r   r  r  rS  r  ro   r	  r  )r&   ra  r  r  rG   rg  r  s   &      r'   	FormFontsDocument.FormFonts-  s     ta0~~~##!!#& $   1 1% 8 8""5)A1X**54.u/@/@/CDE  r)   c                t    \        V 4      p\        WAW#4       \        P                  ! VP                  4       R# )zAdd a new OC layer.N)r   JM_add_layer_configr   ll_pdf_read_ocgr   )r&   r   creatoronra  s   &&&& r'   	add_layerDocument.add_layerB  s(    t$S4s~~.r)   c                p   ^ p\        V 4      p\        P                  ! V^4      p\        P                  ! V\	        R4      \	        R4      4       \        P
                  ! V\	        R4      V4       \        P                  ! V\	        R4      ^4      p	V'       g"   \        P                  ! V	\	        R4      4       M]\        V\        4      '       g   Q R\        T4      : R\        : 24       h\        P                  ! V	\        P                  ! V4      4       \        P                  ! V\	        R4      ^4      p
\        P                  ! R	4      p\        P                  ! W^4      p\        P
                  ! V\	        R
4      R4       V'       d#   \        P                  ! V\	        R4      V4       M!\        P                  ! V\	        R4      R4       \        P                  ! Wx4      p\        V4      p\        P                   ! V\	        R4      4      p\        P                  ! W4       VR8  d   \        P                   ! V\	        R4      4      p\        P"                  ! V4      '       g   \%        \&        4      h\        P(                  ! W4      pVP*                  '       g   \%        \&        4      hM \        P                   ! V\	        R4      4      p\        P                   ! V\	        R4      4      pVP*                  '       g"   \        P                  ! V\	        R4      ^4      p\        P                  ! W4       V'       dU   \        P                   ! V\	        R4      4      pVP*                  '       g"   \        P                  ! V\	        R4      ^4      pMS\        P                   ! V\	        R4      4      pVP*                  '       g"   \        P                  ! V\	        R4      ^4      p\        P                  ! W4       \        P,                  ! VP*                  4       \        P.                  ! V4      pV# )zAdd new optional content group.r  OCGr*  IntentViewz)fixme: intent is not a str. type(intent)= type=UsageCreatorInfoCreatorPyMuPDFr  ArtworkOCGsConfigsr  OrderONOFFr  )r   r   rG  rU  r  r  rX  rK  r@   r  r   r  rY  r\  rY  JM_ensure_ocpropertiesr  rI  r   MSG_BAD_OC_CONFIGr  r   rm  r  )r&   r   configro  intentusager  ra  ocgintentsuse_forci_namecre_infoindocgocpr  cfgs   &&&&&&           r'   add_ocgDocument.add_ocgH  s   t$ $$S!,3 0(5/B&&sHV,<dC**30BAF  (6*:;FC((LBT&\O7TGLL1   %*<*<V*DE))#x/@!D$$]3**7Q?&&x)1DiP##Hhy.A5I##Hhy.A9M%%c/ %S)  hv&67S)B;$$S(9*=>C%%c** "344%%c2C>>> "344 " $$S(3-8C  hw&78~~~**30A1ECS)$$S(4.9C>>>..sHTNAF##C%9C>>>--c8E?AFS) 	cnn-'r)   c                    V P                   '       d   \        R4      h\        P                  ! V P                  V4      pV'       d&   RV n        RV n        V P                  4        RV n        V# )zDecrypt document.r   FT)r   r   r   fz_authenticate_passwordr   r  r  r   )r&   passwordr  s   && r'   authenticateDocument.authenticate  sU    >>>.//,,TYYA %D %DMMODL
r)   c                p    \        V ^ R7      pVP                  '       g   R# \        P                  ! V4      # )z-Check whether incremental saves are possible.r  F)r   r   r   pdf_can_be_saved_incrementallyr&   ra  s   & r'   can_save_incrementallyDocument.can_save_incrementally  s+    ta0~~~33C88r)   r  Twidgetsc               $    V ^8  d   QhRRRRRR/# )r  r  r   r  rs  r  r,   )r  s   "r'   r  rt    s&     @ @d @D @D @r)   c               p    \        V 4      p\        P                  ! V\        V4      \        V4      4       R# )a  Convert annotations or fields to permanent content.

Notes:
    Converts annotations or widgets to permanent page content, like
    text and vector graphics, as appropriate.
    After execution, pages will still look the same, but no longer
    have annotations, respectively no fields.
    If widgets are selected the PDF will no longer be a Form PDF.

Args:
    annots: convert annotations
    widgets: convert form fields

N)r   r   pdf_bake_documentr6   )r&   r  r  ra  s   &$$ r'   bakeDocument.bake  s(     t$S[#g,?r)   c                |    V P                   '       d   \        R4      h\        P                  ! V P                  4      # )zNumber of chapters.r   )r   r   r   fz_count_chaptersr   r-   s   &r'   rw  Document.chapter_count  s.     >>>.//&&		22r)   c                    V P                   '       d   \        R4      h\        P                  ! V P                  4      pV^ 8  g   W8  d   \        R4      h\        P
                  ! V P                  V4      pV# )zPage count of chapter.r   zbad chapter number)r   r   r   r  r   fz_count_chapter_pages)r&   rz  chaptersrX  s   &&  r'   rx  Document.chapter_page_count  s^    >>>.//**DII6Q;'-233,,diiAr)   c                    \        V RR4      '       d   \        R4      h\        V R4      '       d   V P                  '       d   RV n        V P	                  4        RV n        / V n        RV n        R# )zClose document.r   Tr   _outlineN)r   r   r=   r  r5  r   r  r   r-   s   &r'   r  Document.close  s^    4d++.//4$$ DM ! 	r)   c                   V P                   '       g   V P                  '       d   \        R4      hV P                  pTpTp\        P
                  ! V4      pV^ 8  d   ^ pWW^,
          8  d
   V^,
          pV^ 8  d
   V^,
          pWg^,
          8  d
   V^,
          p\        \        4      p\        WEWc4      p	\        \        4      p
\        W4       F  p\        \        V,           4       K  	  V	# )z[Convert document to a PDF, selecting page range and optional rotation. Output bytes object.r  )r   r  r   r   r   r  r9   JM_mupdf_warnings_storeJM_convert_to_pdfrS  rv   )r&   r  r  r`  fz_docr  rT  srcCountlen0r1  len1rg  s   &&&&        r'   r  Document.convert_to_pdf  s    >>>T...;<<''/6B1AB6AB1AB*+B7*+t"A.q124 #
r)   c                    V ^8  d   QhRRRR/# r  r{  r6   r  r,   )r  s   "r'   r  rt    s     ; ;S ;c ;r)   c                    V P                   '       d   \        R4      h\        V 4      pV\        V4      9  g   V\        RV4      9  d   \        R4      h^p^pVR8X  d   V^,
          p^ pV P	                  WWE4      # )zCopy a page within a PDF document.

This will only create another reference of the same page object.
Args:
    pno: source page number
    to: put before this page, '-1' means after last page.
r   r  r  r   r   r9   rS  rA  r&   r{  r  rv  r7  r8  s   &&&   r'   	copy_pageDocument.copy_page  s|     >>>.//Y
5,,U2z221228aBF##CV::r)   c                J   V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\        P
                  ! \        P                  ! V4      \        R4      4      pVP                  '       d#   \        P                  ! V\        R4      4       R# R# )zDelete XML metadata.r  r  MetadataN)
r   r  r   r   r   r  r  r  r   rH  )r&   ra  r  s   &  r'   del_xml_metadataDocument.del_xml_metadata  sq    >>>T...;<<t$!!5#4#4c#:HV<LM???hz&:; r)   c                   V ^8  d   QhRR/# )r  r{  r6   r,   )r  s   "r'   r  rt    s     & &s &r)   c                $    V P                  V4      # )z$Delete one page from a PDF.
        )r  )r&   r{  s   &&r'   r  Document.delete_page  s       %%r)   c                   V P                   '       g   \        R4      hV P                  '       d   \        R4      hV P                  pR;rEV'       d   V'       d   \        R4      hVP	                  RR4      pVP	                  RR4      pV^ 8  d   WC,          pK  V^ 8  d   WS,          pK  YEu;8:  d   V8  g   M \        R4      h\        \        WE^,           4      4      pM\        V4      ^8  g   V. 8X  d   \        R4      h\        V4      ^8X  du   Vw  rE\        V4      \        J d   \        V4      \        J g   \        R4      hWE8  d   YTrTYEu;8:  d   V8  g   M \        R4      h\        \        WE^,           4      4      pMM\        V^ ,          \        4      '       d   V^ ,          pV^ 8  d   Ws,          pK  V3pM\        V^ ,          4      p\        \        \        \        V4      4      4      pV. 8X  d   \        R	4       R
# VP                  4        V^ ,          ^ 8  g   VR,          V8  d   \        R4      h\!        V4      pV P#                  4       p	\%        V P'                  4       4       F3  w  rW,          ^,          ^,
          V9   g   K"  V P)                  V4       K5  	  V P+                  V4       \-        V4       F  p
V P/                  V
4       K  	  V P1                  4        R
# )zDelete pages from a PDF.

Args:
    Either keywords 'from_page'/'to_page', or two integers to
    specify the first/last page to delete.
    Or a list/tuple/range object, which can contain arbitrary
    page numbers.
    Or a single integer page number.
r  r   z*cannot mix keyword and positional argumentr  r  r  z need 1 or 2 positional argumentszboth arguments must be intznothing to deleteNr  )r  r   r   rv  r:   r   rS  r9   r   r6   r@   r   r  setrv   sort	frozensetget_tocrZ  r  r  rQ  reversedr  r5  )r&   r  kwrv  r  r  rP  r{  frozen_numberstocrg  r  s   &*,         r'   r  Document.delete_pages  sQ    {{{[))>>>.//__

 !MNN{B'Ay"%Aa%a%&J& !566E!UO,G4y1}
 !CDD4yA~Q347c>$%ABB5q*
*$%9::aQ0DGS))1gAg%C&Q.s3G-.b='(1:>WR[J6122"7+lln !7!7!9:GAvay1}.%%d+ ; 	n-'"Aa  # 	r)   c               0    V ^8  d   QhRRRRRRRRRRR	R
/# )r  r   r  r4  
ByteStringrj   r  rW  r  rs  r  r,   )r  s   "r'   r  rt  Y  sD     $ $$$ $ 	$
 $ $r)   c                J   V P                  4       pW9   d   \        RV R24      hVf   TpVf   TpVf   TpV P                  VVVVVR7      p\        4       pV P	                  VRR4       V P	                  VR\        V4      4       V P	                  VR\        V4      4       V# )a$  Add an item to the EmbeddedFiles array.

Args:
    name: name of the new item, must not already exist.
    buffer_: (binary data) the file content.
    filename: (str) the file name, default: the name
    ufilename: (unicode) the file name, default: filename
    desc: (str) the description.
zName 'z' already exists.r4  rj   rW  r  r  z/EmbeddedFileParams/CreationDateParams/ModDate)r  r   r  get_pdf_nowr  r  )	r&   r   r4  rj   rW  r  r  r  dates	   &&&&&&   r'   embfile_addDocument.embfile_addY  s      &&(	vdV+<=>>H I<D  !# !  }$8$ 5{47HI$ 0+d2CDr)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  rt    s     ) )s )r)   c                4    \        V P                  4       4      # )zGet number of EmbeddedFiles.)r9   r  r-   s   &r'   embfile_countDocument.embfile_count  s    4%%'((r)   c                   V ^8  d   QhRR/# )r  rE   r  r,   )r  s   "r'   r  rt    s     & & 6 &r)   c                F    V P                  V4      pV P                  V4      # )a  Delete an entry from EmbeddedFiles.

Notes:
    The argument must be name or index of an EmbeddedFiles item.
    Physical deletion of data will happen on save to a new
    file with appropriate garbage option.
Args:
    item: name or number of item.
Returns:
    None
)r  r  r&   rE   r  s   && r'   embfile_delDocument.embfile_del  s%     %%d+  %%r)   c                    V ^8  d   QhRRRR/# )r  rE   r  rs  r  r,   )r  s   "r'   r  rt    s     	* 	* 6 	*5 	*r)   c                F    V P                  V4      pV P                  V4      # )zGet the content of an item in the EmbeddedFiles array.

Args:
    item: number or name of item.
Returns:
    (bytes) The file content.
)r  r  r  s   && r'   embfile_getDocument.embfile_get  s%     %%d+$$S))r)   c                    V ^8  d   QhRRRR/# )r  rE   r  rs  r7   r,   )r  s   "r'   r  rt    s      !7 D r)   c                   V P                  V4      pRV P                  4       V,          /pV P                  W#4      pV P                  VR4      w  rVVR8w  d   WcR&   V P                  VR4      w  rVVR8w  d   WcR&   V P                  VR4      w  rWVR8w  d6   \        P
                  ! VP                  4       4      P                  4       VR&   V# )	zGet information of an item in the EmbeddedFiles array.

Args:
    item: number or name of item.
Returns:
    Information dictionary.
r   r  r  r  r  r  zParams/CheckSumchecksum)r  r  r  xref_get_keyr  r  r  decode)r&   rE   r  r  r  r  r  md5s   &&      r'   embfile_infoDocument.embfile_info  s     %%d+D..056!!#0##D*?@;'+^$##D*:;;"&Y""4):;;#+#3#3CJJL#A#H#H#JHZ r)   c                   V ^8  d   QhRR/# r  rs  r   r,   )r  s   "r'   r  rt    s      t r)   c                ,    . pV P                  V4       V# )z#Get list of names of EmbeddedFiles.)r  )r&   r  s   & r'   r  Document.embfile_names  s    	I&r)   c               0    V ^8  d   QhRRRRRRRRRRR	R
/# )r  rE   r  r4  OptBytesrj   r  rW  r  rs  r  r,   )r  s   "r'   r  rt    sD      (  	
  r)   c                    V P                  V4      pV P                  VVVVVR7      p\        4       pV P                  VR\	        V4      4       V# )a]  Change an item of the EmbeddedFiles array.

Notes:
    Only provided parameters are changed. If all are omitted,
    the method is a no-op.
Args:
    item: number or name of item.
    buffer_: (binary data) the new file content.
    filename: (str) the new file name.
    ufilename: (unicode) the new filen ame.
    desc: (str) the new description.
r  r  )r  r  r  r  r  )	r&   rE   r4  rj   rW  r  r  r  r  s	   &&&&&&   r'   embfile_updDocument.embfile_upd  s^    & %%d+  !# !  }$ 0+d2CDr)   c           
     h   \        V 4      p\        P                  ! WA4      p\        P                  ! V\	        R4      4      p\        P                  ! V\	        R4      4      p\        P
                  ! V\	        R4      4      '       Ed   \        P                  ! V4      P                  R4      '       EgX   \        P                  ! V\	        R4      4      pVP                  '       d   \        P                  ! V4      '       d"   \        P                  ! V\	        R4      4      p	MTp	\        WA4      p
V
R8w  d    V'       g   \        WA4      p\        V4      pMRpV'       gL   \        \        P                  ! V	4      4      \        V
4      \        \        P                  ! V4      4      V3pV# \        \        \        P                  ! V	4      4      \         \        V
4      \"        \        \        P                  ! V4      4      \$        V/p V# V'       g   R
pV# \        R	\         R	\"        R	\$        R/pV# )z4
Get a font by xref. Returns a tuple or dictionary.
r  r  r  CIDFontTypeBaseFontr*  n/ar)   r`   )r`   r`   r`   r)   )r   r   rJ  r  r  pdf_name_eqr  r5   r   pdf_is_nullJM_get_fontextensionr  r#  r  r	  r2  dictkey_extdictkey_typer1  )r&   r  	info_onlynamedra  r  rb  subtypebasefontbnamer  r4  bytes_r   s   &&&&          r'   extract_fontDocument.extract_font  s   
 t$##C.""3(89$$S(9*=>eXf%566))73>>}MM))#x
/CDH&&&%*;*;H*E*E**30@A &s1Ce|I+C6)'2+E,=,=e,DE)#.)%*;*;G*DE	. 	 %&9%:K:KE:R&S#%6s%;$&78I8I'8R&S'	  	 $ 	 %b#R$b'	 	r)   c                *   V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\	        V^\
        P                  ! V4      ^,
          4      '       g   \        \        4      h\
        P                  ! W!^ 4      p\
        P                  ! V\        R4      4      p\
        P                  ! V\        R4      4      '       g   \        R4      h\
        P                  ! V\        R4      \        R4      4      pVP                  '       d   \
        P                  ! V4      pM^ p\
        P                  ! W#4      p\!        4       p\#        Wx4       Wh\$        &   \
        P&                  ! VP)                  4       4      V\*        &   V# )z(Get image by xref. Returns a dictionary.r  r  Imageznot an imageSMaskMask)r   r  r   r   r  r   r  r  r  r  r  r  pdf_dict_getar   r  pdf_load_imager7   _make_image_dictdictkey_smaskr<  r  dictkey_cs_name)	r&   r  ra  r  r  r  smaskr2  r   s	   &&       r'   extract_imageDocument.extract_image	  s(   >>>T...;<<t$a!3!3C!8!:;;l++$$S2$$S(9*=>  (7*;<<n--Xg%68HI<<<$$Q'EE ""3,V!!=#66s~~7GH?	r)   Fc                L    V P                  VVVVVVVVV	V
VVVVVVVVVVR7      # )z(
Save PDF using some different defaults
)garbagecleandeflatedeflate_imagesdeflate_fontsincrementalr  expandlinearpretty
encryptionpermissionsowner_pwuser_pw	no_new_idpreserve_metadatause_objstmscompression_effortraise_on_repair)save)r&   rj   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r!  s   &&&&&&&&&&&&&&&&&&&&&r'   ez_saveDocument.ez_save'  sV    4 yy-+'%'!#"3'#5 /)   	r)   c                    V P                   '       g   V P                  '       d   \        R4      h\        P                  ! V P
                  V4      pVP                  VP                  3# )z-Find new location after layouting a document.r  )r   r  r   r   fz_lookup_bookmark2r   rz  r   )r&   r  locations   && r'   find_bookmarkDocument.find_bookmarkX  sM    >>>T...;<<,,dii<..r)   c                   \        V 4      p\        P                  ! V4      p \        V^ V^,
          4      '       d   \        VR	V^,
          4      '       g   \	        \
        4      h\        P                  ! \        P                  ! W14      4      p\        P                  ! V4      p\        P                  ! V\        R4      4      pVP                  '       Ed   \        P                  ! V4      p\        P                  ! W84      p	\        V4       EFO  p
\        P                  ! Wz4      p\        P                  ! V\        R4      4      p\        P                   ! V\        R4      4      '       d   Kb  \        P"                  ! VR4      P                  '       d   K  \        P                  ! \        P                  ! V4      4      p\        P$                  ! V4      p\        P&                  ! W>V4       \        P(                  ! W>^ 4      p\        P*                  ! V\        R4      4       \        P*                  ! V\        R4      4       \        P,                  ! W4       EKR  	  \        P.                  ! V\        R4      V	4       \1        V4      pV'       d   VP                  '       dp   \        P2                  ! V\        P4                  ! R4      \        P6                  ! 4       ^ 4      p\9        VVV^4       \        P.                  ! V\        R4      V4       \        P$                  ! V4      p\        P&                  ! W>V4       \        P(                  ! W>^ 4      p\        P:                  ! W2V4       \        P<                  ! VP                  4       V P?                  4        R#   \        P<                  ! TP                  4       i ; i)
zMake a full page duplicate.r  r  r  r;  r      rS  Nr  ) r   r   r  r  r   r  r  r  r  r  r  r   r  rR  rS  r  r  r  pdf_create_objectpdf_update_objectr  rH  rK  rU  JM_read_contentspdf_add_streamr  PdfObjr0  rI  r  r5  )r&   r{  r  ra  rv  r:  r=  
old_annotsrG   
new_annotsrg  r  r  copy_or  r%  rK  s   &&&              r'   fullcopy_pageDocument.fullcopy_page_  s   t$**C0
0	9S!Z!^44#BJN;; .11..0I0I30TUE++U3E++UHX4FGJ $$$''4"00#9
qA++Z;A#00!Xi5HIG(('8G3DEE **Au5@@@ "44e6P6PRS6TUF 22C8D++S?"33SBF&&0AB&&>((*= " ""E8H+=zJ #E*C s~~~ //e6Z6Z\`6achcococqstu #xa8""E8J+?J **C0D##S6**Cq9E!!3E2''8 ''8s   E5N& DN& *C
N& &"Oc               0    V ^8  d   QhRRRRRRRRRRR	R
/# )r  r1  r
  r  r6   r  r  fontdictOptDictrs  r   r,   )r  s   "r'   r  rt    sL     c ccc c 	c
 c cr)   c           
        \        W4      pVf   Vf(   \        P                  ! W4      w  rgrp
RVRVRVRV	RV
/pM-VR,          pVR,          pVR,          pVR,          pVR,          pVR	8X  d   \        R
4      hVR9   d   RpMRpVR9   d   ^ pM VR9   d   ^pMVR9   d   ^pMVR9   d   ^pMRpWR&   VR8X  d   \        pMVR8X  d   \
        pMRpWR&   WR&   W.pV P                  P                  V4       M$V^,          pVR,          pVR,          pVR,          pVf   ^ pM\        V4      p\        RV4      pW8:  d   V# V^ 8  d+   V P                  WR,          VR,          VR,          W4      pMRpWR&   WE^&   \        W4       V# )aa  Get list of glyph information of a font.

Notes:
    Must be provided by its XREF number. If we already dealt with the
    font, it will be recorded in doc.FontInfos. Otherwise we insert an
    entry there.
    Finally we return the glyphs for the font. This is a list of
    (glyph, width) where glyph is an integer controlling the char
    appearance, and width is a float controlling the char's spacing:
    width * fontsize is the actual space.
    For 'simple' fonts, glyph == ord(char) will usually be true.
    Exceptions are 'Symbol' and 'ZapfDingbats'. We are providing data for these directly here.
Nr   r   r  ascender	descenderr  simpler`   zxref is not a fontTFZapfDingbatsSymbolglyphsr  )Type1MMType1TrueType)FangtiMing)HeitiSong)GothicMincho)DotumBatangr  )CheckFontInfor  _get_font_propertiesr   zapf_glyphssymbol_glyphsr  ro   r9   r'  r  UpdateFontInfo)r1  r  r  r  r7  fontinfor   r  stypeascdscr  r<  r?  oldlimitr  s   &&&&&           r'   get_char_widthsDocument.get_char_widths  s   ( !+-2-G-G-R*5sDE3  'uo (#J/!(+by !566 88 ))**--,,!'X~%$!&!'X#+Z 'HMM  *{Hh'Fh'F
+H>H6{Hc5/Ma<))v&*9MwF F#s%r)   c                   \        V 4      p\        P                  ! \        P                  ! V4      \	        R4      \	        R4      4      pVP
                  '       g   R# VR8X  d"   \        P                  ! V\	        R4      4      pM5\        P                  ! \        P                  ! V\	        R4      4      V4      pVP
                  '       g   \        \        4      h\        V4      pV# )z,Content of ON, OFF, RBGroups of an OC layer.r  OCPropertiesNr  r}  r  )r   r   r   r  r  r   r  r  r   r  JM_get_ocg_arrays)r&   r  ra  r  r  r   s   &&    r'   	get_layerDocument.get_layer  s    t$!!!!3' (
 ~~~R<$$c8C=9C%%&&Xi-@AC ~~~/00$	r)   c                   \        V 4      p\        P                  ! V4      pV^8X  dg   \        P                  ! \        P                  ! V4      \        R4      \        R4      \        R4      4      p\        P                  ! V4      '       g   ^ p. p\        P                  ! 4       p\        V4       FG  p\        P                  ! WV4       RVRVP                  RVP                  /pVP                  V4       KI  	  V# )zShow optional OC layers.r  rX  r}  numberr   rn  )r   r   pdf_count_layer_configsr   r  r  rI  PdfLayerConfigrS  pdf_layer_config_infor   rn  ro   )r&   ra  rG   r  r   r8  rg  rE   s   &       r'   
get_layersDocument.get_layers  s    t$))3/6%%%%s+V$^,Y'	C %%s++##%qA''6aDIIt||D
 IIt  	r)   c                    V P                   '       g   V P                  '       d   \        R4      h\        V 4      p^ p\	        V4       \
        P                  ! V4      pV# )zMake new xref.r  )r   r  r   r   ENSURE_OPERATIONr   r,  )r&   ra  r  s   &  r'   get_new_xrefDocument.get_new_xref+  sN    >>>T...;<<t$&&s+r)   c               $    V ^8  d   QhRRRRRR/# )r  r1  r
  r  r6   rs  r,   )r  s   "r'   r  rt  5  s!      J c c r)   c                4   V P                   '       g   V P                  '       d   \        R4      hV P                  VR4      w  r#VR8w  g   VR	9  d   \        RV 24      hV P                  VR4      w  r$VR8w  d   ^ # \	        VP                  RR4      4      pV# )
zReturn optional content object xref for an image or form xobject.

Args:
    xref: (int) xref number of an image or form xobject.
document close or encryptedr  r   bad object type at xref r  r  0 Rr`   /Image/Form)r   r  r   r  r6   r  )r1  r  r  r   r  r   s   &&    r'   r  Document.get_oc5  s     ===C,,,:;;""43;$&997v>??  t,;E2&'	r)   c           	     8   \         P                  ! R4      p\        V 4      p\         P                  ! \         P                  ! \         P
                  ! V4      \        R4      4      \        R4      \        R4      4      p\        4       p\         P                  ! V4      '       g   V# \         P                  ! V4      p\        V4       EFN  p\         P                  ! W64      p\         P                  ! V4      p\         P                  ! \         P                  ! V\        R4      4      4      p	\         P                  ! V\        R4      V\        R4      4      p
RpV
P                  '       d   \         P                  ! V
4      p\!        4       p\         P                  ! V\        R	4      4      pVP                  '       d   \         P"                  ! V4      '       d'   VP%                  \         P                  ! V4      4       M\         P                  ! V4      '       d   \         P                  ! V4      p\        V4       F\  p\         P                  ! W4      p\         P"                  ! V4      '       g   K7  VP%                  \         P                  ! V4      4       K^  	  \&        R8  d/   \         P(                  ! 4       p\         P*                  ! VVW4      pM+\         P*                  ! V\         P,                  ! 4       W4      pR
V	RVRV'       * RV/pTpVVV&   EKQ  	  V# )z&Show existing optional content groups.rx  r  rX  r|  r*  rw  r  Nrt  r   r  ro  r  )r        )r   r  r   r   r  r  r  r7   rI  r  rS  r  r  r  r   r  r   r  ro   mupdf_version_tuplePdfResourceStackpdf_is_ocg_hiddenr0  )r&   r  ra  ocgsr   rG   rg  r  r  r   r  r  r  r  r  r  r  resource_stackhiddenrE   r  s   &                    r'   get_ocgsDocument.get_ocgsF  sM   /t$""""E$5$5s$;Xf=MN( 
 V!!4((I&qA%%t/C##S)D++U-?-?hvFV-WXD%%sHW,=r8ICVWCE~~~))3/fG''hx.@AF   $$f--NNE$5$5v$>?''00++V4A"1X!//; ,,a00#NNE,=,=q,AB & #k1!&!7!7!900#~uR00#u||~uRDgf*U	D DBI? @ 	r)   c               $    V ^8  d   QhRRRRRR/# )r  r1  r
  r  r6   rs  r7   r,   )r  s   "r'   r  rt  u  s+     AH AHj AH AH AHr)   c                   V\        V P                  4       4      9  d   \        R4      hV P                  VRR7      pRV9  d   \        R4      h\	        V4      pVP                  R4      pVP                  RV4      pV^ 8  g   V^ 8  d   RpMBW$^,           V P                  R	R
4      P                  4       p\        \        \        V4      4      pVP                  R4      pV^ 8  d   RpMOVP                  RV4      pV^ 8  d   VP                  RV4      pV^ 8  d   \        R4      hW$^,           V^,            pVP                  R4      pV^ 8  d   RpM^ ;rTpV	^8  g   W8w  dK   V^,          pWS8  g   \        R4      hW%,          R8X  d
   V	^,          p	W%,          R8X  g   KL  V
^,          p
KW  W$^,           V^,            pVP                  RR4      P                  RR4      P                  RR4      pVP                  RR4      P                  RR4      P                  RR4      p^ RIp VP                  V4      pRVRVRVR V/#   \         d    \        4        \        RT: 24       h i ; i)!a`  Return the definition of an OCMD (optional content membership dictionary).

Recognizes PDF dict keys /OCGs (PDF array of OCGs), /P (policy string) and
/VE (visibility expression, PDF array). Via string manipulation, this
info is converted to a Python dictionary with keys "xref", "ocgs", "policy"
and "ve" - ready to recycle as input for 'set_ocmd()'.
bad xrefTr[  
/Type/OCMDzbad object type/OCGs[r  Nrk  r   /P/r  ro  zbad object at xrefz/VE[r  z/Andz"and",z/Notz"not",z/Orz"or",z 0 R] 0 Rr   z][z],[zbad /VE key: r  rv  policyve)rS  xref_lengthr   r^  r9   r   r  r8   r   r  r6   jsonloadsrk   r{   rv   )r1  r  r   textlenp0rJ  rv  r  r  lprpr  s   &&          r'   get_ocmdDocument.get_ocmdu  sK    uS__.//Z((t5t#.//d)YYx YYsB6R!VDQ$,,UC8>>@DC'DYYu6F4$BAvYYtR(Av !5661frAv.YYv6BKBBq&BHa|$%9::8s?!GB8s?!GB1frAv&B

68,*( 
 GS)11&#>FFtUSBZZ^
 fdHfdBGG	   -v./s   ,I &I-c                   . p\        V ^ R7      pVP                  '       g   V# \        P                  ! \        P                  ! V4      \        R4      4      pVP                  '       g   V# \        P                  ! V\        R4      4      pVP                  '       g   V# \        P                  ! V\        R4      4      pVP                  '       g   V# \        WQ4      pV# )z!Get list of outline xref numbers.r  r  r  r  )r   r   r   r  r  r  r  )r&   r  ra  r  r  r  s   &     r'   r  Document.get_outline_xrefs  s    ta0~~~L!!%"3"3C"8(6:JKL##D(:*>?   L""68G+<=L .r)   c               $    V ^8  d   QhRRRRRR/# r  r{  r6   fullr   rs  r   r,   )r  s   "r'   r  rt    s!      # T T r)   c                z   V P                   '       g   V P                  '       d   \        R4      hV P                  '       g   R# \	        V4      \
        Jd    VP                  pV P                  V^4      pV'       g   V Uu. uF  qDRR NK	  	  up# V#   \         d    \        4        \        R4      hi ; iu upi )z1Retrieve a list of fonts used on a page.
        r  zneed a Page or page numberNr,   r  )
r   r  r   r  r   r6   r]  rk   r{   r   r&   r{  r  r  rH   s   &&&  r'   get_page_fontsDocument.get_page_fonts  s     >>>T...;<<{{{I9C?jj Q'$'(CqcrFC((
  ?  !=>>?
 )s   B B8!B5c               $    V ^8  d   QhRRRRRR/# r  r,   )r  s   "r'   r  rt    s!     
 
3 
d 
d 
r)   c                    V P                   '       g   V P                  '       d   \        R4      hV P                  '       g   R# V P	                  V^4      pV'       g   V Uu. uF  qDRR NK	  	  up# V# u upi )z2Retrieve a list of images used on a page.
        r  Nr,   r  r   r  r   r  r   r  s   &&&  r'   get_page_imagesDocument.get_page_images  sj     >>>T...;<<{{{IQ'$'(CqcrFC((
 )s   "A4c                t    V P                  4        Uu. uF  p\        P                  ! V4      NK  	  up# u upi )zReturn page label definitions in PDF document.

Returns:
    A list of dictionaries with the following format:
    {'startpage': int, 'prefix': str, 'style': str, 'firstpagenum': int}.
)r  r  	rule_dict)r&   rE   s   & r'   get_page_labelsDocument.get_page_labels  s0     372G2G2IJ2I$%2IJJJs   5c                    . pV'       g   V# V P                  4       pV. 8X  d   V# \        V P                  4       F=  p\        P                  ! WT4      pWa8X  g   K!  VP                  V4       V'       g   K<   V# 	  V# )zReturn a list of page numbers with the given label.

Args:
    doc: PDF document object (resp. 'self').
    label: (str) label.
    only_one: (bool) stop searching after first hit.
Returns:
    List of page numbers having this label.
)r  rS  rv  r  get_label_pnoro   )r1  labelonly_onerP  r`  rg  plabels   &&&    r'   get_page_numbersDocument.get_page_numbers  ss     N%%'R<Ns~~&A((3Fq!8 ' r)   r  r  r  r  r  c               8    V ^8  d   QhRRRRRRRRR	R
RRRRRR/# )r  r1  r
  r{  r6   r  r   r  r+  r  r   r  r   r  rs  'Pixmap'r,   )r  s   "r'   r  rt    sX     ! !!!  	! #! ! ! ! !r)   c          	     b    Vf   \         pVf   \        pW,          P                  VW4VVVR7      # )a  Create pixmap of document page by page number.

Notes:
    Convenience function calling page.get_pixmap.
Args:
    pno: (int) page number
    matrix: pymupdf.Matrix for transformation (default: pymupdf.Identity).
    colorspace: (str,pymupdf.Colorspace) rgb, rgb, gray - case ignored, default csRGB.
    clip: (irect-like) restrict rendering to this area.
    alpha: (bool) include alpha channel
    annots: (bool) also render annotations
)r  r  r  r  r  r  )Identityr  r  )r1  r{  r  r  r  r  r  r  s   &&$$$$$$r'   get_page_pixmapDocument.get_page_pixmap  sB    . >FJx"" #  	r)   c               8    V ^8  d   QhRRRRRRRRR	R
RRRRRR/# )r  r1  r
  r{  r6   optionr  r  r   r  OptInttextpage
'TextPage'r  r   rs  
typing.Anyr,   )r  s   "r'   r  rt  /  sb     L LLL L 	L
 L !L L Lr)   c                4    W,          P                  W#WFR7      # )zExtract a document page's text by page number.

Notes:
    Convenience function calling page.get_text().
Args:
    pno: page number
    option: (str) text, words, blocks, html, dict, json, rawdict, xhtml or xml.
Returns:
    output from page.TextPage().
)r  r  r  )r  )r1  r{  r  r  r  r  r  s   &&&&&&&r'   get_page_textDocument.get_page_text/  s    & x  % KKr)   c                    V ^8  d   QhRRRR/# )r  r{  r6   rs  r   r,   )r  s   "r'   r  rt  D  s      S T r)   c                    V P                   '       g   V P                  '       d   \        R4      hV P                  '       g   R# V P	                  V^4      pV# )z4Retrieve a list of XObjects used on a page.
        r  r,   r  )r&   r{  r  s   && r'   get_page_xobjectsDocument.get_page_xobjectsD  sI     >>>T...;<<{{{IQ'
r)   c                ,   \        V ^ R7      pVP                  '       g   R# \        P                  ! \        P                  ! V4      \        R4      \        R4      \        R4      4      pRpVP                  '       d   \        P                  ! V4      pV# )zGet the /SigFlags value.r  r  r  SigFlagsr  )r   r   r   r   r  r  r  )r&   ra  sigflagssigflags   &   r'   get_sigflagsDocument.get_sigflagsN  sz    ta0~~~I&&!!#& $$	 &&x0Gr)   c               $    V ^8  d   QhRRRRRR/# )r  r1  r
  r<  r   rs  r   r,   )r  s   "r'   r  rt  ^  s&     4 444 4r)   c                  a aa V VV3R loS P                   '       d   \        R4      hS P                  4        S P                  pV'       g   . # ^p. pS! W$V4      pS P                  '       d   S'       g   S P                  V4       V# )zCreate a table of contents.

Args:
    simple: a bool to control output. Returns a list, where each entry consists of outline level, title, page number and link destination (if simple = False). For details see PyMuPDF's documentation.
c                  < V '       Ed:   V P                   P                  '       Ed   V P                  '       d   V P                  pMRpV P                  '       gg   V P                  '       dR   V P
                  R8X  d-   SP                  V P                  4      pV^ ,          ^,           pMV P
                  ^,           pMRpMRpS	'       g,   \        P                  ! V S4      pVP                  W#WV.4       MVP                  W#V.4       V P                  '       d   S! V P                  W^,           4      pV P                  p EKB  V# )zPRecursively follow the outline item chain and record item information in a list.r   r  )r   r   r  is_externalr  r   resolve_linkr  getLinkDictro   downr]  )
olItemr  lvlr  resolver   linkr1  r  r<  s
   &&&    r'   r  !Document.get_toc.<locals>.recurseg  s    &V[[333<<<"LLEE)))zzz!;;",&)&6&6vzz&BG#*1:>D#);;?D!D ,,VS9DLL#d!9:LL#d!34;;;#FKKa@ELr)   r   )r   r   r  outliner  r  )r1  r<  r  r  r  r  r  s   ff    @r'   r  Document.get_toc^  sn    	@ ===.//IfS):::f!!#&
r)   c                :   Rp\        V ^ R7      pVP                  '       d?   \        P                  ! \        P                  ! V4      \        R4      \        R4      4      pVe6   VP                  '       d$   \        P                  ! V4      p\        V4      pV# RpV# )zGet document XML metadata.Nr  r  r  r`   )r   r   r   r   r  r  r"  JM_UnicodeFromBuffer)r&   xmlra  r  r   s   &    r'   get_xml_metadataDocument.get_xml_metadata  s    ta0>>>%%%%c*V$Z(C
 ?s~~~((-D%d+B 	 B	r)   c                    V ^8  d   QhRRRR/# r  r1  r
  rs  r   r,   )r  s   "r'   r  rt    s      
 t r)   c                ^   V P                   '       d   \        R4      hV P                  '       g   \        R4      h\        V P                  4       FY  pV P                  V4       FA  pV^,          \        P                  8X  d   K!  V^,          \        P                  8X  d   K?    R# 	  K[  	  R# )z0Check whether there are annotations on any page.r   r  TF)	r   r   r  rS  rv  page_annot_xrefsr   PDF_ANNOT_LINKrT  r1  rg  rE   s   &  r'   
has_annotsDocument.has_annots  s~    ===.//zzz[))s~~&A,,Q/Q5#7#7747eF\F\;\ 0 '
 r)   c                    V ^8  d   QhRRRR/# r  r,   )r  s   "r'   r  rt    s     
 
z 
d 
r)   c                "   V P                   '       d   \        R4      hV P                  '       g   \        R4      h\        V P                  4       F;  pV P                  V4       F#  pV^,          \        P                  8X  g   K!    R# 	  K=  	  R# )z*Check whether there are links on any page.r   r  TF)r   r   r  rS  rv  r  r   r  r  s   &  r'   	has_linksDocument.has_links  sm    ===.//zzz[))s~~&A,,Q/7e222 0 ' r)   c                	   V P                   '       d   \        R 4      hV P                  4       V n        \	        RRRRRRRRRR	R
RRRRRRRRR/
P                  4        UUu. uF  w  rWP                  V4      3NK  	  upp4      V n        V P                  R4      R8X  d   RMV P                  R4      V P                  R&   R# u uppi )z,cannot initialize - document still encryptedr  r  z
info:Titleauthorzinfo:Authorr  zinfo:Subjectkeywordszinfo:Keywordsrn  zinfo:Creatorproducerzinfo:Producerr  zinfo:CreationDater  zinfo:ModDatetrappedzinfo:Trappedr  r  N)r  r   r,  r  r7   rD   r  r  )r&   r  rH   s   &  r'   r  Document.init_doc  s    KLL))+ %X#L$]%n&%n&*+>%n%n= $eg=&=&SQ,,Q/0 =&  /3.?.?.Mv.Ud[_[l[lmy[zl#s   C
c
                   Rp
\        V\        4      '       dG   VP                  P                  ^8  d   \        \        V4      p\        RVP                  4       4      p
M$\        V\
        4      '       d   Tp
M\        V4      p
V
'       g   \        R4      hV
P                  '       g   V
P                  4       p\        RV4      p
V P                  V
VVVVVVVV	R7	      # )z
Insert an arbitrary supported document to an existing PDF.

The infile may be given as a filename, a Document or a Pixmap. Other
parameters - where applicable - equal those of insert_pdf().
Npngzbad infile parameterra  )r  r  r  r`  r5  r  show_progressfinal)r@   r  r  rG   r  r   tobytesr   r  r  
insert_pdf)r&   infiler  r  r  r`  r5  r  r  r  r4  pdfbytess   &&&&&&&&&&  r'   insert_fileDocument.insert_file  s    " ff%%  ""Q&v.5&.."23C))C6"C344zzz))+H5(+C#!+  
 
	r)   c               @    V ^8  d   QhRRRRRRRRR	RR
RRRRRRRRR/
# )r  r1  r
  r{  r6   r   ztyping.Union[str, list, None]r   r  r  r3  r   r  r%  r  rp  r  rs  r,   )r  s   "r'   r  rt    sl       0 	
      r)   c	           	         V P                  WVR7      p	\        V4      '       g   ^ # V	P                  RVVVVVR7      p
V
# )zCreate a new PDF page and insert some text.

Notes:
    Function combining pymupdf.Document.new_page() and pymupdf.Page.insert_text().
    For parameter details see these methods.
)r{  r  r3  )r   r   r%  rp  )2   H   )new_pager   r  )r1  r{  r   r   r  r3  r   r%  rp  r   r   s   &&&&&&&&&  r'   insert_pageDocument.insert_page  sP    " |||@Dzz  
 	r)   r  r  r  r`  r5  rr  r  r  _gmapc               d   V P                   '       g   V P                  '       d   \        R4      hV P                  VP                  8X  d   \        R4      hTpV^ 8  d   V P                  pV P                  pVP                  pTpTpTp\        V^ 4      p\        VV^,
          4      pV^ 8  d
   V^,
          p\        VV^,
          4      pV^ 8  d   Tp\        W4      p\        V4      T
u;8  d   ^ 8  d|   M Mx\        P                  P                  VP                  4      pV'       g   Rp\        P                  P                  V P                  4      pV'       g   Rp\        RV RV R24       VP                  pV P                  P                  VR4      pVf   \        V 4      pWP                  V&   \         '       d+   \#        V P$                  VP$                  VVVVVVV
VV4       Ma\'        V 4      p\'        V4      pVP(                  '       d   VP(                  '       g   \+        R4      h\-        V4       \/        VVVVWWgW4
       V P1                  4        V'       d   V P3                  VVVVR	7       V'       d   V P5                  WVVWR
7       V^8X  d   RV P                  V&   R# R# )aM  Insert a page range from another PDF.

Args:
    docsrc: PDF to copy from. Must be different object, but may be same file.
    from_page: (int) first source page to copy, 0-based, default 0.
    to_page: (int) last source page to copy, 0-based, default last page.
    start_at: (int) from_page will become this page number in target.
    rotate: (int) rotate copied pages, default -1 is no change.
    links: (int/bool) whether to also copy links.
    annots: (int/bool) whether to also copy annotations.
    widgets: (int/bool) whether to also copy form fields.
    join_duplicates: (int/bool) join or rename duplicate widget names.
    show_progress: (int) progress message interval, 0 is no messages.
    final: (bool) indicates last insertion from this source PDF.
    _gmap: internal use only

Copy sequence reversed if from_page > to_page.r  z'source and target cannot be same objectz
memory PDFzInserting 'z' at 'r   Nzsource or target not a PDF)r  r  r  )r  r  r  rr  )r   r  r   r  rv  r'  minr9   rh   r   basenamer   rv   r  r:   Graftmapr  extra_FzDocument_insert_pdfr   r   r   r  rd  JM_merge_ranger5  r;  r  )r&   docsrcr  r  r  r`  r5  r  r  rr  r  r  r  r,  outCountr  r  rT  innameoutnameisrtpdfoutpdfsrcs   &&$$$$$$$$$$$          r'   r  Document.insert_pdf  sY   L >>>T...;<<>>V---FGG6B??$$  QZX\"6ABX\"6Bv;**WW%%fkk2F%gg&&tyy1G&k&y:; ""4.=TNE#(NN4 ;'IIKK! &d+F%f-F$$$F,=,=,=!=>>V$662r2umc 	NN6RbNIVb"rsA:#'DNN4  r)   c                	    \        V ^ R7      pVP                  '       g   R# \        P                  ! V4      pV'       d   R# R# )rx   r  FT)r   r   r   pdf_has_unsaved_changesr&   ra  r$  s   &  r'   is_dirtyDocument.is_dirty  s7    ta0~~~))#.t#e#r)   c                p    \        V ^ R7      pVP                  '       d   \        P                  ! V4      # R# )z)
Check whether we have a linearized PDF.
r  F)r   r   r   pdf_doc_was_linearizedr  s   & r'   is_fast_webaccessDocument.is_fast_webaccess  s-    
 ta0>>>//44r)   c                   \        V ^ R7      pVP                  '       g   R# Rp \        P                  ! \        P                  ! V4      \        P
                  \        P                  \        P                  4      p\        P                  ! V4      '       d   \        P                  ! V4      pT^ 8  d   T# R#   \         d    \        '       d   \        4         R# i ; i)z Either False or PDF field count.r  Fr  )r   r   r   r   r  PDF_ENUM_NAME_RootPDF_ENUM_NAME_AcroFormPDF_ENUM_NAME_FieldsrI  r  rk   r  r{   )r&   ra  r  fieldss   &   r'   r  Document.is_form_pdf  s     ta0~~~	((%%c*,,00..	F !!&))++F3 A:L  	##(8	s   B	B9 9C
CCc                    \        V P                  \        P                  4      '       d   R# \        P                  ! V P                  P
                  4      '       d   RpV# RpV# )zCheck for PDF.TF)r@   r   r   r   ll_pdf_specificsr   rk  s   & r'   r  Document.is_pdf  sS     dii!2!233
 !!$))"6"677C 
 C
r)   c                z    V P                   '       d   \        R4      h\        \        P                  ! V 4      4      # )z Check if document is layoutable.r   )r   r   r   r   r  r-   s   &r'   is_reflowableDocument.is_reflowable  s/     >>>.//E33D9::r)   c                    \        V ^ R7      pVP                  '       g   R# \        P                  ! V4      pV'       d   R# R# )zCheck whether PDF was repaired.r  FT)r   r   r   pdf_was_repairedr	  s   &  r'   is_repairedDocument.is_repaired  s5     ta0~~~""3'r)   c                   V P                   '       g   V P                  '       d   \        R4      h^ p^ p\        V 4      p\        P
                  ! V4      p\        P                  ! V4      pR\        V4      R\        V4      /# )z(Show if undo and / or redo are possible.r  undoredo)r   r  r   r   r   pdf_can_undopdf_can_redor   )r&   r	  r	  ra  s   &   r'   journal_can_doDocument.journal_can_do  sm    >>>T...;<<t$!!#&!!#&T
FDJ77r)   c                    V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\        P
                  ! V4       R# )zActivate document journalling.r  N)r   r  r   r   r   pdf_enable_journalr  s   & r'   journal_enableDocument.journal_enable  s:    >>>T...;<<t$  %r)   c                    V P                   '       g   V P                  '       d   \        R4      h\        V 4      pVP                  ;'       d    VP                  P
                  pV# )z Check if journalling is enabled.r  )r   r  r   r   r   journal)r&   ra  enableds   &  r'   journal_is_enabledDocument.journal_is_enabled  sL    >>>T...;<<t$..;;S^^%;%;r)   c                   V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\	        V\
        4      '       d   \        P                  ! W!4       M7\        V4      p\        P                  ! V4      p\        P                  ! W$4       VP                  P                  '       g   \        R\        4       R# R# )zLoad a journal from a file.r  z!Journal and document do not matchN)r   r  r   r   r@   r  r   pdf_load_journalr.  r  pdf_deserialise_journalr   r)	  r  r  )r&   rj   ra  r%  stms   &&   r'   journal_loadDocument.journal_load  s    >>>T...;<<t$h$$""31$X.C&&s+C))#3~~%%%8:NO &r)   c                    V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\        P
                  ! W!4      pV# )z#Show operation name for given step.r  )r   r  r   r   r   pdf_undoredo_step)r&   r  ra  r   s   &&  r'   journal_op_nameDocument.journal_op_name  sA    >>>T...;<<t$&&s1r)   c                    V P                   '       g   V P                  '       d   \        R4      h^ p\        V 4      p\        P
                  ! V4      w  r1W13# )zShow journalling state.r  )r   r  r   r   r   pdf_undoredo_state)r&   stepsra  r   s   &   r'   journal_positionDocument.journal_position  sK    >>>T...;<<t$,,S1	yr)   c                    V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\        P
                  ! V4       R# )zMove forward in the journal.r  T)r   r  r   r   r   pdf_redor  s   & r'   journal_redoDocument.journal_redo  ;    >>>T...;<<t$sr)   c                8   V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\	        V\
        4      '       d   \        P                  ! W!4       R# \        V4      p\        P                  ! W#4       VP                  4        R# )zSave journal to a file.r  N)r   r  r   r   r@   r  r   pdf_save_journalJM_new_output_fileptrpdf_write_journalfz_close_output)r&   rj   ra  outs   &&  r'   journal_saveDocument.journal_save  sk    >>>T...;<<t$h$$""31'1C##C-!r)   c                4   V P                   '       g   V P                  '       d   \        R4      h\        V 4      pVP                  P
                  '       g   \        R4      hV'       d   \        P                  ! W!4       R# \        P                  ! V4       R# )zBegin a journalling operation.r  zJournalling not enabledN)
r   r  r   r   r   r)	  r   r   pdf_begin_operationpdf_begin_implicit_operation)r&   r   ra  s   && r'   journal_start_opDocument.journal_start_op+  sg    >>>T...;<<t$~~%%% 9::%%c0..s3r)   c                    V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\        P
                  ! V4       R# )zEnd a journalling operation.r  N)r   r  r   r   r   pdf_end_operationr  s   & r'   journal_stop_opDocument.journal_stop_op7  s:    >>>T...;<<t$$r)   c                    V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\        P
                  ! V4       R# )zMove backwards in the journal.r  T)r   r  r   r   r   pdf_undor  s   & r'   journal_undoDocument.journal_undo>  r@	  r)   c                    \        V ^ R7      pVP                  '       g   R# \        P                  ! V4      pV\        P                  8X  d   R# \        P
                  ! V4      # )zDocument language.r  N)r   r   r   pdf_document_languagerF  rD  )r&   ra  rH  s   &  r'   rI  Document.languageF  sN     ta0~~~**3/5&&&22488r)   c                    V P                   '       d   \        R4      h\        P                  ! V P                  4      pVP
                  VP                  3# )z Id (chapter, page) of last page.r   )r   r   r   fz_last_pager   rz  r   )r&   last_locs   & r'   last_locationDocument.last_locationQ  sB     >>>.//%%dii0..r)   c                   \        V 4      p\        P                  ! 4       p\        P                  ! V4      p. p\	        V4       F  p\        P
                  ! WV4       VP                  ^8X  d   RpMVP                  ^8X  d   RpMRpRVRVP                  RVP                  RVRVP                  R	VP                  /pVP                  V4       K  	  V# )
z-Show OC visibility status modifiable by user.checkboxradioboxr  r]  r   depthr   ro  locked)r   r   PdfLayerConfigUipdf_count_layer_config_uirS  pdf_layer_config_ui_infor   r   ra	  selectedrb	  ro   )r&   ra  r8  rG   r   rg  rb  rE   s   &       r'   layer_ui_configsDocument.layer_ui_configsY  s    t$%%'++S1qA**CD9yyA~"a"aDIITZZE$--dkkD IIdO! " 	r)   c                "   V P                   '       g   V P                  '       d   \        R4      hV P                  p\        P
                  ! V4      '       g   R# TpTp\        V4      p\        P                  ! V4      '       g;   VP                  VP                  ,
          pVP                  VP                  ,
          pVR8:  g   VR8:  d   \        R4      h\        P                  ! WVWt4       V P                  4        V P                  4        R# )z Re-layout a reflowable document.r  Nr  zbad page size)r   r  r   r   r   r  r  r  r  r  r  r  r  r5  r  )	r&   r   r  r3  r   r1  r   r"  r$  s	   &&&&&    r'   layoutDocument.layoutr  s    >>>T...;<<ii..44D!((++qttAqttA8qCxo..  #!6r)   c                X   V P                   '       g   V P                  '       d   \        R4      hVf   ^ pW9  d   \        R4      h\        V4      \        J d%   V^ 8  d   V P
                  pV^ 8  d   W,          pK  \        V\        4      '       d#   \        P                  ! V P                  V4      pM%Vw  rE\        P                  ! V P                  WE4      p\        W04      pRVn        Wn        W`P                  \        V4      &   \         P"                  ! 4       Vn        Wn        V# )zLoad a page.

'page_id' is either a 0-based page number or a tuple (chapter, pno),
with chapter number and page number within that chapter.
r  zpage not in documentT)r   r  r   r   r6   rv  r@   r   fz_load_pager   fz_load_chapter_pager   r   r   r  rY  r  r  rX  r]  )r&   page_idnpr   rz  pagenumr  s   &&     r'   r  Document.load_page  s     >>>T...;<<?G344=CGaKBA+gs##%%dii9D&G--diiJD4
#&3 !557

r)   c                V   V P                   '       d   \        R4      hV P                  p\        P                  ! RR4      p\        P
                  ! V4      pV^ 8  d   W,          pK  W8  d   \        \        4      h\        P                  ! W!4      pVP                  VP                  3# )zConvert pno to (chapter, page).r   r  )
r   r   r   r   fz_make_locationr  r  fz_location_from_page_numberrz  r   )r&   r{  this_docry  rv  s   &&   r'   location_from_page_number"Document.location_from_page_number  s    >>>.//99$$R,))(3
AgCn--00?{{CHH$$r)   c                    V P                   '       g   V P                  '       d   \        R4      h\        P                  ! V!  p\        P
                  ! V P                  P                  VP                  4       4      pV# )z.Make a page pointer before layouting document.r  )	r   r  r   r   
FzLocationll_fz_make_bookmark2r   r   r  )r&   ry  marks   && r'   make_bookmarkDocument.make_bookmark  sY    >>>T...;<<$))499+?+?Pr)   c                   V ^8  d   QhRR/# r  rs  r7   r,   )r  s   "r'   r  rt    s      $ r)   c                j   V P                  4       pV^ 8X  d   R# V P                  VR4      pV^ ,          R8X  d   / # V^ ,          R8X  d<   \        V^,          P                  4       ^ ,          4      pV P	                  VRR7      pMV^ ,          R8X  d   V^,          pMRpVe   VR,          R	8X  d   VRR R
8X  g   / # RRRRRR/pV^R P                  R4      pVR,           F#  p VP                  4       w  rgTR8X  g   K  RYF&   K%  	  V#   \
         d    \        ^8  d   \        4        Tu u # i ; i)zReturn the PDF MarkInfo value.NMarkInfor  r  Tr[  r7   r  <<>>MarkedFUserPropertiesSuspects/r  NNtruer  )r]  r  r6   r8   r^  rk   r  r{   )r&   r  r   r  validrH   r  r   s   &       r'   markinfoDocument.markinfo  s4    !19tZ0a5F?Ia5F?r!u{{}Q'(D""4D"9CUf_Q%CC;s2w$3rs8t3CI5"2E:uM!Biooc"RAWWY
 !
    '!+0@s   &D"D21D2c                    V ^8  d   QhRRRR/# r  r,   )r  s   "r'   r  rt    s     ; ;S ;c ;r)   c                    V P                   '       d   \        R4      h\        V 4      pV\        V4      9  g   V\        RV4      9  d   \        R4      h^p^ pVR8X  d   V^,
          p^ pV P	                  WWE4      # )zMove a page within a PDF document.

Args:
    pno: source page number.
    to: put before this page, '-1' means after last page.
r   r  r  r  r  s   &&&   r'   	move_pageDocument.move_page  s{     >>>.//Y
uZ((BeB
6K,K1228aBF##CV::r)   c                	    V P                   # r+   rD  r-   s   &r'   r   Document.name  s    zzr)   c                   V P                   '       g   R# \        V 4      pRpRp\        P                  ! \        P                  ! V4      R4      p\        P
                  ! WT4      p\        P                  ! V4      '       d   \        P                  ! V4      pV'       d'   \        P                  ! WT\        P                  4       M%\        P                  ! WT\        P                  4       Vf   V^ 8  # V# )z"Get/set the NeedAppearances value.NNeedAppearancesrz  r  )r  r   r   r|  r  r  pdf_is_boolpdf_to_boolr  PDF_TRUE	PDF_FALSE)r&   r   ra  oldvalappkeyformapps   &&     r'   need_appearancesDocument.need_appearances  s    t$"""!!#& !!$/S!!&&s+Fenn=eoo>=Q;r)   c                   V P                   '       d   \        R4      h\        V P                  \        P
                  4      '       d   V P                  MV P                  P                  4       p\        P                  ! V4      pV# )zIndicate password required.r   )r   r   r@   r   r   r   r   fz_needs_password)r&   r   rI   s   &  r'   r  Document.needs_pass  sZ     >>>.// *499e6F6F G G499TYY__M^%%x0
r)   c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r  r1  r
  r{  r6   r  r  r3  rs  r   r,   )r  s   "r'   r  rt    s:        	
 r)   c                8    V P                  WVR7       W,          # )a   Create and return a new page object.

Args:
    pno: (int) insert before this page. Default: after last page.
    width: (float) page width in points. Default: 595 (ISO A4 width).
    height: (float) page height in points. Default 842 (ISO A4 height).
Returns:
    A pymupdf.Page object.
r  r3  )rD  )r1  r{  r  r3  s   &&&&r'   r  Document.new_page  s     	Sf5xr)   c                   V P                   '       g   V P                  '       d   \        R4      h\        V4      \        J d   ^ V3pW9  d   \        R4      h\        V4      V P                  8X  d   R# \        V 4      pV^ ,          p\        V\        4      '       g   \        \        \        4       TpV^,          pTp\        P                  ! WE4      p\        P                  ! W&4      pVP                  VP                   3# )z!Get (chapter, page) of next page.r  page id not in documentr,   )r   r  r   r   r6   r   r\	  r   r@   r  MSG_BAD_PAGEIDPyExc_ValueErrorr   rt	  fz_next_pagerz  r   )r&   ro	  rv	  r  rz  r{  ry  next_locs   &&      r'   next_locationDocument.next_location#  s    >>>T...;<<=C'lG677>T///I"4(qk#s##N$45qk$$W2%%x5..r)   c                	   \         '       d"   \        P                  ! V P                  V4      # \	        V P                  \
        P                  4      '       d.   \
        P                  ! V P                  4      pV P                  pM+\
        P                  ! V P                  4      p\        V 4      pV^ 8  d   W,          pK  W8  d   \        \        4      h\
        P                  ! W14      p\        V4      pV# ru  )r  r   r  r   r@   r   r   r  r  r   r   r  r  JM_get_annot_xref_list)r&   rG   rv  r  rL  r  s   &&    r'   r  Document.page_annot_xrefs8  s    ;))499a88dii!2!233..tyy9J99L--dii8J+D1L!eOA>n--,,\='1r)   c                J   V P                   '       d   \        R4      h\        '       d   V P                  V 4      # \	        V P
                  \        P                  4      '       d!   \        P                  ! V P
                  4      # \        P                  ! V P
                  4      # )zNumber of pages.r   )
r   r   r  r  r@   r   r   r   r  r  r-   s   &r'   rv  Document.page_countJ  sp     >>>.//;##D))tyy%"2"233''33(($))44r)   c                X   V P                   '       d   \        R4      hV P                  p\        P                  ! V4      pTpV^ 8  d   WC,          pK  \        V 4      pWC8  d   \        \        4      h\        P                  ! WT4      p\        V4      p\        V4      p\        V4      pV# )z2Get CropBox of page number (without loading page).r   )r   r   r   r   r  r   r  r  
JM_cropboxrp  r+  )	r&   r{  rv	  rv  rG   ra  r  cropboxr  s	   &&       r'   page_cropboxDocument.page_cropboxV  s    >>>.//99))84
!eOAt$?n--++S4W%g&3i
r)   c                   \        V4      \        J d"   V P                  pV^ 8  d   W,          pK  ^ V3pW9  d   \        R4      hVw  r4\        P
                  ! W44      p\        P                  ! V P                  V4      pV# )z&Convert (chapter, pno) to page number.r	  )r   r6   rv  r   r   rt	  fz_page_number_from_locationr   )r&   ro	  rp	  rz  r{  ry  page_ns   &&     r'   page_number_from_location"Document.page_number_from_locationj  sr    =CBA+'lG677$$g333TYYDr)   c                   \         '       d"   \        P                  ! V P                  V4      # V P                  '       d   \        R4      h\        P                  ! V P                  4      pTpV^ 8  d   W2,          pK  \        V 4      p^ pW28  d   \        \        4      h\        P                  ! \        P                  ! WC4      4      pV# )zGet xref of page number.r   )r  r   r(  r   r   r   r   r  r   r  r  r  )r&   r{  rv  rG   ra  r  s   &&    r'   r(  Document.page_xrefx  s    ;??DIIs33>>>.//))$))4
!eOAt$?n-- 9 9# ABr)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  rt    s      C r)   c                    V P                  4       pV^ 8X  d   R# V P                  VR4      pV^ ,          R8X  d   R# V^ ,          R8X  d   V^,          R,          # R# )z)Return the PDF PageLayout value.
        N
PageLayoutr  
SinglePager   r	  r]  r  r&   r  r   s   &  r'   
pagelayoutDocument.pagelayout  sX     !19t\2a5F?a5F?a59r)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  rt    s      # r)   c                    V P                  4       pV^ 8X  d   R# V P                  VR4      pV^ ,          R8X  d   R# V^ ,          R8X  d   V^,          R,          # R# )z'Return the PDF PageMode value.
        NPageModer  UseNoner   r	  r	  r	  s   &  r'   pagemodeDocument.pagemode  sX     !19tZ0a5F?a5F?a59r)   c               (    V ^8  d   QhRRRRRRRR/# )r  r  r  r  r  rs  zcollections.abc.Iterable[Page]r,   )r  s   "r'   r  rt    s)     ( (6 (v (6 (Tr (r)   c              #    "   V P                   '       g   R# T;'       g    ^ pV^ 8  d   WP                   ,          pK  V\        V P                   4      9  d   \        R4      hVe   W P                   8:  d   TMV P                   pV^ 8X  d   \        R4      hVf   W8  d   RpM^p\        WV4       F  pV P                  V4      x  K  	  R# 5i)zmReturn a generator iterator over a page range.

Arguments have the same meaning as for the range() built-in.
Nzbad start page numberzarg 3 must not be zeror  )rv  rS  r   r  )r&   r  r  r  r{  s   &&&& r'   rX  Document.pages  s     
 

ai__$Edoo..455 'DOO,Ct 19566<|d+C>>#&' ,s   CB.Cc                    \        V ^ R7      p^ pVP                  '       g   V# \        P                  ! \        P                  ! V4      \        R4      4      p\        P                  ! V4      pV# )zGet xref of PDF catalog.r  r  )r   r   r   r  r  r  r  )r&   ra  r  r  s   &   r'   r]  Document.pdf_catalog  sX    ta0~~~K!!%"3"3C"8(6:JK%r)   c                (    V P                  RWR7      # )zGet PDF trailer as a string.)r\  r  r  )r^  )r&   r\  r  s   &&&r'   r  Document.pdf_trailer  s    zGGr)   c                   V P                   '       d   ^ # V P                  p\        P                  ! V4      pVP                  '       d   \        P
                  ! V4      # Rp\        P                  ! V\        P                  4      '       g   V\        P                  ,          p\        P                  ! V\        P                  4      '       g   V\        P                  ,          p\        P                  ! V\        P                  4      '       g   V\        P                  ,          p\        P                  ! V\        P                  4      '       g   V\        P                  ,          pV# )zDocument permissions.l    )r  r   r   r{  r   pdf_document_permissionsfz_has_permissionFZ_PERMISSION_PRINTPDF_PERM_PRINTFZ_PERMISSION_EDITPDF_PERM_MODIFYFZ_PERMISSION_COPYPDF_PERM_COPYFZ_PERMISSION_ANNOTATEPDF_PERM_ANNOTATE)r&   r1  ra  perms   &   r'   r  Document.permissions  s     YY11#6 >>>11#66 &&sE,E,EFF%...D&&sE,D,DEE%///D&&sE,D,DEE%---D&&sE,H,HII%111Dr)   c                h   V P                   '       g   V P                  '       d   \        R4      h\        V4      \        J d   ^ V3pW9  d   \        R4      hVR8X  d   R# Vw  r#\
        P                  ! W#4      p\
        P                  ! V P                  V4      pVP                  VP                  3# )z%Get (chapter, page) of previous page.r  r	  rx   rx   r,   )r   r  r   r   r6   r   rt	  fz_previous_pager   rz  r   )r&   ro	  rz  r{  ry  prev_locs   &&    r'   prev_locationDocument.prev_location  s     >>>T...;<<=C'lG677vI$$W2))$))S9..r)   c                    V ^8  d   QhRRRR/# )r  r   r   rs  r,   )r  s   "r'   r  rt    s     9 9 9 9r)   c                :   / pVP                   pVP                  P                  4        F	  w  rEWRV&   K  	  VP                  P                  P
                  pVP                  P                  4       pRVn        VP                  4        Rp\        P                  ^d4       V P                  V4      pVP                  4        F  w  rEW$,          pWP                  V&   K  	  V^8X  d    V# VP                  P                  4       p	W8w  g   Q RV: RVR RV	R 24       hV# )zMake a fresh copy of a page.Nz	refs_old=z m_internal_old=z#xz m_internal_new=)r]  rX  rD   r   r   refsrW  r   r  store_shrinkr  )
r&   r   r1  r{  r  rH   refs_oldm_internal_oldr   m_internal_news
   &&        r'   reload_pageDocument.reload_page  s   
kk$$**,DAqM -6 99'',,335	3~~c" $$&DAME"'Q ' q=
   "YY779N!3 M xk!2>2"66G7KLM3r)   c                t    \        V RR7      pVP                  '       d   \        P                  ! V4       R# R# )z(
If we are a PDF document, does repair.
Fr  N)r   r   r   pdf_check_documentr  s   & r'   repairDocument.repair4  s,     te4>>>$$S) r)   c                l   V'       g   V'       d   R# R#  \         P                  ! V P                  V4      w  r4pT'       d   TP                  TP                  3YE3# \         P                  ! T P                  T4      pYdT3#   \         d(    \        '       d   \        4        T'       d   Ru # Ru # i ; i)a  Calculate internal link destination.

Args:
    uri: (str) some Link.uri
    chapters: (bool) whether to use (chapter, page) format
Returns:
    (page_id, x, y) where x, y are point coordinates on the page.
    page_id is either page number (if chapters=0), or (chapter, pno).
)r  r  rx   rx   )r  rx   rx   )	r   fz_resolve_linkr   rk   r  r{   rz  r   r	  )r&   r  r  ry  xpypr{  s   &&&    r'   r  Document.resolve_link<  s     %%O	//		3?KCR KK*B2200C@{  	##(8%%O		s#   $B B3B3*B3.B32B3c                   \        V4      pV'       g   ^ ;rV^ 8  d   W!8  d   \        R4      h\        P                  ! 4       p\	        \        V4      4      pV
'       Eg{   \        P                  ! 4       pV'       d=   \        P                  Vn        \        P                  Vn	        W.n
        Wn        Wn        V'       d   V'       d=   \        P                  Vn        \        P                  Vn        W.n        Wn        Wn        V'       d=   \        P                  Vn        \        P                  Vn        Wn        W.n        Wn        V'       d   V'       d=   \        P                  Vn        \        P                  Vn        W.n        Wn        Wn        V'       d=   \        P                  Vn        \        P                  Vn        Wn        W.n         Wn!        MT
p\	        \        V4      4      pW,
          pV'       d   \        RV 24      hV	'       d   V PE                  ^4       \G        V 4      p\        PH                  ! VV4       R# )a  Rewrite images in a PDF document.

The typical use case is to reduce the size of the PDF by recompressing
images. Default parameters will convert all images to JPEG where
possible, using the specified resolutions and quality. Exclude
undesired images by setting parameters to False.
Args:
    dpi_threshold: look at images with a larger DPI only.
    dpi_target: change eligible images to this DPI.
    quality: Quality of the recompressed images (0-100).
    lossy: process lossy image types (e.g. JPEG).
    lossless: process lossless image types (e.g. PNG).
    bitonal: process black-and-white images (e.g. FAX)
    color: process colored images.
    gray: process gray images.
    set_to_gray: whether to change the PDF to gray at process start.
    options: (PdfImageRewriterOptions) Custom options for image
            rewriting (optional). Expert use only. If provided, other
            parameters are ignored, except set_to_gray.
z0{dpi_target=} must be less than {dpi_threshold=}zInvalid options: N)%r  r   r   PdfImageRewriterOptionsr  r  FZ_RECOMPRESS_FAXbitonal_image_recompress_methodFZ_SUBSAMPLE_AVERAGEbitonal_image_subsample_methodbitonal_image_subsample_to bitonal_image_recompress_quality!bitonal_image_subsample_thresholdFZ_RECOMPRESS_JPEG&color_lossless_image_recompress_method%color_lossless_image_subsample_method!color_lossless_image_subsample_to(color_lossless_image_subsample_threshold'color_lossless_image_recompress_quality#color_lossy_image_recompress_method"color_lossy_image_subsample_method%color_lossy_image_subsample_thresholdcolor_lossy_image_subsample_to$color_lossy_image_recompress_quality%gray_lossless_image_recompress_method$gray_lossless_image_subsample_method gray_lossless_image_subsample_to'gray_lossless_image_subsample_threshold&gray_lossless_image_recompress_quality"gray_lossy_image_recompress_method!gray_lossy_image_subsample_method$gray_lossy_image_subsample_thresholdgray_lossy_image_subsample_to#gray_lossy_image_recompress_qualityrecolorr   pdf_rewrite_images)r&   dpi_threshold
dpi_targetqualitylossylosslessbitonalrp  r  set_to_grayr!  quality_strtemplate_optsdir1rU  dir2invalid_optionsra  s   &&&&&&&&&&&       r'   rewrite_imagesDocument.rewrite_imagesV  s   B 'l)**M>j9OPP5573}%&w002D7<7N7N46;6P6P32</8C59F6BGBZBZD?AFA[A[D>=G:DQACN@?D?W?WD<>C>X>XD;AN>:D7@K=AFAYAYD>@E@Z@ZD=<F9CP@BM?>C>V>VD;=B=W=WD:@M=9C6?J<D3t9~+00ABCCLLOt$  d+r)   c                    V P                   '       g   \        R4      h\        V P                  4       F#  pV P	                  V4      P                  V4       K%  	  R# )zChange the color component count on all pages.

Args:
    components: (int) desired color component count, one of 1, 3, 4.

Invokes the same-named method for all pages.
r  N)r  r   rS  rv  r  r
  )r&   
componentsrg  s   && r'   r
  Document.recolor  sB     {{{[))t'ANN1%%j1 (r)   c                h  a	a
a \        V R4      '       d   V P                  # \        V P                  4       Uu/ uF  qP	                  V4      VbK  	  upoR o
V
V3R lo	V	3R lp\
        P                  ! V 4      p\
        P                  ! \
        P                  ! V4      R4      p/ p\
        P                  ! R4      p\
        P                  ! WF4      pVP                  4       '       d	   V! WW4       \
        P                  ! W64      pVP                  4       '       d	   V! WX4       WPn        V# u upi )a  Convert the PDF's destination names into a Python dict.

The only parameter is the pymupdf.Document.
All names found in the catalog under keys "/Dests" and "/Names/Dests" are
being included.

Returns:
    A dcitionary with the following layout:
    - key: (str) the name
    - value: (dict) with the following layout:
        * "page":  target page number (0-based). If no page number found -1.
        * "to": (x, y) target point on page - currently in PDF coordinates,
                i.e. point (0,0) is the bottom-left of the page.
        * "zoom": (float) the zoom factor
        * "dest": (str) only occurs if the target location on the page has
                not been provided as "/XYZ" or if no page number was found.
    Examples:
    {'__bookmark_1': {'page': 0, 'to': (0.0, 541.0), 'zoom': 0.0},
    '__bookmark_2': {'page': 0, 'to': (0.0, 481.45), 'zoom': 0.0}}

    or

    '21154a7c20684ceb91f9c9adc3b677c40': {'page': -1, 'dest': '/XYZ 15.75 1486 0'}, ...
_resolved_namesc                    \         P                  ! R4      p\         P                  ! V4      p\         P                  ! W ^^ 4       VP	                  4        \        V4      # )z1Return string version of a PDF object definition.   )r   fz_new_bufferFzOutputpdf_print_objrE	  r  )r  bufferoutputs   &  r'   
obj_string*Document.resolve_names.<locals>.obj_string  sI    ((-F^^F+FQ2""$'//r)   c                  < RRRR/pV P                  4       '       d   \        P                  ! V 4      p V P                  4       '       d
   S! V 4      pM6V P	                  4       '       d   S! \        P
                  ! V R4      4      pMV# VP                  RR4      ^R pVP                  R4      pV^8  d   W!R&   V# VRV P                  4       pW#R pW!R&   VP                  R	4      '       dx   VR VP                  4       R
,          p\        V4      ^8  d   VP                  R4       K#  \        \        \        V4      4      pV^ ,          V^,          3VR&   V^,          VR&   VP!                  R4      '       d6   SP#                  \%        VP                  4       ^ ,          4      R4      VR&   V# \%        V4      VR&   V# )z3Generate value of one item of the names dictionary.r   destr`   r  r  r   r	  Nz/XYZ:r  r  Nr  r  rk  r  )pdf_is_indirectr   r  rI  r  r  r  r   stripr5   r8   r9   ro   r   r  r  r  r:   r6   )	r  
templ_dictarrayr  subval
array_listr  r5
  
page_xrefss	   &      r'   	get_array)Document.resolve_names.<locals>.get_array  s    "fb1J""$$005!!"3"""5#6#6sC#@A!! MM&#.q4E **S/CQw%*6"!!4C[&&(F$KE!&v ''v& #[[]3/
 *o)%%c* UJ/0$%aD!A$<
4 %&qT
6" u%%%/^^Cq8I4J2%N
6"  &)[
6"r)   c                H  < \         P                  ! V4      p\        V4       F{  p\         P                  ! W4      p\         P                  ! W4      pVP                  4       '       d   VP                  4       pM\        RV R24       RpV'       g   Kq  S! V4      W&   K}  	  R# )zaGenerate name resolution items for pdf_dict.

This may be either "/Names/Dests" or just "/Dests"
zkey z is no /NameN)r   r  rS  r  r  r  r  rv   )	dest_dictpdf_dict
name_countrg  r  r  dict_keyr@
  s   &&     r'   	fill_dict)Document.resolve_names.<locals>.fill_dict  s     ++H5J :&,,X9,,X9??$$"0Hd1#\23#H8*3C.I' 'r)   r  Dests)r=   r-
  rS  rv  r(  r   r{  r  r  r  r  r  pdf_load_name_tree)r&   rg  rG
  ra  catalogrC
  dests	old_destsr  r@
  r5
  r?
  s   &        @@@r'   resolve_namesDocument.resolve_names  s   2 4*++'''49$//4JK4JqnnQ'*4JK
	0.	`	9, 11$7 %%e&7&7&<fE	 ""7+ &&w6	  ""i+ ''3i&(K Ls   D/c                	2   V P                   p V P                  '       g   V P                  '       d   \        R 4      h\	        V4      \
        J d   MZ\        VR4      '       d   \        V4      pM<\        VR4      '       d   VP                  pM\        VR4      '       g   \        R4      hWP                  8X  d   V'       g   \        R4      hV
'       d   V'       d   \        R4      hV P                  ^8  d   \        R4      hV'       d/   V P                  V8w  g   V P                  '       d   \        R4      hV'       d   \        V4      ^(8  g   V'       d   \        V4      ^(8  d   \        R	4      h\        V 4      p\        P                  ! 4       pVVn        VVn        VVn        VVn        VVn        V	Vn        VVn        VVn        V
Vn        VVn        VVn        VVn        VVn        VVn        VVn        Ve   VP;                  V4       MVe   VP;                  V4       Ve   VP=                  V4       VVn        VVn         VVn!        R
p^ VPD                  n#        \I        V4       V^ 8X  d   \K        V4       \M        V\
        4      '       d   \        PN                  ! VVV4       M3\Q        V4      p\        PR                  ! VVV4       VPU                  4        V'       d*   V P                   '       d   V'       g   \W        R4      hR
# R
# R
# )r  r<   r   seek)filename must be str, Path or file objectz$save to original must be incrementalz3'linear' and 'use_objstms' cannot both be requestedzcannot save with zero pageszincremental needs original filez"password length must not exceed 40NzDocument save did a repair),r	  r   r  r   r   r  r=   r   rv  r   r9   r   r   PdfWriteOptionsdo_incrementaldo_asciido_compressdo_compress_imagesdo_compress_fontsdo_decompress
do_garbage	do_pretty	do_lineardo_cleando_sanitizedont_regenerate_iddo_appearance
do_encryptr  opwd_utf8_set_valueupwd_utf8_set_valuedo_preserve_metadatado_use_objstmsr   r   rX  JM_embedded_cleanJM_ensure_identityr@   pdf_save_documentrC	  pdf_write_documentrE	  rk   )r&   rj   r  r  r  r  r  r  r  r  r  r  
appearancer  r  r  r  r  r  r  r   r!  is_repaired_prera  rU  rF	  s   &&&&&&&&&&&&&&&&&&&&&&    r'   r"  Document.save=  s   4 **=>>>T...;<<>S Xv&&8}HXv&&}}H6**HIIyy CDDkRSS??Q:;;yyH$ !BCCs7|b(HX9KABBt$$$&)""0!.#! "+'$&$$X. $$W-$$W-$5!)"4*+'#>s#h$$##C48'1C$$S#t4!"<>> )8 r)   c                p   V P                   '       d   \        R4      h\        V4      \        J d   MH\	        VR4      '       d   \        V4      pM*\	        VR4      '       d   VP
                  pM\        R4      hWP
                  8X  d   \        R4      h\        V 4      p\        P                  ! W!4       R# )z.Save a file snapshot suitable for journalling.zdoc is closedr<   r   rR
  zcannot snapshot to originalN)	r   r   r   r  r=   r   r   r   pdf_save_snapshot)r&   rj   ra  s   && r'   save_snapshotDocument.save_snapshot  s    >>>_-->S Xv&&8}HXv&&}}HHIIyy :;;t$.r)   c                Z    V P                  V P                  R\        P                  R7      # )zSave PDF incrementallyT)r  r  )r"  r   r   PDF_ENCRYPT_KEEPr-   s   &r'   saveIncrDocument.saveIncr  s!    yyAWAWyXXr)   c               T    V ^8  d   QhRRRRRRRRRRRRR	RR
RRRRRRRRRRRRRRR/# )r  r1  r
  attached_filesr   clean_pagesembedded_fileshidden_text
javascriptr  
redactionsredact_imagesr6   remove_linksreset_fieldsreset_responses
thumbnailsxml_metadatars  r  r,   )r  s   "r'   r  rt    s     Y; Y;Y; Y; Y; !	Y;
 Y; Y; Y; Y; Y; Y; Y; "Y; Y; Y; Y;r)   c                	2   R  pV P                   '       g   \        R4      hV P                  '       g   V P                  '       d   \        R4      hV'       g   RpRpV'       d   V P	                  / 4       V  EF6  pV
'       d(   VP                  4        F  pVP                  4        K  	  V	'       d+   VP                  4       pV F  pVP                  V4       K  	  RpVP                  4        F  pVP                  ^ ,          \        P                  8X  d   V'       d   VP                  RR7       V'       d   VP                  4        VP                  ^ ,          \        P                  8X  g   K  RpK  	  V'       d   V'       d   VP!                  VR7       V'       g   V'       g   EK5  VP#                  4        VP%                  4       '       g   EK^  V'       d~   VP%                  4       p\'        V4      ^8X  g   Q hV^ ,          pV P)                  V4      pV! VP+                  4       4      pV'       d$   RP-                  V4      pV P/                  VV4       V'       g   EK  V P1                  VP2                  R	4      ^ ,          R
8w  g   EK  V P5                  VP2                  R	R
4       EK9  	  V'       d)   V P7                  4        F  pV P9                  V4       K  	  V'       d   V P;                  4        V'       g   V'       g   ^ pMV P=                  4       p\?        ^V4       F  pV PA                  V4      '       g   RV R2p\        V4      hV'       d5   V P1                  VR4      ^,          R8X  d   RpV PC                  VV4       Kg  V'       g   Kq  V P1                  VR4      ^,          R8X  d)   V PC                  VR4       V P/                  VRRR7       K  V P1                  VR4      ^ ,          R
8w  g   K  V P5                  VRR
4       K  	  R# )c                   . pRpRpRpV  F  pVR8X  d   RpVP                  V4       K  VR8X  d   RpVP                  V4       K;  VR8X  d   RpRpKH  VR
R R8X  d$   V^ ,          R8w  d   RpVP                  V4       Ku  VR	8X  d   RpVP                  V4       K  V'       d   V'       d   K  VP                  V4       K  	  V'       d   V# R# )a  Remove hidden text from a PDF page.

Args:
    cont_lines: list of lines with /Contents content. Should have status
        from after page.cleanContents().

Returns:
    List of /Contents lines from which hidden text has been removed.

Notes:
    The input must have been created after the page's /Contents object(s)
    have been cleaned with page.cleanContents(). This ensures a standard
    formatting: one command per line, single spaces between operators.
    This allows for drastic simplification of this code.
Fs   BTTs   ETs   3 TrNs   Tr   3   Qr  ro   )
cont_lines	out_linesin_textsuppressmake_returnrs   s   &     r'   remove_hidden%Document.scrub.<locals>.remove_hidden  s      IGHK"5="G$$T*5=#G$$T*7?#H"&K9%$q'T/$H$$T*4<$H$$T*  &/ #0   r)   r  zclosed or encrypted docFr+  )r4  T)imagesr  Thumbr  z	bad xref z - clean PDF before scrubbingSz/JavaScriptz<</S/JavaScript/JS()>>r  z	/Metadata<<>>s   deleted)r\  r  N)"r  r   r  r   set_metadatar  resetr)  delete_linkr  r   r   rL  rY  r  r  apply_redactionsr  get_contentsr9   xref_streamr  r  update_streamr  r  r  r  r  r  r  rS  r^  r_  )r1  rv
  rw
  rx
  ry
  rz
  r  r{
  r|
  r}
  r~
  r
  r
  r
  r
  r   r\  r5  r  found_redactsr   r  r  r  r
  r   
xref_limitr   r  s   &&&&&&&&&&&&&&               r'   scrubDocument.scrub  s$   "/	b zzz[))s}}}677KJR D"llnFLLN - (!D$$T* " "M::a=E$C$CC%%d%3"**,::a=E$:$::$(M ' m%%]%;;!$$&&))+5zQ&Qxt,*4??+<=
 ::j1D%%dD1z##DIIw7:fD$$TYY@S Z ))+% ,   "
J*J!Z(D??4((!$'DE o%c..tS9!<M.!!$,f-a0K?!!$/!!$
!=j1!4>  z6:) )r)   c               8    V ^8  d   QhRRRRRRRRR	R
RRRRRR/# )r  r1  r
  r{  r6   r   r  quadsr   r  r   r  r  r  rs  r   r,   )r  s   "r'   r  rt  O  sX     "
 "
"
"
 "
 	"

 "
 "
 !"
 "
r)   c                    Vf/   ^ \         ,          \        ,          \        ,          \        ,          pW,          P	                  VVVVVR7      # )ai  Search for a string on a page.

Args:
    pno: page number
    text: string to be searched for
    clip: restrict search to this rectangle
    quads: (bool) return quads instead of rectangles
    flags: bit switches, default: join hyphened words
    textpage: reuse a prepared textpage
Returns:
    a list of rectangles or quads, each containing an occurrence.
)r
  r  r  r  )TEXT_DEHYPHENATETEXT_PRESERVE_LIGATURESTEXT_PRESERVE_WHITESPACETEXT_MEDIABOX_CLIP
search_for)r1  r{  r   r
  r  r  r  s   &&&&&&&r'   search_page_forDocument.search_page_forO  s]    * =&'-. // )	)E x"" # 
 	
r)   c                   V P                   '       g   V P                  '       d   \        R4      hV P                  '       g   \        R4      h\	        VR4      '       g   \        R4      h\        \        V 4      4      p\        V4      ^ 8X  g!   \        V4      V9  g   \        V4      V9  d   \        R4      h\        V 4      p\        P                  ! W1\        P                  4       V P                  4        R# )z,Build sub-pdf with page numbers in the list.r  r  r  zsequence requiredr  N)r   r  r   r  r=   rS  r9   r  r'  r   r   pdf_rearrange_pages2PDF_CLEAN_STRUCTURE_KEEPr5  )r&   pylistevalid_rangera  s   &&  r'   selectDocument.selects  s    >>>T...;<<{{{[))w..011CI&LA7|;.7|;.122 t$
 	""31O1OP 	r)   c                	    \        V 4      pV'       g   \        P                  pM\        P                  ! V4      p\        P                  ! W#4       R # r%  )r   r   rF  r  pdf_set_document_language)r&   rI  ra  rH  s   &&  r'   r  Document.set_language  s;    t$&&D55h?D''2r)   c                   V P                   '       d   \        R4      h\        V P                  4       P	                  4       4      pV\        4       8X  d   \        R4      hV'       d]   \        V4      \        \        39  d   \        R4      h\        V4      P                  V4      pV\        4       8w  d   \        RV 24      hV'       d]   \        V4      \        \        39  d   \        R4      h\        V4      P                  V4      pV\        4       8w  d   \        RV 24      hV'       d]   \        V4      \        \        39  d   \        R4      h\        V4      P                  V4      pV\        4       8w  d   \        RV 24      hV'       d   \        V4      \        \        39  d   \        R	4      hV Fc  p	\        V	4      \        \        39   g   \        R
V	 R24      h\        V	4      P                  V4      pV\        4       8w  g   KW  \        RV 24      h	  V'       d5   \        V4      P                  4       pVR8X  d   RpVR9  d   \        R4      h\        V 4      p
\        P                  ! \        P                  ! V
4      \        R4      \        R4      4      pVP                   '       g   R# VR8X  d"   \        P"                  ! V\        R4      4      pM5\        P$                  ! \        P"                  ! V\        R4      4      V4      pVP                   '       g   \        \&        4      h\)        WW4WV4       \        P*                  ! V
P                   4       R# )z5Set the PDF keys /ON, /OFF, /RBGroups of an OC layer.r   z document has no optional contentzbad type: 'on'zbad OCGs in 'on': zbad type: 'off'zbad OCGs in 'off': zbad type: 'locked'zbad OCGs in 'locked': zbad type: 'rbgroups'zbad RBGroup 'r   zbad OCGs in RBGroup: 	UNCHANGED	Unchangedzbad 'basestate'r  rX  Nr  r}  )r  r  r
  r  )r   r   r  ry  r  r   r   r   
differencer  upperr   r   r   r  r  r   r  r  r  JM_set_ocg_arraysrm  )r&   r  	basestatero  offrbgroupsrb	  rv  r  ri  ra  r  r  s   &&&&&&&      r'   	set_layerDocument.set_layer  s   >>>.//4==?'')*35=?@@Bxe}, !122B""4(ACEz #5aS!9::Cyu- !233C##D)ACEz #6qc!:;;F|D%=0 !566F&&t,ACEz #9!!=>>H~dE]2 !788Aw4-/$}QCq%9::F%%d+:$'<QC%@AA  I,,.IK''	 :: !233t$!!!!3' (
 ~~~R<$$c8C=9C%%&&Xi-@AC ~~~/0032HEs~~.r)   c                   \        V\        4      '       dU   V P                  4        Uu. uF  q3R,          V8X  g   K  VR,          NK  	  ppV. 8X  d   \        RV R24      hV^ ,          p\	        V 4      pV^8X  d   \
        P                  ! WQ4       R# V^8X  d   \
        P                  ! WQ4       R# \
        P                  ! WQ4       R# u upi )z$Set / unset OC intent configuration.r   r]  z	bad OCG 'r  N)	r@   r  rg	  r   r   r   pdf_toggle_layer_config_uipdf_deselect_layer_config_uipdf_select_layer_config_ui)r&   r]  re  uir
  ra  s   &&&   r'   set_layer_ui_configDocument.set_layer_ui_config  s     fc""-1-B-B-D]-Dr6
V\H\lbll-DF]| 9VHB!788AYFt$Q;,,S9q[..s;,,S9 ^s
   CCc                    V ^8  d   QhRRRR/# )r  r	  r7   rs  r   r,   )r  s   "r'   r  rt    s      T d r)   c                   V P                  4       pV^ 8X  d   \        R4      hV'       d   \        V\        4      '       g   R# RRRRRR/p\	        VP                  4       4      P                  VP                  4       4      '       gE   R\	        VP                  4       4      P                  VP                  4       4       2p\        V4      hRpVP                  V4       VP                  4        FF  w  rg\        V4      P                  4       pVR9  d   \        RV R	V R
24      hVRV RV 2,          pKH  	  VR,          pV P                  VRV4       R# )zSet the PDF MarkInfo values.	not a PDFFr	  r	  r	  zbad MarkInfo key(s): r	  zbad key value 'z': 'r   r	  r   r	  r	  T)r	  false)r]  r   r@   r7   r  r  
issupersetr
  rN  rD   r  r  r  )r&   r	  r  r	  badkeyspdfdictr  r   s   &&      r'   set_markinfoDocument.set_markinfo  s,   !19[))z(D995"2E:uM5::< ++HMMO<<-c(--/.B.M.Mejjl.[-\]GW%%X++-JCe*""$E-- ?3%tE7!!DEE3%q((G	 (
 	4$
G4r)   c               $    V ^8  d   QhRRRRRR/# )r  r1  r
  r  r7   rs  r  r,   )r  s   "r'   r  rt     s!     ; ;* ; ; ;r)   c                b   V P                   '       g   \        R4      hV P                  '       g   V P                  '       d   \        R4      hVf   / pM\	        V4      \
        Jd   \        R4      hRRRRR	R
RRRRRRRRRRRRRRRR/p\        VP                  4       4      p\        VP                  4       4      P                  V4      pV\        4       8w  d   RV 2p\        V4      hV P                  R!R4      w  rgVR8w  d   ^ pM\        VP                  RR4      4      pV/ 8X  d
   V^ 8X  d   R# V^ 8X  d:   V P                  4       pV P                  VR4       V P                  R!RV R24       M,V/ 8X  d&   V P                  R!RR 4       V P                  4        R# VP!                  4        U	U
u. uF  w  rW),          f   K  W3NK  	  up
p	 FE  w  rW+,          p\#        V4      '       d   VR"9   d   R pM\%        V4      pV P                  WV4       KG  	  V P                  4        R# u up
p	i )#zKUpdate the PDF /Info object.

Args:
    m: a dictionary like doc.metadata.
r  r  Nzbad metadatar  Authorr  Producerrn  ry  r  rd  r  r  r  r,  r  ModDater  Subjectr  Keywordsr  Trappedzbad dict key(s): Infor  rk  r`   r
  r  r  r  )noner  )r  r   r   r  r   r7   r  r  r
  r  r6   r  re  r_  r  r  rD   r   r  )r1  r  keymap
valid_keysdiff_setr   r  r  	info_xrefr  rH   r  r  pdf_keys   &&            r'   r
  Document.set_metadata   s    zzz[))===C,,,;<<9A!WD ^,,h
yWd$Nyy
y
 '
qvvx=++J7su%hZ0CS/!""2v.;IDLL34I7yA~>((*Ii0RI;d);<"WR0LLN,-GGIOIDA!IOHCkG99'7 7!#&Y5 P 	 Ps   2H+H+c               (    V ^8  d   QhRRRRRRRR/# )r  r1  r
  r  r6   r  rs  r  r,   )r  s   "r'   r  rt  =  s(      J c s t r)   c                   V P                   '       g   V P                  '       d   \        R4      hV P                  VR4      w  r4VR8w  g   VR
9  d   \        RV 24      hV^ 8  d1   V P                  VR4      w  r4VR8w  g   VR9  d   \        RV 24      hV^ 8X  d,   RV P	                  V4      9   d   V P                  VRR4       R# V P                  VRV R	24       R# )zAttach optional content object to image or form xobject.

Args:
    xref: (int) xref number of an image or form xobject
    oc: (int) xref number of an OCG or OCMD
ri  r  r   rj  r  r  r  Nr  rl  )z/OCGz/OCMD)r   r  r   r  xref_get_keysr  )r1  r  r  r  r   s   &&&  r'   r  Document.set_oc=  s     ===C,,,:;;""43;$&997v>??6&&r62GAF{d*;; #;B4!@AA7ts0066T40tt4[1r)   c               0    V ^8  d   QhRRRRRRRRR	RR
R/# )r  r1  r
  r  r6   rv  ztyping.Union[list, None]r  r  r  rs  r,   )r  s   "r'   r  rt  S  sL     G GGG +G 	G
 )G Gr)   c                  a	a
 \        V P                  4       P                  4       4      o	V	V
3R lo
RpV'       d   \        V4      \        \
        39   dk   \        V4      P                  S	4      pV\        4       8w  d   RV 2p\        V4      hVRRP                  \        R V4      4      ,           R,           ,          pV'       dK   \        V4      P                  4       pRR	R
RRRRR/pVR9  d   \        RV 24      hVRW,           2,          pV'       d   VRS
! V4       2,          pVR,          pV^ 8X  d   V P                  4       pM#RV P                  VRR7      9  d   \        R4      hV P                  W4       V# )a  Create or update an OCMD object in a PDF document.

Args:
    xref: (int) 0 for creating a new object, otherwise update existing one.
    ocgs: (list) OCG xref numbers, which shall be subject to 'policy'.
    policy: one of 'AllOn', 'AllOff', 'AnyOn', 'AnyOff' (any casing).
    ve: (list) visibility expression. Use instead of 'ocgs' with 'policy'.

Returns:
    Xref of the created or updated OCMD.
c                F  < \        V 4      \        \        39  g   \        V 4      ^8  d   \	        RV  24      hV ^ ,          P                  4       R
9  d   \	        RV ^ ,           24      hV ^ ,          P                  4       R8X  d   \        V 4      ^8w  d   \	        RV  24      hRV ^ ,          P                  4        2pV R,           FL  p\        V4      \        J d%   VS9  d   \	        RV 24      hVRV R2,          pK:  VRS! V4       2,          pKN  	  VR	,          pV# )r  zbad 've' format: notzbad operand: z[/r	  zbad OCG r   r  r  )andorr
  )r   r   r   r9   r   r  r  r6   )r  rE   ri  all_ocgsve_makers   &  r'   r
  #Document.set_ocmd.<locals>.ve_makerh  s	   Bxe},B! #4RD!9::!u{{}$88 =A!899!u{{}%#b'Q, #4RD!9::1'DVV7c>((8A388as$K'Da}--D  CKDKr)   z<</Type/OCMDz
bad OCGs: r  r   c                    V  R 2# )r  r,   r  s   &r'   <lambda>#Document.set_ocmd.<locals>.<lambda>  s
    4jr)   r  anyonAnyOnallonAllOnanyoffAnyOffalloffAllOffzbad policy: r  z/VEr	  r~  Tr[  zbad xref or not an OCMD)r
  r
  r
  r
  )r  ry  r  r   r   r   r
  r   r  r  r  r  re  r^  r_  )r1  r  rv  r  r  r   r  r   polsr
  r
  s   &&&&&    @@r'   set_ocmdDocument.set_ocmdS  s`   & s||~**,-	$ DJ4-/D	$$X.ACEz"1#& o%Hsxx,@$(GHH3NND[&&(F((	D CC <x!899c$,((Dc(2,((D 19##%D$!GG677$%r)   c                   V ^8  d   QhRR/# )r  r	  r  r,   )r  s   "r'   r  rt    s     1 1 1r)   c                >   RpV P                  4       pV^ 8X  d   \        R4      hV'       g   \        R4      hV^ ,          R8X  d
   VR,          pV F?  pVP                  4       VP                  4       8X  g   K(  V P                  VRRV 24        R# 	  \        R4      h)zSet the PDF PageLayout value.r
  zbad PageLayout valuer	  r	  r	  T)r	  	OneColumnTwoColumnLeftTwoColumnRightTwoPageLeftTwoPageRightr]  r   r  r  )r&   r	  r	  r  rH   s   &&   r'   set_pagelayoutDocument.set_pagelayout  s    m!19[))344a=C#BJA!QWWY.!!$!g>  /00r)   c                   V ^8  d   QhRR/# )r  r	  r  r,   )r  s   "r'   r  rt    s     / /S /r)   c                >   RpV P                  4       pV^ 8X  d   \        R4      hV'       g   \        R4      hV^ ,          R8X  d
   VR,          pV F?  pVP                  4       VP                  4       8X  g   K(  V P                  VRRV 24        R# 	  \        R4      h)zSet the PDF PageMode value.r
  zbad PageMode valuer	  r	  r	  T)r	  UseOutlines	UseThumbs
FullScreenUseOCUseAttachmentsr
  )r&   r	  r	  r  rH   s   &&   r'   set_pagemodeDocument.set_pagemode  s    `!19[))122A;#|HA~~1779,!!$
asG<  -..r)   c                H   a R oV3R lpV P                  V! V4      4       R# )a   Add / replace page label definitions in PDF document.

Args:
    doc: PDF document (resp. 'self').
    labels: list of label dictionaries like:
    {'startpage': int, 'prefix': str, 'style': str, 'firstpagenum': int},
    as returned by get_page_labels().
c                .   V R,           R2pV P                  RR4      R8w  d   VRV R,           R2,          pV P                  RR4      R8w  d   VRV R,           2,          pV P                  R	^4      ^8  d   VR
V R	,           2,          pVR,          pV# )zConvert Python label dict to corresponding PDF rule string.

Args:
    label: (dict) build rule for the label.
Returns:
    PDF label rule string wrapped in "<<", ">>".
	startpager	  prefixr`   z/P(r  r  z/S/firstpagenumz/St r	  )r:   )r  r  s   & r'   create_label_str2Document.set_page_labels.<locals>.create_label_str  s     %&b)Ayy2&",s5?+1--yy"%+s5>*++yy+a/tE.1233IAHr)   c                   < V P                  R R7       RP                  V  Uu. uF  pS! V4      NK  	  up4      pV# u upi )zReturn concatenated string of all labels rules.

Args:
    labels: (list) dictionaries as created by function 'rule_dict'.
Returns:
    PDF compatible string for page label definitions, ready to be
    enclosed in PDF array 'Nums[...]'.
c                    V R ,          # )r  r,   r  s   &r'   r
  ?Document.set_page_labels.<locals>.create_nums.<locals>.<lambda>  s    anr)   r  r`   )r  r  )r`  r  r  r  s   &  r'   create_nums-Document.set_page_labels.<locals>.create_nums  sB     KK4K5fEfU)%0fEFAH Fs   >N)ra  )r1  r`  r  r  s   && @r'   set_page_labelsDocument.set_page_labels  s"    	$	 	[01r)   c               (    V ^8  d   QhRRRRRRRR/# )r  r1  r
  r  r   r  r6   rs  r,   )r  s   "r'   r  rt    s6     } }}} } 	}r)   c           	        V P                   '       g   V P                  '       d   \        R4      hV P                  '       g   \        R4      hV'       g   \	        V P                  4       4      # \        V4      \        \        39  d   \        R4      h\	        V4      pV P                  pV^ ,          p\        V4      \        \        39  d   \        R4      hV^ ,          ^8w  d   \        R4      h\        \        V^,
          4      4       F  pW,          pW^,           ,          pR)V^,          u;8:  d   V8:  g   M \        RV R24      h\        V4      \        \        39  g   \	        V4      R*9  d   \        RV^,            24      h\        V^ ,          4      \        Jg   V^ ,          ^8  d   \        R	V^,            24      hV^ ,          V^ ,          ^,           8  g   K  \        R	V^,            24      h	  V P                  4       p	. p	^ .V	,           p
V P                  4       V
^ &   V\	        V	4      8  dB   \        V\	        V	4      ,
          4       F"  pV
P                  V P                  4       4       K$  	  ^ ^ /pR
^ RR)RR)RV
^ ,          /.p\        V4       EFN  pW,          pV^ ,          p\        V^,          4      p\!        V P                  ^,
          \#        ^ V^,          ^,
          4      4      pV P%                  V4      pV P'                  V4      P(                  p\+        ^HV^$,
          4      pRVR\,        /pV^,          ^ 8  d
   \.        VR&   \	        V4      ^8  d   \        V^,          4      \        \0        39   d   \+        ^HVV^,          ,
          4      VR&   M\        V^,          4      \2        J d   V^,          P5                  4       MTpRV9  d   VVR&   MuV V,          p\+        VR,          4      pVP6                  P(                  VP8                  ,
          Vn        VVP:                  ,          pVP<                  VP8                  3VR&   / pR)VR&   ^ VR
&   R)VR&   R)VR&   R)VR&   \>        P@                  ! VV4      VR&   VR,          VR&   VVR&   W^,
          ,          VR&   W^,           ,          VR&   VPC                  R4      VR&   VPC                  R^ 4      ^VPC                  R^ 4      ,          ,           VR&   V^,           W&   WV^,
          ,          ,          pVPC                  R4      '       g   V'       d   W8  d   VR
;;,          ^,          uu&   MVR
;;,          ^,          uu&   VR,          R)8X  d   V^,           VR&   V^,           VR&   M4VR,          VR&   VVR,          ,          pV^,           VR&   V^,           VR&   VP                  V4       EKQ  	  \E        V4       EF  w  ppRpVR
,          ^ 8w  d   VRVR
,           2,          p VVR,          ,          p VR,          R)8  d   VRV
VR,          ,           R2,          p TR,          R)8  d   TRT
TR,          ,           R2,          p TR,          R)8  d   TR T
TR,          ,           R2,          p TR,          R)8  d   TR!T
TR,          ,           R2,          p TR,          R)8  d   TR"T
TR,          ,           R2,          p TR#TR,          ,           ,          pTPC                  R4      '       d>   \	        TR,          4      ^8X  d'   TR$\M        \        TR,          4      4       R%2,          pTPC                  R^ 4      ^ 8  d   TR&TR,           2,          pT^ 8X  d
   TR',          pTR(,          pT PO                  Y,          T4       EK  	  V PQ                  4        V#   \F         d    \H        ^8  d   \K        4         ELi ; i  \F         d    \H        ^8  d   \K        4         ELi ; i  \F         d    \H        ^8  d   \K        4         ELi ; i  \F         d    \H        ^8  d   \K        4         ELi ; i  \F         d    \H        ^8  d   \K        4         ELi ; i  \F         d    \H        ^8  d   \K        4         ELi ; i  \F         d    \H        ^8  d   \K        4         ELi ; i)+a  Create new outline tree (table of contents, TOC).

Args:
    toc: (list, tuple) each entry must contain level, title, page and
        optionally top margin on the page. None or '()' remove the TOC.
    collapse: (int) collapses entries beyond this level. Zero or None
        shows all entries unfolded.
Returns:
    the number of inserted items, or the number of removed items respectively.
r  r  z'toc' must be list or tuplez'items must be sequences of 3 or 4 itemsz#hierarchy level of item 0 must be 1zrow z: page number out of rangezbad row zbad hierarchy level in row r  r  lastr  r  r  r  r]  r8
  topr  r   rp  r  r  r  r  r	  z/Count z/First r  z/Last z/Next z/Parent z/Prev z/Titlez/C[ r  z/F z/Type/Outlinesr	  r  )r   r  ))r   r  r   r  r9   r  r   r   r   rv  rS  r6   r  ro   re  r  r  r'  r(  r	  r3  r)  r  	LINK_NONEr  r7   r8  r	  rj  rx  ri  r  
getDestStrr:   rZ  rk   r  r{   r   r_  r  )r1  r  r  toclenrv  t0rg  t1t2	old_xrefsr  lvltabolitemsr  r  r  r{  r(  page_heightr  rC
  r   rn  rH  r   r  r>  r$  s   &&&                         r'   set_tocDocument.set_toc  s    ===C,,,;<<zzz[))s{{}%% 9T5M):;;S^^
V8D%=(FGGa5A:BCCeFQJ'(ABUBA,*, 4s*D!EFFRu-#b'2G 8QU9!566RU3&2a519 #>Ai!HII!ur!uqy  #>Ai!HII )  KKM	 	sY&&(QC	N"FS^35C,,./ 6 Q
 QVRaIJ vAAA$C!%Ecnnq(#a1*:;Cc*I**3/66KK",-CsFI6Itax$-	&!1vz!:#u-&+Bad0B&CIdO 04AaDzT/A!		yI9,*-	$"3x %io 6"&,,"5"5"? %(<(< <+077EGG*<	$AAgJAgJAfIAfIAfI((I>AfI AeHAgJ q/AhKUAfI"w/AgJ"x3a)--PQ:R6RRAgJa%FKC!G_-F j))X#.w1$w1$g"$"#a%w!"Qv"6N&	vf~. 1uV!"QvNN1q z w'EArC'{aG..r&z!
g;#WT"W+%6$7t<<Cf:?VDF$4#5T::Cf:?VDF$4#5T::C
h<"$Xd2h<&8%9>>C
f:?VDF$4#5T::C
x"W+-- vvg3r'{#3q#8ibk(:;<A>>vvgq!A%R[M**Av''4KCdgs+u (x 	o  '1,0@  '1,0@  '1,0@  '1,0@  '1,0@  '1,0@  '1,0@s~   (_(9)`#)`6)a7)b!)b+c( `` `32`36 aa b b b('b(+ cc c65c6c               D    V ^8  d   QhRRRRRRRRR	RR
RRRRRRRRRRR/# )r  r1  r
  r  r6   rC
  r8  r  r  r{  r  r  r  r  r   rj   r  r  rs  r  r,   )r  s   "r'   r  rt    s     jJ jJjJjJ jJ 	jJ
 jJ jJ jJ jJ jJ jJ jJr)   c
                   V P                  4       V,          p
^ p\        V4      \        J Ed   VR,          \        8X  dm   VR,          pV P	                  V4      pV P                  V4      P                  pVP                  R\        ^H^$4      4      pWP                  ,
          Vn	        WrR&   \        P                  ! W4      pVP                  R4      '       g   \        R4      hVP                  R4      pV'       dU   \        \        \         V4      4      p\#        V4      ^8w  g!   \%        V4      ^ 8  g   \'        V4      ^8  d   \        R4      hVP                  RR	4      pVP                  R
R	4      pV^V,          ,           pVP                  R4      pV P)                  V
VR,          VVVVR7      # V\*        8X  d   V P-                  V4      # Vf   Vf   R# Vf   V P)                  V
RVR7      # V\        8X  d   Ve#   V\/        ^V P0                  ^,           4      9  d   \        R4      hV P	                  V^,
          4      pV P                  V^,
          4      P                  pVf   \        ^HV^$,
          4      pM"\        V4      pWP                  ,
          Vn	        RVRVRVRVRVRV	/p\        P                  ! VV4      pVR8X  g   VP                  R4      '       g   \        R4      hV P)                  WR,          VR7      # )a  Update TOC item by index.

It allows changing the item's title and link destination.

Args:
    idx:
        (int) desired index of the TOC list, as created by get_toc.
    dest_dict:
        (dict) destination dictionary as created by get_toc(False).
        Outrules all other parameters. If None, the remaining parameters
        are used to make a dest dictionary.
    kind:
        (int) kind of link (pymupdf.LINK_GOTO, etc.). If None, then only
        the title will be updated. If pymupdf.LINK_NONE, the TOC item will
        be deleted.
    pno:
        (int) page number (1-based like in get_toc). Required if
        pymupdf.LINK_GOTO.
    uri:
        (str) the URL, required if pymupdf.LINK_URI.
    title:
        (str) the new title. No change if None.
    to:
        (point-like) destination on the target page. If omitted, (72, 36)
        will be used as target coordinates.
    filename:
        (str) destination filename, required for pymupdf.LINK_GOTOR and
        pymupdf.LINK_LAUNCH.
    name:
        (str) a destination name for pymupdf.LINK_NAMED.
    zoom:
        (float) a zoom factor for the target location (pymupdf.LINK_GOTO).
r  r   r  z/Azbad bookmark destrp  zbad color valuer  Fr  r  r  NN)re  r  rp  r  r  N)re  r  zbad page numberr  re   r  r`   )r  r   r7   r  r(  r	  r3  r:   r)  rj  r  r  r5   r   r   r  r  r9   r  r'  rf  r  r  rS  rv  )r1  r  rC
  r  r{  r  r  r  rj   r  r  r(  r&  re  rp  r  r  r  r  ddicts   &&&&&&&&&&          r'   set_toc_itemDocument.set_toc_item  s   Z $$&s+		?d" I-'MM#.	!..s3::]]4r27"TT)"$$%%i;F$$T** !455MM'*ES./u:?c%j1nE
Q$%677==/D]]8U3FQX%E }}Z0H''bz! (   9##C((<EM<''T'GG9{cq#..12D)EE !233cAg.I**373::Kz2{R/02Y"TT) D"3CHD
 !!)U3R<v0066011##D5#IIr)   c                :   V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\        P
                  ! \        P                  ! V4      \        R4      4      pVP                  '       g   \        \        \        4       \        P                  ! VP                  R4      4      p\        P
                  ! V\        R4      4      pVP                  '       d   \        W%V^ 4       R# \        P                  ! W$\        P                   ! 4       ^ 4      p\        P"                  ! V\        R4      \        R4      4       \        P"                  ! V\        R4      \        R4      4       \        P"                  ! V\        R4      V4       R# )	z"Store XML document level metadata.r  r  r  r  r  r  XMLN)r   r  r   r   r   r  r  r  r   r  MSG_BAD_PDFROOTr  r  r  r0  r/  r0  rU  )r&   r  ra  r  r%  r  s   &&    r'   set_xml_metadataDocument.set_xml_metadata  s   >>>T...;<<t$!!5#4#4c#:HV<LM_&:;22HOOG4LM  $(<=>>>cQ/&&%,,.!DCXf%5x
7KLXi%8(5/Jhz&:C@r)   c               (    V ^8  d   QhRRRRRRRR/# )r  r1  r
  verboser   fallbackrs  r  r,   )r  s   "r'   r  rt  %  s/     v+ v+* v+t v+t v+X^ v+r)   c                F  a a V'       gL   \         P                  ! S 4      p\         P                  ! V\        \	        S P
                  4      4      4       R# / oV 3R lpV 3R lpV 3R lpR pV3R lpV3R lp	V! S 4       S'       g   V'       d   \        R4       ^ # ^ p
^ pSP                  4        F  pV
\        V4      ,          p
K  	  S  F  pVP                  4        F  p\        V4      \        Jd   K  VR	,          R
,          pV	! V4      pVf   K6  SV,          w  ppw  ppVR,           F3  pVP                  V^ ,          4       VP                  V^,          4       K5  	  VVVV33SV&   K  	  K  	  SP                  4        EF  w  pw  pppV! VV^ ,          V^,          4      p\        V4      ^ ,          pVe   \        V4      \        V4      8  d   V'       d   \        RV: R24       Kl  V'       d   \        RV: R24       S P                  VR7      pV^ ,          pV! V4       S P                  VRR7      pV F<  pV! V4      w  ppS P!                  VV4       V'       g   V'       g   K2  V! VVV4       K>  	  V\        V4      ,          pEK  	  W,
          # )a4  Build font subsets in a PDF.

Eligible fonts are potentially replaced by smaller versions. Page text is
NOT rewritten and thus should retain properties like being hidden or
controlled by optional content.

This method by default uses MuPDF's own internal feature to create subset
fonts. As this is a new function, errors may still occur. In this case,
please fall back to using the previous version by using "fallback=True".
Fallback mode requires the external package 'fontTools'.

Args:
    fallback: use the older deprecated implementation.
    verbose: only used by fallback mode.

Returns:
    The new MuPDF-based code returns None.  The deprecated fallback
    mode returns 0 if there are no fonts to subset.  Otherwise, it
    returns the decrease in fontsize (the difference in fontsize),
    measured in bytes.
Nc                L  < SP                  V R4      pV^ ,          R8w  d   R	# \        V^,          ^R
 P                  RR4      4      pSP                  VR4      pV^ ,          R8w  d   RpM	V^,          pSP                  VR4      pV^ ,          R8w  d   RpW43# V^,          pW43# )z(Retrieve old font '/W' and '/DW' values.DescendantFontsr<
  Nrk  r`   WDWr6   NNr  )r  r6   r  )r  dfdf_xrefwidthsdwidthsr1  s   &    r'   get_old_widths-Document.subset_fonts.<locals>.get_old_widthsH  s    !!$(9:B!u!!"Q%"+--eR89G%%gs3FayG#&&w5GqzU" ?" "!*?"r)   c                  < SP                  V R4      pV^ ,          R8w  d   R# \        V^,          ^R	 P                  RR4      4      p\        V4      \        Jg	   V'       g3   SP                  VR4      ^ ,          R8w  d   SP                  VRR4       MSP                  VRV4       \        V4      \        Jg	   V'       g4   SP                  VR4      ^ ,          R8w  d   SP                  VRR4       R# SP                  VRV4       R# )
zRestore the old '/W' and '/DW' in subsetted font.

If either parameter is None or evaluates to False, the corresponding
dictionary key will be set to null.
r9  r<
  Nrk  r`   r:  r  r;  r  )r  r6   r  r   r  r  )r  r?  r@  r=  r>  r1  s   &&&  r'   set_old_widths-Document.subset_fonts.<locals>.set_old_widthsZ  s     !!$(9:B!u"Q%"+--eR89GVC'v3;K;KGUX;Y<<   #v6  #v6WS(S=M=M>>>   $7    $8r)   c                  < ^ RI p^ RIpRP                  VP                  \	        VP
                  4      ^R7      4      R,           pS
P                  V RR7      pVP                  RRV,           4      pS
P                  V R4      pV^ ,          R	8X  d   \        V^,          ^R P                  R
R4      4      pS
P                  VR4      pV^ ,          R8X  d`   \        V^,          P                  R
R4      4      pS
P                  VRR7      p	V	P                  RRV,           4      p	S
P                  W4       S
P                  W4       R# )zGenerate a name prefix to tag a font as subset.

We use a random generator to select 6 upper case ASCII characters.
The prefixed name must be put in the font xref as the "/BaseFont" value
and in the FontDescriptor object as the '/FontName' value.
Nr`   )r  +Tr[  z
/BaseFont/r9  r<
  rk  FontDescriptorr  z
/FontName/r  )randomstringr  choicesr   ascii_uppercaser^  r  r  r6   r_  )r3  rI  rJ  r  font_strr=  r>  r   fd_xreffd_strr1  s   &         r'   set_subset_fontname2Document.subset_fonts.<locals>.set_subset_fontnamer  s    WWV^^E&2H2H,IQ^OPSVVFxDAH''lV6KLH!!(,=>B!ubeAbk11%<=%%g/?@a5F?!"Q%--r":;G __W_FF#^^L,:OPF%%g6h1r)   c           
         ^ RI Hp ^ RIpTP                  4       ;_uu_ 4       pT R2pT R2pT R2pTRRT 2RR	R
RR.p	\        P                  ! T R2RRR7      ;_uu_ 4       p
RT9   dO   T	P                  RT 24       TP                  ^4       \        T4      pT F  pT
P                  T R24       K  	  MNT	P                  RT 24       TP                  ^4       \        T4      pT F  pT
P                  TR R24       K  	  RRR4       \        P                  ! TR4      ;_uu_ 4       pTP                  T 4       RRR4        \        P                  ! T4        TP#                  T	4       \%        TR7      pTP&                  pTP(                  ^ 8X  d   RpRRR4       T#   \         d$    \        '       d   \	        4        \        R4       h i ; i  + '       g   i     L; i  + '       g   i     L; i  \          d     Li ; i  \          d    \	        4        Rp Li ; i  + '       g   i     X# ; i)zBuild font subset using fontTools.

Args:
    buffer: (bytes) the font given as a binary buffer.
    unc_set: (set) required glyph ids.
Returns:
    Either None if subsetting is unsuccessful or the subset font buffer.
Nz/This method requires fontTools to be installed.z/oldfont.ttfz/newfont.ttfz/uncfile.txtz--retain-gidsz--output-file=z--layout-features=*z--passthrough-tablesz--ignore-missing-glyphsz--ignore-missing-unicodesz--symbol-cmapr   utf8)r    z--gids-file=r#   z--unicodes-file=04xwb)r%  )fontTools.subsetsubsetImportErrorr  r{   rv   tempfileTemporaryDirectoryr;   r<   ro   r  r   r   rh   r  rk   mainr  r3
  glyph_count)r3
  unc_setgid_setftsrZ  tmp_diroldfont_pathnewfont_pathuncfile_pathr  unc_fileunc_listuncr%  r  
new_buffers   &&&             r'   build_subset+Document.subset_fonts.<locals>.build_subset  s   .
 ,,..'"),7"),7"),7 #$\N3)*-/#	 WWy5sVLLPX(l<.$ABC(#'=#+C$NNcU":6 $, &6|n$EFC(#'=#+C$NNc#Yb>: $, M WW\400HNN6* 1IIl+&HHTN6D!%J''1,%)
U /\ g  ''N,<IJ* ML 10 !  ! &"$!%J&W /.\ s   F( AH-%B$G		'H-0G,	H-G?"<H(G?GG)$H-,G<7H-?H
H-HH-H*'H-)H**H--H>	c           
       <a R oV3R lp\        V P                  4       EF  pV P                  VRR7       F  pV^ ,          pV^,          pV^,          pVR9  d   K'  \        V4      ^8  d   V^,          R8X  d   KG  V P	                  V4      pVR	,          pV! W4      p	SP                  V\        4       \        4       \        4       \        4       334      w  rpVP                  V4       V	 F  pV
P                  V4       K  	  \        VR7      pV
P                  VP                  4       ?WV3SV&   K  	  EK  	  R# )
zPopulate 'font_buffers'.

For each font candidate, store its xref and the list of names
by which PDF text may refer to it (there may be multiple).
c                    RV 9   dT   V P                  R4      p\        W^,           V^,            ^4      pV P                  WV^,            \        V4      4      p KZ  V # )zLRecreate font name that contains PDF hex codes.

E.g. #20 -> space, chr(32)
#)r   r6   r  chr)r   r  r  s   &  r'   	norm_name@Document.subset_fonts.<locals>.repl_fontnames.<locals>.norm_name  sR    
 Tk		#ADQQ/4A<<QQ@Dr)   c                  < V^,          pV.pV P                  V^ ,          R4      ^,          R,          pS! V4      pW#9  d   VP                  V4       V P                  V^ ,          R4      pV^ ,          R8w  d   V# V^,          ^R pVP                  R4      '       d"   \        VRR 4      pV P	                  VRR7      pVP                  R	4      pV^ 8  d~   VP                  R
V^,           4      p\        VP                  R
V^,           4      VP                  RV^,           4      4      pWG^,           V pS! V4      pW#9  d   VP                  V4       V# )zoReturn a list of fontnames for an item of page.get_fonts().

There may be multiple names e.g. for Type0 fonts.
r  r	  r9  r<
  r  NTr[  z	/BaseFontr	  r	  r  )r  ro   r  r6   r^  r   r  )	r1  rE   r   rs  descendentsr  rJ  rK  ro  s	   &&      r'   get_fontnamesDDocument.subset_fonts.<locals>.repl_fontnames.<locals>.get_fontnames  sJ   
  7!
++DGZ@CBG$X.(LL*!..tAw8IJq>W, L)!nQr2''//{3B/0D"%//$4/"HK %%k27$))#rAv6B[--c26:K<L<LTSUXYSY<Z[B*6B7H(2H,X.r)   Tr  rG  r&  N)otfttfwoffwoff2r  )
rS  rv  r  r9   r  r:   r  r  r  r   )r1  rt  rg  r  	font_xreffont_extr  extrr&  rs  name_setxref_setsubsetsr   r  ro  font_bufferss   &              @r'   repl_fontnames-Document.subset_fonts.<locals>.repl_fontnames  s#   	8 3>>*++AD+9A !!I tH tH (  !8}q(Xa[C-? ++I6D!%bJ)#1E2>2B2B"SUCECE35>$B3/H LL+ % T* !&:6DLL+08G/LL,9 : +r)   c                X   < SP                  4        F  w  pw  p pW9   g   K  Vu # 	  R # r+   )rD   )r   r3
  r  r@  r  s   &   r'   find_buffer_by_name2Document.subset_fonts.<locals>.find_buffer_by_name  s3    ,8,>,>,@((1a#!M -A r)   zNo fonts to subset.r  :N!   NcharszCannot subset r   zBuilt subset of font rw  Tr[  )r   r{  pdf_subset_fonts2r   rS  rv  rv   r  r9   get_texttracer   r7   r  rD   r'  r^  r_  ) r1  r5  r6  ra  rA  rD  rP  ri  r  r  old_fontsizenew_fontsizer&  r   rJ  r   r3
  r  r  set_ucsset_gidr  
old_bufferr  rh  r  r3  rM  r|  width_table	def_widthr  s    f&&                            @r'   subset_fontsDocument.subset_fonts%  ss   8 55c:C##CeCNN.C)DE	#$	0	20>	@K	MZ	 	s-/&++-JC
O+L . D **,:T)<,,X6>9Ef9M6($6WggAKK!%KK!% ' )1(Wg<N'OV$ - " :F9K9K9M5J58W%j'!*gajIJH~a(H!S_J%GnXL:;/|1=>""j"9C1vH) ' H
 &	)7	)B&Y!!)X6))"9k9E & C
O+L9 :N< **r)   c                
   \        V 4      p\        P                  ! \        P                  ! V4      \	        R4      \	        R4      \	        R4      4      p\        P
                  ! V4      '       d   \        P                  ! V4      '       g   V^8  d   R# \        \        4      hV^ 8  d   R# \        P                  ! W14       V'       d9   \        P                  ! V4       \        P                  ! VP                  4       R# R# )zActivate an OC layer.r  rX  r}  N)r   r   r   r  r  rI  r  r   MSG_BAD_OC_LAYERpdf_select_layer_configpdf_set_layer_config_as_defaultrm  r   )r&   r  
as_defaultra  cfgss   &&&  r'   switch_layerDocument.switch_layer]  s    t$""!!3' (#	 !!4((0C0CT0J0Jz.//A:%%s31137!!3>>2 r)   c                   V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\        P
                  ! V4      p\        V^V^,
          4      '       g   \        R\        4       \        V4       \        WB4      p\        P                  ! WAV4       V'       d   \        \        V4      4       R# R# )z!Replace object definition source.r  r}  N)r   r  r   r   r   r  r  r  r  rd  r  r-  JM_refresh_linksr   )r&   r  r   r   ra  xreflenr]  s   &&&&   r'   r_  Document.update_objectq  s    >>>T...;<<t$$$S)a++J-%c073l401 r)   c                   V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\        P
                  ! V4      pV^8  g   W8  d   \        \        4      h\        P                  ! WQ^ 4      p\        P                  ! V4      '       g   \        \        4      h\        V4      pVP                  '       g   \        \        4      h\        WWW4       ^Vn        R# )zReplace xref stream part.r  N)r   r  r   r   r   r  r  r  r  MSG_IS_NO_DICTr.  r   r  r/  r0  dirty)	r&   r  r   r\  compressra  r  r  r%  s	   &&&&&    r'   r
  Document.update_stream  s    >>>T...;<<t$$$S)!8t~l++$$S2  %%n-- (~~~^,,31	r)   c                p    \        V ^ R7      pVP                  '       d   \        P                  ! V4      # ^ # )z!
Count versions of PDF document.
r  )r   r   r   pdf_count_versionsr  s   & r'   version_countDocument.version_count  s-    
 ta0>>>++C00r)   c                	    ^ RI Hp V! 4       pV P                  VVVV
VVVVVVVV	VVVVVVVVVR7       VP                  4       # )rx   r  )r  r  r  rj
  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r!  )r;   r  r"  r  )r&   r  r  r  r  r  r  r  r  r  r  rj
  r  r  r  r  r  r  r  r   r!  r  bios   &&&&&&&&&&&&&&&&&&&&&  r'   r   Document.write  sl    . 	i		#%-+'%'!"3'#5 /+ 	 	
. ||~r)   c                	&    V P                   ! V/ VB # r+   )r   r  s   &*,r'   r  Document.tobytes  s    zz4*6**r)   c                b    \        V 4       V P                  P                  V P                  4      # zPDF xref number of page.ro  r   r(  r]  r-   s   &r'   r  Document.xref  %     	D{{$$T[[11r)   keepc          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r  r1  r
  sourcer6   targetr  r   rs  r  r,   )r  s   "r'   r  rt    s0     !3 !3z !33 !3 !3d !3VZ !3r)   c               t   V P                  V4      '       d'   V P                  V4      pV P                  VVRRR7       Vf   . pV P                  V4       F  pWS9   d   K  V P	                  W%R4       K  	  V P                  V4       F-  pV P                  W4      pV P	                  W%V^,          4       K/  	  R# )a  Copy a PDF dictionary object to another one given their xref numbers.

Args:
    doc: PDF document object
    source: source xref number
    target: target xref number, the xref must already exist
    keep: an optional list of 1st level keys in target that should not be
          removed before copying.
Notes:
    This works similar to the copy() method of dictionaries in Python. The
    source may be a stream object.
FT)r  r\  Nr  )xref_is_streamxref_stream_rawr
  r
  r  r  )r1  r  r  r  r   r  rE   s   &&&$   r'   	xref_copyDocument.xref_copy  s     f%%((0F	   <D$$V,C{V&1 -
 $$V,C##F0DV$q'2 -r)   c                   \        V 4      p\        P                  ! V4      p\        V^V^,
          4      '       g   VR8w  d   \	        \
        4      hV^ 8  d   \        P                  ! W14      pM\        P                  ! V4      pVP                  '       g   R# \        P                  ! WR4      pVP                  '       g   R# Rp\        P                  ! V4      '       d   Rp\        P                  ! V4      R R2pEMo\        P                  ! V4      '       d   RpEMO\        P                  ! V4      '       d   RpEM/\        P                  ! V4      '       d   Rp\        P                  ! V4      R pM\        P                   ! V4      '       d   R	pM\        P"                  ! V4      '       d   RpRpM\        P$                  ! V4      '       d%   R
p\        P&                  ! V4      '       d   RpM{RpMx\        P(                  ! V4      '       d   RpR\        P*                  ! V4       2pM@\        P,                  ! V4      '       d#   Rp\/        \        P0                  ! V4      4      pMRpVf   \3        V^^ 4      p	\5        V	4      pW3# )z+Get PDF dict key value of object at 'xref'.r  Nr  rH  r  r<
  r7   r6   r  r   r	  r
  r   r	  rJ  unknownr  )r  r  )r   r   r  r  r   r  rJ  r  r   r|  r9
  r  rI  r  
pdf_is_intr  pdf_is_realr  r	  r	  r  r  pdf_is_stringr	  r  JM_object_to_bufferr  )
r&   r  r  ra  r  r  subobjr   r   r%  s
   &&&       r'   r  Document.xref_get_key  s	   t$$$S)a++
l++!8''2C##C(C~~~##$$S.   ##  ((D&&v.q16D''Dv&&Df%%D&&v.q1Dv&&Dv&&DDv&&D  ((v&&Du((012D  ((D$U%=%=f%EFDD<%fa3C',D|r)   c                   \        V 4      p\        P                  ! V4      p\        V^V^,
          4      '       g   VR8w  d   \	        \
        4      hV^ 8  d   \        P                  ! W!4      pM\        P                  ! V4      p\        P                  ! V4      p. pV^ 8X  d   V# \        V4       F>  p\        P                  ! \        P                  ! WG4      4      pVP                  V4       K@  	  V# )zFGet the keys of PDF dict object at 'xref'. Use -1 for the PDF trailer.r  )r   r   r  r  r   r  rJ  r  r  rS  r  r  ro   )	r&   r  ra  r  r  rG   r   rg  r  s	   &&       r'   r
  Document.xref_get_keys,  s    t$$$c*a++
l++!8''3C##S)C$6IqA##U%;%;S%DECIIcN  	r)   c                    V P                   '       g   V P                  '       d   \        R4      hV P                  VR4      ^,          R8X  d   R# R# )zCheck if xref is a font object.r  r  z/FontTFr   r  r   r  r&   r  s   &&r'   xref_is_fontDocument.xref_is_font?  sB    >>>T...;<<T6*1-8r)   c                    V P                   '       g   V P                  '       d   \        R4      hV P                  VR4      ^,          R8X  d   R# R# )z!Check if xref is an image object.r  r  rm  TFr  r  s   &&r'   xref_is_imageDocument.xref_is_imageG  sB    >>>T...;<<T9-a0H<r)   c                    \        V ^ R7      pVP                  '       g   R# \        \        P                  ! W!4      4      # )z!Check if xref is a stream object.r  F)r   r   r   r   pdf_obj_num_is_streamr  s   && r'   r  Document.xref_is_streamO  s0    ta0~~~E//:;;r)   c                    V P                   '       g   V P                  '       d   \        R4      hV P                  VR4      ^,          R8X  d   R# R# )z Check if xref is a form xobject.r  r  rn  TFr  r  s   &&r'   xref_is_xobjectDocument.xref_is_xobjectV  sB    >>>T...;<<T9-a0G;r)   c                t    ^ p\        V ^ R7      pVP                  '       d   \        P                  ! V4      pV# )zGet length of xref table.r  )r   r   r   r  )r&   r  ra  s   &  r'   r  Document.xref_length^  s1    ta0>>>((-Gr)   c                    V P                   '       d   \        R4      h\        '       d%   \        P                  ! V P
                  WV4      pV# \        V 4      p\        P                  ! V4      p\        V^V^,
          4      '       g   VR8w  d   \        \        4      hV^ 8  d   \        P                  ! WQ4      pM\        P                  ! V4      p\        \        P                  ! V4      W#4      p\        V4      p	V	# )z#Get xref object source as a string.r   r  )r   r   r  r   r^  r   r   r   r  r  r  rJ  r  r  r  JM_EscapeStrFromBuffer)
r&   r  r\  r  rI   ra  r  r  r%  r   s
   &&&&      r'   r^  Document.xref_objectf  s    >>>.//;##TYY%HCJt$$$S)a++
l++!8''2C##C(C!%"<"<S"A:U%c*r)   c           	        V P                   '       d   \        R4      hV'       d<   \        V\        4      '       d&   \        P                  V4      \        4       R039  d   \        R4      h\        V\        4      '       d@   V'       d8   V^ ,          R8X  d5   \        P                  VR,          4      \        4       8w  d   \        R4      h\        V 4      p\        P                  ! V4      p\        V^V^,
          4      '       g   VR8w  d   \        \        4      hVR8w  d   \        P                  ! WA4      pM\        P                  ! V4      p\        WbV4      pVP                  '       g   R# VR8w  d   \        P                   ! WAV4       R# \        P"                  ! V4      p\%        V4       FC  p	\        P&                  ! V\        P(                  ! Wy4      \        P*                  ! Wy4      4       KE  	  R# )z&Set the value of a PDF dictionary key.r   r	  z	bad 'key'r	  zbad 'value'Nr  )r   r   r@   r  INVALID_NAME_CHARSintersectionr  r   r   r  r  r  rJ  r  JM_set_object_valuer   r-  r  rS  rU  r  r  )
r&   r  r  r   ra  r  r  r]  rG   rg  s
   &&&&      r'   r  Document.xref_set_keyy  sx   >>>.//*S#..2D2Q2QRU2V_b_dgjfk^l2l[))%%%UeAh#oJ\JiJijoprjsJtx{x}J}]++t$$$S) a++
l++2:''2C##C(C%c6!!!2:##Cw7""7+A1X""..w:..w: r)   c                   V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\        P
                  ! V4      p\        V^V^,
          4      '       g   VR8w  d   \        \        4      hV^ 8  d   \        P                  ! W!^ 4      pM\        P                  ! V4      pRp\        P                  ! V4      '       d"   \        P                  ! W!4      p\        V4      pV# )zGet decompressed xref stream.r  Nr  )r   r  r   r   r   r  r  r  r  r  r!  pdf_load_stream_numberr#  r&   r  ra  r  r  r$  r%  s   &&     r'   r
  Document.xref_stream  s    >>>T...;<<t$$$c*a++
l++19((#Q7C##S)C$$..:C #&Ar)   c                   V P                   '       g   V P                  '       d   \        R4      h\        V 4      p\        P
                  ! V4      p\        V^V^,
          4      '       g   VR8w  d   \        \        4      hV^ 8  d   \        P                  ! W!^ 4      pM\        P                  ! V4      pRp\        P                  ! V4      '       d"   \        P                  ! W!4      p\        V4      pV# )z&Get xref stream without decompression.r  Nr  )r   r  r   r   r   r  r  r  r  r  r!  pdf_load_raw_stream_numberr#  r  s   &&     r'   r  Document.xref_stream_raw  s    >>>T...;<<t$$$c*a++
l++19((#Q7C##S)C$$22C>C #&Ar)   c                d   \        V 4      p\        P                  ! \        P                  ! V4      \	        R4      4      pVP
                  '       g   \        \        \        4       \        P                  ! V\	        R4      4      p^ pVP
                  '       d   \        P                  ! V4      pV# )z"Get xref of document XML metadata.r  r  )
r   r   r  r  r  r   r  r1  r  r  )r&   ra  r  r  r  s   &    r'   xref_xml_metadataDocument.xref_xml_metadata  s|    t$!!5#4#4c#:HV<LM_&:;  $(<=>>>##S)Dr)   c                	    V P                   # r+   )r  r-   s   &r'   r
  Document.<lambda>  s    DMMr)   )r  r  r  r  r  r=  r  r  r-
  r   r  r  r  r   r   r  r   ru  )r   	   )NNNNrx   rx   rr  r  )r  r  r  )r  r  r  rx   rx  rz  r<  )r  S  J  NNrx   NN)r  r  NN)rx   r  rx   )r  )rx   rx   N)r   FTTTFFFFFr    NNTr  r  rx   F)r  rx   Nr  )r   NNNFr%  )r  r  r  r  TTrx   r  )Nrr  r  r  helvNru  r+   )Nrx   rx   rr  r	  rw  )
Nrx   rx   TTTTTFNrv  )rx   rx   rx   rx   rx   rx   rx   rx   rx   rx   rx   rx   r  r  NNr  rx   rx   F)TTTTTTTrx   TTTTT)FNNN)NNNNN)rx   NNN)NNNNNNNrx   FF)rx   Nr  r  )FFFFFFFFFFFFr  r  NNr  rx   rx   F)r   r  r  __dict__)r/   r0   r1   r2   r|  r  r  r  typingoverloadr  sysversion_infor   r  r   r  r  r  r  r  r;  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r'  r,  r/  rA  rD  rQ  r  r5  ra  rf  r{  ri  rp  r  r  r  r  rw  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r#  r(  r4  rU  rZ  ra  re  r  ry  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r	  r  r  r	  r	  r"	  r&	  r+	  r1	  r5	  r:	  r>	  rG	  rL	  rP	  rT	  rI  r\	  rg	  rj	  r  rw	  r}	  r	  r	  r   r	  r  r  r	  r  rv  r	  r	  r(  r	  r	  rX  r]  r  r  r	  r	  r	  r  r'
  r
  rN
  r"  ro
  rs
  r
  r
  r
  r  r
  r
  r
  r
  r  r
  r
  r  r  r'  r-  r2  r  r  r_  r
  r  r   r  r  r  r  r
  r  r  r  r  r  r^  r  r
  r  r  	__slots__r  	is_streamr3   r,   r)   r'   r   r   	  s   ,;. __  6!		 
	 
	 
	!W<rX)($@9+C@ C@LDP DPL
>
+-^%("HDL% <@)" (	/6 p0)	8	 
'H8  (/DL
9@T @4 @$ 3 3$.; ;2<& &
C J$ $L)&	*, >/b</b/6 pc cJ,2"-^AHF$ $
 
K4! #'	!
 ! &*! #!  !  !FL L* 4 4l"
{,)V <t( 	t(
 t( t( t( t( t( t( t( t( t( t(n $ $    ,   ; ;  	8&P
"
4% 9 9 / /2(<%  :; ;(  0   $/*$ 	5 	5("    ( (:H  0/ 9v*4U,n2AF\?|/"YY; Y;v"
 "
H 6?/B:".; ;z,G GR1 / *2X} }~jJ jJXA$v+ v+p	3(2$  0d+ 2 2
!3T !3F0d&<&$L$$
 CI12GIr)   r   c                  >    ] tR tRtR tR tR
R ltR tR tR t	Rt
R	# )DocumentWriteri  c                	    V # r+   r,   r-   s   &r'   r  DocumentWriter.__enter__  r  r)   c                	&    V P                  4        R # r+   r  r  s   &*r'   r  DocumentWriter.__exit__  r  r)   c                	,   \        V\        4      '       d   M<\        VR 4      '       d   \        V4      pM\        VR4      '       d   VP                  p\        V\        4      '       d7   \        P
                  ! W\        P
                  P                  4      V n        R# \        V4      p\        P
                  ! W2\        P
                  P                  4      V n        VP                  4       ^ 8X  g   Q h\        V P                  R4      '       g   Q hR# )r  r   _outN)r@   r  r=   r   r   FzDocumentWriterPathType_PDFr   rC	  OutputType_PDFrW  )r&   r   r!  rF	  s   &&& r'   r   DocumentWriter.__init__  s    tS!!dJ'':DdF##99DtS!!..u?U?U?b?bcDI (.C..e>T>T>c>cdDI'')Q...DIIv....r)   c                	t    \        V4      p\        P                  ! V P                  V4      p\	        V4      pV# r+   )r  r   fz_begin_pager   rG  )r&   rJ  	mediabox2rR  device_wrappers   &&   r'   
begin_pageDocumentWriter.begin_page  s2    #H-	$$dii;&/r)   c                	F    \         P                  ! V P                  4       R # r+   )r   fz_close_document_writerr   r-   s   &r'   r  DocumentWriter.close  s    &&		2r)   c                	F    \         P                  ! V P                  4       R # r+   )r   fz_end_pager   r-   s   &r'   end_pageDocumentWriter.end_page  s    499%r)   r$  Nr`   )r/   r0   r1   r2   r  r  r   r
  r  r  r3   r,   r)   r'   r  r    s     /.3&r)   r  c                  0   ] tR tRtR tRR ltR t]R 4       t]R 4       t	]R 4       t
RR	 lt]R
 4       t]R 4       tRR ltRR lt]R 4       tR tRR lt]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       tRR ltR tR tRtR# )r  i   c                	0    \        V 4      \        Jd   R # R # r+   )r   r  r-   s   &r'   r[  Font.__del__   s    :T! "r)   Nc                	   V'       df   \        VR 4      '       d   VP                  4       pM!\        V\        4      '       d   \	        V4      p\        V\        4      '       g   \        R4      h\        V\        4      '       d   VP                  4       pRV9   g   RV9   g   RV9   d   \        R4       VR
9   d   ^ pMVP                  R4      '       d   ^pMVP                  R4      '       d   ^pMhVP                  R4      '       d   ^pMNV\        P                  4       9   d   ^ R	IpVP                  V4      pR	p?MV^ 8  d   \        P                  W4      p\         P"                  ! V4      p\%        WW4WWxW4
      pWn        R	# )r  zbad type: 'fontbuffer'r	  \r   z!Warning: did you mean a fontfile?china-skoreajapanN)cjkchina-tchina-ts)r=   r  r@   r  r  r   r  r  rv   r5   fitz_fontdescriptorsr  pymupdf_fontsmyfontBase14_fontdictr:   r   r  JM_get_fontr   )r&   r   r%  r&  scriptrI  r  is_bold	is_italicis_serifembedfname_lowerr   rH  r  s   &&&&&&&&&&&    r'   r   Font.__init__	   sK    z:..'002
J	22":.
j%00 !9::h$$"..*Kk!T[%8C;<N;<<<''	22''00''00 4 9 9 ;;$*11+>
!A*..xB11(;8tx8 	r)   c                	"    R V P                    R2# )zFont('r  r   r-   s   &r'   r   Font.__repr__<   s    		{"%%r)   c                B    \         P                  ! V P                  4      # )z Return the glyph ascender value.)r   fz_font_ascenderr   r-   s   &r'   r:  Font.ascender?        %%dii00r)   c                	6    V P                   P                  4       # r+   )r   fz_font_bboxr-   s   &r'   r6  	Font.bboxD   s    yy%%''r)   c                	    \         P                  ! \         P                  ! V P                  P                  P
                  4      4      p\         P                  ! V4      # r+   )r   rF  ll_fz_keep_bufferr   r   r3
  fz_buffer_extract_copy)r&   r4  s   & r'   r3
  Font.bufferH   s<    ..%"9"9499;O;O;V;V"WX++W55r)   c           	     z   \         P                  ! V4      p. pV F  p	\        V	4      p
V'       d6   \         P                  ! V P                  V
4      pV^ 8  d   V P                  pM$\         P
                  ! V P                  WV4      w  rVP                  V\         P                  ! XW4      ,          4       K  	  V# )z@Return tuple of char lengths of unicode 'text' under a fontsize.)r   r  ordfz_encode_character_scr   !fz_encode_character_with_fallbackro   r  )r&   r   r   rI  r$  wmode
small_capsrH  r   chr  gidr  s   &&&&&&&      r'   char_lengthsFont.char_lengthsM   s    11(;BBA22499a@!899D!CCDIIqZ^_	IIh!7!7c!IIJ  	r)   c                B    \         P                  ! V P                  4      # )z!Return the glyph descender value.)r   fz_font_descenderr   r-   s   &r'   r;  Font.descender\   s     &&tyy11r)   c                	  a \         P                  ! V P                  P                  4      pV'       g   R # \	        V\         P
                  4      '       g   Q h\        '       d|   VP                  .oV3R lpV! ^4      pV! ^4      pV! ^4      pV! ^4      pV! ^4      pV! ^4      pV! ^4      p	V! ^4      p
V! ^4      pV! ^4      pV! ^4      pV! ^4      pV! ^4      pR\        '       d   XMVP                  R\        '       d   XMVP                  R\        '       d   XMVP                  R\        '       d   XMVP                  R\        '       d   XMVP                  R\        '       d   XMVP                  R\        '       d   X	MVP                  R	\        '       d   X
MVP                  R
\        '       d   XMVP                  R\        '       d   XMVP                   R\        '       d   XMVP"                  R\        '       d   XMVP$                  R\        '       d   XMVP&                  R\        '       d   X/# VP(                  /# )Nc                j   < S^ ,          ^V ,          ^,
          ,          pS^ ,          V ,	          S^ &   V# ru  r,   )bitsrI   rH   s   & r'   bFont.flags.<locals>.bk   s/    dqDy!m,tt|!
r)   monoserifr  r  
substitutestretchz	fake-boldzfake-italicopentypezinvalid-bboxr  zcjk-langr(  znever-embed)r   ll_fz_font_flagsr   r   r@   fz_font_flags_tr   is_monor'  r%  r&  ft_substitute
ft_stretch	fake_boldfake_italichas_opentypeinvalid_bboxr  cjk_langr(  never_embed)r&   r  rI  rR  r'  r%  r&  rS  rT  rU  rV  rW  rX  rY  r(  rZ  rH   s   &               @r'   r  
Font.flagsa   s   ""499#7#781e334444;A dGtHdG!IaDM1J!IA$KQ4LQ4LtHaDEA$K;;AIIKKQZZ;;AII[[	akk!//kk
q||[[	akk{{KKQUUKKQZZ!''{{ 	 AB 	r)   c                   \         P                  ! V4      pV'       d6   \         P                  ! V P                  V4      pV^ 8  d   V P                  pM$\         P                  ! V P                  WV4      w  rx\         P
                  ! XWt4      # )z2Return the glyph width of a unicode (font size 1).)r   r  r;  r   r<  r  )	r&   chr_rI  r$  r=  r>  rH  r@  r  s	   &&&&&&   r'   glyph_advanceFont.glyph_advance   sj    11(;..tyy$?Caxyy??		4Y]^IC%%dC77r)   c                X   \         P                  ! V4      pV'       d6   \         P                  ! V P                  V4      pV^ 8  d   V P                  pM$\         P                  ! V P                  WV4      w  rg\        \         P                  ! XV\         P                  ! 4       4      4      # )z1Return the glyph bbox of a unicode (font size 1).)r   r  r;  r   r<  r+  fz_bound_glyphr|  )r&   charrI  r$  r>  rH  r@  r  s   &&&&&   r'   
glyph_bboxFont.glyph_bbox   sx    11(;..		4@Caxyy??DZ^_ICE(($U^^5EFGGr)   c                	B    V P                   P                  P                  # r+   )r   r   r]  r-   s   &r'   r]  Font.glyph_count   s    yy##///r)   c                    \        V4      # )z$Return the unicode for a glyph name.)glyph_name_to_unicoder  s   &&r'   rh  Font.glyph_name_to_unicode   s    $T**r)   c                &   V'       d=   \         P                  ! V4      p\         P                  ! V P                  WV4      w  rxV# V'       d$   \         P                  ! V P                  V4      pV# \         P
                  ! V P                  V4      pV# )z0Check whether font has a glyph for this unicode.)r   r  r<  r   r;  r  )	r&   rn  rI  r$  r6  r>  rH  r@  r  s	   &&&&&&   r'   	has_glyphFont.has_glyph   sv    55h?D??		3X\]IC 
	 22499cB 
 //		3?
r)   c                	B    \         P                  ! V P                  4      # r+   )r   fz_font_is_boldr   r-   s   &r'   r%  Font.is_bold   s    $$dii00r)   c                	B    \         P                  ! V P                  4      # r+   )r   fz_font_is_italicr   r-   s   &r'   r&  Font.is_italic   s    &&		22r)   c                	B    \         P                  ! V P                  4      # r+   )r   fz_font_is_monospacedr   r-   s   &r'   is_monospacedFont.is_monospaced   s    **DII66r)   c                	B    \         P                  ! V P                  4      # r+   )r   fz_font_is_serifr   r-   s   &r'   r'  Font.is_serif   s    %%tyy11r)   c                	    R # r%  )r   r   rP  r   r   cppyygbl"mupdf_mfz_font_flags_ft_substituterS  ll_fz_font_t3_procspdf_font_writing_supported)r&   r  r  r{  rS  s   &    r'   is_writableFont.is_writable   s    r)   c                	F    \         P                  ! V P                  4      pV# r+   )r   fz_font_namer   rk  s   & r'   r   	Font.name   s      +
r)   c                   V P                   p\        P                  ! V4      p^ p	\        V\        4      '       g   \        \        4      hV Fm  p
\        V
4      pV'       d!   \        P                  ! W{4      pV^ 8  d   TpM\        P                  ! W{WH4      w  rV	\        P                  ! XW4      ,          p	Ko  	  W,          p	V	# )z1Return length of unicode 'text' under a fontsize.)r   r   r  r@   r  r  MSG_BAD_TEXTr:  r;  r<  r  )r&   r   r   rI  r$  r=  r>  thisfontrH  r   r?  r  r@  r  s   &&&&&&&       r'   text_lengthFont.text_length   s    9911(;$$$\**BBA228?!8#D!CCHQW^	%((s::B  		r)   c                    \        V4      # )z$Return the glyph name for a unicode.)unicode_to_glyph_name)r&   r?  s   &&r'   r  Font.unicode_to_glyph_name   s    $R((r)   c                    \         P                  ! V P                  4      pV Uu. uF  q"P                  NK  	  pp\	        V4      p\        V4      pV# u upi )z5
Returns sorted list of valid unicodes of a fz_font.
)r   fz_enumerate_font_cmap2r   ucsr  sorted)r&   ucs_gidsrg  ucssucss_uniqueucss_unique_sorteds   &     r'   valid_codepointsFont.valid_codepoints   sM     00;'(x!x($i#K0!! )s   Ar$  )
NNNrx   Nr  rx   rx   rx   r  )rr  Nrx   rx   rx   )Nrx   rx   rx   )Nrx   rx   )r/   r0   r1   r2   r[  r   r   r{  r:  r6  r3
  rA  r;  r  r^  rc  r]  rh  rk  r%  r&  ru  r'  r  r   r  r  r  r3   r,   r)   r'   r  r     s,   1f& 1 1 ( ( 6 6 2 2 ) )V	8	H 0 0+
 1 1 3 3 7 7 2 2  $  
&)"r)   r  c                  "    ] tR tRtR tR tRtR# )r  i!  c                	>    \        V 4      \        J g   R # RV n        R # rZ  )r   r  r   r-   s   &r'   r[  Graftmap.__del__!  s    DzX%r)   c                	b    \        V4      p\        P                  ! V4      pW0n        R V n        R# )TN)r   r   pdf_new_graft_mapr   r   )r&   r1  dstmap_s   &&  r'   r   Graftmap.__init__	!  s(    s#&&s+	r)   ro  N)r/   r0   r1   r2   r[  r   r3   r,   r)   r'   r  r  !  s    
r)   r  c                      ] tR tRtR tR tR tR tR tR t	R t
R	 t]R
 4       t]R 4       t]R 4       t]R R l4       t]R 4       t]R 4       t]R 4       tRR ltRR ltR t]R 4       tRtRtR# )Linki!  c                	&    V P                  4        R # r+   )r   r-   s   &r'   r[  Link.__del__!  s    r)   c                	V    \        V\        P                  4      '       g   Q hWn        R # r+   )r@   r   FzLinkr   )r&   r   s   &&r'   r   Link.__init__!  s    4....	r)   c                	P    \        V 4       R \        V P                  4      ,           # zlink on ro  r  r   r-   s   &r'   r   Link.__repr__!      DC,,,r)   c                	P    \        V 4       R \        V P                  4      ,           # r  r  r-   s   &r'   r   Link.__str__!  r  r)   c                	    \        V^ R7      pVP                  '       g   R# \        P                  ! W2^ 4      pVP                  '       g   R# \	        V4      pV# rx   r  N)r   r   r   r  r  r&   r1  r  ra  link_objrI  s   &&&   r'   _borderLink._border !  sJ    sQ/~~~))#Q7"""H%r)   c                	    \        V^ R7      pVP                  '       g   R# \        P                  ! W2^ 4      pVP                  '       g   \	        \
        4      h\        V4      pV# r  )r   r   r   r  r   r  r  r  s   &&&   r'   _colorsLink._colors*!  sR    sQ/~~~))3a8"""l++X&r)   c                	"    R V n         RV n        R # rZ  )r   r   r-   s   &r'   r   Link._erase4!  s    r)   c                	    \        V^ R7      pVP                  '       g   R# \        P                  ! WC^ 4      pVP                  '       g   R# \	        WV4      pV# r  )r   r   r   r  r  )r&   r  r1  r  ra  r  rI  s   &&&&   r'   
_setBorderLink._setBorder8!  sL    sQ/~~~))#Q7"""X6r)   c                	v    V P                  V P                  P                  P                  V P                  4      # r+   )r  r   r   r  r-   s   &r'   r  Link.borderB!  '    ||DKK..33TYY??r)   c                	v    V P                  V P                  P                  P                  V P                  4      # r+   )r  r   r   r  r-   s   &r'   r  Link.colorsF!  r  r)   c                   \        V R4      '       d   V P                  f   \        R4      hV P                  P                  P                  '       g'   V P                  P                  P                  '       d   \        R4      hV P                  P                  pV P
                  '       g"   V P                  P                  R4      '       d   RpMVP                  V P                  4      p\        WV4      # )z Create link destination details.r   Norphaned object: parent is Noner  rm  )
r=   r   r   r   r  r  r  r5   r  linkDest)r&   r1  r  s   &  r'   r8
  	Link.destJ!  s     4""t{{':>??;;'''4;;+=+=+J+J+J;<<kk  txx22377C""488,C3''r)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  Link.__annotate__[!  s      S r)   c                	    \        V 4       V P                  P                  pVP                  '       g   ^ # VP                  V P                  R4      pV^,          R8w  d   \        V^,          4      # ^ # )rx   r  r  )ro  r   r  r  r  r6   )r&   r1  r  s   &  r'   r  
Link.flagsZ!  sW    Dkk  zzzTYY,Q46>qt9r)   c                N   \        V 4       \        '       d!   \        P                  ! V P                  4      # V P                  pVP
                  '       d   VP
                  P                  '       g   R# \        \        P                  ! VP
                  P                  4      4      # )zFlag the link as external.F)
ro  r  r   Link_is_externalr   r   r  r   r   fz_is_external_linkr&   	this_links   & r'   r  Link.is_externale!  sq     	D;))49955II	###9+?+?+C+C+CU..	0D0D0H0HIJJr)   c                `   V P                   P                  '       g   R# \        V 4        T P                   P                  4       pTP                  '       g   R# \        T4      pT'       Ed8   RTn        T P                  Tn	        YP                  P                  \        T4      &   T P                  ^ 8  d   T P                  P                  4        Uu. uF)  q"^,          \        P                  8X  g   K   T^ ,          NK+  	  ppT P                  P                  4        Uu. uF)  q"^,          \        P                  8X  g   K   T^,          NK+  	  ppTP!                  T P                  4      pY5^,           ,          Tn        YE^,           ,          Tn        T# ^ Tn        RTn        T# u upi u upi )z
Next link.NTr`   )r   r   ro  r  r   	Link_nextr]  r  r   r   rX  rY  r  r  r   r  r  )r&   r  ri  
link_xrefslink_idsr  s   &     r'   r]  	Link.nextp!  sK    yy###D )).."C~~~Cj3CKCJ.1JJ""2c7+yy1},0KK,C,C,Ef,Eq1QVQeQeIedadd,E
f*.++*A*A*Cd*CQtuOcOcGcDAaDD*Cd &&tyy1%Ag.!'* 
 
 gds   F&5F& F+F+c                    \        V 4       V P                  e   V P                  P                  '       g   \        R4      h\	        V P                  P                  4       4      p\        V4      pV# )zRectangle ('hot area').z"self.this.m_internal not available)ro  r   r   rk   rp  r   r+  r  s   & r'   r   	Link.rect!  sV     	D 99DII$8$8$8ABBtyy~~/03i
r)   Nc                	    \        V4      \        Jd	   R VRVRV/pV P                  WP                  P                  P                  V P
                  4      # )r  r  r  )r   r7   r  r   r   r  )r&   r  r  r  r  s   &&&&&r'   r  Link.set_border!  sE    <t#uguhGFv{{'9'9'>'>		JJr)   c                   \        V 4       V P                  P                  p\        V4      \        Jd   RVRV/pVP	                  R4      pVP	                  R4      pVe   \        R4       V. R
39   d    VP                  V P                  RR4       R# \        VR4      '       d   \        V4      .p\        V4       \        V4      R9   g   Q hR\        V4       R	2pVP                  V P                  RV4       R# )zSet border colors.r   r  Nz!warning: links have no fill colorr  r  r  r  r  r,   r  )ro  r   r   r7   r:   rv   r  r  r=   r  r  r9   r   )r&   r  r  r   r1  r  s   &&&&  r'   r  Link.set_colors!  s    Dkk  <t#dHf5Fzz&!H%78b"XTYYT26;''Fm_F66{i'''	&!"!$C+r)   c                	
   \        V 4       V P                  P                  pVP                  '       g   \        R 4      h\	        V4      \
        J g   \        R4      hVP                  V P                  R\        V4      4       R# )r  zbad 'flags' valuer  N)	ro  r   r  r   r   r6   r  r  r  )r&   r  r1  s   && r'   r  Link.set_flags!  sb    Dkk  zzz[))E{c!011CU4r)   c                    \         '       d!   \        P                  ! V P                  4      # V P                  pVP                  '       d   VP                  P
                  # R# )zUri string.r`   )r  r   link_urir   r   r  r  s   & r'   r  Link.uri!  sG     ;>>$)),,II	+4+?+?+?y##''GRGr)   rt  )Nrx   NNrx  r  )r/   r0   r1   r2   r[  r   r   r   r  r  r   r  r{  r  r  r8
  r  r  r]  r   r  r  r  r  r   r3   r,   r)   r'   r  r  !  s    -- @ @ @ @ ( (   K K  6 	 	K
,( H H Dr)   r  c                      ] tR tRtR tR tR tR tR tRRR	RR
RRRRRRR/R lt	R t
R tR tR tR tR tR tR tR tR tR tR!R lt]R 4       tR tR tR tR t]
t]t]tR tR# )"r  i!  c           	     	v    \         P                  ! \        V  Uu. uF  qV,          NK  	  up4      4      # u upi r+   mathsqrtsumr&   r  s   & r'   __abs__Matrix.__abs__!  ,    yy404acc401220   6c           
     	   \        VR 4      '       dw   \        V P                  V,           V P                  V,           V P                  V,           V P
                  V,           V P                  V,           V P                  V,           4      # \        V4      ^8w  d   \        R4      h\        V P                  V^ ,          ,           V P                  V^,          ,           V P                  V^,          ,           V P
                  V^,          ,           V P                  V^,          ,           V P                  V^,          ,           4      # r  Matrix: bad seq len
r=   r  r   rI  r  rH  rh  r  r9   r   r&   r  s   &&r'   __add__Matrix.__add__!      1k""$&&1*dffqj$&&1*&&1*dffqj$&&1*> >q6Q;233dffqtmTVVad]DFFQqTM&&1Q4-!A$1G 	Gr)   c                	f    \        V 4      \        V 4      u;8H  ;'       d    ^ 8H  '       * # u '       * # ru  r'  r  r-   s   &r'   r   Matrix.__bool__!  )    IT//a/00/00r)   c                	p    \        VR 4      '       g   R# \        V4      ^8H  ;'       d    W,
          '       * # r  Fr=   r9   )r&   r  s   &&r'   __eq__Matrix.__eq__!  s-    sI&&3x1}11dj!11r)   c                	    V P                   V P                  V P                  V P                  V P                  V P
                  3V,          # r+   r   rI  r  rH  rh  r  r  s   &&r'   r  Matrix.__getitem__!  s2    ?BBr)   r   NrI  r  rH  rh  r  c                  V'       g-   R;V n         ;V n        ;V n        ;V n        ;V n        V n        EM\        V4      ^8  d   \        R4      h\        V4      ^8X  d8   \        \        V4      w  V n         V n        V n        V n        V n        V n        EM\        V4      ^8X  Ed   \        V^ ,          \        P                  4      '       d   V^ ,          P                   V n         V^ ,          P                  V n        V^ ,          P                  V n        V^ ,          P                  V n        V^ ,          P                  V n        V^ ,          P
                  V n        EM\        V^ ,          R4      '       d   \        P                  ! V^ ,          4      p\!        \        P"                  ! V4      ^4      p	\!        \        P$                  ! V4      ^4      p
V	;V n         V n        Wn        V
) V n        R;V n        V n        EM0\        \        V^ ,          4      w  V n         V n        V n        V n        V n        V n        M\        V4      ^8X  g   \        V4      ^8X  d]   V^,          ^ 8X  dO   \        V^ ,          4      RR\        V^,          4      RR3w  V n         V n        V n        V n        V n        V n        Mw\        V4      ^8X  d]   V^,          ^8X  dO   R\        V^,          4      \        V^ ,          4      RRR3w  V n         V n        V n        V n        V n        V n        M\        R4      hVe   Wn         Ve   W n        Ve   W0n        Ve   W@n        Ve   WPn        Ve	   W`n        R# R# )aZ  
Matrix() - all zeros
Matrix(a, b, c, d, e, f)
Matrix(zoom-x, zoom-y) - zoom
Matrix(shear-x, shear-y, 1) - shear
Matrix(degree) - rotate
Matrix(Matrix) - new copy
Matrix(sequence) - from 'sequence'
Matrix(mupdf.FzMatrix) - from MuPDF class wrapper for fz_matrix.

Explicit keyword args a, b, c, d, e, f override any earlier settings if
not None.
r  r  r  r  zMatrix: bad argsN)r   rI  r  rH  rh  r  r9   r   r  r  r@   r   r|  r=   r  radiansroundcossin)r&   r   rI  r  rH  rh  r  r  thetac_s_s   &$$$$$$*   r'   r   Matrix.__init__!  s    BEEDFETVEdfEtvEY]233Y!^=@=M:DFDFDFDFDFDFY!^$q'5>>22aaaaaaa+..T!W-488E?A.488E?A."$$"%%ADUDQRGAT>Y!^s4yA~$q'Q,=B47^S%Q.#s>3:DFDFDFDFDFDFY!^Q1=@d1gd1gS#>>:DFDFDFDFDFDF /00 =QF=QF=QF=QF=QF=QF=r)   c                <    \        4       pVP                  V 4       V# )zCalculate inverted matrix.)r  invert)r&   m1s   & r'   
__invert__Matrix.__invert__"  s    X
		$	r)   c                	    ^# )   r,   r-   s   &r'   r  Matrix.__len__"      r)   c           	     	L   \        VR 4      '       dw   \        V P                  V,          V P                  V,          V P                  V,          V P
                  V,          V P                  V,          V P                  V,          4      # \        ^^4      pVP                  W4      # r  )	r=   r  r   rI  r  rH  rh  r  concat)r&   r  r  s   && r'   __mul__Matrix.__mul__ "  ss    1k""$&&1*dffqj$&&1*&&1*dffqj$&&1*> >Aa[yy!!r)   c                	    \        V P                  ) V P                  ) V P                  ) V P                  ) V P
                  ) V P                  ) 4      # r+   )r  r   rI  r  rH  rh  r  r-   s   &r'   __neg__Matrix.__neg__'"  s;    tvvgw$&&466'DFF7KKr)   c                	f    \        V 4      \        V 4      u;8H  ;'       d    ^ 8H  '       * # u '       * # ru  r  r-   s   &r'   __nonzero__Matrix.__nonzero__*"  r  r)   c                	    \        V 4      # r+   r  r-   s   &r'   __pos__Matrix.__pos__-"  s    d|r)   c                	8    R \        \        V 4      4      ,           # r  r  r   r-   s   &r'   r   Matrix.__repr__0"  s    #eDk***r)   c                	    \        V4      pV^ 8X  d	   W n        R# V^8X  d	   W n        R# V^8X  d	   W n        R# V^8X  d	   W n        R# V^8X  d	   W n        R# V^8X  d	   W n        R# \        R4      hrx   zindex out of rangeN)r  r   rI  r  rH  rh  r  r  r&   rg  rH   s   &&&r'   __setitem__Matrix.__setitem__3"  s    !H!VaV 	 !VaV 	 !VaV 	 !VaV
 		 !VaV 	 !VaV 	 122r)   c           
     	   \        VR 4      '       dw   \        V P                  V,
          V P                  V,
          V P                  V,
          V P
                  V,
          V P                  V,
          V P                  V,
          4      # \        V4      ^8w  d   \        R4      h\        V P                  V^ ,          ,
          V P                  V^,          ,
          V P                  V^,          ,
          V P
                  V^,          ,
          V P                  V^,          ,
          V P                  V^,          ,
          4      # r  r  r  s   &&r'   __sub__Matrix.__sub__?"  r  r)   c           	     	   \        VR 4      '       d   \        V P                  R,          V,          V P                  R,          V,          V P                  R,          V,          V P
                  R,          V,          V P                  R,          V,          V P                  R,          V,          4      # \        V4      ^,          pV'       g   \        R4      h\        ^^4      pVP                  W4      # r  r  zmatrix not invertible)r=   r  r   rI  r  rH  rh  r  util_invert_matrixZeroDivisionErrorr  )r&   r  r  m2s   &&  r'   __truediv__Matrix.__truediv__H"  s    1k""$&&2+a-"QA&&2+a-"QAG G"1%#$;<<Aa[yy""r)   c                    \        V4      \        V4      u;8X  d   ^8X  g   M \        R4      h\        W4      w  V n        V n        V n        V n        V n        V n        V # )z.Multiply two matrices and replace current one.r  )	r9   r   util_concat_matrixr   rI  r  rH  rh  r  )r&   onetwos   &&&r'   r  Matrix.concatR"  sK    3x3s8(q(2339KC9U6r)   c                    Vf   \        V 4      pM\        V4      pV^ ,          ^8X  d   ^# V^,          w  V n        V n        V n        V n        V n        V n        ^ # )zmCalculate the inverted matrix. Return 0 if successful and replace
current one. Else return 1 and do nothing.
)r+  r   rI  r  rH  rh  r  )r&   r4  r  s   && r'   r  Matrix.invertY"  sP     ;$T*C$S)Cq6Q;9<Q6r)   c                   \        V P                  4      \        8  ;'       d%    \        V P                  4      \        8  ;'       gA    \        V P                  4      \        8  ;'       d    \        V P
                  4      \        8  # )z,True if rectangles are mapped to rectangles.)r,  rI  EPSILONr  r   rH  r-   s   &r'   is_rectilinearMatrix.is_rectilinearf"  s]     DFFg%??#dff+*? > >[7"<<s466{W'<	>r)   c                   \        V4      pV^ 8  d   VR,          pK  VR8  d   VR,          pK  \        ^ V,
          4      \        8  d    V # \        RV,
          4      \        8  dM   V P                  pV P                  pV P
                  V n        V P                  V n        V) V n        V) V n        V # \        RV,
          4      \        8  dK   V P                  ) V n        V P                  ) V n        V P
                  ) V n        V P                  ) V n        V # \        RV,
          4      \        8  dK   V P                  pV P                  pV P
                  ) V n        V P                  ) V n        W n        W0n        V # \        P                  ! V4      p\        P                  ! V4      p\        P                  ! V4      pV P                  pV P                  pWb,          WPP
                  ,          ,           V n        Wc,          WPP                  ,          ,           V n        V) V,          W`P
                  ,          ,           V n        V) V,          W`P                  ,          ,           V n        V # )z2Calculate pre rotation and replace current matrix.r  g     V@g     f@g     p@)r  r,  r8  r   rI  r  rH  r  r  r  r   )r&   r  r   rI  radr  r  s   &&     r'   	prerotateMatrix.prerotatel"  s   eai#slESLEq5y>G#F C (AAVVDFVVDFRDFRDF6 3 ')ffWDFffWDFffWDFffWDF* ' ')AAffWDFffWDFFF  ,,u%CAAAAUQZ'DFUQZ'DFBFQZ'DFBFQZ'DFr)   c                    \        V4      p\        V4      pV ;P                  V,          un        V ;P                  V,          un        V ;P                  V,          un        V ;P                  V,          un        V # )z1Calculate pre scaling and replace current matrix.r  r   rI  r  rH  )r&   sxsys   &&&r'   prescaleMatrix.prescale"  sM    2Y2Y""""r)   c                   \        V4      p\        V4      pV P                  V P                  rCV ;P                  W P                  ,          ,          un        V ;P                  W P                  ,          ,          un        V ;P                  W,          ,          un        V ;P                  W,          ,          un        V # )z2Calculate pre shearing and replace current matrix.r@  )r&   r"  rH   r   rI  s   &&&  r'   preshearMatrix.preshear"  sn    !H!Hvvtvv1!ff*!ff*!%!%r)   c                2   \        V4      p\        V4      pV ;P                  WP                  ,          W P                  ,          ,           ,          un        V ;P                  WP
                  ,          W P                  ,          ,           ,          un        V # )z5Calculate pre translation and replace current matrix.)r  rh  r   r  r  rI  rH  )r&   txtys   &&&r'   pretranslateMatrix.pretranslate"  sW    2Y2Y"vv+VV++"vv+VV++r)   r  r+   ) r/   r0   r1   r2   r  r  r   r  r  r   r	  r  r  r  r  r  r   r$  r'  r.  r  r  r{  r9  r=  rC  rF  rK  __inv____div__normr3   r,   r)   r'   r  r  !  s    3G12
C5' 5' 5' 5' 5' 5' 5'n"L1+
G# > >
)V	 GGDr)   r  c                  8    ] tR tRtRtR tR tR tR tR t	Rt
R	# )
IdentityMatrixi"  z"Identity matrix [1, 0, 0, 1, 0, 0]c                	    \        R4      # )r  )r  rx   rx   r  rx   rx   )hashr-   s   &r'   __hash__IdentityMatrix.__hash__"  s    M""r)   c                	4    \         P                  V R R 4       R# )r  N)r  r   r-   s   &r'   r   IdentityMatrix.__init__"  s    c3'r)   c                	    R # )z,IdentityMatrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)r,   r-   s   &r'   r   IdentityMatrix.__repr__"  s    =r)   c                	    VR 9   d   RV P                   V&   R# VR9   d   RV P                   V&   R# W P                   V&   R# )adr  bcefr  N)r  )r&   r   r   s   &&&r'   __setattr__IdentityMatrix.__setattr__"  s8    4<"%DMM$V^"%DMM$"'MM$r)   c                 	    \        R 4      h)zIdentity is readonly)NotImplementedError)r  s   *r'   	checkargsIdentityMatrix.checkargs"  s    !"899r)   r,   N)r/   r0   r1   r2   __doc__rT  r   r   r]  ra  r3   r,   r)   r'   rQ  rQ  "  s    ,#(>(:r)   rQ  c                  $    ] tR tRtRtRR ltRtR# )r  i"  z#link or outline destination detailsNc           	     	
  a  VP                   pV'       * pR S n        R S n        ^ S n        RS n        RS n        \        S n        \        ^ ^ 4      S n	        \        4       S n        R S n        VP                  S n        \        ^ ^ 4      S n        VP                  S n        V 3R lpR pV'       d`   S P                  P!                  R4      '       g?   RV^ ,          ^,            R\#        V^,          4       R\#        V^,          4       2S n        VP                   '       d   RS n        \$        S n        S P                  '       g   RS n        \        S n        V'       EdZ   S P                  '       EdG   S P                  P'                  RR	4      S n        S P                  P!                  R4      '       Ed   \(        S n        \*        P,                  ! R
S P                  4      pV'       d   \/        VP1                  ^4      4      ^,
          S n        \        \3        VP1                  ^4      4      \3        VP1                  ^4      4      4      S n	        S P                  \4        ,          \6        ,          S n        EM?\*        P,                  ! RS P                  4      pV'       d(   \/        VP1                  ^4      4      ^,
          S n        M\8        S n        \*        P,                  ! RS P                  4      pV'       g   Q hV'       dq   V'       di   V! VP1                  ^4      4      p	VP;                  4       P=                  V	4      S n        S P                  f   \        4       S n        V	S P                  R&   MAV! S P                  R,          4      S n        M"\8        S n        V! S P                  4      S n        VP                   '       Edu   S P                  '       g   EM`S P                  P!                  R4      '       Ed	   S P                  R,          S n        S P                  P!                  R4      '       d   S P                  R,          S n        RS n        R S n        \>        S n        S P                  PA                  R4      p
\C        V
4      ^8X  ds   V
^,          P!                  R4      '       dU   \D        S n        V
^ ,          S n        \/        V
^,          PA                  R4      ^ ,          R,          4      ^,
          S n        M6RS P                  9   d   RS n        \$        S n        MRS n        \>        S n        \G        S P                  \        4      '       g   Q hR# )r`   Fc                   < SP                   R ,          P                  R4      p\        4       pV F1  pVP                  R4      pV^ 8  d   W4^,           R W#RV &   K-  RW#&   K3  	  V# )r	  &r   N)r  r8   r7   r   )r  rD   rI   rE   eqr&   s   &    r'   uri_to_dict&linkDest.__init__.<locals>.uri_to_dict"  sc    HHRL&&s+E&CYYs^7%)Q$%[CSb	N $CI  Jr)   c           	         V P                  RR4      pVP                  R4      pV^ ,          pVR,           F8  pVR,          pV\        \        V^R7      4      ,          pW#R,          ,          pK:  	  V# )z'Unescape '%AB' substrings to chr(0xAB).z%%z%25%r	  r  )baser+  )r  r8   rn  r6   )r   r8   rv  rE   pieces   &    r'   unescape#linkDest.__init__.<locals>.unescape"  sk    LLu-EKK$EAhGb		R3s5r2338# " Nr)   rm  z#page=z&zoom=0,r   z	&zoom=nanz&zoom=0z7^#page=([0-9]+)&zoom=([0-9.]+),(-?[0-9.]+),(-?[0-9.]+)$z^#page=([0-9]+)$z^#nameddest=(.*)N	nameddestr	  zfile:r   z//r+  zpage=rg  rc   Tr  )$r  r8
  	file_specr  is_mapis_urir  r  r)  ltr7   r  
new_windowr   r  r  r5   r   r   r  r  rer  r6   groupr  LINK_FLAG_L_VALIDLINK_FLAG_T_VALID
LINK_NAMEDrN
  r:   r  r8   r9   r  r@   )r&   r  rlinkr   isExtisIntri  ro  r  r  ftabs   f&&&       r'   r   linkDest.__init__"  s   		
	1+V
HH	1+77				 ,,S11a1~Xia6I5J!IV[\]V^L_K`aDH???DI DIxxxDI!DI5TXXXxx''Y?DHxx""3''%	HHVX\X`X`a #AGGAJ! 3DI#E1771:$7qwwqz9JKDG!%.?!?BS!SDJ!3TXX>A$'
Oa$7	$.	HH%7B'x#$,QWWQZ$8E)1)?)?)A)E)Ee)LDJ#zz1 .2V
6;DJJ{3)4TXXb\)BDJ&	(2
???888$$W--!%">>,,T22%)^^B%7DN#'	~~++C0t9>Aw))'22$.	)-a$'Qc(:1(=b(A$BQ$F	"$	"'	$**d++++r)   )r8
  rr  r  rs  rt  r  ru  r  rv  r   r  r  r+   r/   r0   r1   r2   rc  r   r3   r,   r)   r'   r  r  "  s    -b, b,r)   r  c                  p    ] tR tRtRtR tR tR tR tR t	R t
R	 tR
 t]R 4       tR tR tRR ltRtR# )rZ  i:#  z.
Class describing a PDF form field ("widget")
c                	   R V n         RV n        ^ V n        R V n        R V n        R V n        R V n        R V n        R V n        ^ V n	        ^ V n
        ^ V n        R V n        R V n        R V n        R V n        RV n        RV n        ^ V n        ^ V n        ^ V n        RV n        R V n        R V n        R V n        R V n        R V n        R V n        R V n        R V n        ^ V n        R # )Nr
  Helvr`   rx   rx   rx   )r  border_styleborder_widthborder_dasheschoice_values	rb_parent
field_namefield_labelfield_valuefield_flagsfield_display
field_typefield_type_stringr_  button_caption	is_signedr   	text_fonttext_fontsizetext_maxlentext_format_text_dar$  script_strokescript_formatscript_changescript_calcscript_blurscript_focusr   r  r-   s   &r'   r   Widget.__init__?#  s     !!!%"#!!! 		r)   c                	<    R V P                    RV P                   R2# )zWidget:(field_type=z script=r  )r  r$  r-   s   &r'   r   Widget.__repr__d#  s#    $T%;%;$<HT[[MQRSSr)   c                    V P                   '       g
   RV n         R# RpV F9  pV P                   P                  4       VP                  4       8X  g   K2  W n          R# 	  RV n         R# )zAEnsure text_font is from our list and correctly spelled.
        r  N)CourTiRor  ZaDb)r  r  )r&   valid_fontsr  s   &  r'   _adjust_fontWidget._adjust_fontg#  sU     ~~~#DN6A~~##%2!"   r)   c           	     ,   V P                   \        ^^4      9  d   \        R4      hV P                   \        P                  8X  d   V P
                  R
9  d   \        V R4      '       d   V P                  P                  pVP                  V P                  R4      w  r#VR8X  dk   \        \        \        V^R P                  RR4      P                  4       4      4      pV F(  pWPP                  8w  g   K  VP                  VRR4       K*  	  R	# R	# R	# R	# R	# )z Any widget type checks.
        zbad field typer   zParent/Kidsr<
  rk  r`   ASz/OffN)FOffr  )r  rS  r   r   PDF_WIDGET_TYPE_RADIOBUTTONr  r=   r   r  r  r   r  r6   r  r8   r  )r&   r1  	kids_type
kids_valuer  r  s   &     r'   _checkerWidget._checkeru#  s     ??%1+--.. ??e???DDTDT\jDjovw{  ~F  pG  pG ++$$C$'$4$4TYY$N!IG#c#z!B'7'?'?b'I'O'O'QRS!Dyy(((tV< " $ pGDj?r)   c                x   V P                   '       g   R# Rp^ pRpV P                   P                  4       p\        V4       F  w  rVVR8X  dK   WE^,
          ,          R,          p\        WE^,
          ,          4      pR;WE&   ;WE^,
          &   WE^,
          &   KV  VR8X  d+   \        WE^,
          ,          4      .pR;WE&   WE^,
          &   K  VR8X  g   K  WE^,
          V  Uu. uF  p\        V4      NK  	  ppR;WE&   ;WE^,
          &   ;WE^,
          &   WE^,
          &   K  	  Wn        W n        W0n        RV n         R# u upi )	zExtract font name, size and color from default appearance string (/DA object).

Equivalent to 'pdf_parse_default_appearance' function in MuPDF's 'pdf-annot.c'.
Nr  Tfr	  r`   grgr  )r  r8   rZ  r  r  r  r   )r&   r  r7  rf  datrg  rE   r  s   &       r'   r  Widget._parse_da#  s)   
 }}}mm!!# ~GAt|q5z"~ca%j)/111qSC!Hs{ca%j)+$&&qSt|),U16AuQx6:<<<qS<C!HsQ3x & " 7s   D7c                   V P                   P                  '       g   V P                   P                  '       d   \        R4      hV P                  '       g   \        R4      hV P
                  R8X  d   RV n        \        V P                  4       \        V P                  4       V P                  '       g   RV n	        \        V P                  4       V P                  '       g   ^ V n
        V P                  '       g   ^ V n        V P                  P                  4       R,          V n        V P                  \        P                   \        P"                  \        P$                  39   pV P&                  '       g	   RV n        M(\)        V P&                  4      \*        Jd   \        R4      hV'       g   V P,                  '       g	   RV n        M(\)        V P,                  4      \*        Jd   \        R4      hV'       g   V P.                  '       g	   RV n        M(\)        V P.                  4      \*        Jd   \        R4      hV'       g   V P0                  '       g	   RV n        M(\)        V P0                  4      \*        Jd   \        R	4      hV'       g   V P2                  '       g	   RV n        M(\)        V P2                  4      \*        Jd   \        R
4      hV'       g   V P4                  '       g	   RV n        M(\)        V P4                  4      \*        Jd   \        R4      hV'       g   V P6                  '       g	   RV n        M(\)        V P6                  4      \*        Jd   \        R4      hV P9                  4        R# )z$Validate the class entries.
        zbad rectzfield name missingUnnamedN:rx   r  Nzscript content must be a stringz$script_calc content must be a stringz&script_change content must be a stringz&script_format content must be a stringz&script_stroke content must be a stringz$script_blur content must be a stringz%script_focus content must be a stringr  )r   is_infiniteis_emptyr   r  r  r  r  r_  r   r  r  r  r
  r  r   PDF_WIDGET_TYPE_BUTTONPDF_WIDGET_TYPE_CHECKBOXr  r$  r   r  r  r  r  r  r  r  r  )r&   btn_types   & r'   	_validateWidget._validate#  s|    II!!!yy!!!Z((122y(#D4$$%4??#'DO4??#    !D!!!!"D --335c: ??,,..11' 
 {{{DK$++c)>?? 4+++#D$""#3.CDD4---!%D$$$%S0EFF4---!%D$$$%S0EFF4---!%D$$$%S0EFF4+++#D$""#3.CDD4,,, $D$##$C/DEEr)   c                z   V P                   '       g   R# V P                  P                  pV'       g   Q h\        V4      p\        P                  ! W P                   4      p\        P
                  ! V\        R4      4      pVP                  4       '       g   R# VP                  \        R4      V P                  4       VP                  \        R4      4      pVP                  4       '       g   \        R4       R# \        VP                  4       4       F  pVP                  V4      pVP                  4       '       g   K,  VP                  4       pWP                   8X  d   KN  VP                  \        R4      4      p	V	P!                  4       R8X  g   K  VP                  \        R4      V P                  4       K  	  R# )	zPropagate the field flags.

If this widget has a "/Parent", set its field flags and that of all
its /Kids widgets to the value of the current widget.
Only possible for widgets existing in the PDF.

Returns True or False.
Fr  Ffr@  z0warning: malformed PDF, Parent has no Kids arrayr  rZ  T)r  r   r   r   rJ  r  r  r  rP  r  rI  rv   rS  r  r  r  r  )
r&   r1  ra  
pdf_widgetr  rB  rg  rC  r  r  s
   &         r'   _sync_flagsWidget._sync_flags#  sT    yyykk  
ss#**3		:
##J0BC!!## 	0@0@A ""8F#34  ""FGt))+,A$$Q'C??$$>>#Dyy &&x	':;G&&(H4  $1A1AB - r)   c                   V P                   R9  d   R# \        V R4      '       d   V P                  P                  pMR# V P                  pRRRR/pVP	                  VR4      pV^ ,          R8X  dZ   . pV^,          ^R pVP                  R4      R,          pV F)  pVP                  VP                  4       ^ ,          4       K+  	  WSR&   V^ ,          R	8X  d   . p\        V^,          P                  R
4      ^ ,          4      pVP                  V4      pVP                  R4      R,          pV F)  pVP                  VP                  4       ^ ,          4       K+  	  WSR&   VP	                  VR4      p	V	^ ,          R8X  dZ   . p
V	^,          ^R p	V	P                  R4      R,          pV F)  pV
P                  VP                  4       ^ ,          4       K+  	  WR&   V	^ ,          R	8X  d   . p
\        V	^,          P                  R
4      ^ ,          4      pVP                  V4      p	V	P                  R4      R,          pV F)  pV
P                  VP                  4       ^ ,          4       K+  	  WR&   V# )zReturn the on/off state names for button widgets.

A button may have 'normal' or 'pressed down' appearances. While the 'Off'
state is usually called like this, the 'On' state is often given a name
relating to the functional context.
Nr   r  r  zAP/Nr7   r	  r	  r  r   zAP/Dr  r   r  )	r  r=   r   r  r  r8   ro   r6   r^  )r&   r1  r  statesAPNnstatesapntri  nxrefAPDdstatesapdtdxrefs   &            r'   button_statesWidget.button_states$  s    ??&(4""++$$CyyD&$/tV,q6VGa&2,C99S>"%Dqwwy|, &8q6VGAS)!,-E//%(C99S>"%Dqwwy|, &8tV,q6VGa&2,C99S>"%Dqwwy|, $6Nq6VGAS)!,-E//%(C99S>"%Dqwwy|, $6Nr)   c                	.    V P                   P                  # r+   )_annotr]  r-   s   &r'   r]  Widget.nextN$  s    {{r)   c                    V P                   R9  d   R# V P                  4       pVf   \        4       pVP                  4        F  pW,           F  pVR8w  g   K  Vu u # 	  K!  	  \	        R4       R# )ae  Return the "On" value for button widgets.

This is useful for radio buttons mainly. Checkboxes will always return
"Yes". Radio buttons will return the string that is unequal to "Off"
as returned by method button_states().
If the radio button is new / being created, it does not yet have an
"On" value. In this case, a warning is shown and True is returned.
Nr  z(warning: radio button has no 'On' value.Tr  )r  r  r7   r  rv   )r&   bstater  rH   s   &   r'   on_stateWidget.on_stateR$  se     ??&(##%>VFAYY:H   	:;r)   c                D    \         P                  V P                  4       R# )z.Reset the field value to its default.
        N)r  _reset_widgetr  r-   s   &r'   r
  Widget.resetg$  s     	DKK(r)   c                   V P                  4        V P                  4        RV n        \        V P                  4      ^8X  d   RV P                  ,           pM[\        V P                  4      ^8X  d   RV P                  ,           pM-\        V P                  4      ^8X  d   RV P                  ,           pXP
                  ! V P                  RV P                  RV P                  / V n        V P                  '       d   \        V P                  4       \        P                  V P                  V 4       RV n        V'       d   V P                  4        R# R# )z!Reflect Python object in the PDF.r`   !{:g} {:g} {:g} rg /{f:s} {s:g} Tfz{:g} g /{f:s} {s:g} Tfz%{:g} {:g} {:g} {:g} k /{f:s} {s:g} Tfr  r  N)r  r  r  r9   r   r  r  r  r  util_ensure_widget_calcr  r  _save_widgetr  )r&   
sync_flagsr   s   && r'   rN  Widget.updatel$  s     !Q&5EC!Q&*T]]:C!Q&9DMMIC

DOO :t~~ :&*&8&8: #DKK0 	4;;- r)   )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r_  r  r  r   r$  r  r  r  r  r  r  r   r  r  r  r  r  Nr  )r/   r0   r1   r2   rc  r   r   r  r  r  r  r  r  r{  r]  r  r
  rN  r3   r,   r)   r'   rZ  rZ  :#  s]    #JT=*>EN+Z/b    *)
 r)   rZ  )_extrac                      ] tR tRtR t]R 4       tR t]R 4       t]R 4       t	]R 4       t
]R 4       t]R	 4       t]R
 4       t]R 4       t]R 4       t]R 4       tR.tRtR# )r+  i$  c                	    Wn         R # r+   r$  r&   r>  s   &&r'   r   Outline.__init__$  s    	r)   c                    \        V RR4      # )zoutline destination detailsNr  r-   s   &r'   r8
  Outline.dest$  s     dD))r)   c                    \        V RV4      # )zW
Like `dest` property but uses `document` to resolve destinations for
kind=LINK_NAMED.
Nr  )r&   r   s   &&r'   destinationOutline.destination$  s    
 dH--r)   c                	x    V P                   pVP                  4       pVP                  '       g   R # \        V4      # r+   )r   r  r   r+  )r&   r>  down_ols   &  r'   r  Outline.down$  0    YY'')!!!wr)   c                	    \         '       d!   \        P                  ! V P                  4      # V P                  pVP                  '       g   R # TP                  P
                  pTf   R # \        P                  ! T4      # r  )r  r  Outline_is_externalr   r   r  r   r  )r&   r>  r  s   &  r'   r  Outline.is_external$  s[    ; --tyy99YY}}}mm;((--r)   c                	D     V P                   P                  P                  # rv  )r   r   rA  r-   s   &r'   rA  Outline.is_open$  s    99''///r)   c                	x    V P                   pVP                  4       pVP                  '       g   R # \        V4      # r+   )r   r]  r   r+  )r&   r>  next_ols   &  r'   r]  Outline.next$  r  r)   c                	X     V P                   P                  P                  P                  # rv  )r   r   r   r-   s   &r'   r   Outline.page$  s!    99'',,111r)   c                	B    V P                   P                  P                  # r+   )r   r   r  r-   s   &r'   r  Outline.title$  s    yy##)))r)   c                	n    V P                   pVP                  '       g   R # VP                  P                  # r+   )r   r   r  r  s   & r'   r  Outline.uri$  s'    YY}}}}}   r)   c                	B    V P                   P                  P                  # r+   )r   r   ri  r-   s   &r'   ri  	Outline.x$      yy##%%%r)   c                	B    V P                   P                  P                  # r+   )r   r   rj  r-   s   &r'   rj  	Outline.y$  r  r)   r   r$  N)r/   r0   r1   r2   r   r{  r8
  r  r  r  rA  r]  r   r  r  ri  rj  r  r3   r,   r)   r'   r+  r+  $  s     * *.     . . # #
     % %
 * * ! ! & & & & 	Ir)   r+  c                  a \         P                  ! 4       pWn        Wn        W&n        W6n        V'       d   S'       d$   \        S\         P                  4      '       g   Q hM\         P                  ! 4       o ! V3R lR\         P                  4      pV! 4       pVP                  VP                  4       4       Wn        V# )z,
Returns a mupdf.PdfFilterOptions instance.
c                  2   <a  ] tR tRtV V3R ltR tRtV ;t# )'_make_PdfFilterOptions.<locals>.Factoryi$  c                	R   < \         SV `  4        V P                  4        SV n        R # r+   )r   r   use_virtual_filtersopts)r&   	__class__r	  s   &r'   r   0_make_PdfFilterOptions.<locals>.Factory.__init__ %  s!     "'')"
r)   c           	     	j     \        P                  ! TTTTTT P                  P                  4       4      # ru  )r%   r	  r  r   ll_pdf_new_sanitize_filter)r&   ctxr1  chainstruct_parents	transformr!  s   &&&&&&&r'   filter._make_PdfFilterOptions.<locals>.Factory.filter%  s9     77&!

++- r)   )r	  )r/   r0   r1   r2   r   r  r3   __classcell__)r
  r	  s   @r'   Factoryr  $  s    # r)   r  )r   PdfFilterOptionsr  r  r  	no_updater@   PdfSanitizeFilterOptionsPdfFilterFactory2add_factoryr  _factory)	r  r  r  r  r  r	  r  r  factorys	   &&&&&f   r'   r  r  $  s     $$&GO+M! eU%C%CDDDD224E	e-- 	2 )G,,./"Nr)   c            &         ] tR tRtR tR tR tR tERR lt^RRRR^ RR]	P                  ^^ ^ RR3R	 ltR
 tR tR tERR ltR tERR ltERR ltR tR tR tR tR tR tR R ltR tER	R ltERR ltR tR tERR ltR t ERR! lt!R" t"ERR# lt#R$ t$R% t%ERR& lt&R' R( lt'R) R* lt(ERR+ R, llt)R-^R.RR/RR0RR1RR2^ R3RR4RR5]	P                  R6^R7^ R8^ R9RR:R/R; R< llt*ERR= R> llt+R? R@ lt,RA RB lt-RC RD lt.RE RF lt/RG RH lt0ERRI RJ llt1ERRK RL llt2ERRM RN llt3ERRO RP llt4ERRQ RR llt5ERRS RT llt6RU RV lt7RW t8RX t9ERRY lt:ERRZ R[ llt;ERR\ lt<R] t=R^ t>]?R_ 4       t@]?R` 4       tARa tBERRb ltC]?Rc 4       tD]?Rd 4       tERe tFRf Rg ltGRh tHRi Rj ltI]?Rk Rl l4       tJERRm Rn lltKERRo Rp lltLERRq Rr lltMERRs Rt lltNERRu Rv lltOERRw Rx lltPERRy Rz lltQERR{ R| lltRERR} R~ lltSERR R lltTERR R lltUERR ltVR tW]?R 4       tX]?R 4       tY]?R 4       tZERR lt[ERR lt\R t]ERR lt^ERR R llt_ERR R llt`ERR R lltaR tbR R ltcR]dRRRRRRRRRR /R R llteR tfER R R lltgERR lthERR ltiERR ltjR R ltkER!R ltlERR R lltmR tnR toR tpR tqR trER	R R lltsR ttR tuER"R ltvRRR^ RRR8^ R^ R6^RR RR RR/	R R lltwRER
RRR^ RR RRR^ RR RRR8^ RRR^ R^ /R ltxERR R lltyR-^RRR.RRRR^ R^ RRRRR2RR^R^ R8^ RRRR R^R^R^ /R R lltzR7^ R2RRRR^ R^R^RRRRR.RR-^RRR^RRR^ RR R^ R8^ R^ R^/R R llt{]?R 4       t|]?R 4       t}ERR lt~R R ltR tR t]?R 4       t]?R 4       tR tR tR tRRRRRR/R R llt]?R 4       t]?R R l4       tR tRRRRRRRR/R R lltR tR tR tR tERR ltR tR tR tER#R R llt]?R 4       t]?R 4       tR R ltERR ltR tER$R ER  llt]?ER 4       t]?! ]BERER7      tRtERtR# (%  r   i%  c                	   \        V\        P                  \        P                  34      '       g   Q R V 24       hWn        RV n        RV n        RV n        \        4       V n	        W n
        VP                  '       de   \        V\        P                  4      '       d(   VP                  P                  P                  V n        R# VP                  P                  V n        R# RV n        R# )z	page is: TNr`   )r@   r   r   r   r   r   
last_point	draw_contr7   rX  r   r   r   r]  )r&   r   r   s   &&&r'   r   Page.__init__ %  s    $u}} =>>R)D6@RR>	6???4//"oo33::"oo44DKr)   c                	"    V P                  4       # r+   )r   r-   s   &r'   r   Page.__repr__0%  s    ||~r)   c                	   \        V R R4      p\        V P                  P                  \        P
                  4      '       d,   V P                  P                  P                  P                  pM V P                  P                  P                  pV'       d]   V P                  P                  pV P                  P                  e   RpVR8X  d   RpRV RV RV P                  P                  R R	2pV# RV 2pV# )
r   Nr  r`   znew PDFr  z of <z, doc# rH  >)r   r@   r   r   r   pdf_pager   r]  r   r   r   r  )r&   r   r]  ri  rI   s   &    r'   r   Page.__str__3%  s    x.dii**ENN;;YY))//66FYY))00F  A{{!!-Bw&qc1F1Fq0IKC 
 &"C
r)   c                	   \         '       d-   \        P                  ! V P                  \	        V4      4      pV# V P                  4       p\        P                  ! V\        P                  4      pV'       d   \	        V4      p\        P                  ! V4      p\        P                  ! VP                  VP                  VP                  VP                  ,           VP                  ,
          VP                  VP                  ,           VP                   ,
          4      p\        P"                  ! W%4       \        P$                  ! V4       \'        VR 4       V# r  )r  r   _add_caret_annotr   JM_point_from_py	_pdf_pager   pdf_create_annotrJ  pdf_annot_rectrq  ri  rj  r  r  r  r  r  rW  JM_add_annot_id)r&   rn  r   r   r  r$  s   &&    r'   r*  Page._add_caret_annotF%  s    ;**DII7G7NOE  >>#D**41F1FGE$U+((/LLacc133:+<accADDj144>OP((2""5)E3'r)   Nc                	   V P                  4       pV'       d   TMTpV'       d   TMTp	\        V4      p
\        V4      pVP                  '       g   \	        \
        4      h\        P                  ! V\        P                  4      p\        P                  ! V4      p\        P                  ! V
P                  V
P                  V
P                  VP                  ,           VP                  ,
          V
P                  VP                  ,           VP                   ,
          4      p\        P"                  ! W4       \        P$                  p\        P&                  ! W4       V'       d   \        P(                  ! W4       \+        VP-                  4       WW^4      p\        P.                  ! \        P0                  ! V4      \3        R4      V4       \        P4                  ! \        P0                  ! V4      \3        R4      V4       \        P6                  ! V4       \        P"                  ! W4       \        P&                  ! W4       \9        VR4       \;        V4      # )r  r  rS  r  )r,  r+  r.  r   r  r/  r   r-  rL  r.  fz_make_rectri  rj  r  r  r  r  r  PDF_ANNOT_IS_PRINTr  pdf_set_annot_icon_namer  r1  rU  r  r  r  rW  r/  r   )r&   rn  r4  rj   rW  r  iconr   ufrH  r  filebufr   r$  r  r  s   &&&&&&&         r'   _add_file_annotPage._add_file_annotU%  s   ~~#YDhU#$W-!!!^,,&&tU-L-LM  'qssACCqttadd):ACC!$$J<MN  *((!!%/))%6DHHJ2!D5..u5x~sK&&u':':5'A8JCWYabu%  *!!%/s#U|r)   Fc                	   R V 2pV P                  4       pV'       d   V'       g   \        R4      hV'       d   V'       g   Tp\        V4      w  pp\        V4      w  pp\        V4      p\        P
                  ! V4      '       g   \        P                  ! V4      '       d   \        \        4      h\        P                  ! V\        P                  4      p\        P                  ! V4      pV'       g   \        P                  ! VV4       MJ\        P                  ! V\        R4      V4       V'       d"   \        P                  ! V\        R4      V4       \        P                  ! VV4       V^ 8  d   VR,          pK  VR8  d   VR,          pK  V^ 8w  d"   \        P                  ! V\        R4      V4       \        P                   ! VV4       V^ 8  d   \        P"                  ! VVRV 4       \        P$                  ! VV4       \        P&                  ! VV4       V	'       d*   V	 F#  p\        P(                  ! V\+        V4      4       K%  	  V
'       dn   \        P,                  ! V\        R4      \        R4      4       \        P.                  ! VV4       \1        V
4      p\2        P4                  ! V\7        V
4      V4       V'       g   \9        VVVWC4       \        P:                  ! V4       \=        VR	4       \?        V4      pV# )
z<?xml version="1.0"?>
            <body xmlns="http://www.w3.org/1999/xtml"
            xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"
            xfa:contentType="text/html" xfa:APIVersion="Acrobat:8.0.0" xfa:spec="2.4">
            r  r  DSr  r;  Nr  FreeTextCalloutr  ) r,  r   rB  r  r   r  r  r  r-  rK  r  r  r  r  r  rP  pdf_set_annot_quaddingrQ  pdf_set_annot_border_widthr  pdf_add_annot_border_dash_itemr  rU  pdf_set_annot_callout_styler9   r   JM_set_annot_callout_liner   r  rW  r/  r   )r&   r   r   r   r   r   r_  r  r  r  calloutline_endr]  r  r`  richtextr  r   r   rc  rd  ntcolr5  r$  r   r&  rH  point_countr  s   &&&&&&&&&&&&&&&&&            r'   _add_freetext_annotPage._add_freetext_annotp%  sA   $ F	
 ~~LMM
%J+J7t+J7tD!$$Q''5+A+A!+D+Dl++&&tU-F-FG''.	 ((5**9Xd^RH..y$O  *qjcMFmcMFQ;""9hx.@&I$$UE219%%eT&5\:((=##E7344UE!HE  y(4.(CT:UV--eX>g,K++E5>;O UE4Du%s#El
r)   c                	   \        V P                  4      p\        V4      '       g   \        \        4      h\
        P                  ! 4       p\
        P                  ! V\
        P                  ! ^ 4      V4       \
        P                  ! V4      p\
        P                  ! V\
        P                  4      p\
        P                  ! V4      p\        V4      p\
        P                  ! VP                  4       V4      p\!        V4       EF  p	W,          p
\        V
4      p\
        P                  ! VP                  4       ^V,          4      p\!        V4       F  pW,          p\        V4      '       d   \#        V4      ^8w  d   \        \        4      h\
        P$                  ! \'        V4      V4      p\
        P(                  ! WP*                  4       \
        P(                  ! WP,                  4       K  	  \
        P.                  ! W4       EK  	  \
        P0                  ! V\3        R4      V4       \
        P4                  ! V4       \7        VR4       \9        V4      # )rx   rc  r  )r   r   PySequence_Checkr   MSG_BAD_ARG_INK_ANNOTr   r|  rd  rq  r*  r-  rM  r  r9   rR  r1  rS  PySequence_Sizerh  r+  rT  ri  rj  rK  rU  r  rW  r/  r   )r&   r   r   r  inv_ctmr   r&  n0inklistr  sublistn1r  rg  r  rn  s   &&              r'   _add_ink_annotPage._add_ink_annot%  s   DII&%%344nn  u||A<((-&&tU-@-@A''.	Y%%dhhj"5rAgGWB((QV<F2YJ'**oa.@A.E$&;<<001A!1DgN))&'':))&'':    1  	9hy&97Cu%s#U|r)   c                	H   V P                  4       p\        P                  ! V\        P                  4      p\	        V4      p\	        V4      p\        P
                  ! WEV4       \        P                  ! V4       \        VR 4       VP                  '       g   Q h\        V4      # r)  )
r,  r   r-  rE  r+  pdf_set_annot_linerW  r/  r   r   )r&   rJ  rK  r   r   r   rI  s   &&&    r'   _add_line_annotPage._add_line_annot%  s~    ~~&&tU-A-ABR R   1-u%s#U|r)   c                	x   V P                  4       p\        V4      ^8  d   \        \        4      h\        P
                  ! W24      pV FC  p\        V4      ^8w  d   \        \        4      h\        V4      p\        P                  ! WF4       KE  	  \        P                  ! V4       \        VR4       \        V4      # )r  r  )r,  r9   r   MSG_BAD_ARG_POINTSr   r-  rL  r+  pdf_add_annot_vertexrW  r/  r   )r&   rI  r0  r   r   r  rn  s   &&&    r'   _add_multilinePage._add_multiline%  s    ~~v;?011&&t8A"a' "455$Q'E&&u4	  	u%s#U|r)   c                	`   V P                  4       p. ROp^ p	\        P                  ! V\        P                  4      p
\	        V4      p\        P
                  ! V4      p\        P                  ! W4       V'       d   \        V4      w  r\        P                  ! VP                  4       V	4      p\        V	4       F   p\        P                  ! WV,          4       K"  	  \        P                  ! \        P                  ! V
4      \        R4      V4       V'       d   V'       g   Q h\        P                  ! \        P                  ! V
4      R\        P                   ! V4      4       \        P"                  ! \        P                  ! V
4      \        R4      V4       \        P$                  ! \        P                  ! V
4      \        R4      V4       \        P&                  ! V
4       \)        V
R4       \        P*                  ! V
P,                  4      p
\        P.                  ! V
4      p
\1        V
4      # )r  r:  r   DAr   r  )r  r  r  rx   )r,  r   r-  r  JM_quad_from_pyfz_rect_from_quadr  rB  rR  r1  rS  rT  rU  r  r  r  r  r  rP  rW  r/  ll_pdf_keep_annotr   r   r   )r&   rM  r   da_strr  r   r   r   rd  rc  r   qr$  rp  rg  s   &&&&&&&        r'   _add_redact_annotPage._add_redact_annot%  s   ~~&&tU-C-CDD!##A&  */5KE%%dhhj%8C5\))#Aw7 "u22598D>3OM6''.!--d3
 **5+>+>u+ExPT~W]^""5#6#6u#=x}eTu%s#''(8(89&U|r)   c                	   V P                  4       p\        V4      p\        P                  ! V4      '       g   \        P                  ! V4      '       d   \        \        4      h\        P                  ! W24      p\        P                  ! WT4       \        P                  ! V4       \        VR 4       VP                  '       g   Q h\        V4      # r)  )r,  r  r   r  r  r   r  r-  r  rW  r/  r   r   )r&   r   r0  r   r$  r   s   &&&   r'   _add_square_or_circlePage._add_square_or_circle&  s    ~~D!$$Q''5+A+A!+D+Dl++&&t8  *u%s#U|r)   c                	f   \        V4      p\        V4      p\        P                  ! V4      '       g   \        P                  ! V4      '       d   \        \        4      hV P                  4       p. ROp\        V4      pRpRpV\        V4      9   d
   WR,          pM\        V\        4      '       d   VP                  4       pM\        V\        4      '       d&   \        P                  ! V4      P!                  4       pMY\        V\"        \$        34      '       d   TpM:\        V\&        P(                  4      '       d   VP+                  4       pM	V^ ,          p\        P,                  ! V\        P.                  4      p	V'       Ed   \        P0                  ! V4      p
\        P2                  ! V
4      pVP5                  4       VP7                  4       r\9        VP:                  V,          VP<                  V,          4      pW,          pW,          pVP>                  VP@                  ,           ^,          pVPB                  V^,          ,
          pVPD                  V^,          ,
          pVV,           pVV,           p\        PF                  ! VVVV4      p\        PH                  ! W4       \        PJ                  ! W4       \        PL                  ! \        PN                  ! V	4      \Q        R4      \        PR                  ! R4      4       \        PT                  ! V	R4       Mj\        PH                  ! W4       \        PL                  ! \        PN                  ! V	4      \Q        R4      \Q        V4      4       \        PT                  ! W4       \        PV                  ! V	4       \Y        V	R4       \[        V	4      # )ApprovedNr*  
ImageStampzImage Stampr  )rj  AsIsConfidentialDepartmentalExperimentalExpiredFinal
ForCommentForPublicReleaseNotApprovedNotForPublicReleaseSold	TopSecretDraft).r+  r  r   r  r  r   r  r,  r9   rS  r@   r  r  r  r  r  
read_bytesr  r  r;   r  r  r-  rN  r  fz_new_image_from_bufferr   r"  r  r  r3  r*  r+  ri  rj  r2  r  pdf_set_annot_stamp_imagerU  r  r  r  r  rW  r/  r   )r&   r   stampr$  r   stamp_idrG   r  r   r   fzbuffr2  r   r"  scaler  r3  r  r  r  r  r  s   &&&                   r'   _add_stamp_annotPage._add_stamp_annot$&  s   DzD!$$Q''5+A+A!+D+D\**~~  ME!H?Dv&&--/Cs##,,u%002Cy122Crzz**.."CA;D&&tU-B-BC399#>F008C 557CEEGq

Qa8EIEYF gg'1,FEAI%BFQJ&BeBfB""2r2r2A$$U.++E7u22598F;KUM_M_`lMmn((>$$U.u22598F;KXVZ^\((5u%s#U|r)   c                	   V P                  4       p\        V4      p\        P                  ! V\        P                  4      p\        P
                  ! V4      p\        P                  ! VP                  VP                  VP                  VP                  ,           VP                  ,
          VP                  VP                  ,           VP                  ,
          4      p\        P                  ! Wg4       \        P                  ! Wb4       V'       d   \        P                  ! Wc4       \        P                   ! V4       \#        VR 4       \%        V4      # r)  )r,  r+  r   r-  rO  r.  r2  ri  rj  r  r  r  r  r  r  r4  rW  r/  r   )r&   rn  r   r5  r   r  r   r$  s   &&&&    r'   _add_text_annotPage._add_text_annoth&  s    ~~e$&&tU-A-AB  'qssACCqttadd):ACC!$$J<MN  *$$U1))%6u%s#U|r)   c                	    \        V 4       V P                  P                  '       g   \        R 4      h\	        WV4      pV'       g   R# \
        P                  ! V 4      Vn        W0P                  \        V4      &   V# )r  N)	ro  r   r  r   Page__add_text_markerr  r   rX  rY  )r&   r
  r0  r  s   &&& r'   _add_text_markerPage._add_text_markerv&  s^    D{{!!![))#D<]]4(
$'C!
r)   c                   \        V 4       \        '       dA   \        P                  V P                  n        \        P                  ! V P                  V4      # \        V P                  4      p\        V4      pV^8  d   R# R
p\        V\        4      '       g   \        R4      h\        P                  ! VP                  4       \        R4      4      P                   '       g0   \        P"                  ! VP                  4       \        R4      V4       \        P                  ! VP                  4       \        R4      4      pVP                   '       g   Q RV: RVP                   : 24       h\%        V4       F  pW,          p\'        V4      pV'       g   \)        RVR R24       K0   \        P*                  ! VP-                  4       \/        VP-                  4       V4      4      p\        P0                  ! VP-                  4       \        P2                  ! V4      ^ 4      p	\        P4                  ! WY4       K  	  R#   \6         d+    \8        '       d   \;        4        \)        RTR R	24        K  i ; i)z&Add links from list of object sources.Nzbad 'linklist' argumentr  zlcount=z annots.m_internal=zskipping bad link / annot item rH  r   z.
r  )ro  r  r   Page_addAnnot_FromStringr
  r+  r   r   r9   r@   r   r   r   r  r  r  r   rX  rS  JM_StrAsCharrv   rY  r1  r  r  r  rK  rk   r  r{   )
r&   linklistr   lcountrg  r  txtpyr   r   r  s
   &&        r'   r+  Page._addAnnot_FromString&  s   D;272P2PDNN/11499hGGDII&XA: (E**788!!488:x/ABMMM$$dhhj(82DfM##TXXZ(1CD   CWVI-Av/@/@.B"CC vAKE&D9!Aa@AD,,dhhj:Mtxxz[_:`a00$((*e>N>NPU>VXYZ$$f6   D''N,<9!AcBCDs   &BH99I.I.-I.c                	    V P                  4       pVP                  4       p\        WCW4      pVP                  '       g   \	        R 4      h\        VR4       \        V4      # )zcannot create widgetr:  )r,  r1  JM_create_widgetr   r   r/  r   )r&   r  r  r   ra  r   s   &&&   r'   
_addWidgetPage._addWidget&  sQ    ~~hhj JC 677s#U|r)   c                	    V P                  4       p\        P                  ! 4       p^ Vn        Wn        W%n        W5n        \        P                  ! VP                  4       WE4      pV# ru  )	r,  r   PdfRedactOptionsblack_boxesr   image_methodline_artpdf_redact_pager1  )r&   r   r
  graphicsr   rU  successs   &&&&   r'   _apply_redactionsPage._apply_redactions&  sQ    ~~%%'	" ''
D?r)   c                	    V P                  4         V P                  P                  V 4       R V n        RV n        R V n        R V n        R #   \         d    \	        4         L5i ; irZ  )_reset_annot_refsr   r  rk   r{   r   r]  r   r-   s   &r'   r   Page._erase&  s]     	KK$$T* 	  		s   A A#"A#c                <   \        V 4      p\        P                  ! VP                  4       \        P                  4      p\        P                  ! VP                  4       \        P
                  4      p\        V P                  4      p\        P                  ! WBV4      # )a  Count missing graphic state pushs and pops.

        Returns:
            A pair of integers (push, pop). Push is the number of missing
            PDF "q" commands, pop is the number of "Q" commands.
            A balanced graphics state for the page will be reached if its
            /Contents is prepended with 'push' copies of string "q
"
            and appended with 'pop' copies of "
Q".
        )	r   r   r  r  r  PDF_ENUM_NAME_Contentsr   r    pdf_count_q_balance_outparams_fn)r&   r   r%  r  ra  s   &    r'   _count_q_balancePage._count_q_balance&  sy     D!  HHJ))
 !!HHJ((
 t{{+ 55cEEr)   c                    V ^8  d   QhRRRR/# )r  r  r  rs  r  r,   )r  s   "r'   r  Page.__annotate__&  s       6 r)   c                	   Ve   V^ 8X  d   R # V P                   pVP                  VRR7      pRV9   g   RV9   g   \        R4      h/ pV P                  4        F	  w  rVWTV&   K  	  WP	                  4       9   d	   WA,          # ^ pRVR 2pWP                  4       9   d   V^,          pRVR 2pK%  V P                  W4       V# )NTr[  	/Type/OCGr~  zbad optional content: 'oc'MCrH  )r   r^  r   _get_resource_propertiesr  r  _set_resource_property)	r&   r  r1  checkpropsr  ri  rg  mcs	   &&       r'   _get_optional_contentPage._get_optional_content&  s    :qkkt4u$(=9::113DA!H 49!AZLLN"FAaUB##B+	r)   c                X    V P                  4       p\        VP                  4       4      pV# )z
page list Resource/Properties
)r,  JM_get_resource_propertiesr  )r&   r   r   s   &  r'   r  Page._get_resource_properties&  s%     ~~'
3	r)   c                	x     \        P                  ! T P                  YT4      p\        P
                  ! T4      pT# rv  )r  r   page_get_textpager   r   r  r  r  fz_bound_pager  rQ  _globalsr   fz_enable_device_hintsFZ_NO_CACHEr@   r   r   r   r   fz_run_pagerj  fz_close_device)r&   r  r  r  ll_tpagetpager   r!  r   r  devs   &&&&       r'   _get_textpagePage._get_textpage&  s2    ..tyy$vNH%%h/ELr)   c                	   \         P                  ! 4       pV P                  4       pVP                  4       pT
pTpTp^ p^p^p^p^p^pV^ 8  d   \         P                  ! VV^ 4      p\         P
                  ! \         P                  ! V\        R4      \        R4      4      4      p\         P
                  ! \         P                  ! V\        R4      \        R4      4      4      pVV,           ^ 8X  d   \        \        4      h^ p^ p^ p^ pM6V'       d   \        V4      p^ pM V'       d   \         P                  ! V4      p^ pV'       Ed   VP                  pVP                  4       pVP                  4       p\         P                  ! V4      pTp VP!                  V R4      p!V!e0   T!p\         P                  ! VP                  4       V^ 4      p^ p^ p^ pMVP#                  4       ^ 8X  d,   \         P$                  ! V\         P&                  ! 4       4      p"M\         P(                  ! V\         P*                  ! 4       \         P*                  ! 4       \         P,                  ! R4      \         P.                  ! 4       ^4      p#^ V#n        RV#n        \         P$                  ! V#\         P&                  ! 4       4      p$\         P$                  ! VV$4      p"^ p^ pV'       Ed   \         P2                  ! 4       p%\4        '       d   \         P6                  ! V%X4       M@\         P8                  ! V%XP:                  P<                  VP:                  P>                  4       V'       dp   \        V4      p\4        '       d   \         P6                  ! V%V4       M@\         P8                  ! V%VP:                  P<                  VP:                  P>                  4       \         P@                  ! V%4      p\C        V4      p VP!                  V R4      p!V!e   T!p\         P                  ! VP                  4       V^ 4      p\         P
                  ! \         P                  ! V\        R4      \        R4      4      4      p\         P
                  ! \         P                  ! V\        R4      \        R4      4      4      p^ p^ pM@\         PD                  ! V4      p"V"P                  4       pV"P                  4       pV'       g   ^ pV'       d   \         PF                  ! X"4      p&V&P:                  '       g   \        R4      hV"PI                  4       p'V"P1                  4       p(\         PJ                  ! V"4      w  p)p*\         PD                  ! V4      p$\         PL                  ! VVV'V(V)V*^^ \O        4       \O        4       V&V$4      p"V'       dJ   \         PP                  ! VX"4      pV	'       d   \S        VVV	4       \         PT                  ! V4      pVVX &   ^pV'       Ed   \         PV                  ! VPY                  4       \        R4      4      p+V+P:                  '       g0   \         PZ                  ! VPY                  4       \        R4      ^4      p+\         P\                  ! V+\        R4      4      p,V,P:                  '       g"   \         PZ                  ! V+\        R4      ^4      p,\_        VVWWV4      p-\         P`                  ! V,VX4       \         Pb                  ! ^24      p.R	\e        V-Pf                  V-Ph                  V-Pj                  V-Pl                  V-Pn                  V-Pp                  34       R
V R2p/\         Pr                  ! V.V/4       \u        VVPY                  4       V.V4       V'       d   VV3# VR3# )rx   Widthr:  HeightrA  Nz#uncompressed image cannot have maskr<  XObject
q
z cm
/z Do
Q
);r   rF  r,  r1  r  r  r  r  r   MSG_IS_NO_IMAGEr.  fz_read_filer   r   r"  fz_md5_pixmap2r:   r  fz_new_image_from_pixmapFzImagefz_convert_pixmapr-  FzDefaultColorspacesFzColorParamsr  FzMd5r   fz_md5_update_bufferfz_md5_updater   r  r9   fz_md5_final2r  rz  fz_compressed_image_bufferbpcfz_image_resolution$fz_new_image_from_compressed_buffer2r   pdf_add_imager  r  r  r  rY  r  calc_image_matrixr  r0
  r   r   rI  r  rH  rh  r  fz_append_stringJM_insert_contents)0r&   rj   pixmapr   imaskr  overlayr`  keep_proportionr  r  r3  r  r  _imgnamedigestsmaskbufr   ra  r   r"  img_xref	rc_digestdo_process_pixmapdo_process_streamdo_have_imaskdo_have_imagedo_have_xrefrefimgbufarg_pixdigestmd5_pyr  imagerS  maskstatecbuf1r  r  xresyresri  xobjectr  nresr  s0   &&&&&&&&&&&&&&&&                                r'   _insert_imagePage._insert_image'  s   
 .."~~ hhj	!8((dA6C  %"5"5sHW<MxX[}"]^A  %"5"5sHX<NPXY\P]"^_A1uz /22 ! !MM +F3$%!"//9F()% kkG		A		A))'2FF;;vt,D,,TXXZ1E$%! ! !==?a'!::7EMMOTE00#!..0!..0!66t<!//1B  !BH$(BM 99"emmoND!::7DIE$%! ! KKME{**E6:##E6+<+<+A+A6CTCTCXCXY,U3;..w?''w/A/A/F/FHZHZH^H^_((/F6]F;;vt,D,,TXXZ1E$$e&9&93@QS[\_S`&ab$$e&9&93@RT\]`Ta&bc ! !66v>GGIGGI$%M 44e<E### "GHH))+C))+J2259JD$11':D>>FFE %%c51C c2.'',H&GFOI<66txxz8KCXYI'''!33DHHJ@UWXY	((HY4GHG%%%11)Xi=PRST#Aq$HC37&&r*D	355#%%suucee"LMNfU]T^^fgA""4+sDHHJg>W$$T>!r)   c                	   V P                  4       pVP                  4       p\        WW4WVWxW4
      p\        P                  ! VP                  4       \        R 4      4      pVP                  4       '       g0   \        P                  ! VP                  4       \        R 4      ^4      p\        P                  ! V\        R4      4      pVP                  '       gQ   \        P                  ! V^4      p\        P                  ! VP                  4       V\        R 4      \        R4      4       \        V^ 4      w  ppV'       g   \        R4      h\        P                  ! VV^ 4      p\        P                   ! WV4       V# )r<  r  zcannot insert font)r,  r1  r$  r   r  r  r  r  rY  r  r   rZ  rV  r  r   r  r  )r&   r   r  r%  r&  
set_simpler  r=  rL  r  r  r   ra  r   ri  r  r@  r  font_objs   &&&&&&&&&&&        r'   _insertFontPage._insertFont'  s   ~~hhjsHRW`hs22488:x?TU	$$&&//
H[<QSTUI""9hv.>?&&sA.E
E8K3H(SYJZ[eQ'4 455))#tQ7EX6r)   c                	    V P                  4       pV^ 8X  d   \        W14      pM\        W24      pV'       d   \        V4      # R# r   )r,  JM_get_annot_by_nameJM_get_annot_by_xrefr   )r&   r   r  r   r   s   &&&  r'   _load_annotPage._load_annot'  s;    ~~19(4E(4E< r)   c           	     	H    \        WP                  W#WEV4      p\        V4      # r+   )JM_pixmap_from_pager   r  )r&   r1  r  r  r  r  r  r  s   &&&&&&& r'   _makePixmapPage._makePixmap'  s     !#yy#5$Oc{r)   c                	   \         P                  ! \         P                  P                  4      p\        V P                  R R7      pVP
                  '       dX   \         P                  ! VP                  4       V4      p\         P                  ! V4      '       d   \         P                  ! V4      p\         P                  ! V4      '       d   R# \        V4      # )Fr  N)r   rq  rr  r   r   r   r  r  rI  pdf_to_rectr  rp  )r&   boxtyper   r   r  s   &&   r'   
_other_boxPage._other_box'  s    ||U\\889DII6???%%txxz7;C!!#&&((-$$d++t$$r)   Tc                	0    \        V P                  VR 7      # )r  )r   r   )r&   r   s   &&r'   r,  Page._pdf_page'  s    DII99r)   c                :    V P                   P                  4        R# )z,Invalidate / delete all annots of this page.N)rX  rW  r-   s   &r'   r  Page._reset_annot_refs'  s     r)   c                	r   V^8  d   V^8  d   Vf   R# \        \        \        V^ 4      ^d,          4      4      pV^d8  d   ^cp\        \        \        V^ 4      ^d,          4      4      pV^d8  d   ^cpRVR VR 2pV'       g   R# \        V P                  4      p\
        P                  ! VP                  4       \        R4      4      pVP                  '       g0   \
        P                  ! VP                  4       \        R4      ^4      p\
        P                  ! V\        R4      4      p	V	P                  '       g"   \
        P                  ! V\        R4      ^4      p	\
        P                  ! V	4      p
\        V
4       F9  p\
        P                  ! W4      p\
        P                  ! V4      pW8X  g   K7  Vu # 	  \
        P                  ! VP!                  4       ^4      p\
        P"                  ! V\        R4      V4       \
        P"                  ! V\        R4      V4       \
        P$                  ! WV4       V# )r  Nfitzca02dr<  r@  r=  r>  )r6   r  r'  r   r   r   r  r  r  r   rY  r  rS  r  r  rZ  r1  r[  r  )r&   gstater=  r>  r  tCAtcar   ri  rk  rG   rg  rp  r   opas   &&&&&          r'   _set_opacityPage._set_opacity'  s   7rQw9#4%Bc)*+#:C%B
S()*#:C#c3s),DII&&&txxz8K3HI	###//
H[<QSTUI!!)Xk-BC**9h{6KQODt$qA''0B$$R(D~	 
   Q/Xd^R8Xd^R8D#.r)   c           
     	   V P                   pVf   \        R4      hVP                  '       g   \        R4      hRpW9  d   \        R4      h\        V4      pV P                  p\        V^ ,          VP
                  V^,          ,
          V^,          VP
                  V^,          ,
          4      pVP                  VP                  u;8:  d$   VP                  u;8  d   VP                  8:  dE   M MAVP                  VP                  u;8:  d$   VP
                  u;8  d   VP
                  8:  g   M \        V R24      hVP                  V P                  VR\        \        V4      4       R24       R # )Nr  r  zbad boxtypez not in MediaBoxr  r  )CropBoxBleedBoxTrimBoxArtBox)r   r   r  r+  rJ  r  r  r  r  r  r  r   r   )r&   r  r   r1  valid_boxesmbs   &&&   r'   _set_pageboxPage._set_pagebox(  s
   kk;>??zzz[))B%]++Dz]]DGRUUT!W_d1gruutAwG34773bee38[4778[VXV[V[8[y(89::Gq5;1G0H-JKr)   c                	Z    V P                  4       p\        VP                  4       W4       R # r+   )r,  JM_set_resource_propertyr  )r&   r   r  r   s   &&& r'   r  Page._set_resource_property+(  s    ~~ T8r)   c	                	   \        V4      p	\        V4      p
Tp\        V P                  4      pVP	                  4       pVP                  4       p\        V4       \        WWGP                  4      pV'       g   \        P                  ! V4      p\        P                  ! V^4      p\        P                  ! VRV4       \        P                  ! V^4      p\        P                  ! V\        R4      V4       \        P                  ! ^4      p\        P                  ! VR4       \        P                   ! WV
VV4      pV^ 8  d"   \#        V\        P$                  ! V4      V4       \        P&                  ! V\        R4      4      pVP(                  '       g"   \        P*                  ! V\        R4      ^4      p\        P,                  ! V\        R4      4      pVP(                  '       g"   \        P*                  ! V\        R4      ^4      p\        P                  ! VVV4       \        P                  ! ^24      p\        P                  ! VR4       \        P                  ! VV4       \        P                  ! VR4       \/        WVV4       V# )r   fullpager  z/fullpage Dor<  z q /z Do Q )r  r  r   r   r  r1  rd  JM_xobject_from_pager   r  rZ  r  rU  r  r0
  r  pdf_new_xobjectr  r  r  r   rY  r  r  )r&   
fz_srcpager  r  r  r  r  r  r  r	  r  rc_xrefr  tpagerefr	  xobj1subres1subresr%  xobj2ri  r  s   &&&&&&&&&             r'   _show_pdf_pagePage._show_pdf_page/(  s   !$''TYY'99;  %V}}M&&u-G $$VQ/GZ7##FA.68I#6@!!"%sN3%%fsFCH6VU%?%?%FK 228Xk=RS	###//+9NPQRI##Ix	/BC   ,,Y8KQOFFHe4
 ""2&tV,tX.tX.6T7;r)   c                    V ^8  d   QhRRRR/# )r  rn  r   rs  r   r,   )r  s   "r'   r  r  h(  s      Z E r)   c                    \        V 4      p V P                  V4      pV^ 8w  d   V P                  V4       \        T4      p\	        Y4       \        TR4      '       g   Q hT#   T^ 8w  d   T P                  T4       i i ; i)zAdd a 'Caret' annotation.r   )annot_preprocessr*  r  r   annot_postprocessr=   )r&   rn  old_rotationr   s   &&  r'   add_caret_annotPage.add_caret_annoth(  s    '-	0))%0Eq !!,/u$&x(((( q !!,/ !s   A" "A=c                    V ^8  d   QhRRRR/# r  r   r   rs  r   r,   )r  s   "r'   r  r  u(  s     	 	Y 	5 	r)   c                    \        V 4      p V P                  V\        P                  4      pV^ 8w  d   V P	                  V4       \        Y4       T#   T^ 8w  d   T P	                  T4       i i ; i)z*Add a 'Circle' (ellipse, oval) annotation.)r3  rg  r   rD  r  r4  r&   r   r5  r   s   &&  r'   add_circle_annotPage.add_circle_annotu(  k    '-	0..tU5K5KLEq !!,/$& q !!,/ !    A A-c               4    V ^8  d   QhRRRRRRRRR	RR
RRR/# )r  rn  r   r4  r  rj   r  rW  r  r  r5  rs  r   r,   )r  s   "r'   r  r  (  sP         	
    r)   c           	         \        V 4      p V P                  VVVVVVR7      pV^ 8w  d   V P                  V4       \        Y4       T#   T^ 8w  d   T P                  T4       i i ; i)z"Add a 'FileAttachment' annotation.)rW  r  r5  )r3  r8  r  r4  )	r&   rn  r4  rj   rW  r  r5  r5  r   s	   &&&&&&&  r'   add_file_annotPage.add_file_annot(  s}     (-
	0((' ) E q !!,/$& q !!,/ !s   A	 	A$r   r   r   r_  r  r  r  rB  rC  r]  r  r`  rD  r  c               T    V ^8  d   QhRRRRRRRRR	R
RR
RR
RRRR
RR
RRRRRRRRRR/# )r  r   r   r   r  r   r  r   r  r   r  r_  r  r  r  rB  rC  r6   r]  r  r`  rs  r   r,   )r  s   "r'   r  r  (  s     . .. .
 . . . . !.  . . . . . .  !.& '.r)   c                   \        V 4      p V P                  VVVVVVVVV	V
VVVVVVR7      pV^ 8w  d   V P                  V4       \        T T4       T#   T^ 8w  d   T P                  T4       i i ; i)zAdd a 'FreeText' annotation.)r   r   r   r_  r  r  r  rB  rC  r]  r  r`  rD  r  )r3  rG  r  r4  )r&   r   r   r   r   r   r_  r  r  r  rB  rC  r]  r  r`  rD  r  r5  r   s   &&&$$$$$$$$$$$$$$  r'   add_freetext_annotPage.add_freetext_annot(  s    , (-	0,,%%))!-!-!#%#!%! - E& q !!,/$& q !!,/ !s   !A A/c                   V ^8  d   QhRR/# r  rs  r   r,   )r  s   "r'   r  r  (  s      38r)   c                    Vf   \        WW4R7      pM\        V4      pV P                  V\        P                  4      pV# )zAdd a 'Highlight' annotation.r  r  r  )get_highlight_selectionCheckMarkerArgr  r   PDF_ANNOT_HIGHLIGHT)r&   r
  r  r  r  rc  rI   s   &&&&&  r'   add_highlight_annotPage.add_highlight_annot(  s<     ='PAu%A##Au'@'@A
r)   c                    V ^8  d   QhRRRR/# )r  handwritingr   rs  r   r,   )r  s   "r'   r  r  (  s       % r)   c                    \        V 4      p V P                  V4      pV^ 8w  d   V P                  V4       \        Y4       T#   T^ 8w  d   T P                  T4       i i ; i)z^Add a 'Ink' ('handwriting') annotation.

The argument must be a list of lists of point_likes.
)r3  rR  r  r4  )r&   rR  r5  r   s   &&  r'   add_ink_annotPage.add_ink_annot(  se    
 (-	0''4Eq !!,/$& q !!,/ !   A Ac               $    V ^8  d   QhRRRRRR/# )r  rJ  r   rK  rs  r   r,   )r  s   "r'   r  r  (  s!     	 	 	 	 	r)   c                    \        V 4      p V P                  W4      pV^ 8w  d   V P                  V4       \        Y4       T#   T^ 8w  d   T P                  T4       i i ; i)zAdd a 'Line' annotation.)r3  rV  r  r4  )r&   rJ  rK  r5  r   s   &&&  r'   add_line_annotPage.add_line_annot(  sc    '-	0((0Eq !!,/$& q !!,/ !rV  c                    V ^8  d   QhRRRR/# r  rI  r   rs  r   r,   )r  s   "r'   r  r  (  s     	 	 	 	r)   c                    \        V 4      p V P                  V\        P                  4      pV^ 8w  d   V P	                  V4       \        Y4       T#   T^ 8w  d   T P	                  T4       i i ; i)zAdd a 'Polygon' annotation.)r3  r[  r   rG  r  r4  r&   rI  r5  r   s   &&  r'   add_polygon_annotPage.add_polygon_annot(  sk    '-	0''0G0GHEq !!,/$& q !!,/ !r?  c                    V ^8  d   QhRRRR/# r\  r,   )r  s   "r'   r  r  (  s     	 	 	% 	r)   c                    \        V 4      p V P                  V\        P                  4      pV^ 8w  d   V P	                  V4       \        Y4       T#   T^ 8w  d   T P	                  T4       i i ; i)zAdd a 'PolyLine' annotation.)r3  r[  r   rF  r  r4  r^  s   &&  r'   add_polyline_annotPage.add_polyline_annot(  sk    '-	0''0I0IJEq !!,/$& q !!,/ !r?  c                    V ^8  d   QhRRRR/# r9  r,   )r  s   "r'   r  r  )  s     	 	9 	 	r)   c                    \        V 4      p V P                  V\        P                  4      pV^ 8w  d   V P	                  V4       \        Y4       T#   T^ 8w  d   T P	                  T4       i i ; i)z&Add a 'Square' (rectangle) annotation.)r3  rg  r   rC  r  r4  r;  s   &&  r'   add_rect_annotPage.add_rect_annot)  r>  r?  c               8    V ^8  d   QhRRRRRRRRRR	R
R	RRRR/# )r  r   r  r   r   r  r  r6   r   r  r   r  r   rs  r   r,   )r  s   "r'   r  r  )  s\     < < < 	<
 < < < < < <r)   c	                   Rp	V'       d   \        \        P                  4      P                  V4      '       g   \	        V4       \	        V4       V'       g   RpV'       g   ^pV'       g   Rp\        VR4      '       d   WwV3p\        V4      ^8  d
   VR,          pRp
V
P                  ! VRVRV/ p	Vf   RpV'       d0   \        VR4      '       d   WfV3p\        V4      ^8  d
   VR,          pMRp\        V 4      p V P                  WV	WVR7      pV^ 8w  d   V P                  V4       \        Y4       T'       d   TP                  4       P                  4       RR pTw  rpppTP                  T4       TP                  T4       TP                  T4       TP                  T4       TP                  T4       TP                  R	4       R
P                  T4      pTP!                  T^ 4       T#   T^ 8w  d   T P                  T4       i i ; i)zAdd a 'Redact' annotation.Nr  r  Nr   Nr  r  r  )r   rb  r  r   r  r  r  r  r  r  r  )r  rJ  
whitespacer
  r  r=   r9   r  r3  rd  r  r4  r(  r  ro   r  r7  )r&   rM  r   r   r   r  r   r   r  rb  r   r5  r   r>  r@  rA  rB  rC  rD  r'  s   &&&&&&&&&           r'   add_redact_annotPage.add_redact_annot)  s    F--.99$??tz"!&
z;//(jA
:"'^
5CZZDxD8DF| 4-- -Dt9q=8DD'-	0**46" + /E q !!,/$& \\^..0"5F &A2r2MM"MM"MM"MM"MM"MM$F#BLLQ# q !!,/ !s   >G0 0Hc                   V ^8  d   QhRR/# rI  r,   )r  s   "r'   r  r  K)  s     B B Br)   c                |    Vf   \        WW4R7      pM\        V4      pV P                  V\        P                  4      # )zAdd a 'Squiggly' annotation.rK  )rL  rM  r  r   PDF_ANNOT_SQUIGGLYr&   r
  r  r  r  rc  s   &&&&& r'   add_squiggly_annotPage.add_squiggly_annotK)  s8     ='PAu%A$$Q(@(@AAr)   c                    V ^8  d   QhRRRR/# r9  r,   )r  s   "r'   r  r  Y)  s     	 	I 	5 	r)   c                    \        V 4      p V P                  W4      pV^ 8w  d   V P                  V4       \        Y4       T#   T^ 8w  d   T P                  T4       i i ; i)z$Add a ('rubber') 'Stamp' annotation.)r3  r  r  r4  )r&   r   r|  r5  r   s   &&&  r'   add_stamp_annotPage.add_stamp_annotY)  sc    '-	0))$6Eq !!,/$& q !!,/ !rV  c                   V ^8  d   QhRR/# rI  r,   )r  s   "r'   r  r  d)  s     D DSX Dr)   c                |    Vf   \        WW4R7      pM\        V4      pV P                  V\        P                  4      # )zAdd a 'StrikeOut' annotation.rK  )rL  rM  r  r   PDF_ANNOT_STRIKE_OUTrs  s   &&&&& r'   add_strikeout_annotPage.add_strikeout_annotd)  s6    ='PAu%A$$Q(B(BCCr)   c               (    V ^8  d   QhRRRRRRRR/# )r  rn  r   r   r  r5  rs  r   r,   )r  s   "r'   r  r  l)  s)     	 	J 	c 	 	QV 	r)   c                    \        V 4      p V P                  WVR7      pV^ 8w  d   V P                  V4       \        Y4       T#   T^ 8w  d   T P                  T4       i i ; i)z&Add a 'Text' (sticky note) annotation.)r5  )r3  r  r  r4  )r&   rn  r   r5  r5  r   s   &&&&  r'   add_text_annotPage.add_text_annotl)  sh    '-	0((4(@Eq !!,/$& q !!,/ !s   A A c                   V ^8  d   QhRR/# rI  r,   )r  s   "r'   r  r  w)  s     C CSX Cr)   c                |    Vf   \        WW4R7      pM\        V4      pV P                  V\        P                  4      # )zAdd a 'Underline' annotation.rK  )rL  rM  r  r   PDF_ANNOT_UNDERLINErs  s   &&&&& r'   add_underline_annotPage.add_underline_annotw)  s6    ='PAu%A$$Q(A(ABBr)   c                    V ^8  d   QhRRRR/# )r  r\  rZ  rs  r   r,   )r  s   "r'   r  r  )  s       E r)   c                   \        V 4       V P                  pVP                  '       g   \        R4      hVP	                  4        V P                  VP                  VP                  4      pV'       g   R# RVn        \        P                  ! V 4      Vn        W0P                  \        V4      &   VP                  Vn        W1n        VP                  4        V# )zAdd a 'Widget' (form field).r  NT)ro  r   r  r   r  r  r  r  r   r  r   rX  rY  r  rN  )r&   r\  r1  r   s   &&  r'   
add_widgetPage.add_widget)  s    Dkkzzz[)) 1 163D3DE}}T*&+E#r)   c                |     \        V 4       V P                  RR7      pVP                  '       g   . # \        V4      # )z
page get list of annot names
Fr  )ro  r,  r   JM_get_annot_id_listr&   r   s   & r'   annot_namesPage.annot_names)  s8     	>D~~u~-I#D))r)   c                    \        V 4      # )z8
List of xref numbers of annotations, fields and links.
)JM_get_annot_xref_list2r-   s   &r'   r  Page.annot_xrefs)  s     't,,r)   c              #    "   \         P                  \         P                  \         P                  3p\	        VR4      '       g7   V P                  4        Uu. uF  q3^,          V9  g   K  V^ ,          NK  	  ppMEV P                  4        Uu. uF+  q3^,          V9   g   K  V^,          V9  g   K"  V^ ,          NK-  	  ppV F)  pV P                  V4      pV'       g   K  RVn        Vx  K+  	  R# u upi u upi 5i)zGenerator over the annotations of a page.

Args:
    types: (list) annotation types to subselect from. If none,
           all annotations are returned. E.g. types=[PDF_ANNOT_LINE]
           will only yield line annotations.
r  TN)r   r  PDF_ANNOT_POPUPrT  r=   r  
load_annot_yielded)r&   types
skip_typesr   r  r  r   s   &&     r'   r  Page.annots)  s      **E,A,A5CYCYZ
um,,)-)9)9);V);At:?U41Q44);KVK)-)9)9);h);Atu}4QRSTQU]gQg41Q44);KhDOOD)Eu#   Whs6   AC:C0*C07C:C5 C50C5=C:C:c          
     ,    V ^8  d   QhRRRRRRRRRR/# )	r  r   'Page'r
  r6   r  r   rs  r   r,   )r  s   "r'   r  r  )  sA     m mmm m 	m
 mr)   c           
        R p\        V 4       V P                  pVP                  '       g   VP                  '       d   \	        R4      hVP
                  '       g   \	        R4      h. pV P                  \        P                  3R7       F"  pVP                  VP                  4       4       K$  	  V. 8X  d   R# V P                  W1V4      pV'       g   \	        R4      hV P                  4       p	V F  p
V
R,          pV
R,          pV'       d$   V	P                  V4       V	P                  WR	7       R
V
P                  4       9   g   KW  V
R
,          pV
P!                  R^ 4      pV
R,          pV
R,          pV
R,          pV! WVV4      pRpV^ 8  g   K  V^8  g   K  V	P#                  VVVVVVR7      pVR,          pK4  	  V	P%                  4        R# )a  Apply the redaction annotations of the page.

Args:
    page: the PDF page.
    images:
          0 - ignore images
          1 - remove all overlapping images
          2 - blank out overlapping image parts
          3 - remove image unless invisible
    graphics:
          0 - ignore graphics
          1 - remove graphics if contained in rectangle
          2 - remove all overlapping graphics
    text:
          0 - remove text
          1 - ignore text
c                   V'       d   V P                   \        8:  d   V #  \        WV4      pTR,          pT P                   p\        P                  ! YF,          4      T,          pYpP                  8  d   T # T pT P                  P                  T P                  P                  ,           T,
          R,          p	Yn        T#   \        \        P
                  3 d    \        '       d   \        4        T u # i ; i)a   Calculate minimal sub-rectangle for the overlay text.

Notes:
    Because 'insert_textbox' supports no vertical text centering,
    we calculate an approximate number of lines here and return a
    sub-rect with smaller height, which should still be sufficient.
Args:
    annot_rect: the annotation rectangle
    new_text: the text to insert.
    font: the fontname. Must be one of the CJK or Base-14 set, else
        the rectangle is returned unchanged.
    fsize: the fontsize
Returns:
    A rectangle to use instead of the annot rectangle.
333333?      ?)r  r8  get_text_lengthr   r   FzErrorBaser  r{   r  ceilr3  r*  rj  blr  )

annot_rectnew_textr  r7  
text_widthline_heightr  r"  r$  rj  s
   &&&&      r'   center_rect*Page.apply_redactions.<locals>.center_rect)  s      z//7:!!",XUC

  #+K$$E		*,-;A%%%!!A:==??2Q6#=ADH  1 12 "''"$!!"s   C   &C6'C65C6r  r  )r  FzError applying redactions.r   r   )r   rp  r   r  r   r   r   )r   r   rp  r  r  Tr  )ro  r   r  r   r   r  r  r   r  ro   r  r  	new_shape	draw_rectfinishr  r:   insert_textboxcommit)r   r
  r  r   r  r1  redact_annotsr   r   shaperedactr  r   r  r  r6  r7  rp  trects   &&&&               r'   r
  Page.apply_redactions)  s   0 	D 	Dkks}}};<<zzz[))[[))+ ! 
E   !9!9!;<	
 B##D(;9::  #FJ&>D
+$3&!&>

7A.z*z*|,#J%G1f!-- !&!&## . B SLE5 $6 	r)   c                    VR9  d   \        R4      h\        V P                  4      p\        P                  ! 4       pWn        \        P                  ! V4      p\        P                  ! W P                  V4       R# )zJConvert colorspaces of objects on the page.

Valid values are 1, 3 and 4.
z!components must be one of 1, 3, 4Nr  )	r   r   r   r   pdf_recolor_optionsnum_compPdfRecolorOptionspdf_recolor_pager]  )r&   r*
  pdfdocroptroptss   &&   r'   r
  Page.recolor%*  s]    
 Y&@AA!$++.((*"''-v{{E:r)   c                ,   \        V4      pVP                  '       g#   W P                  ,          P                  '       d   \	        R4      hW P
                  ,          p\        V 4      p\        V4      p\        P                  ! W44       \        V4       R# )z-Clip away page content outside the rectangle.z"rect must not be infinite or emptyN)r+  r  r   r  r   rt  r   r  r   pdf_clip_pager  )r&   r   r  r  pclips   &&   r'   clip_to_rectPage.clip_to_rect2*  sm    Dzyy 0:::ABB***t$%G+!r)   c                d    V P                   e   R# \        '       g   R# \        V 4      pWn         R# )z!Try to access layout information.N)layout_informationr   )r&   layout_infos   & r'   
get_layoutPage.get_layout=*  s+     "".{!$'"-r)   c                    V P                  R4      pVf   V P                  # V P                  p\        V^ ,          VP                  V^,          ,
          V^,          VP                  V^,          ,
          4      # )z
The ArtBoxr  r	  r	  rJ  r+  r  r&   r   r  s   &  r'   artboxPage.artboxK*  s[     x(<<<]]DGRUUT!W_d1gruutAwGGr)   c                    V P                  R4      pVf   V P                  # V P                  p\        V^ ,          VP                  V^,          ,
          V^,          VP                  V^,          ,
          4      # )zThe BleedBoxr  r  r  s   &  r'   bleedboxPage.bleedboxT*  s[     z*<<<]]DGRUUT!W_d1gruutAwGGr)   c                   \        V 4       \        V P                  4      p\        P                  ! V4      p\        V4      pVP                  '       d   V P                  P                  '       dz   V P                  pVP                  VP                  rTV P                  R9  d   YTrT\        ^ ^ WE4      p\        P                  RR7      P                  4       R,          p\!        V4       V# )zGet page rectangle.F)r
  rx      r  )ro  r   r   r   r  r+  r  r   r  r	  r  r3  ru  r  mupdf_warningsr  rv   )r&   r   r  cbr   r"  r   s   &      r'   bound
Page.bound]*  s    D499%!!$'3i???t{{111B88RYYq}}H,1q!Q"C&&U&3>>@DCCL
r)   c                	   V'       g#   V P                   '       g   V P                  4        \        V P                  R R7      pVP                  '       g   R# \        ^VR7      p\        P                  ! VP                  4       W#4       R# )Fr  N)r  r  )	
is_wrappedwrap_contentsr   r   r   r  r   pdf_filter_page_contentsr1  )r&   r  r   r  s   &&  r'   r  Page.clean_contentso*  sW     TYY7(XF&&
DBr)   c                    \        V 4       V P                  RR7      pVP                  '       g"   \        P                  ! V P
                  4      pM\        VP                  4       4      p\        V4      pV# )zThe CropBox.Fr  )	ro  r,  r   r   r  r   r	  r  r+  )r&   r   r  s   &  r'   r	  Page.cropboxx*  sW     	D~~u~-%%dii0CTXXZ(C3i
r)   c                	.    V P                   P                  # r+   )r	  r*  r-   s   &r'   cropbox_positionPage.cropbox_position*  s    ||r)   c                    \        V 4       \        V4       V P                  4       p \        VP                  4      pV'       g   M"\        P
                  ! W#P                  4       KA  \        P                  ! VP                  4      p\        P
                  ! W!P                  4       \        V4      pV'       dD   RVn        \        P                  ! V 4      Vn        WUP                  P                  \        V4      &   VP                  4        V# )z!Delete annot and return next one.T)ro  r,  r  r   r   r  rU  r   r   r  r   r   rX  rY  r   )r&   r   r   r  	nextannotr  s   &&    r'   delete_annotPage.delete_annot*  s    DE~~)%**5I""48((4	tZZ0ICK t,CJ.1JJ""2c7+
r)   c                    V ^8  d   QhRRRR/# r  r   r  r  r6   r,   )r  s   "r'   r  r  *  s     - -6 - -r)   c                l    \        \        R^4      pVP                  4        V P                  WR7       R# )zDelete the image referred to by xef.

Actually replaces by a small transparent Pixmap using method Page.replace_image.

Args:
    xref: xref of the image to delete.
)r  Nrx   rx   r  r  )r  r  
clear_withreplace_image)r   r  r  s   && r'   delete_imagePage.delete_image*  s-     V\1-4,r)   c                f  a a \        S 4       \        S\        4      '       g   R# VV 3R lp\        S P                  RR7      pVP
                  '       g   V! 4       # S\        ,          pV^8  d   V! 4       # \        P                  ! VP                  4       \        R4      4      pVP
                  '       g   V! 4       # \        P                  ! V4      pV^ 8X  d   V! 4       # ^ p\        V4       F5  p\        P                  ! \        P                  ! WX4      4      pWG8X  g   K5   M	  WG8w  d   V! 4       # \        P                  ! VX4       \        P                   ! VP#                  4       V4       \        P$                  ! VP                  4       \        R4      V4       \'        V4       V! 4       # )zDelete a Link.Nc                    < SR ,          ^ 8X  d   R#  SR,          p SP                   V ,          pVP                  4        R#   \         d    \        ^8  d   \	        4         R# i ; i)r  NrY  )rX  r   rk   r  r{   )linkidlinkobjlinkdictr&   s     r'   finished"Page.delete_link.<locals>.finished*  sY    1$f!$**62  '!+0@s   ,A  A%$A%Fr  r  )ro  r@   r7   r   r   r   r  r   r  r  r  r  rS  r  r  r  r  r1  rU  r  )	r&   r  r  r   r  r  r  oxrefrg  s	   ff       r'   r
  Page.delete_link*  sD   D8T**		 DII6:%!8:##TXXZ(1CD   :""F+19:A$$e&9&96&EFE} 
 =:*T2DHHJ(:FC$zr)   c               $    V ^8  d   QhRRRRRR/# )r  r   r  r\  rZ  rs  r,   )r  s   "r'   r  r  *  s!      F F v r)   c                "   \        V 4       \        VRR4      pVf   \        R4      hVP                  pV P	                  V4       RVP
                  n        \        VP                  P                  4       4      pV F  pVP                  V K  	  V# )z0Delete widget from page and return the next one.r  Nzbad type: widget)
ro  r   r   r]  r  r  r   r   r  r  )r   r\  r   
nextwidgetkeylistr  s   &&    r'   delete_widgetPage.delete_widget*  s    D$/=/00[[
% #v++-.C$ r)   c                   V ^8  d   QhRR/# r  rs  r  r,   )r  s   "r'   r  r  *  s     8 86 8r)   c                J   \         '       d*   \        \        P                  ! V P                  4      4      # V P                  RR7      pVP                  '       g8   \        \        P                  ! \        P                  P                  4      4      # \        \        V4      4      # )zReflects page de-rotation.Fr  )r  r  r   Page_derotate_matrixr   r,  r   r   rq  UNITre  )r&   r  s   & r'   ru  Page.derotation_matrix*  sn     ;%44dii@AA..%.0!!!%,,u||'8'89::-g677r)   c          $     `    V ^8  d   QhRRRRRRRRRRRR	R
R	RRRRRRRRRRRRRRRRRRRRRR/# )r  r   r  rJ  r   rK  p3p4rp  r  r   r  r  r  r  r-  	closePathr   lineCapr6   lineJoinr  stroke_opacityfill_opacityr  rs  r)  r,   )r  s   "r'   r  r  *  s     % %%% % 	%
 % % % % % % % % % % "%   !%" #%$ %%r)   c                    V P                  4       pVP                  \        V4      \        V4      \        V4      \        V4      4      pVP                  VVVVVVV	V
VVVR7       VP	                  V4       V# )zODraw a general cubic Bezier curve from p1 to p4 using control points p2 and p3.rp  r   r  r  r  r  r-  r  r  r	  r  )r  draw_bezierr)  r  r  )r   rJ  rK  r  r  rp  r   r  r  r-  r  r  r  r  r  r	  r  r2  r   s   &&&&&&&&&&&&&&&&&  r'   r  Page.draw_bezier*  sy    ( nnOOE"IuRy%)U2YG

!#-) 	 	 	

7r)   c               T    V ^8  d   QhRRRRRRRRR	RR
RRRRRRRRRRRRRRRRRRR/# )r  r   r  r  r   radiusr  rp  r  r   r-  r  r  r  r  r6   r  r  r   r  r	  r  rs  r)  r,   )r  s   "r'   r  r  +  s             	 
               "        r)   c                    V P                  4       pVP                  \        V4      V4      pVP                  VVVVVV	VVVVR7
       VP	                  V
4       V# )*Draw a circle given its center and radius.
rp  r   r  r  r  r  r-  r  r	  r  )r  draw_circler)  r  r  )r   r  r  rp  r   r-  r  r  r  r  r  r  r	  r  r2  r   s   &&&&&&&&&&&&&&  r'   r  Page.draw_circle+  sf    " nnOOE&M62

!-) 	 	 	

7r)   c          "     \    V ^8  d   QhRRRRRRRRRRR	RR
RRRRRRRRRRRRRRRRRRRRR/# )r  r   r  rJ  r   rK  r  rp  r  r   r  r  r  r  r-  r  r   r  r6   r  r  r  r	  r  rs  r)  r,   )r  s   "r'   r  r  :+  s     $ $$$ $ 	$
 $ $ $ $ $ $ $ $ $ "$  $  !$" #$r)   c                    V P                  4       pVP                  \        V4      \        V4      \        V4      4      pVP                  VVVVV
VVV	VVVR7       VP	                  V4       V# )zdDraw a special Bezier curve from p1 to p3, generating control points on lines p1 to p2 and p2 to p3.r  )r  
draw_curver)  r  r  )r   rJ  rK  r  rp  r   r  r  r-  r  r  r  r  r  r	  r  r2  r   s   &&&&&&&&&&&&&&&&  r'   r  Page.draw_curve:+  ss    & nnNN59eBir;

!#-) 	 	 	

7r)   c               L    V ^8  d   QhRRRRRRRRRR	R
RRRRRRRRRRRRRRR/# )r  r   r  rJ  r   rK  rp  r  r  r  r  r  r  r6   r  r  r   r-  r  r	  rs  r)  r,   )r  s   "r'   r  r  `+  s             	 
             "      r)   c                    V P                  4       pVP                  \        V4      \        V4      4      pVP                  VVVRVVV	V
VVR7
       VP	                  V4       V# )z&Draw a line from point p1 to point p2.F
rp  r  r  r  r  r  r-  r  r	  r  )r  	draw_liner)  r  r  )r   rJ  rK  rp  r  r  r  r  r  r-  r  r	  r  r2  r  s   &&&&&&&&&&&&&  r'   r  Page.draw_line`+  sj      nnMM%)U2Y/

!-) 	 	 	

7r)   c               P    V ^8  d   QhRRRRRRRRRR	R
RRRRRRRRRRRRRRRRR/# )r  r   r  r   z"typing.Union[rect_like, quad_like]rp  r  r   r  r  r-  r  r  r  r6   r  r  r   r  r	  r  rs  r)  r,   )r  s   "r'   r  r  +  s         4    	 
             "        r)   c                    V P                  4       pVP                  V4      pVP                  VVVVVVVV
VVR7
       VP                  V	4       V# )z4Draw an oval given its containing rectangle or quad.r  )r  	draw_ovalr  r  )r   r   rp  r   r  r-  r  r  r  r  r  r	  r  r2  r   s   &&&&&&&&&&&&&  r'   r   Page.draw_oval+  s`      nnMM$

!-) 	 	 	

7r)   c               T    V ^8  d   QhRRRRRRRRRR	R
RRRRRRRRRRRRRRRRRRR/# )r  r   r  rI  r   rp  r  r   r  r  r  r  r-  r  r6   r  r  r   r  r  r	  r  rs  r)  r,   )r  s   "r'   r  r  +  s     " """ " 	"
 " " " " " " " ""  " " "r)   c                    V P                  4       pVP                  V4      pVP                  VVVVVVVV
VVVR7       VP                  V	4       V# )z&Draw multiple connected line segments.r  )r  draw_polyliner  r  )r   rI  rp  r   r  r  r-  r  r  r  r  r  r	  r  r2  r   s   &&&&&&&&&&&&&&  r'   r$  Page.draw_polyline+  se    " nnf%

!#-) 	 	 	

7r)   c               P    V ^8  d   QhRRRRRRRRRR	R
RRRRRRRRRRRRRRRRR/# )r  r   r  rM  r   rp  r  r   r  r  r  r  r  r6   r  r-  r  r   r  r	  r  rs  r)  r,   )r  s   "r'   r  r  +  s             	 
             "        r)   c                    V P                  4       pVP                  \        V4      4      pVP                  VVVVVVVV
VVR7
       VP	                  V	4       V# )zDraw a quadrilateral.r  )r  	draw_quadQuadr  r  )r   rM  rp  r   r  r  r  r  r-  r  r  r	  r  r2  r   s   &&&&&&&&&&&&&  r'   r(  Page.draw_quad+  sd      nnMM$t*%

!-) 	 	 	

7r)   c               P    V ^8  d   QhRRRRRRRRRR	R
RRRRRRRRRRRRRRRRR/# )r  r   r  r   r   rp  r  r   r  r  r  r  r  r6   r  r-  r  r   r  r	  r  rs  r)  r,   )r  s   "r'   r  r  +  s     # ### # 	#
 # # # # # # "#  # # #r)   c                    V P                  4       pVP                  \        V4      VR7      pVP                  VVVVVVVV
VVR7
       VP	                  V	4       V# )z7
Draw a rectangle. See Shape class method for details.
)r  r  )r  r  r+  r  r  )r   r   rp  r   r  r  r  r  r-  r  r  r	  r  r  r2  r   s   &&&&&&&&&&&&&&  r'   r  Page.draw_rect+  sh    & nnMM$t*VM4

!-) 	 	 	

7r)   c          $     `    V ^8  d   QhRRRRRRRRRR	R
R	RRRRRR	RRRRRRRRRRRRRRRRRR/# )r  r   r  r  r   rn  betar  rp  r  r   r  r  
fullSectorr   r-  r  r  r  r6   r  r  r  r	  r  rs  r)  r,   )r  s   "r'   r  r  ,  s     , ,,, , 	,
 , , , , , , , , , , ",   !," #,$ %,r)   c                    V P                  4       pVP                  \        V4      \        V4      W7R7      pVP                  VVVV	VVVV
VVVR7       VP	                  V4       V# )zDraw a circle sector given circle center, one arc end point and the angle of the arc.

Parameters:
    center -- center of circle
    point -- arc end point
    beta -- angle of arc (degrees)
    fullSector -- connect arc ends with center
r0  r  )r  draw_sectorr)  r  r  )r   r  rn  r/  rp  r   r  r0  r-  r  r  r  r  r  r  r	  r  r2  r   s   &&&&&&&&&&&&&&&&&  r'   r3  Page.draw_sector,  sq    6 nnOOE&M5<OU

!#-) 	 	 	

7r)   c               T    V ^8  d   QhRRRRRRRRRR	R
RRRRRRRRRRR	RRRRRRRR/# r  r   r  rJ  r   rK  breadthr  rp  r  r  r  r  r  r6   r  r  r   r-  r  r	  r  rs  r)  r,   )r  s   "r'   r  r  =,       ! !!! ! 	!
 ! ! ! ! ! ! ! "!  ! ! !r)   c                    V P                  4       pVP                  \        V4      \        V4      VR7      pVP                  VVVRVVV
VVVR7
       VP	                  V	4       V# )z/Draw a squiggly line from point p1 to point p2.r7  Fr  )r  draw_squiggler)  r  r  r   rJ  rK  r7  rp  r  r  r  r  r  r-  r  r	  r  r2  r  s   &&&&&&&&&&&&&&  r'   r;  Page.draw_squiggle=,  sq    " nneBirGD

!-) 	 	 	

7r)   c               T    V ^8  d   QhRRRRRRRRRR	R
RRRRRRRRRRR	RRRRRRRR/# r6  r,   )r  s   "r'   r  r  `,  r8  r)   c                    V P                  4       pVP                  \        V4      \        V4      VR7      pVP                  VVVRVVV
VVVR7
       VP	                  V	4       V# )z-Draw a zigzag line from point p1 to point p2.r:  Fr  )r  draw_zigzagr)  r  r  r<  s   &&&&&&&&&&&&&&  r'   r@  Page.draw_zigzag`,  sn    " nnOOE"IuRy'OB

!-) 	 	 	

7r)   c                	t   V P                   pVP                   p\        V\        P                  4      '       g   Q h\        P                  ! 4       pW&n        \        V4      p\        P                  ! WV4      p\        P                  ! WHV\        P                  ! 4       4       \        P                  ! V4       R # r+   )r   r@   r   r  r  r  r  rJ  r  rj  r  )	r&   r  r  r  r   rT  r!  r  r  s	   &&&&     r'   extend_textpagePage.extend_textpage,  s    yyZZ2u001111&&('nnR)4c5>>+;<s#r)   c                	0    \         P                  ! V 3/ VB # r+   )tablefind_tables)r&   r  s   &,r'   rG  Page.find_tables,  s      000r)   c                D   \        V 4       V P                  RR7      pVP                  '       g   R# \        P                  ! V4      pVP                  '       g   R# \        V4      pRVn        \        P                  ! V 4      Vn	        W0P                  \        V4      &   V# )zFirst annotation.Fr  NT)ro  r,  r   r   pdf_first_annotr   r   r  r   r   rX  rY  )r&   r   r   r  s   &   r'   first_annotPage.first_annot,  s~     	D~~u~-%%d+El]]4(
$'C!
r)   c                "    V P                  4       # )z
First link on page
)
load_linksr-   s   &r'   
first_linkPage.first_link,  s    
   r)   c                   \        V 4       ^ pV P                  RR7      pVP                  '       g   R# \        P                  ! V4      pVP                  '       g   R# \        V4      pRVn        \        P                  ! V 4      Vn	        W0P                  \        V4      &   \        4       p\        P                  W44       TpV# )zFirst widget/field.Fr  NT)ro  r,  r   r   pdf_first_widgetr   r   r  r   r   rX  rY  rZ  r  r[  )r&   r   r   r  r\  s   &    r'   first_widgetPage.first_widget,  s     	D~~u~-&&t,El]]4(
$'C!3'
r)   c                	   \        V 4       V P                  pV^ 8w  d   V P                  ^ 4       V P                  p. pV'       d   RMRp\	        WE4      p\
        P                  ! W6\
        P                  ! 4       \
        P                  ! 4       4       \
        P                  ! V4       V^ 8w  d   V P                  V4       V# )rx   TF)
ro  ru  r  r   JM_new_bbox_devicer   r  r|  rj  r  )r&   layersr5  r   r   
inc_layersr  s   &&     r'   get_bboxlogPage.get_bboxlog,  s    D}}1a yy#T
 "14enn&68HIs#1l+	r)   c                $   \        V 4       V P                  pV^ 8w  d   V P                  ^ 4       V P                  p\	        V\
        P                  4      '       d   \
        P                  ! V4      p\	        V\
        P                  4      '       g   Q RV P                  : 24       hV'       d   RMRp\
        P                  ! V4      p \        P                  ! YQY#4      pT^ 8w  d   T P                  T4       \        T4      '       g   Te   R# T# )z3Extract vector graphics ("line art") from the page.z
self.this=TFN)ro  ru  r  r   r@   r   r   r   r  r  r   get_cdrawingsr   callableJM_new_lineart_device_Devicer|  r  ptmr  rj  r  )
r&   extendedcallbackmethodr5  r   clipsprectr   r  s
   &&&&      r'   r\  Page.get_cdrawings,  s    D}}1a yydEMM**<<%D$-->*$))>- e##D)$$TXFB 1l+H!3	r)   c                ,   \        V 4       . p\        V P                  4      pVP                  4       p\        P
                  ! V\        P                  4      p\        P                  ! V4      '       dh   \        P                  ! V4      p\        V4       F@  p\        P                  ! WF4      p\        P                  ! V4      pVP                  V4       KB  	  V# VP                  '       d(   \        P                  ! V4      pVP                  V4       V# )zGet xrefs of /Contents objects.)ro  r   r   r  r   r  r  rI  r  rS  r  r  ro   r   )	r&   rI   r   r  rK  rG   rg  icontr  s	   &        r'   r
  Page.get_contents,  s    DDII&hhj%%c5+G+GHh''##H-A1X++H8''.

4   
    ##H-DJJ
r)   c                    \        V 4       V'       d"   \        P                  ! V P                  4      pM \        P                  ! V P                  4      p\        V4      # )zd
Make a DisplayList from the page for Pixmap generation.

Include (default) or exclude annotations.
)ro  r   fz_new_display_list_from_pager   &fz_new_display_list_from_page_contentsrX  )r&   r  r  s   && r'   get_displaylistPage.get_displaylist,  sA     	D44TYY?B==diiHB2r)   c                    V ^8  d   QhRRRR/# )r  r`  r   rs  r   r,   )r  s   "r'   r  r  
-  s     | |T |D |r)   c                   RpV P                  VR7      p\        \        V4      4       EFF  pW4,          pVR,          P                  R4      '       g   \	        VR,          4      VR&   M\	        VR,          4      VR&   VR,          R8w  d   VR,          p. pV F  pV^ ,          p	VR,          p
V	R	8X  d,   R	\	        V
^ ,          4      P                  4       V
^,          3pMHV	R
8X  d   R
\        V
^ ,          4      3pM,\        V	.V
 Uu. uF  p\        V4      NK  	  up,           4      pVP                  V4       K  	  WuR&   VR,          R9   d   V F  pVP                  V4      W[&   K  	  WSX&   EKI  	  V# u upi )a  Retrieve vector graphics. The extended version includes clips.

Note:
For greater comfort, this method converts point-likes, rect-likes, quad-likes
of the C version to respective Point / Rect / Quad objects.
It also adds default items that are missing in original path types.
)r`  r   r  r   scissorrx  rD   r	  rw  qu)
r  r   rp  r  r  r  r  r  r	  even_odd)r  r  )r\  rS  r9   r5   r+  	normalizer)  r   r)  ro   r:   object)r&   r`  allkeysr  rg  npathrD   newitemsrE   cmdrestr  DrawpathDrawpathlistget_linearts   &&             r'   get_drawingsPage.get_drawings
-  s]      ( 3s3xAFE=++F33 $U6] 3f#'i(8#9i V}g%g!Dq'C8Dt $d47m&=&=&?aI $d47m4$cU-E1eAh-E%EFOOD) " "*gV}
* A$yy|EH ! F1 !2 
 .Fs   E6c               (    V ^8  d   QhRRRRRRRR/# )r  r   r  hashesr   r  rs  r   r,   )r  s   "r'   r  r  -  s0     ' ''' ' 	'r)   c                v   V P                   pV'       d   VP                  '       d   RpVP                  '       g   Rp\        V RR4      pV'       d   V'       g   V# V'       g8   V P                  \        R7      pVP                  VR7      p?V'       d   W@n        V'       d   VP                  '       g   V# V P                  4       p/ pV F&  pV^ ,          p	\        W94      p
WV
P                  &   ?
K(  	  \        \        V4      4       F,  pWK,          pVP                  VR,          ^ 4      p	WR&   WV&   K.  	  V# )	zExtract image information only from a pymupdf.TextPage.

Args:
    hashes: (bool) include MD5 hash for each image.
    xrefs: (bool) try to find the xref for each image. Sets hashes to true.
TF_image_infoN)r  r  r  r  )r   r  r   r$  TEXT_PRESERVE_IMAGESextractIMGINFOr  
get_imagesr  r  rS  r9   r:   )r   r  r  r1  imginforT  imglistr  rE   r  r  rg  s   &&&         r'   get_image_infoPage.get_image_info-  s    kkSZZZFzzzE$t45N"")=">B''v'6G#* CJJJN//#D7D#C"&CJJ	 
 s7|$A:D;;tH~q1DLAJ	 %
 r)   c                    V ^8  d   QhRRRR/# r  r   r  rs  r   r,   )r  s   "r'   r  r  -  s     " "f " "r)   c                   \        V4      \        \        39   d   V^ ,          pM\        V4      \        J d   TpMkV P	                  4        Uu. uF  qD^,          V8X  g   K  VNK  	  ppV. 8X  d   \        R4      h\        V4      ^8w  d   \        R4      hV^ ,          ^ ,          p\        V P                  V4      pVP                  p?V P                  RR7      pV'       g3   V U	u. uF$  qR,          V8X  g   K  \        V	R,          4      NK&  	  p
p	V
# V U	u. uF7  p	V	R,          V8X  g   K  \        V	R,          4      \        V	R,          4      3NK9  	  p
p	V
# u upi u up	i u up	i )ay  Return list of image positions on a page.

Args:
    name: (str, list, int) image identification. May be reference name, an
          item of the page's image list or an xref.
    transform: (bool) whether to also return the transformation matrix.
Returns:
    A list of pymupdf.Rect objects or tuples of (pymupdf.Rect, pymupdf.Matrix)
    for all image locations on the page.
bad image namezmultiple image names foundTr  r  r6  r  )r   r   r   r6   r  r   r9   r  r   r  r  r+  r  )r   r   r  r  rg  r  r  r  infosimbboxess   &&&        r'   get_image_rectsPage.get_image_rects-  sN    :$&7D$Z3D"&//"3D"3Qtt|qq"3GD"} !122W" !=>>1:a=DT[[$'##4#016Q2X,&:P&d2f:&FQ   Bh<6) <bj!6"[/#:;  
 % E Rs$   E!E'E;EE$.(E$c                    V P                   P                  4       pV'       g   R# VP                  4        \        P                  ! V P
                  V4      # )zReturn the label for this PDF page.

Args:
    page: page object.
Returns:
    The label (str) of the page. Errors return an empty string.
r`   )r   r  r  r  r  r]  )r   r`  s   & r'   	get_labelPage.get_label.  s<     --/""4;;77r)   c                    V ^8  d   QhRRRR/# r  r,   )r  s   "r'   r  r  %.  s       4 r)   c                N   \        V 4       V P                  p. pV'       d@   \        P                  ! WP                  4      pVP                  V4       VP                  pKG  V. 8w  d   V P                  P                  '       d   \        V 4       Uu. uF#  pV^,          \        P                  8X  g   K!  VNK%  	  pp\        V4      \        V4      8X  dL   \        \        V4      4       F3  pWV,          ^ ,          W&,          R&   WV,          ^,          W&,          R&   K5  	  V# u upi )zfCreate a list of all links contained in a PDF page.

Notes:
    see PyMuPDF ducmentation for details.
r  rY  )ro  rO  r  r  r   ro   r]  r  r  r   r  r9   rS  )r   lnr5  nlri  	linkxrefsrg  s   &      r'   r)  Page.get_links%.  s     	D__""2{{3BLLBB;4;;--- ,D11  ! tu333 1  
 9~U+s9~.A'0|AEHV$%.\!_EHTN / s   D"4D"r  r  r  r  r  r  c               4    V ^8  d   QhRRRRRRRRR	R
RR
RR/# )r  r   r  r  r   r  r+  r  r   r  r   r  rs  r  r,   )r  s   "r'   r  r  ?.  sP     ) )) $)
 ')  ) ) ) )r)   c                  Vf   \         pV'       d   V^H,          p\        Ww4      p\        V4      \        J d?   VP	                  4       R8X  d   \
        pM"VP	                  4       R8X  d   \        pM\         pVP                  R9  d   \        R4      hV P                  VR7      pVP                  WWTR7      p	RpV'       d   V	P                  W"4       V	# )a  Create pixmap of page.

Keyword args:
    matrix: Matrix for transformation (default: Identity).
    dpi: desired dots per inch. If given, matrix is ignored.
    colorspace: (str/Colorspace) cmyk, rgb, gray - case ignored, default csRGB.
    clip: (irect-like) restrict rendering to this area.
    alpha: (bool) whether to include alpha channel
    annots: (bool) whether to also render annotations
Nr6  r8  zunsupported colorspace)r  )r  r  r  r  r  )r  r  r   r  r
  r  r  rG   r   rl  r  r  )
r   r  r  r  r  r  r  r  r  r  s
   &$$$$$$   r'   r  Page.get_pixmap?.  s    ( J8DD'F
s"!V+#
!!#v-#
"
<<y(566!!!0mm6mYKK!
r)   c           	        V P                   pV^ 8X  d   \        # V P                  pV^Z8X  dO   \        ^^ ^ ^VP                  VP
                  ,
          VP                  ,
          VP                  ,
          ^ 4      pMVR8X  dO   \        ^^ ^ ^^ VP
                  VP                  ,
          VP                  ,
          VP                  ,
          4      pM2\        ^^ ^ ^RVP                  ,          RVP                  ,          4      pW0P                  ,          p\        \        V4      4      R,           pVP                  R4      p\        P                  WR4      pVR9   d/   Vw  rxrWn        Wrn        Wn        Wn        V P                  V4       V P                  ^ 4       V( pV P!                  4        F'  pVP"                  V,          pVP%                  V4       K)  	  V P'                  4        F:  pVR,          V,          pV P)                  V4       WR&    V P+                  V4       K<  	  V P/                  4        F,  pVP"                  V,          pWn        VP1                  4        K.  	  V#   \,         d     K  i ; i)z;Set page rotation to 0 while maintaining visual appearance.  z cm rS  Fr  r  Z   r  )ru  r  rJ  r  r  r  r  r  ru  r   r   r  r  _insert_contentsset_mediaboxr  r  r   r  r)  r
  insert_linkrk   r  rN  )r&   ry  r  mat0r  rx  r@  r  r  r  r  r   r$  r  r\  s   &              r'   remove_rotationPage.remove_rotationj.  s   mm!8 ]]"9!Q1beebeembee&;bee&CQGDCZ!Q1a)>)FGD!Q1b255j"ruu*=D +++c
#f,jj ""4e4 )NBBEEEEb!!d[[]E

S ANN1 # NN$DVs"AT"L  & % llnFc!AKMMO % 
  s   I**I98I9c               (    V ^8  d   QhRRRRRRRR/# )r  x_tolerancer  y_tolerancefinal_filterr   rs  r   r,   )r  s   "r'   r  r  .  s:     aR aR5:aRMRaRaR 
aRr)   c                j  aa \        V 4       V P                  pVe   \        V4      pVoVoVf   V P                  4       pVV3R lpV Uu. uF  p VR,          P                  VP                  8  g   K(  VR,          P
                  VP
                  8:  g   KL  VR,          P                  VP                  8  g   Kp  VR,          P                  VP                  8:  g   K  VNK  	  p	p\        V	 Uu. uF  qR,          NK  	  upR R7      p
. pV
'       d   V
^ ,          5pRpV'       dv   Rp\        \        V
4      ^,
          ^ R	4       FP  pV! W,          V4      '       g   K  WV,          P                  ,          pWV,          P                  ,          pW RpKR  	  K}  VP                  V4       V
^  \        \        V
4      R R7      p
K  \        \        V4      R R7      pV'       g   V# V Uu. uF*  qP                  S8  g   K  VP                   S8  g   K(  VNK,  	  up# u upi u upi u upi )
aJ  Join rectangles of neighboring vector graphic items.

Args:
    clip: optional rect-like to restrict the page area to consider.
    drawings: (optional) output of a previous "get_drawings()".
    x_tolerance: horizontal neighborhood threshold.
    y_tolerance: vertical neighborhood threshold.

Notes:
    Vector graphics (also called line-art or drawings) usually consist
    of independent items like rectangles, lines or curves to jointly
    form table grid lines or bar, line, pie charts and similar.
    This method identifies rectangles wrapping these disparate items.

Returns:
    A list of Rect items, each wrapping line-art items that are close
    enough to be considered forming a common vector graphic.
    Only "significant" rectangles will be returned, i.e. having both,
    width and height larger than the tolerance values.
c                  < V P                   V P                  8  d   V P                  V P                   3MV P                   V P                  3w  r#V P                  V P                  8  d   V P                  V P                  3MV P                  V P                  3w  rEVP                   VP                  8  d   VP                  VP                   3MVP                   VP                  3w  rgVP                  VP                  8  d   VP                  VP                  3MVP                  VP                  3w  r W6S
,
          8  g(   W'S
,           8  g   WXS,
          8  g   WIS,           8  d   R# R# )zDetect whether r1, r2 are "neighbors".

Items r1, r2 are called neighbors if the minimum distance between
their points is less-equal delta.

Both parameters must be (potentially invalid) rectangles.
FTr  r  r  r  )r1r2rr1_x0rr1_x1rr1_y0rr1_y1rr2_x0rr2_x1rr2_y0rr2_y1delta_xdelta_ys   &&        r'   are_neighbors,Page.cluster_drawings.<locals>.are_neighbors.  s     02uuruu}beeRUU^255"%%.NF/1uuruu}beeRUU^255"%%.NF/1uuruu}beeRUU^255"%%.NF/1uuruu}beeRUU^255"%%.NFW,,W,,W,,W,,  r)   r   c                2    V P                   V P                  3# r+   r  r  r$  s   &r'   r
  'Page.cluster_drawings.<locals>.<lambda>.  s    144,r)   r  TFc                2    V P                   V P                  3# r+   r  r  s   &r'   r
  r  .  s    add|r)   c                2    V P                   V P                  3# r+   r  r  s   &r'   r
  r  .  s    !$$r)   r  )ro  r   r+  r}  r  r  r  r  r  rS  r9   r*  r+  ro   r  r  r3  )r&   r  drawingsr  r  r  parear  r  pathsprects	new_rectsr$  repeatrg  r  r  s   &&&&&&         @@r'   cluster_drawingsPage.cluster_drawings.  s   0 	D		JE((*H	: 
&	(  &	(	 
 &	(  &	( A 	 
 E2Eq6E28NO	
 
AFs6{Q26A$VY22AY\\)AY\\)"I!% 7 Qq	CK-CDF3y>/EF	$Q9a'(9ahh>P9QQK
 34 Rs6   %H&6H&H&>H&"H&3H+3H0
H0H0c                f    \        V 4       V P                  P                  V P                  VR7      # )z)List of fonts defined in the page object.rv  )ro  r   r  r]  r&   r  s   &&r'   	get_fontsPage.get_fonts/  s(    D{{))$++D)AAr)   c           	     4   \        V 4       V P                  pVP                  '       g   VP                  '       d   \	        R4      h\        ^^RR4      p\        4       pV'       d   WE3pMTp\        V4      \        \        39   d)   \        VR,          4      \        J g   \	        R4      hTpMuVP                  V P                  R4       Uu. uF  qV^,          8X  g   K  VNK  	  p	p\        V	4      ^8X  d   V	^ ,          pM!V	. 8X  d   \	        R4      h\	        RV R24      hVR,          p
V
^ 8w  g	   V'       d    V P                  WrR7      ^ ,          # V P#                  4       p\%        V4      p\'        V4      '       g   V# V F  pV^ ,          VR	,          8w  d   K  \)        V^,          4      pVP*                  pV^ 8X  d   Tp TpV# \        \-        VP.                  VP0                  4      4      p\3        VP.                  VP4                  ,
          4      p\3        VP6                  VP4                  ,
          4      p\        ^V,          ^ ^ ^V,          ^ ^ 4      pVV,          ( pVV3p TpV# 	  TpV# u upi   \         d    \!        4        Tu # i ; i)
zGet rectangle occupied by image 'name'.

'name' is either an item of the image list, or the referencing
name string - elem[7] of the resp. item.
Option 'transform' also returns the image transformation matrix.
r  z!need item of full page image listTr  zfound multiple images named 'r  )r  r  )ro  r   r   r  r   r+  r  r   r   r   r6   r  r]  r9   r  rk   r{   r,  JM_image_reporterr   r)  r   util_hor_matrixlllrr,  r  ur)r&   r   r  r1  inf_rectnull_matr   rE   rg  r  r  r&  r  rH   rc  r6  hmr"  r   m0r  s   &&&                  r'   get_image_bboxPage.get_image_bbox/  sU    	Dkk===C,,,;<<1b"%8%BB:$&R>S( !DEED"%"5"5dkk4"HY"HQTUVWTXLqq"HGY7|q qzB !122 #@b!IJJBx19	 ++D+FqII >>#)CyyIAttBxQqT
A66DA~ 
 add34BADD144K AADD144K AAq!QUAq1Br'
AB
%   
M Z     s   I8!I8=I= =JJc                f    \        V 4       V P                  P                  V P                  VR7      # )z*List of images defined in the page object.rv  )ro  r   r  r]  r  s   &&r'   r  Page.get_imagesH/  s(    D{{**4;;T*BBr)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  r  M/  s      d r)   c                    . pV P                  4        FK  w  r#V P                  P                  VRR7      pRV9   d   RpMRV9   d   RpMK8  VP                  W#V34       KM  	  V# )zGet OCGs and OCMDs used in the page's contents.

Returns:
    List of items (name, xref, type), where type is one of "ocg" / "ocmd",
    and name is the property name.
Tr[  r  r  r~  ocmd)r  r   r^  ro   )r&   r   pnamer  r   octypes   &     r'   get_oc_itemsPage.get_oc_itemsM/  sl     88:KE;;**4D*ADd"%IIuF+, ; 	r)   c                   \        V 4       \        P                  ! V P                  4      p\	        V4      pTpV^8X  d   \        P
                  M\        P                  p\        P                  ! WT4      p\        P                  ! R4      p\        P                  ! V4      p\        P                  ! VVP                  VP                  ,
          VP                  VP                  ,
          V^4      p	\        P                  ! V P                  W\        P                   ! 4       4       \        P"                  ! V	4       VP%                  4        \'        V4      p
V
# )zMake SVG image from page.   )ro  r   r  r   r  FZ_SVG_TEXT_AS_PATHFZ_SVG_TEXT_AS_TEXTr  r0
  r1
  fz_new_svg_devicer  r  r  r  r  rj  r  rE	  r  )r&   r  text_as_pathrJ  r  tboundstext_optionr%  rF	  r  r   s   &&&        r'   get_svg_imagePage.get_svg_image`/  s    D&&tyy1'3?13De//%JcJc))'7!!$'nnS!%%

7::%

7::% 	$))Su~~/?@c"%c*r)   c               $    V ^8  d   QhRRRRRR/# )r  r   r   r   r   rs  r  r,   )r  s   "r'   r  r  x/  s&       	r)   c                	    TpVf   V P                  4       pM\        VR4      V 8w  d   \        R4      hVP                  V4      pVf   ?V# )Nr   not a textpage of this page)r$  r   r   extractTextbox)r   r   r  rT  r   s   &&&  r'   r  Page.get_textboxx/  sU    
 :""$BR"d*:;;t$	r)   c                	6    \         P                  ! V .VO5/ VB # r+   r
  r  s   &*,r'   r  Page.get_text/  r  r)   c                	6    \         P                  ! V .VO5/ VB # r+   )r  get_text_blocksr  s   &*,r'   r  Page.get_text_blocks/  s    $$T;D;F;;r)   c                	6    \         P                  ! V .VO5/ VB # r+   )r  get_text_selectionr  s   &*,r'   r  Page.get_text_selection/  s    ''>t>v>>r)   c                	6    \         P                  ! V .VO5/ VB # r+   )r  get_text_wordsr  s   &*,r'   r  Page.get_text_words/  s    ##D:4:6::r)   c                	6    \         P                  ! V .VO5/ VB # r+   )r  get_textpage_ocrr  s   &*,r'   r  Page.get_textpage_ocr/  s    %%d<T<V<<r)   c               $    V ^8  d   QhRRRRRR/# )r  r  r   r  r6   rs  r  r,   )r  s   "r'   r  r  /  s"       # S] r)   c                	d   \        V 4       Vf   \        ^^4      pV P                  pV^ 8w  d   V P                  ^ 4        V P	                  WVR7      pV^ 8w  d   V P                  V4       \        T4      p\        P                  ! T 4      Tn        T#   T^ 8w  d   T P                  T4       i i ; i)N)r  r  )	ro  r  ru  r  r  r  r  r   r   )r&   r  r  r  r5  r  s   &&&&  r'   r$  Page.get_textpage/  s    D>Aq\F}}1a 	0))$F)KHq !!,/H%!---	 q !!,/ !s   B B/c                	   \        V 4       V P                  pV^ 8w  d   V P                  ^ 4       V P                  p. p \
        P                  ! T4      p\        P                  ! T4      p\        P                  ! ^^ ^ R^ TP                  4      Tn        \        P                  ! Y$\        P                  ! 4       \        P                  ! 4       4       \        P                  ! T4       T^ 8w  d   T P                  T4       T# )rx   r  )ro  ru  r  r   r  r   JM_new_texttrace_devicer   r  r|  r  r_  r  rj  r  )r&   r5  r   r   r  rd  s   &     r'   r  Page.get_texttrace/  s    D}}1a yy//3C ##D)..Aq"a:$U^^%5u~~7GHc"1l+	r)   c                b    \        V 4       V P                  P                  V P                  4      # )z,List of xobjects defined in the page object.)ro  r   r  r]  r-   s   &r'   get_xobjectsPage.get_xobjects/  s#    D{{,,T[[99r)   r  c                	   V P                   pVf   \        R4      h^ pVP                  R4      '       d
   VR,          p\        P	                  V4      p	V	\        4       8w  d   \        RV	 24      h\        W4      p
V
e0   V
^ ,          p\        W{4      '       d   V# VP                  V4       V# \        P                  VP                  4       R 4      p^ pR	p. R
Op. ROp VP                  V4      p^ pV^ 8  d    VP                  V4      p^pVP                  4       \         P#                  4       9   d   ^ R IpVP'                  V4      p?Ve_   \)        V4      \*        J d   TpMJ\-        VR4      '       d   \+        V4      pM,\-        VR4      '       d   VP.                  pM\        R4      hR pV P1                  WVW4VW]Wn4
      pV'       g   V# V^ ,          pV^,          p\        W{4      '       d   V# VP                  VVR7       V#   \         d    \        ^8  d   \        4         EL9i ; i  \         d    \        ^8  d   \        4         ELEi ; i)Nr  r	  r	  zbad fontname chars r  r   zbad fontfile)r7  r  )r  r  r  r  )r  china-ssjapan-skorea-s)r   r   r5   r  r  r  	CheckFontrK  rU  r"  r:   r  r  rk   r  r{   r  r  r   r!  r   r  r=   r   r  )r&   r   r%  r&  r  r=  r  r1  r  	inv_charsr  r  r  rL  
CJK_number
CJK_list_n
CJK_list_sr   fontfile_strr  r7  s   &&&&&&&              r'   insert_fontPage.insert_font/  s=   kk;>??s##|H&33H=	29+>??(7DS''%K !$$X^^%5t<
=
C
	#))(3JE >'--h7
 >>388:: &--h7J H~$':.."8}6**'}} 00LxzWZ$XC J1vq6##K 	D84[  	#a'N,<	  '!+0@s$   H :H/  H,+H,/ IIcss	scale_lowarchiver  r  _scale_word_width_verbosec                   V ^8  d   QhRR/# )r  rs  r   r,   )r  s   "r'   r  r  0  s     Q# Q# 
Q#r)   c       	   	       a V^Z,          ^ 8X  g   \        R4      hV^ 8  d   VR,          pK  VR8  d   VR,          pK  ^ Tu;8:  d   ^8:  g   M \        R4      hVf   Rp\        V4      pVR9   d$   \        ^ ^ VP                  VP                  4      pM"\        ^ ^ VP                  VP                  4      pRV,           p\	        V\
        4      '       d   \        W-VR7      pM$\	        V\        4      '       d   TpM\        R4      hV^ 8X  d   RM^V,          pTP                  T^TV
'       d   \        P                  M^ VR	7      oSP                  '       g   ^SP                  ,          pRV3# \        SP                  4      Sn        SP                  P                  SP                  P                  3R8X  g   Q hSP                  P                  SP                  P                  3R8X  g   Q h^SP                  ,          pVV8  g   Q R
V: RV: 24       h\!        SP                  P"                  SP                  P"                  ,
          V,          ^ 4      pV3R lpVP%                  V4      p^ Tu;8:  d   ^8  dJ   M MFV^ ,          pVP'                  WR7      pRV R2p\(        P+                  VVP-                  4       ^ 4       V P/                  VV^ WgV	R7       SP                  P0                  SP                  P2                  ,           ^,          V,          pVP0                  VP2                  ,           ^,          p\5        V^ ^ VVP6                  ) VP8                  ) 4      \5        V) 4      ,          \5        ^^ ^ ^VP6                  VP8                  4      ,          pV^ ,          P;                  4        F)  pVR;;,          V,          uu&   V P=                  V4       K+  	  VV3# )a  Insert text with optional HTML tags and stylings into a rectangle.

Args:
    rect: (rect-like) rectangle into which the text should be placed.
    text: (str) text with optional HTML tags and stylings.
    css: (str) CSS styling commands.
    scale_low: (float) force-fit content by scaling it down. Must be in
        range [0, 1]. If 1, no scaling will take place. If 0, arbitrary
        down-scaling is acceptable. A value of 0.1 would mean that content
        may be scaled down by at most 90%.
    archive: Archive object pointing to locations of used fonts or images
    rotate: (int) rotate the text in the box by a multiple of 90 degrees.
    oc: (int) the xref of an OCG / OCMD (Optional Content).
    opacity: (float) set opacity of inserted content.
    overlay: (bool) put text on top of page content.
    _scale_word_width: internal, for testing only.
    _verbose: internal, for testing only.
Returns:
    A tuple of floats (spare_height, scale).
    spare_height:
        The height of the remaining space in <rect> below the
        text, or -1 if we failed to fit.
    scale:
        The scaling required; `0 < scale <= 1`.
        Will be less than `scale_low` if we failed to fit.
zbad rotation angler  z'scale_low' must be in [0, 1]Nr`   zbody {margin:1px;})htmluser_cssr  z"'text' must be a string or a Story)	scale_min	scale_maxr  r5  z
scale_low=z scale=c                 6   < SP                   SP                   R 3# r+   r  )r  fits   *r'   rect_function*Page.insert_htmlbox.<locals>.rect_functionz0  s    88SXXt++r)   r=  r>  r	   gs
)r`  r  r  r  r  r  r	  )r   r+  r3  r  r@   r  Story	fit_scaler   FZ_PLACE_STORY_FLAG_NO_OVERFLOW
big_enough	parameterfilledr   r  r  r'  r  write_with_linksr  r  r  r  show_pdf_pager*  r+  r  ri  rj  r)  r  )r   r   r   r  r  r  r`  r  r]  r  r  r  	temp_rectmycssstoryrect_scale_maxr  spare_heightr&  r1  r  rj  r  mp1mp2r  r  r%  s   &&&$$$$$$$$$               @r'   insert_htmlboxPage.insert_htmlbox0  sK   T {a122qjcMFmcMFI""<==;CDzYQ4;;

;IQ4::t{{;I %s* dC  tWEEe$$EABB "+aQ]oo(?Pe;;VW    ~~~%E; #**%
SXX[[)V333

szz}}-777CMM!	!;ji\5(#;;!CHHKK#**--75@!D	, $$]3 !FE%%%=DD6A""5!((*a8 	4awO xx{{SXX[[(A-5 ww A% 5!Qvv6fWoQ1a./ 	 F$$&DLCLT" ' U""r)   rj   r3  r  r  r  r   r  r  c               $   \        V 4       V P                  pVP                  '       g   \        R4      hV^ 8X  d<   \	        V4      \	        V4      ,           \	        V	4      ,           ^8w  d   \        R4      hV'       d]   \        V4      \        J d   MH\        VR4      '       d   \        V4      pM*\        VR4      '       d   VP                  pM\        R4      hV'       d5   \        P                  P                  V4      '       g   \        RV R24      hV'       d5   \        V4      \        \        \        P                   39  d   \        R4      hV	'       d   \        V	4      \"        Jd   \        R	4      hV'       d   V'       g   V'       g   \        R
4      hV'       d5   \        V4      \        \        \        P                   39  d   \        R4      hV
^ 8  d   V
R,          p
K  V
R8  d   V
R,          p
K  V
R9  d   \        R4      h\%        V4      pVP&                  '       g   VP(                  '       d   \        R4      hWP*                  ( ,          pVP-                  V P.                  4       Uu. uF  pV^,          NK  	  ppTVP1                  V P.                  4       Uu. uF  pV^,          NK  	  up,          pTVP3                  V P.                  4       Uu. uF  pV^,          NK  	  up,          pRp^ pVR,           pVV9   d   V^,          pV\        V4      ,           pK$  V'       d   V P5                  4        VP6                  pV P9                  VV	VVVVVVV
VVVVVVR7      w  ppVe   VVn        V# u upi u upi u upi )a  Insert an image for display in a rectangle.

Args:
    rect: (rect_like) position of image on the page.
    alpha: (int, optional) set to 0 if image has no transparency.
    filename: (str, Path, file object) image filename.
    height: (int)
    keep_proportion: (bool) keep width / height ratio (default).
    mask: (bytes, optional) image consisting of alpha values to use.
    oc: (int) xref of OCG or OCMD to declare as Optional Content.
    overlay: (bool) put in foreground (default) or background.
    pixmap: (pymupdf.Pixmap) use this as image.
    rotate: (int) rotate by 0, 90, 180 or 270 degrees.
    stream: (bytes) use this as image.
    width: (int)
    xref: (int) use this as image.

'page' and 'rect' are positional, all other parameters are keywords.

If 'xref' is given, that image is used. Other input options are ignored.
Else, exactly one of pixmap, stream or filename must be given.

'alpha=0' for non-transparent images improves performance significantly.
Affects stream and filename only.

Optimum transparent insertions are possible by using filename / stream in
conjunction with a 'mask' image of alpha values.

Returns:
    xref (int) of inserted image. Re-use as argument for multiple insertions.
r  z4xref=0 needs exactly one of filename, pixmap, streamr  r   zbad filenamezNo such file: 'r   z#stream must be bytes-like / BytesIOzpixmap must be a Pixmapz mask requires stream or filenamez!mask must be bytes-like / BytesIOr  bad rotate value!rect must be finite and not emptyfzImgr   )rj   r  r   r  r  r  r  r  r`  r  r  r3  r  r  r  )rx   r  r  r  )ro  r   r  r   r   r   r  r=   r   rh   r   r  r  r  r  r;   r  r  r+  r  r  rt  r  r]  r  r  r  r  r  )r   r   r  rj   r3  r  r  r  r  r  r`  r   r  r  r1  r$  r  rg  ilstrG   r  r  s   &&$$$$$$$$$$$$        r'   insert_imagePage.insert_image0  s   ` 	Dkkzzz[))19$x.4<7$v,F!KSTTH~$:..x=6**#== 00BGGNN844#ohZq$ABBVUIrzz,JJBCCVF26778?@@DJui&DD@AAqjcMFmcMF**/00J:::@AA.... "11$++>?>!>?s44T[[ABA!1ABBs11$++>?>!1>??s7$FA3q6zH $$**+ + 
g" !(CC @B?s   8N*N#Nc               (    V ^8  d   QhRRRRRRRR/# )	r  r   r  r!  r7   r|	  r   rs  r  r,   )r  s   "r'   r  r  "1  s(     , ,& ,t ,4 ,4 ,r)   c                    \        V 4       \        P                  ! W4      pVR8X  d   \        R4      hV P	                  V34       R# )z'Insert a new link for the current page.r`   link kind not supportedN)ro  r  getLinkTextr   r+  )r   r!  r|	  r   s   &&& r'   r  Page.insert_link"1  s=    D!!$,B;677!!5(+r)   r  r%  r  r  rp  r   皙?miter_limitrender_moder-  r  r	  c          (     h    V ^8  d   QhRRRRRRRRR	R
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRR/# )r  r   r  rn  r   r   typing.Union[str, list]r   r  r  r  r   r  r%  r  r  r6   r  rp  r  r   r  rH  rI  r`  r-  r  r   r  r	  r  r,   )r  s   "r'   r  r  *1  s     / /// */
 / !/ / / / / / /  / / /  !/" #/$ %/& "'/(  )/* +/r)   c               	    V P                  4       pVP                  VVVVVVVVV	V
VVVVVVVVR 7      pV^ 8  d   VP                  V4       V# ))r   r  r   r%  r  r  rp  r   r  rI  rH  r`  r-  r  r	  r  )r  r  r  )r   rn  r   r   r  r   r%  r  r  rp  r   r  rH  rI  r`  r-  r  r  r	  r  r2  r   s   &&&$$$$$$$$$$$$$$$$$  r'   r  Page.insert_text*1  ss    0 nn__!!%##)%%  
( 7JJw	r)   
expandtabsc          .     t    V ^8  d   QhRRRRRRRRR	R
RRRRRRRR
RRRRRRRR
RRRR
RRRRRRRRRRRRR R
R!R
/# )"r  r   r  r   r   r3
  rK  r  r6   r  r  rp  r  r  rN  r	  r   r%  r  r   r  r   r  r  rH  r-  r  r  r   rI  r`  r  r  rs  r,   )r  s   "r'   r  r  [1  s    F FFF ,F
 F  F F F F  F F F F F !F  !F" #F$ %F& 'F( )F* +F, -F. "/F0 1Fr)   c                   V P                  4       pVP                  VVVVVV
VVVV	VVVVVVVVVVR7      pV^ 8  d   VP                  V4       V# )a  Insert text into a given rectangle.

Notes:
    Creates a Shape object, uses its same-named method and commits it.
Parameters:
    rect: (rect-like) area to use for text.
    buffer: text to be inserted
    fontname: a Base-14 font, font name or '/name'
    fontfile: name of a font file
    fontsize: font size
    lineheight: overwrite the font property
    color: RGB color triple
    expandtabs: handles tabulators with string function
    align: left, center, right, justified
    rotate: 0, 90, 180, or 270 degrees
    morph: morph box with a matrix and a fixpoint
    overlay: put text in foreground or background
Returns:
    unused or deficit rectangle area (float)
)r   r  r   r%  r  r  rp  r   rN  rI  rH  r  r  r`  r-  r  r	  r  )r  r  r  )r   r   r3
  r  r  rp  r  rN  r	  r   r%  r   r   r  rH  r-  r  r  rI  r`  r  r  r2  r   s   &&&$$$$$$$$$$$$$$$$$$$  r'   r  Page.insert_textbox[1  s|    Z nn!!!##%)%)   
, 7JJw	r)   c                (    V P                  4       R8H  # )z3Check if /Contents is in a balanced graphics state.r	  )r  r-   s   &r'   r  Page.is_wrapped1  s     $$&&00r)   c                   \        V P                  RR7      pVP                  '       g   R# \        P                  ! VP                  4       \        R4      4      pVP                  '       g   R# \        P                  ! V4      # )zPage language.Fr  NLang)r   r   r   r   r  r  r  pdf_to_str_buf)r&   r  rH  s   &  r'   rI  Page.language1  s]     tyy59!!!--gkkmXf=MN##D))r)   c              #  p   "   V P                  4       pV F  pVe   VR,          V9   g   K  Vx  K  	  R# 5i)zGenerator over the links of a page.

Args:
    kinds: (list) link kinds to subselect from. If none,
           all links are returned. E.g. kinds=[LINK_URI]
           will only yield URI links.
Nr  )r)  )r&   kinds	all_linksr  s   &&  r'   r5  
Page.links1  s2      NN$	D}V 5 s   %6
6c                    V ^8  d   QhRRRR/# )r  identztyping.Union[str, int]rs  r   r,   )r  s   "r'   r  r  1  s       6 5 r)   c                :   \        V 4       \        V4      \        J d   ^ pTpM#\        V4      \        J d   TpRpM\	        R4      hV P                  W24      pV'       g   V# RVn        \        P                  ! V 4      Vn	        W@P                  \        V4      &   V# )zhLoad an annot by name (/NM key) or xref.

Args:
    ident: identifier, either name (str) or xref (int).
Nz&identifier must be a string or integerT)ro  r   r  r6   r   r   r   r  r   r   rX  rY  )r&   r]  r  r   r  s   &&   r'   r  Page.load_annot1  s     	D;#DD%[CDDEFFt*J]]4(
$'C!
r)   c                `   \        V 4       \        P                  ! V P                  4      pVP                  '       g   R# \        V4      pRVn        \        P                  ! V 4      Vn	        WP                  \        V4      &   ^ Vn        RVn        V P                  P                  '       dn   V P                  4       pV Uu. uF"  q3^,          \        P                  8X  g   K   VNK$  	  ppV'       d&   V^ ,          pV^ ,          Vn        V^,          Vn        V# ^ Vn        RVn        V# u upi )zGet first Link.NTr`   )ro  r   fz_load_linksr   r   r  r   r  r   r   rX  rY  r  r  r  r  )r&   r  r  ri  link_ids   &    r'   rN  Page.load_links1  s    D!!499-~~~Cj]]4(
$'C!;;$$&E %F111E1E)EQQEF("1:  
 CHCF
 Gs   D+$D+c                (   \        V 4       \        V P                  4      p\        W!4      pTpV'       g   V# RVn        \
        P                  ! V 4      Vn        W@P                  \        V4      &   \        4       p\        P                  WE4       TpV# )zLoad a widget by its xref.T)ro  r   r   JM_get_widget_by_xrefr   r  r   r   rX  rY  rZ  r  r[  )r&   r  r   r   r  r\  s   &&    r'   load_widgetPage.load_widget1  sw    DDII&%t2J]]4(
$'C!3'
r)   c                    \        V 4       V P                  RR7      pVP                  '       g"   \        P                  ! V P
                  4      pM\        VP                  4       4      p\        V4      # )zThe MediaBox.Fr  )	ro  r,  r   r   r  r   JM_mediaboxr  r+  )r&   r   r   s   &  r'   rJ  Page.mediabox2  sS     	D~~u~-&&		2D
+DDzr)   c                	j    \        V P                  P                  V P                  P                  4      # r+   )r)  rJ  r  r  r-   s   &r'   mediabox_sizePage.mediabox_size2  s#    T]]%%t}}'7'788r)   c                	    \        V 4      # r+   )Shaper-   s   &r'   r  Page.new_shape2      T{r)   c                ,    \         P                  V 4      # )z7All /Contents streams concatenated to one bytes object.)r  _get_all_contentsr-   s   &r'   read_contentsPage.read_contents2  s    &&t,,r)   c                b    \        V 4       V P                  pVP                  V 4      pW n        R# )z-Refresh page after link/annot/widget updates.N)ro  r   r	  r   )r&   r1  r   s   &  r'   refreshPage.refresh!2  s&    Dkkt$	r)   c                    V ^8  d   QhRRRR/# r  r,   )r  s   "r'   r  r  )2  s     $  $ $ $ r)   c                  V P                   pVP                  V4      '       g   \        R4      h\        V4      \        V4      ,           \        V4      ,           ^8w  d   \        R4      hV P	                  V P
                  W$VR7      pVP                  Wa4       V P                  4       R,          pVP                  VR4       RV n	        R# )a  Replace the image referred to by xref.

Replace the image by changing the object definition stored under xref. This
will leave the pages appearance instructions intact, so the new image is
being displayed with the same bbox, rotation etc.
By providing a small fully transparent image, an effect as if the image had
been deleted can be achieved.
A typical use may include replacing large images by a smaller version,
e.g. with a lower resolution or graylevel instead of colored.

Args:
    xref: the xref of the image to replace.
    filename, pixmap, stream: exactly one of these must be provided. The
        meaning being the same as in Page.insert_image.
zxref not an imagez3Exactly one of filename/stream/pixmap must be given)rj   r   r  r+  Nr  )
r   r  r   r   r@  r   r  r
  r
  r  )r   r  rj   r  r   r1  r3  last_contents_xrefs   &&$$$   r'   r  Page.replace_image)2  s    . kk  &&011>DL(4<71<RSS$$II % 
 	h%!..04 	,d3r)   c                    \        V 4       \        V P                  ^ R7      pVP                  '       g   ^ # \	        V4      # )zPage rotation.r  )ro  r   r   r   JM_page_rotationr  s   & r'   ru  Page.rotationO2  s3     	DDII2%%r)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  r  Y2  s     2 2 2r)   c                >    \        \        P                  V 4      4      # )zReflects page rotation.)r  r  _rotate_matrixr-   s   &r'   rx  Page.rotation_matrixX2  s     e**4011r)   c                    \        V 4       \        P                  ! V P                  VP                  \        V4      \        P                  ! 4       4       R# )z-Run page through a device.
dw: DeviceWrapper
N)ro  r   r  r   rR  r  rj  )r&   rk  r  s   &&&r'   rm  Page.run]2  s5     	D$))RYY0A!0DennFVWr)   r
  r  r  c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  r  d2  s     ' ' 'r)   c               6   Vf/   ^ \         ,          \        ,          \        ,          \        ,          pVe   \	        V4      p\        V 4       TpVf   V P                  W$R7      pM\        VR4      V 8w  d   \        R4      hVP                  WR7      pVf   ?V# )aZ  Search for a string on a page.

Args:
    text: string to be searched for
    clip: restrict search to this rectangle
    quads: (bool) return quads instead of rectangles
    flags: bit switches, default: join hyphened words
    textpage: a pre-created pymupdf.TextPage
Returns:
    a list of rectangles or quads, each containing one occurrence.
)r  r  r   r  )r
  )
r
  r
  r
  r
  r+  ro  r$  r   r   search)r   r   r  r
  r  r  rT  rlists   &&$$$$  r'   r
  Page.search_ford2  s    ( ="#*+ ** %	%E :DD:""":BR"d*:;;		$	,r)   c                &    V P                  RV4      # )zSet the ArtBox.r  r  r&   r   s   &&r'   
set_artboxPage.set_artbox2  s      400r)   c                &    V P                  RV4      # )zSet the BleedBox.r  r  r  s   &&r'   set_bleedboxPage.set_bleedbox2  s      T22r)   c                   \        V 4       V P                  pVP                  '       d   \        R4      hVP                  '       g   \        R4      hV\        ^VP                  4       4      9  d   \        R4      hVP                  V4      '       g   \        R4      hVP                  V P                  RVR R24       R# )	z-Set object at 'xref' as the page's /Contents.r   r  r}  zxref is no streamrS  rH  r  N)
ro  r   r   r   r  rS  r  r  r  r  )r&   r  r1  s   && r'   set_contentsPage.set_contents2  s    Dkk===.//zzz[))uQ 122Z((!!$''011J4($@r)   c                &    V P                  RV4      # )z,Set the CropBox. Will also change Page.rect.r  r  r  s   &&r'   set_cropboxPage.set_cropbox2        D11r)   c                   \        V 4       \        V P                  4      pV'       g1   \        P                  ! VP                  4       \        R4      4       R# \        P                  ! V4      p\        \        R4      '       g   Q h\        P                  ! VP
                  \        R4      \        P                  ! V4      4       R# )zSet PDF page default language.rU  rD  N)ro  r   r   r   rH  r  r  r  r=   r  rD  )r&   rI  r  rH  s   &&  r'   r  Page.set_language2  s    Dtyy)w{{}hv.>?55h?D5"ABBBB**KKV$77=r)   c                   \        V 4       V P                  4       p\        V4      p\        P                  ! V4      '       g   \        P
                  ! V4      '       d   \        \        4      h\        P                  ! VP                  4       \        R4      V4       \        P                  ! VP                  4       \        R4      4       \        P                  ! VP                  4       \        R4      4       \        P                  ! VP                  4       \        R4      4       \        P                  ! VP                  4       \        R4      4       R# )zSet the MediaBox.MediaBoxr  r  r  r  N)ro  r,  r  r   r  r  r   r  r3  r  r  rH  )r&   r   r   rJ  s   &&  r'   r  Page.set_mediabox2  s    D~~"4(""8,,,,X66l++Xj-A8LDHHJ(;<DHHJ(:;DHHJ(<=DHHJ(;<r)   c                    \        V 4       \        V P                  4      p\        V4      p\        P
                  ! VP                  4       \        R4      V4       R# )zSet page rotation.r;  N)ro  r   r   JM_norm_rotationr   rP  r  r  )r&   ru  r   ry  s   &&  r'   r  Page.set_rotation2  s?    DDII&x(
HX,>Dr)   c                &    V P                  RV4      # )zSet the TrimBox.r  r  r  s   &&r'   set_trimboxPage.set_trimbox2  r  r)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  r  2  s     z z zr)   c	                   RR lp	\        V 4       V P                  p
V
P                  '       d   VP                  '       g   \        R4      hVP                  '       g   VP
                  '       d   \        R4      hV^ 8  d   W2P                  ,          pK  W#,          pWP                  ( ,          pV'       g   VP                  MVP                  V,          pVP                  '       g   VP
                  '       d   \        R4      hWP                  ( ,          pV	! WWGR7      pV
P                  V P                  4       Uu. uF  q^,          NK  	  ppTV
P                  V P                  4       Uu. uF  q^,          NK  	  up,          pTV
P                  V P                  4       Uu. uF  q^,          NK  	  up,          pRp^ pVR,           pVV9   d   V^,          pV\        V4      ,           pK$  VP                  pV
P                  V8X  d   \        R4      hV
P                  P!                  VR	4      pVf   \#        V
4      pVV
P                  V&   VV3pV
P$                  P!                  V^ 4      pV'       d   V P'                  4        V P)                  VVVVVVVVR
7      pVV
P$                  V&   V# u upi u upi u upi )a  Show page number 'pno' of PDF 'docsrc' in rectangle 'rect'.

Args:
    rect: (rect-like) where to place the source image
    docsrc: (document) source PDF
    pno: (int) source page number
    keep_proportion: (bool) do not change width-height-ratio
    overlay: (bool) put in foreground
    oc: (xref) make visibility dependent on this OCG / OCMD (which must be defined in the target PDF)
    rotate: (int) degrees (multiple of 90)
    clip: (rect-like) part of source page rectangle
Returns:
    xref of inserted object (for reuse)
c           	     :   V P                   V P                  ,           R,          pVP                   VP                  ,           R,          p\        ^^ ^ ^VP                  ) VP                  ) 4      \        V4      ,          pW,          pVP
                  VP
                  ,          pVP                  VP                  ,          p	V'       d   \        W4      ;rV\        W4      ,          pV\        ^^ ^ ^VP                  VP                  4      ,          p\        V4      # )a  Calculate transformation matrix from source to target rect.

Notes:
    The product of four matrices in this sequence: (1) translate correct
    source corner to origin, (2) rotate, (3) scale, (4) translate to
    target's top-left corner.
Args:
    sr: source rect in PDF (!) coordinate system
    tr: target rect in PDF coordinate system
    keep: whether to keep source ratio of width to height
    rotate: rotation angle in degrees
Returns:
    Transformation matrix.
       @)	r*  r+  r  ri  rj  r  r3  r  JM_TUPLE)
srtrr  r`  smptmpr  sr1fwfhs
   &&&&      r'   calc_matrix'Page.show_pdf_page.<locals>.calc_matrix2  s      55255=C'C55255=C'C q!QCEE6CEE62VF^CA&CCII%BSZZ'Bb+%A1aCEE35511AA;r)   r  r=  z!clip must be finite and not empty)r  r`  fzFrmr   z%source document must not equal targetN)r  r  r  r  r  r  r  )Trx   )ro  r   r  r   r  r  rv  rt  r   r  r]  r  r  r  r  r  r:   r  r  r  r/  )r   r   r  r{  r  r  r  r`  r  r  r1  r  tar_rectsrc_rectr  rg  r?  rG   r  isrcgmappno_idr  s   &&&&&&&&&              r'   r1  Page.show_pdf_page2  sj   2 	D 	Dkkzzz[))===D,,,@AAAg$$$C;5555(,8==(--$2F 4 4 4@AA====XoU "33DKK@A@!@As224;;?@?!1?@@s11$++>?>!1>?? s7$FA3q6zH==D DEE }}  t,<C=D"&CMM$ ~~!!&!, "" # 	
 "&vQ B@?s   J92J>*Kc                   \        V 4       \        P                  ! 4       pV P                  RR7      pVP                  '       g   \        V4      # \        P                  ! \        P                  P                  4      p\        P                  ! W#V4       \        V4      pV P                  R,          ^ 8X  d   \        V4      pV# \        ^^ ^ R^ V P                  P                  4      pV# )zPage transformation matrix.Fr  r  r  )ro  r   r|  r,  r   r{  rq  rE  rd  ru  r  r	  r3  )r&   r  r   rJ  r  s   &    r'   rt  Page.transformation_matrixL3  s     	Dnn~~u~-$S))<< 7 78  5$==3!#+C 
 Aq"a)<)<=C
r)   c                    V P                  R4      pVf   V P                  # V P                  p\        V^ ,          VP                  V^,          ,
          V^,          VP                  V^,          ,
          4      # )zThe TrimBoxr  r  r  s   &  r'   trimboxPage.trimbox_3  s[     y)<<<]]DGRUUT!W_d1gruutAwGGr)   c               $    V ^8  d   QhRRRRRR/# )r  r   r  r!  r7   rs  r  r,   )r  s   "r'   r  r  h3  s&     A A& At A Ar)   c                    \        V 4       \        P                  ! W4      pVR8X  d   \        R4      hV P                  P                  VR,          W R7       R# )z"Update a link on the current page.r`   rD  r  r   N)ro  r  rE  r   r   r_  )r   r!  r   s   && r'   update_linkPage.update_linkh3  sH    D!!$,B;677!!#f+u!@r)   c              #    "   V P                  4        Uu. uF)  q"^,          \        P                  8X  g   K   V^ ,          NK+  	  ppV F/  pV P                  V4      pVe   VP                  V9   g   K+  Vx  K1  	  R# u upi 5i)zGenerator over the widgets of a page.

Args:
    types: (list) field types to subselect from. If none,
            all fields are returned. E.g. types=[PDF_WIDGET_TYPE_TEXT]
            will only yield text fields.
N)r  r   rT  rf  r  )r&   r  r   widget_xrefsr  r\  s   &&    r'   r  Page.widgetsq3  st      '+&6&6&8[&8aDEDZDZ<Z!&8[ D%%d+F} 1 1U : ! \s   BA=A=*B3Bc                    V P                  4       w  rV^ 8  d    RV,          p\        P                  WR4       V^ 8  d)   RV,          R,           p\        P                  WR4       R# R# )z,Ensure page is in a balanced graphics state.r  Fs   
Qr  TN)r  r  r  )r&   pushpopprependro   s   &    r'   r  Page.wrap_contents3  s\    ))+	!8tmG""4%87c\E)F""46 r)   c                    V ^8  d   QhRRRR/# )r  r   r  rs  r  r,   )r  s   "r'   r  r  3  s     1 11 1r)   c	                   \        V \        4      '       g   Q hV'       g   \        R4      h\        V4      \        J d$   V^ 8X  d   Vf   VP                  WWCR7       R# V3pV^ ,          P                  p	\        4       p
V
P                  V P                  P                  V P                  P                  R7      pV F(  pWP                  ,          p	VP                  WVR7       K*  	  Vf   T	pV P                  VV
^ VVVV	VR7       Rp
RpR# )a  Write the text of one or more pymupdf.TextWriter objects.

Args:
    rect: target rectangle. If None, the union of the text writers is used.
    writers: one or more pymupdf.TextWriter objects.
    overlay: put in foreground or background.
    keep_proportion: maintain aspect ratio of rectangle sides.
    rotate: arbitrary rotation angle.
    oc: the xref of an optional content object
z$need at least one pymupdf.TextWriterN)r]  rp  r  r	  )r]  rp  )r  r  r`  r  r  )r@   r   r   r   
TextWriter
write_text	text_rectr   r  r   r  r3  r1  )r   r   writersr  rp  r]  r  r`  r  r  textdocr  writers   &&&&&&&&&    r'   r  Page.write_text3  s   * $%%%%CDD=J&{t|""4"W"*qz##*  tyytyy?O?O PF$$$DeEB  <D+ 	 		
 r)   c                b    \        V 4       V P                  P                  V P                  4      # r  r  r-   s   &r'   r  	Page.xref3  r  r)   zpage rectangle)r1  )rX  r   r  r  r]  r   r   r   rx  r  ru  r+   )Nrx   Nr  )NNNNNr  rx   r  rx   rx   rx   rx   r  NN)rx   r  Nr%  )Nr  r  N)r  Nrx   rx   NNNrz  )NNrr  rx   NNT)Note)r  r  rx   rv  )ru  NNr  NFrx   rx   Tr  r  rx   )ru  NNNr  rx   rx   Tr  r  rx   )
ru  Nr  rx   rx   TNr  r  rx   )ru  NNr  Nrx   rx   TFr  r  rx   )ru  NNr  rx   rx   NTr  r  rx   )ru  NNr  rx   rx   NTr  r  rx   N)ru  NNTNr  Frx   rx   Tr  r  rx   )r  ru  Nr  rx   rx   TNr  r  rx   r   r  r  )NNr   r   T)Nr  )r  NNFrx   rx   )rx   TTrx   rx   N)NNTNNTrx   rx   )r/   r0   r1   r2   r   r   r   r*  r8  r   PDF_ANNOT_LE_OPEN_ARROWrG  rR  rV  r[  rd  rg  r  r  r  r+  r  r  r   r  r  r  r  r  r  r   r  r	  r,  r  r  r  r  r/  r6  r<  rB  rF  rO  rT  rY  r_  rc  rg  rn  rt  rx  r}  r  r  r  r  r  r  r
  r
  r  r  r{  r  r  r  r  r	  r  r  r  r
  r  ru  r  r  r  r  r   r$  r(  r  r3  r;  r@  rC  rG  rK  rO  rS  rY  r\  r
  rl  r}  r  r  r  r)  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r$  r  r  r  r9  r@  r  r  r  r  rI  r5  r  rN  rf  rJ  rl  r  rt  rw  r  ru  rx  rm  r
  r  r  r  r  r  r  r  r  r1  rt  r  r  r  r  r  r  r   r  r3   r,   r)   r'   r   r   %  s    &< 22!N`@	<
BH DD
F0.2j"X* 	%:!BL*97r	 2.
  . #. !%. !%. #'. "#. !. ".  77. . .  !." #.$ %.` 				< <|B B	 	D D	 	C C$	*-(m m^;	". H H H H$C 
 
  .-*X 8 8% %N   D$ $L   D   D" "H   D# #J, ,\! !F! !F	$1   ! !  & >$| ||' 'R" "H8 4) %-) 	)
 (,) !%) ") ")V4laR aRFB
>@C
&0 5<?;=  *:
QfQ#
 Q# Q# Q# Q# Q# Q# Q# Q# Q#fz 	z
 z z !z z z z z z z z zx, ,/
 !/ $(/ #/  $/  / / !/  / #'/ "#/  !/  !/" !#/$ !%/& %&'/( #$)/* +/bF
 F #'F !F F  F #$F  F  $F #F !F $(F  "#!F" !#F$ %F& !'F(  !)F* +F,  -F. %&/FP 1 1 * *.6$   9 9-$  	$ 
 $  $ L & & 2 2X' 	'
 ' ' 'R13A2=E2z zx  $ H HA"71 1f 2 2
 E/0D r)   r   c                     ] tR tRtR tR tR tR tR t]	R 4       t
R4R	 ltR5R
 ltR6R lt]	R 4       tR t]	R 4       tR t]	R 4       tR6R lt]	R 4       t]	R 4       t]	R 4       t]	R 4       tR7R ltR8R ltR tR tR tR t]	R R l4       t]	R 4       tR t ]	R  4       t!R9R! lt"R:R" lt#R;R# lt$R$ t%R% t&R& t'R' t(R( t)]	R) 4       t*]	R* 4       t+R+ t,]	R, 4       t-R- t.]	R. 4       t/]	R/ 4       t0]	R0 4       t1]	R1 4       t2]-t3]t4R2 t5R3t6R# )<r  i3  c                   RV n         RV n         \        T\        \        P
                  3\        P                  \        P                  \        \        \        34      '       dE   Tw  r#^ p\        P                  ! T\        T4      \        P                  ! ^ 4      T4      pYPn        R# \        T\        \        P
                  3\        P                  \        P                  \        \        \        3\        \         34      '       dD   Tw  r#p\        P                  ! T\        T4      \        P                  ! ^ 4      T4      pYPn        R# \        T\        \        P
                  \#        R4      3\$        \        P&                  34      '       EdK   Tw  r&\)        T\        4      '       d   TP                  pMTf   \        P
                  ! R4      p\)        T\$        4      '       d   TP                  p\        P*                  ! T4      P,                  '       g   \/        R4      hTP,                  '       d]   \        P0                  ! TT\        P
                  ! 4       \        P2                  ! R4      \        P4                  ! 4       ^4      T n        R# \        P6                  ! T4      T n        T P                  P,                  '       g   \9        \:        4      hR# \        T\$        \        P&                  3\$        \        P&                  34      '       d   Tw  rg\)        T\$        4      '       d   TP                  p\)        T\$        4      '       d   TP                  pTpTp	TP,                  '       g9   \        P6                  ! T	4      p
T
P,                  '       g   \9        \:        4      hM\        P<                  ! Y4      p
Yn        R# \        T\$        \        P&                  3\>        \        3\>        \        3R4      '       g>   \        T\$        \        P&                  3\>        \        3\>        \        34      '       Ed    \A        T4      ^8X  d+   Tw  rkp\        P                  ! \        PB                  4      pMTw  rkr\        T4      p\)        T\$        4      '       d   TP                  MTp\        PD                  ! T4      '       g7   \        PF                  ! YPI                  4       TPK                  4       YT4      pMW\        PF                  ! YPI                  4       TPK                  4       Y\        P                  ! \        PB                  4      4      pYPn        R# \        T\L        \$        \        P&                  34      '       d>   T^ ,          R8X  d0   Tw  pp\)        T\$        4      '       d   TP                  pYPn        R# \        T\$        \        P&                  3\        R34      '       Ed   T^ ,          p\A        T4      ^8X  d
   T^,          M^p\)        T\$        4      '       d   TP                  MTp\O        T^ ^4      '       g   \/        R4      h\        P*                  ! T4      pTP,                  '       g   T'       g   \/        R4      h\        P                  ! 4       p\        PP                  ! T4      p\        PR                  ! T4      p\        PT                  ! T4      p\        PV                  ! Y+TTT4      pTP,                  PH                  TP,                  n$        TP,                  PJ                  TP,                  n%        TP,                  PX                  TP,                  n,        TP,                  PZ                  TP,                  n-         \\        P^                  ! TP,                  TP,                  T4       YPn        R# \        T\        P
                  \        3\        \        R\        \         34      '       Ed   Tw  r+pp$p\)        T\        4      '       d/   TP                  p\)        T\        P
                  4      '       g   Q h\        Pn                  ! T4      pTT,           T,          p%\        P                  ! 4       p\        PV                  ! Y+TTT4      p\)        T$\p        \r        34      '       d#   \        Pt                  ! T$4      p&\A        T$4      pMW\w        T$4      p'T'P,                  '       g   \/        R4      h\        Px                  ! T'4      w  pp(\        Pt                  ! T$4      p&T%T,          T8w  d$   \/        RT: RT: R	T: R
T: RT%: RT: 24      h\        Pz                  ! TP,                  T&4       YPn        R# \        TR4      '       Ed   Tw  p)Rp*\}        T)R4      '       d0   T)P                  4       p+T+'       d   \        P                  ! T+4      p,M\}        T)T*4      '       d,   T)P                  p+T+'       d   \        P                  ! T+4      p,M\)        T)\L        4      '       d   \        P                  ! T)4      p,MZ\w        T)4      p'T'P,                  '       d   T'P,                  P@                  '       g   \/        R4      h\        P                  ! T'4      p,\        P                  ! X,\        P                  ! \        \        \        \        4      \        P                  ! T,P                  4       ^ ^ T,P                  4       ^ ^ 4      4      w  r[p\        P                  ! T,4      w  p-p.T-TP,                  n,        T.TP,                  n-        YPn        R# \        T\        \        P                  3\        4      '       Ed   Tw  p/p0\        T/4      p1\        P                  ! T14      p2\O        T0^T2^,
          4      '       g   \/        \        4      h\        P                  ! T1T0^ 4      p3\        P                  ! T3\        R4      4      p4\        P                  ! T4\        R4      4      '       g\   \        P                  ! T4\        R4      4      '       g6   \        P                  ! T4\        R4      4      '       g   \/        \        4      h\        P                  ! T1T34      p,\        P                  ! T,\        P                  ! \        \        \        \        4      \        P                  ! T,P                  4       ^ ^ T,P                  4       ^ ^ 4      4      w  p5rT5T n        R# Rp6T F  p7T6R\#        T74       RT7 R2,          p6K  	  \        T64      h)a  
Pixmap(colorspace, irect, alpha) - empty pixmap.
Pixmap(colorspace, src) - copy changing colorspace.
Pixmap(src, width, height,[clip]) - scaled copy, float dimensions.
Pixmap(src, alpha=1) - copy and add or drop alpha channel.
Pixmap(filename) - from an image in a file.
Pixmap(image) - from an image in memory (bytes).
Pixmap(colorspace, width, height, samples, alpha) - from samples data.
Pixmap(PDFdoc, xref) - from an image at xref in a PDF document.
Nz"source colorspace must not be Nonerawzbad alpha valuez'cannot drop alpha for 'NULL' colorspacezbad samples datazbad samples length w=z h=z alpha=z n=z stride=z size=r   r  bad image datar  r  Alpha
Luminosityz+Unrecognised args for constructing Pixmap:
    r   r#   )V_samples_mv_memory_viewrI  r+  r   r-  rq  FzIrectIRectr+  r   fz_new_pixmap_with_bboxrK  r  r   r6   r   r   r  FzPixmapr@   fz_pixmap_colorspacer   r   r  r  r   fz_new_pixmap_from_alpha_channelr   MSG_PIX_NOALPHA!fz_new_pixmap_from_color_and_maskr  r9   fz_infinite_irectrL  fz_scale_pixmapri  rj  r  r  fz_pixmap_colorantsfz_pixmap_widthfz_pixmap_heightfz_new_pixmapr  r  r   pixmap_copyfz_pixmap_samples_memoryviewr  striderG   rS  fz_samples_setfz_samples_getr@  r  r  r  r.  rT  ll_fz_pixmap_copy_rawr=   r   fz_new_image_from_filer   rz  fz_get_pixmap_from_imageFZ_MIN_INF_RECTFZ_MAX_INF_RECTr|  r   r"  r  r   r   r   r  r  r  r  r  r  r  r  rk   )8r&   r  r  r   r  rS  spixmpixspmmpmr  r   r"  r6  r  src_pixr@  sepsrG   src_viewpm_viewr  tptrsptr	pm_stridepm_npm_alpha
src_stridesrc_nrj  ri  pm_isrc_irg  src_pix_alphar  samplesr  samples2r%  r  	imagedatar   r6  r2  r  r  r1  r  ra  r  r  rb  r  r   args8   &*                                                      r'   r   Pixmap.__init__3  s	     
 ! U//0u}}eT5A 
 HBE..r3CD3I5K^K^_`KachiBIU//0u}}eT5Ad  #OBe..r3CD3I5K^K^_`KachiBIz5+=+=tDzJVUZUcUcLdeeHB"j))WW''-$''yy--d3>>> "FGG}}}!33**,2248++-	 "BBDI	yy+++&88 , vu~~68PQQJD$''yy$''yyCC???<<SA~~~&88 & ==cGI7%s|UYZZvu~~6uclSS4yA~!
}}U%<%<=#' '-#-dF#;#;diiG--d33**7IIKaTXY**7IIKaTYTaTabgbybyTz{IcFENN#;<<aEAQEAr"f%%WWIvu~~6dDD 7D"4yA~DG1E#-dF#;#;diiGE1a(( "344++G4B=== "KLL&&(D))'2A%%g.A&&w/A$$RAtU;B%0022BMMO%0022BMMO!(!3!3!8!8BMM!(!3!3!8!8BMM  !!2=='2D2DaHh Iu11:>S$QTVZP[\\'+$B1gu"j))WW!"e&8&89999%%b)A%i1_F&&(D$$RAtU;B7UI$677 33G<7|(1~~~$&89911#6a 33G<zT! $:t4QD%1$iPVyX_Z^Y`"abb''AId##JIDy),,!))+66u=CD))!66u=CIs++229=(3~~~S^^-?-?-?$&67744S9
 55MM/?OUdeNNCEEGQ3557AqAHB1
 2237JD$!%BMM!%BMMIx)9)9:C@@IC"3'C((-GD!WQY// ,//((dA6C&&sHY,?@E%%eXg->??!--eXg5FGG!--eXl5KLL /22&&sC0C 66MM/?OUdeNN3557Aq#%%'1a@IC
 DI BD$tCykC533 T""r)   c                	    V P                   # r+   )r  r-   s   &r'   r  Pixmap.__len__4  s    yyr)   c                	    \        V 4      \        J g   R # RpV P                  '       d+   V P                  P                  P                  P
                  pRV RV P                   RV P                   R2# )Nr
  zPixmap(z, r  )r   r  r  r   r   r   irectr  )r&   r  s   & r'   r   Pixmap.__repr__4  s]    DzV#
???--88==JBtzzl"TZZLBBr)   c                   V P                   p\        P                  ! V4      VP                  4       ,          p\        P                  ! V4      p\        P
                  ! V4      pV^8X  d   \        P                  ! Wc4       MV^8X  d   \        P                  ! Wc4       MV^8X  d   \        P                  ! Wc4       MrV^8X  d   \        P                  ! Wc4       MTV^8X  d   \        P                  ! Wc4       M6V^8X  d   \        P                  ! WcV^ 4       M\        P                  ! Wc4       VP                  4        \        V4      pV# )z
Pixmap._tobytes
)r   r   fz_pixmap_strider"  r0
  r1
  fz_write_pixmap_as_pngfz_write_pixmap_as_pnmfz_write_pixmap_as_pamfz_write_pixmap_as_psdfz_write_pixmap_as_psfz_write_pixmap_as_jpegrE	  r#  )r&   format_jpg_qualityrS  r  r%  rF	  barrays   &&&     r'   _tobytesPixmap._tobytes4  s     YY%%b)BDDF2!!$'nnS!\E88A\E88A\E88A\E88A\E77@\))#;B((1!#&r)   c                	   V P                   pV^8X  d   \        P                  ! WA4       R# V^8X  d   \        P                  ! WA4       R# V^8X  d   \        P                  ! WA4       R# V^8X  d   \        P
                  ! WA4       R# V^8X  d   \        P                  ! WA4       R# V^8X  d   \        P                  ! WAV4       R# \        P                  ! WA4       R# r  )r   r   fz_save_pixmap_as_pngfz_save_pixmap_as_pnmfz_save_pixmap_as_pamfz_save_pixmap_as_psdfz_save_pixmap_as_psfz_save_pixmap_as_jpeg)r&   rj   r  r  rS  s   &&&& r'   	_writeIMGPixmap._writeIMG5  s    YY\E77E\E77E\E77E\E77E\E66rD\E88{S!77Er)   c                B    \         P                  ! V P                  4      # )z$Indicates presence of alpha channel.)r   fz_pixmap_alphar   r-   s   &r'   r  Pixmap.alpha5  rB  r)   Nc                    Vf#   \         P                  ! V P                  4       R# Vf$   \         P                  ! V P                  V4       R# \	        V P                  V\        V4      4       R# )z*Fill all color components with same value.N)r   fz_clear_pixmapr   fz_clear_pixmap_with_valueJM_clear_pixmap_rect_with_valuerK  )r&   r   r6  s   &&&r'   r  Pixmap.clear_with5  sH    =!!$)),\,,TYY>+DIIu>Nt>TUr)   c                Z    V P                   p\        W24      pV'       g   \        V4      # V# )z
Return count of each color.
)r   JM_color_countr9   )r&   r  r  rS  r   s   &&&  r'   color_countPixmap.color_count5  s(     YYR&8O	r)   c                <   ^ p^ pVe'   V P                   \        V4      9   d   V P                   pV P                  RVR7      P                  4        F  w  rEW%,          pWS8  g   K  TpTpK  	  V'       g    ^\	        ^.V P
                  ,          4      3# W2,          X3# )z/Return most frequent color and its usage ratio.T)r  r  )r  r+  r5  rD   r  rG   )r&   r  	allpixelscntpixelr  maxpixels   &&     r'   color_topusagePixmap.color_topusage(5  s    	

d4j 8::D ,,Dd,CIIKLEI{ 	 L
 ucUTVV^,--**r)   c                ~    \        \        P                  ! V P                  4      4      pVP                  R8X  d   R# V# )zPixmap Colorspace.r  N)r+  r   r  r   r   )r&   r  s   & r'   r  Pixmap.colorspace75  s1     22499=>77f	r)   c                J   V P                   pVP                   p\        P                  ! V4      '       g   \        R4      hVP	                  4       VP	                  4       8w  d   \        R4      h\        P
                  ! W4\        V4      \        P                  ! R4      4       R# )zCopy bbox from another Pixmap.z'cannot copy pixmap with NULL colorspacez%source and target alpha must be equalN)r   r   r  r   r  fz_copy_pixmap_rectrK  r  )r&   r4  r6  rS  r  s   &&&  r'   r8  Pixmap.copy?5  su    YY(())'22GHH88:(EFF!!"/?/EuGaGabfGghr)   c                X    \         P                  ! V P                  4      p\        V4      # )zMD5 digest of pixmap (bytes).)r   r  r   r  rk  s   & r'   r  Pixmap.digestI5  s"     ""499-Szr)   c                    \         P                  ! V P                  4      '       g   \        R4       R# \         P                  ! V P                  V4       R# )z5Apply correction with some float.
gamma=1 is a no-op.zcolorspace invalid for functionN)r   r  r   r  fz_gamma_pixmap)r&   gammas   &&r'   
gamma_withPixmap.gamma_withO5  s9     ))49955=>tyy%0r)   c                B    \         P                  ! V P                  4      # )zThe height.)r   r  r   r-   s   &r'   r"  Pixmap.hW5  r1  r)   c                .   V P                   p\        P                  ! V4      P                  '       g   \	        R4       R# \        V4      p\        P                  ! V4      '       d   \        P                  ! V4       R# \        P                  ! W#4       R# )z Invert the colors inside a bbox.zignored for stencil pixmapFT)	r   r   r  r   r  rK  rL  fz_invert_pixmapfz_invert_pixmap_rect)r&   r6  rS  r$  s   &&  r'   invert_irectPixmap.invert_irect\5  sk    YY))"-88889T"%%a((""2&##B*r)   c                X    \         P                  ! V P                  4      p\        V4      # )zPixmap bbox - an IRect object.)r   fz_pixmap_bboxr   JM_py_from_irectr  s   & r'   r  Pixmap.irecti5  s#     ""499-%%r)   c                B    \         P                  ! V P                  4      # )zCheck if pixmap is monochrome.)r   fz_is_pixmap_monochromer   r-   s   &r'   is_monochromePixmap.is_monochromeo5  s     ,,dii88r)   c                   V P                   pVP                  4       pVP                  4       VP                  4       ,          V,          pR p\	        ^ W24       F)  pV^ 8X  d   V! V^ V4      pK  V! WV4      pVX8w  g   K(   R# 	  R# )z%
Check if pixmap has only one color.
c                    \        4       p\        V4       F/  pVP                  \        P                  ! WV,           4      4       K1  	  V# r+   )r   rS  ro   r   r  )rS  offsetrG   rI   rg  s   &&&  r'   _pixmap_read_samples0Pixmap.is_unicolor.<locals>._pixmap_read_samples|5  s7    &C1X

5//1H=> Jr)   FT)r   rG   r   r"  rS  )r&   rS  rG   r  r\  r[  sample0samples   &       r'   is_unicolorPixmap.is_unicolort5  s{    
 YYDDF!#	
 Q)F{.Aq9-r1=W$  * r)   c                    \         '       d*   R p\        V4      V P                  n        V P                  # \        P
                  ! V P                  4      # )zThe size of one pixel.c                B    \         P                  ! V P                  4      # r+   )r   pixmap_nr   r-   s   &r'   n2Pixmap.n.<locals>.n25  s    ~~dii00r)   )r  r{  r
  rG   r   fz_pixmap_componentsr   )r&   re  s   & r'   rG   Pixmap.n5  s<     ;1'|DNN66M))$))44r)   c                   \        V4      p\        P                  ! 4       pW%n        V'       d   VP	                  V4       V'       d   VP                  V4       V P                  p\        V\        4      '       d   \        P                  ! Wa^ V4       R# \        V4      p \        P                  ! WvV4       VP                  4        R#   TP                  4        i ; i)z$
Save pixmap as an OCR-ed PDF page.
N)get_tessdatar   FzPdfocrOptionsr  language_set2datadir_set2r   r@   r  fz_save_pixmap_as_pdfocrrC	  fz_write_pixmap_as_pdfocrrE	  )r&   rj   r  rI  tessdatarU  r  rF	  s   &&&&&   r'   pdfocr_savePixmap.pdfocr_save5  s      )$$& )x(iih$$**C1dC'2C&//4@##%##%s   !C
 
Cc                x    \        V4      p^ RIHp V! 4       pV P                  WQW#R7       VP	                  4       # )a^  Save pixmap as an OCR-ed PDF page.

Args:
    compress: (bool) compress, default 1 (True).
    language: (str) language(s) occurring on page, default "eng" (English),
            multiples like "eng+ger" for English and German.
    tessdata: (str) folder name of Tesseract's language support. If None
            we use environment variable TESSDATA_PREFIX or search for
            Tesseract installation.
Notes:
    On failure, make sure Tesseract is installed and you have set
    <tessdata> or environment variable "TESSDATA_PREFIX" to the folder
    containing your Tesseract's language support data.
r  )r  rI  rp  )rj  r;   r  rq  r  )r&   r  rI  rp  r  r  s   &&&&  r'   pdfocr_tobytesPixmap.pdfocr_tobytes5  s7      )i(V||~r)   c                    ^ RI Hp T P                  pT'       g   RpMRTP
                  ^8X  d   T P                  '       g   RMRpM*TP
                  ^8X  d   T P                  '       g   RMRpMRpTP                  Y0P                  T P                  3T P                  4      pT#   \         d    \        R4       h i ; i)z&Create a Pillow Image from the Pixmap.)r  zPIL/Pillow not installedr`  LAr7  RGBAr8  )PILr  rY  rv   r  rG   r  	frombytesr  r3  r  )r&   r  cspacer   r2  s   &    r'   	pil_imagePixmap.pil_image5  s    	!
 DXX]"jjj3dDXX] $


5DDoodZZ$=t||L
  	./	s   B% %B=c                    V P                  4       pRVP                  4       9  d   V P                  V P                  3VR&   VP                  ! V/ VB  R# )a  Write to image file using Pillow.

An intermediate PIL Image is created, and its "save" method is used
to store the image. See Pillow documentation to learn about the
meaning of possible positional and keyword parameters.
Use this when other output formats are desired.
r  N)r|  r  r  r  r"  )r&   r  r  r2  s   &*, r'   pil_savePixmap.pil_save5  sE     nn%!YY		2F5M$!&!r)   c                    \         P                  ! 4       pV P                  4       pRVP                  4       9  d   V P                  V P
                  3VR&   VP                  ! V.VO5/ VB  VP                  4       # )a  Convert to an image in memory using Pillow.

An intermediate PIL Image is created, and its "save" method is used
to store the image. See Pillow documentation to learn about the
meaning of possible positional or keyword parameters.
Use this when other output formats are desired.
r  )r;   r  r|  r  r  r  r"  r  )r&   r  r  	bytes_outr2  s   &*,  r'   pil_tobytesPixmap.pil_tobytes5  sd     JJL	nn%!YY		2F5M,T,V,!!##r)   c                0   \         '       d,   \        P                  ! V P                  P                  W4      #  V^ 8  gP   WP                  P                  P
                  8  g,   V^ 8  g%   W P                  P                  P                  8  d   \        \        \        4       V P                  P                  P                  pV P                  P                  P                  pWB,          W1,          ,           p\        V P                  WUV,            4      pV# )zPGet color tuple of pixel (x, y).
Last item is the alpha if Pixmap.alpha is true.)r  r   pixmap_pixelr   r   r   r"  r  MSG_PIXEL_OUTSIDEr	  rG   r  r   
samples_mv)r&   ri  rj  rG   r  rg  rI   s   &&&    r'   r:  Pixmap.pixel5  s     ;%%dii&:&:AAAq5		,,...q5		,,...%'78II  ""%%,,JT__a1-.
r)   c                   V ^8  d   QhRR/# )r  rs  r  r,   )r  s   "r'   r  Pixmap.__annotate__	6  s      u r)   c                	0    V P                   p\        V4      # r+   )r  r  )r&   mvs   & r'   r  Pixmap.samples6  s    __bzr)   c                    V P                   f&   \        P                  ! V P                  4      V n         V P                   # )z
Pixmap samples memoryview.
)r  r   r  r   r-   s   &r'   r  Pixmap.samples_mv6  s3     #$AA$))LDr)   c                	b    V P                   '       d   V P                   P                  4        R # R # r+   r  releaser-   s   &r'   _samples_mv_releasePixmap._samples_mv_release6  %    $$& r)   c                	B    \         P                  ! V P                  4      # r+   )r   fz_pixmap_samples_intr   r-   s   &r'   samples_ptrPixmap.samples_ptr6  s    **49955r)   c                   R^R^R^R^R^R^R^R^R	^R
^/
p\        V4      \        J d   M<\        VR4      '       d   \        V4      pM\        VR4      '       d   VP                  pVf+   \        P
                  P                  V4      w  rVVR,          pVP                  VP                  4       R4      pVf)   \        RV R\        VP                  4       4       24      hV P                  '       d   VR9   d   \        RV R24      hV P                  '       d2   V P                  P                  ^8  d   VR9   d   \        RV R24      hV^8X  d'   V P                  V P                   V P"                  4       V P%                  WV4      # )zOutput as image in format determined by filename extension.

Args:
    output: (str) only use to overrule filename extension. Default is PNG.
            Others are JPEG, JPG, PNM, PGM, PPM, PBM, PAM, PSD, PS.
r  pnmpgmppmpbmpampsdpsjpgjpegr  r   Nr	  Image format  not in r   z' cannot have alphaunsupported colorspace for 'r  r     r  r  r  )r   r  r=   r   rh   r   splitextr:   r  r   r   r  r  r  rG   r  r  r  r)  )r&   rj   r4
  r  valid_formatsr@  r  r  s   &&&&    r'   r"  Pixmap.save"6  sk    qqqqqqqaq >S Xz**8}HXv&&}}H>WW%%h/FAWF5;}VHHU=CUCUCW=X<YZ[[:::#*q(;<==???t0014	9I;F81EFF!8LLDII.~~h[99r)   c                   V P                   p^ p^ pVP                  4       ^ 8X  d   \        \        4      h\        P
                  ! V4      p\        P                  ! V4      p	\        P                  ! V4      p
W,          V^,           ,          p. ROp. ROp^ p^ pV'       dM   \        V\        \        34      '       d1   \        V4      V8X  d!   \        V4       F  pVV,          VV&   K  	  ^pV'       dM   \        V\        \        34      '       d1   \        V4      V8X  d!   \        V4       F  pVV,          VV&   K  	  ^p\        4       p^ pV'       dV   \        V\        \        34      '       d   Tp\        V4      pMQ R\        T4       24       hVW,          8  d   \        R4      h \        P                   ! VVVV\        P"                  ! V4      VP$                  VVVV4
       R# )aq  Set alpha channel to values contained in a byte array.
If omitted, set alphas to 255.

Args:
    alphavalues: (bytes) with length (width * height) or 'None'.
    premultiply: (bool, True) premultiply colors with alpha values.
    opaque: (tuple, length colorspace.n) this color receives opacity 0.
    matte: (tuple, length colorspace.n)) preblending background color.
z!unexpected type for alphavalues: zbad alpha valuesNrx   rx   rx   rx   )r   r  r   r  r   r  r  r  r@   r   r   r9   rS  r  r  r   Pixmap_set_alpha_helperr  r   r  r  )r&   alphavaluespremultiplyopaquematter  r  r  rG   r   r"  balenr  r  zero_outbgroundrg  r  data_lenr  r  data_fix	fz_mul255s   &&&&&                  r'   	set_alphaPixmap.set_alphaK6  s    ii99;!o..%%c*!!#&""3'1j$77CK1<L1X"1Iq	 HZ663u:?1X"1X
 Gw +y'9::"{+Q=d;>O=PQQq!% "455)),,d3NNr)   c                   R^R^R^R^R^R^R^R^R	^R
^R^R^/pVP                  VP                  4       R4      pVf)   \        RV R\        VP	                  4       4       24      hV P
                  '       d   VR9   d   \        R4      hV P                  '       d2   V P                  P                  ^8  d   VR9   d   \        RV R24      hV^8X  d'   V P                  V P                  V P                  4       V P                  WB4      pV# )z1
Convert to binary image stream of desired type.
r  r  r  r  r  r  tgatpicr  r  r  r  Nr  r  z'{output}' cannot have alphar  r   r  r  )r:   r  r   r   r  r  r  rG   r  r  r  r   )r&   r4
  r  r  r  r  s   &&&   r'   r  Pixmap.tobytes6  s   
 qqqqqqqqaq 5;}VHHU=CUCUCW=X<YZ[[:::#*;<<???t0014	9I;F81EFF!8LLDII.s0r)   c                ^    V P                   pWP                  n        W#P                  n        R# )z"Set resolution in both dimensions.N)r   r   r  r  )r&   r  r  rS  s   &&& r'   r  Pixmap.set_dpi6  s    YY!!r)   c                ^    V P                   pWP                  n        W#P                  n        R# )zSet top-left coordinates.N)r   r   ri  rj  )r&   ri  rj  rS  s   &&& r'   
set_originPixmap.set_origin6  s    YYr)   c                   \         '       d-   \        P                  ! V P                  P                  WV4      # V P                  p\        V^ VP                  4       ^,
          4      '       d)   \        V^ VP                  4       ^,
          4      '       g   \        \        4      hVP                  4       p\        V4       F-  pW6,          p\        V^ ^4      '       d   K   \        \        4      h	  \        P                  ! V4      pW,          WQ,          ,           p \        T4       F!  pTP#                  Yv,           Y6,          4       K#  	  R# )zSet color of pixel (x, y).N)r  r   	set_pixelr   r   r  r   r"  r   r  rG   rS  MSG_BAD_COLOR_SEQr   r  r  r  r  )	r&   ri  rj  rp  rS  rG   r  rg  r  s	   &&&&     r'   r  Pixmap.set_pixel6  s    ;??499#7#7uEEYY1bddfqj))!Q
1K1K/00DDFqAAAq#&& "344  '',J 1X!!!%2 r)   c                    V P                   pVP                  4       p. p\        V4       F>  pW&,          p\        V^ ^4      '       g   \	        \
        4      hVP                  V4       K@  	  \        V4      p\        W5V4      p\        V4      pV# )z Set color of all pixels in bbox.)
r   rG   rS  r  r   r  ro   rK  JM_fill_pixmap_rect_with_colorr   )	r&   r6  rp  rS  rG   r  r  rg  r   s	   &&&      r'   r  Pixmap.set_rect6  s|    YYDDFqAAAq#&& "344HHQK	 
  %*2$7!W	r)   c                    V^8  d   \        R4       R# \        P                  ! V P                  V4       RV n        V P                  4        R# )z_Divide width and height by 2**factor.
E.g. factor=1 shrinks to 25% of original size (in place).zignoring shrink factor < 1N)r  r   fz_subsample_pixmapr   r  r  )r&   factors   &&r'   shrinkPixmap.shrink6  s?     A:89!!499f5   "r)   c                B    \         P                  ! V P                  4      # )zPixmap size.)r   fz_pixmap_sizer   r-   s   &r'   r  Pixmap.size7  s     $$dii00r)   c                6    V P                   P                  4       # )z%Length of one image line (width * n).)r   r  r-   s   &r'   r  Pixmap.stride7  s     yy!!r)   c                    V P                   '       d   V P                   P                  ^8  d   \        R4       R# \        P                  ! V P
                  W4      # )z/Tint colors with modifiers for black and white.z(warning: colorspace invalid for functionN)r  rG   rv   r   fz_tint_pixmapr   )r&   blackwhites   &&&r'   	tint_withPixmap.tint_with7  s?    $//"3"3a"7>?##TYY==r)   c                B    \         P                  ! V P                  4      # )z
The width.)r   r  r   r-   s   &r'   r   Pixmap.w7  rB  r)   c                   VP                   '       g   \        R4      h\        V4      pVP                  VP                  VP
                  VP                  .p\        P                  ! V P                  WRV4      p\        V4      # )z!Return pixmap from a warped quad.zquad must be convex)	is_convexr   r_  r  r  r  r  r   fz_warp_pixmapr   r  )r&   rM  r  r3  rc  rI  r  s   &&&&   r'   warpPixmap.warp7  s`    ~~~Z0E%FFD!44qttQTT*""DIIvfEs|r)   c                B    \         P                  ! V P                  4      # )zx component of Pixmap origin.)r   fz_pixmap_xr   r-   s   &r'   ri  Pixmap.x%7         ++r)   c                6    V P                   P                  4       # )zResolution in x direction.)r   r  r-   s   &r'   r  Pixmap.xres*7       yy~~r)   c                B    \         P                  ! V P                  4      # )zy component of Pixmap origin.)r   fz_pixmap_yr   r-   s   &r'   rj  Pixmap.y/7  r  r)   c                6    V P                   P                  4       # )zResolution in y direction.)r   r  r-   s   &r'   r  Pixmap.yres47  r  r)   c                	b    V P                   '       d   V P                   P                  4        R # R # r+   r  r-   s   &r'   r[  Pixmap.__del__<7  r  r)   )r  r  r   r<  r   r+   )r  NN)TengN)N_   )Nr  NN)r  r  )7r/   r0   r1   r2   r   r  r   r   r)  r{  r  r  r5  r<  r  r8  r  rH  r"  rO  r  rW  r`  rG   rq  rt  r|  r  r  r:  r  r  r  r  r"  r  r  r  r  r  r  r  r  r  r  r   r  ri  r  rj  r  r  r3  r[  r3   r,   r)   r'   r  r  3  s   V#pC*F 0 0V+  i  
1 1 1 & &
 9 9  * 
5 
5&***"$"$   
  
 ' 6 6':R]~<"32	# 1 1 " "> 0 0 , ,     , ,     EF'r)   r  c                      ] tR tRtR tR tR tR tR tR t	RR	R
R	/R lt
R tR tR tR tR tR tR tR tR t]R 4       tR tR t]R 4       t]t]tRtR	# )r)  iA7  c                	    \         P                  ! V P                  V P                  ,          V P                  V P                  ,          ,           4      # r+   )r  r  ri  rj  r-   s   &r'   r  Point.__abs__C7  s.    yy$&&466DFF?:;;r)   c                	0   \        VR 4      '       d/   \        V P                  V,           V P                  V,           4      # \	        V4      ^8w  d   \        R4      h\        V P                  V^ ,          ,           V P                  V^,          ,           4      # r  Point: bad seq lenr=   r)  ri  rj  r9   r   r&   r  s   &&r'   r  Point.__add__F7  h    1k""!TVVaZ00q6Q;122TVVad]DFFQqTM22r)   c                	f    \        V 4      \        V 4      u;8H  ;'       d    ^ 8H  '       * # u '       * # ru  r  r-   s   &r'   r   Point.__bool__M7  r  r)   c                	p    \        VR 4      '       g   R# \        V4      ^8H  ;'       d    W,
          '       * # r  r  r  s   &&r'   r  Point.__eq__P7  s,    q)$$1v{--DH~-r)   c                	@    V P                   V P                  3V,          # r+   ri  rj  r  s   &&r'   r  Point.__getitem__U7  s    ""r)   c                	*    \        \        V 4      4      # r+   rS  r   r-   s   &r'   rT  Point.__hash__X7      E$K  r)   ri  Nrj  c                  V'       g   RV n         RV n        EM8\        V4      ^8  d   \        R4      h\        V4      ^8X  d0   \	        V^ ,          4      V n         \	        V^,          4      V n        M\        V4      ^8X  d   V^ ,          p\        V\        P                  \        P                  34      '       d$   VP                   V n         VP                  V n        Mr\        VR4      '       g   \        R4      h\        V4      ^8w  d   \        R4      h\	        V^ ,          4      V n         \	        V^,          4      V n        M\        R4      hVe   Wn         Ve	   W n        R# R# )z
Point() - all zeros
Point(x, y)
Point(Point) - new copy
Point(sequence) - from 'sequence'

Explicit keyword args x, y override earlier settings if not None.
r  r  r  zPoint: bad argsN)
ri  rj  r9   r   r  r@   r   rg  fz_pointr=   )r&   ri  rj  r  rX  s   &$$* r'   r   Point.__init__[7  s    DFDFY]122Y!^47^DF47^DFY!^QA!emmU^^<==q-00$%677q6Q;$%9::qtqt122=QF=QF=r)   c                	    ^# r  r,   r-   s   &r'   r  Point.__len__}7  r  r)   c                	p   \        VR 4      '       d/   \        V P                  V,          V P                  V,          4      # \        VR4      '       dJ   \	        V4      ^8X  d:   V P                  V^ ,          ,          V P                  V^,          ,          ,           # \        V 4      pVP                  V4      # )r  r  )r=   r)  ri  rj  r9   r  )r&   r  r  s   && r'   r  Point.__mul__7  s}    1k""!TVVaZ001m$$Q166AaD=466AaD=00$K{{1~r)   c                	F    \        V P                  ) V P                  ) 4      # r+   )r)  ri  rj  r-   s   &r'   r  Point.__neg__7  s    dffWtvvg&&r)   c                	f    \        V 4      \        V 4      u;8H  ;'       d    ^ 8H  '       * # u '       * # ru  r  r-   s   &r'   r  Point.__nonzero__7  r  r)   c                	    \        V 4      # r+   r)  r-   s   &r'   r  Point.__pos__7  rq  r)   c                	8    R \        \        V 4      4      ,           # r  r  r-   s   &r'   r   Point.__repr__7      U4[)))r)   c                	j    \        V4      pV^ 8X  d	   W n        R# V^8X  d	   W n        R# \        R4      hr"  )r  ri  rj  r  r#  s   &&&r'   r$  Point.__setitem__7  s;    !H!VaV  !VaV  122r)   c                	0   \        VR 4      '       d/   \        V P                  V,
          V P                  V,
          4      # \	        V4      ^8w  d   \        R4      h\        V P                  V^ ,          ,
          V P                  V^,          ,
          4      # r  r  r  s   &&r'   r'  Point.__sub__7  r  r)   c                	    \        VR 4      '       d=   \        V P                  R,          V,          V P                  R,          V,          4      # \	        V4      ^,          pV'       g   \        R4      h\        V 4      pVP                  V4      # r*  )r=   r)  ri  rj  r+  r,  r  )r&   r  r  r  s   &&  r'   r.  Point.__truediv__7  si    1k"""QA66"1%#$;<<$K{{2r)   c                Z   V P                   V P                   ,          V P                  V P                  ,          ,           pV\        8  d   \        ^ ^ 4      # \        P
                  ! V4      p\        \        V P                   4      V,          \        V P                  4      V,          4      # )z&Unit vector with positive coordinates.)ri  rj  r8  r)  r  r  r,  r&   r  s   & r'   abs_unitPoint.abs_unit7  sk     FFTVVOdfftvvo-w;1:IIaLS[1_c$&&kAo66r)   c                   \        V4      ^ 8  g   \        R4      hV^ ,          p\        V4      ^8X  d   \        V4      pM'\        V4      ^8X  d   \        V4      pM\        R4      h\        V4      ^8  d   V^,          pMRpRRRR	RR
RR/pWC,          ^ ,          WC,          ^,          ,          p\	        V4      \        J d   \        W,
          4      V,          # \        VP                  VP                  4      pWbP                  ,          pW9   d   R# V P                  VP                  8  d   V P                  VP                  8  d   V P                  VP                  V4      # V P                  VP                  8:  d   V P                  VP                  V4      # V P                  VP                  ,
          V,          # VP                  V P                  u;8:  d   VP                  8:  dg   M McV P                  VP                  8  d%   V P                  VP                  ,
          V,          # VP                  V P                  ,
          V,          # V P                  VP                  8  d   V P                  VP                   V4      # V P                  VP                  8:  d   V P                  VP                  V4      # VP                  V P                  ,
          V,          # )z.Return distance to rectangle or another point.z$at least one parameter must be givenz$arg1 must be point-like or rect-liker  incmmmr  )r  r  r        R@gRQ@r*  gffffff9@r*  )r9   r   r)  r+  r   r,  top_leftbottom_rightri  r  rj  r  distance_tor  	top_rightr  bottom_left)r&   r  ri  unitur  r$  s   &*     r'   r/  Point.distance_to7  s   4y1}CDDGq6Q;aAVq[QACDDt9q=7DD7D(D+; GAJ#7etx=1$$ QZZ(966ADD=vv~''==144''T::**TTTVV#qtt#vv~**tvv**vv~''t<<144''

D99tvv**r)   c                l    \        V4      ^8w  d   \        R4      h\        W4      w  V n        V n        V # )z7Replace point by its transformation with matrix-like m.r  )r9   r   util_transform_pointri  rj  r  s   &&r'   r  Point.transform7  s0    q6Q;233-d6r)   c                6   V P                   V P                   ,          V P                  V P                  ,          ,           pV\        8  d   \        ^ ^ 4      # \        P
                  ! V4      p\        V P                   V,          V P                  V,          4      # )zUnit vector of the point.)ri  rj  r8  r)  r  r  r"  s   & r'   r2  
Point.unit7  sc     FFTVVOdfftvvo-w;1:IIaLTVVaZ!,,r)   r  )r/   r0   r1   r2   r  r  r   r  r  rT  r   r  r  r  r  r  r   r$  r'  r.  r{  r#  r/  r  r2  rN  rO  r3   r,   r)   r'   r)  r)  A7  s    <31.
#! '  '  'D'1*3 7 70+d - - GDr)   r)  c                     ] tR tRtR tR tR tR tR tR t	R t
R	R
RR
RR
RR
/R ltR tR tR tR tR tR tR tR tR t]R 4       t]R 4       t]R 4       t]R 4       tR t]R 4       tR t]t]! R 4      t]! R  4      tR!t R
# )"r)  i7  c                	    V P                   '       d   R # \        V P                  V P                  ,
          4      \        V P                  V P                  ,
          4      ,          # r  )r  r,  r  r  r  r-   s   &r'   r  Quad.__abs__7  s=    ===477TWW$%DGGdgg,=(>>>r)   c                	   \        VR 4      '       dS   \        V P                  V,           V P                  V,           V P                  V,           V P
                  V,           4      # \        V4      ^8w  d   \        R4      h\        V P                  V^ ,          ,           V P                  V^,          ,           V P                  V^,          ,           V P
                  V^,          ,           4      # r  Quad: bad seq lenr=   r)  r  r  r  r  r9   r   r&   rc  s   &&r'   r  Quad.__add__8      1k""!TWWq[$''A+tww{KKq6Q;011DGGadNDGGadNDGGadNDGGaPQdNSSr)   c                	$    V P                   '       * # r+   r  r-   s   &r'   r   Quad.__bool__
8      ==  r)   c                	    VP                  4       pT^8X  d   \	        Y4      # T^8w  d   R# \        T4      '       dL   \        T4      P                  '       d   R# \	        TR,          T 4      ;'       d    \	        TR,          T 4      # \        T4      '       d0   \        ^4       F  p\	        Y,          T 4      '       d   K   R# 	  R# R#   \         d    \        ^8  d   \        4         R# i ; i)r  FTr  r+  )
r  rk   r  r{   util_point_in_quad	CheckRectr+  r  	CheckQuadrS  )r&   ri  rX  rg  s   &&  r'   r|  Quad.__contains__8  s    			A 6%a..6Q<<Aw%aeT2VV7I!B%QU7VVQ<<1X)!$55   !  	#a'N,<	s   C  C/.C/c                	6   \        VR 4      '       g   R# \        V4      ^8H  ;'       dq    V P                  V^ ,          8H  ;'       dS    V P                  V^,          8H  ;'       d5    V P                  V^,          8H  ;'       d    V P
                  V^,          8H  # r  )r=   r9   r  r  r  r  )r&   rM  s   &&r'   r  Quad.__eq__"8  s    tY''4yA~ 
 
GGtAw  GGtAw GGtAw  GGtAw		
r)   c                	l    V P                   V P                  V P                  V P                  3V,          # r+   )r  r  r  r  r  s   &&r'   r  Quad.__getitem__,8  &    $''4773A66r)   c                	*    \        \        V 4      4      # r+   r  r-   s   &r'   rT  Quad.__hash__/8  r  r)   r  Nr  r  r  c                  V'       g'   \        4       ;V n        ;V n        ;V n        V n        EMn\        V4      ^8  d   \        R4      h\        V4      ^8X  d,   \        \         V4      w  V n        V n        V n        V n        EM\        V4      ^8X  d   V^ ,          p\        V\        P                  4      '       ds   W`n        \        VP                  4      \        VP                  4      \        VP                  4      \        VP                  4      3w  V n        V n        V n        V n        Mm\        VR4      '       g   \        R4      h\        V4      ^8w  d   \        R4      h\        \         V4      w  V n        V n        V n        V n        M\        R4      hVe   \        V4      V n        Ve   \        V4      V n        Ve   \        V4      V n        Ve   \        V4      V n        R# R# )z
Quad() - all zero points
Quad(ul, ur, ll, lr)
Quad(quad) - new copy
Quad(sequence) - from 'sequence'

Explicit keyword args ul, ur, ll, lr override earlier settings if not
None.

r@  r  zQuad: bad argsN)r)  r  r  r  r  r9   r   r  r@   r   FzQuadr   r=   )r&   r  r  r  r  r  rX  s   &$$$$* r'   r   Quad.__init__28  sk    49G;DG;dg;$'Y]011Y!^14UD1A.DGTWdgtwY!^QA!U\\**	5:144[%+uUVUYUY{\abcbfbf\g5g2$'47Q.. !122Q1 !45558]2$'47-..>eBiDG>eBiDG>eBiDG>eBiDG>r)   c                	    ^# r  r,   r-   s   &r'   r  Quad.__len__U8  r  r)   c                	>    \        V 4      pVP                  V4      pV# r+   )r)  r  )r&   r  rc  s   && r'   r  Quad.__mul__X8  s    JKKNr)   c                	v    \        V P                  ) V P                  ) V P                  ) V P                  ) 4      # r+   )r)  r  r  r  r  r-   s   &r'   r  Quad.__neg__]8  +    TWWHtwwh477(;;r)   c                	$    V P                   '       * # r+   rF  r-   s   &r'   r  Quad.__nonzero__`8  rH  r)   c                	    \        V 4      # r+   r)  r-   s   &r'   r  Quad.__pos__c8      Dzr)   c                	8    R \        \        V 4      4      ,           # rc  r  r-   s   &r'   r   Quad.__repr__f8      E$K(((r)   c                	    V^ 8X  d   \        V4      V n        R# V^8X  d   \        V4      V n        R# V^8X  d   \        V4      V n        R# V^8X  d   \        V4      V n        R# \        R4      hr"  )r)  r  r  r  r  r  r#  s   &&&r'   r$  Quad.__setitem__i8  sn    !VuQxTW  !VuQxTW
 	 !VuQxTW  !VuQxTW  122r)   c                	   \        VR 4      '       dS   \        V P                  V,
          V P                  V,
          V P                  V,
          V P
                  V,
          4      # \        V4      ^8w  d   \        R4      h\        V P                  V^ ,          ,
          V P                  V^,          ,
          V P                  V^,          ,
          V P
                  V^,          ,
          4      # r?  rA  rB  s   &&r'   r'  Quad.__sub__r8  rD  r)   c                	    \        VR 4      '       d   RV,          pM%\        V4      ^,          pV'       g   \        R4      h\        V 4      pVP	                  V4      pV# )r  r  zMatrix not invertible)r=   r+  r,  r)  r  )r&   r  r  rc  s   &&  r'   r.  Quad.__truediv__y8  sQ    1k""aB#A&q)B'(?@@JKKOr)   c                   \        V P                  V P                  4      pV P                  V,          pV P                  V,          pVP
                  VP
                  ,          ^ 8  d   R# \        V P                  V P                  4      pV P                  V,          pV P                  V,          pVP
                  VP
                  ,          ^ 8  d   R# R# )zCheck if quad is convex and not degenerate.

Notes:
    Check that for the two diagonals, the other two corners are not
    on the same side of the diagonal.
Returns:
    True or False.
FT)planish_liner  r  r  r  rj  )r&   r  rJ  rK  s   &   r'   r  Quad.is_convex8  s     $''*WWq[WWq[44"$$;?$''*WWq[WWq[44"$$;?r)   c                ^    V P                   \        8  ;'       g    V P                  \        8  # )zcCheck whether all quad corners are on the same line.

This is the case if width or height is zero.
)r  r8  r3  r-   s   &r'   r  Quad.is_empty8  s$     zzG#<<t{{W'<<r)   c                .    V P                   P                  # )z(Check whether this is the infinite quad.)r   r  r-   s   &r'   r  Quad.is_infinite8  s     yy$$$r)   c                   \        V P                  V P                  V P                  4      p\	        V^,
          4      \
        8  d   R# \        V P                  V P                  V P                  4      p\	        V^,
          4      \
        8  d   R# \        V P                  V P                  V P                  4      p\	        V^,
          4      \
        8  d   R# R# )zCheck if quad is rectangular.

Notes:
    Some rotation matrix can thus transform it into a rectangle.
    This is equivalent to three corners enclose 90 degrees.
Returns:
    True or False.
FT)util_sine_betweenr  r  r  r,  r8  r  )r&   sines   & r'   is_rectangularQuad.is_rectangular8  s     !$''477;tax=7" $''477;tax=7" $''477;tax=7"r)   c                    V P                   '       d   \        4       # \        ^^4      P                  VP                  VP
                  4      pW( ,          V,          V,          pV# )zKMorph the quad with matrix-like 'm' and point-like 'p'.

Return a new quad.)r  INFINITE_QUADr  rK  ri  rj  )r&   r  r  deltarc  s   &&&  r'   r-  
Quad.morph8  sP      ?"q!))!##qss36MA%r)   c                	2   \        4       p\        V P                  P                  V P                  P                  V P
                  P                  V P                  P                  4      Vn        \        V P                  P                  V P                  P                  V P
                  P                  V P                  P                  4      Vn	        \        V P                  P                  V P                  P                  V P
                  P                  V P                  P                  4      Vn        \        V P                  P                  V P                  P                  V P
                  P                  V P                  P                  4      Vn        V# r+   )r+  r  r  ri  r  r  r  r  rj  r  r'  r  r  r&   r$  s   & r'   r   	Quad.rect8  s    F47799dggiiDGGII>47799dggiiDGGII>47799dggiiDGGII>47799dggiiDGGII>r)   c                *   \        VR4      '       d   M\        V4      ^8w  d   \        R4      hV ;P                  V,          un        V ;P                  V,          un        V ;P
                  V,          un        V ;P                  V,          un        V # )z1Replace quad by its transformation with matrix m.r  r  )r=   r9   r   r  r  r  r  r  s   &&r'   r  Quad.transform8  sb    1k""Vq[2331111r)   c                	    \        \        V P                  V P                  ,
          4      \        V P                  V P
                  ,
          4      4      # r+   )r'  r,  r  r  r  r  r-   s   &r'   r
  Quad.<lambda>8  /    3s477TWW+<'=s477TWWCT?U#Vr)   c                	    \        \        V P                  V P                  ,
          4      \        V P                  V P
                  ,
          4      4      # r+   )r'  r,  r  r  r  r  r-   s   &r'   r
  r  8  r  r)   )r  r  r   r  r  )!r/   r0   r1   r2   r  r  r   r|  r  r  rT  r   r  r  r  r  r  r   r$  r'  r.  r{  r  r  r  ry  r-  r   r  rN  r  r3  r3   r,   r)   r'   r)  r)  7  s   ?
T!*
7!!0 !0$ !04 !0D !0F
<!)T	  * = = % %  0  
 GVWEVWFr)   r)  c                     ] tR tRtR tR tR tR tR tR t	R t
R	 tR
RRRRRRRRRRR/R ltR tR tR tR tR tR tR tR tR tR t]R 4       t]R 4       tR t]R 4       tR  R! ltR" tR# tR$ tR% t ]R& 4       t!]R' 4       t"]R( 4       t#R) t$R* t%R+ t&]R, 4       t'R- t(]R. 4       t)]R/ 4       t*R0 t+R1 t,]R2 4       t-]t.]t/]t0]! ](4      t1])t2]*t3R3t4R# )4r+  i8  c                	    V P                   '       g   V P                  '       d   R # V P                  V P                  ,
          V P                  V P
                  ,
          ,          # r<  )r  r  r  r  r  r  r-   s   &r'   r  Rect.__abs__8  s>    ===D,,,$''!dgg&788r)   c                	   \        VR 4      '       dS   \        V P                  V,           V P                  V,           V P                  V,           V P
                  V,           4      # \        V4      ^8w  d   \        R4      h\        V P                  V^ ,          ,           V P                  V^,          ,           V P                  V^,          ,           V P
                  V^,          ,           4      # r  Rect: bad seq lenr=   r+  r  r  r  r  r9   r   r  s   &&r'   r  Rect.__add__8  rD  r)   c                	    \        VR 4      '       g   \        R4      h\        V4      p\        V 4      pVP                  V4      # r  zbad operand 2)r=   r   r+  	intersect)r&   ri  r  r$  s   &&  r'   __and__Rect.__and__8  s:    q)$$_--!WJ{{2r)   c                	f    \        V 4      \        V 4      u;8H  ;'       d    ^ 8H  '       * # u '       * # ru  r  r-   s   &r'   r   Rect.__bool__8  r  r)   c                	p   \        VR 4      '       d   V\        V 4      9   # \        V4      pV^8X  d   \        W4      # V^8X  d   \	        4       p \        V4      pV P                  VP                  u;8*  ;'       d(    VP                  u;8*  ;'       d    V P                  8*  Mu ;'       dM    V P                  VP                  u;8*  ;'       d(    VP                  u;8*  ;'       d    V P                  8*  # u # R#   \         d.    \        ^8  d   \        4        \        T4      P                  p Li ; i)r  F)r=   r   r9   util_is_point_in_rectINFINITE_RECTr+  rk   r  r{   r)  r   r  r  r  r  )r&   ri  rX  r$  s   &&  r'   r|  Rect.__contains__8  s    1k""d##F6(116A!G GGqtt66qtt66tww6 7 7GGqtt66qtt66tww6868  !'!+0@GLL!s   C= =5D54D5c                	p    \        VR 4      '       g   R# \        V4      ^8H  ;'       d    W,
          '       * # r  r  r  s   &&r'   r  Rect.__eq__9  s-    tY''4yA~33t{"33r)   c                	l    V P                   V P                  V P                  V P                  3V,          # r+   r  r  r  r  r  s   &&r'   r  Rect.__getitem__9  rR  r)   c                	*    \        \        V 4      4      # r+   r  r-   s   &r'   rT  Rect.__hash__9  r  r)   r  NrJ  r  r  r  r  c                   \        VRVRVRVRVRVRV/ w  r4rV\        V4      V n        \        V4      V n        \        V4      V n        \        V4      V n        R# )a  
Rect() - all zeros
Rect(x0, y0, x1, y1)
Rect(top-left, x1, y1)
Rect(x0, y0, bottom-right)
Rect(top-left, bottom-right)
Rect(Rect or IRect) - new copy
Rect(sequence) - from 'sequence'

Explicit keyword args p0, p1, x0, y0, x1, y1 override earlier settings
if not None.
r  rJ  r  r  r  r  N)util_make_rectr  r  r  r  r  r&   r  rJ  r  r  r  r  r  s   &$$$$$$*r'   r   Rect.__init__9  s]     ($Y2Y"YYYrYVXY****r)   c                	    ^# rY  r,   r-   s   &r'   r  Rect.__len__,9  r  r)   c                	   \        VR 4      '       dS   \        V P                  V,          V P                  V,          V P                  V,          V P
                  V,          4      # \        V 4      pVP                  V4      pV# r  )r=   r+  r  r  r  r  r  )r&   r  r$  s   && r'   r  Rect.__mul__/9  s[    1k""!TWWq[$''A+tww{KKJKKNr)   c                	v    \        V P                  ) V P                  ) V P                  ) V P                  ) 4      # r+   )r+  r  r  r  r  r-   s   &r'   r  Rect.__neg__69  r_  r)   c                	f    \        V 4      \        V 4      u;8H  ;'       d    ^ 8H  '       * # u '       * # ru  r  r-   s   &r'   r  Rect.__nonzero__99  r  r)   c                	    \        VR 4      '       g   \        R4      h\        V 4      p\        V4      ^8X  d   VP	                  V4      # \        V4      ^8X  d   VP                  V4      # \        R4      hr  )r=   r   r+  r9   include_pointinclude_rect)r&   ri  r$  s   && r'   __or__Rect.__or__<9  sb    q)$$_--Jq6Q;??1%%q6Q;>>!$$))r)   c                	    \        V 4      # r+   r+  r-   s   &r'   r  Rect.__pos__F9  re  r)   c                	8    R \        \        V 4      4      ,           # r  r  r-   s   &r'   r   Rect.__repr__I9  rh  r)   c                	    \        V4      pV^ 8X  d	   W n        R# V^8X  d	   W n        R# V^8X  d	   W n        R# V^8X  d	   W n        R# \        R4      hr"  )r  r  r  r  r  r  r#  s   &&&r'   r$  Rect.__setitem__L9  s_    !H!VqW  !VqW
 	 !VqW  !VqW  122r)   c                	   \        VR 4      '       dS   \        V P                  V,
          V P                  V,
          V P                  V,
          V P
                  V,
          4      # \        V4      ^8w  d   \        R4      h\        V P                  V^ ,          ,
          V P                  V^,          ,
          V P                  V^,          ,
          V P
                  V^,          ,
          4      # r  r  r  s   &&r'   r'  Rect.__sub__V9  rD  r)   c                	   \        VR 4      '       do   \        V P                  R,          V,          V P                  R,          V,          V P                  R,          V,          V P
                  R,          V,          4      # \        V4      ^,          pV'       g   \        RV 24      h\        V 4      pVP                  V4      pV# )r  r  zMatrix not invertible: )	r=   r+  r  r  r  r  r+  r,  r  )r&   r  r  r$  s   &&  r'   r.  Rect.__truediv__]9  s    1k"""Q"Q"QRTUVWW"1%#&=aS$ABBJKKOr)   c                B    \        V P                  V P                  4      # zBottom-left corner.r)  r  r  r-   s   &r'   r1  Rect.bottom_leftg9       TWWdgg&&r)   c                B    \        V P                  V P                  4      # zBottom-right corner.r)  r  r  r-   s   &r'   r.  Rect.bottom_rightl9  r  r)   c                $    V P                  V4      # )z.Check if containing point-like or rect-like x.r|  r9  s   &&r'   containsRect.containsq9        ##r)   c                	P    \        ^ V P                  V P                  ,
          4      # ru  r'  r  r  r-   s   &r'   r3  Rect.heightu9      1dgg'((r)   c                   V ^8  d   QhRR/# r  rs  r  r,   )r  s   "r'   r  Rect.__annotate__y9       9 9 9r)   c                D    \        V P                  V P                  V4      # zUCalculate area of rectangle.
parameter is one of 'px' (default), 'in', 'cm', or 'mm'.
_rect_arear  r3  r  s   &*r'   get_areaRect.get_areay9      $**dkk488r)   c                    \        V4      ^8w  d   \        R4      h\        W4      w  V n        V n        V n        V n        V # )zExtend to include point-like p.r  )r9   r   util_include_point_in_rectr  r  r  r  r  s   &&r'   r  Rect.include_point}9  s9    q6Q;122-G-P*$'47r)   c                "   \        V4      ^8w  d   \        R4      h\        V4      pVP                  '       g   V P                  '       d2   \        \        \
        \
        3w  V n        V n        V n        V n	        V # VP                  '       d   V # V P                  '       dJ   VP                  VP                  VP                  VP                  3w  V n        V n        V n        V n	        V # \        W4      w  V n        V n        V n        V n	        V # )zExtend to include rect-like r.r  )r9   r   r+  r  r  r  r  r  r  r  r  util_union_rectr  s   &&r'   r  Rect.include_rect9  s    q6Q;011G===D,,,1@/Sbds1s.DGTWdgtw  ZZZK]]]12qttQTT1441G.DGTWdgtw  2A1I.DGTWdgtwr)   c                V   \        V4      ^8X  g   \        R4      h\        V4      pVP                  '       d   V # V P                  '       dJ   VP                  VP
                  VP                  VP                  3w  V n        V n        V n        V n        V # VP                  '       dJ   VP                  VP
                  VP                  VP                  3w  V n        V n        V n        V n        V # V P                  '       d   V # \        W4      w  V n        V n        V n        V n        V # )z)Restrict to common rect with rect-like r.r  )
r9   r   r+  r  r  r  r  r  r  util_intersect_rectr  s   &&r'   r  Rect.intersect9  s    1v{011G===K12qttQTT1441G.DGTWdgtw  ZZZ12qttQTT1441G.DGTWdgtw
 	 ]]]K1DT1M.DGTWdgtwr)   c                   \        V4      p V P                  '       * ;'       d    V P                  '       * ;'       d    VP                  '       * ;'       d    VP                  '       * ;'       d}    V P                  VP                  8  ;'       d\    VP                  V P                  8  ;'       d;    V P
                  VP                  8  ;'       d    VP
                  V P                  8  # )z4Check if intersection with rectangle x is not empty.)r+  r  r  r  r  r  r  )r&   ri  rect2s   && r'   
intersectsRect.intersects9  s    Q'%' '(((' ' &' ' )))	' '
 GGehh&' ' HHtww&' ' GGehh&' ' HHtww&		r)   c                v    V P                   V P                  8  ;'       g    V P                  V P                  8  # z True if rectangle area is empty.r  r  r  r  r-   s   &r'   r  Rect.is_empty9  ,     ww$''!77TWW%77r)   c                    V P                   V P                  u;8H  ;'       d
    \        8H  Mu ;'       d/    V P                  V P                  u;8H  ;'       d
    \
        8H  # u # )z'True if this is the infinite rectangle.r  r  r  r  r  r  r-   s   &r'   r  Rect.is_infinite9  B     ww$''44_4^^DGG9^9^9^^9^^r)   c                v    V P                   V P                  8*  ;'       d    V P                  V P                  8*  # zTrue if rectangle is valid.r  r-   s   &r'   is_validRect.is_valid9  ,     ww$''!88dgg&88r)   c                p    V P                   '       d   \        4       # V P                  P                  W4      # z?Morph with matrix-like m and point-like p.

Returns a new quad.r  r|  rM  r-  r&   r  r  s   &&&r'   r-  
Rect.morph9  +      ?"yyq$$r)   c           	     	v    \         P                  ! \        V  Uu. uF  qV,          NK  	  up4      4      # u upi r+   r  r  s   & r'   rO  	Rect.norm9  r  r  c                    V P                   V P                  8  d$   V P                   V P                  uV n        V n         V P                  V P                  8  d$   V P                  V P                  uV n        V n        V # )z*Replace rectangle with its finite version.r  r-   s   &r'   rs  Rect.normalize9  W    77TWW#wwDGTW77TWW#wwDGTWr)   c                n    \        V P                  V P                  V P                  V P                  4      # z!Return Quad version of rectangle.r)  r*  r  r  r+  r-   s   &r'   rM  	Rect.quad9  %     DGGTWWdggtww77r)   c                *    \        \        V 4      4      # )zReturn the IRect.)r  util_round_rectr-   s   &r'   r  
Rect.round9  s    _T*++r)   c                B    \        V P                  V P                  4      # zTop-left corner.r)  r  r  r-   s   &r'   r-  Rect.top_left9  r  r)   c                B    \        V P                  V P                  4      # zTop-right corner.r)  r  r  r-   s   &r'   r0  Rect.top_right9  r  r)   c           	        \        V4      pV P                  '       g7   V P                  '       g%   VP                  '       g   VP                  '       d   \        R4      h\	        ^^ ^ ^V P
                  ) V P                  ) 4      \	        VP                  V P                  ,          VP                  V P                  ,          4      ,          \	        ^^ ^ ^VP
                  VP                  4      ,          # z+Return matrix that converts to target rect.z'rectangles must be finite and not empty	r+  r  r  r   r  r  r  r  r3  r  s   &&r'   torectRect.torect9  s     Gt}}}FGG1aAx$''2QWWtzz)188dkk+ABCQ1aqtt,-	
r)   c                    \        V4      ^8X  g   \        R4      h\        W4      w  V n        V n        V n        V n        V # )z1Replace with the transformation by matrix-like m.r  )r9   r   util_transform_rectr  r  r  r  r  s   &&r'   r  Rect.transform9  s9    1v{233-@-I*$'47r)   c                	P    \        ^ V P                  V P                  ,
          4      # ru  r'  r  r  r-   s   &r'   r  
Rect.width9  r  r)   r  )5r/   r0   r1   r2   r  r  r  r   r|  r  r  rT  r   r  r  r  r  r  r  r   r$  r'  r.  r{  r1  r.  r  r3  r  r  r  r  r  r  r  r  r-  rO  rs  rM  r  r-  r0  r  r  r  rN  r  r+  r  r*  r  r3   r,   r)   r'   r+  r+  8  s   9
T1"4
7! $ 4 D T d &<1*)T ' ' ' '$ ) )9" 8 8 _ _ 9 9%3 8 8, ' ' ' '

 ) ) G	B	BUOE	B	Br)   r+  c            $         ] tR tRtRt]R 4       tR R ltR tR R lt	R	 R
 lt
R R ltR R ltR R ltR R ltR<R R lltRR/R R lltR R ltR=R R lltR=R R lltR^R RR!R"R#RR$^ R%^ R&RR'RR(^ R)R*R+^R,^ R-RR.^R/^R0^ /R1 R2 lltR3^ R)R*R&RR%^ R4^R/^R'RR#RR!R"R^R RR+^R-RR0^ R(^ R,^ R$^ R.^/R5 R6 lltR>R7 R8 lltR<R9 R: lltR;tR# )?ro  i:  zCreate a new shape.c                h   \        W,
          4      P                  p\        P                  ! \	        VP
                  4      4      pVP                  ^ 8  dF   VP
                  ^ 8:  d   \        P                  V,
          ) pV# \        P                  V,
          p V# VP
                  ^ 8  d    V# V) pV# )zReturn the angle to the horizontal for the connection from C to P.
This uses the arcus sine function and resolves its inherent ambiguity by
looking up in which quadrant vector S = P - C is located.
)r)  r2  r  asinr,  rj  ri  pi)r  r  r
  alfas   &&  r'   horizontal_angleShape.horizontal_angle
:  s     !%LyyQSS"337ssax4(  ww~ 	 ssax  ur)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  Shape.__annotate__:  s      T r)   c                	   \        V4       Wn        VP                  V n        V P                  P                  '       g   \        R 4      hVP                  P                  V n        VP                  P                  V n
        VP                  P                  V n	        VP                  P                  V n        VP                  V n        V P                  ( V n        RV n        RV n        RV n        RV n        RV n        R# )r  r`   N)ro  r   r   r1  r  r   rl  rj  r3  ri  r  r  rt  pctmipctmr   	text_cont	totalcontr  r   r  s   &&r'   r   Shape.__init__:  s    D	;;xx[))((**''))
&&((&&((..	iiZ
	r)   c                	j   V P                   f5   \        V4      ^8X  d   \        W4      V n         R # \        V4      V n         R # \        V4      ^8X  d   \        V4      p\	        V P                   P
                  VP                  4      V P                   n        \	        V P                   P                  VP                  4      V P                   n        \        V P                   P                  VP                  4      V P                   n
        \        V P                   P                  VP                  4      V P                   n        R # \        V4      p\	        V P                   P
                  VP
                  4      V P                   n        \	        V P                   P                  VP                  4      V P                   n        \        V P                   P                  VP                  4      V P                   n
        \        V P                   P                  VP                  4      V P                   n        R # r+   )r   r9   r+  r)  r  r  ri  r  rj  r'  r  r  r9  s   &&r'   
updateRectShape.updateRect2:  s<   991v{ J	 G	 1v{!H"499<<5		"499<<5		"499<<5		"499<<5		G"499<<6		"499<<6		"499<<6		"499<<6		r)   c               $    V ^8  d   QhRRRRRR/# r  rJ  r   rK  rs  r)  r,   )r  s   "r'   r  r$  G:  s!      J J 5 r)   c                   \        V4      p\        V4      pV P                  V8X  gZ   V ;P                  \        \	        WP
                  ,          4      4      R,           ,          un        Wn        V P                  V4       V ;P                  \        \	        W P
                  ,          4      4      R,           ,          un        V P                  V4       W n        V P                  # )zDraw a line between two points. m
 l
)r)  r  r   r   r  r'  r,  )r&   rJ  rK  s   &&&r'   r  Shape.draw_lineG:  s    2Y2Y2%NNijj(ABVKKN OOOB)HR**_$=>GGr)   c                    V ^8  d   QhRRRR/# )r  rI  r   rs  r)  r,   )r  s   "r'   r  r$  U:  s      D U r)   c           
     &   \        V4       F  w  r#V^ 8X  dx   V P                  \        V4      8X  g]   V ;P                  \	        \        \        V4      V P                  ,          4      4      R,           ,          un        \        V4      V n        MLV ;P                  \	        \        \        V4      V P                  ,          4      4      R,           ,          un        V P                  V4       K  	  \        VR,          4      V n        V P                  # )z%Draw several connected line segments.r1  r2  r  )rZ  r  r)  r   r   r  r'  r,  )r&   rI  rg  r  s   &&  r'   r$  Shape.draw_polylineU:  s    f%DAAv583NNiqDJJ9N0O&PSY&YYN&+AhDO)HU1X

5J,K"Lv"UUOOA &  r
+r)   c          
     ,    V ^8  d   QhRRRRRRRRRR/# )r  rJ  r   rK  r  r  rs  r)  r,   )r  s   "r'   r  r$  c:  s<        	
  
r)   c                   \        V4      p\        V4      p\        V4      p\        V4      pV P                  V8X  gC   V ;P                  \        \	        WP
                  ,          4      4      R,           ,          un        \	        \        W P
                  ,          4      \        W0P
                  ,          4      ,           \        W@P
                  ,          4      ,           4      pV ;P                  \        V4      R,           ,          un        V P                  V4       V P                  V4       V P                  V4       V P                  V4       W@n        V P                  # )z#Draw a standard cubic Bezier curve.r1   c
)r)  r  r   r   r  r'  r   r,  )r&   rJ  rK  r  r  r  s   &&&&& r'   r  Shape.draw_bezierc:  s     2Y2Y2Y2Y2%NNijj(ABVKKNR**_-R**_0EERR\R\_H]]^)D/F22r)   c                    V ^8  d   QhRRRR/# )r  tetraz"typing.Union[quad_like, rect_like]rs  r)  r,   )r  s   "r'   r  r$  z:  s      A e r)   c                @   \        V4      ^8w  d   \        R4      h\        V^ ,          R4      '       d   \        V4      P                  pM\        V4      pVP                  VP                  VP                  ,
          R,          ,           pVP                  VP                  VP                  ,
          R,          ,           pVP                  VP                  VP                  ,
          R,          ,           pVP                  VP                  VP                  ,
          R,          ,           pV P                  V8X  gI   V ;P                  \        \        W`P                  ,          4      4      R,           ,          un        W`n
        V P                  WbP                  V4       V P                  WRP                  V4       V P                  WBP                  V4       V P                  W2P                  V4       V P!                  VP"                  4       W`n
        V P                  # )z"Draw an ellipse inside a tetrapod.zinvalid arg lengthr  r  r1  )r9   r   r=   r+  rM  r)  r  r  r  r  r  r   r   r  r'  r  r,  r   )r&   r<  rc  mtmrr  mls   &&     r'   r   Shape.draw_ovalz:  sY   u:?12258[))U  AUATTQTTADD[C''TTQTTADD[C''TTQTTADD[C''TTQTTADD[C''2%NNijj(ABVKKN ODD"%DD"%DD"%DD"%r)   c               $    V ^8  d   QhRRRRRR/# )r  r  r   r  r  rs  r)  r,   )r  s   "r'   r  r$  :  s&     C C* Ce C Cr)   c                    V\         8  g   \        R4      h\        V4      pW^ 3,
          pV P                  WRRR7      # )r  radius must be positiver  Fr2  )r8  r   r)  r3  )r&   r  r  rJ  s   &&& r'   r  Shape.draw_circle:  sC    677vqk!CEBBr)   c               (    V ^8  d   QhRRRRRRRR/# )r  rJ  r   rK  r  rs  r)  r,   )r  s   "r'   r  r$  :  s2     0 00 0 	0
 
0r)   c                    Rp\        V4      p\        V4      p\        V4      pWV,
          V,          ,           pW2V,
          V,          ,           pV P                  WWc4      # )z4Draw a curve between points using one control point.7.SQ?)r)  r  )r&   rJ  rK  r  kappak1k2s   &&&&   r'   r  Shape.draw_curve:  sY     2Y2Y2Y7e##7e##//r)   c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r  r  r   rn  r/  r  r0  r   rs  r)  r,   )r  s   "r'   r  r$  :  sC     H HH H 	H
 H 
Hr)   c                   \        V4      p\        V4      pR pR pR p\        P                  ! V) 4      p\        P                  ! \        P                  ! RV4      4      R,          p	\        P                  ! \        P                  ! ^ZV4      4      p
V
^,          p\	        V4      ^\        P
                  ,          8  d   W,          pK/  V P                  V8X  g=   V ;P                  V! \        W P                  ,          4      !  ,          un        W n        \        ^ ^ 4      pTpTpW,
          p\	        V4      pV\        8  g   \        R4      hV P                  W4      p\	        V4      \	        V
4      8  EdB   VP                  \        P                  ! VV
,           4      V,          ,           pVP                  \        P                   ! VV
,           4      V,          ,           p\        VV4      pVP                  \        P                  ! VV,           4      V,          \        P                  ! V4      ,          ,           pVP                  \        P                   ! VV,           4      V,          \        P                  ! V4      ,          ,           p\        VV4      p^\        P                  ! V4      ,
          ^,          ^,          \	        VV,
          4      ,          pV\	        W,
          4      ,          pVVV,
          V,          ,           pVVV,
          V,          ,           pV ;P                  V! \        \#        VV P                  ,          4      \#        VV P                  ,          4      ,           \#        WP                  ,          4      ,           4      !  ,          un        W,          pVV
,          pTpEK[  \	        V4      R8  EdW   V^,          pVP                  \        P                  ! VV,           4      V,          ,           pVP                  \        P                   ! VV,           4      V,          ,           p\        VV4      pVP                  \        P                  ! VV,           4      V,          \        P                  ! V4      ,          ,           pVP                  \        P                   ! VV,           4      V,          \        P                  ! V4      ,          ,           p\        VV4      p^\        P                  ! V4      ,
          ^,          ^,          \	        VV,
          4      ,          pV\	        W,
          4      ,          ^\        P                  ! V4      ,
          ,          pVVV,
          V,          ,           pVVV,
          V,          ,           pV ;P                  V! \        \#        VV P                  ,          4      \#        VV P                  ,          4      ,           \#        WP                  ,          4      ,           4      !  ,          un        V'       d   V ;P                  V! \        W P                  ,          4      !  ,          un        V ;P                  V! \        WP                  ,          4      !  ,          un        V ;P                  V! \        WP                  ,          4      !  ,          un        Wn        V P                  # )zDraw a circle sector.c                (    \        W34      R ,           # )r1  r   r   rI  s   &&r'   r
  #Shape.draw_sector.<locals>.<lambda>:      )QF+f4r)   c                ,    \        WW#WE34      R ,           # )r9  rP  r  s   &&&&&&r'   r
  rR  :  s    iqQ0B&Cf&Lr)   c                (    \        W34      R ,           # )r2  rP  rQ  s   &&r'   r
  rR  :  rS  r)   r  rD  MbP?r  )r)  r  r  copysignr,  r  r  r   r  r'  r8  r   r!  ri  r   rj  r  r   )r&   r  rn  r/  r0  l3l4l5betarw360w90w45r   r  r  r
  r<  r   q1q2r  r  r  kappahrI  cp1cp2beta2s   &&&&&                       r'   r3  Shape.draw_sector:  s    ve4L4dU#||DMM#u56"=ll4==U34Ag%j1tww;&ME5(NNb(5::+=">??N#O!QKE!fW}677$$V3%j3s8#txxs
+c11Btxxs
+c11Bb"Atxxs
+c1DHHSMAABtxxs
+c1DHHSMAABb"A$((3-'1,q03q1u:=FSZ'Eq1uo%Cq1uo%CNNb(S4::%&cDJJ.>)??$q::~BVV#  N LECKDAu:AIEtxxu-33Btxxu-33Bb"Atxxu-3dhhuoEEBtxxu-3dhhuoEEBb"A$((5/)Q.2SQZ?FSZ'1txx+>?Eq1uo%Cq1uo%CNNb(S4::%&cDJJ.>)??$q::~BVV#  N NNb(5::+=">??NNNb(6JJ+>"?@@NNNb(1zz>":;;Nr)   r  Nc                    V ^8  d   QhRRRR/# )r  r   r   rs  r)  r,   )r  s   "r'   r  r$  :  s     1 1i 1E 1r)   c          
        \        V4      pVf   V ;P                  \        \        \	        VP
                  V P                  ,          4      VP                  VP                  .,           4      4      R,           ,          un        V P                  V4       VP                  V n        V P                  # \        VR4      '       dN   V^ 8:  g   VR8  d   \        RV R24      h\        VP                  VP                  4      V,          pV^ 3p^ V3pM\        VR4      '       dm   \        V4      ^8X  d]   Vw  rxWsP                  ,          ^ 3p^ WP                  ,          3p\        Wx4      ^ 8:  g   \!        Wx4      R8  d   \        RV R24      hM\        RV R24      hV P#                  VP                  V,           VP
                  V,
          4      p	V P%                  WP
                  VP
                  V,           4      p	V P#                  WP&                  V,
          4      p	V P%                  WP&                  VP&                  V,
          4      p	V P#                  WP(                  V,           4      p	V P%                  WP(                  VP(                  V,
          4      p	V P#                  WP                  V,           4      p	V P%                  WP                  VP                  V,           4      V n        V P                  V4       V P                  # )a  Draw a rectangle.

Args:
    radius: if not None, the rectangle will have rounded corners.
        This is the radius of the curvature, given as percentage of
        the rectangle width or height. Valid are values 0 < v <= 0.5.
        For a sequence of two values, the corners will have different
        radii. Otherwise, the percentage will be computed from the
        shorter side. A value of (0.5, 0.5) will draw an ellipse.
z re
r  r  zbad radius value r   r  )r+  r   r   r  r   r  r'  r  r3  r,  r*  r  r=   r   r  r9   r'  r  r  r+  r  )
r&   r   r  r$  rH  r  pyrxryr  s
   &&$       r'   r  Shape.draw_rect:  sM    J>NNiQTTDJJ&'177AHH*==)  N OOAddDO??" 6;''{fsl #4VHA!>??AGGQXX&/AQBQBVY''CK1,<FBww,"BR((]#B2{a3r;#4 #4VHA!>?? $5 0:;;^^ADD2Iqttby1__Rqttby1^^Br	*__Rqttby1^^Br	*__Rqttby1^^Br	*//"ddADD2I>r)   c                    V ^8  d   QhRRRR/# )r  rM  r   rs  r)  r,   )r  s   "r'   r  r$  &;  s     B Bi BE Br)   c                    \        V4      pV P                  VP                  VP                  VP                  VP
                  VP                  .4      # )zDraw a Quad.)r)  r$  r  r  r  r  )r&   rM  rc  s   && r'   r(  Shape.draw_quad&;  s;    J!!144qttQTT144"@AAr)   c               (    V ^8  d   QhRRRRRRRR/# )r  rJ  r   rK  r7  r  rs  r)  r,   )r  s   "r'   r  r$  +;  s2        	
 
r)   c                4   \        V4      p\        V4      pW!,
          p\        V4      p^\        \        V^V,          ,          ^ 4      4      ,          pV^8  d   \	        R4      hWV,          p\        \        W4      4      pV( p	. p
\        ^V4       F`  pV^,          ^8X  d   \        VR4      V,          pM$V^,          ^8X  d   \        V^4      V,          pMKI  V
P                  W,          4       Kb  	  V P                  V.V
,           V.,           4       V# )z%Draw a zig-zagged line from p1 to p2.points too closer  )
r)  r,  r6   r  r   r  r  rS  ro   r$  )r&   rJ  rK  r7  r
  r<  r9  r  r  i_matrI  rg  r  s   &&&&         r'   r@  Shape.draw_zigzag+;  s     2Y2YG!f#eC1w;/3447/00Y/0q#A1uz!RL2%Q!!QK"$MM!)$  	B4&=B4/0	r)   c               $    V ^8  d   QhRRRRRR/# r/  r,   )r  s   "r'   r  r$  H;  s(     # ## #
 
#r)   c                   \        V4      p\        V4      pW!,
          p\        V4      p^\        \        V^V,          ,          ^ 4      4      ,          pV^8  d   \	        R4      hWV,          p\        \        W4      4      pV( p	Rp
. p\        ^V4       Fp  pV^,          ^8X  d   \        W) 4      V,          pM4V^,          ^8X  d   \        W4      V,          pM\        V^ 4      V,          pVP                  W,          4       Kr  	  V.V,           V.,           p\        V4      p^ pV^,           V8  d?   V P                  W,          W^,           ,          W^,           ,          4       V^,          pKL  V# )z#Draw a squiggly line from p1 to p2.rq  gh?3OP@)r)  r,  r6   r  r   r  r  rS  ro   r9   r  )r&   rJ  rK  r7  r
  r<  r9  r  r  rr  r  rI  rg  r  s   &&&&          r'   r;  Shape.draw_squiggleH;  s:    2Y2YG!f#eC1w;/3447/00Y/0q#A1uz!RL2%Q!!K"$!QK"$MM!)$  "%&k!eckOOFIv!e}fUmDFA	r)   r   r  r   r  r%  r  r  rp  r   rI  r  rG  rH  r`  r-  r  r	  r  c          &     d    V ^8  d   QhRRRRRRRRR	R
RRRRRRRRRRRRRRRRRRRRRRRRRRRR/# )r  rn  r   r3
  rK  r   r  r  r  r   r  r%  r  r  r   r  r6   rp  r  r   rI  r  rH  r`  r-  r  r	  r  rs  r,   )r  s   "r'   r  r$  p;  s     x xx (x
 x x x x x x x x x x x  !x" #x$ %x& 'x( )x* 
+xr)   c          
     	T   \        V4      '       g   ^ # \        V4      \        \        39  d   VP	                  4       pMTp\        V4      ^ 8  g   ^ # \        V4      p \        RP                  V4       Uu. uF  p\        V4      NK  	  up4      pTpTP                  R4      '       d
   TR,          pT P                  P                  TYhTR7      p\        T P                   T4      pT^,          pTR,          pTR,          pTR,          pTR,          pTR	,          pT'       d
   Y4,          pM(TT,
          ^8:  d   TR
,          pMTTT,
          ,          pT^8  d%   T P                   P#                  TT^,           4      p M	TR,          p . p!T F4  p"T'       d   TR%9  d   Rp#MT p#T!P%                  \'        T"T#TT4      4       K6  	  T!p\)        T	R4      p$\)        T
R4      p%T
'       g   T^ 8X  d   T	p
\)        T	R4      p%\+        T4      p&Tp'T'^Z,          ^ 8w  d   \-        R4      hT'^ 8  d   T'R,          p'K  T'R,          p'R p(R p)Rp*Rp+Rp,T P.                  p-T P0                  p.T&'       d   \3        ^^ ^ ^T^ ,          P4                  T P4                  ,           T-T^ ,          P6                  ,
          T P6                  ,
          4      p/T/( T^,          ,          T/,          p0\9        \;        T04      4      R,           p1MRp1T-TP6                  ,
          T P6                  ,
          p2TP4                  T P4                  ,           p3T2p4T'^Z8X  d_   T-TP6                  ,
          T P6                  ,
          p3TP4                  ) T P4                  ,
          p2T1T*,          p1T.\=        T24      ,
          p4MT'R8X  dX   T-) TP6                  ,           T P6                  ,           p3TP4                  T P4                  ,           p2T1T+,          p1\=        T24      p4MyT'^8X  ds   TP4                  ) T P4                  ,
          p3T-) TP6                  ,           T P6                  ,           p2T1T,,          p1\=        TP6                  T P6                  ,           4      p4T P                  P?                  T4      p5T5e
   RT5 R2p6Rp7MR;p6p7T P                  PA                  TTR7      p8T8f   Rp8MRT8 R2p8T(! T6T8T1T3T2TT4      p9T^ 8  dI   T9T R2,          p9T9\9        Y,          4      R,           ,          p9Te   T9\9        T4      R ,           ,          p9T	e
   T9T$,          p9T
e
   T9T%,          p9T9T^ ,          ,          p9^p:\        T4      ^8  d   T9T)! T4      ,          p9M	T9R!,          p9\C        ^\        T4      4       FE  p;T4T8  d    M=T;^8  d
   T9R",          p9T9TT;,          R!,           ,          p9T4T,          p4T:^,          p:KG  	  T9R#T7 R$2,          p9T ;PD                  T9,          un"        T:# u upi   \         d    \        4         ^ # i ; i)&rx   r   r	  r	  r   r%  r  r  r  r<  r   r:  r;  r  r?  Nr  r  r<  r  c                P    R V  V RV R\        W434       RV R\        V4       R2# )r  BT
1 0 0 1 z Tm
/r    Tf rP  r   rI  r  rH  rh  r  r  s   &&&&&&&r'   r
  #Shape.insert_text.<locals>.<lambda>;  s@    uQCs$qc)UVTZJ[I\\bcdbeefgpqrgsfttx-yr)   c                     R \        V 4       R2# )zTJ
0 -z TD
rP  r   s   &r'   r
  r  ;  s    WYq\N%8r)   0 1 -1 0 0 0 cm
0 -1 1 0 0 0 cm
-1 0 0 -1 0 0 cm
 cm
r`   r  /OC / BDC
EMC
r(  r)   Tr  w  M TJz
T* z
ET
Q
r>  r=  )#r   r   r   r   r  r9   r)  r'  r  r:  rk   r{   r5   r   r  rK  r1  rU  ro   getTJstrr  
CheckMorphr   r3  r  r  ri  rj  r   r  r,  r  r  rS  r(  )<r&   rn  r3
  r   r  r   r%  r  r  rp  r   rI  r  rH  r`  r-  r  r	  r  r   r  maxcoder6  r  rP  r7  r  r<  r  r:  r;  lheightr?  tabr  r  	color_strfill_strmorphingry  templ1templ2cmp90cmm90cm180r3  r  r  r  r'  r  rL  spaceoptcontbdcemcr  r  nlinesrg  s<   &&&$$$$$$$$$$$$$$$$                                         r'   r  Shape.insert_textp;  su   0 F||<e},$$&DD4y1}e	388D>:>a3q6>:;G C  "IEyy$$XZ % 
 !40A;J'(#&!J'[)	+G	!Q&nG(Y"67GS=XX--dGaK@Fh'FA&(BBJJx1fh78  eS)	T3'q(D ,He$8q=/00Ag3JCCiy8##$

 1aE!HJJ$7%(**9Ltvv9UVB#a.2%C8C=)G3BBuww'ww"9EGG#dff,D77(TVV#C%KBCH$E CZ7UWW$tvv-D''DFF"C%KBHE CZGG8dff$D'EGG#dff,C%KB$&&()E ))11"5'&)CCNC#		&&.\&J=Ewe$Ec5"dCA?{m4((DIl56>>D&	+.66IDHD
 	Qt9q=F7O#DDLDq#d)$Aw1uDGdN"DWEaKF % 	&S!! 	$g ; 		s$   X 7X	X 	X X'&X'r  rN  c          *     l    V ^8  d   QhRRRRRRRRR	R
RRRRRRRR
RRRRRRRRRRRR
RRRRRRRRRRRR/# )r  r   r   r3
  rK  r  r6   r  r  rp  r  r  rN  r	  r   r%  r  r   r   r  r  rH  r-  r  rI  r`  r  r   r  rs  r,   )r  s   "r'   r  r$  -<  s     B BB (B
 B B B B B B B B B B B  !B" #B$ %B& 'B( )B* +B, -B. 
/Br)   c          
       aaPaQ \        V4      pVP                  '       g   VP                  '       d   \        R4      h\	        VR4      p\	        V	R4      pV	f   V^ 8X  d   Tp	\	        VR4      pV P
                  P                  V4      pVe
   RV R2pRpMR;ppV P
                  P                  VVR	7      pVf   RpMR
V R2pV^Z,          ^ 8w  d   \        R4      hTpV^ 8  d   VR,          pK  VR,          p\        V4      '       g    VR-9   d   VP                  # VP                  # RpRpRpV P                  pTp V P                  R
4      '       d
   V R,          p V P
                  P                  V WVR7      p!\        V P                  V!4      p"V"^,          p#V#R,          oQV#R,          p$V#R,          oPV#R,          p%V#R,          p&V#R,          p'V'       d   Tp(MV&V',
          ^8:  d   Rp(M	V&V',
          p(SV(,          p)\        V4      \         \"        39   d   RP%                  V4      p*MTp*\'        V* U+u. uF  p+\)        V+4      NK  	  up+4      p,V$'       d;   V,^8  d4   RP%                  V* U+u. uF  p+\)        V+4      R8  d   T+MRNK  	  up+4      p*V*P+                  4       p*V P                  P-                  V!V,^,           4      oPV$'       d   V%R.9  d   Rp-MSPp-VVPVQ3R lp.SQ^ 8  d   SP^ ,          ^,          S,          p/MSp/Rp0\/        V4      '       d   \1        ^^ ^ ^V^ ,          P2                  V P2                  ,           V P                  V^ ,          P4                  ,
          V P4                  ,
          4      p1V1( V^,          ,          V1,          p2\7        \9        V24      4      R,           p3MRp3^p4\;        ^ SV&,          4      p5V^ 8X  d-   VP<                  V5,           p6VP                  p7VP                  p8MV^Z8X  dI   \;        SV&,          ^ 4      p5VP>                  V5,           p6VP                  p7VP                  p8V3V,          p3MV^8X  dL   \;        ^ SV&,          4      ) p5VP@                  V5,           p6VP                  p7R/p4VP                  p8V3V,          p3MJ\;        SV&,          ^ 4      ) p5VPB                  V5,           p6VP                  p7R/p4VP                  p8V3V,          p3. p9\E        V*4       EF  w  p:p;V;PG                  V4      PI                  R4      p<\K        V<4      p=Rp>T7p?\M        V=4       EF  p@V<V@,          pAV.! VA4      pBV?VB8  d#   V>XAR,           ,          p>V?XBV/,           ,          p?K>  V>'       d2   V>PO                  4       R,           p>V0V>,          p0V9PQ                  R 4       Rp>T7p?XBV78:  d   XAR,           p>V7XB,
          V/,
          p?K  \K        V94      ^ 8  d   R!V9R/&   XA FM  p+V.! V>4      V7V.! V+4      ,
          8:  d   V>V+,          p>K(  V>R,          p>V0V>,          p0V9PQ                  R!4       T+p>KO  	  V>R,          p>V7V.! V>4      ,
          p?EK   	  V>'       d)   V0V>PO                  4       ,          p0V9PQ                  R!4       V:\K        V*4      ^,
          8  g   EK  V0R,          p0EK  	  V0PS                  R4      '       d   V0RR/ p0V0PU                  R4      ^,           pCV)VC,          V'S,          ,
          pDVDV8,
          pEVE\V        8  d
   R/XE,          # \Y        XE4      pEVE\V        8  d   ^ pER"V V R#2V3,           pFR$ pGV0P+                  4       pHR!V9R/&   \E        VH4       EF  w  p:pI^ pJV7V.! VI4      ,
          pKV6V5V:V(,          ,          ,           pLV^8X  dL   VR-9   d#   XL\;        XK^,          ^ 4      V4,          ,           pLMXL\;        ^ XK^,          4      V4,          ,
          pLM~V^8X  d>   VR-9   d   XL\;        XK^ 4      V4,          ,           pLMUXL\;        ^ XK4      V4,          ,
          pLM:V^8X  d4   XIPU                  R4      pMVM^ 8  d   V9V:,          '       d   XKXM,          pJM^ pJVXLP4                  ,
          V P4                  ,
          pNVLP2                  V P2                  ,           pOV^Z8X  dD   VXLP4                  ,
          V P4                  ,
          pOVLP2                  ) V P2                  ,
          pNMVR%8X  dD   V) XLP4                  ,           V P4                  ,           pOVLP2                  V P2                  ,           pNMJV^8X  dD   XLP2                  ) V P2                  ,
          pOV) VLP4                  ,           V P4                  ,           pNXFXG! XOXNV S4      ,          pFV^ 8  dJ   XFV R&2,          pFVF\7        VS,          4      R',           ,          pFVe   XF\7        V4      R(,           ,          pFV^8X  d   XF\7        XJ4      R),           ,          pFVe
   XFV,          pFV	e
   XFV,          pFXF\[        XIV-V$SQ4       R*2,          pFEK  	  XFR+V R,2,          pFV ;P\                  VF,          un.        V P_                  V4       XE# u up+i u up+i )0a  Insert text into a given rectangle.

Args:
    rect -- the textbox to fill
    buffer -- text to be inserted
    fontname -- a Base-14 font, font name or '/name'
    fontfile -- name of a font file
    fontsize -- font size
    lineheight -- overwrite the font property
    color -- RGB stroke color triple
    fill -- RGB fill color triple
    render_mode -- text rendering control
    border_width -- thickness of glyph borders as percentage of fontsize
    expandtabs -- handles tabulators with string function
    align -- left, center, right, justified
    rotate -- 0, 90, 180, or 270 degrees
    morph -- morph box with a matrix and a fixpoint
Returns:
    unused or deficit rectangle area (float)
z%text box must be finite and not emptyr  r  Nr  r  r  r`   r(  r	  r)  zrotate must be multiple of 90r  r  r  r  r	  ry  r  r<  r?  r   r:  r;  r  r#   r  ?c           	        < S^ 8  d:   \        V  Uu. uF  pS\        V4      ,          ^,          NK  	  up4      S,          # \        V 4      S,          # u upi )zCalculate pixel length of x.)r  r:  r9   )ri  r  r   r?  r  s   & r'   pixlen$Shape.insert_textbox.<locals>.pixlen<  sM    !|q9q!F3q6N1--q9:XEE1v(( :s   "Ar  r   TFr  r{  c                @    R \        W34       RV R\        V4       R2# )r|  z Tm /r   r}  rP  )r   rI  r  rH  s   &&&&r'   r
  &Shape.insert_textbox.<locals>.<lambda>6=  s'    Xi.?-@aS)TU,W[#\r)   r  r  r  r  z Tw zTJ
zET
r  r  r  r  )0r+  r  r  r   r  r   r  r  r   r3  r  r5   r  rK  r1  r   r   r   r  r'  r:  r  rU  r  r  ri  rj  r   r  r)  r*  r  r+  r  rZ  rN  r8   r9   rS  r$   ro   r  r  r8  r,  r  r(  r,  )Rr&   r   r3
  r  r  rp  r  rN  r	  r   r%  r   r   r  rH  r-  r  rI  r`  r  r  r  r  r  r  r  r  ry  r  r  r  r3  r6  r  rP  r7  r<  r  r:  r;  lheight_factorr  r   r  r  	tj_glyphsr  blenr   r  r  r'  progrc_pntrn  maxwidth	maxheightjust_tabrg  rs   line_t	num_wordslbuffry  r  wordpl_wlb_counttext_heightmorer  templtext_tr  r  plr%  spacesr  rL  r?  r  sR   &&&$$$$$$$$$d$$$$$$$$                                                           @@r'   r  Shape.insert_textbox-<  s;	   X Dz===D,,,DEEeS)	T3'<K1,D ,H))11"5'&)CCNC# 		&&.\&J=Ewe$EB;!<==Ag3JCCi F||"%/4;;AtzzA##$C  "IEyy$$XZ % 
 !40A;J'(#(#&!J'[)	'N	!Q& N%	1N^+ <D%=(6"BBr*r!s1vr*+gmbAbs1v|!4bABB]]_))$!<f$>>II
	) a<":a=8+DDe1aE!HJJ/uQxzz1IDFF1RB #a.2%C8C=)G3BB
 aH,-!8GGeOEzzHIBY(X-q1EGGeOE{{H

I%KBCZ1h122EGGeOEzzHE{{I%KB 8h.22EGGeOE{{HE

I%KB
  }GAt__Z066s;FFIED 9%ayd|4<TCZ'ED4K'D !LLNT1EEMDOOD)8# 3JE#d?T1D x=1$#(HRLAe}6!9(<<
 . !  &-/G &J &&3r7Q;e %j ==9D::d#a' (9x+??Y&'>$;4y'>DseE7$'",\"f%DAqGF1I%B%1~#566Cz(?b1fa 05 88Caa 05 88C!(?b!u 44Cau 44C!A:(1++ 6kGG355.466)C55466>Dby~.uuftvvow/eedffnvgo.E$UH55DQ;-t,,	,"9:UBB*Ik2U::Dz	'*V33 	! x9fh?@EED_ &b 	$se3$] + Bs   7i/0i4c               L    V ^8  d   QhRRRRRRRRRRR	R
RRRRRRRRRRRRRR/# )r  r  r  rp  r  r   r  r6   r  r  r  rr  r   r-  r  r	  r  r  rs  r  r,   )r  s   "r'   r  r$  q=  s     Y YY Y 	Y
 Y Y Y Y Y Y Y Y Y 
Yr)   c           
        V P                   R8X  d   R# V^ 8X  d   RpMVf   ^ p\        VR4      p\        VR4      pV P                  P                  V4      pVe    RV R2V P                   ,           V n         RpMRpV P                  P	                  WR7      pVe   R	V R
2V P                   ,           V n         V^8w  d1   V^ 8w  d*   V ;P                   \        V4      R,           ,          un         V^ 8w  d   V R2V P                   ,           V n         V^ 8w  d   V R2V P                   ,           V n         VR9  d   V R2V P                   ,           V n         V	'       d!   V ;P                   R,          un         RV n        Ve   V ;P                   V,          un         Ve   V ;P                   V,          un         Ve=   V'       g   V ;P                   R,          un         MoV ;P                   R,          un         MUV'       g   V ;P                   R,          un         M3V ;P                   R,          un         MV ;P                   R,          un         V ;P                   V,          un         \        V4      '       d   \        ^^ ^ ^V^ ,          P                  V P                  ,           V P                  V^ ,          P                  ,
          V P                  ,
          4      pV( V^,          ,          V,          p\        \        V4      4      R,           V P                   ,           V n         V ;P                  RV P                   ,           R,           ,          un        RV n         RV n        R# )zFinish the current drawing segment.

Notes:
    Apply colors, opacity, dashes, line style and width, or
    morphing. Also whether to close the path
    by connecting last to first point.
r`   Nr  r  r  r  r  r(  r	  r)   w
z J
z j
z d
zh
zB
zB*
zf
zf*
zS
r  r  r  )Nr`   [] 0)r   r  r   r  r  r   r  r  r  ri  r3  rj  r  r)  )r&   r  rp  r   r  r  r  rr  r-  r  r	  r  r  r  r  r  r  r  r  r  s   &&&&&&&&&&&&&       r'   r  Shape.finishq=  s   , >>RA:E]E eS)	T3'))11"5$WIV4t~~EDNCC		&&.&J u->DNA:%1*NNi.77Na< 'y->DNq= (z.?DN++ &xt_t~~=DNNNe#N"DONNi'NNNh&N NNe+NNNf,NNNe+NNNf,NNNe#N#e1aE!HJJ/uQxzz1IDFF1RB #a.2%C&x}5?$..PDN'DNN2U::r)   c                    V ^8  d   QhRRRR/# )r  r  r   rs  r  r,   )r  s   "r'   r  r$  =  s      d d r)   c                   \        V P                  4       V ;P                  V P                  ,          un        V P                  P	                  4       V n        V P                  '       di   V'       d   V P                  P                  4        \        P                  V P                  RV4      pV P                  P                  W P                  4       RV n
        RV n        RV n        RV n        RV n        R# )zUpdate the page's /Contents object with Shape data.

The argument controls whether data appear in foreground (default)
or background.
r+  Nr`   )ro  r   r)  r(  r  r  r  r  r1  r
  r  r   r   )r&   r  r  s   && r'   r  Shape.commit=  s     	DII$..(..0>>>		'')))$))T7CDHH""48	r)   )r1  r   r3  r'  r  r   r&  r   r(  r)  r  ri  rj  r%  r  )r  ru  Nrx   rx   NFNTr  r  rx   )r/   r0   r1   r2   rc  r|  r!  r   r,  r  r$  r  r   r  r  r3  r  r(  r@  r;  r  r  r  r  r3   r,   r)   r'   ro  ro  :  s    &(7*.0C0HT14 1fB
:#Px
 x  $x x  x x x x x x #x x  !x" #x$ !"%x&  'x( )xzB
 B #B B B B  B B  B "B B  $B  !B" #B$ %B& 'B( )B* +B, !"-BH
Yv r)   ro  c                      ] tR tRtRR ltR t]R 4       t]R 4       t	R t
RR ltRR	 ltRR
 ltR tRR lt]RR l4       t]RR l4       tRR lt ! R R4      tRR ltRR ltRR ltRR ltRtR# )r*  i=  Nc                	   \         P                  ! VP                  R 4      4      pV'       d"   \        V\        4      '       g   \	        V4      pV'       d   VP
                  M\         P                  ! R4      p\        \         R4      '       d   \         P                  ! WRW64      V n        R# \         P                  ! WRW64      V n        R# )r  NFzStoryS)
r   r  r  r@   r~  r   	FzArchiver=   r  FzStory)r&   r   r!  emr  r4  archs   &&&&&  r'   r   Story.__init__=  s{    66G8LM:gw77g&G&w||EOOT,B5*%%2DDIw"CDIr)   c                d   V P                   p^ pVP                  RRR4      pV'       d   VP                  p\        V4      ^8X  dV   V^ ,          R8X  dH   V^,          R9   d:   VP	                  R4      pV'       g!   RV 2pVP                  RV4       V^,          pVP                  RRR4      pK  R# )z\
Look for `<h1..6>` items in `self` and adds unique `id`
attributes if not already present.
Nr"  123456rY  h_id_)r  r   r  r9   r  r  r  )r&   domrg  ri  r   attrid_s   &      r'   add_header_idsStory.add_header_ids=  s    
 iiHHT4&99D4yA~$q'3,47h3F,,T2!!+COOD#.FAD$-A r)   c                :   \        V \        4      '       d   T pM\        RV 4      p\        4       pV FS  pVP                  ^,          '       g   K  VP                  '       g   K2  VP                  V9   d   KE  WCVP                  &   KU  	  V EFQ  pVP                  ^,          '       g   K  VP
                  '       g   K3  \        4       p\        VP                  4      VR&   VP
                  P                  R4      '       d[   VP
                  R,          p W7,          p \        TR&   TP                  w  rr\        Y4      TR	&   TP                   ^,
          TR
&   MYVP
                  P                  R4      '       d!   \"        VR&   VP
                  R,          VR&   M\$        VR&   VP
                  VR&   W%P                   ^,
          ,          P'                  V4       EKT  	  V#   \         d-   p	\        ^8  d   \        4        \        RT RT 24      T	hRp	?	ii ; i)aF  
Adds links to PDF document.
Args:
    document_or_stream:
        A PDF `Document` or raw PDF content, for example an
        `io.BytesIO` instance.
    positions:
        List of `ElementPosition`'s for `document_or_stream`,
        typically from Story.element_positions(). We raise an
        exception if two or more positions have same id.
Returns:
    `document_or_stream` if a `Document` instance, otherwise a
    new `Document` instance.
We raise an exception if an `href` in `positions` refers to an
internal position `#<name>` but no item in `positions` has `id =
name`.
ra  r  rm  r	  zNo destination with id=z, required by position_from: Nr  r  r   zname:r   r   r  )r@   r   r7   
open_closerY  r9  r+  r   r5   rk   r  r{   r   r%   r  r)  page_numr{  r   r  )document_or_stream	positionsr   id_to_positionpositionposition_fromr  	target_idposition_torh  r  r  r  r  s   &&            r'   add_pdf_linksStory.add_pdf_links>  s   & ((33)H'9:H
 !H##a''X[[[;;.03;HKK0 " 'M((1,,-2D2D2D v#M$6$67V %%0055 - 2 22 6IE&4&@ 
 $-DL%0%5%5NBB "'rDJ#.#7#7!#;DL %))44W=='1V'4'9'9"'=V'/V&3&8&8U //!34@@FQ 'T ; % E/!38H*-DYKOlmzl{+|}  DE  EEs   G##H.'HHc                	B    V P                  4       pVP                  4       # r+   )r   rg  r&   r  s   & r'   r  
Story.bodyY>  s    mmo{{}r)   c                	X    \         P                  ! V P                  4      p\        V4      # r+   )r   fz_story_documentr   r  r  s   & r'   r   Story.document^>  s     %%tyy1Cyr)   c                	    \        V4      pV'       d   VP                  M\        P                  ! R 4      p\        P                  ! V P                  WC4       R # r+   )r  r   r   rJ  fz_draw_story)r&   rR  r  ctm2r  s   &&&  r'   draw
Story.drawb>  s6     &)#fkk)>TYY2r)   c                  aa \        S4      \        J dQ   SP                  4        F;  p\        V4      \        J d   VP	                  4       '       d   K.  \        RV R24      h	  M/ o\        S4      '       d   SP                  P                  ^8w  d   \        R4      hVV3R lp\        P                  ! V P                  V4       R# )zE
Trigger a callback function to record where items have been placed.
zinvalid key 'r   z@callback 'function' must be a callable with exactly one argumentc                  <  ! R  R4      pV! 4       pV P                   Vn         V P                  Vn        V P                  Vn        \        V P                  4      Vn        V P
                  Vn        V P                  Vn        V P                  Vn        V P                  Vn	        S'       d&   SP                  4        F  w  r4\        W#V4       K  	  S! V4       R# )c                      ] tR tRtRtR# )=Story.element_positions.<locals>.function2.<locals>.Position2iu>  r,   Nr/   r0   r1   r2   r3   r,   r)   r'   	Position2r  u>  s    r)   r  N)ra	  headingrY  rp  r   r   r  rectangle_numrect_numr9  rD   setattr)r  r  	position2r  rH   r  rm   s   &    r'   	function2*Story.element_positions.<locals>.function2t>  s     !I&nnIO ( 0 0I#;;IL,X]];IN%]]IN#+#6#6I !)!7!7I%]]IN JJLDAY1- )i r)   N)r   r7   r  r  isidentifierr   r]  __code__co_argcountr   fz_story_positionsr   )r&   rm   r  r  r  s   &ff  r'   element_positionsStory.element_positionsg>  s     :YY[Q31>>+;+;$}QCq%9:: ! D!!X%6%6%B%Ba%G_``	!  	  $))Y7r)   c                    \        V4      p\        P                  ! 4       p\        P                  ! V P                  WV4      pV\        V4      3# )z%
Wrapper for fz_place_story_flags().
)r  r   rq  fz_place_story_flagsr   rp  )r&   wherer  r/  r  s   &&&  r'   placeStory.place>  sA      '))499eUK_f---r)   c                	F    \         P                  ! V P                  4       R # r+   )r   fz_reset_storyr   r-   s   &r'   r
  Story.reset>  s    dii(r)   c                	P  aa R p^ o^ p\        ^ ^ ^ ^ 4      p V! Wg4      w  rp
V^,          pV'       d
   S^,          oV P                  V	4      w  rS'       d   VV3R lpV P                  V4       V'       d   V'       dN   V'       d#   V'       d   V! SW^4       VP                  4        VP	                  V4      pV'       d   V! SW^ 4       V P                  WZ4       V'       g#   V'       d   V! SW^4       VP                  4        MV P                  R V
4       V'       d   EK  R # )Nc                &   < SV n         S! V 4       R # r+   )r  )r  r  
positionfns   &r'   positionfn2 Story.write.<locals>.positionfn2>  s     )1H%x(r)   )r+  r  r  r  r
  r  )r&   r  rectfnr  pagefnr  r  r/  rJ  r   r  r  r  r  s   &&&f&        @r'   r   Story.write>  s    aAq!"(":HCMHA::t,LD)
 &&{3!"8XA>) ++X6Cx:		3$(;OO%		$$4r)   c	                	  aaa \        4       oR p	 T	p
V! S4      p	RoW8X  d   RoT	p\        WWG4      pV'       d   VP                  4        \        4       oVVV3R lpTP                  S'       d   T MR VVV4       S'       g   Ku  R # )NFTc                b   < SP                  V 4       S'       d   S'       d   S! V 4       R # R # R # r+   r
  )r  r  r  stables   &r'   r  +Story.write_stabilized.<locals>.positionfn2>  s%      *jx( )6r)   )r   r*  r  r   )r  	contentfnr  r!  r  r  r  r  r  r  content_prevcontent2r4  r  r  r  s   &&&&&f&&&     @@r'   write_stabilizedStory.write_stabilized>  s    F	"L+GF&H(b:E$$&I)
 KK$F$	 vr)   c                	   aa \         P                  ! 4       p\        V4      p	. oVV3R  lp
\        P	                  WWW:WVV4	       V	P                  4        VP                  ^ 4       \        P                  VS4      # )c                N   < SP                  V 4       S'       d   S! V 4       R # R # r+   r
  r  r  r  s   &r'   r  6Story.write_stabilized_with_links.<locals>.positionfn2>  !    X&8$ r)   )r;   r  r  r*  r  r  rQ
  r  )r  r  r!  r  r  r  r  r  r   r  r  r  s   &&&&f&&&   @r'   write_stabilized_with_links!Story.write_stabilized_with_links>  se     '		%
 	v&BU[ftuA""6955r)   c                	   aa \         P                  ! 4       p\        V4      p. oVV3R  lpV P                  WQWcR7       VP	                  4        VP                  ^ 4       \        P                  VS4      # )c                N   < SP                  V 4       S'       d   S! V 4       R # R # r+   r
  r  s   &r'   r  +Story.write_with_links.<locals>.positionfn2>  r  r)   )r  r  )r;   r  r  r   r  rQ
  r*  r  )r&   r  r  r  r   r  r  r  s   &&f&   @r'   r0  Story.write_with_links>  s[    '		%
 	

6k
IA""6955r)   c                  *    ] tR tRtRtRR ltR tRtR# )Story.FitResulti>  a   
The result from a `Story.fit*()` method.

Members:

`big_enough`:
    `True` if the fit succeeded.
`filled`:
    Tuple (x0, y0, x1, y1) from the last call to `Story.place()`. This
    will be wider than .rect if any single word (which we never split)
    was too wide for .rect.
`more`:
    `False` if the fit succeeded.
`numcalls`:
    Number of calls made to `self.place()`.
`parameter`:
    The successful parameter value, or the largest failing value.
`rect`:
    The pumupdf.Rect created from `parameter`.
Nc                	N    Wn         W n        W0n        W@n        WPn        W`n        R # r+   r-  r/  r  numcallsr.  r   )r&   r-  r/  r  r)  r.  r   s   &&&&&&&r'   r   Story.FitResult.__init__?  s     (O KI$M&NIr)   c                	    R V P                    RV P                   RV P                   RV P                   RV P                   RV P
                   2# )z big_enough=z filled=z more=z
 numcalls= parameter= rect=r(  r-   s   &r'   r   Story.FitResult.__repr__?  sP    "4??"3t{{mTYYK !$..!1TYYK)r)   r(  ry  )r/   r0   r1   r2   rc  r   r   r3   r,   r)   r'   	FitResultr&  >  s    	(		r)   r/  c                  a aaaaaaaa V3R lo\        S\        \        34      '       g   Se   Q h\        S\        \        34      '       g   Se   Q h ! VVV3R lR4      pV! 4       oS'       d&   S! RSP                  : RSP                  : R24       S P                  4        VVVV3R lpVVVV VV3R	 loR
 p	SP                  f?   S'       d	   S! R4       V	! SP                  R4      p
 S! V
4      '       g   MIV
^,          p
K  S! SP                  4      '       d'   S'       d   S! RSP                  : R24       V! 4       # SP                  f?   S'       d	   S! R4       V	! SP                  ^4      p
 S! V
4      '       d   MPV
^,          p
K  S! SP                  4      '       g.   RSn        S'       d   S! RSP                  : R24       V! 4       # S'       d&   S! RSP                  : RSP                  : R24        SP                  SP                  ,
          V8  d   V! 4       # SP                  SP                  ,           ^,          p
S! V
4       KX  )a  
Finds optimal rect that contains the story `self`.

Returns a `Story.FitResult` instance.
    
On success, the last call to `self.place()` will have been with the
returned rectangle, so `self.draw()` can be used directly.

Args:
:arg fn:
    A callable taking a floating point `parameter` and returning a
    `pymupdf.Rect()`. If the rect is empty, we assume the story will
    not fit and do not call `self.place()`.

    Must guarantee that `self.place()` behaves monotonically when
    given rect `fn(parameter`) as `parameter` increases. This
    usually means that both width and height increase or stay
    unchanged as `parameter` increases.
:arg pmin:
    Minimum parameter to consider; `None` for -infinity.
:arg pmax:
    Maximum parameter to consider; `None` for +infinity.
:arg delta:
    Maximum error in returned `parameter`.
:arg verbose:
    If true we output diagnostics.
:arg flags:
    Passed to mupdf.fz_place_story_flags(). e.g.
    zero or `mupdf.FZ_PLACE_STORY_FLAG_NO_OVERFLOW`.
c                8   < S'       g   Q h\        R V  24       R# )zfit(): Nrv   )r   r5  s   &r'   r%   Story.fit.<locals>.log>?  s    N7gdV$%r)   Nc                  (   < ] tR tRtV VV3R ltRtR# )Story.fit.<locals>.StateiE?  c                	   < SV n         SV n        R V n        R V n        R V n        ^ V n        S'       d   SV n        SV n        R # R # r+   )pminpmaxpmin_resultpmax_resultr  r)  pmin0pmax0)r&   r8  r7  r5  s   &r'   r   !Story.fit.<locals>.State.__init__F?  sE     	 	#' #' " !!%DJ!%DJ r)   )r)  r8  r<  r:  r7  r;  r9  r  Nr   )r8  r7  r5  s   r'   Stater5  E?  s    	& 	&r)   r>  zstarting. state.pmin= state.pmax=r   c            
       < SP                   eU   SP                  SP                   8w  d-   S'       d	   S! R4       S! SP                   4      p V '       g   Q hSP                  pM>SP                  '       d   SP                  M\        P                  SP                  R7      pS'       d7   S! RSP                  : RSP                  : RSP                   : RV: 24       V# )NzCCalling update() with pmax, because was overwritten by later calls.)r)  zfinished. state.pmin0=z state.pmax0=r?  z: returning result=)	r8  last_pr:  r9  r*  r/  r)  r;  r<  )r-  r  r%   r  rN  r5  s     r'   rI   Story.fit.<locals>.retW?  s    zz%<<5::-ac!'

!3J%%:**.3.?.?.?**U__^c^l^l_Em-n~]uzzmK_X^W`abMr)   c                `  < S! V 4      p\        V\        4      '       g   Q R\        V4      : RV: 24       hVP                  '       d5   Rp\        P                  V S
P                  R7      pS'       d	   S! R4       MS	P                  VS4      w  rES
;P                  ^,          un        V'       * p\        P                  VVS
P                  V VVR7      pS'       d$   S! RS
P                  R R	V: R
V : RV: R2	4       V'       d   V S
n        VS
n	        MV S
n
        VS
n        V S
n        V# )z
Evaluates `more, _ = self.place(fn(parameter))`. If `more` is
false, then `rect` is big enough to contain `self` and we
set `state.pmax=parameter` and return True. Otherwise we set
`state.pmin=parameter` and return False.
ztype(rect)=r-  F)r.  r)  z9update(): not calling self.place() because rect is empty.)r/  r  r)  r.  r   r-  zupdate(): called self.place(): z>2dz: more=r,  r   )r@   r+  r   r  r*  r/  r)  r  r8  r:  r7  r9  rA  )r.  r   r-  r  r  r/  r  fnr%   r&   r  r5  s   &     r'   rN  Story.fit.<locals>.updatee?  s    i=DdD))Ckd4j]'D7+CC)}}}"
9u~~VSU#zz$6!#!%X
%!!&"+!#- )  9%..9MXPTwVbXaWccjeidkklmn&
$*!&
$*!$ELr)   c                N    V e   V ^ 8X  d   V# W,          ^ 8  d
   ^V ,          # V ) # )zq
Returns same sign as `direction`, larger or smaller than `p` if
direction is positive or negative respectively.
r,   )r  	directions   &&r'   oppositeStory.fit.<locals>.opposite?  s/    
 yAqD  }q 1u2Ir)   zfinding pmin.zstate.pmin=z is big enough.zfinding pmax.z No solution possible state.pmax=z$doing binary search with state.pmin=r  )r@   r6   r  r7  r8  r
  )r&   rD  r7  r8  r}  r5  r  r>  rI   rH  r.  r%   r  rN  s   ffff&ff    @@@r'   r%  	Story.fit?  s   >	& $e--==$e--==
	& 
	& (UZZM5::-q9:

	 	#	 #	J		 ::m- R0Ii((Q	ejj!!C;5::- ?@u::m- R0I)$$Q	%**%%!
C"C

}A FGu C?EJJ=%**aPQzzEJJ&.uejj0A5I9r)   c                r   a
aaa Vw  oorxVS,
          oVS,
          o
V
VVV3R lp	V P                  WW4WV4      # )a1  
Finds smallest value `scale` in range `scale_min..scale_max` where
`scale * rect` is large enough to contain the story `self`.

Returns a `Story.FitResult` instance with `.parameter` set to `scale`.

:arg width:
    width of rect.
:arg height:
    height of rect.
:arg scale_min:
    Minimum scale to consider; must be >= 0.
:arg scale_max:
    Maximum scale to consider, must be >= scale_min or `None` for
    infinite.
:arg delta:
    Maximum error in returned scale.
:arg verbose:
    If true we output diagnostics.
:arg flags:
    Passed to Story.place().
c                X   < \        SSSV S,          ,           SV S,          ,           4      # r+   r  )r  r3  r  r  r  s   &r'   rD  Story.fit_scale.<locals>.fn?  s&    BU5[ 0"uV|2CDDr)   r%  )r&   r   r"  r#  r}  r5  r  r  r  rD  r3  r  r  r  s   &&&&&&&   @@@@r'   r+  Story.fit_scale?  sA    . BRb	E 	ExxyHHr)   c                Z   aa	a
 Vw  oo
SV,           o	VV	V
3R lpV P                  WrW5V4      # )a   
Finds smallest height in range `height_min..height_max` where a rect
with size `(width, height)` is large enough to contain the story
`self`.

Returns a `Story.FitResult` instance.

:arg width:
    width of rect.
:arg height_min:
    Minimum height to consider; must be >= 0.
:arg height_max:
    Maximum height to consider, must be >= height_min or `None` for
    infinite.
:arg origin:
    `(x0, y0)` of rect.
:arg delta:
    Maximum error in returned height.
:arg verbose:
    If true we output diagnostics.
c                .   < \        SSSSV ,           4      # r+   r  )r3  r  r  r  s   &r'   rD  Story.fit_height.<locals>.fn?  s    BBvI..r)   rN  )r&   r  
height_min
height_maxoriginr}  r5  rD  r  r  r  s   &&&&&&& @@@r'   
fit_heightStory.fit_height?  s/    , B%Z	/xx
7CCr)   c                Z   aa	a
 Vw  oo	S	V,           o
VV	V
3R lpV P                  WrW5V4      # )a  
Finds smallest width in range `width_min..width_max` where a rect with size
`(width, height)` is large enough to contain the story `self`.

Returns a `Story.FitResult` instance.
Returns a `FitResult` instance.

:arg height:
    height of rect.
:arg width_min:
    Minimum width to consider; must be >= 0.
:arg width_max:
    Maximum width to consider, must be >= width_min or `None` for
    infinite.
:arg origin:
    `(x0, y0)` of rect.
:arg delta:
    Maximum error in returned width.
:arg verbose:
    If true we output diagnostics.
c                .   < \        SSSV ,           S4      # r+   r  )r  r  r  r  s   &r'   rD  Story.fit_width.<locals>.fn@  s    B5"--r)   rN  )r&   r3  	width_min	width_maxrU  r}  r5  rD  r  r  r  s   &&&&&&& @@@r'   	fit_widthStory.fit_width?  s/    , B&[	.xxyAAr)   r$  )r`   N   Nr+   ru  r<  )Nr_  NNNT)NNrV  Frx   )rx   NrV  Frx   )rx   Nr	  rV  F)r/   r0   r1   r2   r   r  r|  r  r{  r  r   r  r  r  r
  r   r  r  r0  r/  r%  r+  rV  r]  r3   r,   r)   r'   r*  r*  =  s    D.& R Rh  3
8>.)%N  > 6 66% %NXtI<D8B Br)   r*  c                      ] tR tRtR tR tR tR R ltR tR!R R	 llt	R
 R lt
R"R ltR!R R lltR!R R lltR!R R lltR tR R R lltR tR#R ltR R ltR R ltR t]R 4       tR$R lt]tRtR# )%r  i@  c                	&   \        V\        P                  4      '       d&   V^ ,          p\        P                  ! V4      V n        M=\        V\        P                  4      '       d   V^ ,          V n        M\        RV 24      hRV n        RV n        R# )rx   Unrecognised args: TN)rI  r   rq  r  r   rk   r   r   )r&   r  rJ  s   &* r'   r   TextPage.__init__@  sm    dELL))AwH))84DIe//00QDI1$899r)   c                	|   V P                   p\        P                  ! R 4      p\        P                  ! V4      pV^8X  d   \        P                  ! WB^ 4       MIV^8X  d   \        P
                  ! WB^ 4       M*V^8X  d   \        P                  ! WB^ 4       M\        W24       VP                  4        \        V4      pV# )r  )
r   r   r0
  r1
  fz_print_stext_page_as_htmlfz_print_stext_page_as_xmlfz_print_stext_page_as_xhtmlJM_print_stext_page_as_textrE	  r  )r&   r  
this_tpager%  rF	  r   s   &&    r'   _extractTextTextPage._extractText@  s    YY
!!$'nnc" a<--cqA\,,Sa@\..sB'8%c*r)   c                	2    \        V P                  W4       R # r+   )JM_make_textpage_dictr   )r&   	page_dictr  s   &&&r'   _getNewBlockListTextPage._getNewBlockList2@  s    dii8r)   c                	    R V P                   P                  RV P                   P                  /pV P                  W!4       V# r	  )r   r  r3  ro  )r&   r  rn  s   && r'   _textpage_dictTextPage._textpage_dict5@  s6    diioox9I9IJ	i-r)   c                D     \        P                  ! T P                  4      # )z*Return a list with text block information.)"r  r   extractBLOCKSr   r   rq  r   rJ  r0
  Fixed_EMPTYr   FZ_STEXT_BLOCK_TEXTfz_clear_bufferJM_char_bboxJM_rects_overlapr  JM_append_runer  fz_union_rectr  fz_append_byter  r6  i_imager  r<  r   r"  r  r  r  r  r  ro   )r&   block_nri  tp_rectr%  r[  block	blockrectline_n	last_charrs   linerectr?  cbboxr   r2  r  litems   &                 r'   ru  TextPage.extractBLOCKS:@  s    &&tyy11r)   Nc                   V ^8  d   QhRR/# r	  r,   )r  s   "r'   r  TextPage.__annotate__n@  s     
 
$ 
r)   c                    V P                  RR7      pVe   VP                  VR&   VP                  VR&   V'       d!   VR,          pVP                  R R7       WCR&   V# )z>Return page content as a Python dict of images and text spans.Fr  r  r3  blocksc                B    V R ,          ^,          V R ,          ^ ,          3# r6  r,   rI  s   &r'   r
  &TextPage.extractDICT.<locals>.<lambda>v@      qy|QvYq\&Br)   r  rr  r  r3  r  r&   r  r  r  r  s   &&&  r'   extractDICTTextPage.extractDICTn@  s[    !!e!,>88CLIICM]FKKBKC"M
r)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  r  z@  s     $ $S $r)   c                $    V P                  ^4      # )z%Return page content as a HTML string.rj  r-   s   &r'   extractHTMLTextPage.extractHTMLz@  r  r)   c           	     n   RpV P                   p. pV EF  pV^,          pVP                  P                  \        P                  8X  d   K8  VP                  4       p^ pVP                  4       pVP                  '       d   Rp	MRp	\        P                  ! V4      p
V
P                  '       d   V
P                  4       pRp
V'       d   \        P                  ! \        \        \        \        4      p\        P                  ! V4      '       g   Q h\        P                  ! VP                  4       ^ ^ VP                  4       ^ ^ 4      p\        P                   ! WkV4      w  rp\        P"                  ! V4      p\%        V4      pV^ 8X  d;   VP                  4       VP                  4       ,          VP'                  4       ,          p\        P(                  ! \        P*                  ! VP                  P,                  4      4      p\/        4       pVV\0        &   \3        VP                  P4                  4      V\6        &   \9        VP;                  4       4      V\<        &   VP                  4       V\>        &   VP                  4       V\@        &   \        PB                  ! V4      V\D        &   \        PF                  ! V4      V\H        &   VPK                  4       V\L        &   VPO                  4       V\P        &   VPS                  4       V\T        &   VV\V        &   V'       d   XVR&   V	VR&   VPY                  V4       EK   	  V# )z*Return a list with image meta information.TFNr  zhas-maskr  )-r   r   r   r   rw  r~  r  r  fz_compressed_buffer_sizer  r  r  rL  r|  r   r"  r  r  r  rG   r-  ll_fz_keep_colorspacer  r7   dictkey_numberrp  r6  dictkey_bboxr{  i_transformdictkey_matrixdictkey_widthdictkey_heightr@  dictkey_colorspacer<  r  r  dictkey_xresr  dictkey_yresr  dictkey_bpcr  ro   )r&   r  r  ri  r   r  r2  img_sizer  has_mask
compr_buffr$  r  r  r   r"  r  r  
block_dicts   &&                 r'   r  TextPage.extractIMGINFO~@  sf   YY
EqLG$$(A(AA--/CH88:D 99#>J$$$%??A!
MM/?OUde11!4444NN3557Aq#%%'1a@!::31E	--c2vq="uuw03557:H##E$?$?@Y@Y$Z[BJ)0J~&'6u7G7G7L7L'MJ|$):5;L;L;N)OJ~&(+J}%),J~&-2-B-B2-FJ)**/*B*B2*FJ''*xxzJ|$'*xxzJ|$&)ggiJ{#'/J|$'-
8$%-Jz"IIj!Q  R 	r)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  r  @  s      # r)   c                *  a ^ RI o^ RIpV P                  RR7      p ! V3R lRVP                  4      pVe   VP                  VR&   VP
                  VR&   V'       d!   VR,          pVP                  R	 R
7       WdR&   VP                  VRV^R7      pV# )z.Return 'extractDICT' converted to JSON format.NFr  c                  $   < ] tR tRtV 3R ltRtR# )'TextPage.extractJSON.<locals>.b64encodei@  c                	z   < \        V4      \        \        39   d    SP                  V4      P	                  4       # R # r+   r   r  r  	b64encoder  r&   r  base64s   &&r'   r   /TextPage.extractJSON.<locals>.b64encode.default@  3    7ui00!++A.5577 1r)   r,   Nr/   r0   r1   r2   r   r3   r  s   r'   r  r  @      8 8r)   r  r  r3  r  c                B    V R ,          ^,          V R ,          ^ ,          3# r  r,   r  s   &r'   r
  &TextPage.extractJSON.<locals>.<lambda>@  r  r)   r  
separatorsr	  r	  r   rc   r  r  rr  JSONEncoderr  r3  r  dumpsr&   r  r  r  r  r  r  r  s   &&&    @r'   extractJSONTextPage.extractJSON@  s    !!e!,	8(( 	8
 >88CLIICM]FKKBKC"Mjj1jM
r)   c                   V ^8  d   QhRR/# r	  r,   )r  s   "r'   r  r  @  s     
 
T 
r)   c                    V P                  RR7      pVe   VP                  VR&   VP                  VR&   V'       d!   VR,          pVP                  R R7       WCR&   V# )zCReturn page content as a Python dict of images and text characters.Tr  r  r3  r  c                B    V R ,          ^,          V R ,          ^ ,          3# r  r,   r  s   &r'   r
  )TextPage.extractRAWDICT.<locals>.<lambda>@  r  r)   r  r  r  s   &&&  r'   extractRAWDICTTextPage.extractRAWDICT@  s[    !!d!+>88CLIICM]FKKBKC"M
r)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  r  @  s      S r)   c                *  a ^ RI o^ RIpV P                  RR7      p ! V3R lRVP                  4      pVe   VP                  VR&   VP
                  VR&   V'       d!   VR,          pVP                  R	 R
7       WdR&   VP                  VRV^R7      pV# )z1Return 'extractRAWDICT' converted to JSON format.NTr  c                  $   < ] tR tRtV 3R ltRtR# )*TextPage.extractRAWJSON.<locals>.b64encodei@  c                	z   < \        V4      \        \        39   d    SP                  V4      P	                  4       # R # r+   r  r  s   &&r'   r   2TextPage.extractRAWJSON.<locals>.b64encode.default@  r  r)   r,   Nr  r  s   r'   r  r  @  r  r)   r  r  r3  r  c                B    V R ,          ^,          V R ,          ^ ,          3# r  r,   r  s   &r'   r
  )TextPage.extractRAWJSON.<locals>.<lambda>@  r  r)   r  r  r  r  r  s   &&&    @r'   extractRAWJSONTextPage.extractRAWJSON@  s    !!d!+	8(( 	8
 >88CLIICM]FKKBKC"Mjj1jM
r)   c                	v    \        V4      p\        V4      p\        P                  ! V P                  W4^ 4      pV# ru  )r+  r   fz_copy_selectionr   )r&   pointapointbr   rI  r  s   &&&   r'   extractSelectionTextPage.extractSelection@  s3    V$V$''		1;r)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  r  @  s     / / /r)   c                    V'       g   V P                  ^ 4      # V P                  4       R,          pVP                  R R7       RP                  V Uu. uF  q3^,          NK  	  up4      # u upi )z%Return simple, bare text on the page.rV   c                &    V ^,          V ^ ,          3# rp  r,   r  s   &r'   r
  &TextPage.extractText.<locals>.<lambda>@  s    1Q41,r)   r  r`   )rj  ru  r  r  )r&   r  r  rI  s   &&  r'   extractTextTextPage.extractText@  s]    $$Q''##%a(./wwf-f!f-..-s   A+c                	    V P                   p\        V\        P                  4      '       g   Q h\	        V4      p\        W#4      p\        V4      pV# r+   )r   r@   r   r  r  JM_copy_rectangle PyUnicode_DecodeRawUnicodeEscape)r&   r   ri  rl  r  r   s   &&    r'   r  TextPage.extractTextbox@  sG    YY
*e&7&78888t$!*3-e4	r)   c                F     \        P                  ! T P                  T4      # )z)Return a list with text word information.)r  r   extractWORDSr   r   rq  rv  r   rJ  r0
  r   rw  rx  ry  rz  r  r  JM_is_word_delimiterJM_is_rtl_charr  JM_append_wordr{  r|  )r&   
delimitersbuflenlast_char_rtlr  wbboxri  r  r[  r  r  r  rs   word_nr?  r  word_delimiterthis_char_rtls   &&                r'   r  TextPage.extractWORDS@  s    %%dii<<r)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  r  3A  s     $ $c $r)   c                $    V P                  ^4      # )z&Return page content as a XHTML string.r  r-   s   &r'   extractXHTMLTextPage.extractXHTML3A  r  r)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  r  7A  s     $ $C $r)   c                $    V P                  ^4      # )z$Return page content as a XML string.r  r-   s   &r'   
extractXMLTextPage.extractXML7A  r  r)   c                    V P                   p\        P                  ! VP                  P                  4      p\        P
                  ! V4      pRVn        V# )zTextPage current poolsize.N)r   r   Poolr   poolfz_pool_size)r&   r  r  r  s   &   r'   poolsizeTextPage.poolsize;A  sA    		zz%**//0!!4(r)   c                v    V P                   pVP                  P                  p\        V4      p\	        V4      pV# )zPage rectangle.)r   r   rJ  rp  r+  )r&   ri  rJ  r  s   &   r'   r   TextPage.rectCA  s6     YY
((11h'3i
r)   c                   \        V P                  V4      pV'       g   V# \        V4      p\        V4       F0  p\	        WF,          4      pV'       d   WtV&   K"  VP
                  WF&   K2  	  V'       d   V# ^ pWe^,
          8  dt   WF,          pWF^,           ,          p	VP                  V	P                  8w  g   W,          P                  '       d   V^,          pKb  W,          WF&   WF^,            V^,          pK  V# )z)Locate 'needle' returning rects or quads.)JM_search_stext_pager   r9   rS  r)  r   r  r  )
r&   needlehit_maxr
  r  rD   rg  rc  v1v2s
   &&&&      r'   r  TextPage.searchMA  s    "499f5JCuASVAA  J!)mBUBuu~"'!3!3!3QWCFE
QJE
r)   rt  r  rZ  ru  r+   )rx   r  )r/   r0   r1   r2   r   rj  ro  rr  ru  r  r  r  r  r  r  r  r  r  r  r  r  r   r{  r   r  extractTEXTr3   r,   r)   r'   r  r  @  s    	*9
2h
$.`,
*/6p$$  4 Kr)   r  c                  d    ] tR tRtRR lt]R 4       tRR ltRR ltR t	RR R	 llt
RR
 ltRtR# )r  ijA  Nc                   \         P                  ! 4       V n        W n        W0n        \        V4      V n        \        ^^ ^ R^ V P                  P                  4      V n	        V P                  ( V n
        \        4       V n        RV P                  n        \        4       V n        RV P                  n        \        4       V n        RV n        R# )z;Stores text spans for later output on compatible PDF pages.z'Position following last text insertion.zAccumulated area of text spans.TNr  )r   fz_new_textr   r]  rp  r+  r   r  r3  r  r8  r)  r  rc  r  r  
used_fontsr   )r&   	page_rectr]  rp  s   &&&&r'   r   TextWriter.__init__lA  s    %%'	
O	!Q2q$))*:*:;XXI	'"K!B%r)   c                	    \        \        P                  ! V P                  \        P                  ! R 4      \        P
                  ! 4       4      4      p\        V4      pV# r+   )rp  r   fz_bound_textr   FzStrokeStater|  r+  r  s   & r'   _bboxTextWriter._bbox}A  sC    u22DIIu?R?RSW?XZ_ZhZhZjkl3i
r)   c           
        \        V4      V P                  ,          pVf   \        R4      pVP                  '       g    \'        RTP                   R24      hV'       d.   V P)                  V4      pRP+                  \-        V4      4      p^ p\.        P0                  ! V4      p	\3        V4      p
\.        P4                  ! V^ ^ WJP6                  V
P8                  4      p^ p^ pV^ 8X  d0   \.        P:                  ! V P
                  VP
                  WWW4      pM#\=        V P
                  VP
                  WWW4      p\?        V4      p\        VRR 4      V P@                  ,          V n!        V PD                  V P@                  ,          V n#        V PF                  V PB                  3pVPH                  R,          ^8X  d   V PJ                  PM                  V4       V# )z8Store 'text' at point 'pos' using 'font' and 'fontsize'.Nr  zUnsupported font 'r  r`   rK  r  )'r)  r8  r  r  r%   r   r   r   t3matrixr6  r]  use_glyph_bboxwidth_countwidth_default
has_digestr   r{  r|  mupdf_font_namer   	clean_rtlr  r  r   r  r+  fz_make_matrixri  rj  fz_show_stringJM_show_string_csr{  r  r  r  r  r  r  r  )r&   r@  r   r  r   rI  right_to_leftr>  r{  rH  r  trm
markup_dirr=  r  s   &&&&&&&&       r'   ro   TextWriter.appendA  sm   Cj499$<<D 1$))B?@@>>$'D778D>*DM11(;S!""8Q8SS!##F
?&&		499c_ipC#TYY		3e\fmC$BC/DHH4dhh.nndoo-::f"OO%
r)   c           
     	    VR ,          pV F0  pV P                  WW4WVR7       V;P                  V,          un        K2  	  V P                  V P                  3# )r  )r  r   rI  r>  )ro   rj  r  r  )	r&   r@  r   r  r   rI  r>  r  r  s	   &&&&&&&  r'   appendvTextWriter.appendvA  sP    S.AKKT!  :EEWE  ~~t..r)   c           	     F   V'       g   V# VP                  R4      p. p\        \        V4      4       Fu  pW$,          p\        V4      ^8  d   K  \        V Uu. uF  p\	        V4      NK  	  up4      ^8  d   KH  RP                  \        V4      4      W$&   VP                  V4       Kw  	  . p\        \        V4      4       F  pV. 8X  d   VP                  W4,          4       K#  W4,          VR,          ^,           8  dU   \        V4      ^8  d:   \        W'^ ,          VR,          ^,            4      W'^ ,          VR,          ^,           % W4,          .pK  W4,          VR,          ^,           8X  g   K  VP                  W4,          4       K  	  RP                  V4      pV# u upi )a  Revert the sequence of Latin text parts.

Text with right-to-left writing direction (Arabic, Hebrew) often
contains Latin parts, which are written in left-to-right: numbers, names,
etc. For output as PDF text we need *everything* in right-to-left.
E.g. an input like "<arabic> ABCDE FG HIJ <arabic> KL <arabic>" will be
converted to "<arabic> JIH GF EDCBA <arabic> LK <arabic>". The Arabic
parts remain untouched.

Args:
    text: str
Returns:
    Massaged string.
r   r`   r  )r8   rS  r9   r'  r:  r  r  ro   )r&   r   wordsr  rg  r   r  idx2s   &&      r'   r  TextWriter.clean_rtlA  s?    K

3s5z"AAFQJ#q&9q!s1vq&9":S"@778A;/

1 # s3xArzCF#$r(Q,&t9q=4<1gR155Eq'DHqL1 x48a<'CF# ! xx+ ':s   F
c               H    V ^8  d   QhRRRRRRRRR	R
RRRRRRRRRRRRRR/# )r  r  z'TextWriter'r   r   r   rK  r@  r   r  ztyping.Optional[Font]r   r  r  r  r  r6   warnr   r"  r>  rs  r   r,   )r  s   "r'   r  TextWriter.__annotate__A  s     ` ` `` *` 	`
 (` ` !` ` `  ` ` `r)   c                8
  a aaa
a%a&a'a( \        V4      pVP                  '       d   \        R4      h\        S4      \        Jd   \	        R4      oVVV
3R lo(VVV
3R lo&VVV
V 3R lo%SR,          pS(! R4      pVP
                  V,
          o'VP                  V,           pV&3R lpV%V'V(3R	 lpSP                  pSP                  pV'       g   VV,
          ^8:  d   R
pMVV,
          pMTpSV,          pS'pVe   \        V4      pMVP                  VSV,          3,           pW19  d   \        R4      hV\        8X  d   RpMV\        8X  d   RpM^ p\        V4      \        J d   VP                  4       pM*. pV F"  pVP                  VP                  4       4       K$  	  \!        VP"                  VP$                  ,
          V,          4      ^,           p. p. p\'        V4       EF  w  ppVR9   dJ   VP)                  VV34       VP
                  V,
          pVP)                  \+        V4      ^,
          4       KW  V^ 8X  d   VP,                  VP.                  ,
          pMVP
                  V,
          pV	'       d   S P1                  V4      pS(! V4      pVV8:  d7   VP)                  VV34       VP)                  \+        V4      ^,
          4       K  VP3                  R4      pV! VV4      w  pp\+        V4      p RP5                  VRV 4      p \7        VRV 4      VV^,
          ,          ,           p!V!V8:  d,   VP)                  V V!34       VVR pVVR p\+        V4      pRp M	V^,          p\+        V4      ^ 8X  d   EK  V'       d   K  Q h	  \+        V4      p"V"V8  d5   RV RV" R2p#Vf   M&V'       d   \9        RV#,           4       M\        V#4      h\        4       p$V\+        V4      ^,
          .,          p\;        V4       F  p VP=                  ^ 4      w  ppT	'       d   RP5                  \E        T4      4      pT^ 8X  d   Tp$T\F        8X  d:   TT9  d3   TS'8  d,   T! T$T4       TT$n        T$;P$                  T,          un        K  T^ 8  g   TP.                  T8X  d(   T$;P.                  TT,
          T,          ,          un        S%! T$T4       TT$n        T$;P$                  T,          un        K  	  V#   \>         d    \@        ^8  d   \C        4          T# i ; i)a  Fill a rectangle with text.

Args:
    writer: pymupdf.TextWriter object (= "self")
    rect: rect-like to receive the text.
    text: string or list/tuple of strings.
    pos: point-like start position of first word.
    font: pymupdf.Font object (default pymupdf.Font('helv')).
    fontsize: the fontsize.
    lineheight: overwrite the font property
    align: (int) 0 = left, 1 = center, 2 = right, 3 = justify
    warn: (bool) text overflow action: none, warn, or exception
    right_to_left: (bool) indicate right-to-left language.
zfill rect must not empty.r  c                ,   < SP                  V SSR7      # )zReturn length of a string.r   r>  )r  ri  r  r   r>  s   &r'   r  (TextWriter.fill_textbox.<locals>.textlenB  s"    ##H $  r)   c                ,   < SP                  V SSR7      # )z5Return list of single character lengths for a string.r2  )rA  r3  s   &r'   rA  -TextWriter.fill_textbox.<locals>.char_lengthsB  s    $$Qj$QQr)   c                2   < SP                  WSSSR 7      pV# ))r  r   r>  r
  )r@  r   rI   r  r   r>  r  s   && r'   append_this,TextWriter.fill_textbox.<locals>.append_thisB  s&    --D8
   C Jr)   皙?r   c                t  < . p. pV F  pS! V4      p\        V4      pW`8:  d%   VP                  V4       VP                  V4       K@  \        V4      pV^ 8  g   KT  \        VRV 4      pW`8:  d;   VP                  VRV 4       VP                  V4       WGR pWWR p\        V4      pKW  V^,          pKb  	  W#3# )z.Cut any word in pieces no longer than 'width'.N)r  ro   r9   )	r  r*  nwordsword_lengthsr   wl_lstwlrG   rA  s	   &&      r'   
norm_words+TextWriter.fill_textbox.<locals>.norm_wordsB  s    FL%a[;MM!$ ''+ K!eVBQZB{ae,$++B/bE!'KQ' ( ''r)   c                  < VP                  R4       Uu. uF  q"R8w  g   K  VNK  	  pp\        V4      pV^ 8X  d   R# V^8X  d   S
! W^ ,          4       R# \        V Uu. uF  pS! V4      NK  	  up4      pV^,
          pSV,
          V,          pV F%  pS
! W4      w  rV	P                  V,           V n        K'  	  R# u upi u upi )zJustified output of a line.r   r`   N)r8   r9   r  ri  )r  rs   r   r*  r<  r*  gapsgaplr@  r  r8  	std_widthr  s   &&        r'   output_justify/TextWriter.fill_textbox.<locals>.output_justify5B  s     !%

3;17QQE;ZF{{E8,%0%Qgaj%01BA:DNd*D#E-$$+   < 1s   B=B=Cr  NzText must start in rectangle.r  r  r`   zOnly fitting  of z lines.z	Warning: )r`   r   )$r+  r  r   r   r  r  r  r:  r;  r)  r*  r  r  r  r  r  r6   r  rj  rZ  ro   r9   r  ri  r  r8   r  r  rv   rS  r  r  r  r{   r  r  ))r  r   r   r@  r  r   r  r  r.  r"  r>  	tolerance	space_len	std_startr@  rF  rR  rS  r  
LINEHEIGHTr  r  	textlinesrs   	max_lines	new_lines
no_justifyrg  r*  r*  r=  rG   line0r?  r  r   r  r8  rA  rE  r  s)   f&&&ff&&&&f                          @@@@r'   fill_textboxTextWriter.fill_textboxA  s|   6 Dz===899:T!<D		R	 	 sN	CL	JJ*	GGi'		(4	$ mmnnSyA~) G'
 ?*C''Y377C?<== %%F&&FF :)II  !23  355J67!;		
 +GAty   $	!23

Y.!!3y>A#57Av#%%

Y.''-BU{  $,!!3y>A#57 JJsOE #-UE":E<E
Ar+bq)*Y!a%-@@;$$eR[1!!"IE#/#3LE
A EFAu:?qqQ ,^ YI!)D@C|c)* o%s9~)**
y!A$==+b
 wwx~.Av**q
/BrI~ud+#:%1u*EBJ&00t$EGGGz!G1 "4 /  '1,0@* /s   S44 TTc	                   \        V4       \        V P                  VP                  ,
          4      R8  d   \        R4      hVeZ   \	        V4      \
        \        39  g5   \	        V^ ,          4      \        Jg   \	        V^,          4      \        Jd   \        R4      hVe   Ve   \        R4      h\        VRR4      e   VR'8X  d   V P                  pVf   V P                  p VP                  4       p	^p
V^ 8  d
   V^8  d   Tp
^p. R(OpV'       d   \        V4      w  rV^8X  d   \        P                  ! 4       pM2V^8X  d   \        P                   ! 4       pM\        P"                  ! 4       p\        P$                  ! V	P'                  4       ^4      p\        P(                  ! R4      p\        P*                  ! V	P'                  4       \        P,                  ! 4       W4      p\        P.                  ! VV P0                  \        P,                  ! 4       VVV
\        P2                  ! \        P4                  4      4       \        P6                  ! V4       \9        W4      p\;        V4      pVV3pTpV^ ,          pV^,          pVw  ppVP=                  4       pVP?                  V4      pVe
   RV R	2pR
pMR;ppR.pV'       d   VPA                  V4       VPB                  pVPD                  R)9   d3   VP                  PF                  VP                  PH                  ,
          pM^ pVPJ                  p\M        V4      '       g   VPN                  ^ 8w  g   V^ 8w  dM   VPA                  R\Q        VPR                  VPT                  VPN                  ,           V,
          34       R24       V'       dc   V^ ,          V PV                  ,          p \        ^^4      PY                  V PR                  V PT                  4      pV( V^,          ,          V,          pV'       g	   V'       d+   VPA                  \Q        \[        V4      4      R,           4       V EF  p!V!P]                  R4      '       d   K  V!R8X  d)   VPA                  V!4       VPA                  VR R24       KL  V!P]                  R4      '       d8   \_        V!Pa                  4       ^ ,          R,          4      V,           p"RV"R R2p!EM\V!P]                  R4      '       d   V!Pa                  4       p#\c        V#^,          4      p$V^ 8w  d   V$R,          p%M^p%VPA                  \Q        V%4      R,           4       \_        V#^ ,          R,          4      V,           p&RPe                  RV&R 2.V#R,          ,           4      p!MV!P]                  R4      '       d#   VPA                  V!Pg                  RR4      4       MqV!P]                  R4      '       d#   VPA                  V!Pg                  RR 4      4       M8V!P]                  R!4      '       d"   VPA                  V!Pg                  R!R"4      4       VPA                  V!4       EK
  	  V'       d   VPA                  V4       VPA                  R#4       R$Pe                  V4      Pi                  R%4      p\j        Pm                  VVVR&7       RpV Pn                   F  p&\q        VV&4       K  	  V# )*a  Write the text to a PDF page having the TextWriter's page size.

Args:
    page: a PDF page having same size.
    color: override text color.
    opacity: override transparency.
    overlay: put in foreground or background.
    morph: tuple(Point, Matrix), apply a matrix with a fixpoint.
    matrix: Matrix to be used instead of 'morph' argument.
    render_mode: (int) PDF render mode operator 'Tr'.
rV  zincompatible page rectNz%morph must be (Point, Matrix) or Nonez$only one of matrix, morph is allowedr  r  r  z BDCEMCr`   rc  r|  z cmBTrH  z Trz gsr  NNz/Alp TfrG  z wr+  r   z/Fr	  z rgr  RGz gz Gz kz Kr  r#   r  )r  r  r  r  )9ro  r,  r   r   r   r   r   r)  r  r   r]  rp  r,  rB  r   r  fz_device_cmykfz_device_grayrZ  r1  r0
  pdf_new_pdf_devicer|  fz_fill_textr   r  fz_default_color_paramsr  JM_merge_resourcesr  r  r  ro   r  ru  r3  r  rJ  r   r  r   ri  rj  r8  rK  r  r  r6   r8   r  r  r  r  r  r  r  repair_mono_font)'r&   r   rp  r]  r  r-  r  rI  r  r  r  ncol	dev_colorr  ri  rK  r  max_numscont_stringr  r  r  max_alpmax_fontold_cont_linesr  r  r  new_cont_linesr  r}  r  r  rs   alpr  r7  r   r  s'   &&&&&&&&&                              r'   r  TextWriter.write_textB  sh    	Dtyy499$%,566UE4=0E!H~U2E!H~V3 !HII%"3CDD7K.6'R-llG=JJEnn&GE!|!D$I"7">qy"002
"113
"113
**7;;=!<I**40H**GKKM5>>;KYaCIINN$''(E(EF !!3' *7>H0(;K,FCq6a&$ ++-,,R0'$'CCNC#!!#&""==I%II$$tyy6EE]]88ruuzUaZ!!HYbddRUUlU>R7S-T,UUX"YZa499$A1aL--acc1337EVeAh&.FF!!)HV,<"="EF"D}}U##t|%%d+%%Qs&;<}}U##$**,q/"-.8c!WC(u%%zz|d1g!#AA%%ilT&9:472;'(2xx2d1X$r( :;u%%%%dll4&>?t$$%%dll4&>?t$$%%dll4&>?!!$'5 #6 !!#&e$))N+227;tWg>OODT4( $
r)   )
rp  r  r8  r  r]  r   r  r   r   r  r  )Nrr  Nrx   rx   )Nrr  NF)NNrr  Nrx   NFF)Nr  r  NNrx   rx   )r/   r0   r1   r2   r   r{  r  ro   r'  r  rR  r  r3   r,   r)   r'   r  r  jA  s?    "  
*X/,\`DD Dr)   r  c                     ] tR tRtRtR tR tR tR tR t	R t
R	R
RR
RR
RR
RR
RR
/R ltR tR tR tR tR tR tR tR tR t]R 4       t]R 4       t]R 4       tR tR R ltR  tR! tR" tR# t]R$ 4       t]R% 4       t ]R& 4       t!R' t"R( t#R) t$]R* 4       t%]R+ 4       t&]R, 4       t']R- 4       t(R. t)R/ t*]R0 4       t+]t,]t-]'t.](t/R1t0R
# )2r  iNC  z
IRect() - all zeros
IRect(x0, y0, x1, y1) - 4 coordinates
IRect(top-left, x1, y1) - point and 2 coordinates
IRect(x0, y0, bottom-right) - 2 coordinates and point
IRect(top-left, bottom-right) - 2 points
IRect(sequ) - new from sequence or rect-like
c                	H    \         P                  W4      P                  4       # r+   )r+  r  r  r  s   &&r'   r  IRect.__add__XC      ||D$**,,r)   c                	H    \         P                  W4      P                  4       # r+   )r+  r  r  r9  s   &&r'   r  IRect.__and__[C  rn  r)   c                	,    \         P                  W4      # r+   )r+  r|  r9  s   &&r'   r|  IRect.__contains__^C  s      ))r)   c                	6   \        VR 4      '       g   R# \        V4      ^8H  ;'       dq    V P                  V^ ,          8H  ;'       dS    V P                  V^,          8H  ;'       d5    V P                  V^,          8H  ;'       d    V P
                  V^,          8H  # r  )r=   r9   r  r  r  r  r  s   &&r'   r  IRect.__eq__aC  sz    q)$$1v{jjtww!A$jj477ad?jjtwwRSTURVjj[_[b[bfghifj[jjr)   c                	l    V P                   V P                  V P                  V P                  3V,          # r+   r  r  s   &&r'   r  IRect.__getitem__fC  rR  r)   c                	*    \        \        V 4      4      # r+   r  r-   s   &r'   rT  IRect.__hash__iC  r  r)   r  NrJ  r  r  r  r  c               	b    \        VR VRVRVRVRVRV/ w  V n        V n        V n        V n        R# )r  rJ  r  r  r  r  N)util_make_irectr  r  r  r  r  s   &$$$$$$*r'   r   IRect.__init__lC  s?    -<t-n-nr-nVX-n]_-ndf-nkm-n*$'47r)   c                	    ^# rY  r,   r-   s   &r'   r  IRect.__len__oC  r  r)   c                	H    \         P                  W4      P                  4       # r+   )r+  r  r  r  s   &&r'   r  IRect.__mul__rC  rn  r)   c                	v    \        V P                  ) V P                  ) V P                  ) V P                  ) 4      # r+   )r  r  r  r  r  r-   s   &r'   r  IRect.__neg__uC  s+    dggXx$''DGG8<<r)   c                	H    \         P                  W4      P                  4       # r+   )r+  r  r  r9  s   &&r'   r  IRect.__or__xC  s    {{4#))++r)   c                	    \        V 4      # r+   r  r-   s   &r'   r  IRect.__pos__{C  rq  r)   c                	8    R \        \        V 4      4      ,           # r  r  r-   s   &r'   r   IRect.__repr__~C  r  r)   c                	    \        V4      pV^ 8X  d	   W n        R# V^8X  d	   W n        R# V^8X  d	   W n        R# V^8X  d	   W n        R# \        R4      hr"  )r6   r  r  r  r  r  r#  s   &&&r'   r$  IRect.__setitem__C  s_    F!VqW  !VqW
 	 !VqW  !VqW  122r)   c                	H    \         P                  W4      P                  4       # r+   )r+  r'  r  r  s   &&r'   r'  IRect.__sub__C  rn  r)   c                	H    \         P                  W4      P                  4       # r+   )r+  r.  r  r  s   &&r'   r.  IRect.__truediv__C  s    (..00r)   c                B    \        V P                  V P                  4      # r  r  r-   s   &r'   r1  IRect.bottom_leftC  r  r)   c                B    \        V P                  V P                  4      # r  r  r-   s   &r'   r.  IRect.bottom_rightC  r  r)   c                	P    \        ^ V P                  V P                  ,
          4      # ru  r  r-   s   &r'   r3  IRect.heightC  r  r)   c                $    V P                  V4      # )zCheck if x is in the rectangle.r  r9  s   &&r'   r  IRect.containsC  r  r)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  IRect.__annotate__C  r  r)   c                D    \        V P                  V P                  V4      # r  r  r  s   &*r'   r  IRect.get_areaC  r  r)   c                P    V P                   P                  V4      pVP                  # )z$Extend rectangle to include point p.)r   r  r  )r&   r  r   s   && r'   r  IRect.include_pointC  s     yy&&q)zzr)   c                P    V P                   P                  V4      pVP                  # )z(Extend rectangle to include rectangle r.)r   r  r  )r&   r$  r   s   && r'   r  IRect.include_rectC  s     yy%%a(zzr)   c                H    \         P                  W4      P                  4       # )z4Restrict rectangle to intersection with rectangle r.)r+  r  r  r  s   &&r'   r  IRect.intersectC  s    ~~d&,,..r)   c                	,    \         P                  W4      # r+   )r+  r  r9  s   &&r'   r  IRect.intersectsC  s    t''r)   c                v    V P                   V P                  8  ;'       g    V P                  V P                  8  # r  r  r-   s   &r'   r  IRect.is_emptyC  r  r)   c                    V P                   V P                  u;8H  ;'       d
    \        8H  Mu ;'       d/    V P                  V P                  u;8H  ;'       d
    \
        8H  # u # )zTrue if rectangle is infinite.r  r-   s   &r'   r  IRect.is_infiniteC  r  r)   c                v    V P                   V P                  8*  ;'       d    V P                  V P                  8*  # r  r  r-   s   &r'   r  IRect.is_validC  r  r)   c                p    V P                   '       d   \        4       # V P                  P                  W4      # r  r  r  s   &&&r'   r-  IRect.morphC  r  r)   c           	     	v    \         P                  ! \        V  Uu. uF  qV,          NK  	  up4      4      # u upi r+   r  r  s   & r'   rO  
IRect.normC  r  r  c                    V P                   V P                  8  d$   V P                   V P                  uV n        V n         V P                  V P                  8  d$   V P                  V P                  uV n        V n        V # )z)Replace rectangle with its valid version.r  r-   s   &r'   rs  IRect.normalizeC  r   r)   c                n    \        V P                  V P                  V P                  V P                  4      # r  r  r-   s   &r'   rM  
IRect.quadC  r  r)   c                	    \        V 4      # r+   r  r-   s   &r'   r   
IRect.rectC  s    Dzr)   c                B    \        V P                  V P                  4      # r
  r  r-   s   &r'   r-  IRect.top_leftC  r  r)   c                B    \        V P                  V P                  4      # r  r  r-   s   &r'   r0  IRect.top_rightC  r  r)   c           	        \        V4      pV P                  '       g7   V P                  '       g%   VP                  '       g   VP                  '       d   \        R4      h\	        ^^ ^ ^V P
                  ) V P                  ) 4      \	        VP                  V P                  ,          VP                  V P                  ,          4      ,          \	        ^^ ^ ^VP
                  VP                  4      ,          # r  r  r  s   &&r'   r  IRect.torectC  s    Gt}}}FGGq!QDGG8dggX64::-qxx$++/EFGAq!QTT14401	r)   c                	H    \         P                  W4      P                  4       # r+   )r+  r  r  r  s   &&r'   r  IRect.transformC  s    ~~d&,,..r)   c                	P    \        ^ V P                  V P                  ,
          4      # ru  r  r-   s   &r'   r  IRect.widthC  r  r)   r  )1r/   r0   r1   r2   rc  r  r  r|  r  r  rT  r   r  r  r  r  r  r   r$  r'  r.  r{  r1  r.  r3  r  r  r  r  r  r  r  r  r  r-  rO  rs  rM  r   r-  r0  r  r  r  r+  r  r*  r  r3   r,   r)   r'   r  r  NC  s   --*k
7!o o$ o4 oD oT od o-=,*-1 ' ' ' ' ) )$9

/( 8 8 _ _ 9 9%3 8 8   ' ' ' '	/ ) ) 
B	B	B	Br)   r  PDF_ENUM_NAME_CourierCourier-ObliqueCourier-BoldCourier-BoldOblique	HelveticaHelvetica-ObliqueHelvetica-BoldHelvetica-BoldObliqueTimes-RomanTimes-Italic
Times-BoldTimes-BoldItalicr>  r=  r  heithebohebicourcoitcobocobitirotibotiittibisymbzadbr  ifitzColor	ColorBurn
ColorDodgeDarken
Difference	Exclusion	HardLightHueLightenr  MultiplyNormalOverlay
SaturationScreen	Softlightr  c                0    R V  R\        WV34       RV R2# )z<</A<</S/GoTo/D[z	 0 R/XYZ z	]>>/Rect[]/BS<</W 0>>/Subtype/Link>>rP  )r   rI  r  rH  rh  s   &&&&&r'   r
  r
  .E  s2    )9!IiQRWXPYFZE[[defdg  hC  (Dr)   goto2c                    R V  RV R2# )z<</A<</S/GoTo/Dz>>/Rect[r  r,   rQ  s   &&r'   r
  r
  /E  s    s(1#=XYr)   r  c                <    R V  R\        WV34       RV RV RV R2# )z<</A<</S/GoToR/D[z /XYZ z]/F<</F()/UF()/Type/Filespec>>>>/Rect[r  rP  r~  s   &&&&&&&r'   r
  r
  0E  sP    0A!F9VW\]U^K_J``hijhkkpqrps  tM  NO  MP  Pk  /lr)   r  c                    R V  RV RV R2# )z<</A<</S/GoToR/Dz/F(	)>>/Rect[r  r,   r   rI  r  s   &&&r'   r
  r
  1E  s    $4QCs1#YqcId"er)   r  c                    R V  RV RV R2# )z<</A<</S/Launch/F<</F(r  r  r  r,   r  s   &&&r'   r
  r
  2E  s    $:1#U1#E^_`^aa|"}r)   r  c                    R V  RV R2# )z<</A<</S/URI/URI(r  r  r,   rQ  s   &&r'   r
  r
  3E  s    /s)A3>YZr)   r  c                    R V  RV R2# )z<</A<</S/GoTo/D(z)/Type/Action>>/Rect[r  r,   rQ  s   &&r'   r
  r
  4E  s     03HKfgr)   c                      ] tR tRtRtRtR# )r  i7E  z0Raised for documents with file structure issues.r,   Nr/   r0   r1   r2   rc  r3   r,   r)   r'   r  r  7E  s    :r)   r  c                      ] tR tRtRtRtR# )r  i;E  zRaised if file does not exist.r,   Nr  r,   r)   r'   r  r  ;E  s    (r)   r  c                      ] tR tRtRtRtR# )r  i?E  z5Raised when creating documents from zero-length data.r,   Nr  r,   r)   r'   r  r  ?E  s    ?r)   r  r  r:  bidir6  r  r  r  r  rp  r  r  r  zcs-namedar  descriptionr;  r  effectr  rj   r   r  
char_flagsr  r  r3  rY  r  rD   r  r[  r  r  r   r]  rU  r   r  r  spansr  r  r  r  r   rW  r  r=  r  r  r  )fontdescriptorsfontbuffersloaderc                    V'       d
   V^ ,          MRpRRRRRRRR/pWC,          ^ ,          WC,          ^,          ,          ^,          pWP,          V,          # )	rx   r  r&  r'  r(  )r  r  r)  r+  r,  r,   )r  r3  r  r2  r3  r  s   &&&   r'   r  r  G  sM    47D	vt[$dLQA	
agaj	 Q&A9vr)   c                    . pV P                  4       '       g   V# \        V4       F/  pVP                  \        P                  ! WV,           4      4       K1  	  \        V4      # r+   )r  rS  ro   r   r  r  )r  r[  rG   rI   rg  s   &&&  r'   _read_samplesr  G  sN     C>>
AY

E((&1*=> #;r)   c                "    W8*  ;'       d    W8*  # r+   r,   )rH   lowhighs   &&&r'   r  r  G  s    8!!	!r)   c           
     H   \         P                  ! V 4      p\        V4       EF{  pTpWA9   d   K  \         P                  ! W4      p\         P                  ! V\        R 4      4      pVP                  '       g   KX  \         P                  ! V4      p\        V^,
          R	R	4       EF  p\         P                  ! Wh4      p	\         P                  ! \         P                  ! V	\        R4      4      \        R4      4      '       g   K`  \         P                  ! V	\        R4      4      p
\         P                  ! V	\        R4      4      pV
P                  '       dg   \         P                  ! \         P                  ! V
\        R4      4      \        R4      4      '       g   K  \         P                  ! V
\        R4      4      pR	p\         P                  ! V4      '       d/   \         P                  ! V^ 4      p\         P                  ! W4      pMe\         P                  ! V4      '       dJ   \         P                  ! V P                  4       \         P                  ! V4      4      w  p pVP                   pV^ 8  d   EK  TpWA9   g   EK  \         P"                  ! Wh4       EK  	  EK~  	  R# )
r  r  r  r  r  r
  GoTor  Nr  )r   r  rS  r  r  r  r   r  r  r  rI  pdf_lookup_page_numberr  r	  r   r  r   r  )ra  rP  	pagecountrg  rQ  r  r  r  r  r  re  r8
  r{  r  r'  r@  s   &&              r'   rO  rO  G  s   %%c*I9=++S4##Whx.@A   ""6*taxR(A##V/A$$e&8&8!Xi=P&QS[\bScdd''HSM:F%%q(6*:;D   ((%*<*<fhsm*TV^_eVfgg))68C=AC!!4((,,dA622C@$$d++!&!6!6		UE]E]_cEd!e!QmmQwB}&&2+ ) r)   c                    \        V \        P                  \        P                  34      '       g   Q R \	        V 4      : RV : 24       hV P
                  '       g   \        \        4      hR# )ztype(cond)=z cond=N)r@   r   r   r   r   r   rk   MSG_IS_NO_PDF)conds   &r'   
ASSERT_PDFr  G  sV    dU]]E,=,=>??YKDJ=PWRVQXAYY????&& r)   c                 >    \        \        \        \        \        4      # r+   )r  r  r  r,   r)   r'   EMPTY_IRECTr  G      /?OTTr)   c                 *    \        4       P                  # r+   )
EMPTY_RECTrM  r,   r)   r'   
EMPTY_QUADr  G  s    <r)   c                 >    \        \        \        \        \        4      # r+   )r+  r  r  r,   r)   r'   r  r  G      /?SSr)   c                >    \        V 4      '       g   \        R 4      hR# )z No journalling operation startedN)JM_have_operationrk   ra  s   &r'   rd  rd  G  s    S!!:;; "r)   c                 >    \        \        \        \        \        4      # r+   )r  r  r  r,   r)   r'   INFINITE_IRECTr  G  r  r)   c                 *    \        4       P                  # r+   )r  rM  r,   r)   r'   r|  r|  G  s    ?r)   c                 >    \        \        \        \        \        4      # r+   )r+  r  r  r,   r)   r'   r  r  G  r  r)   c                v    \        V \        P                  4      '       g   Q h\        P                  ! V 4      pV# )z+
Turn fz_buffer into a Python bytes object
)r@   r   rF  r7  )r4  rI   s   & r'   r#  r#  G  s0     gu~~....

&
&w
/CJr)   c                    V f   R# \        V \        4      '       g   Q R\        V 4      : 24       hV P                  RR4      pRpV F  pV\	        V4      ,          pK  	  V# )Nr`   ztype(c)=rS  surrogateescape)r@   r  r   r  rn  )r  rI  rI   bbs   &   r'   r  r   H  s`    & 	ya,($q'},	*+A
Cs2w Jr)   c                   \        V \        \        34      '       d   T pM\        V R4      '       dl   V P	                  4       p\        V\
        4      '       d   VP                  R4      p\        V\        \        34      '       g   \        R\        V4       24      hM\        P                  ! 4       # \        P                  ! V4      # )z
Make fz_buffer from a PyBytes, PyByteArray or io.BytesIO object. If a text
io.BytesIO, we convert to binary by encoding as utf8.
r  r  z&.getvalue() returned unexpected type: )r@   r  r  r=   r  r  r  rk   r   r   rF  r  )r   r  s   & r'   r.  r.  H  s    
 &5),--		$	$ dC  ;;w'D$	 233DT$ZLQRR 4 ~~//55r)   c                J    \        V 4      '       g   R # \        W,          4      # r+   )rJ  r  )r  r  s   &&r'   JM_FLOAT_ITEMr$  /H  s    C  ?r)   c                v    V\        V 4      8  d)   W,          p\        V\        \        34      '       d   ^ V3# R# )rx   r  )r9   r@   r6   r  )r  r  r  s   && r'   r  r  4H  s3    
SX~xdS%L))d7NNr)   c                   ^ p^p^p	Rp
V
'       d   TpMTpRpTp\        V4      p\        P                  ! V4      p\        V4      p\        P                  ! VV4      p\        P
                  ! W4      p\        P                  ! V4      p\        P                  ! V 4      pVP                  '       dF   \        P                  ! V4      \        P                  ! V4      8X  d   \        P                  ! V4      pW8w  EdA   \        P                  ! V4      pVP                  '       d   \        P                  ! V4      pW8X  d:   \        V4       F)  p\        P                  ! VV\        P                  4       K+  	  M\        V4       F)  p\        P                  ! VV\        P                   4       K+  	  M\        P"                  ! V4      '       d   \        P$                  ! ^ 4      pMWVP                  '       dF   \        P                  ! V4      \        P                  ! V4      8w  d   \        P$                  ! ^ 4      p\        P&                  ! VVW4      pV'       d   \        P(                  ! V4       M\        P*                  ! V^4       \        P,                  ! VV4      pV'       dA   \        P.                  ! VV\        P0                  ! 4       \        P2                  ! 4       4       M?\        P4                  ! VV\        P0                  ! 4       \        P2                  ! 4       4       \        P6                  ! V4       V# )zZ
Pixmap creation directly using a short-lived displaylist, so we can support
separations.
TN)r  r   r  r  fz_intersect_rectr  fz_round_rectfz_document_output_intentr   r@  fz_keep_colorspacefz_page_separationsfz_count_separationsrS  fz_set_separation_behaviorFZ_SEPARATION_SPOTFZ_SEPARATION_COMPOSITEfz_page_uses_overprintfz_new_separationsr  r/  r0  rM  r  r|  rj  fz_run_page_contentsr  )r1  r   r  r  r  r  r  
SPOTS_NONESPOTS_OVERPRINT_SIM
SPOTS_FULLFZ_ENABLE_SPOT_RENDERINGspotsr  r  r  r   rclipr6  oirG   rg  r  r  s   &&&&&&&                r'   r  r  <H  sR   
 JJ##DJs#Ft$DD!E""4/D""40Dt$D 
	(	(	-B	}}}  $(=(=b(AA11"5J ((.???**40A"qA44T1e>V>VW " qA44T1e>[>[\ "))$// ++A.D]]]u44R8E<Q<QR\<]]
 ++A.D

'
'
D$
FCc"((d3

"
"63
/C$U^^%5u~~7GH""4enn.>@PQ	#Jr)   c                    V # r+   r,   r  s   &r'   r  r  H  s    Hr)   c                    V ^8  d   QhRRRR/# r  r  typing.Sequencers  r   r,   )r  s   "r'   r  r  H  s     I I IE Ir)   c                .    \        \        R  V 4      4      # )c                >    \        V 4      R 8  d   \        V ^4      # ^ # )g-C6?r,  r  r  s   &r'   r
  JM_TUPLE.<locals>.<lambda>H      c!fnuQ{C!Cr)   r   r  r  s   &r'   r  r  H      CQGHHr)   c                    V ^8  d   QhRRRR/# r<  r,   )r  s   "r'   r  r  H  s     I I IU Ir)   c                .    \        \        R  V 4      4      # )c                >    \        V 4      R 8  d   \        V ^4      # ^ # )rV  r@  r  s   &r'   r
  JM_TUPLE3.<locals>.<lambda>H  rB  r)   rC  rD  s   &r'   	JM_TUPLE3rJ  H  rE  r)   c                    V f   R# \        V \        4      '       d   V P                  R4      p \        V \        4      '       g   Q R\	        V 4      : RV : 24       hV # )Nr`   rS  ztype(s)=z s=)r@   r  r  r  r   r  s   &r'   r	  r	  H  sS    y!UHHVa1($q'4QD11Hr)   c                   \        V \        P                  4      '       g   Q h\        V 4      p\        P                  ! V 4      p\        V4      p^ p \         RV V 2pWd9  d   MV^,          pK   \        V4      p\        P                  ! V\        V4      4      p\        P                  ! VRV4       ^ VP                  4       P                  n        R# )zs
Add a unique /NM key to an annotation or widget.
Append a number to 'stem' such that the result is a unique name.
-r/  N)r@   r   r   r   r  r  JM_annot_id_stemr  pdf_new_stringr9   r  r1  r   rX  )	r   stemr   r&  rs  rg  stem_idresponser   s	   &&       r'   r/  r/  H  s    
 eU^^,,,,5!D##U+I &E	A
%&avaS1	QG$H3x=9D		4.-.DHHJ*r)   c                   \         P                  ! W^ 4      p\         P                  ! V4      '       g   \        \        \
        4       \         P                  ! V\        R4      4      p\         P                  ! V\        R4      4      ^ 8X  g&   \         P                  ! V\        R4      4      ^ 8X  d$   \         P                  ! V\        R4      V4       R# \        \        \
        4       R# )z)
Add OC object reference to a dictionary
r  rs  OCMDr  N)
r   r  r  r  MSG_BAD_OC_REFr	  r  r  r  rU  )ra  r  r  indobjrb  s   &&&  r'   r  r  H  s     ##Cq1FV$$ 01vx'78E0A5x'78A=37 01r)   c                   \        4       pR pR
pR
pR p\        P                  ! V \        R4      4      p\        P                  ! V4      '       d   \        P
                  ! \        P                  ! V^4      4      p\        P                  ! V4      ^8X  dy   \        P                  ! V^4      p\        \        P                  ! V4      4       F>  p\        P                  ! \        P                  ! Wg4      4      pVP                  V4       K@  	  \        P                  ! V \        R4      4      p	V	P                  '       Ed   \        P
                  ! \        P                  ! V	\        R4      4      4      p\        P                  ! \        P                  ! V	\        R4      4      4      pVR8X  d   R p\        P                  ! V	\        R4      4      pVP                  '       db   \        \        P                  ! V4      4       F>  p\        P                  ! \        P                  ! WW4      4      pVP                  V4       K@  	  \        P                  ! V \        R4      4      pVP                  '       d5   \        P                  ! \        P                  ! V\        R4      4      4      p\        4       p
W:\        &   \        V4      V
\         &   W*\"        &   WJR	&   V
# )NBorderBSr:  r
  r`   r  BEIr  r  )r   r   r  r  rI  r  r  r  rS  r  ro   r   r  r7   r  r   dictkey_dashesdictkey_style)r&  dash_pyr  r  r  r  dashrg  r  bs_or%  s   &          r'   r  r  H  s
   fGEEF
C


i();
<C3!!5#6#6Q#?@$)&&Q/DE//67&&(;(;T(EF$ 8 y(4.9D!!5#5#5tXc]#KL!!5#5#5tXc]#KLB;E  $6>>>E//56&&(;(;S(DE$ 7 

i$
8C
~~~!!5#5#5sHSM#JK
&C '?CNJr)   c                   \        4       p\        4       p\        4       p\        P                  ! V \        P                  4      p\        P
                  ! V4      '       dd   \        P                  ! V4      p\        V4       F>  p\        P                  ! \        P                  ! WF4      4      pVP                  V4       K@  	  W!\        &   \        P                  ! V R 4      p\        P
                  ! V4      '       dd   \        P                  ! V4      p\        V4       F>  p\        P                  ! \        P                  ! WF4      4      pVP                  V4       K@  	  W1\        &   V# )r:  )r7   r   r   r  PDF_ENUM_NAME_CrI  r  rS  r  r  ro   dictkey_stroker  dictkey_fill)r&  r%  bcfcr  rG   rg  rf  s   &       r'   r  r  H  s   
&C	BB9e&;&;<A!"qA##U%8%8%>?CIIcN  It,A!"qA##U%8%8%>?CIIcN  Jr)   c                   \        V \        4      '       g   Q hR p^ pV P                  \        4      pV P                  \        4      pV P                  \
        4      pV P                  RR
4      p\        V4      p	\        P                  ! V\        R4      4       \        P                  ! V\        R4      4       \        P                  ! V\        R4      4       V^ 8  d   V	P                  \        4      pVf   V	P                  \        4      pVf   V	P                  \
        4      pV^ 8  d   V	P                  RR
4      p\        V\        4      '       d{   \        V4      ^ 8  dk   \        V4      p\        P                  ! W4      p
V F  p\        P                  ! W4       K  	  \        P                  ! W*\        R4      \        R4      4       \        P                  ! V\        P                  ! V4      \        R4      \        R4      4       V^ 8X  d   \!        V4      pM\        R4      p\        P                  ! W#\        R4      \        R4      4       V^ 8  d   \        P"                  ! V\        R4      ^4       \        P$                  ! V\        R4      4      p\        P&                  ! V\        R4      \        R4      4       \        P(                  ! V\        R	4      V4       R # R # )Nr  rZ  r[  rY  r  r:  r
  r  r\  r  )r@   r7   r:   r  r]  r^  r  r   rH  r  r   r9   rR  pdf_array_push_intrV  pdf_new_realJM_get_border_stylerY  r  rU  rP  )r  r1  r&  r  dashlennwidthndashesnstylencloudsoborderdarrrH  s   &&&         r'   r  r  H  s&   fd####
CGZZ'Fjj.)GZZ'Fzz8R(G y)G 
	8D>2		8D>2		8H#56 zm,++~.~++}-{;;"-7E""sG}q'8w-""C1A$$d. YhtnhsmL	'TNSM	 !|!6*sm	$#G{HTNA>  )Xd^<C#>Xc]G<	 r)   c                    V ^\8X  d   R# ^ T u;8:  d   ^8:  g
   M V ^
8X  d   \        V 4      # RT u;8:  d
   R8:  d    R#  V R8:  d   RV R 2# RV R	 2# )
\   z\u005ci   i  z\ufffd  z\urU  z\U08xrn  r?  s   &r'   make_escapery  3I  s^    	Rx	rSB"H2w	2		 
 	vRH~RH~r)   c                F    \         P                  ! V \        V4      4       R# )z?
APPEND non-ascii runes in unicode escape format to fz_buffer.
N)r   r  ry  )r  r?  s   &&r'   r{  r{  @I  s     
4R1r)   c                   \        V4      pVP                  VP                  VP                  VP                  VVVV3pV P                  V4       V^,           \        P                  ! \        P                  P                  4      3# )z
Functions for wordlist output
)	r  r  r  r  r  ro   r   rq  rv  )r[  r  r  r  r  r  r  r  s   &&&&&&  r'   r  r  GI  sm     	t$AHHHHHHHH	E 
LLA:u||ELL$<$<===r)   c                   \        V 4      p\        P                  ! V\        R4      4      p\        P                  ! V4      '       g"   \        P
                  ! V\        R4      ^4      p\        P                  ! V ^4      p\        P                  ! V\        R4      V4       Ve"   \        P                  ! V\        R4      V4       \        P                  ! V\        R4      \        R4      4       \        P
                  ! V\        R4      ^4      pV'       g   M\        P                  ! V\        R4      4      p\        V4      p	\        V	4       Ff  p
^ p\        W:4      w  rV^8X  d   K  \        P                  ! W^ 4      p\        P                  ! W4      '       g   KP  \        P                  ! W}4       Kh  	  \        P                  ! WV4       R# )	z)
Add OC configuration to the PDF catalog
r}  r*  Nry  	BaseStater  r  r|  )r  r   r  r  rI  rX  rZ  r  rU  r9   rS  r  r  pdf_array_containsrK  )ra  r   rn  r  r  configsr  onarrayrv  rG   rg  r  rh  inds   &&&&          r'   rl  rl  ZI  sX    !#
&C  #x	':;Gw''**C)1DaHC#A	""Ax'7>&&8I+>H	8K0(5/B&&8D>1=G!!3(89GqAD!"(GAAv((#Q7C''33$$g3  
'%r)   c                H   \        W4      p\        P                  ! V4      pV P                  P                  '       g   V# VP
                  VP                  VP                  P                  ,           8  d-   VP
                  VP                  P                  ,
          Vn        V# )z
return rect of char quad
)JM_char_quadr   r`  r   r=  r  r  r  )rs   r?  rc  r$  s   &&  r'   ry  ry  xI  sq     	TA"A??   ttaddR]]''''ttbmm(((Hr)   c                   ^ pV'       d   V'       d   V\        W4      ,          pV\        P                  ! V 4      \        ,          ,          pV\        P                  ! V 4      \
        ,          ,          pV\        P                  ! V 4      \        ,          ,          pV\        P                  ! V 4      \        ,          ,          pV# ru  )
detect_super_scriptr   rq  TEXT_FONT_ITALICrx  TEXT_FONT_SERIFEDrt  TEXT_FONT_MONOSPACEDrn  TEXT_FONT_BOLD)r  rs   r?  r  s   &&& r'   JM_char_font_flagsr  I  s    E$T..	U$$T*-===E	U##D),===E	U((.1EEEE	U""4(>99ELr)   c                   \         '       d@   \        P                  ! \        P                  ! V P
                  VP
                  4      4      # \        V \        P                  4      '       g   Q h\        V\        P                  4      '       g   Q h\        P                  '       d   VP                  # V P
                  P                  '       d   VP                  # \        P                  ! \        P                  ! VP
                  P                  4      4      p\!        V4      p\#        V4      pVP
                  P$                  pW4,
          \&        ,           pV^8  d@   \        P(                  ^ 8X  d+   \        P                  ! VP
                  P                  4      # VP
                  P$                  p\        P*                  ! V4      pVP,                  VP.                  ,
          pVR8  d   RpRpRp\        P(                  '       g   V^8  d   WF,          pW6,          pW4,
          pW5,          V,          pWE,          V,          pV P
                  P0                  P2                  p	V P
                  P0                  P4                  p
\        P6                  ! W) W^ ^ 4      p\        P6                  ! WV
) V	^ ^ 4      pV	R8X  d   ^Vn        ^Vn        \        P6                  ! ^^ ^ ^VP
                  P:                  P2                  ) VP
                  P:                  P4                  ) 4      p\        P6                  ! ^^ ^ ^VP
                  P:                  P2                  VP
                  P:                  P4                  4      p\        P<                  ! \        P                  ! VP
                  P                  4      V4      p\        P<                  ! W4      pV	^8X  d]   VP>                  P4                  ^ 8  dB   W?P>                  n        W?P@                  n        WOPB                  n        WOPD                  n        MHV) VP>                  n        V) VP@                  n        V) VPB                  n        V) VPD                  n        VPB                  P2                  ^ 8  d#   ^ VPB                  n        ^ VP>                  n        VPD                  P2                  VPB                  P2                  ,
          pV\&        8  d   \        PF                  ! W!P
                  PH                  4      pV'       d   \        PJ                  ! VVV P
                  P                  4      pVPB                  P2                  W,          ,           VPD                  n        VPD                  P2                  VP@                  n        \        P<                  ! W4      p\        P<                  ! W4      pV# )zA
re-compute char quad if ascender/descender values make no sense
rV  ?r  皙r  )&r  r   rV  r   r  r   r@   FzStextLineFzStextCharr  r   rM  r=  FzFontll_fz_keep_fontr  JM_font_ascenderJM_font_descenderr  FLT_EPSILONr   r3  r  r  r  ri  rj  r  rH  rU  fz_transform_quadr  r  r  r  r  r  r  )rs   r?  r  rR  rS  r7  asc_dscr6  fwidthr  r  trm1trm2xlate1xlate2rM  cwidthr  s   &&                r'   r  r  I  s    [ ||E..OPPdE--....b%++,,,,%%%wwww<<--bmm.@.@ABD
4
 C
D
!CMMEi+%G!|449||BMM..//
 MMEd#DWWtwwF
Tz###w{mmiG
+
C
+
C
 	AA2qQ2Dqb!Q2D	R!!!Q1r}}/C/C/E/E.EH\H\H^H^G^_F!!!Q1bmm.B.B.D.DbmmFZFZF\F\]F""5<<0B0B#CVLD""4.D 	Av$''))a-				D	D	D	D	
 wwyy1}		WWYY"F))4A++T5$//:O:OPF		FN2DGGI		DGGI""4.D""40DKr)   c           
        \         P                  ! V P                  4      p\         P                  ! V ^ 4      p\	        V4      pV^ 8X  d   R# \         P
                  ! V\        R4      4      p. p\        V4       EF  p\         P                  ! \         P                  ! WF4      4      pV^8X  d   \         P                  ! \         P                  ! \         P                  ! WF4      ^ 4      4      \         P                  ! \         P                  ! \         P                  ! WF4      ^4      4      3pVP                  V4       K  \         P                  ! \         P                  ! WF4      4      pVP                  V4       EK  	  V# )z0
return list of choices for list or combo boxes
NOpt)r   r  r   pdf_choice_widget_options2r9   r  r  rS  r  r  r  ro   )	r   r&  rU  rG   optarrr  rg  r  r  s	   &        r'   JM_choice_optionsr  I  s    ##UZZ0I++UA6DT
AAvHUO<FEAY!4!4f!@A6,,e.A.A5CVCVX^Cbde.fg,,e.A.A5CVCVX^Cbde.fgC LL#**E,?,?,KLCLL#  Lr)   c                   \         P                  ! V\         P                  ! V 4      4      pVP                  VP                  ,
          pVP
                  VP                  ,
          pV^ 8:  g   V^ 8:  d   ^ # V P                  4       pWRP                  V P                  4       ,
          ,          V P                  4       VP                  V P                  4       ,
          ,          ,           p\         P                  ! V P                  4       4      ^8X  d   ^V,
          p Tp\        ^ V4       F  p\         P                  ! W^ 4       V^,          p\         P                  ! W^ 4       V^,          p\         P                  ! W^ 4       V^,          p\         P                  ! WV4       V^,          pV P                  4       '       g   K  \         P                  ! W^4       V^,          pK  	  We,          pV^ 8X  d    ^# V^,          pK   Tp\        V4       F  p\        V P                  4       ^,
          4       F#  p	\         P                  ! WV4       V^,          pK%  	  V P                  4       '       d#   \         P                  ! W^4       V^,          pK  \         P                  ! WV4       V^,          pK  	  We,          pV^ 8X  d    ^# V^,          pK  )zG
Clear a pixmap rectangle - my version also supports non-alpha pixmaps
)r   fz_intersect_irectrR  r  r  r  r  r  rj  rG   ri  r@  r  rS  r  r  )
r8
  r   rI  r   rj  destspandestpr  ri  r  s
   &&&       r'   r1  r1  J  s$    	  E$8$8$>?A	qttA	qttAAva{{}Htvvx(4668qttdffh+GGE T__./14eA1a[$$Ta0Q$$Ta0Q$$Ta0Q$$Te4Q::<<((#6FA ! EAv FA qA4668A:&$$Te4Q ' zz||$$Tc2Q$$Te4Q  	6 	
Qr)   c                J   \        V \        \        34      '       d   V .p \        V \        \        34      '       g   R. 3# \        V 4      R9  d   R. 3# V R,          p\        \        V4      4       F#  pW,          ^ 8  g   W,          ^8  g   K  ^W&   K%  	  \        V4      V3# )r  rV   r  )rx   r  r   r  )r@   r6   r  r   r   r9   rS  )rp  rI   rg  s   &  r'   rB  rB  <J  s    %#u&&utUm,,2v
5z%2v
(C3s8_6A:!CF  s8S=r)   c                F     \        P                  ! T P                  T4      # rv  )r  r   ll_JM_color_countr   r7   r   rR  r  r(  r  r  r  r  r  r  rG   rj  ri  r  fz_is_empty_irectrS  r:   )rS  r  r   r9  r  r  r  r3  rG   	substrider  oldpixrg  r  newpixr:  r  s   &&               r'   r4  r4  NJ  s    &&r}}d;;r)   c                    \         P                  ! V \         P                  4      w  rV'       d   V^ 8X  d   R# \         P                  ! \         P                  ! W4      4      p\         P
                  ! W24       V# )z"
compress char* into a new buffer
N)r    fz_new_deflated_data_from_bufferFZ_DEFLATE_BESTrF  fz_new_buffer_from_datafz_resize_buffer)inbufferr  compressed_lengthr  s   &   r'   JM_compress_bufferr  vJ  s_     $DD!!D
 $)
..66tO
PC	32Jr)   c                   ^ p\         P                  ! 4       pV  F  pVP                  P                  \        P
                  8w  d   K.  V F  p^ pV Fl  p\        WW4      p\        W4      '       g   K!  ^pV'       d   VP                  R4       ^ pVP                  \        VP                  P                  4      4       Kn  	  V'       g   K  ^pK  	  K  	  VP                  4       p	V	# )rx   r#   )r;   StringIOr   r   r   rw  ry  rz  r   ry  r  r  )
r   rl  need_new_liner3
  r  rs   line_had_textr?  r$  r  s
   &&        r'   r  r  J  s    M[[]F  E$=$==DM *#D,,$%M$T*()LLR]]__!=>  } !    	AHr)   c                   \         P                  ! 4       p^pTpTpW8  d   RpTpTp\        V4      pTp	 \        WV4      '       g   M\         P                  ! W	4      p
\         P
                  ! V
4      p\         P                  ! WK4      w  rp\         P                  ! W\         P                  ! 4       \         P                  ! 4       4       \         P                  ! V4       Rp\         P                  ! WKWV4      p\         P                  ! VRV4       W,          p	K  \         P                  ! 4       p^Vn        ^Vn        ^Vn        ^Vn        ^Vn        ^ Vn        ^ Vn        ^ Vn        ^ Vn        ^Vn        ^ Vn        \         P2                  ! R4      p\         P4                  ! V4      p\         P6                  ! VVV4       VP9                  4        \         P:                  ! V4      p\=        V\>        4      '       g   Q hV# )zl
Convert any MuPDF document to a PDF
Returns bytes object containing the PDF, created via 'write' function.
Ni    r  ) r   r   r  r  rm	  r  pdf_page_writer  r|  rj  r  rH  rI  rS
  rZ
  rV
  rW
  rX
  r^
  rT
  rU
  rY
  r\
  r]
  r[
  r0
  r1
  ri
  rE	  r7  r@   r  )r1  r  rT  r`  r	  r-  r  rh  ry  rg  r   rJ  r  ri  rK  rL  rU  r%  rF	  r  s   &&&&                r'   r  r  J  s   
  FD
A
A	w
6
"C
A
a  !!#)&&t,#(#7#7#I $U^^%5u~~7GHc"%%fQfb(3		   "DDODDDDDDMDDNDMDN


d
#C
..
C	VS$/$$S)AaHr)   c           
     ,   \         P                  ! \         P                  ! \         P                  ! V 4      R 4      4      p\         P                  ! V\         P
                  4      p\         P                  ! V4      p \        WV4       \         P                  ! V\        R4      V4       V\         P                  8X  dv   V\        \        ,          ,          p\         P                  ! \         P                  ! V 4      \         P                  ! V4      \        R4      \        R4      \        R4      4       \         P                  ! \         P                  ! V 4      R4      pVP                  '       ga   \         P                   ! V ^4      p\         P                  ! \         P                  ! V 4      V\        R4      \        R4      \        R4      4       \         P"                  ! W4       V#   \$         d    \&        '       d   \)        4        \         P*                  ! Y4       T\         P                  8X  d^   \         P                  ! \         P                  ! T 4      \         P                  ! T4      \        R4      \        R4      \        R4      4       h i ; i)zRoot/AcroForm/SigFlagsr+  r  r  r  zRoot/AcroForm/Fieldsr  )r   r  r|  r  pdf_create_annot_rawrT  r  JM_set_field_typer  r  PDF_WIDGET_TYPE_SIGNATURESigFlag_SignaturesExistSigFlag_AppendOnlyrV  rU  r   rR  rK  rk   r  r{   r  )	r1  r   r   	fieldnameold_sigflagsr   r&  r  r	  s	   &&&&     r'   r  r  J  s   ##E$7$78I8I#8NPh$ijL
 &&tU-C-CDE##E*I&#$/&&y(3-K5222#'>AS'STH%%c*%%h/V$Z(Z( ""5#4#4S#9;QR&&sA.D%%c*V$Z(X& 	T- L  N$4t+5222%%c*%%l3V$Z(Z( 	s   <C3G( 0A6G( (J?BJc                   \         '       d   \        P                  ! V 4      # \        V 4      p\        P
                  ! \        P                  ! V \        R4      4      4      p\        P                  ! V4      '       g   \        P                  ! V4      '       d   TpVP                  VP                  ,
          pVP                  VP                  ,
          pW2n        WBn
        V# )z
return a PDF page's CropBox
r  )r  r   r	  ri  r   r  r  r  r  r  r  r  )rL  rJ  r	  r  r  s   &    r'   r	  r	  K  s     {))8$H..x)9LMG   ))U-C-CG-L-L	wzz	!B	wzz	!BJJNr)   c                    \        V 4      p\        VP                  VP                  ,
          4      p\        VP                  VP
                  ,
          4      p\        P                  ! W#4      pV# r+   )r	  r,  r  r  r  r  r   fz_make_point)rL  r   r   r"  r  s   &    r'   JM_cropbox_sizer  K  sO    hDDGGdggADGGdggAq$DKr)   c                D    \        V 4      p\        P                  ! V4      # )z
just the inverse of rotation
)r  r   r*  )r   mps   & r'   re  re   K  s     
t	$B!!"%%r)   c                   ^ p\         P                  ! V ^4      p\         P                  ! V\        R4      ^4       \         P                  ! V\        R4      ^4      p\         P                  ! V\        R4      V4       \         P                  ! V\        R4      V4       \         P                  ! V\        R4      V4       \         P
                  ! V\        R4      \        R4      4       Rp	\         P                  ! V \         P                  ! V	4      \         P                  ! 4       ^ 4      p
\         P
                  ! V\        R4      V
4       \        W
W4       \         P                  ! V4      w  rk\         P                  ! V
\        R	4      V4       \         P                  ! V
\        R
4      V4       \         P                  ! V
\        R4      ^4      p\         P                  ! V\        R4      V4       V# )z=
embed a new file in a PDF (not only /EmbeddedFiles entries)
r  r  r  r  r  r  Filespecs     rR  r  r  r  )r   rZ  rY  r  r  rU  r/  r  r0  r0  rT  rP  )ra  r  rj   rW  r  r  r  r  efbsr  r@  paramss   &&&&&&       r'   r  r  (K  sp    D


S!
$C	C$3		 	 htna	8B	""3x@	""3	B	""3(8$?	sHV,hz.BC	B004LLN	A 
r8C=!,SS+%%c*GD	1htnd3	1hx0$7$$Q(:A>F	68F#3T:Jr)   c                   \         P                  ! \         P                  ! V 4      \        R4      4      p\         P                  ! V\        R4      4      pVP                  '       d<   \         P
                  ! V4      ^ 8X  d!   \         P                  ! V\        R4      4       \         P                  ! V\        R4      \        R4      \        R4      4      pVP                  '       d$   \         P                  ! V\        R4      R4       R# R# )z
perform some cleaning if we have /EmbeddedFiles:
(1) remove any /Limits if /Names exists
(2) remove any empty /Collection
(3) set /PageMode/UseAttachments
r  
Collectionr  r  r	  r  N)	r   r  r  r  r   r  rH  r   r\  )ra  r  collefiless   &   r'   rf
  rf
  MK  s     u00#68HID dH\$:;D5--d3q84,!78  W_%W	F hz&:<LM r)   c                t    V P                   '       g   R # \        P                  ! V 4      p\        VRR7      pV# )r`   r  errors)r   r   r7  r  )r  r  r  s   &  r'   r  r  eK  s/    ???$$T*A
*1Y
?CJr)   c           	     :   \         P                  ! \         P                  ! V 4      \        R4      4      pVP                  '       g   \         P
                  ! ^4      pRpV F  pV\        V4      ,          pK  	  \         P                  ! \         P                  ! V 4      \        R4      ^4      p\         P                  ! V\         P                  ! V\        V4      4      4       \         P                  ! V\         P                  ! V\        V4      4      4       R# R# )z
Store ID in PDF trailer
r
  r`   N)r   r  r  r  r   
fz_memrnd2rn  rX  rK  rP  r9   )ra  r  rnd0rndrg  s   &    r'   rg
  rg
  mK  s     

e//4htn
EC>>># A3q6MC &&(9(93(?$QRSc5#7#7c#h#GHc5#7#7c#h#GH r)   c                   \         P                  ! \         P                  ! \         P                  ! V 4      \        R4      4      \        R4      4      pVP                  '       d   V# \         P                  ! \         P                  ! V 4      \        R4      4      p\         P
                  ! V\        R4      ^4      p\         P                  ! V\        R4      ^ 4       \         P
                  ! V\        R4      ^4      p\         P                  ! V\        R4      ^ 4       \         P                  ! V\        R4      ^ 4       \         P                  ! V\        R4      ^ 4       \         P                  ! V\        R4      ^ 4       V# )	z/
Ensure OCProperties, return /OCProperties key
r  rX  r|  r  r  r  r~  RBGroups)r   r  r  r  r   rY  rX  )ra  r  r  r  s   &   r'   r  r  }K  s    

U//0A0A#0FQWHXY[cdr[s
tC
~~~
e//4hv6FGD

!
!$(@!
DC	S(6"2A6Xc]A6A	Q2	Q3	Q 115	Q 4a8Jr)   c                   V '       g   R# V P                  R4      '       d   R# V P                  R4      '       d   R# V P                  R4      '       d   R# V P                  R4      '       d   R# V P                  R4      '       d   R	# V P                  R
4      '       d   R	# V P                  R4      '       d   R# V P                  R4      '       d   R# R# )z
Make /DA string of annotation
r  Cor  coTir  tiSySymbrB  Zar  za)r5   r,  s   &r'   JM_expand_fnamer  K  s     6tvtvtvtvtvtvtvtvr)   c                H   V \         P                  8X  d   R# V \         P                  8X  d   R# V \         P                  8X  d   R# V \         P                  8X  d   R# V \         P
                  8X  d   R# V \         P                  8X  d   R# V \         P                  8X  d   R# R# )	z
String from widget type
ButtonCheckBoxRadioButtonTextListBoxComboBox	Signaturer  )r   r  r  r  PDF_WIDGET_TYPE_TEXTPDF_WIDGET_TYPE_LISTBOXPDF_WIDGET_TYPE_COMBOBOXr  )r  s   &r'   JM_field_type_textr  K  s~     ,,,...111***---...///r)   c                   \        V \        P                  4      '       g   Q h\        P                  ! V\        P                  ! V 4      4      pVP
                  VP                  ,
          pVP                  VP                  ,
          pV^ 8:  g   V^ 8:  d   ^ # V P                  4       pWRP                  V P                  4       ,
          ,          V P                  4       VP                  V P                  4       ,
          ,          ,           p Tp\        V4       FI  p\        V P                  4       4       F)  p	\        P                  ! WW,          4       V^,          pK+  	  KK  	  We,          pV^,          pV^ 8X  g   Ku   ^# ru  )r@   r   r  r  rR  r  r  r  r  r  rj  rG   ri  rS  r  )
r8
  rf  rI  r   rj  r  r  r  ri  rg  s
   &&&       r'   r  r  K  s   dENN++++  E$8$8$$?@A	qttA	qttAAva{{}Htvvx(4668qttdffh+GGE
qADFFH%$$Tcf5Q &  		Q6r)   c                ,   \        V \        P                  4      '       g   Q hRp\        P                  ! V 4      p^ p\	        V 4      p\        P
                  ! V4      p \        V\        P                  4      '       g   Q hVP                  '       g   Mv\        P                  ! V4      p\        P                  ! VR4      pVP                  '       d    \        P                  ! Wb4      '       g   ^pM\        P                  ! V4      pK  V'       d   V# R# )z
Return the first annotation whose /IRT key ("In Response To") points to
annot. Used to remove the response chain of a given annotation.
Nr;  )
r@   r   r   r  r   rJ  r   r  r  rU  )r   r  r&  r  r   irt_annot_objr  s   &      r'   r  r  K  s    
 eU^^,,,,I##E*IE5!D%%d+I
)U^^4444###++I6u5<<<##A11((3	 r)   c                    \        V \        P                  4      '       g   Q h\        P                  '       d   R# \        P
                  ! V 4      # )+
need own versions of ascender / descender
rT  )r@   r   r  r  r   r/  )r  s   &r'   r  r  K  s;     dELL))))%%%!!$''r)   c                    \        V \        P                  4      '       g   Q h\        P                  '       d   R# \        P
                  ! V 4      pV# )r  gɿ)r@   r   r  r  r   rD  )r  rI   s   & r'   r  r  K  sA     dELL))))%%%

!
!$
'CJr)   c                     V ^ 8:  g   V ^8X  g   RT u;8:  d
   R8:  d    R#  MR# V'       g   R# \        V 4      pV F  pW28X  g   K   R# 	  R# )z7Check if ch is an extra word delimiting character.
    i*   i.   TFrw  )r?  r  rb  rH  s   &&  r'   r  r  K  sW     	
89R!6! 	 " r7D9  r)   c                &    V R 8  g   V R8  d   R# R# )i  i 	  FTr,   rx  s   &r'   r  r  L  s    	EzR%Zr)   c                    \        V \        P                  4      '       g   Q h\        P                  ! V 4      pVP	                  R 4      p\
        P                  '       g   VR8X  g   V^8w  d   V# W^,           R # )rG  Nr  )r@   r   r  r  r   r  r   )r  r   r  s   &  r'   JM_font_namer  L  sa    dELL))))d#D		#A   AGqAvA<r)   c           	        ^p\         P                  ! V4      p\        V4       EF7  p\         P                  ! W4      p\         P                  ! W4      p\         P
                  ! V4      '       gH   \         P                  ! R\         P                  ! V4       R\         P                  ! V4       R24       K  \         P                  ! V\         P                  4      p	\         P                  ! V\         P                  4      p
V
P                  '       d   \         P                  ! V
4      '       d'   \         P                  ! V\         P                  4      pMT
p\         P                  ! V\         P                  4      p\         P
                  ! V4      '       d&   \         P                  ! V\         P                   4      p\         P                  ! V4      pRpV'       d   \#        W4      pVV\         P                  ! V	4      \%        \         P                  ! V4      4      \         P                  ! V4      \         P                  ! V4      V3pVP'                  V4       EK:  	  V# )r  r   z' is no font dict ( 0 R)r  )r   r  rS  r  r  r  fz_warnr  r  r  PDF_ENUM_NAME_SubtypePDF_ENUM_NAME_BaseFontr   r  PDF_ENUM_NAME_NamePDF_ENUM_NAME_EncodingPDF_ENUM_NAME_BaseEncodingr  r  ro   )ra  dict_fontliststream_xrefr   rG   rg  refnamer7  r  r  r   r  r  r  r  s   &&&&            r'   JM_gather_fontsr  L  s   	
B5!A1X((2))%3  **MMQu009::MeN^N^_gNhMiinop$$Xu/J/JK%%h0L0LM"""e&7&7&A&A%%h0H0HIDD%%h0L0LMX&&))(E4T4TUH)&s1C!!'*#E$5$5d$;<!!'*!!(+ 	= > Ir)   c                    V ^8  d   QhRRRR/# )r  r  mupdf.PdfObjr  r6   r,   )r  s   "r'   r  r  CL  s     % % %c %r)   c           	        \        V \        P                  4      '       g   Q h^p\        P                  ! V4      p\	        V4       EF  p\        P
                  ! W4      p\        P                  ! W4      p\        P                  ! V4      '       gH   \        P                  ! R\        P                  ! V4       R\        P                  ! V4       R24       K  \        P                  ! V\        R4      4      p	\        P                  ! V	\        R4      4      '       g   K  \        P                  ! V\        R4      4      p
\        P                  ! V\        R4      4      pVP                  '       d   \        P                  ! V4      pM\        P                   ! 4       pV
P                  '       d-   \        P"                  ! \        P$                  ! V
4      V4      pM.\        P&                  ! \        P&                  P(                  4      p\        P                  ! V4      pV\        P                  ! V4      V\+        V4      3pVP-                  V4       EK  	  V# )z.
Store info of a /Form xobject in Python list
r   z' is no form dict (r  r  Formr,  r  )r@   r   r   r  rS  r  r  r  r  r  r  r  r  r  r   pdf_to_matrixr|  r  r  rq  rr  rp  ro   )r1  r  	imagelistr  r   rG   rg  r  	imagedictrb  r  r  r  r6  r  r  s   &&&&            r'   JM_gather_formsr  CL  s    c5,,----	
B5!A1X((%3**54	  ++MMQu009::MeN^N^_hNiMjjopq""9hy.AB  (899y(6*:;y(8*<=<<<%%a(C.."C<<<**E,=,=a,@#FD<< ; ;<D	* !!7+%	 	; < Ir)   c               $    V ^8  d   QhRRRRRR/# )r  r1  zmupdf.PdfDocumentr  r	  r  r6   r,   )r  s   "r'   r  r  kL  s#     7 7+ 7L 7Z] 7r)   c                F   ^p\         P                  ! V4      p\        V4       EF  p\         P                  ! W4      p\         P                  ! W4      p\         P
                  ! V4      '       gH   \         P                  ! R\         P                  ! V4       R\         P                  ! V4       R24       K  \         P                  ! V\        R4      4      p	\         P                  ! V	\        R4      4      '       g   K  \         P                  ! V4      p
^ p\         P                  ! V\        R4      \        R4      4      pVP                  '       d   \         P                  ! V4      p\         P                  ! V\        R4      \        R	4      4      p\         P                  ! V4      '       d   \         P                  ! V^ 4      p\         P                   ! ^ 4      p\         P                  ! V\        R
4      \        R4      4      p\         P                  ! V4      '       d   Tp\         P                  ! V^ 4      p\         P                  ! V\        R4      4      '       g'   \         P                  ! V\        R4      4      '       dK   \         P                  ! V^4      p\         P                  ! V4      '       d   \         P                  ! V^ 4      p\         P                  ! V\        R4      \        R4      4      p\         P                  ! V\        R4      \        R4      4      p\         P                  ! V\        R4      \        R4      4      pV
V\         P"                  ! V4      \         P"                  ! V4      \         P"                  ! V4      \%        \         P                  ! V4      4      \%        \         P                  ! V4      4      \%        \         P                  ! V4      4      \%        \         P                  ! V4      4      V3
pVP'                  V4       EK  	  V# )z'
Store info of an image in Python list
r   z' is no image dict (r  r  r  r  r  Filterr  
ColorSpaceCSDeviceN
Separationr  r:  r  rA  BitsPerComponentBPC)r   r  rS  r  r  r  r  r  r  r  r  r  r  r   rI  r  r0  r  r  ro   )r1  r  r  r  r   rG   rg  r  r  rb  r  genr  r  altcsr  csesr  r3  r  r  s   &&&&                 r'   JM_gather_imagesr  kL  s    
BE"A1X((2**54	  ++MMAe//899MeN^N^_hNiMjjopq""9hy.AB  (9::	*##Ix/@(6BRS""5)C%%i(1CXc]Sg&&))'15GQ  H\,BHTNSb!!D$$T1-B!!"hy&9::((Xl-CDD++D!4%%e,,!//q9E##Ix/@(3-P$$Y0BHSMR!!)X6H-I8TY?[   '  (  %#E$5$5b$9:#E$5$5e$<=#E$5$5g$>?#E$5$5g$>? 	a b Ir)   c                f   \        V \        P                  4      '       g   Q h^ p\        P                  ! V 4      p VP                  '       g   MJV\        P
                  ! \        P                  ! V4      4      8X  d   ^pM\        P                  ! V4      pK^  V'       g   \        RVR R24      hV# )z
retrieve annot by its xref
xref rH  z is not an annot of this page)	r@   r   r   rJ  r   r  r  rU  rk   )r   r  r  r   s   &&  r'   r  r  L  s     dEMM****E!!$'E
5##E$7$7$>??E$$e,%Qx'DEFFLr)   c                   \        V \        P                  4      '       g   Q hV'       g   R# ^ p\        P                  ! V 4      p VP                  '       g   Mb\        P
                  ! \        P                  ! \        P                  ! V4      R4      4      w  rEW8X  d   ^pM\        P                  ! V4      pKv  V'       g   \        RV R24      hV# )z"
retrieve annot by name (/NM key)
Nr/  r   z' is not an annot of this page)
r@   r   r   rJ  r   pdf_to_stringr  r  rU  rk   )r   r   r  r   rS  r  s   &&    r'   r  r  L  s     dEMM****E!!$'E
,,U-@-@ATATUZA[]a-bcE$$U+!D6!?@AALr)   c                   . p\         P                  ! V P                  4       \         P                  4      pVP                  '       g   V# \        \         P                  ! V4      4       Fi  p\         P                  ! W#4      p\         P                  ! VR 4      pVP                  '       g   KD  VP                  \         P                  ! V4      4       Kk  	  V# )r/  )r   r  r  PDF_ENUM_NAME_Annotsr   rS  r  r  r  ro   r  )r   rs  r  rg  r&  r   s   &     r'   r  r  L  s    EU-G-GHFE''/0''2	""9d3???LL((.	 1 Lr)   c                   \         '       d   \        P                  ! V 4      pV# . p\        P                  ! V \        R4      4      p\        P                  ! V4      p\        V4       F  p\        P                  ! W$4      p\        P                  ! V4      p\        P                  ! V\        R4      4      pVP                  '       g   Kc  \        P                  ! \        P                  ! V4      4      pV\        P                  8X  d   K  \        P                  ! VR4      p	VP                  Wh\        P                   ! V	4      34       K  	  V# )zC
return the xrefs and /NM ids of a page's annots, links and fields
r  r  r/  )r  r   r	  r   r  r  r  rS  r  r  r   r  r  PDF_ANNOT_UNKNOWNr  ro   r  )
rL  rs  r  rG   rg  r&  r  r  rb  r  s
   &         r'   r	  r	  L  s     {,,h7E8H+=>FV$AAY''3	+$$i)1DE!!!00%2C2CW2MNE+++!!9d3tE$<$<c$BCD  Lr)   c                    V P                  R R7      p V P                  '       g   \        4       # \        V P	                  4       4      # Fr  )r,  r   r   r	  r  r   s   &r'   r  r  L  s3    >>5>)D???v!488:..r)   c                   \         P                  pV f   V# T pVP                  R4      '       g   VP                  R4      '       d   \         P                  pV# VP                  R4      '       g   VP                  R4      '       d   \         P                  pV# VP                  R4      '       g   VP                  R4      '       d   \         P
                  pV# VP                  R4      '       g   VP                  R4      '       d   \         P                  pV# VP                  R	4      '       g   VP                  R
4      '       d   \         P                  pV# )z/
return pdf_obj "border style" from Python str
rI  r  rH  r  rg  r\  r3  Ur  r
  )r   PDF_ENUM_NAME_Sr5   PDF_ENUM_NAME_BPDF_ENUM_NAME_DPDF_ENUM_NAME_IPDF_ENUM_NAME_U)r  r  r  s   &  r'   rk  rk  L  s    

C}
A	
c		all3//%:O:OC
 J	 
c		all3//%:O:OC J 
c		all3//%:O:OC J 
c		all3//%:O:OCJ 
c		all3//%:O:OCJr)   c
                  a	 V	3R lp
^ pRpV'       d!   \         P                  ! RW^ 4      pV
! V4      # V'       d,   \        V4      p\         P                  ! RW^ 4      pV
! V4      # VR8  d   \         P                  ! V4      pV
! V4      # V '       dP   \         P
                  ! V 4      pVP                  '       d	   V
! V4      # \         P                  ! WV4      pV
! V4      # \         P                  ! W44      w  rpRpV'       d   \         P                  ! RWV^ 4      pVP                  '       d	   V
! V4      # \         P                  ! W4WV4      pV
! V4      # )z.
return a fz_font from a number of parameters
c                   < V P                   '       g   \        \        4      hV P                   P                  P                  '       g   \
        P                  ! V S4       V # r+   )r   r   MSG_FONT_FAILEDr  rZ  r   fz_set_font_embedding)r  r(  s   &r'   fertigJM_get_font.<locals>.fertigM  sB    //$$000''e4r)   Nr  )r   fz_new_font_from_filer.  r  fz_new_cjk_fontfz_new_base14_fontr   fz_new_builtin_fontfz_lookup_noto_fontr  fz_load_fallback_font)r   r%  r&  r$  rH  r  r%  r&  r'  r(  r2  r  r  r%  r  r  s   &&&&&&&&&f      r'   r#  r#  M  s+    ED**D(1Ed| ,,,dCBd|"}$$X.d| ''1???$<((IFd| 116@DD,,dDqId|&&hSD$<r)   c                6   V^8  d   R# \         P                  ! W4      p\         P                  ! V\        R4      4      pVP                  '       dM   \         P
                  ! \         P                  ! V^ 4      4      p\         P                  ! V\        R4      4      pM \         P                  ! V\        R4      4      pVP                  '       g   \        R4       R# TpRp\         P                  ! V\        R4      4      pVP                  '       d   Tp\         P                  ! V\        R4      4      pVP                  '       d   Tp\         P                  ! V\        R4      4      pVP                  '       d   Tp\         P                  ! V\        R4      4      pVP                  '       d*   \         P                  ! V4      '       g   \        R	4       R# \         P                  ! V\        R
4      4      '       d   Mq\         P                  ! V\        R4      4      '       d   MJ\         P                  ! V\        R4      4      '       d   M#\        R\         P                  ! V4      : 24       V'       g   \        R4       R# \         P                  ! V4      # )z8
Return the contents of a font file, identified by xref
Nr9  rH  z%invalid font - FontDescriptor missingFontFile	FontFile2	FontFile3r  invalid font descriptor subtypeType1CCIDFontType0COpenTypezwarning: unhandled font type zwarning: unhandled font type)r   rJ  r  r  r   r  r  rv   r  r  r  r"  )r1  r  r  desftr  r   s   &&    r'   r  r  MM  s    axc(Aq(+<"=>E(()<)<UA)FG  h/?&@A  H-=$>?>>>79AF


Q 4
5C
~~~


Q 5
6C
~~~


Q 5
6C
~~~  hy&9:>>>%"3"3C"8"856S(8"455sH_$=>>sHZ$8993E4E4Ec4J3MNO./  ((r)   c                   \         P                  ! V \        R4      \        R4      4      pVP                  '       g   R# \         P                  ! V4      pV^8  d   R# . p\        V4       Fm  p\         P                  ! W4      p\         P                  ! W4      p\         P                  ! V4      p\         P                  ! V4      pVP                  Wx34       Ko  	  V# )zy
Return the items of Resources/Properties (used for Marked Content)
Argument may be e.g. a page object or a Form XObject
r<  
Propertiesr,   )r   r   r  r   r  rS  r  r  r  r  ro   )	r  
propertiesrG   r   rg  r  r  r  r  s	   &        r'   r  r  M  s    
 $$S(;*?,AWXJ   	z*q5IqA((7C((7C!!#&A##C(DIIqi   Ir)   c                2   Rp\         P                  ! V 4      pVP                  '       dM   \         P                  ! V4      pV\         P                  ! V4      8X  d   RpM\         P
                  ! V4      pK^  V'       g   \        RV R24      h\        V4      # )z
retrieve widget by its xref
FTr  z is not a widget of this page)r   rR  r   r  r  rV  rk   r   )r   r  r  r   r&  s   &&   r'   re  re  M  s     E""D)E



''/	5##Y//E%%u-5&CDEE%=r)   c                ,  a \         P                  ! V P                  4      p\        V P                  4      pVP	                  4       pT pV3R lpR p\         P
                  ! VP                  4      pVSn        V\         P                  8X  d1   \         P                  ! WB4      '       d   V! RR4       MV! RR4       M	V! RR4       V! SR\        \         P                  ! V4      4      4       V! SR\        \        V4      4      4       \         P                  ! V4      p	V! SR	V	4       R
 p
V
! V\        R4      4      pVe   V! SRV4       RpV\         P                  8X  d   \         P                  ! V\        R4      4      pVP                   '       d   V! SR\         P"                  ! V4      4       \         P                  ! V\        R4      4      pVP                   '       d   \         P$                  ! V4      pV'       g   \         P&                  ! V4      pV! SR\        V4      4       V! SR\         P(                  ! V4      4       \         P*                  ! \         P,                  ! V\        R4      \        R4      4      4      pV^ 8X  d   ^pV! SRV4       \         P,                  ! V\        R4      \        R4      4      p\         P.                  ! V4      '       dk   \         P0                  ! V4      p^ .V,          p\3        V4       F1  p\         P4                  ! \         P6                  ! VV4      4      VV&   K3  	  V! SRV4       V! SR\         P8                  ! VP                  4      4       V! SR\         P:                  ! VP                  4      4       \         P,                  ! V\        R4      \        R4      4      p\         P.                  ! V4      '       dk   \         P0                  ! V4      p^ .V,          p\3        V4       F1  p\         P*                  ! \         P6                  ! VV4      4      VV&   K3  	  V! SRV4       \         P,                  ! V\        R4      \        R4      4      p\         P.                  ! V4      '       dk   \         P0                  ! V4      p^ .V,          p\3        V4       F1  p\         P*                  ! \         P6                  ! VV4      4      VV&   K3  	  V! SRV4       V! SR\=        V 4      4       \         P>                  ! \         P@                  ! V\        R4      4      4      pV! SR \        V4      4       \         P,                  ! V\        R4      \        R!4      4      pVP                   '       d(   V! SR"\        \         P>                  ! V4      4      4       V! SR#\         PB                  ! V4      4       SPE                  4        \         P                  ! V\        R$4      4      p\G        V4      pV! SR%V4       V! SR&\G        \         P,                  ! V\        R'4      \        R(4      4      4      4       V! SR)\G        \         P,                  ! V\        R'4      \        R*4      4      4      4       V! SR+\G        \         P,                  ! V\        R'4      \        R,4      4      4      4       V! SR-\G        \         P,                  ! V\        R'4      \        R.4      4      4      4       V! SR/\G        \         P,                  ! V\        R'4      \         PH                  ! R04      4      4      4       V! SR1\G        \         P,                  ! V\        R'4      \         PH                  ! R24      4      4      4       R# )3zy
Populate a Python Widget object with the values from a PDF form field.
Called by "Page.first_widget" and "Widget.next".
c                    < \        SW4       R # r+   r  )r  r   rZ  s   &&r'   SETATTR)JM_get_widget_properties.<locals>.SETATTRM  s    #r)   c                    \        WV4       R # r+   rI  )modr  r   s   &&&r'   SETATTR_DROP.JM_get_widget_properties.<locals>.SETATTR_DROPM  s     	% r)   r  TFNr  r  r  c                   T p^p V P                   '       g   R# \        P                  ! W4      pVP                   '       d!   \        P                  ! V4      pV'       d   V# \        P                  ! V \	        R4      4      p V P                   VP                   8X  d   \        R4      hV^,          pV^ 8X  g   K  \        P                  ! V\	        R4      4      p^pK  )z
This is a modified version of MuPDF's pdf_dict_get_inheritable(), with
some changes:
* Returns string from pdf_to_text_string() or None if not found.
* Recurses to parent if current node exists but with empty string
  value.
Nr  zcycle in resources)r   r   r  r  r  rk   )r  r  slowhalfbeatr  r  s   &&    r'   'pdf_dict_get_inheritable_nonempty_labelIJM_get_widget_properties.<locals>.pdf_dict_get_inheritable_nonempty_labelM  s     ???$$T/C~~~005 L%%dHX,>?D$//1 455MH1}))$0BCr)   TUr  r  r  r  r  r  rZ  r:  r  r  r  r  r  MKBGr_  BCr  r  r^  r  r=  r  r  r  r$  r  rW  Kr  r  r  Vr  r  r  Blr  Fo)%r   r  r   r   r1  pdf_widget_typer  r  pdf_signature_is_signedr	  pdf_field_border_styler  pdf_load_field_namer  r  r  r   r  r  pdf_field_valuepdf_field_displayr  r   rI  r  rS  r  r  pdf_text_widget_max_lenpdf_text_widget_formatr  r  r  pdf_field_flagsr  JM_get_scriptr  )r   rZ  r&  r   ra  twrJ  rN  r  r  rS  r  fvaluer  r  rG   rH  rg  rf  r  r  sss   &f                    r'   JM_get_widget_propertiesrj  M  s    ##EJJ/I5::&D
((*C	B$! &&rww/J"FU444((88K&K&T"):5;W;WXa;b)cd,.?@RS]@^._`**95Jz28 4Ix~NEV]E2FU666  )Xh-?@>>>e.>.>.DE  HTN;>>>&&s+F&&y1(9&(AB%*A*A)*LM$$U%8%8HTNT\]`Ta%bcLq6


i$#
GC#$C!GqA##E$7$7Q$?@AaD V_a0(E(Ebgg(NO(D(DRWW(MN


i$$
HC#$cAgqA&&u':':3'BCCF V\3/


i$$
HC#$cAgqA&&u':':3'BCCF V^S1*;E*BC		!	!%"@"@HUYN"[	\B%6r%:;


i$$
HC
~~~V-/@AYAYZ]A^/_`(=(=i(HI  	9hsm4A	q	B2&%--i$RUWX %--i$RUWX %--i$RUWX %--i$RUWX %--i$I[I[\`Iabc %--i$I[I[\`Iabcr)   c                   V^8  d   R# \         P                  ! W4      p\         P                  ! V\        R4      4      pVP                  '       dM   \         P
                  ! \         P                  ! V^ 4      4      p\         P                  ! V\        R4      4      pM \         P                  ! V\        R4      4      pVP                  '       g   R# Tp\         P                  ! V\        R4      4      pVP                  '       d   R# \         P                  ! V\        R4      4      pVP                  '       d   R# \         P                  ! V\        R4      4      pVP                  '       d   \         P                  ! V\        R	4      4      pVP                  '       d*   \         P                  ! V4      '       g   \        R
4       R# \         P                  ! V\        R4      4      '       d   R# \         P                  ! V\        R4      4      '       d   R# \         P                  ! V\        R4      4      '       d   R# \        R\         P                  ! V4       R24       R# )z>
Return the file extension of a font file, identified by xref
r  r9  rH  r;  pfar<  ry  r=  r  r>  r?  cffr@  cidrA  rx  zunhandled font type 'r   )r   rJ  r  r  r   r  r  r  rv   r  r  )r1  r  r  rB  r  s   &&   r'   r  r  LN  s    axc(Aq(+<"=>E(()<)<UA)FG  h/?&@A  H-=$>?>>>A


Q 4
5C
~~~


Q 5
6C
~~~


Q 5
6C
~~~  hy&9:>>>%"3"3C"8"856S(8"455sH_$=>>sHZ$899+E,=,=c,B+C1EFr)   c                ,   \        4       p\        P                  ! V 4      '       dn   \        P                  ! V 4      p\	        V4       FH  p\        P
                  ! W4      p\        P                  ! V4      pWQ9  g   K7  VP                  V4       KJ  	  V# )zx
Get OCG arrays from OC configuration
Returns dict {"basestate":name, "on":list, "off":list, "rbg":list, "locked":list}
)r   r   rI  r  rS  r  r  ro   )rp  list_rG   rg  r  rE   s   &     r'   JM_get_ocg_arrays_imprq  xN  ss    
 FE3%qA%%s.C##S)D T"	 
 Lr)   c                T   \        4       p\        P                  ! V \        R 4      4      p\	        V4      pV'       d   W1R&   \        P                  ! V \        R4      4      p\	        V4      pV'       d   W1R&   \        P                  ! V \        R4      4      p\	        V4      pV'       d   W1R&   \        4       p\        P                  ! V \        R4      4      p\        P                  ! V4      '       d[   \        P                  ! V4      p\        V4       F5  p\        P                  ! W%4      p\	        V4      pVP                  V4       K7  	  V'       d   W1R&   \        P                  ! V \        R4      4      pVP                  '       d   \        P                  ! V4      pWR	&   V# )
r  ro  r  r
  Lockedrb	  r  r
  r}  r
  )r7   r   r  r  rq  r   rI  r  rS  r  ro   r   r  )	confr   rp  rp  rG   rg  r  list1r  s	   &        r'   rY  rY  N  sC   	B


dHTN
3C!3'E4


dHUO
4C!3'E5	


dHX$6
7C!3'E8FE


dHZ$8
9C3%qA%%s.C)3/ELL  :


dH[$9
:C
~~~!!3';Ir)   c                   \         P                  ! V4      p\        ^ V^4       F  p\         P                  ! \         P                  ! W4      4      p\         P
                  ! V4      p\         P                  ! \         P                  ! W^,           4      4      p\        V^^ 4      p\         P                  ! V4      p\        V\        4      '       g   Q hVP                  R4      pV P                  WX34       K  	  R# )rx   r  N)r   r  rS  r  r  r  r  fz_buffer_extractr@   r  r  ro   )	r  r  rG   rg  r  r{  r  r%  r  s	   &&       r'   r  r  N  s    D!A1a^((%*=*=d*FGs#((%*=*=dE*JK!#q!,##C(!U####HHWsh r)   c                "   V P                   '       g   R# \        P                  ! V \        R4      4      p\        P                  ! V4      pVR8X  d6   \        P                  ! V \        R4      4      pVP                   '       g   R# MR# \        P
                  ! V4      '       d!   \        \        P                  ! V4      4      pM@\        P                  ! V4      '       d#   \        P                  ! V4      p\        V4      pMR# V'       d   V# R# )z
JavaScript extractor
Returns either the script source or None. Parameter is a PDF action
dictionary, which must have keys /S and /JS. The value of /S must be
'/JavaScript'. The value of /JS is returned.
Nr
  
JavaScriptJS)r   r   r  r  r  r  r	  r  r!  r"  r  )r  r  jjjsr$  r%  s   &     r'   rf  rf  N  s     >>>3.A			1	B	\Xd^4}}}  	2"5#;#;B#?@			R	 	 ##B'',
r)   c                |    V P                   P                  '       d    \        P                  ! V ^ 4      '       g   ^ # ^# )z 
Ensure valid journalling state
)r   r)	  r   r4	  r  s   &r'   r  r  N  s,     ~~e&=&=c1&E&Er)   c                   V \         P                  8X  d   R# V \         P                  8X  d   R# V \         P                  8X  d   R# V \         P                  8X  d   R# V \         P
                  8X  d   R# V \         P                  8X  d   R# V \         P                  8X  d   R# V \         P                  8X  d   R# V \         P                  8X  d   R	# V \         P                  8X  d   R
# V \         P                  8X  d   R# V \         P                  8X  d   R# V \         P                  8X  d   R# V \         P                  8X  d   R# R# )z'
return extension for MuPDF image type
faxr  flatelzwrldbmpgifjb2r  jpxjxrr  r  tiffr  )r   FZ_IMAGE_FAXFZ_IMAGE_RAWFZ_IMAGE_FLATEFZ_IMAGE_LZWFZ_IMAGE_RLDFZ_IMAGE_BMPFZ_IMAGE_GIFFZ_IMAGE_JBIG2FZ_IMAGE_JPEGFZ_IMAGE_JPXFZ_IMAGE_JXRFZ_IMAGE_PNGFZ_IMAGE_PNMFZ_IMAGE_TIFF)rb  s   &r'   JM_image_extensionr  N  s     """u"""u$$$w"""u"""u"""u"""u$$$u###v"""u"""u"""u"""u###vr)   c                v   \        V\        P                  4      '       g   Q h\        P                  ! \        P                  P                  4      p\        P
                  ! \        P                  ! V4      V4      p\        P
                  ! V\        4      pV\        V4      3p\        P                  V4       R # r+   )r@   r   r|  rq  rE  r  fz_quad_from_rectg_img_info_matrixJM_py_from_quad
g_img_inforo   )r  r  r   r  r$  rc  r  s   &&&&   r'   JM_image_filterr  N  s~    c5>>****U\\,,-A!8!8!;SAA$56A##Ddr)   c                   V '       g   R# \        V 4      pV^8  d   \        R4       R# T p\        P                  ! V4      pV\        P                  8X  d   R# V'       d   \        P
                  ! W24      pM\        P                  ! W24      p\        P                  ! V4      p\        P                  ! V4      p\        P                  ! V4      w  r\        P                  ! V4      p
\        P                  ! VP                  4       4      p\        4       pVP                  4       V\        &   VP!                  4       V\"        &   WR&   \%        V4      V\&        &   W\(        &   W\*        &   VP-                  4       V\.        &   VP1                  4       V\2        &   \5        V4      V\6        &   W\8        &   V'       d	   Wl\:        &   V# )z
Return basic properties of an image provided as bytes or bytearray
The function creates an fz_image and optionally returns it.
Nr  orientation)r9   rv   r   fz_recognize_image_formatFZ_IMAGE_UNKNOWNr  fz_new_buffer_from_shared_datarz  fz_image_orientation_matrixr  fz_image_orientationr<  r  r7   r   r  r"  r  r{  r  r  r  rG   r  r  r  r  r  r  dictkey_image)r  
keep_imager  r  rb  r%  r  r  r  r  r  cs_namer  s   &&           r'   JM_image_profiler  O  s`   
 	?Dax!"A++Q/E&&&22A<22A<**C0E

+
+U
3C**51JD,,e4K&&(8(8(:;GVF"WWYFM#ggiFN(M/4FN L L"''')F 99;FK-e4FK&O!&Mr)   c                d   V P                  4       p\        P                  ! 4       s\        P                  ! 4       p\        P
                  ! W\        4        ! R  R\        P                  4      pV! 4       p\        ^^^^VR7      p. s\        P                  ! WV4       \        \        4      p. sV# )c                  .   a  ] tR tRtV 3R ltR tRtV ;t# )0JM_image_reporter.<locals>.SanitizeFilterOptionsi4O  c                	D   < \         SV `  4        V P                  4        R # r+   r   r   use_virtual_image_filterr&   r
  s   &r'   r   9JM_image_reporter.<locals>.SanitizeFilterOptions.__init__5O  s    G))+r)   c                	H    \        R \        P                  ! V4      W44       R # r+   )r  r   r|  )r&   r  r  r   r  rp  s   &&&&&&r'   image_filter=JM_image_reporter.<locals>.SanitizeFilterOptions.image_filter8O  s    D%.."5tCr)   r,   r/   r0   r1   r2   r   r  r3   r  r
  s   @r'   SanitizeFilterOptionsr  4O  s    	,	D 	Dr)   r  )r  r  r  r  r	  )r1  r   r|  r  rq  rd  PdfSanitizeFilterOptions2r  r  r  r   )r   r1  rJ  r  sanitize_filter_optionsfilter_optionsr   s   &      r'   r  r  -O  s    
((*C(||~H	T->?D ? ? D 45+)N J	""C~>	z	BJIr)   c                    \        \        R 4      '       * p \        \        R4      '       * p\        \        R4      '       * p\        \        R4      '       * p\        \        R4      '       * p\        \        R4      '       * p\        \        R4      '       * p\        \        R4      '       * p\        \        R4      '       * p\        4       p	WR	&   \        \        P                  4      V	R
&   \        \        P
                  4      V	R&   \        \        P                  4      V	R&   \        \        P                  4      V	R&   \        \        P                  4      V	R&   \        \        P                  4      V	R&   \        \        P                  4      V	R&   \        \        P                  4      V	R&   \        \        P                  4      V	R&   \        \        P                  4      V	R&   \        \        P                  4      V	R&   \        \        P                  4      V	R&   \        \         4      V	R&   \        \        P"                  4      V	R&   W	R&   W)R&   W9R&   WIR&   WYR&   WiR&   WyR&   WR&   \        \        P$                  4      V	R &   V	# )!TOFUTOFU_BASE14TOFU_CJKTOFU_CJK_EXTTOFU_CJK_LANG
TOFU_EMOJITOFU_HISTORICTOFU_SILTOFU_SYMBOLbase14cbzepubr   iccr2  r  r|  ra  zplotter-cmykz	plotter-gz	plotter-nzplotter-rgbz	py-memoryr  tofuztofu-cjkztofu-cjk-extztofu-cjk-langz
tofu-emojiztofu-historicztofu-silztofu-symbolxps)r=   r   r7   r   FZ_ENABLE_CBZFZ_ENABLE_EPUBFZ_ENABLE_HTMLFZ_ENABLE_ICCFZ_ENABLE_IMGFZ_ENABLE_JPXFZ_ENABLE_JSFZ_ENABLE_PDFFZ_PLOTTERS_CMYKFZ_PLOTTERS_GFZ_PLOTTERS_NFZ_PLOTTERS_RGB	JM_MEMORYFZ_ENABLE_SVGFZ_ENABLE_XPS)
	have_TOFUhave_TOFU_BASE14have_TOFU_CJKhave_TOFU_CJK_EXThave_TOFU_CJK_LANGhave_TOFU_EMOJIhave_TOFU_HISTORIChave_TOFU_SILhave_TOFU_SYMBOLrI   s
             r'   JM_fitz_configr  OO  s   %eV44I%e];;%eZ88M%e^<<%e_==%e\::O%e_==%eZ88M%e];;
&C.M"5#6#67CJ"5#7#78CK"5#7#78CK"5#6#67CJ"5#6#67CJ"5#6#67CJ"5#5#56CI"5#6#67CJ"5#9#9:C"5#6#67C"5#6#67C"5#8#89C"9oC"5#6#67CJ'K+
O/0-0+
O."5#6#67CJJr)   c                   \         P                  ! V\        R4      4      p\         P                  ! W\         P                  ! 4       ^ 4      p\         P
                  ! V4      p\         P                  ! V4      '       d;   V'       d   \         P                  ! WE4       V# \         P                  ! WE^ 4        V# \         P                  ! V ^4      pV'       d@   VP                  '       d   \         P                  ! Wt4       \         P                  ! Wu4       M>\         P                  ! Wu4       VP                  '       d   \         P                  ! Wt4       \         P                  ! V\        R4      V4       V# )aO  
Insert a buffer as a new separate /Contents object of a page.
1. Create a new stream object from buffer 'newcont'
2. If /Contents already is an array, then just prepend or append this object
3. Else, create new array and put old content obj and this object into it.
   If the page had no /Contents before, just create a 1-item array.
rS  )r   r  r  r/  r0  r  rI  rK  r3  rR  r   rU  )ra  r  newcontr  rK  newcontsr  carrs   &&&&    r'   r  r  vO  s
    !!'8J+?@H##C%,,.!DHH%D(##  4 K ""8q9 K ""3*"""$$T4  0  0"""$$T47HZ$8$?Kr)   c
                   Rp
RpRp^ p^ p^ pRpRpRpRp\        V 4       V	R8  d   \        P                  ! V	4      w  pppV'       d9   \        P                  ! RVXV^ 4      p
\        P                  ! W
WV4      pRp^ pEMV'       d   \        P
                  ! V4      w  ppV'       d6   \        P                  ! WX^ ^ 4      p
\        P                  ! W
V4      pRp^pMV'       d   \        P                  ! RW%^ 4      p
MI\        V4      pVP                  '       g   \        \        \        4       \        P                  ! RW^ 4      p
V'       g   \        P                  ! W
4      p^ pM\        P                  ! W
V4      p^p\        P                  ! V4      p\!        \        P"                  ! \        P$                  ! V\'        R4      4      4      4      p\)        \        P"                  ! \        P$                  ! V\'        R4      4      4      4      pV'       g   \)        \+        W4      4      p\        P,                  ! V
4      p\        P.                  ! V
4      pVRVRVRVR\1        V4      R	V	R
VRV/.pV# )z
Insert a font in a PDF
Nr  r  r  r   r   r  r<  r  r:  r;  r  )rd  r   r  r  pdf_add_cjk_fontr  pdf_add_simple_fontr4  r.  r   r  r#  r	  r  pdf_add_cid_fontr  r  r  r  r  r	  r  r/  rD  r   )ra  r  r%  r&  r  r  r=  rL  r  r  r  r%  r  ixrefr  r<  r   r   r  extor  r  rR  rS  s   &&&&&&&&&&              r'   r$  r$  O  s/    D
CDEEF
E	D	DDS"}!44X>dE,,T4uaH))#XeL
 44V<JD$00tQJD00HEHDF 224J(4~~~.0@A44T3QG 11#< 44SIX&E 1 153E3EhPXYcPd3e fgDe//1C1CXxXaOb1cdeD !5c!AB

 
 
&C

!
!$
'Ct$v,HCSE Lr)   c                R   \        V \        P                  4      '       d   V # \        V \        4      '       dD   \        P                  ! V P                  V P
                  V P                  V P                  4      p V # \        V \        4      '       dZ   \        P                  ! V P                  V P
                  V P                  V P                  4      p\        P                  ! V4      pV# \        V \        P                  4      '       d   \        P                  ! V 4      pV# V '       d"   \        V 4      '       d   \        V 4      ^8w  d%   \        P                  ! \        P                  4      # . ROp\        ^4       Fq  pW,          W#&   W#,          f'   \        P                  ! \        P                  4      u # W#,          \        8  d	   \        W#&   W#,          \        8  g   Ki  \        W#&   Ks  	  \        P                   ! V^ ,          V^,          V^,          V^,          4      # )z6
PySequence to mupdf.FzIrect. Default: infinite irect
r  )r@   r   r  r  r  r  r  r  r+  rq  rJ  rL  r  rS  r  r  fz_make_irect)r$  rI   r  rg  s   &   r'   rK  rK  O  sj    !U]]##!UMM144qttQTT2!Tll144qttQTT2mmC 
!U\\""mmA
$Q''?1+=+B}}U4455A1Xt4<==!8!8994/!"AD4/!"AD  qtQqT1Q4166r)   c                   \         P                  ! V 4      p\         P                  ! V\        R4      4      p\         P                  ! V4      '       d   \         P
                  ! V4      # \         P                  ! V4      p. p\        V4       Fz  p\         P                  ! W%4      p\         P                  ! V4      '       d   \         P                  ! V^4      pVP                  \        \         P
                  ! V4      4      4       K|  	  V# )z
ListBox retrieve value
rZ  )r   r  r  r  r  r  r  rS  r  rI  ro   r	  )r   r&  r  rG   r  rg  elems   &      r'   JM_listbox_valuer  O  s    
 ##U+IHSM:FF##''00 	V$AE AY""F.t$$&&a0D')A)A4)HIJ	 
 Lr)   c           	        R pV^8  d   VR,          pMV^8X  d   WR^ ,          R R2,          pMnV^8X  d   Q hV^8X  d+   WR^ ,          R RV^,          R RV^,          R R2,          pM4WR^ ,          R RV^,          R RV^,          R RV^,          R R2,          pVR\        V4       RV R2,          p\        P                  ! \        P                  ! V 4      \        P                  V4       R	# )
r`   z0 g r  z g r   z rg z k r	  rX  N)r  r   r  r  PDF_ENUM_NAME_DA)r   ra  rf  r   r   r  s   &&&&& r'   r  r  P  s    
 Cax	a&3	q	a&1SVAJaAqz66a&1SVAJaAqz3q6!*C@@Qx()8*C88C	""5#6#6u#=u?U?UWZ[r)   c                4     \        P                  ! YY#T4      # rv  )4r  r   JM_make_spanlistr   rx  rq  rv  ry  rz  r  r  r  r  r   r  rg  rU  r  r  FZ_STEXT_SYNTHETICr  r  argbr  rR  r  r  r  dictkey_charsr  r
  JM_py_from_pointdictkey_originrp  r  r|  ro   r7   r  dictkey_flagsdictkey_bididictkey_char_flagsr  dictkey_fontr  rn  r  	dictkey_cr   r{  r  dictkey_spans)	line_dictrs   r  r  r  	char_list	span_list	span_rect	line_rect
char_style	old_styler  rJ  span_originr?  r$  r  rU  rR  r  	char_dicts   &&&&&                r'   r  r  *P  s    %%is'JJr)   c                    V P                  4       p\        V4      p\        P                  ! V P                  4      p V'       d;   V\        P
                  \        P                  39   g   V\        P                  8  d=   \        P                  ! V \        P                  ! \        P                  4      4      pRpMVR8X  dR   V P                  4       ^8X  d=   \        P                  ! V \        P                  ! \        P                  4      ^_^4      pM4\        P                  ! \        P                  ! VP                  4      4      p\!        V4      pV P#                  4       V\$        &   V P'                  4       V\(        &   W1\*        &   V P                  4       V\,        &   V P/                  4       V\0        &   V P3                  4       V\4        &   V P7                  4       V\8        &   \;        V4      V\<        &   Wa\>        &   R# )zPopulate a dictionary with information extracted from a given image.

Used by 'Document.extract_image' and by 'JM_make_image_block'.
Both of these functions will add some more specific information.
r  r  N) fz_compressed_image_typer  r   ll_fz_compressed_image_bufferr   r  r  r  fz_new_buffer_from_image_as_pngr  r^  rG    fz_new_buffer_from_image_as_jpegrF  r6  r3
  r#  r   r  r"  r  r  r  r  r  r  r  r  r  r9   r  r  )r2  img_dictimg_typer  ll_cbufr%  r   s   &&     r'   r	  r	  P  sv    ++-H
X
&C 11#..AG	,,e.D.DEEe((( 33''(E(EF 	3557a<44,,U-J-JKRQRT nnU44W^^DEc"F!eegH]"uuwH^[#&557H  XXZH\ XXZH\GGIH[ [H\$]r)   c                X   V P                  4       p\        W!4       VP                  4       pVP                  '       dH   VP	                  \
        P                  ! \
        P                  4      4      pVP                  4       VR &   MRVR &   \        V P                  4       4      V\        &   R# )r  N)r~  r	  r  r   r  r   r  r^  rw  r{  r  r  )r  r  r2  r  r  s   &&   r'   JM_make_image_blockr  P  s    
--/CS%88:D33E4G4GHeHe4fg!335
6!
6!253D3D3F!GJ~r)   c                r     \        P                  ! T P                  YTP                  TP                  4      # rv  )r  r   JM_make_text_blockr   r   rq  rv  r  r'  r6  r  r7   r  r|  r=  dictkey_wmoder  r  dictkey_dirrp  r  ro   dictkey_lines)
r  r  r  r  r  	line_list
block_rectrs   r  r  s
   &&&&&     r'   r  r  P  s-    ''(8(8*4??\c\n\noor)   c                F     \        P                  ! T P                  Y4      # rv  )r  r   rm  r   r   r0
  rq  rJ  fz_contains_rectr6  r  r   FZ_STEXT_BLOCK_IMAGEr  r'  r7   r  r  rp  r  r  r  ro   dictkey_blocks)	rT  rn  r  text_buffer
block_listr  r  r  r  s	   &&&      r'   rm  rm  Q  s    **2==)IIr)   c           	        . ROp\        V \        P                  4      '       d   V # \        V \        4      '       dX   \        P                  ! V P                  V P
                  V P                  V P                  V P                  V P                  4      # V '       d"   \        V 4      '       d   \        V 4      ^8w  d   \        P                  ! 4       # \        ^4       F1  p\        W4      W&   W,          e   K  \        P                  ! 4       u # 	  \        P                  ! V^ ,          V^,          V^,          V^,          V^,          V^,          4      # )rx   )rx   rx   rx   rx   rx   rx   )r@   r   r|  r  r   rI  r  rH  rh  r  rJ  rL  rS  r$  rq  )r  r   rg  s   &  r'   r  r  /Q  s    A!U^^$$!V~~acc133QSS!##qss;;$Q''?1+=+B~~1XQ"4<<<>!  >>!A$!adAaD!A$!==r)   c           	        \         P                  ! \         P                  P                  4      p\         P                  ! \         P                  ! V \        R4      4      4      p\         P                  ! V4      '       g   \         P                  ! V4      '       d   ^ Vn        ^ Vn	        RVn
        RVn        \         P                  ! \         P                  ! VP                  VP                  4      \         P                  ! VP                  VP                  4      \         P                  ! VP                  VP                  4      \         P                  ! VP                  VP                  4      4      pVP                  VP                  ,
          ^8  g#   VP                  VP                  ,
          ^8  d/   \         P                  ! \         P                  P                  4      pV# )z
return a PDF page's MediaBox
r  d    )r   rq  rE  r  r  r  r  r  r  r  r  r  fz_minfz_max)rL  page_mediaboxrJ  s   &  r'   ri  ri  >Q  s8    LL!8!89M  **8Xj5IJH h''5+D+DX+N+NLLLLhkk2LLhkk2LLhkk2LLhkk2	M 	=+++a/-"2"22Q6U\\%<%<=r)   c
                   \         '       d    \        P                  ! V VVVVVVVVV	4
      # Tp
^ p\        P                  ! W2,
          4      ^,           pW#8  d\   TpW8:  dR   \        WWWVWy4       V^,          pV^ 8  d    W,          ^ 8X  d   \        RV RV R24       V^,          pV
^,          p
KW  R# TpW8  dR   \        WWWVWy4       V^,          pV^ 8  d    W,          ^ 8X  d   \        RV RV R24       V^,          pV
^,          p
KW  R# )z
Copy a range of pages (spage, epage) from a source PDF to a specified
location (apage) of the target PDF.
If spage > epage, the sequence of source pages is reversed.
z	Inserted rH  z pages.N)r  r   r  r   fz_absi
page_mergerv   )doc_desdoc_srcspageepageapager`  r5  r  r  	graft_map	afterpagecounterr\  r   s   &&&&&&&&&&    r'   r  r  [Q  s$   " {## 	 IGMM%-(1,E}mw&[qLGq W%<%A)G9Dw?@AIDNI  mw&[qLGq W%<%A)G9Dw?@AIDNI r)   c                    \         P                  ! V P                  4       \        R4      4      pVP                  '       g0   \         P
                  ! V P                  4       \        R4      ^4      p\         P                  ! V\        R4      4      p\         P                  ! V\        R4      4      p\         P                  ! V\        R4      4      p\         P                  ! V\        R4      4      pRpRp\         P                  ! V4      '       Ed   \         P                  ! V4      p	\         P                  ! V4      '       d   \        \         P                  ! V4      4       Fm  p
\         P                  ! \         P                  ! W:4      4      pVP                  R4      '       g   KF  \         P                  ! VR,          4      pW8  g   Kk  TpKo  	  M!\         P
                  ! V\        R4      V	4      pV^,          p\        V	4       F  p
\         P                  ! \         P                  ! WZ4      4      p\         P                  ! VR,          4      V,           pRV 2p\         P                  ! WZ4      p\         P                  ! W=V4       K  	  \         P                  ! V4      '       d   \        \         P                  ! V4      4       Fm  p
\         P                  ! \         P                  ! WJ4      4      pVP                  R4      '       g   KF  \         P                  ! VR,          4      pW8  g   Kk  TpKo  	  M!\         P
                  ! V\        R4      ^4      pV^,          p\        \         P                  ! V4      4       F  p
\         P                  ! \         P                  ! Wj4      4      p\         P                  ! VR,          4      V,           pRV 2p\         P                  ! Wj4      p\         P                  ! WMV4       K  	  Wx3# )	a?  
Merge the /Resources object created by a text pdf device into the page.
The device may have created multiple /ExtGState/Alp? and /Font/F? objects.
These need to be renamed (renumbered) to not overwrite existing page
objects from previous executions.
Returns the next available numbers n, m for objects /Alp<n>, /F<m>.
r<  r@  r  Alpr   r  r	  r  )r   r  r  r  r   rY  r  r  rS  r  r  r5   fz_atoir  r  )r   temp_resri  	main_extg
main_fonts	temp_extg
temp_fontsre  	max_fontsrG   rg  ri  r  r   r  r  s   &&              r'   r_  r_  Q  s    ""488:x/DEI++DHHJ8MqQ	""9h{.CDI##Ix/?@J ""8Xk-BCI##Hhv.>?JGI ##y)Y''5--i89'')?)?	)MN~~e,,MM#b'*;G : //	8K;PRSTI1qA##U%;%;Y%JKCc"g&0A9D(()7C	5  $$u))*56A$$e&<&<j&LMD??3''d2h'A}	 7 ,,Y8H!L
NI5%%j12  %"8"8*"HIMM$r(#i/1#w$$Z3Jc2 3 r)   c                h    \         P                  V 4       \        '       d   \        RV  24       R# R# )z
redirect MuPDF warnings
zMuPDF warning: N)r  ro   JM_mupdf_show_warningsrv   ru   s   &r'   JM_mupdf_warningr>  Q  s,     ""4(/$() r)   c                j    \         P                  V 4       \        '       d   \        R V  R24       R# R# )zMuPDF error: r#   N)r  ro   r  rv   ru   s   &r'   JM_mupdf_errorr@  Q  s,    ""4(-vR() r)   c                H    \        V \        4      '       g   Q h\        W4      # r+   )r@   r   JM_new_bbox_device_Device)r   rX  s   &&r'   rV  rV  Q  s     b$$b55r)   c           
        \        V \        P                  4      '       g   Q h\        P                  ! V P                  P
                  4      p\        P                  ! R4      pV  F  pVP                  P                  \        P                  8X  g   K.  V F  pV Ff  p\        V\        WE4      4      '       g   \        P                  ! V4      '       g   K<  \        P                  ! W%P                  P                  4       Kh  	  \        P                  ! V\        R4      4       K  	  \        P                  ! V\        R4      4       K  	  V# )z)
make a buffer from an stext_page's text
r  r#   )r@   r   r  rq  r   rJ  r0
  r   rw  rz  ry  r  fz_append_runer  r}  r:  )r   r   r  r  rs   r?  s   &     r'   JM_new_buffer_from_stext_pagerE  Q  s     dE--....<<001D


c
"C  E$=$==B,T<3IJJ$)$=$=d$C$C ((mmoo>  $$S#d)4    c$i0  Jr)   c                   Vf   R# \        V4      pVf   R# \        P                  ! VP                  R4      4      p\        P                  ! W\        P
                  ! 4       ^ 4      p\        P                  ! V ^4      p\        P                  ! V\        R4      \        P                  ! R4      4       \        P                  ! V\        R4      V4       V# )z
make new PDF action object from JavaScript source
Parameters are a PDF document and a Python string.
Returns a PDF action object.
NrS  r
  ry  rz  )
r  r   r  r  r/  r0  rG  rU  r  r  )ra  r   r  r%  r  	newactions   &&    r'   JM_new_javascriptrH  Q  s     }D|

.
.t{{6/B
CC!!#ELLNA>F&&sA.I	y(3-1C1CL1QR	y(4.&9r)   c                    \        V 4      # r+   )JM_new_output_fileptr_Outputr  s   &r'   rC	  rC	  R  s    '--r)   c                n    V ^ 8  d   V R,          p K  V R8  d   V R,          p K  V ^Z,          ^ 8w  d   ^ # V # )z:
# return normalized /Rotate value:one of 0, 90, 180, 270
r  r,   )r`  s   &r'   r  r  R  s8     1*#
C-#{aMr)   c                    \         P                  ! R 4      p\         P                  ! V4      p\         P                  ! W@W4       VP	                  4        \         P
                  ! V4       V# )r/
  )r   r0
  r1
  r2
  rE	  fz_terminate_buffer)r  r  r  r%  rF	  s   &&&  r'   r  r  #R  sO    


c
"C
..
C	83	c"Jr)   c                n   V P                   '       g   V# T pVP                   '       Ed   \        P                  ! V4      pW19   g1   \        P                  ! V\	        R4      4      P                   '       d    V# VP                  V4       \        P                  ! V\	        R4      4      p\        P                  ! V4      '       d   \        WA4      p\        P                  ! V\	        R4      4      p\        P                  ! V\	        R4      4      p\        P                  ! V4      '       d   EK  TpEK  V# )zs
Return list of outline xref numbers. Recursive function. Arguments:
'obj' first OL item
'xrefs' empty Python list
r  r  Nextr  )r   r   r  r  r  ro   r  r  )r  r  thisobjnewxrefr  r   s   &&    r'   r  r  ,R  s     >>>G



""G,u117HV<LMXXX L 	g""GXg->?e$$$e3E$$gx/?@##Whx.@A  '**GLr)   c                    ^ p\         P                  ! V P                  4       \         P                  4      p\         P                  ! V4      p\        V4      pV# )z=
return a PDF page's /Rotate value: one of (0, 90, 180, 270)
)r   r  r  rt  r  r  )r   r`  r  s   &  r'   r~  r~  ER  sF     F

(
($((*e6P6P
QCc"Ff%FMr)   c                    \         P                  ! \        VR4      4      p\         P                  ! V4      p\         P                  ! \         P
                  4      p\         P                  ! WV4      pV# )zH
create PDF object from given string (new in v1.14.0: MuPDF dropped it)
rS  )r   r  r  r  	PdfLexbufPDF_LEXBUF_SMALLpdf_parse_stm_obj)r1  r4  r4  r   lexbufr  s   &&    r'   r  r  QR  sV     225f3EFG!!'*F__U334F$$S&9FMr)   c                   \        V \        P                  4      '       g   Q hVf   \        P                  ! 4       pVe8   \        V\        P                  4      '       g   Q R\	        V4      : RV 24       h\        P
                  ! V 4      p\        V4      p\        V4      p\        P                  ! Wh4      p\        P                  ! Wg4      p\        P                  ! V4      p	\        V\        P                  4      '       g   Q h\        P                  ! W)WS4      p
V'       d   \        P                  ! V
4       M\        P                  ! V
^4       \        P                  ! V4      '       gX   \        P                   ! WzV	4      p\        P"                  ! W\        P$                  ! 4       V\        P&                  ! 4       4       M\        P(                  ! Wz4      p\        P"                  ! W\        P$                  ! 4       \        P*                  ! \        P*                  P,                  4      \        P&                  ! 4       4       \        P.                  ! V4       \1        RV
4      # )z
Version of fz_new_pixmap_from_display_list (util.c) to also support
rendering of only the 'clip' part of the displaylist rectangle
ztype(seps)=r   r  )r@   r   rO  r  r   rf  r  r  r'  r  r(  r-  r  r/  r0  r  rN  ri  r|  rj  rM  rq  rr  r  r  )rp  r  r  r  r  r  r   r  r8  r  r  r  s   &&&&&&      r'   r`  r`  _R  s    eU001111|""$<:dE,?,?@@Z[T$ZMQSTXSYBZZ@&&u-Ds#FD!E""4/D""40D%Er5--....

'
'4
?Cc"((d3$$U++00eD!!%enn.>u~~GWX&&v3!!%enn.>U\\MhMh@ikpkykyk{|	#5#r)   c                *   \        V \        P                  4      '       d   V # \        V \        4      '       d,   \        P                  ! V P                  V P
                  4      # \        '       d   \        P                  ! V 4      # \        P                  ! ^ ^ 4      p\        V ^ 4      p\        V ^4      pVe   Vf   V# \        V\        4      p\        V\        4      p\        V\        4      p\        V\        4      p\        P                  ! W#4      # )zE
PySequence to fz_point. Default: (FZ_MIN_INF_RECT, FZ_MIN_INF_RECT)
)r@   r   rg  r)  ri  rj  r  r   r+  r$  r'  r  r  r  )r  r  ri  rj  s   &   r'   r+  r+  R  s     !U]]##!U}}QSS!##&&{%%q))	q!	BaAaAyAI	Q AQ AQ AQ A==r)   c                   \         '       d   \        P                  ! W4      # \        V \        P
                  4      '       g   Q h\        V\        P                  4      '       g   Q h\        P                  ! VP                  P                  4      p^ p^ p^ p^ p\        V4       Fp  w  rxVP                  P                  \        P                  8X  d;   \        V4       F"  w  r\        V
4       F  w  rK  	  VX,          pK$  	  VX	,          pWG,          pKr  	  V F  pVP                  P                  \        P                  8X  g   K.  V F  p
^ pV
 F^  p\        W4      p\        P                  ! V4      '       g   \        W-4      '       g   K=  VP                  P                   p\#        W4       K`  	  V^
8w  g   Kr  V^ 8  g   K{  \        P$                  ! V R4       K  	  K  	  R# )z
Plain text output. An identical copy of fz_print_stext_page_as_text,
but lines within a block are concatenated by space instead a new-line
character (which else leads to 2 new-lines).
r#   N)r  r   rh  r@   r   rF  r  rq  r   rJ  rZ  r   rw  ry  r  rz  r  r{  r  )r%  r   r   r  n_blocksn_linesn_chars	n_blocks2r  n_lines2rs   n_chars2r?  chbboxs   &&            r'   rh  rh  R  s    [00;;c5>>****dE--....<<001DIHGG%t,	  E$=$=="+U"3$-t$4LH %58# #4 xG -   E$=$==	B)$3F11$77/== %'MMOO	&s6  ?y1}**35  r)   c                f   \         P                  ! W4      p\         P                  ! V 4      pV'       gY   Ve   VP                  '       g   \         P                  ! W4       R# VP                  '       d   \         P                  ! WB4       R# VP                  '       d   VP                  '       g   \        V4      pM\        \         P                  ! WB4      4      pW68w  dP   \        WS4      pVP                  '       g   \         P                  ! WV4       R# \         P                  ! WW4       R# R# )z
Create a JavaScript PDF action.
Usable for all object types which support PDF actions, even if the
argument name suggests annotations. Up to 2 key values can be specified, so
JavaScript actions can be stored for '/A' and '/AA/?' keys.
N)	r   r  r  r   rH  rf  rH  rU  rV  )r&  key1key2r   key1_objra  r$  rG  s   &&&&    r'   JM_put_scriptrg  R  s     !!)2H

&
&y
1C <ty/ 	    x. ???("5"5"5x(u11(AB %c1	y	:	dA r)   c                ^    V P                   V P                  V P                  V P                  3# r+   r  r  s   &r'   rS  rS  R  !    44qttQTT!!r)   c                    V P                   V P                  V P                  V P                  V P                  V P
                  3# r+   r  )r  s   &r'   r{  r{  R  s-    33QSS!##qssACC''r)   c                2    V P                   V P                  3# r+   r  )r  s   &r'   r  r  R  s    338Or)   c                ^   V P                   P                  V P                   P                  3V P                  P                  V P                  P                  3V P                  P                  V P                  P                  3V P
                  P                  V P
                  P                  33# )z
PySequence from fz_quad.
)r  ri  rj  r  r  r  )rc  s   &r'   r  r  R  sn    
 TTVVQTTVVTTVVQTTVVTTVVQTTVVTTVVQTTVV	 r)   c                ^    V P                   V P                  V P                  V P                  3# r+   r  r  s   &r'   rp  rp  S  ri  r)   c           
     :   \        V \        P                  4      '       d   V # \        V R 4      '       dG   \	        V 4      ^8X  d7   \        V ^ ,          R4      '       d   \        P
                  ! \        V 4      !  p \        V \        P
                  4      '       d   \        P                  ! V 4      # \        V \        4      '       d   \        P                  ! V P                  P                  V P                  P                  V P                  P                  V P                  P                  V P                  P                  V P                  P                  V P                  P                  V P                  P                  4      # \        P                  ! ^ ^ ^ ^ ^ ^ ^ ^ 4      p. ROpV '       d-   \        V \        \         34      '       d   \	        V 4      ^8w  d   V# \#        V ^ 4      f    \        P                  ! \%        V 4      4      # \'        ^4       EFK  pV\	        V 4      8  d   Vu # W,          p\)        V4      '       d   \+        V4      ^8w  d   Vu # \#        V^ 4      W#,          n        \#        V^4      W#,          n        W#,          P                  e   W#,          P                  f   Vu # \-        W#,          P                  \.        4      W#,          n        \-        W#,          P                  \.        4      W#,          n        \1        W#,          P                  \2        4      W#,          n        \1        W#,          P                  \2        4      W#,          n        EKN  	  V^ ,          Vn
        V^,          Vn        V^,          Vn        V^,          Vn        V# )r  r  r  )r@   r   rV  r=   r9   rq  r   r  r)  fz_make_quadr  ri  rj  r  r  r  r   r$  r  rS  rJ  rL  r'  r  r  r  )r$  rc  r  rg  r  s   &    r'   r_  r_  S  sW   !U\\""q-  SVq[WQqT;5O5OLL%(#1ell##&&**1d!!	 	 	1aAq!Q2AAJq5$-00CFaKQ"&&q'9::1XA;Hd$$(<(AHsA&sA&466>QTVV^Hadffo.adffo.adffo.adffo.  Q4ADQ4ADQ4ADQ4ADHr)   c                   \        V \        P                  4      '       g   Q \        V 4       4       h\        P                  ! V \        P
                  4      p\        P                  ! V4      '       d   \        P                  ! R4      p\        \        P                  ! V4      4       F  pV^ 8  d   \        P                  ! V^ 4       \        P                  ! W4      p\        P                  ! V4      '       g   KU  \        P                  ! V4      p\        P                  ! W%4       K  	  V# VP                  '       d   \        P                  ! V4      pV# \        P                  ! ^ 4      pV# )zC
Read and concatenate a PDF page's /Contents object(s) in a buffer
r  )r@   r   r0  r   r  r  rI  rF  rS  r  r}  r  r!  r"  fz_append_bufferr   )r  rK  r%  rg  r  r  s   &     r'   r.  r.  8S  s    gu||,,@g@,!!'5+G+GHH(##nnT"u**845A1u$$S"-%%h2C""3'',,S1&&s1 6 J	 
			##H- J nnQJr)   c                H   \        V \        P                  4      '       d   V # \        V \        P                  4      '       d   \        P                  ! V 4      # \        V \        4      '       dB   \        P
                  ! V P                  V P                  V P                  V P                  4      # \        V \        4      '       dB   \        P
                  ! V P                  V P                  V P                  V P                  4      # V '       d"   \        V 4      '       d   \        V 4      ^8w  d/   \        P                  ! \        P                  P                  4      # . ROp\        ^4       F~  p\        W4      W&   W,          f1   \        P                  ! \        P                  P                  4      u # W,          \         8  d	   \         W&   W,          \"        8  g   Kv  \"        W&   K  	  \        P
                  ! V^ ,          V^,          V^,          V^,          4      # )r  r  )r@   r   rq  r  r+  r2  r  r  r  r  r  rJ  rL  rr  rS  r$  r  r  )r$  r  rg  s   &  r'   r  r  NS  s\   !U\\""!U]]##||A!T!!!$$addADD99!U!!!$$addADD99$Q''?1+=+B||ELL7788A1XQ"4<<< ; ;<<4/!"AD4/!"AD  adAaD!A$!55r)   c                     V P                   VP                  8  gR   V P                  VP                  8  g7   V P                  VP                   8:  g   V P                  VP                  8:  d   ^ # ^# ru  r  rQ  s   &&r'   rz  rz  eS  sG    	ttqtt|ttqtt|ttqtt|ttqtt|r)   c                2   V e   V P                   '       g   R# \        P                  ! V P                  4       \	        R4      4      pVP                   '       d   V P                  4       p\        P                  ! W P                  4       4      p\        P                  ! 4       p\        P                  ! 4       p\        P                  ! WV4       \        P                  ! W WV4      p\        P                  ! VP                   4      V P                   n        R# R# )z4
refreshes the link and annotation tables of a page
Nr  )r   r   r  r  r  r1  r	  rq  r|  rd  pdf_load_link_annotsll_fz_keep_linkr5  )r   r  ra  r]  r'  rk  r  s   &      r'   r  r  pS  s     |4???


dhhj(8*<
=C
~~~hhj--sHHJ?>>#  $x@))3c8L % 5 5t G r)   c                   V P                   '       g   \        P                  ! 4       # \        V 4      pV^ 8X  d   \        P                  ! 4       # \	        V P                  4       4      pVP                  pVP                  pV^Z8X  d   \        P                  ! ^ ^R^ V^ 4      pV# V^8X  d   \        P                  ! R^ ^ RW44      pV# \        P                  ! ^ R^^ ^ V4      pV# )z"
calculate page rotation matrices
r  )	r   r   r|  r~  r  r  ri  rj  r  )r   ru  cb_sizer   r"  r  s   &     r'   r  r  S  s     ???~~%H1}~~dhhj)G		A		A2~  Ar1a3 H 
S  Q2q4 H   B1a3Hr)   c                F     \        P                  ! T P                  T4      # rv  )r  r   r  r   r   rq  rJ  r9   r
  hfuzzvfuzzrE  fz_string_from_bufferfind_stringr   rw  r  ry  rz  on_highlight_char)r   r  r   r
  Hitshitsr4  haystack_stringhaystackbeginr  insiderg  r  rs   r?  r$  s   &&               r'   r  r  S  s    ))$//6BBr)   c           	        \         P                  ! V4      '       d   \         P                  ! R4       R#  \         P                  ! V\         P                  4      pV^8X  d3   \         P                  ! V\         P
                  4      p\        WW$4       MAV^8X  d   \        WW$4       M-V^8X  d   \        WW$4       M \         P                  ! V4       R# \         P                  ! V4      p\        V4       F  p	\         P                  ! Wi4      p
\         P                  ! V
4      '       d   \         P                  ! V
4      pM^ p\         P                  ! V
\         P                  4      pVP                   '       g   K  TpW9  d!   VP#                  V4       \%        WW#W4       K  \         P                  ! R4        \         P                  ! V4       R# 	  \         P                  ! V4       R#   \         P                  ! T4       i ; i)zH
Step through /Resources, looking up image, xobject or font information
z.Circular dependencies! Consider page cleaning.N)r   pdf_mark_objr  r  PDF_ENUM_NAME_XObjectPDF_ENUM_NAME_Fontr  r  r  pdf_unmark_objr  rS  r  r!  r  r  r   ro   r  )ra  r  r  r  r  r  xobjr  rG   rg  r  sxrefsubrsrcsxref_ts   &&&&&&        r'   r  r  S  sz    $FG#!!$(C(CD19%%dE,D,DEDCu:QYS;QYCu:( 	T"# t$qA((1C""3''((-((e.K.KLG!!!(MM'*%sU%PMM"RST"!   	T"T"s   BG. B#G. =?G. G. .Hc                   V'       g   R# \        V\        \        34      '       g   Q h\        V4      pV^ 8X  d   R# \        P
                  ! V 4      p\        P                  ! V4      p\        P                  ! WB4      p\        V4       F  pW,          pTp\        V\        4      '       d   \        P                  ! WX4       K;  \        V\        \        34      '       d   \        V4      ^8X  g   Q R4       hVw  rV	'       d	   V
'       g   Q R4       h\        P                  ! V^4      p\        P                  ! W4       \        P                  ! W4       K  	  \        P                  ! V\        R4      V4       R# )z
set ListBox / ComboBox values
Nzbad choice field listr  )r@   r   r   r9   r   r  r  rR  rS  r  pdf_array_push_text_stringpdf_array_push_arrayrU  r  )r   r  rG   r&  ra  r  rg  r  optopt1opt2	optarrsubs   &&          r'   JM_set_choice_optionsr  T  s    uudm,,,,UAAv##U+I

&
&	
2C  #)F1Xhc3,,f:sUDM22sCyA~^G^^EJDD9"99=22FA>I,,i>,,i>  
	8E?F;r)   c                   ^ p^ pRpV\         P                  8X  d   \        R4      p\         P                  pEM*V\         P                  8X  d-   \        R4      p\         P                  p\         P
                  pMV\         P                  8X  d2   \        R4      p\         P                  \         P
                  ,          pMV\         P                  8X  d   \        R4      pMV\         P                  8X  d   \        R4      p\         P                  pMQV\         P                  8X  d   \        R4      p\         P                  pM V\         P                  8X  d   \        R4      pVe4   VP                  '       d"   \         P                  ! V\        R4      V4       V^ 8w  g   V^ 8w  dU   \         P                  ! V\        R4      4      pWd( ,          pWc,          p\         P                  ! V\        R4      V4       R# R# )z
Set the field type
NBtnTxChSigrV  r  )r   r  r  PDF_BTN_FIELD_IS_PUSHBUTTONr  PDF_BTN_FIELD_IS_RADIOr  r  r  PDF_CH_FIELD_IS_COMBOr  r  r   rU  r4  rP  )r1  r  r   setbits	clearbitstypenamerH  s   &&&    r'   r  r  'T  sw    GIHu+++E?33	22	2E?55	..	//	/E?669U9UU		++	+D>	..	.D>//		//	/D>--	00	0E? 3 3 339!|yA~%%c8D>:
sHTND9	 &r)   c                   Rp\         P                  ! V 4      pVP                  R4      p\        V4      pV^,
          pWW,          pWW \        V4      p\         P                  ! W4      p	V	P
                  '       g   V^ 8  dz   RP                  V4      p
\         P                  ! \         P                  ! V \        V
4      4      4      '       d   \        R\        V4       R24      hWV^,
           \        V4      pK  \         P                  ! W\         P                  ! V4      4       \         P                  ! W4      p	\         P                  ! V	4      '       g   \        RV R24      h\         P                  ! V	4      pW8w  d   \        RV R24      h\        V ^^ 4      p\        V4      pRV RV R2pRV R	V 2pVP!                  W^4      p\#        VV4      pV# )
z"
Set a PDF dict key to some value
zfitz: replace me!r	  z	path to 'z' has indirectszcannot insert value for 'r   r  r  r   )r   r  r8   r9   r|  r   r  r9
  r  rk   pdf_dict_putpr  r  r  r  r  r  r  )r  r  r   
eyecatcherra  rp  r  rg  skeytestkeyr  r  r%  objstrnullvalnewvalnewstrr]  s   &&&               r'   r  r  MT  s    %J

&
&s
+CIIcNEu:DqA8Du:D!!#+G QhA$$U%8%8l1o%NOO)L,>+? OPPQhu:D 
%";";J"GH!!#+Gw''3C5:;;##G,D3C5:;;
c1a
(C#C(F $qA&GawF^^GQ/F "#v.GNr)   c                   V'       d"   \         P                  ! V \        R 4      V4       VeU   \         P                  ! V \        R4      4       V'       d-   \         P                  ! V \        R4      ^4      p\        Wb4       VeU   \         P                  ! V \        R4      4       V'       d-   \         P                  ! V \        R4      ^4      p\        Wc4       VeU   \         P                  ! V \        R4      4       V'       d-   \         P                  ! V \        R4      ^4      p\        We4       Ve   \         P                  ! V \        R4      4       V'       dk   \         P                  ! V \        R4      ^4      p\        V4      p\        V4       F-  pWH,          p	\         P                  ! V^4      p
\        W4       K/  	  R# R# R# )r}  Nr  r  rs  r  )	r   r\  r  rH  rX  JM_set_ocg_arrays_impr9   rS  r  )rt  r
  ro  r
  r
  rb	  rp  rG   rg  item0r  s   &&&&&&     r'   r
  r
  }T  sL   x'<iH	~D(4.1**D(4.!DC!3+
D(5/2**D(5/1EC!3,D(8"45**D(82DaHC!3/D(:"67**D(:2FJC8}A1X 00#q9%s2   r)   c                    \         P                  ! V 4      pV F0  p\         P                  ! W#^ 4      p\         P                  ! W4       K2  	  R# )zu
Set OCG arrays from dict of Python lists
Works with dict like {"basestate":name, "on":list, "off":list, "rbg":list}
N)r   r  r  rK  )rp  rp  ra  r  r  s   &&   r'   r  r  T  s>    
 
&
&s
+C$$S2S& r)   c                P   \         P                  ! V 4      p\         P                  ! W2^ 4      pVP                  '       g   \	        \
        \        4       \         P                  ! V \        R4      4      pVP                  '       g"   \         P                  ! V \        R4      ^4      p\         P                  ! V\        R4      4      pVP                  '       g"   \         P                  ! V\        R4      ^4      p\         P                  ! V\         P                  ! V4      V4       R# )z
Insert an item into Resources/Properties (used for Marked Content)
Arguments:
(1) e.g. page object, Form XObject
(2) marked content name
(3) xref of the referenced object (insert as indirect reference)
r<  rD  N)r   r  r  r   r  r  r	  r  r  rY  rU  r  )r  r   r  ra  r  ri  rE  s   &&&    r'   r"  r"  T  s     
&
&s
+C

 
 A
.C>>>./""3(=>I++C+1FJ	##Ix/EFJ   ,,Y8NPQR
	z5#5#5d#;SAr)   c                  a \        V \        4      '       d   V P                  p \        V \        P                  4      '       g   Q R\        V 4      : R\
        : 24       h\        V 4      pVP                  '       g   Q R4       h\        P                  ! V 4      pVP                  4       pV3R lpV! R4      pTpV! R4      p\        V4      p\        V4      p	\        P                  ! W4      p\        P                  ! W4       V! R4      pV'       d{   \        V4      '       dj   \        V4      p
\        P                   ! WJ4      p^ p\#        V
4       F!  pWm,          p\        P$                  ! W4       K#  	  \        P&                  ! W;4       V! R4      pV'       d   \        V4      '       d{   \        V4      p
\        P                   ! WJ4      p\#        V
4       F   p\        P(                  ! WV,          4       K"  	  \        P*                  ! W>\-        R	4      \-        R
4      4       V! R4      pV'       d   \        V4      '       d~   \        V4      p
\        P                   ! WJ4      p^ p\#        V
4       F!  pWm,          p\        P$                  ! W4       K#  	  \        P*                  ! W?\-        R4      \-        R4      4       V! R4      pVe-   \/        V4      p\        P0                  ! V\-        R4      V4       V! R4      pVeJ   \/        V4      p\        P2                  ! V4      pVV8w  d"   \        P0                  ! V\-        R4      V4       V\        P4                  8X  d4   V! R4      pTpV'       d"   \        P6                  ! V\-        R4      V4       V! R4      pTp\        P8                  ! VV4       V\        P:                  \        P<                  39   d   V! R4      p\?        W4       V! R4      p\A        V4      p\        P*                  ! VV\-        R	4      \-        R4      4       V! R4      pTp\        P*                  ! V\        PB                  ! V4      \-        R	4      \-        R4      4       V! R4      p\/        V4      p\        P0                  ! V\-        R4      V4       \        PD                  ! V\-        R4      4       \        PD                  ! V\-        R4      4       V! R4      pVe   V\        P<                  8X  d   V\        PF                  ,          pMYV\        PH                  8X  d   V\        PJ                  ,          pM,V\        PL                  8X  d   V\        PN                  ,          p\        P6                  ! V\-        R 4      V4       V! R!4      p\/        V4      pV'       d   \        PP                  ! VV4       V! R"4      p\S        V\-        R#4      \        PT                  ! 4       V4       V! R$4      p\S        V\-        R%4      \-        R&4      V4       V! R'4      p\S        V\-        R%4      \-        R(4      V4       V! R)4      p\S        V\-        R%4      \-        R*4      V4       V! R+4      p\S        V\-        R%4      \-        R,4      V4       V! R-4      p\S        V\-        R%4      \        PV                  ! R.4      V4       V! R/4      p\S        V\-        R%4      \        PV                  ! R04      V4       V! R14      p\/        V4      pV\        PH                  8X  d   V'       g<   \        PX                  ! WCR2^4       \        PZ                  ! V\-        R34      R24       EM\        P\                  ! V4      pVP                  '       dR   \        P^                  ! V4      p\        PX                  ! WCV^4       \        PZ                  ! V\-        R34      V4       EMyV'       d"   \        PZ                  ! V\-        R34      V4       EMNV\        P`                  8X  d   \        P\                  ! V4      pVP_                  4       pVR4V39   g   VR58X  d\   \        PX                  ! WCV^4       \        PZ                  ! V\-        R34      V4       \        PZ                  ! V\-        R*4      V4       M\        PZ                  ! V\-        R34      R24       \        PZ                  ! V\-        R*4      R24       MeV'       d^   \        PX                  ! WCV^4       V\        P<                  \        P:                  39   d!   \        PD                  ! V\-        R64      4       \        Pb                  ! V 4       \        Pd                  ! V ^4       \        Pf                  ! V ^4       \        Ph                  ! V 4       R# )7z
Update the PDF form field with the properties from a Python Widget object.
Called by "Page.add_widget" and "Annot.update_widget".
ztype(annot)=rv  r   c                   < \        SV R 4      # r+   )r   )r   rZ  s   &r'   GETATTR)JM_set_widget_properties.<locals>.GETATTRT  s    vtT**r)   r  r   r_  r  rZ  r  r  rV  rX  r  NrU  r  r+  r  MaxLenr  r  r  r
  r  r:  r  r^  r;  r  r  r  r  r$  r  r  rW  rY  r  r  r  rZ  r  r  r  r[  r  r\  r  r  r  TYesr\  )5r@   r   r   r   r   r   r   r   r  r1  r  r  r  r  rJ  r9   rR  rS  rT  pdf_field_set_fill_colorri  rV  r  r  r  r`  r  rP  pdf_field_set_displayr  r  r  rk  rj  rH  r  r  r  r  r  pdf_field_set_button_captionrg  r0  r  pdf_set_field_valuer\  pdf_button_field_on_stater  r  rV  pdf_set_annot_hotpdf_set_annot_activerW  )r   rZ  r   r&  ra  r  r   r  r   rot_matrG   fill_colrf  rg  r  
border_colr  r   old_namer  rH  r  r  r  r  r>  r   onstatero  s   &f                           r'   JM_set_widget_propertiesr  T  sw   
 5%  

uenn--H,$u+w/HH-5!D???:::?##E*I
((*C+ L!EJ FOE5!D#D)G""41D	U) L!E!%((J&&s.qA(C%%h4  	&&y; O$E!%((J$$S,qA$$V1X6 Ix~x}M N#E!%((J((0
qA(C%%j6  	I8D>8D>R M"EU#&&y(4.%H L!EE",,Y78**9hsmTJ U///&""9hx.@+NO$EA		1- e33U5S5STT(e+ N#E
e
$C		3F N#EL	|,TNSM	 JE	e	B	""9htnbA	y(4.1	y(4.1 -(K7775666K5<<<5777K57775<<<K	8D>;G $%E	e	B	**9b9 HE)Xc]ELLNEB O$E)Xd^Xc]EB O$E)Xd^Xc]EB O$E)Xd^Xc]EB M"E)Xd^Xc]EB M"E)Xd^U-?-?-EuM N#E)Xd^U-?-?-EuM M"EDU666%%ceQ?##Ix~uE 55i@G!!!&&w/))#"a@''	8D>2F''	8D>4H	u55	511)<  "T2J$%-%%cb!<##Ix~rB##Ix}bA##YF##YuE%%cdA>e<<e>[>[\\""9hsm<	% 	E1%	ua(	5!r)   c                   ^ pV\        V4      8  d   \        P                  ! W8R 4      w  rW,          p\        P                  ! W4      pV^ 8X  d   \        P                  ! W^ V4      w  rMTp\        P
                  ! WW+WWVV4	       \        P                  ! WV4      pV^ 8X  d   \        P                  ! W-^ 4      pK  \        P                  ! V^ V) 4      pK  V# r   )r9   r   fz_chartoruner;  r<  fz_show_glyphr  fz_pre_translate)r   	user_fontr#  r  r=  
bidi_levelr$  rI  rg  rX  r  r@  r  r  s   &&&&&&&&      r'   r!  r!  }U  s     	
A
c!f*$$QrU+	**9:!8??	PQS[\ICDD#jV^_$$T6A:((15C((a#6CJr)   c                    \         P                  ! V 4      pVP                  R R7      pVP                  \	        ^ 4      4      pV^ 8  d   VRV pV# )r  r  N)r   r7  r  r   rn  )r  
buff_bytesr  r  s   &   r'   r  r  U  sN    --d3J


9

-CQAAv"1gJr)   c                "    \        RV  24       R# )z
Generate a warning.
z	warning: Nr2  ru   s   &r'   r  r  U  s     ivr)   c                   V'       d   \         P                  ! V4      w  rEV^8  d   \        V4      p\        V\         P                  4      '       g   Q hVP
                  '       dm   \         P                  ! V4      w  ruWt8  dO   \         P                  ! V\         P                  \         P                  4       \         P                  ! WV^4       R# \         P                  ! WV^ 4       R# )z8
update a stream object
compress stream when beneficial
N)
r   rT  r  r@   rF  r   rU  PDF_ENUM_NAME_FilterPDF_ENUM_NAME_FlateDecodepdf_update_stream)r1  r  r4  r  r  r@  buffer_compressedlength_compresseds   &&&&    r'   r0  r0  U  s    
 ++G4	B; 27 ;/@@@@ +++','>'>?P'Q$!$-&&!66!;;
 ++C6GK	Cgq1r)   c                   \        V\        P                  4      '       g   Q R\        V4      : 24       hV^ 8  d   \        P                  ! W^ 4      pV# \        VP                  4      pVP                  4       p\        P                  ! \        P                  ! V\        R4      4      4      p\        P                  ! V\        R4      4      pVP                  '       d   \        P                  ! W84      p	M\        P                  ! W4      p	\        V4      p
\        P                  ! W\        P                   ! 4       \        P"                  ! ^ 4      V
4      p\%        WV
^4       \        P&                  ! V\        R4      V	4       V# )z`
Make an XObject from a PDF page
For a positive xref assume that its object can be used instead
ztype(gmap)=r  r<  )r@   r   PdfGraftMapr   r  r   r   r  r  r  r  r   r  pdf_graft_objectr.  r'  r|  r0  r0  rU  )r	  fsrcpager  r  r+  srcpagespagerefrJ  r  ri  r%  s   &&&&       r'   r&  r&  U  s*   
 dE--..@;4:-0@@.ax&&vQ72 L/ x}}-;;=$$U%C%CHhWaNb%cd**8Xk5JK???55d>I..v9I x(
 %%f8H%,,WX/[^_Q/ 	5(;"7CLr)   c                .    \        V \        \        34      # r+   )r@   r   r   rL  s   &r'   rJ  rJ  U  s    a%''r)   c                    \        V 4      # r+   )r9   rL  s   &r'   rL  rL  U  s    q6Mr)   zbad annot typezbad or missing annot AP/Nz%arg must be seq of seq of float pairszbad seq of pointszbad type: 'buffer'zbad color sequencer  zbad filetypezbad locationzbad config numberzbad layer numberzbad 'oc' referencezbad page idr  zPDF has no rootzrect is infinite or emptyzbad type: 'text'r}  zcolor count failedzneed font file or bufferzcannot create fontzis no annotationzis no imager  zobject is no PDF dictzsource pixmap has no alphazpixel(s) outside imager   c                    \        V 4      hr+   )rk   )r   excs   &&r'   r  r  V  s     S/r)   c                    V '       g   R # \        V \        4      '       d   V P                  RVR7      pM\        V \        4      '       d
   V R,          pXP	                  RVR7      pV# )r`   rS  r  rV   raw_unicode_escape)r@   r  r  r  r  )r  r  r   rI   s   &&  r'   r  r  V  sU    !SXXfVX,	Au		qT
))()
8CJr)   c                   V ^8  d   QhRR/# )r  r  r  r,   )r  s   "r'   r  r   V  s     P P& Pr)   c                    V '       dX   \        V 4      \        \        39  g1   \        V 4      R9  g!   \	        V 4      ^ 8  g   \        V 4      ^8  d   \        R4      hR# R# )r  z/need 1, 3 or 4 color components in range 0 to 1Nr  )r   r   r   r9   r  r'  r   r  s   &r'   r  r   V  sM    GD%=(1vY&1vz1vzNOO  	r)   c               $    V ^8  d   QhRRRRRR/# )r  r   r   r   r  rs  r   r,   )r  s   "r'   r  r  +V  s!      D C E r)   c                X    V P                  4        F  pV^,          V8X  g   K  Vu # 	  R# )zGReturn an entry in the page's font list if reference name matches.
    N)r  )r   r   r  s   && r'   r  r  +V  s&     ^^Q48H r)   c               $    V ^8  d   QhRRRRRR/# )r  r1  r   r  r6   rs  r   r,   )r  s   "r'   r  r  3V  s!      x s t r)   c                N    V P                    F  pW^ ,          8X  g   K  Vu # 	  R# )z3Return a font info if present in the document.
    N)r  )r1  r  r  s   && r'   rK  rK  3V  s      ]]Q4<H r)   c                    V ^8  d   QhRRRR/# )r  r
  r  rs  r   r,   )r  s   "r'   r  r  ;V  s     	 	* 	 	r)   c                    \        V 4      '       d   \        V 4      pVP                  3# \        V 4      '       d   V 3# V  F2  p\        V4      '       d   K  \        V4      '       d   K)  \	        R 4      h	  V # )zbad quads entry)rK  r+  rM  rL  r   )r
  r$  rc  s   &  r'   rM  rM  ;V  sb    Kyx!	!.//  Lr)   c                    V ^8  d   QhRRRR/# )r  r  r  rs  r   r,   )r  s   "r'   r  r  GV  s     	 	* 	 	r)   c                x   \        V 4      '       g   R # \        V 4      \        \        39   d   \	        V 4      ^8X  g   \        R4      h\	        V ^ ,          4      ^8X  d   \	        V ^,          4      ^8X  g   \        R4      hV ^,          ^,          V ^,          ^,          u;8X  d   ^ 8X  g   M \        R4      hR# )Fz$morph must be a sequence of length 2zinvalid morph param 0zinvalid morph param 1T)r   r   r   r   r9   r   rD  s   &r'   r  r  GV  s    77Ge}$Q1?@@!INs1Q4yA~011Q47ad1g""011r)   c                   V ^8  d   QhRR/# )r  r  r  r,   )r  s   "r'   r  r  SV  s     H H: Hr)   c                    R # r+   )r=   r   r   r   rD  s   &r'   ro  ro  SV  s    
r)   c                    V ^8  d   QhRRRR/# )r  rc  r  rs  r   r,   )r  s   "r'   r  r  YV  s     
 
 
 
r)   c                     \        V 4      pVP                  #   \         d    \        ^8  d   \        4         R# i ; i)zcCheck whether an object is convex, not empty  quad-like.

It must be a sequence of 4 number pairs.
F)r)  rk   r  r{   r  )rc  q0s   & r'   rL  rL  YV  s=    
!W <<  !#(8s     ==c                    V ^8  d   QhRRRR/# )r  r$  r  rs  r   r,   )r  s   "r'   r  r  fV  s     
- 
- 
- 
-r)   c                     \        V 4      p T P                  ;'       g    T P
                  '       * #   \         d    \        ^8  d   \        4         R# i ; i)zZCheck whether an object is non-degenerate rect-like.

It must be a sequence of 4 numbers.
F)r+  rk   r  r{   r  r  r  s   &r'   rK  rK  fV  sL    
G 

++amm,,  !#(8s   2  AAc               $    V ^8  d   QhRRRRRR/# )r  r  z&typing.Union[list, tuple, float, None]r  r  rs  r,   )r  s   "r'   r  r  sV  s"     . .7 .C .C .r)   c                   V '       g   R # \        V R4      '       d   V 3p \        V 4       \        V 4      ^8X  d3   \        V ^ ,          4      R,           pVR8X  d
   VR,           # VR,           # \        V 4      ^8X  d5   \        \	        V 4      4      R,           pVR8X  d
   VR,           # VR,           # \        \	        V 4      4      R,           pVR8X  d
   VR,           # VR	,           # )
r`   r  r   r  zG zg zRG zrg zK zk )r=   r  r9   r   r   )r  r  r  s   && r'   r  r  sV  s    q+DqM
1v{adOc!8q4x1T1
1v{eAh#%Hq5y3!e)3%(c!ACx1t8-QX-r)   c                   aa V P                  4       o\        S4      oVV3R  lp S^ 8w  d0   \        P                  ! SP	                  4       \        R4      ^ 4       \        P                  ! SV4      pV F$  p\        V4      p\        P                  ! WF4       K&  	  \        P                  ! V4       \        VR4       V! 4        \        T4      #   \         d"    \        '       d   \        4        T! 4         R# i ; i)c                 x   < S^ 8w  d2   \         P                  ! S P                  4       \        R4      S4       R# R# )rx   r;  N)r   rP  r  r  )r  ru  s   r'   r  $Page__add_text_marker.<locals>.finalV  s,    q=""7;;=(82DhO r)   r;  r  N)r,  r~  r   rP  r  r  r-  r_  pdf_add_annot_quad_pointrW  r/  rk   r  r{   r   )	r&   r
  r0  r  r   rE   rc  r  ru  s	   &&&    @@r'   r  r  V  s    nnG(HPq=""7;;=(82DaH&&w
;D%A**54  	u%s#
 <	  N$4s   C BC C=(C=<C=c                \    \        V \        4      '       g   Q h\        \        R V  24      pV# )r  )r@   r  r   r   )ri  rI   s   & r'   r  r  V  s/    a
%>!-
.C Jr)   c                    V ^8  d   QhRRRR/# )r  r1  r   r8  r=  r,   )r  s   "r'   r  r  V  s     
# 
# 
# 
#r)   c                    V^ ,          pRp\        V P                  4       F  w  rEV^ ,          V8X  g   K  Rp M	  V'       d   WP                  X&   R# V P                  P                  V4       R# )rx   FTN)rZ  r  ro   )r1  r8  r  r  rg  fis   &&    r'   rO  rO  V  s[    7DE3==)a5D=E * aT"r)   c                (   ^ p\        \        V4      4       Fe  pW,          pV\        V 4      8  d#   \        V\        4      '       d
   RV9   d   K:   R# Ve   \        W,          V4      '       g    R# V^,          pKg  	  V\        V 4      8w  d   R# R# )z
Returns true if <args> matches <types>.

Each item in <types> is a type or tuple of types. Any of these types will
match an item in <args>. `None` will match anything in <args>. `type(None)`
will match an arg whose value is `None`.
NFT)rS  r9   r@   r   )r  r  r  rg  rb  s   &*   r'   rI  rI  V  sz     	
A3u:D	>%''DEMZ%?%?	Q  	CI~r)   c                   \        V4      p\        P                  ! V4      pVP                  VP                  ,
          pVP
                  VP                  ,
          pTp	Tp
V'       d   \        W4      pW,          pW,          pM^;r\        W4      pV^ 8w  d   V^8w  d   TpTpTpV^8  d*   W|,          W,          8  d   W,          p	Tp
M>Tp	W~,          p
M3W8w  d*   W|,          W,          8  d   W,          p	Tp
MTp	W~,          p
MTp	Tp
\        P                  ! VP                  VP                  ,           ^,          VP                  VP
                  ,           ^,          4      p\        P                  ! ^^ ^ ^RR4      p\        P                  ! VV4      p\        P                  ! V\        P                  ! W4      4      p\        P                  ! V\        P                  ! VP                  VP                  4      4      pV# )z"
# compute image insertion matrix
g      )r  r   	fz_rotater  r  r  r  r'  r  r  r  rf  fz_scalefz_translateri  rj  )r  r3  r  r`  r  r  ry  trwtrhr   r"  larger  r  smallr  r  r  s   &&&&&             r'   r  r  V  s    BE
//&
!C
((UXX
C
((UXX
CAAE"]^KE{v}	Av8chAAAA	8chAAAA


XX A%XX A%C 

q!Q4
6C
//#s
#C
//#u~~a3
4C
//#u11#%%?
@CJr)   c                   V P                   P                  ^ 8X  d   V P                   P                  P                  ^8X  d   V P                   P                  P                  ^ 8X  dn   VP                   P
                  P                  V P                   P                  P
                  P                  VP                   P                  R,          ,
          8  # ^ # )rx   皙?)r   r=  r  ri  rj  rU  
first_charr  )rs   r?  s   &&r'   r  r  W  s    !doo&9&9&;&;q&@T__EXEXEZEZ^_E_}}##%%(B(B(I(I(K(KbmmN`N`cfNf(fffr)   c           	         V  R \        V 4       R\        \        V 4      4       R2p\        V 4       F  pVRV R2,          pK  	  V# )r    (z):
r  r#   )r   r9   r  )ri  rI   rg  s   &  r'   dir_strr  W  sK    Cqa	CAK=
-CVaS| Jr)   c          
     ,    V ^8  d   QhRRRRRRRRR	R/# )
r  r   r  r?  ztyping.Union[list, tuple, None]r<  r   r  r6   rs  r,   )r  s   "r'   r  r  W  s2     " "3 " ? " "Y\ "ad "r)   c           	        V P                  R4      '       d   V P                  R4      '       d   V # \        V 4      '       g   R# V'       d   Vf@   RP                  V  Uu. uF"  p\	        V4      R8  d   \	        V4      R MRNK$  	  up4      pMLRP                  V  Uu. uF0  p\	        V4      R8  d   V\	        V4      ,          ^ ,          R MRNK2  	  up4      pRV,           R,           # V^ 8  d;   RP                  V  Uu. uF  qA\	        V4      ,          ^ ,          R NK  	  up4      pM,RP                  V  Uu. uF  p\	        V4      R NK  	  up4      pRV,           R,           # u upi u upi u upi u upi )	a  Return a PDF string enclosed in [] brackets, suitable for the PDF TJ
operator.

Notes:
    The input string is converted to either 2 or 4 hex digits per character.
Args:
    simple: no glyphs: 2-chars, use char codes as the glyph
            glyphs: 2-chars, use glyphs instead of char codes (Symbol,
            ZapfDingbats)
    not simple: ordering < 0: 4-chars, use glyphs not char codes
                ordering >=0: a CJK font! 4 chars, use char codes as glyphs
z[<z>]z[<>]r`   r  02xb7rU  )r5   r  r   r  r:  )r   r?  r<  r  r  otxts   &&&&  r'   r  r  W  sD    tt!4!4::>77tTt!s1v|s1vclEtTUD77OSTt!s1v|F3q6N1%c*EtTD d{T!! !|wwDADq#a&>!,S12DABww6A3q6#,67$; U U B6s   (E(6E-#E2;E7c                    V ^8  d   QhRRRR/# )r  r  r  rs  r,   )r  s   "r'   r  r  3W  s     2 23 23 2r)   c                   \        V 4      '       g   R# R pRpV  F  p\        V4      pV^8  d   V! V 4      u # V^8  d"   V^8  d   VR9   d
   VR,          pW#,          pKG  V^8  d   VRVR 2,          pK]  V^8X  d   VR,          pKo  V^	8X  d   VR	,          pK  V^
8X  d   VR
,          pK  V^8X  d   VR,          pK  V^8X  d   VR,          pK  VR,          pK  	  RV,           R,           # )a  Return a PDF string depending on its coding.

    Notes:
        Returns a string bracketed with either "()" or "<>" for hex values.
        If only ascii then "(original)" is returned, else if only 8 bit chars
        then "(original)" with interspersed octal strings 
nn is returned,
        else a string "<FEFF[hexstring]>" is returned, where [hexstring] is the
        UTF-16BE encoding of the original.
    z()c                z    \        ^^.4      \        V R4      ,           pRVP                  4       ,           R,           # )   zUTF-16BE<r%  )r  hex)r  r$  s   & r'   make_utf16be!get_pdf_str.<locals>.make_utf16be@W  s1    sCj!Ia$<<QUUW}s""r)   r`   r  r  r  03oz\bz\tr{  z\fz\rz\267)r  r  r  )r   r:  )r  r  r$  r  r  s   &    r'   r  r  3W  s     77# 	AV8?"7rCx$$T	FA82bXA 7JA1WJA2XJA2XJA2XJALA7 : 7S=r)   c           	        V '       d   V # \         P                  ! R4      p V '       d   V # ^ RIpVP                  R^^^ RR7      pVP                  ^ 8X  d=   \
        P                  ! RVP                  4      pV'       d   VP                  ^4      p V # \        P                  R8X  d   VP                  R^^^ RR7      pVP                  P                  4       pVP                  '       g	   V'       g   \        R	4      h\         P                  P                  V4      p\         P                  P                  VR
4      p \         P                  P!                  V 4      '       d   V # \        RV  R24      h\#        4       pR F  pVP                  RV 2^^^ RR7      pVP                  ^ 8X  g   K/  VP                  P                  4       P%                  4       p\'        V4      ^8X  g   Ki  V^,          pV R2pVP)                  V4       \*        P*                  ! V4      p	V	P-                  4        V	'       g   K  V	R,          u # 	  V'       d#   Rp
V F  pV
RV 2,          p
K  	  \        V
4      h\        R	4      h)a  Detect Tesseract language support folder.

This function is used to enable OCR via Tesseract even if the language
support folder is not specified directly or in environment variable
TESSDATA_PREFIX.

* If <tessdata> is set we return it directly.

* Otherwise we return `os.environ['TESSDATA_PREFIX']` if set.

* Otherwise we search for a Tesseract installation and return its language
  support folder.

* Otherwise we raise an exception.
TESSDATA_PREFIXNztesseract --list-langsT)shellcapture_outputr  r   z%List of available languages in "(.+)"win32zwhere tesseractz4No tessdata specified and Tesseract is not installedrp  z8No tessdata specified and Tesseract installation has no z folderzwhereis z/*/tessdataz(No tessdata specified and no match for:
r  )ztesseract-ocr	tesseractr  )rh   r   
subprocessrm  
returncoderw  r  stdoutrx  r  platformr:
  r   r   dirnamer  r  r   r8   r9   ro   globr  )rp  r  cpr  rS  r   attemptsr   pattern	tessdatasr   attempts   &           r'   rj  rj  hW  s     yy*+H 	0!ST[_	`B	}}II=ryyIwwqzHO ||w^^-QqPQX\^]99??$===UVV''//(+77<<477>>(##O!YZbYccjkll vH,^^htf-QqPQX\^]==Ayy(..0H8}!"1+$I[1( IIg.	 9$R=( - :Gd7)$$D  4  QRRr)   CSSr  c          
     ,    V ^8  d   QhRRRRRRRRRR/# )	r  fontcoder  r'  r  r  AnyTyper   rs  r,   )r  s   "r'   r  r  W  s;     B BB!B3:BIOBBr)   c                   Rp\        V4      \        J g   \        R4      hVf   Rp\        P	                  4        Uu. uF  qUP                  V 4      '       g   K  VNK  	  ppV. 8X  d   \        RV  R24      h\        V4      ^8  d   \        R4      hVf   T pV Fj  p\        V,          pVR,          p	VR,          p
VR	,          ! 4       pVP                  W4       V	'       d   R
MRpV
'       d   RMRpWW7W3,          ,          pKl  	  V# u upi )a  Create @font-face items for the given fontcode of pymupdf-fonts.

Adds @font-face support for fonts contained in package pymupdf-fonts.

Creates a CSS font-family for all fonts starting with string 'fontcode'.

Note:
    The font naming convention in package pymupdf-fonts is "fontcode<sf>",
    where the suffix "sf" is either empty or one of "it", "bo" or "bi".
    These suffixes thus represent the regular, italic, bold or bold-italic
    variants of a font. For example, font code "notos" refers to fonts
    "notos" - "Noto Sans Regular"
    "notosit" - "Noto Sans Italic"
    "notosbo" - "Noto Sans Bold"
    "notosbi" - "Noto Sans Bold Italic"

    This function creates four CSS @font-face definitions and collectively
    assigns the font-family name "notos" to them (or the "name" value).

All fitting font buffers of the pymupdf-fonts package are placed / added
to the archive provided as parameter.
To use the font in pymupdf.Story, execute 'set_font(fontcode)'. The correct
font weight (bold) or style (italic) will automatically be selected.
Expects and returns the CSS source, with the new CSS definitions appended.

Args:
    fontcode: (str) font code for naming the font variants to include.
              E.g. "fig" adds notos, notosi, notosb, notosbi fonts.
              A maximum of 4 font variants is accepted.
    CSS: (str) CSS string to add @font-face definitions to.
    archive: (Archive, mandatory) where to place the font buffers.
    name: (str) use this as family-name instead of 'fontcode'.
Returns:
    Modified CSS, with appended @font-face statements for each font variant
    of fontcode.
    Fontbuffers associated with "fontcode" will be added to 'archive'.
z1
@font-face {font-family: %s; src: url(%s);%s%s}
z'archive' must be an Archiver`   zNo font code 'z' found in pymupdf-fonts.zfontcode too shortr  r  r   zfont-weight: bold;zfont-style: italic;)r   r~  r   r  r  r5   r9   r  )r)  r'  r  r   CSSFONTr  	font_keysfkeyr  r  r  fbuff	bold_textitalic_texts   &$$$          r'   css_for_pymupdf_fontr2  W  s   R DG=G#788
{ 1557R7q<<;Q7IRB>(3LMNN
9~-..|#D)F|hX E ,0(b	/5+2$i===  J# Ss   DDc          
     ,    V ^8  d   QhRRRRRRRRRR/# )	r  r   r  r   r   r  r  r6   rs  r,   )r  s   "r'   r  r  W  s1     ': ':# ': ': ':UX ':`e ':r)   c           	        VP                  4       p\        P                  VR4      pRpVR8X  d   \        pVR8X  d   \        pVe[   \        V  Uu. uF<  p\        V4      R8  d   V\        V4      ,          ^,          MV^,          ^,          NK>  	  up4      pWr,          # V\        P                  4       9   d   \        V \        V,          W#4      # VR9   d   \        V 4      V,          # \        RV R24      hu upi )zCalculate length of a string for a built-in font.

Args:
    fontname: name of the font.
    fontsize: font size points.
    encoding: encoding to use, 0=Latin (default), 1=Greek, 2=Cyrillic.
Returns:
    (float) length of text.
Nr>  r=  r  zFont 'z' is unsupported)r  r  r  r  r  r  r  r  )r  r"  r:   rN  rM  r  r:  r  util_measure_stringr9   r   )r   r   r   r  r  r?  r  r   s   &&&&    r'   r  r  W  s     ~~H""8T2HF8>!PTUPT1c!fslA"sAFPTUV|?''))"/(+X
 	
  	 	 4y8##
vhZ'78
99) Vs   AC:c                    V ^8  d   QhRRRR/# )r  r2  r  rs  r7   r,   )r  s   "r'   r  r  X  s     ' 'z 'd 'r)   c                   \        V 4      \        P                  J d   V P                  4       pMK\	        V R4      '       d   V P                  4       pM(\        V 4      \        \        39   d   T pM\        R4      h\        P                  V4      # )a*  Return basic properties of an image.

Args:
    img: bytes, bytearray, io.BytesIO object or an opened image file.
Returns:
    A dictionary with keys width, height, colorspace.n, bpc, type, ext and size,
    where 'type' is the MuPDF image type (0 to 14) and 'ext' the suitable
    file extension.
r  zbad argument 'img')r   r;   r  r  r=   r  r  r  r   r  image_profile)r2  r   s   & r'   r8  r8  X  sj     CyBJJ	f			cui(	(-..v&&r)   c                <  a  \        S P                  \        4      '       g   Q h\        S P                  4      '       g   S P                  '       d]   S P                  f   Q h\        S P                  S P                  4      ! S P                  4      pV'       g   \        R4       RS n        R# V 3R lp\        S P                  \        4      '       g   Q h\        S P                  4      pV^ 8X  d   V! 4       # S P                  \        ,          pVR8w  d   V! 4       # S P                  V^,
          ,          pV\        ,          pVR8w  d   V! 4       # V\        ,          pS P                  \        ,          pWx8w  d   V! 4       #  S P                  P                  4        F  w  rW9  g   K  WV	&   K  	  ^ pV^ 8X  d&   RV\        &   S P                  P                  4        R# \        R4       V! 4        R#   \         d    \        '       d   \        4        Rp Lei ; i)	aU  
Append current path to list or merge into last path of the list.
(1) Append if first path, different item lists or not a 'stroke' version
    of previous path
(2) If new path has the same items, merge its content into previous path
    and change path["type"] to "fs".
(3) If "out" is callable, skip the previous and pass dictionary to it.
Nz2calling cdrawings callback function/method failed!c                    < S P                   P                  S P                  P                  4       4       S P                  P	                  4        R # r+   )rF	  ro   pathdictr8  rW  r  s   r'   ro   jm_append_merge.<locals>.appendNX  s0    s||((*+r)   r  r  r  z$could not merge stroke and fill pathr  )r@   rF	  r   r]  rb  r   r;  rv   r9   r  dictkey_itemsrD   rk   r  r{   rW  )r  respro   r  thistyper  prevtype	previtems	thisitemsr  rH   r   s   f           r'   jm_append_mergerD  3X  s    cggt$$$$ 

szzz::1 377CJJ/=DHI cggt$$$$sww<Dqyx||\*H3x77DFD\"H3xm$Im,IxLL&&(DA}Q ) 
 
Qw"l67  N$4s   "G5 +
G5 5HHHc                    V P                   '       g)   V P                  P                  V\        V4      34       R # V P                  P                  V\        V4      V P                  34       R # r+   )rW  r  ro   rp  
layer_name)r  r  r   r  s   &&&&r'   jm_bbox_add_rectrG  zX  sI    :::

D/$"789

D/$"7HIr)   c                    \         P                  ! \         P                  P                  4      p\         P                  ! VP	                  4       V4      p\        WVR 4       R# )z
fill-imageN)r   rq  rE  ll_fz_transform_rectr  rG  )r  r  r  r  r  color_paramsr$  s   &&&&&& r'   jm_bbox_fill_imagerK  X  s>    U\\,,-A""AJJL#6Ac<0r)   c                     \        W\        P                  ! \        P                  V4      R 4       R#   \         d    \
        '       d   \        4        h i ; i)zfill-imgmaskN)rG  r   rI  fz_unit_rectrk   r  r{   )r  r  r  r  r  rp  r  rJ  s   &&&&&&&&r'   jm_bbox_fill_image_maskrN  X  sE    #E$>$>u?Q?QSV$WYgh N$4s   04 AAc	           	         V'       d   R MRp \        W\        P                  ! VRV4      R4       R#   \         d    \        '       d   \        4        h i ; i)TFNz	fill-pathrG  r   ll_fz_bound_pathrk   r  r{   	r  r  r   rr  r  r  rp  r  rJ  s	   &&&&&&&&&r'   jm_bbox_fill_pathrS  X  sH    tUH#E$:$:4s$K[Y N$4s   #3 A
Ac                     \        W\        P                  ! W#4      R 4       R#   \         d    \        '       d   \        4        h i ; i)z
fill-shadeN)rG  r   ll_fz_bound_shaderk   r  r{   )r  r  shader  r  rJ  s   &&&&&&r'   jm_bbox_fill_shaderW  X  s;    #E$;$;U$H,W N$4s   !% AAc           	          \        W\        P                  ! W#V4      R 4       R#   \         d    \        '       d   \        4        h i ; i)zstroke-textNrG  r   ll_fz_bound_textrk   r  r{   )r  r  r   r  r  r  s   &&&&&*r'   jm_bbox_stroke_textr[  X  >    #E$:$:D#$NP]^ N$4   "& A	A	c           	          \        W\        P                  ! VR V4      R4       R #   \         d    \        '       d   \        4        h i ; i)Nz	fill-textrY  )r  r  r   r  r  s   &&&&*r'   jm_bbox_fill_textr_  X  s?    #E$:$:D$$LkZ N$4s   #' A
A
c           	     L    \        W\        P                  ! VR V4      R4       R # )Nzignore-text)rG  r   rZ  )r  r  r   r  s   &&&&r'   jm_bbox_ignore_textra  X  s    c 6 6tT3 GWr)   c	           	          \        W\        P                  ! W#V4      R 4       R#   \         d    \        '       d   \        4        h i ; i)zstroke-pathNrP  )	r  r  r   r  r  r  rp  r  rJ  s	   &&&&&&&&&r'   jm_bbox_stroke_pathrc  X  r\  r]  c                   V P                   \        ,          p\        V4      p^ .^,          p\        ^4       Fn  pW^,
          V,           ,          p\	        V^,          4      pVP
                  W4^,          &   VP                  W4^,          ^,           &   \	        V^,          4      pKp  	  XP
                  V^ ,          8w  g   VP                  V^,          8w  d   ^ # ^ V n        \        P                  ! V^ ,          V^,          V^,          V^,          V^,          V^,          V^,          V^,          4      pR\        V4      3p	WV^,
          &   W^,
          V1 ^# )a  
Check whether the last 4 lines represent a quad.
Because of how we count, the lines are a polyline already, i.e. last point
of a line equals 1st point of next line.
So we check for a polygon (last line's end point equals start point).
If not true we return 0.
rq  )r;  r>  r9   rS  r+  ri  rj  	linecountr   ro  r  )
r  rD   r  r  rg  rs   r  r  rc  r   s
   &         r'   jm_checkquadrf  X  s    LL-(Eu:D	
aAAYQhl#a)66a%vva%!)tQx(  
ttqt|rttqt|  CM 	1Q41qtQqT1Q41qtQqTJA/!$%D4!8ax$r)   c                   ^ V n         ^ pV P                  \        ,          p\        V4      pW#^,
          ,          p\	        V^,          4      p\	        V^,          4      pW#^,
          ,          p\	        V^,          4      p\	        V^,          4      p	 VP
                  VP
                  8w  gR   VP                  V	P                  8w  g7   VP
                  V	P
                  8w  g   VP                  VP                  8w  d   ^ # V	P
                  VP
                  8  dE   \        P                  ! V	P                  V	P
                  VP                  VP
                  4      p
^pMC\        P                  ! VP                  VP
                  VP                  VP
                  4      p
RpR\        V
4      V3pWV^,
          &   W#^,
          V1 ^# )zq
Check whether the last 3 path items represent a rectangle.
Returns 1 if we have modified the path, otherwise 0.
rw  r  )
re  r;  r>  r9   r+  rj  ri  r   r2  rp  )r  r  rD   r  rQ  r  r  line2r  r  r$  r   s   &           r'   jm_checkrectri  X  sR    CMKLL-(Eu:D!8E	5!9	%B	5!9	%B !8E	5!9	%B	5!9	%B 	
ttrtt|ttrtt|ttrtt|ttrtt| 
ttbdd{rttRTT2446rttRTT2446?1%{3D4!8ax$r)   c           
     h    VP                   p V'       g   R# \        WW#WEWg4       VP                  pK'  r  )headjm_trace_text_spanr]  )	r  r   rb  r  r  rp  r  seqnorJ  s	   &&&&&&&& r'   jm_trace_textrn  Y  s+    99D
Cu:eSyyr)   c                    Rp\        V\        P                  4      '       g   Q h\        P                  ! V4      p\        V\        P                  4      '       g   Q h\        P
                  ! V4      p\        VP                  4       4      p	\        P                  ! VP                  4       V4      p
\        P                  ! \        P                  ! ^^ 4      V
4      p\        P                  ! VP                  VP                  ,          VP                  VP                  ,          ,           4      p\        P                   ! V4      p^ p\#        VP                  4       4      p\%        VP                  4       4      pVR8  d   RpRpW,          W,
          ,          pW,          W,
          ,          p^ p\        P&                  ! VP                  4       4      pVV\(        ,          ,          pV\        P*                  ! VP                  4       4      \,        ,          ,          pV\        P.                  ! VP                  4       4      \0        ,          ,          pV\        P2                  ! VP                  4       4      \4        ,          ,          p^ p\        P6                  ! 4       p\        P8                  ! VP                  VP                  VP                  ) VP                  ^ ^ 4      pVP                  R8X  d   ^Vn        . p\=        VP>                  P@                  4       EF0  p^ pVPC                  V4      PD                  ^ 8  dT   \        PF                  ! VP                  4       VPC                  V4      PD                  VP>                  PH                  4      pVV,          pTpVPC                  V4      PJ                  ^ 8X  d   Tp\        P                  ! VPC                  V4      P                  VPC                  V4      P                  4      p\        PL                  ! VV4      p\        P8                  ! ^^ ^ ^VP                  ) VP                  ) 4      p\        P                  ! VV4      p\        P                  ! V\        P
                  ! ^^ ^ ^VP                  VP                  4      4      pVP                  pVV,           pV
P:                  ^ 8  d#   VP                  ^8X  g?   VP                  R8X  g.   V
PN                  ^ 8w  dD   V
PN                  V
PP                  ) 8X  d(   VP                  V,           pVP                  V,           pM&VP                  V,
          pVP                  V,
          p\        PR                  ! VVVV4      p \        PT                  ! V V4      p VPW                  VPC                  V4      PJ                  VPC                  V4      PD                  VP                  VP                  3V PX                  V PZ                  V P\                  V P^                  334       V^ 8  d   \        P`                  ! VV 4      pEK.  T pEK3  	  \c        V4      pV'       g   V\(        ,          '       gx   \        Pd                  ! VP                  4       ^ ^ ^ 4      w  p!p\        PF                  ! VP                  4       V!VP>                  PH                  4      pW,          pV'       g   TpMTp\g        4       p"\i        V4      V"R&   \k        V	4      V"R&   VP>                  PH                  V"R&   VV"R&   VP>                  Pl                  V"R&   VP>                  Pn                  V"R	&   VV"R
&   VV"R&   ^V"R&   V'       d   \        Pp                  ! \        Pr                  ! \        Pt                  ! V4      4      V\        Pv                  ! 4       \        Pr                  ! 4       \        Px                  ! 4       4      p#V#R,          p#MRp#V Pz                  ^ 8  d   V Pz                  p$M	VR,          p$V#V"R&   VV"R&   VV"R&   V$V"R&   VV"R&   VV"R&   \}        V4      V"R&   V P~                  V"R&   VV"R&   VV"R&   V P                  PW                  V"4       R# )z
jm_trace_text_span(fz_context *ctx, PyObject *out, fz_text_span *span, int type, fz_matrix ctm, fz_colorspace *colorspace, const float *color, float alpha, size_t seqno)
NrV  r  r  r  r=  r  bidi_lvlbidi_dirr:  r;  r  rk  rG  rp  r  r]  	linewidth
spacewidthr   r6  layerrm  r  r  r  r  )Ar@   r   fz_text_span
FzTextSpan	fz_matrixr|  r  r  rf  r#  fz_transform_vectorr  r  r  ri  rj  fz_normalize_vectorr  r  rt  r  rq  r  rx  r  rn  r  rq  r  rH  rS  r   r9   rD   r@  r  r=  r  rh  rI  r  r2  r  ro   r  r  r  r  r|  r   r<  r7   r  r  r  r$  fz_convert_colorr-  r  r  r  rr  rp  rF  rF	  )%r  rJ  rb  r  r  rp  r  rm  out_fontr   r  r  r7  	space_advrR  rS  ascsizedscsizefflagsrK  last_adv	span_bboxry  r  rg  r  	char_origr  r  r  r  r  	char_bboxr  	span_dictr  rr  s%   &&&&&&&&                             r'   rl  rl  Y  s{    HtU//0000T"DsEOO,,,,
..#
CTYY[)H //$((*c
*C

#
#E$7$71$=s
CCIIceeceemceeceem34E

#
#C
(CI
DIIK
(C
TYY[
)C
Tz kSY'GkSY'GF&&		4D
d)))F
e%%tyy{36FFFF
e$$diik25FFFF
e##TYY[1NBBFH I


suuceeceeVSUUAq
AC
uu{EDOO''(::a=!(($))+tzz!}7H7H$//J_J_`Cu::a="I''

1AI	,,Y<	!!!Q1y{{lY[[LI__R%__R1aIKK!UV[[#X
ceerk!#%%w&Bw&Bw&Bw&B&&r2r26	++Ir:	JJqM%%JJqM%%!!
 "!!!		  q5++IyAI!I] )^ %LE---AA499;PRTUWXYKAx..IIKOO))I
 I$	 I I(-Iu,X6Iv////IwIw OO66Iz!__77Iz Iz!I{ I|$$""E$?$?$LM##%""$##% "g
}}qMM	DL	 IwIv!Iy'I{(I|Iv(3Iv..IwIwIwGGNNIr)   c                `   V '       d    \         P                  ! \         P                  P                  4      p\         P                  ! 4       p\         P                  ! V VVP
                  R VP                  4       4      pVR,          # R#   \         d    \        '       d   \        4        h i ; i)Nrk  r,   )
r   r-  r3  r  ll_fz_convert_colorr   r  rk   r  r{   )r  rp  r  r"  r  s   &&   r'   jm_lineart_colorr  Y  s    	 ##U%7%7%A%ABB$$&B++MMKKMC 2wI	  	##(8	s   A5B
 
B-!B-c                b    \        V P                  \        4      '       d   . V n        . V n        R # r+   )r@   rF	  r   scissorsr  r  s   &&r'   jm_lineart_drop_devicer  Y  s!    #''4  CLr)   c	                   V'       d   R MRp \        V\        P                  4      '       g   Q h\        P                  ! V4      V n        \
        V n        \        WV4       V P                  f   R# RV P                  \        &   W0P                  R&   WpP                  R&   \        WV4      V P                  R&   \        V P                  4      V P                  \        &   V P                  V P                  R&   V P                  V P                  R&   V P                   '       d   V P"                  V P                  R	&   \%        V 4       V ;P                  ^,          un        R#   \&         d    \(        '       d   \+        4        h i ; i)
TFNr  rr  r	  r   rm  rt  r   )r@   r   rw  r|  r  trace_device_FILL_PATH	path_typejm_lineart_pathr;  r  r  rp  pathrectdictkey_rectrm  rF  rc  ra	  rD  rk   r  r{   rR  s	   &&&&&&&&&r'   jm_lineart_fill_pathr  Y  s     tUH30000..#&.4(<< &)l#$,j!(-n% !1* Df&5cll&Cl#!$g!$g999%(YYCLL'"		Q	 N$4s   A"E" 2C.E" "F9Fc           
     l     \        Y^ Y4YVT P                  4       T ;P                  ^,          un        R# r   )r%   r   rn  rm  )r  r  r   r  r  rp  r  rJ  s   &&&&&&&&r'   jm_lineart_fill_textr  Y  s(     #QsyyIIINIr)   c           
     n    \        W^VRR^V P                  4       V ;P                  ^,          un        R# )r   Nrn  rm  )r  r   r  s   &&&r'   jm_lineart_ignore_textr  Z  s'    #QT4CII>IINIr)   c                  @   a  ] tR tRtV 3R ltR tR tR tR tRt	V ;t
# )WalkeriZ  c                	   < \         SV `  4        V P                  4        V P                  4        V P	                  4        V P                  4        Wn        R # r+   )r   r   use_virtual_movetouse_virtual_linetouse_virtual_curvetouse_virtual_closepathr  )r&   r  r
  s   &&r'   r   Walker.__init__Z  sC    !!  """$r)   c                	,    V P                   P                  ^8X  d   \        V P                   4      '       d   R# ^ V P                   n        V P                   P                  '       d   V P                   P                  V P                   P
                  8w  d   R\        V P                   P                  4      \        V P                   P
                  4      3pV P                   P                  \        ,          P                  V4       V P                   P
                  V P                   n        RV P                   P                  R&   MRV P                   P                  R&   ^ V P                   n        R#   \         d    \        '       d   \        4        h i ; i)r   NrX  Fr  T)r  re  ri  havemove	lastpoint
firstpointr  r;  r>  ro   rk   r  r{   )r&   r  rE   s   && r'   	closepathWalker.closepathZ  s   	xx!!Q&))!"DHHxx   88%%)<)<<!1$((2D2D!E!1$((2E2E!FHDHH%%m4;;DA)-)<)<DHH&16!!+. 37!!;/ !"DHH 	##(8	s   6E0 ,E0 'DE0 0FFc                	P    ^ V P                   n        \        P                  ! W#4      p\        P                  ! WE4      p	\        P                  ! Wg4      p
\        P                  ! WP                   P
                  4      p\        P                  ! WP                   P
                  4      p	\        P                  ! WP                   P
                  4      p
\        P                  ! V P                   P                  V4      V P                   n        \        P                  ! V P                   P                  V	4      V P                   n        \        P                  ! V P                   P                  V
4      V P                   n        R\        V P                   P                  4      \        V4      \        V	4      \        V
4      3pWP                   n	        V P                   P                  \        ,          P                  V4       R#   \         d    \        '       d   \        4        h i ; i)rx   r  N)r  re  r   r  rh  r  fz_include_point_in_rectr  r  r  r;  r>  ro   rk   r  r{   )r&   r  r  r  x2y2x3y3rJ  rK  r  rp  s   &&&&&&&&    r'   curvetoWalker.curveto8Z  ss   	!"DHH$$R,B$$R,B$$R,B))"hhll;B))"hhll;B))"hhll;B % > >txx?P?PRT UDHH % > >txx?P?PRT UDHH % > >txx?P?PRT UDHH $TXX%7%78$R($R($R(E "$HHHH}-44e< 	##(8	s   G>H H%H%c                	    \         P                  ! \         P                  ! W#4      V P                  P                  4      p\         P
                  ! V P                  P                  V4      V P                  n        R \        V P                  P                  4      \        V4      3pW@P                  n        V P                  P                  \        ,          pVP                  V4       V P                  ;P                  ^,          un        V P                  P                  ^8X  d9   V P                  P                  \        8w  d   \        V P                  4       R# R# R#   \          d    \"        '       d   \%        4        h i ; i)rX  N)r   rh  r  r  r  r  r  r  r  r;  r>  ro   re  r  r  rf  rk   r  r{   )r&   r  ri  rj  rJ  rp  rD   s   &&&&   r'   linetoWalker.linetoSZ  s   	))5+>+>q+DdhhllSB % > >@Q@QSU VDHH$dhh&8&89$R(E
 "$HHHH%%}5ELL% HH!#xx!!Q&488+=+=AW+WTXX& ,X&  	##(8	s   EE   F7Fc                	      \        P                  ! \        P                  ! Y#4      T P                  P                  4      T P                  n        \        P                  ! T P                  P                  4      '       d   \        P                  ! T P                  P                  P                   T P                  P                  P"                  T P                  P                  P                   T P                  P                  P"                  4      T P                  n        T P                  P                  T P                  n        ^T P                  n        ^ T P                  n        R#   \*         d    \,        '       d   \/        4        h i ; ir   )r@   r  r;  r7   r%   rD   r   r9   r   rh  r  r  r  r  r  r2  ri  rj  r  r  re  rk   r  r{   )r&   r  ri  rj  rG   rH   s   &&&&  r'   movetoWalker.movetohZ  s   	!&!9!9''-HHLL"DHH (($((*;*;<<$)$6$6**,,**,,**,,**,,	%! #'(("4"4DHH !DHH!"DHH 	##(8	s   E%E* *FFr<  )r/   r0   r1   r2   r   r  r  r  r  r3   r  r  s   @r'   r  r  Z  s!    86* r)   r  c                8    \         P                  ! \         P                  P                  4      V n        ^ V n        \         P
                  ! ^ ^ 4      V n        \        4       V n        . V P                  \        &   \        V 4      p\         P                  ! \         P                  ! \         P                  ! V4      4      W3P                  4       V P                  \        ,          '       g
   RV n        R# R#   \         d    \         '       d   \#        4        h i ; i)a  
Create the "items" list of the path dictionary
* either create or empty the path dictionary
* reset the end point of the path
* reset count of consecutive lines
* invoke fz_walk_path(), which create the single items
* if no items detected, empty path dict again
N)r   rq  rr  r  re  rg  r  r7   r;  r>  r  fz_walk_pathFzPathll_fz_keep_pathr   rk   r  r{   )r  r  r   walkers   &&& r'   r  r  Z  s    ||U\\%@%@Aq!,v')m$  	ELL)>)>t)DEvO`O`a||]++CL , N$4s   C0C6 6DDc	                    \        V\        P                  4      '       g   Q h\        P                  ! \        VP                  VP                  ,          VP                  VP                  ,          ,
          4      4      V n
        \        P                  ! V4      V n        \        V n        \        WV4       V P                   f   R # RV P                   \"        &   WpP                   R&   \%        WV4      V P                   R&   V P                  VP&                  ,          V P                   \(        &   VP*                  VP,                  VP.                  3V P                   R&   \1        VP2                  4      V P                   R&   RV P                   9  d   RV P                   R&   VP4                  '       d   \        P6                  ! R4      p	\        P8                  ! V	R	4       \;        VP4                  4       FX  p
\        P<                  ! VP>                  V
4      p\        P8                  ! V	\A        V P                  V,          4       R
24       KZ  	  \        P8                  ! V	R\A        V P                  VPB                  ,          4       24       WP                   R&   MRV P                   R&   \E        V PF                  4      V P                   \H        &   V PJ                  V P                   R&   V PL                  V P                   R&   V PN                  '       d   V PP                  V P                   R&   \S        V 4       V ;PL                  ^,          un&        R #   \T         d    \V        '       d   \Y        4        h i ; i)Nr  r  rp  r  r  r  Fr  z[ r   z] r  r  rt  rm  r   )-r@   r   rw  r  r  r,  r   rH  rI  r  
pathfactorr|  r  trace_device_STROKE_PATHr  r  r;  r  r  rr  r  	start_capdash_capend_capr  linejoindash_lenr0
  r  rS  floats_getitem	dash_listr   
dash_phaserp  r  r  rF  rm  rc  ra	  rD  rk   r  r{   )r  r  r   r  r  r  rp  r  rJ  r  rg  r   s   &&&&&&&&&   r'   jm_lineart_stroke_pathr  Z  sr   .300003suusuu}suusuu}'D#EF..#&04(<<&)l#*/&'!1:!Eg'*~~8H8H'Hm$  $i 
 %*&//$:j!cll*(-CLL% ???&&,D""D$/FOO, ,,f.>.>B&&3>>E;Q1R0SST.UV	 -
 ""DBy&J[J[9[/\.]*^_&*LL(#&,CLL(#&5cll&Cl# #W!$g999%(YYCLL'"		Q	 N$4s    CM C*M 2F!M M8,M8c                6   V P                   '       g   R # \        P                  ! V4      V n        \        V n        \        WV4       V P                  f   R # RV P                  \        &   \        V4      V P                  R&   RV P                  9  d   RV P                  R&   \        \        V 4      4      V P                  R&   V P                  V P                  R&   V P                  V P                  R&   \        V 4       V ;P                  ^,          un        R # )Nr  rr  r  Frp  r   rt  )rc  r   r|  r  trace_device_CLIP_PATHr  r  r;  r  r   rp  compute_scissorra	  rF  rD  )r  r  r   rr  r  rp  s   &&&&&&r'   jm_lineart_clip_pathr  Z  s    999nnS!CG*CMCd#
||"(CLL, $XCLL*#,,&$)[!-oc.BCCLLIICLLNNCLLCIINIr)   c                   V P                   '       g   R # \        P                  ! V4      V n        \        V n        \        WV4       V P                  f   R # RV P                  R&   R V P                  R&   RV P                  9  d   RV P                  R&   \        \        V 4      4      V P                  R&   V P                  V P                  R&   V P                  V P                  R&   \        V 4       V ;P                  ^,          un
        R # )	Nr  r  rr  r  Frp  r   rt  )rc  r   r|  r  trace_device_CLIP_STROKE_PATHr  r  r;  rp  r  ra	  rF  rD  )r  r  r   r  r  rp  s   &&&&&&r'   jm_lineart_clip_stroke_pathr  Z  s    999nnS!CG1CMCd#
||#)CLL #CLL#,,&$)[!-oc.BCCLLIICLLNNCLLCIINIr)   c                v    V P                   '       g   R # \        V 4       V ;P                  ^,          un        R # r+   rc  r  ra	  )r  r  r   r  r  rp  s   &&&&&&r'   jm_lineart_clip_stroke_textr  [  #    999CIINIr)   c                v    V P                   '       g   R # \        V 4       V ;P                  ^,          un        R # r+   r  )r  r  r   r  rp  s   &&&&&r'   jm_lineart_clip_textr  [  r  r)   c                v    V P                   '       g   R # \        V 4       V ;P                  ^,          un        R # r+   r  )r  r  r  r  rp  s   &&&&&r'   jm_lineart_clip_image_maskr  [  r  r)   c                    V P                   '       d   V P                  '       g   R # \        V P                  4      pV^8  d   R # V P                  R V ;P                  ^,          un        R # )Nr  )rc  r  r9   ra	  )r  r  r  s   && r'   jm_lineart_pop_clipr  [  sG    999CLLLs||DaxRIINIr)   c                4    V'       d	   W n         R# R V n         R# r`   NrF  )r  r  r   s   &&&r'   jm_lineart_begin_layerr  $[  s    r)   c                    R V n         R# r  r  r  s   &&r'   jm_lineart_end_layerr  +[  s	    CNr)   c                *   V P                   '       g   R # RRR\        V4      R\        V4      R\        V4      R\        P                  ! V4      RVRV P
                  R	V P                  /V n        \        V 4       V ;P
                  ^,          un        R # )
Nr   rx  r   isolatedknockoutr  r]  r   rt  )	rc  rp  r   r   fz_blendmode_namera	  rF  r;  rD  )r  r  r6  r  r  r  r  r  s   &&&&&&&&r'   jm_lineart_begin_groupr  /[  sv    999GOD)XX00;uSYYS^^	CL CIINIr)   c                `    V P                   '       g   R # V ;P                  ^,          un        R # r+   )rc  ra	  r  s   &&r'   jm_lineart_end_groupr  A[  s    999IINIr)   c	           
     j    \        W^WEWgV P                  4       V ;P                  ^,          un        R# r  r  )	r  r  r   r  r  r  rp  r  rJ  s	   &&&&&&&&&r'   jm_lineart_stroke_textr  H[  s#    #QsyyIIINIr)   c	                >    VP                   V n         \        W4       R # r+   )rr  jm_increase_seqno)	r  r  r   r  r  r  rp  r  rJ  s	   &&&&&&&&&r'   jm_dev_linewidthr  M[  s    $$CMs r)   c                     V ;P                   ^,          un         R#   \         d    \        '       d   \        4        h i ; ir  )rm  rk   r  r{   )r  r  vargss   &&*r'   r  r  R[  s1    		Q	 N$4s    A A c               $    V ^8  d   QhRRRRRR/# )r  rJ  r   rK  rs  r  r,   )r  s   "r'   r  r  Z[  s!     + +Z +Z +F +r)   c                V    \        V 4      p \        V4      p\        \        W4      4      # )aM  Compute matrix which maps line from p1 to p2 to the x-axis, such that it
maintains its length and p1 * matrix = Point(0, 0).

Args:
    p1, p2: point_like
Returns:
    Matrix which maps p1 to Point(0, 0) and p2 to a point on the x axis at
    the same distance to Point(0,0). Will always combine a rotation and a
    transformation.
)r)  r  r  )rJ  rK  s   &&r'   rp  rp  Z[  s&     
rB	rB/")**r)   c                  .   a  ] tR tRtV 3R ltR tRtV ;t# )JM_image_reporter_Filterij[  c                	D   < \         SV `  4        V P                  4        R # r+   r  r  s   &r'   r   !JM_image_reporter_Filter.__init__k[  s    %%'r)   c                	    \        V\        P                  4      '       g   Q h\        V \        P                  ! V4      W44       \
        '       d   ^ # R# r   )r@   r   rw  r  r|  r   )r&   r  r  r   r  s   &&&&&r'   r  %JM_image_reporter_Filter.image_filtero[  s=    #u////ennS14?;  r)   r,   r  r  s   @r'   r  r  j[  s    ( r)   r  c                  P   a  ] tR tRtV 3R lt]t]t]	t
]t]t]t]t]t]t]tRtV ;t# )rB  ix[  c                	  < \         SV `  4        Wn        W n        R V n        V P                  4        V P                  4        V P                  4        V P                  4        V P                  4        V P                  4        V P                  4        V P                  4        V P                  4        V P                  4        R# r  )r   r   r  rW  rF  use_virtual_fill_pathuse_virtual_stroke_pathuse_virtual_fill_textuse_virtual_stroke_textuse_virtual_ignore_textuse_virtual_fill_shadeuse_virtual_fill_imageuse_virtual_fill_image_maskuse_virtual_begin_layeruse_virtual_end_layer)r&   r  rW  r
  s   &&&r'   r   "JM_new_bbox_device_Device.__init__y[  s    ""$$$&""$$$&$$&##%##%((*$$&""$r)   )rF  rW  r  )r/   r0   r1   r2   r   r  begin_layerr  	end_layerrS  	fill_pathrc  stroke_pathr_  	fill_textr[  stroke_textra  ignore_textrW  
fill_shaderK  
fill_imagerN  fill_image_maskr3   r  r  s   @r'   rB  rB  x[  s<    %" )K$I!I%K!I%K%K#J#J-Or)   rB  c                  @   a  ] tR tRtV 3R ltR tR tR tR tRt	V ;t
# )rJ  i[  c                	   < \         SV `  4        Wn        V P                  4        V P	                  4        V P                  4        V P                  4        R # r+   )r   r   r  use_virtual_writeuse_virtual_seekuse_virtual_telluse_virtual_truncate)r&   r  r
  s   &&r'   r   %JM_new_output_fileptr_Output.__init__[  sC     !!#r)   c                	8    V P                   P                  W#4      # r+   )r  rQ
  )r&   r  r[  whences   &&&&r'   rQ
  !JM_new_output_fileptr_Output.seek[  s    xx}}f--r)   c                	:    V P                   P                  4       pV# r+   )r  tell)r&   r  rI   s   && r'   r  !JM_new_output_fileptr_Output.tell[  s    hhmmo
r)   c                	6    V P                   P                  4       # r+   )r  truncate)r&   r  s   &&r'   r  %JM_new_output_fileptr_Output.truncate[  s    xx  ""r)   c                	d    \         P                  ! W#4      pV P                  P                  V4      # r+   )r   raw_to_python_bytesr  r   )r&   r  data_rawdata_lengthr  s   &&&& r'   r   "JM_new_output_fileptr_Output.write[  s%    ((?xx~~d##r)   rK  )r/   r0   r1   r2   r   rQ
  r  r  r   r3   r  r  s   @r'   rJ  rJ  [  s!    $.#$ $r)   rJ  c                d   V P                   f   \        4       V n         \        V P                   4      pV^ 8  dG   V P                   V^,
          ,          p\        V4      p\        P
                  ! W0P                  4      pMV P                  pV P                   P                  \        V4      4       V# )zg
Every scissor of a clip is a sub rectangle of the preceding clip scissor
if the clip level is larger.
)	r  r   r9   r  r   r'  r  ro   rp  )r  num_scissorslast_scissorrp  s   &   r'   r  r  [  s    
 ||vs||$La||LN3!,/))'<<@,,LL01Nr)   c                  t   a  ] tR tRtRtV 3R lt]t]t	]
t]t]t]t]t]t]t]t]t]t]t]t]t]t ]!t"]#t$Rt%V ;t&# )r^  i[  z7
LINEART device for Python method Page.get_cdrawings()
c                	4  < \         SV `  4        V P                  4        V P                  4        V P	                  4        V P                  4        V P                  4        V P                  4        V P                  4        V P                   V P                   V P                   V P                  4        V P                  4        V P                  4        V P                  4        V P!                  4        V P#                  4        V P%                  4        V P'                  4        Wn        ^ V n        ^ V n        W n        W0n        RV n        RV n        RV n        ^ V n        \:        P<                  ! 4       V n        \:        P<                  ! 4       V n         \:        P<                  ! 4       V n!        \:        PD                  ! 4       V n#        \:        PD                  ! 4       V n$        ^ V n%        \:        PL                  ! 4       V n        ^ V n'        ^ V n(        ^ V n)        R# rx   Nr`   )*r   r   r  r  use_virtual_clip_pathuse_virtual_clip_image_maskuse_virtual_clip_stroke_pathuse_virtual_clip_stroke_textuse_virtual_clip_textr  r  r  r  r  r  use_virtual_pop_clipuse_virtual_begin_groupuse_virtual_end_groupr  r  rF	  rm  ra	  rc  rb  r  rF  r  rr  r   r|  r_  r  ry  rg  r  r  r  rq  r  re  r  )r&   rF	  rc  rb  r
  s   &&&&r'   r   %JM_new_lineart_device_Device.__init__[  s    	""$$$&""$((*))+))+""$""$$$$##%##%((*!!#$$&""$$$&""$


>>#>>#>>#--/r)   )rc  r  ra	  r  r  r  rF  re  rr  rb  rF	  r  r  r  r_  ry  r  rm  )'r/   r0   r1   r2   rc  r   r  r  r  r  r  clip_image_maskr  	clip_pathr  clip_stroke_pathr  	clip_textr  clip_stroke_textr  r  r  r  r  r  r  r  pop_clipr  begin_groupr  	end_groupr  r  r  r   r3   r  r  s   @r'   r^  r^  [  sl    1j /I0K4O.I5.I5+I+K+K+J+J+O-H0K.I0K.Ir)   r^  c                  T   a  ] tR tRtRtV 3R lt]t]t	]
t]t]t]t]t]t]t]tRtV ;t# )r  i\  z:
Trace TEXT device for Python method Page.get_texttrace()
c                	<  < \         SV `  4        V P                  4        V P                  4        V P	                  4        V P                  4        V P                  4        V P                  4        V P                  4        V P                  4        V P                  4        V P                  4        Wn        ^ V n        ^ V n        ^ V n        RV n        ^ V n        \#        4       V n        \'        4       V n        ^ V n        \,        P.                  ! 4       V n        \,        P.                  ! 4       V n        \,        P.                  ! 4       V n        \,        P6                  ! 4       V n        \,        P:                  ! 4       V n        ^ V n        ^ V n         ^ V n!        RV n"        R# r#  )#r   r   r  r  r  r  r  r  r  r  r  r  rF	  rm  ra	  rc  rb  r7   r;  r   r  rr  r   r|  r_  r  ry  rg  r  rq  r  r  re  r  rF  )r&   rF	  r
  s   &&r'   r    JM_new_texttrace_device.__init__\  s'   ""$$$&""$$$&$$&##%##%((*$$&""$



>>#>>#>>#r)   )rc  r  ra	  r  rF  re  rr  rb  rF	  r  r;  r  r  r_  ry  r  rm  )r/   r0   r1   r2   rc  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r3   r  r  s   @r'   r  r  \  sB    "H "I"K$I(K(K"J"J'O(K$Ir)   r  c                    V ^8  d   QhRRRR/# )r  rg  r  rj   r  r,   )r  s   "r'   r  r  J\  s     1 1 1v 1r)   c                   V P                  4       p^ RIpVP                  R4      pVP                  RV R24      pVP                  R4      pRpRV R2pVR	8X  d   Tp	V	# VR
8X  d   Tp	V	# VR8X  d   Tp	V	# VR8X  d   Tp	V	# Tp	V	# )rx   Na^  
            <!DOCTYPE html>
            <html>
            <head>
            <style>
            body{background-color:gray}
            div{position:relative;background-color:white;margin:1em auto}
            p{position:absolute;margin:0}
            img{position:absolute}
            </style>
            </head>
            <body>
            z?
            <?xml version="1.0"?>
            <document name="z">
            a  
            <?xml version="1.0"?>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
            <style>
            body{background-color:gray}
            div{background-color:white;margin:1em;padding:1em}
            p{white-space:pre-wrap}
            </style>
            </head>
            <body>
            r`   z{"document": "z", "pages": [
r   r  r  xhtml)r  textwrapdedent)
rg  rj   r  r;  r   r  r:  r   r  r$  s
   &&        r'   ConversionHeaderr=  J\  s    		A??  D // %J ' C
 OO  E DXJo6DF{ H 
f H 
e H 
g H Hr)   c                   V ^8  d   QhRR/# )r  rg  r  r,   )r  s   "r'   r  r  ~\  s       r)   c                    V P                  4       pR pRpRpRpTpVR8X  d   TpV# VR8X  d   TpV# VR8X  d   TpV# VR8X  d   TpV# TpV# )r`   z]
}z</body>
</html>
z</document>
r   r  r  r:  )r  )rg  r  r   r  r   r  r:  r$  s   &       r'   ConversionTrailerr@  ~\  s    		ADDD
CEF{ H 
f H 
e H 
g H Hr)   c                    V ^8  d   QhRRRR/# )r  r   r  rs  r6   r,   )r  s   "r'   r  r  \  s      6 c r)   c                    \        V 4       V P                  P                  '       g   \        R4      hV P                  pV^ 8w  d   V P                  ^ 4       V# )zPrepare for annotation insertion on the page.

Returns:
    Old page rotation value. Temporarily sets rotation to 0 when required.
r  )ro  r   r  r   ru  r  )r   r5  s   & r'   r3  r3  \  sL     ;;%%==Lq!r)   c               $    V ^8  d   QhRRRRRR/# )r  r   r  r   z'Annot'rs  r  r,   )r  s   "r'   r  r  \  s!     
 
F 
7 
t 
r)   c                    \        V \        4      '       g   Q h\        V\        4      '       g   Q hWn        WP                  \        V4      &   RVn        R# )zmClean up after annotation insertion.

Set ownership flag and store annotation in page annotation dictionary.
TN)r@   r   r   r   rX  rY  r   )r   r   s   &&r'   r4  r4  \  sH     tT""""ue$$$$L"'RYEMr)   c                p   \        V \        4      '       g   Q hV ^8X  g   V R8X  g   V R8X  d   \        R4      # V \        R4      8X  g!   V \        R4      8X  g   V \        R4      8X  d   \        R4      # V \        R4      8  d3   V \        R4      8:  d#   V \        R4      ,
          \        R	4      ,           # V # )
   i(   i)   r   r#   	r  Zr   )r@   r6   r:  r  s   &r'   canonrJ  \  s    a 	DyAK1;3xCI~c$i1D	>3xCH}c#h3s8|c#h&&Hr)   c                ~    \        V \        4      '       g   Q h\        P                  ! V 4      w  r\	        V4      pW3# r+   )r@   r  r   r  rJ  )r  rG   r  s   &  r'   chartocanonrL  \  s7    aq!DAaA4Kr)   c                >   \         P                  ! V \        R 4      4      p\         P                  ! \         P                  ! V\        R4      4      \        R4      4      '       d3   \	        \         P                  ! V\        R4      4      V4      '       g   ^ # \         P                  ! V \        R4      4      pVP
                  '       g    ^# \         P                  ! V4      '       d   \	        WC4      # \        \         P                  ! V^ 4      VV4      '       g   ^ # ^# )r  r
  r  r  r  )	r   r  r  r  string_in_names_listr   r  dest_is_valid_pager  )r  rv  page_object_nums
names_listr  s   &&&& r'   dest_is_validrR  \  s    Ax}-A""Ax}5   )""Ax}5 
 Ax/0A<<<  
		a	 	 #Q33A& 
 r)   c                    \         P                  ! V 4      pV^ 8X  d   ^ # \        V4       F  pW,          V8X  g   K   ^# 	  ^ # ru  )r   r  rS  )r  rP  r
  numrg  s   &&&  r'   rO  rO  \  s>    


3
C
ax9#%  r)   c                    \        V \        4      '       g   Q h\        \        V 4      4       F"  p\	        WR  V4      pVf   K  W2,          pW#3u # 	  R# )Nr<  )r@   r  rS  r9   match_string)r  r  rg  r  s   &&  r'   r}  r}  \  sR    a3q6]1R5&)?HC6M	 
 r)   c                   V ^8  d   QhRR/# r  r,   )r  s   "r'   r  r  \  s      S r)   c                    ^ RI p \        \        V P                  R,          4      4      P	                  ^R4      p\        \        V P                  ^<,          4      ^<,          4      P	                  ^R4      pV RV R2pV P
                  ! RV P                  ! 4       4      pV P                  ^ 8  d   VRV,           ,          pV# V P                  ^ 8  d   VRV,           ,          pV#  V# )z
"Now" timestamp in PDF Format
Ni  r   r   zD:%Y%m%d%H%M%SrN  rG  )timer  r,  altzonerjuststrftime	localtime)rY  r   rI  tztstamps        r'   r  r  \  s     C$%&,,Q4AS#$r)+11!S9A3as!B]]+T^^-=>F||a#(
 M	 
	#( M 	Mr)   c                       ] tR tRtRtR tRtR# )ElementPositioni]  zDConvert a dictionary with element position information to an object.c                	    R # r+   r,   r-   s   &r'   r   ElementPosition.__init__	]  r  r)   r,   Nr  r,   r)   r'   ra  ra  ]  s
    Nr)   ra  c                     \        4       # r+   )ra  r,   r)   r'   make_story_elposre  ]  s    r)   c               (    V ^8  d   QhRRRRRRRR/# )r  r  r   r  r  r   rs  r   r,   )r  s   "r'   r  r  ]  s0     F F F FYb Fmq Fr)   c                   Vf   V P                   p\        V4      pVf   VP                  pVf   VP                  pVP                  Vn        VP                  Vn        VP                  '       g   VP                  '       d   . # V P                  R^ VR7      R,          p. pV F  p\        VR,          4      pVP                  '       g   VP                  '       d   K;  VR,           FL  p\        VR,          4      pVP                  '       g   VP                  '       d   K;  VP                  V4       KN  	  K  	  V. 8X  d   V# VP                  R R7       VP                  ^ 4      p	V	P
                  VP                  ,
          RV	P                  ,          8:  dc   \        VP                  V	P
                  V	P                  4      p
V
P                  '       g%   V
P                  '       g   VP                  ^ V
4       MVP                  ^ V	4       V. 8X  d   V# VP                  4       pVP                  VP                  ,
          RVP                  ,          8:  dc   \        VP                  VP                  VP                  4      p
V
P                  '       g$   V
P                  '       g   VP                  V
4       V# VP                  V4       V# )	a  Return rectangles of text lines between two points.

Notes:
    The default of 'start' is top-left of 'clip'. The default of 'stop'
    is bottom-reight of 'clip'.

Args:
    start: start point_like
    stop: end point_like, must be 'below' start
    clip: consider this rect_like only, default is page rectangle
Returns:
    List of line bbox intersections with the area established by the
    parameters.
r7   )r  r  r  r6  r[  c                    V P                   # r+   )r  r  s   &r'   r
  )get_highlight_selection.<locals>.<lambda>@]  s    r)   r  r  )r   r+  r*  r+  rj  r  r  r  r  r  ro   r  r  r3  ri  insert)r   r  r  r  r  r[  rI  r6  rs   bboxfr$  bboxls   &&&&        r'   rL  rL  ]  s     |yy:D}|wwggDGffDG}}}(((	 ]]ad  F EAfIt}}}gJJDV%D4===LL	 	  {	JJ'J( IIaLExx%''S5<<//%((EHH-


ammmLLAQ{ IIKEvvC%,,..466588,


ammmLLO L 	ULr)   c                    V ^8  d   QhRRRR/# )r  r   r  rs  r6   r,   )r  s   "r'   r  r  Z]  s        r)   c                l    ^ RI p \        VP                  V 4      4      pV#   \         d    Rp T# i ; i)z+Convenience function accessing unicodedata.NrT  )unicodedatar:  lookuprk   )r   ro  rg  s   &  r'   rh  rh  Z]  sA    +$$T*+ J  J   " 33c                    VP                   VP                   ,
          pVP                  VP                  ,
          p\        P                  ! W0P                   ,          W@P                  ,          ,           4      # r+   ri  rj  r   fz_absr  r   rI  dxdys   &&&  r'   hdistrx  d]  D    	
qssB	
qssB<<UU
R%%Z/00r)   c               (    V ^8  d   QhRRRRRRRR/# )r  r   r   r  r6   rowsrs  r   r,   )r  s   "r'   r  r  j]  s(     ( (Y (C (# (T (r)   c                `   \        V 4      p V P                  '       g   V P                  '       d   \        R4      hV P                  pV P
                  V,          pV P                  V,          pV^ V^ 3p^ V^ V3p\        W3P                  V,           VP                  V,           4      pV.p	\        ^V4       F  p
W,          pV	P                  V4       K  	  V	.p\        ^V4       FE  p
W^,
          ,          p	. pV	 F  pVP                  W,           4       K  	  VP                  V4       KG  	  V# )a^  Return a list of (rows x cols) equal sized rectangles.

Notes:
    A utility to fill a given area with table cells of equal size.
Args:
    rect: rect_like to use as the table area
    rows: number of rows
    cols: number of columns
Returns:
    A list with <rows> items, where each item is a list of <cols>
    PyMuPDF Rect objects of equal sizes.
r=  )r+  r  r  r   r*  r3  r  ri  rj  rS  ro   )r   r  r{  r*  r3  r  delta_hdelta_vr$  rowrg  rectsnrows   &&&          r'   
make_tabler  j]  s	    :D}}}(((<==	B[[4FJJEa"G&!V$GRrttf}-A #C1d^	

1 
 EE1d^ElAKK$ T  Lr)   c                    \         P                  ! V P                  4      p\         P                  ! V4      p\         P                  ! R4      p\         P
                  ! \         P                  ! V4      \        R4      \        R4      4      p\         P                  ! WC4      p\         P                  ! V4      '       g   \         P                  ! WC^4      p\         P                  ! V4      p^ p\         P                  ! V4      p\        V4       F7  p	\         P                  ! \         P                  ! WY4      4      p
W8X  g   K5  ^p M	  V'       g/   \         P                  ! V\         P                   ! W(^ 4      4       R# R# )zD
Ensure that widgets with /AA/C JavaScript are in array AcroForm/CO
r  r  r  N)r   r  r   r  r  r   r  r  r  rI  rX  r  r  rS  r  rK  r  )r   r&  ra  
PDFNAME_COr  r  rG   r  r  rg  r  s   &          r'   r  r  ]  s    ##EJJ/I

&
&y
1C##D)Jc"VZ D 
		D	-Bb!!%%d:BAEI&D1X  !4!4R!;<=E	 
 R!7!71!EF r)   r  rJ  r  r  r  r  c                   aaa R oR oVVV3R lpV! 4       w  rrV e   S! V 4      w  rVe   S! V4      w  rVe   TpVe   Tp	Ve   Tp
Ve   TpWW3# )a  
Helper for initialising rectangle classes.

2022-09-02: This is quite different from PyMuPDF's util_make_rect(), which
uses `goto` in ways that don't easily translate to Python.

Returns (x0, y0, x1, y1) derived from <args>, then override with p0, p1,
x0, y0, x1, y1 if they are not None.

Accepts following forms for <args>:
    () returns all zeros.
    (top-left, bottom-right)
    (top-left, x1, y1)
    (x0, y0, bottom-right)
    (x0, y0, x1, y1)
    (rect)

Where top-left and bottom-right are (x, y) or something with .x, .y
members; rect is something with .x0, .y0, .x1, and .y1 members.

2023-11-18: we now override with p0, p1, x0, y0, x1, y1 if not None.
c                   \        V \        \        34      '       d#   \        V 4      ^8X  d   V ^ ,          V ^,          3# \        V \        \
        P                  \
        P                  34      '       d   V P                  V P                  3# R# )r  r<  )
r@   r   r   r9   r)  r   rg  r
  ri  rj  )r  s   &r'   get_xyutil_make_rect.<locals>.get_xy]  sc    sT5M**sCyA~q63q6>!sUEMM5>>BCC55#%%<r)   c                   \        V \        4      '       d   V # \        V \        4      '       d   V P                  V P                  3# \        V \
        \        \        P                  \        P                  34      '       d/   V P                  V P                  V P                  V P                  3# \        V \        \        34      '       g   V 3p V # r+   )r@   r   r)  ri  rj  r+  r  r   rq  fz_rectr  r  r  r  r   r  s   &r'   
make_tuple"util_make_rect.<locals>.make_tuple]  s    q%  Hq%  338OT5%,,FGG44qttQTT))1tUm,,Ar)   c                   < \        S4      ^ 8X  d   R# \        S4      ^8X  d   S^ ,          p \        V \        \        34      '       d0   \        V 4      ^8X  d    V w  r. VOVO5p\        V4      ^8X  g   Q hV# \        V \        \        34      '       dK   \        V 4      ^8X  d;   V w  rEpS! V4      pS! V4      pS! V4      p. VOVOVO5p\        V4      ^8X  g   Q hV# S! V 4      p\        V4      ^8X  g   Q RV : RV: 24       hV# \        S4      ^8X  d8   S! S^ ,          4      S! S^,          4      ,           p\        V4      ^8X  g   Q hV# \        S4      ^8X  dZ   S! S^ ,          4      w  rxWx3R8w  d   WxS^,          S^,          3# S! S^,          4      w  rW3R8w  d   S^ ,          S^,          W3# M2\        S4      ^8X  d#   S^ ,          S^,          S^,          S^,          3# \	        RS 24      h)rx   zarg=z ret=rb  r  r<  )r9   r@   r   r   rk   )r  rJ  rK  rI   r   rI  r  r  r  r  r  r  r  r  s              r'   handle_args#util_make_rect.<locals>.handle_args]  s   t9>Y!^q'C3u..39>rhBh3x1}$}
3u..39>aqMqMqM qj1jqj3x1}$}
c"Cs8q=2TSF&C6"22=JY!^$q'"VT!W%55Cs8q= =JY!^T!W%FBx<'tAwQ//T!W%FBx<'AwQ// (Y!^7DGT!Wd1g55.tf566r)   r,   )r  rJ  r  r  r  r  r  r  ret_x0ret_y0ret_x1ret_y1r  r  s   $$$$$$j     @@r'   r  r  ]  sn    .	"7F &1]"FF	~	~	~	~	~	~6))r)   c                    \        VR V RVRVRVRVRV/ w  rxrR pV! VR4      pV! VR4      pV! V	R4      p	V! V
R4      p
WxW3# )	r  rJ  r  r  r  r  c                    V'       d    \        \        P                  ! V 4      4      # \        \        P                  ! V 4      4      # r+   )r6   r  r  floor)ri  r  s   &&r'   convert util_make_irect.<locals>.convert^  s+    tyy|$$tzz!}%%r)   FT)r  )r  rJ  r  r  r  r  r  r   rI  r  rH  r  s   $$$$$$*     r'   rz  rz  ^  so    $Q2Q"QQQrQbQJA!&
 	5A5A4A4A:r)   c                R    \        \        P                  ! \        V 4      4      4      # r+   )rS  r   r(  r  r  s   &r'   r  r  ^  s    E//0EFGGr)   c                    \         '       d   \        P                  ! W4      # \        \        P
                  ! \        V 4      \        V4      4      4      # r+   )r  r   r  rp  r   r  r  r  )r   r  s   &&r'   r  r  ^  s<    {(($77522?43HJ[\bJcdeer)   c                f    \        \        P                  ! \        V 4      \        V4      4      4      # r+   )rp  r   r'  r  r  r  s   &&r'   r  r  ^  s-    #### r)   c                T    \         P                  ! \        V 4      \        V4      4      # r+   )r   fz_is_point_inside_rectr+  r  )r  r$  s   &&r'   r  r  &^  s%    (( #" r)   c                f    \        \        P                  ! \        V 4      \	        V4      4      4      # r+   )rp  r   r  r  r+  )r$  r  s   &&r'   r  r  ,^  s-    **" # r)   c                Z    \        V 4      p\        V4      p\        P                  ! W#4      # r+   )r+  r_  r   fz_is_point_inside_quad)r  r   r  rc  s   &&  r'   rJ  rJ  5^  s'    AA((..r)   c                f    \        \        P                  ! \        V 4      \	        V4      4      4      # r+   )r  r   rh  r+  r  )rn  r  s   &&r'   r6  r6  ;^  s-    $$ '!&) r)   c                f    \        \        P                  ! \        V 4      \        V4      4      4      # r+   )rp  r   r|  r  r  s   &&r'   r  r  D^  s-    ## r)   c                f    \        \        P                  ! \        V 4      \        V4      4      4      # r+   )r{  r   rf  r  )r  r-  s   &&r'   r1  r1  M^  s+    OO!"%!"% r)   c                    \'        T 4      pTP                  pY2P                  ,          TP                  TP                  ,          ,
          pT\         P"                  P$                  ) 8  g!   T\         P"                  P$                  8  EdG   \        P                  ! 4       p^T,          pTP                  T,          Tn        TP                  ) T,          Tn        TP                  ) T,          Tn	        Y6,          Tn
        TP                  ) TP                  ,          TP                  TP                  ,          ,
          pTP                  ) TP                  ,          TP                  TP                  ,          ,
          Tn        Y5n        ^ TP                  TP                  TP                  TP                  TP                  TP                  33# R# )rx   )r  r,   )r@   r   r   r   r|  rw  r  r   rI  r  rH  rh  r  r   r*  r,  r  
float_infoepsilonr  )r  rI   r4  r   detr  rdets   &      r'   r+  r+  V^  s/   ( F
#CA
ee)ceeceem
#C
cnn$$$$cnn.D.D(Dnn3wUUFSUUNSUUSUU]*.355#%%suucee<<<Lr)   c                
   \         P                  ! V4      p^ p^ pV\        V 4      8  d   \         P                  ! WR 4      w  rxWg,          pV\         P                  8X  d   \         P
                  ! V4      pMBV\         P                  8X  d   \         P                  ! V4      pM\         P                  ! V4      pV^ 8  d   ^p\         P                  ! WH4      p	\         P                  ! WI^ 4      p
WZ,          pK  WR,          pV# r   )r   r6  r9   r  PDF_SIMPLE_ENCODING_GREEKfz_iso8859_7_from_unicodePDF_SIMPLE_ENCODING_CYRILLICfz_windows_1251_from_unicodefz_windows_1252_from_unicoder  r  )r   r   r   r  r  r   r@  r  r  r  rk  rI   s   &&&&        r'   r5  r5  }^  s    ##H-D	A
C
D	/""4:.u666//2A;;;2215A2215Aq5A%%d.##DQ/	
,CJr)   c                   \        V 4      p\        V4      p\        V4      p\        P                  ! \        P                  ! VP                  VP                  ,
          VP
                  VP
                  ,
          4      4      p\        P                  ! ^^ ^ ^VP                  ) VP
                  ) 4      p\        P                  ! VP                  VP
                  ) VP
                  VP                  ^ ^ 4      p\        P                  ! Wx4      p\        P                  ! W74      p\        P                  ! V4      pVP
                  # rv  )	r+  r   ry  r  ri  rj  r  rf  rh  )	r  r  r   r  r  rc  r  r  r-  s	   &&&      r'   rw  rw  ^  s    AAA!!%"5"5accACCiqss"KLA			aAq133$	5B			accACC4acc1a	8B		 B  'A!!!$A33Jr)   c                   \        V 4      p\        V4      p\        P                  ! \        P                  ! VP                  VP                  ,
          VP
                  VP
                  ,
          4      4      p\        P                  ! ^^ ^ ^VP                  ) VP
                  ) 4      p\        P                  ! VP                  VP
                  ) VP
                  VP                  ^ ^ 4      p\        \        P                  ! WV4      4      # )z{
Return the matrix that maps two points C, P to the x-axis such that
C -> (0,0) and the image of P have the same distance.
)	r+  r   ry  r  ri  rj  r  r{  rf  )r  r  r  r  r  r  r-  s   &&     r'   r  r  ^  s    
 	AA 	!!%"5"5accACCiqss"KLA			aAq133$	5B			accACC4acc1a	8BU__R455r)   c                   ^ p^ pTp\        WR 4      w  rVW%,          p\        WR 4      w  rxW7,          pWh8X  d   TpV\        R4      8X  d,    \        WR 4      w  rVW%,          pV\        R4      8w  g   K*  M\        WR 4      w  rVW%,          pV\        R4      8X  d-    \        WR 4      w  rxW7,          pV\        R4      8w  g   K*  K  \        WR 4      w  rxW7,          pK  V^ 8w  d   R# T# )rx   Nr   )rL  r:  )	h0rN  r"  rG   rh  r}  hcdelta_nncs	   &&       r'   rV  rV  ^  s    	A	A	Abf%KGLAbf%KGLA
(S>)"R&1S>%bf-KGLAS>)"R&1S>%bf-KGLA74!!r)   c                   V '       g   Q h\        V\        P                  4      '       g   Q h\        V\        P                  4      '       g   Q hVP                  P
                  V P                  ,          pVP                  P
                  V P                  ,          p\        W4      pV P                  ^ 8  EdW   V P                  V P                  ^,
          ,          p\        V4      p \        VP                  P                  VP                  VP                  4      V8  d   \!        VP                  P                  VP                  VP                  4      V8  d   \        VP                  P                  VP"                  VP$                  4      V8  dy   \!        VP                  P                  VP"                  VP$                  4      V8  d?   VP"                  Vn        VP                  Vn        V P                  R,          V8X  g   Q hR# V P                  P'                  V4       V ;P                  ^,          un	        R# )rx   Nr  )r@   r   r  r  r   r  r{  rz  r  r9   r
  r_  rx  r  r  r  vdistr  r  ro   )r  rs   r?  r{  rz  ch_quadrM  r  s   &&&     r'   r~  r~  ^  s}   K4dE--....b%++,,,,MM+EMM+E4$Gxx!|zz$((Q,'d#$//--svvwzzBUJ$//--svvwzzBUJ$//--svvwzzBUJ$//--svvwzzBUJZZCFZZCF::b>S(((JJgHHMHr)   c                   \         '       d   \        P                  ! WW#WEWg4      # \        R4      \        R4      \        R4      \        R4      \        R4      \        R4      \        R4      \        R4      \        R	4      .	p\        P
                  ! W4      p	\        P                  ! V ^4      p
\        P                  ! V
\        R
4      \        R4      4       \        \        V4      4       Fq  p\        P                  ! WV,          4      pVP                  '       g   K4  \        P                  ! WV,          \        P                  ! VP                  V4      4       Ks  	  V'       Ed    \        P                  ! V	\        R4      4      p\        P                  ! V4      pV^ 8  Ed   \        P                   ! V
\        R4      V4      p\        V4       EF  p\        P"                  ! W4      pVP                  '       d   \        P$                  ! V4      '       g   KJ  \        P&                  ! VR4      P                  '       d   Ks  \        P                  ! V\        R4      4      p\        P(                  ! V\        R4      4      '       d   K  \        P(                  ! V\        R4      4      '       d   K  \        P(                  ! V\        R4      4      '       d   EK  \        P*                  ! V\        R4      4       \        P*                  ! V\        R4      4       \        P                  ! VP                  V4      p\        P,                  ! V \        P.                  ! V4      ^ 4      p\        P0                  ! VV4       EK  	  VR8w  d"   \        P2                  ! V
\        R4      V4       \        P4                  ! W
4      p\        P6                  ! WV4       R# )z
Deep-copies a source page to the target.
Modified version of function of pdfmerge.c: we also copy annotations, but
we skip some subtypes. In addition we rotate output.
rS  r<  r  r  r  r  r  r;  UserUnitr  r   r  r;  r  r  r  rZ  r  Nr  )r  r   r*  r  r   r  rZ  rU  rS  r9   r  r   r  r   r  r  rX  r  r  r  r  rH  r  r  rK  rP  rY  rI  )r+  r,  	page_frompage_tor`  r5  copy_annotsr0  known_page_objspage_refrn  rg  r  r1  rG   r2  r  r  r3  r   r  s   &&&&&&&&             r'   r*  r*  ^  s    {9vVamm 	

O ((<H ""7A.I	y(6"2HV4DE C(),,h8JK>>>	1+=u?\?\]f]k]kmp?qr	 * {''8H3EF
,q5119hx>PRSTJ1X''7|||5+<+<Q+?+?&&51<<<,,a)1DE$$gx/?@@$$gx/@AA$$Whx.@AA""Ax'89""Ax}566	J..9I9I69RTUV$$j%8# ( |	8H+=vF



3C 
7S1r)   c                    V ^8  d   QhRRRR/# )r  r  r  rs  r+  r,   )r  s   "r'   r  r  0_  s     ) )# )$ )r)   c                6    \        V 4      w  r\        RRW4      # )zReturn a Rect for the paper size indicated in string 's'. Must conform to the argument of method 'PaperSize', which will be invoked.
    r  )
paper_sizer+  )r  r  r3  s   &  r'   
paper_rectr  0_  s     qMMES%((r)   c                    V ^8  d   QhRRRR/# )r  r  r  rs  r   r,   )r  s   "r'   r  r  7_  s      # % r)   c                   V P                  4       pRpVP                  R4      '       d   RpVRR pVP                  R4      '       d   VRR p\        4       P                  VR4      pVR8X  d   V# V^,          V^ ,          3# )zReturn a tuple (width, height) for a given paper format string.

Notes:
    'A4-L' will return (842, 595), the values for A4 landscape.
    Suffix '-P' and no suffix return the portrait tuple.
r  z-lrX  Nz-pr  r	  )r  r  paper_sizesr:   )r  r  r  r   s   &   r'   r  r  7_  s     779DA}}TCRy}}TCRy			4	*BCx	qE2a5>r)   c                    / RR-bRR.bRR/bRR0bRR1bRR2bRR3bRR4bR	R5bR
R6bRR7bRR8bRR9bRR:bRR;bRR<bRR=b/ RR>bRR?bRR@bRRAbRRBbRRCbRRDbRREbRRFbRRGbRRHbRRIbRRJbRRKbR RLbR!RMbR"RNbCR#ROR$RPR%RQR&RRR'RSR(RTR)RUR*RVR+RWR,RX/
C# )Ya  Known paper formats @ 72 dpi as a dictionary. Key is the format string
like "a4" for ISO-A4. Value is the tuple (width, height).

Information taken from the following web sites:
www.din-formate.de
www.din-formate.info/amerikanische-formate.html
www.directtools.de/wissen/normen/iso.htm
a0a1a10a2a3a4a5a6a7a8a9b0b1b10b2b3b4b5b6r  b8b9c0c1c10c2c3c4c5c6c7c8c9zcard-4x6zcard-5x7
commercial	executiveinvoiceledgerlegalzlegal-13lettermonarchztabloid-extra)P	  i*  )  r  )J   i   )  r  )r  r  )r  r  )  r  )*  r  )   r  )   r  )r  r  )  i  )  r  )X   }   )  r  )  r  )  r  )  r  )b  r   )   r  )   r  )r  r  )'
  i]  )-  r  )O   q   )  r  )  r  )  r	  )  r
  )C  r  )   r  )   r  )r  r  )i   i  )r  i  )i)  i  )i
  i  )i  r#  )r$  i  )r#  i  )r#  i  )r#  r$  )i  i  )i`  i  r,   r,   r)   r'   r  r  K_  s   -
l-
l-
 	y-
 	l	-

 	k-
 	j-
 	j-
 	j-
 	j-
 	j-
 	j-
 	l-
 	l-
 	y-
 	l-
  	l!-
" 	k#-
$ 	j%-
& 	j'-
( 	j)-
* 	j+-
, 	j--
. 	l/-
0 	l1-
2 	y3-
4 	l5-
6 	k7-
8 	j9-
: 	j;-
< 	j=-
> 	j?-
@ 	jA-
B 	jC-
D 	JE-
F 	JjZ:+J*:Y-
 -
r)   c                .    \         P                  ! W4      # r+   )r   r2  )r1  r  s   &&r'   r2  r2  _  s    $$S11r)   c                    Q R4       h)z@
Returns description of mupdf.PdfObj (wrapper for pdf_obj) <o>.
zuse mupdf.pdf_debug_obj() ?)r   rI  r  rS  r  pdfobj_stringr	  array_get_boolr  r  r  r  pdf_is_embedded_fileembedded_file_namer9
  r  r  pdf_is_jpx_imager  r  r  r  r  r!  r  r   )r  r  rI   rX  rg  oor  r   s   &&      r'   r  r  _  s     ,++1r)   c               $    V ^8  d   QhRRRRRR/# )r  r   r  r  z'Font'rs  r  r,   )r  s   "r'   r  r  _  s&     H H6 H HD Hr)   c                d   VP                   R,          '       g   R# V P                  pV P                  4       pV Uu. uFf  pV^,          VP                  8X  g   K  V^,          P	                  R4      '       g   K=  V^,          P	                  R4      '       g   K]  V^ ,          NKh  	  ppV. 8X  d   R# \        V4      p\        \        VP                  ^ 4      R,          4      4      pV F=  p\        P                  W'V4      '       d   K!  \        RVP                   RVR 24       K?  	  R# u upi )	a  Repair character spacing for mono fonts.

Notes:
    Some mono-spaced fonts are displayed with a too large character
    distance, e.g. "a b c" instead of "abc". This utility adds an entry
    "/W[0 65535 w]" to the descendent font(s) of font. The float w is
    taken to be the width of 0x20 (space).
    This should enforce viewers to use 'w' as the character width.

Args:
    page: pymupdf.Page object.
    font: pymupdf.Font object.
rK  Nr  r  i  zCannot set width for 'z
' in xref rH  )r  r   r  r   r5   r  r6   r  r^  r  set_font_widthr%   )r   r  r1  r  r  r  r  r  s   &&      r'   r`  r`  _  s    ::f
++C~~H AaDDII 	"#A$//#"6 	;<Q4??:;V 	! 
 
 {JEt))"-467E##Cu55(:d1XFG s   D-D-;D-D-c                    V ^8  d   QhRRRR/# r  srgbr6   rs  r   r,   )r  s   "r'   r  r  _  s     4 4c 4e 4r)   c                v    \        V 4      pV^ ,          R,          V^,          R,          V^,          R,          3# )a   Convert sRGB color code to a PDF color triple.

There is **no error checking** for performance reasons!

Args:
    srgb: (int) RRGGBB (red, green, blue), each color in range(255).
Returns:
    Tuple (red, green, blue) each item in interval 0 <= item <= 1.
g     o@)ro  )r  r  s   & r'   sRGB_to_pdfr  _  s3     	DAQ4%<1qte|33r)   c                    V ^8  d   QhRRRR/# r  r,   )r  s   "r'   r  r  _  s      c e r)   c                    V R,          p V ^,	          pW^,          ,
          ^,	          pW^,          ,
          V^,          ,
          pWV3# )a-  Convert sRGB color code to an RGB color triple.

There is **no error checking** for performance reasons!

Args:
    srgb: (int) SSRRGGBB (red, green, blue), each color in range(255).
    With MuPDF < 1.26, `s` is always 0.
Returns:
    Tuple (red, green, blue) each item in interval 0 <= item <= 255.
i r,   )r  r$  r  rI  s   &   r'   ro  ro  _  sG     	HD
A	b	aARAF#A!9r)   c                    V'       d   \         P                  ! V4      M^ p\         P                  ! V 4      p\        ^ V^4       F5  p\         P                  ! \         P                  ! W4      4      V8X  g   K4   ^# 	  ^ # ru  )r   r  r  rS  r  )r  rQ  rG   str_rg  s   &&   r'   rN  rN  _  s^    ,6Z(AA##Q'D1a^##U%8%8*%HITQ  r)   c                   Rp^ pTpRpVP                   '       Ed   \        WW#V4      p	\        WrW44      '       EgJ   V	^ 8X  d   \        P                  ! V\        R4      4      p
V
P                   '       g4   VP                   '       d!   \        P                  ! V\        R4      4       MuVP                   '       dD   \        P                  ! V\        R4      V
4       \        P                  ! V
\        R4      V4       M \        P                  ! V
\        R4      4       T
pEK  \        P                  ! V\        R4      4       \        P                  ! V\        R4      4       \        P                  ! V\        R4      4      pEK|  V'       d   VP                   '       g   TpTp\        P                  ! V\        R4      4      pV^,          pEK  WeV3# )z
Returns (count, first, prev).
NrP  Prevr  r  )r   strip_outlinesrR  r   r  r  rH  rU  )r1  outlinesrv  rP  rQ  r  r  currentr  r  r]  s   &&&&&      r'   strip_outliner(  `  sb    EEGD



 C*
SW2BOOQw ))'8F3CD**4&1AB___&&tXf-=tD&&tXf-=tD&&tXf-=> ""7HV,<=""7HSM:,,Whv6FG  0 0 0D(((62BCGQJEr)   c                   VP                   '       g   ^ # \        P                  ! V\        R4      4      pVP                   '       g   ^ pM\	        WW#V4      w  repV^ 8X  dc   \        P
                  ! V\        R4      4       \        P
                  ! V\        R4      4       \        P
                  ! V\        R4      4       V# \        P                  ! \        P                  ! V\        R4      4      4      p\        P                  ! V\        R4      V4       \        P                  ! V\        R4      X4       \        P                  ! T\        R4      \        P                  ! V^ 8  d   TMV) 4      4       V# )rx   r  Lastr  )	r   r   r  r  r(  rH  r  rU  rU  )	r1  r&  rv  rP  rQ  r  r  r  	old_counts	   &&&&&    r'   r%  r%  .`  s!   x'):;E'JR\]4	Qw8Xg%678Xf%568Xg%67 I	 $$U%7%7(7BS%TU	8Xg%6>8Xf%5t<8Xg%68I8IPY\]P]"dfcf8ghIr)   c                    V ^8  d   QhRRRR/# )r  r?  r6   rs  r  r,   )r  s   "r'   r  r  J`  s     	 	c 	c 	r)   c                l    ^ RI p VP                  \        V 4      4      pV#   \         d    Rp T# i ; i)z-
Convenience function accessing unicodedata.
Nz.notdef)ro  r   rn  r   )r?  ro  r   s   &  r'   r  r  J`  sB     B( K  Krq  c                    VP                   VP                   ,
          pVP                  VP                  ,
          p\        P                  ! W0P                  ,          W@P                   ,          ,           4      # r+   rs  ru  s   &&&  r'   r  r  V`  ry  r)   pagefn_argspagefn_kwargsinitfninitfn_argsinitfn_kwargsrX  rb  singleconcurrency_statsc       	            V
'       d   \         P                   ! 4       pVR8X  dn   V'       d	   V! V/ VB  \        4       p\        V 4      pVf   \        \	        V4      4      pV F(  pW,          pV! V.VO5/ VB pVP                  V4       K*  	  EM5^RIHp Vf   V
'       d   \         P                   ! 4       p\        V 4      ;_uu_ 4       p\	        V4      p\        \        V4      4      pRRR4       V
'       d,   \         P                   ! 4       X,
          p\        VR R24       V
'       d   \         P                   ! 4       pVR8X  d   VP                  V VVVVVVVV	V
4
      pM.VR8X  d   VP                  V VVVVVVVV	V
4
      pMQ RT: R	24       hV
'       d,   \         P                   ! 4       X,
          p\        VR R
24       V
'       d,   \         P                   ! 4       X,
          p\        VR R24       V#   + '       g   i     EL; i)a  
Returns list of results from `pagefn()`, optionally using concurrency for
speed.

Args:
    path:
        Path of document.
    pagefn:
        Function to call for each page; is passed (page, *pagefn_args,
        **pagefn_kwargs). Return value is added to list that we return. If
        `method` is not 'single', must be a top-level function - nested
        functions don't work with concurrency.
    pagefn_args
    pagefn_kwargs:
        Additional args to pass to `pagefn`. Must be picklable.
    initfn:
        If true, called once in each worker process; is passed
        (*initfn_args, **initfn_kwargs).
    initfn_args
    initfn_kwargs:
        Args to pass to initfn. Must be picklable.
    pages:
        List of page numbers to process, or None to include all pages.
    method:
        'single'
            Do not use concurrency.
        'mp'
            Operate concurrently using Python's `multiprocessing` module.
        'fork'
             Operate concurrently using custom implementation with
             `os.fork()`. Does not work on Windows.
    concurrency:
        Number of worker processes to use when operating concurrently. If
        None, we use the number of available CPUs.
    _stats:
        Internal, may change or be removed. If true, we output simple
        timing diagnostics.

Note: We require a file path rather than a Document, because Document
instances do not work properly after a fork - internal file descriptor
offsets are shared between the parent and child processes.
r4  N)_apply_pagesz.2fzs: count pages.r  forkzUnrecognised method=r   zs: work.z	s: total.)rY  r   r   rS  r9   ro   r`   r8  r%   _multiprocessing_fork)r   r  r/  r0  r1  r2  r3  rX  rb  r5  r6  r   rI   r   r{  r   r$  r8  r  	num_pagess   &&$$$$$$$$$         r'   apply_pagesr=  \`  s   p YY[K1=1fD>=#h-(EC=Dt;k;];AJJqM  	#=IIK$8M	U9-.   IIK!Oqg_-.		AT>//!!C v$$!!C 1-fYa001		aA1S'"#IIK"qgY Ja  s    G<<H	r  r  r  r  r  c       
   
     d    \        VVVVVV	R7      p\        V \        P                  VVVVV
R7      # )a  
Returns list of results from `Page.get_text()`, optionally using
concurrency for speed.

Args:
    path:
        Path of document.
    pages:
        List of page numbers to process, or None to include all pages.
    method:
        'single'
            Do not use concurrency.
        'mp'
            Operate concurrently using Python's `multiprocessing` module.
        'fork'
             Operate concurrently using custom implementation with
             `os.fork`. Does not work on Windows.
    concurrency:
        Number of worker processes to use when operating concurrently. If
        None, we use the number of available CPUs.
    option
    clip
    flags
    textpage
    sort
    delimiters:
        Passed to internal calls to `Page.get_text()`.
)r  r  r  r  r  r  )r0  rX  rb  r5  r6  )r7   r=  r   r  )r   rX  rb  r5  r  r  r  r  r  r  r6  	args_dicts   &$$$$$$$$$$ r'   r  r  `  sI    X !I MM## r)   c                     ] tR tRtRtR t]R 4       t]R 4       t]R/R l4       t	]R 4       t
]R 4       t]R	 4       t]R
 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       tR t]R 4       t]R 4       t]R0R l4       t]R1R l4       t]R1R l4       t]R 4       t]R/R l4       t ]R 4       t!]R  4       t"]R1R! l4       t#]R" 4       t$]R# 4       t%]R0R$ l4       t&]R1R% l4       t']R1R& l4       t(]R1R' l4       t)]R( 4       t*]R) 4       t+]R* 4       t,]R+ 4       t-]R1R, l4       t.R-t/]0! 4       t1R.t2R# )2r  ia  zM
We use @staticmethod to avoid the need to create an instance of this class.
c                	    \        V \        P                  4      '       d   \        \	        V 4      4      # \        \        P
                  ! 4       4      # r+   )r@   r   r   r{  re  r|  r   s   &r'   _derotate_matrixTOOLS._derotate_matrix#a  s6    dEMM**$%<T%BCC$U^^%566r)   c                	   \        W4      p\        V P                  4      Vn        V P                  Vn        V P                  Vn        Wn        VP                  '       g   R Vn        VP                  '       g   R Vn        VP                  '       g   R Vn        VP                  '       g   R Vn	        VP                  '       g   R Vn
        VP                  '       g   R Vn        VP                  '       g   R Vn        V# r+   )rj  r+  r   r  r   r  r$  r  r  r  r  r  r  )r   r\  r  s   && r'   r[  TOOLS._fill_widget)a  s    &u55::&jj}}} FM####'F ####'F ####'F !!!!%F!!!!%F""""&F
r)   c                	x    \        V P                  4      p \        V P                  4       4      p\	        V4      pV# r+   )r   r   r.  r  r#  )r   r%  r  s   &  r'   rs  TOOLS._get_all_contentsAa  s/    DII&txxz*!3'r)   c                    \        V ^R7      p\        V4      p\        VP                  4       VP	                  4       WB4      pV# )zDAdd bytes as a new /Contents object for a page, and return its xref.r  )r   r.  r  r1  r  )r   r  r  r  contbufr  s   &&&   r'   r  TOOLS._insert_contentsHa  s9     ta0$W-!'++-Qr)   c                   V P                   R,          pV P                  R,          pV'       g   R	pRP                  \        \        V4      4      R,           pV'       d   TpMV P                  R,          pV'       g   R
pRP                  \        \        V4      4      R,           pTp	Tp
\        \        W4      4      pV( pW,          pW,          p^ V P                  u;8:  d   ^8  d   M MRpMRpWWWFW3# )a+  Get common parameters for making annot line end symbols.

Returns:
    m: matrix that maps p1, p2 to points L, P on the x-axis
    im: its inverse
    L, P: transformed p1, p2
    w: line width
    scol: stroke color string
    fcol: fill color store_shrink
    opacity: opacity string (gs command)
r  r  r   z RG
r   z rg
r  r`   r  rl  )r  r  r  r  r  r  r  r]  )r   rJ  rK  r_  r   scscolrg  rd  np1np2r  r  r`  r  r]  s   &&&&            r'   _le_annot_parmsTOOLS._le_annot_parmsQa  s     LL!\\(#BxxC%/Bf%BBxxC%/?3,-RGG!!GGaAT22r)   c                   \         P                  WW$4      w  rVrxrr^pV\        ^V	4      ,          pV'       d   TMTpV^ V) R,          3,           V,          pV^ VR,          3,           V,          pRV VP                  R RVP                  R R2pVVP                  R RVP                  R R2,          pV\        V	4      R,           ,          pVV
R,           ,          pV# )	zaMake stream commands for butt line end symbol. "lr" denotes left (False) or right point.
        r  r  r  r   r1  r2  r  s
Q
r  rP  r'  ri  rj  r   )r   rJ  rK  r  r_  r  r  r`  r  r   rM  rd  r]  r  rH  r-  r  botr'  s   &&&&&              r'   r#  TOOLS._le_buttwa  s     /4.C.CEr.^+qQdC1IAAr"u:~#Aqt9}"WIceeAYaay5
q	355)4((
ilV##
dXo	r)   c                   \         P                  WW$4      w  rVrxrrRpV\        ^V	4      ,          pV'       d   WR,          ^ 3,
          MW~R,          ^ 3,           p\        W4      V) V) W3,           pRV,           \         P	                  VP
                  V,          VP                  V,          VP                  V,          VP                  V,          4      ,           pV\        V	4      R,           ,          pVW,           R,           ,          pV# )zcMake stream commands for circle line end symbol. "lr" denotes left (False) or right point.
              @r  q
r  b
Q
)
r  rP  r'  r+  _oval_stringr*  r  r+  r  r   )r   rJ  rK  r  r_  r  r  r`  r  r   rM  rd  r]  r  rH  r-  r$  r'  s   &&&&&             r'   r  TOOLS._le_circlea  s     /4.C.CEr.^+qQdC1IA2q	MQB$]J1"qb!'W_u11!$$)QTTBYr	STSWSWZ\S\]]
ilV##
dkH$$	r)   c                   \         P                  WW$4      w  rVrxrrRpV\        ^V	4      ,          pV'       d   WR,          ^ 3,           MW~R,          ^ 3,
          pV'       d   VR
V,          V) 3,           MV^V,          V) 3,           pV'       d   VR
V,          V3,           MV^V,          V3,           pW,          pW&,          pW,          pRV VP                  R RVP                  R R2pVVP                  R RVP                  R R2,          pVVP                  R RVP                  R R2,          pV\        V	4      R,           ,          pVW,           R	,           ,          pV# )ziMake stream commands for closed arrow line end symbol. "lr" denotes left (False) or right point.
        rX  r  r  r  r   r1  r2  r  rZ  r  rT  r   rJ  rK  r  r_  r  r  r`  r  r   rM  rd  r]  r  rH  r  r'  s   &&&&&            r'   r"  TOOLS._le_closedarrowa  s?    /4.C.CEr.^+qQdC1I QB$]aR4)m "R2a4!*_acA2Y!R2a4)^rQqS!H}


WIbdd1XQrttAhd3
a"$$q&&
a"$$q&&
ilV##
dkH$$	r)   c                F   \         P                  WW$4      w  rVrxrrRpV\        ^V	4      ,          pV'       d   WR,          ^ 3,
          MW~R,          ^ 3,           p\        W4      V) V) W3,           pVP                  VP
                  VP                  ,
          R,          ,           V,          pRV VP                  R RVP                  R R2pVP                  VP                  VP                  ,
          R,          ,           V,          pVVP                  R RVP                  R R2,          pVP                  VP                  VP                  ,
          R,          ,           V,          pVVP                  R RVP                  R R2,          pVP                  VP
                  VP                  ,
          R,          ,           V,          pVVP                  R RVP                  R R2,          pV\        V	4      R	,           ,          pVW,           R
,           ,          pV# )zdMake stream commands for diamond line end symbol. "lr" denotes left (False) or right point.
        rX  r  r  rY  r  r   r1  r2  r  rZ  )r  rP  r'  r+  r*  r  ri  rj  r  r+  r   r   rJ  rK  r  r_  r  r  r`  r  r   rM  rd  r]  r  rH  r-  r$  r  r'  s   &&&&&              r'   r   TOOLS._le_diamonda  s    /4.C.CEr.^+qQdC1IA2q	MQB$]J1"qb!'TTQTTADD[C''2-7)ACC7!ACC7$/TTQTTADD[C''2-
QqQt$$TTQTTADD[C''2-
QqQt$$TTQTTADD[C''2-
QqQt$$
ilV##
dkH$$	r)   c                   \         P                  WW$4      w  rVrxrrRpV\        ^V	4      ,          pV'       d   WR,          ^ 3,           MW~R,          ^ 3,
          pV'       d   VR
V,          V) 3,           MV^V,          V) 3,           pV'       d   VR
V,          V3,           MV^V,          V3,           pW,          pW&,          pW,          pRV VP                  R RVP                  R R2pVVP                  R RVP                  R R2,          pVVP                  R RVP                  R R2,          pV\        V	4      R,           ,          pVV
R	,           ,          pV# )zgMake stream commands for open arrow line end symbol. "lr" denotes left (False) or right point.
        rX  r  r  r  r   r1  r2  r  S
Q
r  rT  r^  s   &&&&&            r'   r!  TOOLS._le_openarrowa  s<    /4.C.CEr.^+qQdC1I QB$]aR4)m "R2a4!*_acA2Y!R2a4)^rQqS!H}


WIbdd1XQrttAhd3
a"$$q&&
a"$$q&&
ilV##
dXo	r)   c                   \         P                  WW$4      w  rVrxrrRpV\        ^V	4      ,          pV'       d   V^V,          ^ 3,
          MV^V,          ^ 3,           pV'       d   V^V,          V) 3,           MVR	V,          V) 3,           pV'       d   V^V,          V3,           MVR	V,          V3,           pW,          pW&,          pW,          pRV VP                  R RVP                  R R2pVVP                  R RVP                  R R2,          pVVP                  R RVP                  R R2,          pV\        V	4      R,           ,          pVW,           R,           ,          pV# )
zoMake stream commands for right closed arrow line end symbol. "lr" denotes left (False) or right point.
        rX  r  r  r   r1  r2  r  rZ  r  rT  r^  s   &&&&&            r'   r%  TOOLS._le_rclosedarrowa  sC    /4.C.CEr.^+qQdC1IQ!A#q\Q!A#q\!R1Q3)^rRTA2J R1Q3(]bBqD!9n


WIbdd1XQrttAhd3
a"$$q&&
a"$$q&&
ilV##
dkH$$	r)   c                   \         P                  WW$4      w  rVrxrrRpV\        ^V	4      ,          pV'       d   WR,          ^ 3,
          MW~R,          ^ 3,           pV'       d   V^V,          V) 3,           MVR
V,          V) 3,           pV'       d   V^V,          V3,           MVR
V,          V3,           pW,          pW&,          pW,          pRV VP                  R RVP                  R R2pVVP                  R RVP                  R R2,          pVVP                  R RVP                  R R2,          pV\        V	4      R,           ,          pVW,           R	,           ,          pV# )zmMake stream commands for right open arrow line end symbol. "lr" denotes left (False) or right point.
        rX  g      @r  r  r   r1  r2  r  rd  r  rT  r^  s   &&&&&            r'   r$  TOOLS._le_ropenarrowa  s?    /4.C.CEr.^+qQdC1I QB$]aR4)m!R1Q3)^rRTA2J R1Q3(]bBqD!9n


WIbdd1XQrttAhd3
a"$$q&&
a"$$q&&
ilV##
dkH$$	r)   c                r   \         P                  WW$4      w  rVrxrrR\        ^V	4      ,          R,          pV'       d   TMTp\        VP                  V,
          VP
                  ^V	,          ,
          VP                  V,           VP
                  ^V	,          ,           4      pVP                  V,          pVP                  V,          pRV VP                  R RVP
                  R R2pVVP                  R RVP
                  R R2,          pV\        V	4      R,           ,          pVV
R	,           ,          pV# )
zbMake stream commands for slash line end symbol. "lr" denotes left (False) or right point.
        g(y?r  r  r  r   r1  r2  r  rS  )	r  rP  r'  r+  ri  rj  r*  r+  r   )r   rJ  rK  r  r_  r  r  r`  r  r   rM  rd  r]  rwr-  r$  r  rU  r'  s   &&&&&              r'   r&  TOOLS._le_slasha  s     /4.C.CEr.^+qQdc!Qi#%Ar133Q;b!##A+>ddRiddRiWIceeAYaay5
q	355)4((
ilV##
dXo	r)   c                   \         P                  WW$4      w  rVrxrrRpV\        ^V	4      ,          pV'       d   WR,          ^ 3,
          MW~R,          ^ 3,           p\        W4      V) V) W3,           pVP                  V,          pRV VP
                  R RVP                  R R2pVP                  V,          pVVP
                  R RVP                  R R2,          pVP                  V,          pVVP
                  R RVP                  R R2,          pVP                  V,          pVVP
                  R RVP                  R R2,          pV\        V	4      R,           ,          pVW,           R	,           ,          pV# )
zcMake stream commands for square line end symbol. "lr" denotes left (False) or right point.
        rX  r  rY  r  r   r1  r2  r  rZ  )r  rP  r'  r+  r*  ri  rj  r  r+  r  r   ra  s   &&&&&              r'   r  TOOLS._le_squareb  sS    /4.C.CEr.^+qQdC1IA2q	MQB$]J1"qb!'DD2I7)ACC7!ACC7$/DD2I
QqQt$$DD2I
QqQt$$DD2I
QqQt$$
ilV##
dkH$$	r)   c                   R pRpWV ,
          R,          ,           pWV ,
          R,          ,           pWV,
          R,          ,           pW2V,
          R,          ,           p	W`V,
          V,          ,           p
WpV,
          V,          ,           pWqV,
          V,          ,           pWV,
          V,          ,           pWV,
          V,          ,           pWV	,
          V,          ,           pWV	,
          V,          ,           pWcV,
          V,          ,           pVP                   R RVP                  R R2pVV! WV4      ,          pVV! WV4      ,          pVV! WV	4      ,          pVV! VVV4      ,          pV# )zQReturn /AP string defining an oval within a 4-polygon provided as points
        c                    V P                   R  RV P                  R  RVP                   R  RVP                  R  RVP                   R  RVP                  R  R2# )r  r   r9  r  )r  rc  r$  s   &&&r'   bezier"TOOLS._oval_string.<locals>.bezier%b  sQ    cc!WAacc!WAacc!WAacc!WAacc!WAacc!WDIIr)   rH  r  r  r   r1  r  )rJ  rK  r  r  rq  rI  r@  mor?  muol1ol2or1or2ur1ur2ul1ul2r'  s   &&&&               r'   r[  TOOLS._oval_string!b  s@   	J 7c/!7c/!7c/!7c/!Gu$$Gu$$Gu$$Gu$$Gu$$Gu$$Gu$$Gu$$Qxqa%
fSr""
fSr""
fSr""
fS#r""	r)   c                	\   \         '       d"   \        P                  ! V P                  4      pMR  pV! V 4      pV'       g   R# Rp^pR	pVP	                  4       p\        V4       EF5  w  rxVR8X  dK   Wg^,
          ,          R,          p\        Wg^,
          ,          4      pR;Wg&   ;Wg^,
          &   Wg^,
          &   KW  VR8X  d+   \        Wg^,
          ,          4      .pR;Wg&   Wg^,
          &   K  VR8X  dK   Wg^,
          V  U	u. uF  p	\        V	4      NK  	  pp	R;Wg&   ;Wg^,
          &   ;Wg^,
          &   Wg^,
          &   K  VR8X  g   K  Wg^,
          V  U	u. uF  p	\        V	4      NK  	  pp	R;Wg&   ;Wg^,
          &   ;Wg^,
          &   ;Wg^,
          &   Wg^,
          &   EK8  	  WSV3pV# u up	i u up	i )
c                0   V P                   p\        V\        P                  4      '       g   Q h\        P                  ! V4      p\        P
                  ! V4      p \        P                  ! V\        R 4      4      pVP                  '       gK   \        P                  ! V4      p\        P                  ! V\        R4      \        R4      \        R 4      4      p\        P                  ! V4      pV#   \         d    \        '       d   \        4         R# i ; i)r^  r  r  N)r   r@   r   r   r  r  r  r  r   r  r   r  rk   r  r{   )r   rG  this_annot_objra  r  r  rb  s   &      r'   Tools__parse_da(TOOLS._parse_da.<locals>.Tools__parse_daCb  s    "ZZ
!*enn====!&!4!4j!A22NC77RVXB==="'"3"3C"8"00 ( 0 ( 4 ("
 #55b9F  ! ++0@s   BC0 0D
DDr`   r  r  r	  r  r  r  )ru  r`   rx   r  )r  r   Tools_parse_dar   r8   rZ  r  )
r   r  r  r  r7  rf  r  rg  rE   r  s
   &         r'   r  TOOLS._parse_da=b  s    ;&&

3C& "%(C  iik ~GAt|q5z"~ca%j)/111qSC!Hs{ca%j)+$&&qSt|),U16AuQx6:<<<qS<C!HsQ3xs{),U16AuQx6EGGGqSGC!HGsQ3x#c(# && % 
 7 7s    F$F)c                	    T p\         P                  ! V4      p\         P                  ! V4      p\         P                  ! W24       R # r+   )r   r  r  pdf_field_reset)r   rG  r  ra  s   &   r'   r  TOOLS._reset_widgettb  s5    
,,Z8**>:c2r)   c                	    V P                  R R7      pVP                  '       g   \        \        P                  ! 4       4      # \        \        V4      4      # r&  )r,  r   r{  r   r|  r  )r   r  s   & r'   r  TOOLS._rotate_matrix{b  sA    ..%.0!!!$U^^%566 !6w!?@@r)   c                	    \        W4       R # r+   )r  )r   r\  s   &&r'   r  TOOLS._save_widgetb  s
     /r)   c                	L   \         '       d$   \        P                  ! V P                  V4       R#  V P                  p\	        V\
        P                  4      '       g   Q h\
        P                  ! \
        P                  ! V4      \        R 4      V4       \
        P                  ! \
        P                  ! V4      \        R4      4       \
        P                  ! \
        P                  ! V4      \        R4      4       R#   \         d    \        '       d   \        4         R# i ; i)r^  r;  r  N)r  r   Tools_update_dar   r@   r   r   r  r  r  rH  rk   r  r{   )r   rb  rG  s   && r'   
_update_daTOOLS._update_dab  s    ;!!5::v6"ZZ
!*enn====..u/B/B:/NPXY]P^`fg""5#6#6z#BHTNS""5#6#6z#BHTNS   ''N,<s   CC> >D#
D#"D#c                 	(    \         ^,          s \         # rv  )TOOLS_JM_UNIQUE_IDr,   r)   r'   r  TOOLS.gen_idb  s     	a!!r)   c                 0    \         P                  ! 4        R# )z
Empty the glyph cache.
N)r   fz_purge_glyph_cacher,   r)   r'   glyph_cache_emptyTOOLS.glyph_cache_emptyb  s    
 	""$r)   c                    \        W4      # )z%
Metadata of an image binary stream.
)r  )r   r  s   &&r'   r8  TOOLS.image_profileb  s    
  33r)   Nc                ,    V e   \        V 4      s\        # )z+
Set MuPDF error display to True or False.
)r   r  ro  s   &r'   mupdf_display_errorsTOOLS.mupdf_display_errorsb  s     >#'8 ##r)   c                ,    V e   \        V 4      s\        # )z.
Set MuPDF warnings display to True or False.
)r   r=  r  s   &r'   mupdf_display_warningsTOOLS.mupdf_display_warningsb  s     >%)"X"%%r)   c                 "    \         P                  # )z"Get version of MuPDF binary build.)r   
FZ_VERSIONr,   r)   r'   r  TOOLS.mupdf_versionb  s     r)   c                    \         P                  ! 4        RP                  \        4      pV '       d   \        P                  4        V# )z>
Get the MuPDF warnings/errors with optional reset (default).
r#   )r   fz_flush_warningsr  r  r  reset_mupdf_warnings)r
  rI   s   & r'   r  TOOLS.mupdf_warningsb  s3     	!ii01&&(
r)   c                 	    \        4       sR # r+   )r   r  r,   r)   r'   r  TOOLS.reset_mupdf_warningsb  s     #'&r)   c                2    \         P                  ! V 4       R# )z
Set anti-aliasing level.
N)r   fz_set_aa_level)r   s   &r'   set_aa_levelTOOLS.set_aa_levelb  s    
 	e$r)   c                	j    V f   \         # \        V 4      ^,           pV^28  d   ^2pV R,          s \         # )N:Nr  N)rO  r9   )rQ  r  s   & r'   set_annot_stemTOOLS.set_annot_stemb  s8     <##4y1}"9D9r)   c                	   \        V ^ R7      pVP                  '       g   R# \        P                  ! W14      p\        P                  ! V\        R4      4      p\        P                  ! V4      '       d   \        P                  ! V4      p\        V4       F  p\        P                  ! WW4      p\        P                  ! V^4      p	\        P                  ! V	\        P                  ! ^ 4      4       \        P                  ! V	\        P                  ! R4      4       \        P                  ! V	\        P                  ! V4      4       \        P                  ! V\        R4      V	4       K  	  R# )rx   r  Fr9  ru  r:  T)r   r   r   rJ  r  r  rI  r  rS  r  rR  rK  rU  rU  )
r1  r  r  ra  r  dfontsrG   rg  dfontwarrays
   &&&       r'   r  TOOLS.set_font_widthb  s    sQ/~~~$$S/##D(3D*EFf%%##F+A1X++F6,,S!4$$VU->->q-AB$$VU->->u-EF$$VU->->u-EF""5(3-@  r)   c                2    \         P                  ! V 4       R# )z&
Set the graphics minimum line width.
N)r   fz_set_graphics_min_line_width)min_line_widths   &r'   set_graphics_min_line_width!TOOLS.set_graphics_min_line_widthb  s    
 	,,^<r)   c                    V '       d@   \         P                  '       d   \         P                  ! 4        R# \        R\        4       R# \         P                  '       d   \         P
                  ! 4        R# R# )z!Set ICC color handling on or off.zMuPDF built w/o ICC supportN)r   r  fz_enable_iccr  r	  fz_disable_iccr  s   &r'   set_iccTOOLS.set_iccb  sH     """##%67GH     " !r)   c                R    V e   \        V 4      \        n        \        P                  # )z!Set / unset MuPDF device caching.)r   r  r   r  s   &r'   set_low_memoryTOOLS.set_low_memory	c  s!     >)-bH&)))r)   c                    V eE   \        V 4      \        n        \        '       d%   \        P
                  ! \        P                  4       \        P                  # )z Set / unset small glyph heights.)r   r  r   r  r   set_small_glyph_heightsr  s   &r'   r  TOOLS.set_small_glyph_heightsc  s:     >+/8H({--h.J.JK+++r)   c                    V eE   \        V 4      \        n        \        '       d%   \        P
                  ! \        P                  4       \        P                  # )z;
Set / unset returning fontnames with their subset prefix.
)r   r  r   r  r   set_subset_fontnamesr  s   &r'   r  TOOLS.set_subset_fontnamesc  s:    
 >(,RH%{**8+D+DE(((r)   c                     \        \        P                  ! 4       \        P                  ! 4       \        P                  ! 4       R7      # )z
Show anti-aliasing values.
)r  r   graphics_min_line_width)r7   r   fz_graphics_aa_levelfz_text_aa_levelfz_graphics_min_line_widthr,   r)   r'   show_aa_levelTOOLS.show_aa_level$c  s5    
  557--/*/*J*J*L 	r)   c                     R# )z
MuPDF store size limit.
Nr,   r,   r)   r'   store_maxsizeTOOLS.store_maxsize/c       r)   c                    V ^d8  d   \         P                  ! 4        ^ # V ^ 8  d    \         P                  ! ^dV ,
          4       R# R# )z'
Free 'percent' of current store size.
N)r   fz_empty_storefz_shrink_store)percents   &r'   r	  TOOLS.store_shrink7c  s8    
 c>  "Q;!!3=1 r)   c                     R# )z
MuPDF current store size.
Nr,   r,   r)   r'   
store_sizeTOOLS.store_sizeCc  r  r)   c                    V eE   \        V 4      \        n        \        '       d%   \        P
                  ! \        P                  4       \        P                  # )z1
Set ascender / descender corrections on or off.
)r   r  r   r  r   set_skip_quad_correctionsr  s   &r'   unset_quad_correctionsTOOLS.unset_quad_correctionsKc  s:    
 >-1"XH*{//0N0NO---r)   r  r,   rv  ru  r+   )3r/   r0   r1   r2   rc  rB  r|  r[  rs  r  rP  r#  r  r"  r   r!  r%  r$  r&  r  r[  r  r  r  r  r  r  r  r8  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  rO  r  fitz_configr3   r,   r)   r'   r  r  a  s1   7  .     #3 #3J      &  *  &  &  &    *  6 4 4l 3 3 A A 0 0 " "
 % % 4 4 $ $ & &     	 	 ) ) % %      " = = # # * * , , ) )     2 2   . .  "Kr)   r  c                     \         P                  ! 4        \         P                  ! R 4       \         P                  ! R 4       R # r+   )r   r  fz_set_warning_callbackfz_set_error_callbackr,   r)   r'   _atexitr  sc  s*    		!!$'	%r)   	_wxcolorsc                     \         # )z}
Returns dict mapping from name to (red, green, blue).
    name: lower-case name.
    red, green, blue: float in range 0..1.
)pdfcolorr,   r)   r'   colors_pdf_dictr  c  s	     Or)   c                     \         # )z}
Returns list of (name, red, green, blue) tuples:
    name: upper-case name.
    red, green, blue: integers in range 0..255.
r  r,   r)   r'   colors_wx_listr  c  s
     r)   c                   ^ RI p\        R\        : 24       \        P                  P                  \         R24      pV R2pVP                  4       R8X  d   V R2pMTp\        R4       \        RV: 24       \        R	V: 24       \        P                  P                  V4      '       g   Q R
V: R24       h\        P                  P                  V4      '       g   Q RV: R24       hVP                  4       R8w  EdN   V '       EdE   \        RV: R\         R24       \        P                  R4      R,          pRP                  V4      pRV R2p\        RV: R24       \        P                  ! V4       F  p\        P                  ! Wg4      pV'       g   K#  V RVP                  ^4       2p	\        P                  P                  V	4      '       g&   \        P                  P!                  V	4      '       d'   \        RV	: R24       \        P"                  ! V	4       \        RV	 RV 24       \        P$                  ! Wy4       K  	  W43# )a  
Allows PyMuPDF installation to be used to compile and link programmes that
use the MuPDF C/C++ API.

Args:
    make_links:
        If true, then on non-windows we also create softlinks to any shared
        libraries that are supplied with a version suffix; this allows them
        to be used in a link command.

        For example we create links such as:

        site-packages/pymupdf/
            libmupdf.so -> libmupdf.so.26.7
            libmupdfcpp.so -> libmupdfcpp.so.26.7

Returns: (mupdf_include, mupdf_lib).
    mupdf_include:
        Path of MuPDF include directory within PyMuPDF install.
    mupdf_lib
        Path of MuPDF library directory within PyMuPDF install.
Nzmupdf_version=z/..z/mupdf-devel/includeWindowsz/mupdf-devel/libzWithin installed PyMuPDF:z    mupdf_include=z    mupdf_lib=zNot a directory: mupdf_include=r   zNot a directory: mupdf_lib=zCreating symlinks in mupdf_lib=z for MuPDF-z .so files.:r  r   Nz[.]z^(lib[^.]+[.]so)[.]$zmupdf_lib_regex=r	  zRemoving existing link pfrom=zCreating symlink: z -> )r  r%   r  rh   r   normpath__file__systemr  r8   r  r  rw  r  rx  islinkr  r  symlink)

make_linksr  r  mupdf_include	mupdf_libregex_suffixmupdf_lib_regexleafr  pfroms
   &         r'   _mupdf_develr  c  s   . >=

H:S)*Ac-.MI%c)*	 	
#%
} /yl77==''N+K]<LA)NN'77==##F'CA%FF#I%** 	.I<{=/UV$**3/4zz,//~Q? "#JJy)D/Aq$+Qqwwqzl3 77>>%((BGGNN5,A,A8%;<IIe$(tD6:;

4' * ##r)   )r  )rF  c                      ] tR tRtRtR# )FitzDeprecationic  r,   Nr  r,   r)   r'   r  r  c  s    r)   r  c                    \         P                  ! R \        R7       RR lp V \         n        RR lpV! \        RR4       V! \        R4       V! \        RR	4       V! \        R
4       V! \        R4       V! \        RR4       V! \        R4       V! \        RR4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        RR4       V! \        R4       V! \        R4       V! \        RR4       V! \
        R4       V! \
        RR4       V! \        R4       V! \        R4       V! \        RR 4       V! \        R!4       V! \        R"4       V! \        R#R$4       V! \        R%R&4       V! \        R'R(4       V! \        R)R*4       V! \        R+R,4       V! \        R-R.4       V! \        R/R04       V! \        R1R24       V! \        R34       V! \        R44       V! \        R54       V! \        R64       V! \        R74       V! \        R8R94       V! \        R:R;4       V! \        R<R=4       V! \        R>4       V! \        R?4       V! \        R@RA4       V! \        RBRC4       V! \        RDRE4       V! \        RF4       V! \        RG4       V! \        RHRI4       V! \        RJ4       V! \        RKRL4       V! \        RMRN4       V! \        RO4       V! \        RP4       V! \        RQ4       V! \        RR4       V! \        RS4       V! \        RT4       V! \        RU4       V! \        RV4       V! \        RW4       V! \        RX4       V! \        RYRZ4       V! \        R[4       V! \        R\R]4       V! \        R^R_4       V! \        R`Ra4       V! \        Rb4       V! \        Rc4       V! \        Rd4       V! \        Re4       V! \        RfRg4       V! \        Rh4       V! \        Ri4       V! \        Rj4       V! \        RkRl4       V! \        Rm4       V! \        Rn4       V! \        Ro4       V! \        Rp4       V! \        RqRr4       V! \        Rs4       V! \        RsRt4       V! \        Ru4       V! \        Rv4       V! \        Rw4       V! \        Rx4       V! \        Ry4       V! \        R4       V! \        R4       V! \        Rz4       V! \        R{R|4       V! \        R}R~4       V! \        RR4       V! \        RR4       V! RRR4       V! RRR4       V! RR4       V! RRR4       V! RRR4       V! RRR4       V! RRR4       V! RR4       V! RR4       V! \        Ry4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        RR4       V! \        RR4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        RR4       V! \        R4       V! \        RR4       V! \        R4       V! \        RR4       V! \        R4       V! \        R4       V! \        RR4       V! \        R
4       V! \        R4       V! \        R4       V! \        R4       V! \        RR4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        RR4       V! \        R4       V! \        R4       V! \        RR4       V! \        RR4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        RR4       V! \        RR4       V! \        R4       V! \        RR4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        RR4       V! \        R4       V! \        RR4       V! \        RR4       V! \        RR4       V! \        RR4       V! \        RR4       V! \        R4       V! \        RR4       V! \        R4       V! \        R4       V! \        R4       V! \        R4       V! \        RR4       V! \        RR4       V! \        RR4       V! \        R4       V! \        Rw4       V! \        R4       V! \        Rs4       V! \        RsRt4       V! \        Ru4       V! \        Rv4       V! \        Rw4       V! \        Rx4       V! \        R4       V! \        R4       V! \         R4       V! \         R4       V! \         R4       V! \         R4       V! \         R4       V! \         R4       V! \         R4       V! \         R4       V! \         R4       V! \         R4       V! \         R4       V! \         R4       V! \         R4       R# (   oncecategoryNc                    \         P                  ! WW#VR 7      pVP                  R4      pV^ 8  d   \        V4       R# WgR P	                  4       ^ ,          R,          p\        V4       R# ))rs   r  NrW  )warningsformatwarningr   r%   r  )r   catrj   rl   re   rs   r   r  s   &&&&&&  r'   showthis!restore_aliases.<locals>.showthisd  sY    %%ctLII'(q5IBx""$Q'+D	r)   c                  a aaa S f   \         P                  \        ,          o S'       gE   RoRpS F:  pVR8X  d   RpK  V'       d   SVP                  4       ,          oRpK1  SV,          oK<  	  \	        S S4      o\	        S SR4      '       d   Q RS  RS 24       h\        S4      '       d0   V VVV3R lp\        S SV4       R	S R
SP                   2Vn        R# \        S SS4       R# )ai  
Adds an alias for a class_ or module item clled <class_>.<new>.

class_:
    Class/module to modify; use None for the current module.
new_name:
    String name of existing item, e.g. name of method.
legacy_name:
    Name of legacy object to create in <class_>. If None, we generate
    from <item> by removing underscores and capitalising the next
    letter.
Nr`   Fr@  Tzclass z already has c            	     b   < \         P                  ! R S: RS RS R2\        R7       S! V / VB # )z"legacy_name=z" removed from z after v1.19.0 - use "z".r  )r  r.  r  )r  r  class_legacy_namenew_name
new_objects   *,r'   deprecated_function<restore_aliases.<locals>._alias.<locals>.deprecated_function*d  s@    (K>@VW_V``bc!0 "D3F33r)   z;*** Deprecated and removed in version after v1.19.0 - use "z". ***
)r  modulesr/   r
  r   r]  r  rc  )r	  r  r
  capitalise_nextr  r  r  s   fff   @r'   _aliasrestore_aliases.<locals>._aliasd  s     >[[*FK#O8&*O$1779,K&+O1$K  fh/
FK66c&VaUb8cc6Z  4 4 V[*=>QRZQ[[c!))*,  '
 V[*5r)   r  fileGetr  r  soundGetr  r  r$  getTextPagerQ  r  setBlendModer  r  r  r  r  r  r  setOCr  r  rY  fileUpdrw  rx  r  convertToPDFr  r  r  deletePageRanger  embeddedFileAddr  embeddedFileCountr  embeddedFileDelr  embeddedFileGetr  embeddedFileInfor  embeddedFileNamesr  embeddedFileUpdr  r  r(  r4  rU  ry  getOCGsr  getPageFontListr  getPageImageListr  r  r  getPageXObjectListr  getSigFlagsr  getToCr  r  r  	insertPDFr	  r  	isFormPDFr  isPDFr	  r	  r\	  r  r}	  r	  r  r  r	  rv  r	  pageCropBoxr(  r]  
PDFCatalogr  
PDFTrailerr	  previousLocationr  r
  r  r
  r'  setToCr2  r_  r
  r  isStreamr  r^  r
  r  r  metadataXMLr  getRectArear  r  r  r  r  r9  r=  	preRotaterC  preScalerF  preShearrK  preTranslater  	getPDFnowr  	getPDFstrr  getTextlengthr8  ImagePropertiesr  	PaperRectr  	PaperSizer  rp  rA  r6  r<  rB  rF  rO  rT  rY  r_  rc  rg  rn  rt  rx  r}  r  r  r  r  r	  r  r  CropBoxPositionr  r
  r  ru  r  r  r  r  r   r$  r(  r  r3  r;  r@  rK  rO  rS  r
  rl  getDisplayListr}  r  getFontListr  r  getImageListr)  r  getSVGimager  r  r  r@  r  r  r  r  
_isWrappedr  rN  rJ  r  rl  MediaBoxSizer  rt  rx  r
  r  
setCropBoxr  setMediaBoxr  r1  showPDFpagert  r  r  r  r  r8  
copyPixmaprH  rO  invertIRectr  pillowWriter  
pillowDatar"  
writeImagewritePNGr  r  setResolutionr  r  r  r  getImageData
getPNGData
getPNGdatar  ry  rR  r<  r+   )r  filterwarningsr  showwarningr   rX  r   r  r  r  r+  r   r  r)  r+  r  ro  )r  r  s     r'   restore_aliasesrS  c  s	   Vo> $H)6V E:I6
E< 
E;J7
E:
E=!
E>M:
E;
E?N;
E< 
E< 
E;
E:
E?#
E:
E8W%
E=!
E:
E=I6
K&
KM:
Ho&
H*+
H&N;
Hk"
Hm$
Hn,=>
Hm,=>
Ho,?@
Hm,=>
Hm,=>
Hn,>?
Ho,?@
Hm,=>
Hn%
Ho&
Ho&
Ho&
H'(
HjI6
H&,=>
H',>?
H'(
Ho&
H),@A
HnM:
Hi*
H()
Hm$
HlK8
Hj!
HmK8
Hh(
Ho&
Hm$
Ho&
Hk"
Ho&
Hk"
Hl#
Hj!
Ho&
Hl#
HnM:
Hk"
HmL9
HmL9
Ho,>?
Hn%
H'(
Hn%
Hn%
Hi*
H()
Ho&
Ho&
H&J7
Hm$
Hm$
Hm$
H'(
H)M:
E:
E:M:
E?#
E>"
E:
E=!
D- 
D,
D,
F$%
FKK8
FJJ7
FJJ7
FNN;
D-K8
D-K8
D#$
D#O<
D/,=>
D,K8
D,K8
D- 
D.!
G]#
GY
D#$
D$%
D"#
D&'
D'(
D/"
D"#
D%&
D&'
D"#
D$%
D&'
D#$
D'(
D"#
D'(
D,
D"#
D)I6
D$,=>
D.!
D- 
D/"
D%&
D- 
D- 
D,
D+
D+
D/"
D+
D+
D- 
D/"
D- 
D- 
D,
D.!
D.!
D#,<=
D.!
D+M:
D"#
D,N;
D+
D,
D/M:
D*
D#$
D"#
D- 
D.M:
D- 
D.!
D- 
D- 
D"#
D,L9
D,
D,
D*J7
D/N;
D+
D/"
D#$
D,
D-L9
D.M:
D.!
D/M:
D)*
D- 
D/"
D,
FL!
FFL9
FL!
FNM:
FJM:
FML9
FFL9
FFJ7
FK 
FIO<
FL!
FK 
FJ
FK 
FIN;
FIL9
FIL9
D+
D*
D"#
D*
D*M:
D/"
D.!
D*
D- 
J'
J%
E=!
E=!
E< 
E;
E;
E?#
E;
E;
E=!
E?#
E=!
E=!
E#$r)   zPyMuPDF z : Python bindings for the MuPDF z library.
Python z running on r  z-bit).
)r`   r  r  r%  )rx   rx   rx   rx   rx   N)PDF_UCDN_SCRIPT_)r  r  r  r  r  r  r  r  r  r  r  r  r>  r=  i   )r     r  )r  rV  r  (      gq=
ףp?rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  )          ?)r  Zd;O?)"   7A`?)#   r  )$    rh?)%   -?)&   gL7A`?)'   jt?)(   r[  ))   r[  )*   r  )+   r`  ),   rZ  )-   r`  ).   rZ  )/   n?)0   r  )1   r  )r  r  )3   r  )4   r  )5   r  )6   r  )7   r  )8   r  )9   r  ):   rn  );   rn  )<   r`  )=   r`  )>   r`  )?   g"~j?)@   r`  )A   v?)B   MbX?)C   r  )D   g/$?)E   Zd;O?)F   "~j?)G   粝K?)r  r  )I   r[  )r  x&1?)K   r  )L   ʡE?)M   g r?)N   r  )r  r  )P   ~jt?)Q   gʡE?)R   gn?)S   gl?)T   r  )U   Gz?)V   re  )W   r  )r  gp=
ף?)Y   q=
ףp?)r  r  )[   r[  )rt  gV-?)]   r[  )^   uV?)r  r  )`   r  )a   r  )b   r`  )c   r`  )d   V-?)e   re  )f   y&1?)g   M?)h   r  )r  uV?)j   r  )k   r`  )l   r`  )m   ;On?)n   r  )o   r`  )p   r`  )r  r  )r   r`  )s   r  )t   re  )u   r  )v   r]  )w   r  )x   gZd;O?)y   r  )z   r  ){   Q?)|   r:  )r  r  )~   r`  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  rW  )rF  rZ  )   gףp=
?)r  gV-?)   r`  )   gK7A`?)   r]  )   r  )   jt?)   r  )   r  )   r  )   y&1?)   r]  )   r  )   /$?)   r  )r  g?)   r`  )   r  )   r`  )r  r`  )   r  )   r  rW  )   r`  )   r`  )   r`  )   r`  )   r  )   r  )   r  )   r  )   tV?)   r  )   r  )   r  )   r  )   r  )   r  )   r  )   r  )   r]  )   r]  )   r]  )   r]  )   r]  )   r]  )   r]  )   r  )   r]  )r  HzG?)   r  )   g{Gz?)   r  )   r`  )   r`  )   r]  )   r  )   r  )   r  )   r  )   r  )   r  )   r  )   r  )   r  )   r  )   r  )   x&?)   r]  )r  ~jt?)   r
  )   r
  )   r
  )   r
  )   r
  )   r  )   r  )   r  )   r  rW  )   r  )   gK7?)   r  )   r  )   r  )   r
  )   r`  )   r
  )r  r
  )   r
  )   r
  )   r  )   r  )r  r  rW  (   rX  K7?r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )rY  rn  )r  ^I+?)r\  gn?)r^  r"  )r_  g\(\?)ra  g5^I?)rc  sh|??)rd  r  )rf  Zd;O?)rg  r  )rh  gQ?)ri  g?5^I?)rj  r`  )rk  g\(\?)rl  x&?)rm  gB`"?)ro  r%  )rp  g=
ףp=?)r  r"  )rq  g)\(?)rr  gOn?)rs  Mb?)rt  '1Z?)ru  gʡE?)rv  gDl?)rw  r  )rx  RQ?)ry  }?5^I?)rz  gT㥛 ?)r{  r  )r|  gDl?)r}  gv/?)r~  gX9v?)r  g/$?)r  r  )r  r!  )r  r!  )r  r  )r  gK7A`?)r  g rh?)r  &1?)r  r  )r  r#  )r  gx?)r  r  )r  rb  )r  r*  )r  d;O?)r  gK7?)r  g+?)r  gA`"?)r  g+?)r  r  )r  MbX?)r  g=
ףp=?)r  E?)r  r  )r  r,  )r  r)  )r  9v?)rt  g-?)r  gm?)r  g;On?)r  g;On?)r  gGz?)r  r#  )r  r#  )r  r.  )r  gCl?)r  ʡE?)r  g?5^I?)r  r  )r  gv/?)r  r]  )r  r$  )r  gQ?)r  r$  )r  V-?)r  r'  )r  r&  )r  r&  )r  r)  )r  r)  )r  %C?)r  r1  )r  r!  )r  gJ+?)r  gx&1?)r  gDl?)r  g|?5^?)r  g(\?)r  J+?)r  r2  )r  K7A`?)r  r3  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r  gCl?)r   rh?)r  r4  )r  gQ?)r  r  )r  r(  )r  r(  )r  r-  )r  g
ףp=
?)r  gh|?5?)r  gx&1?)r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  r   )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  r!  )r  gS㥛?)r  g7A`?)r  gK7A?)r  gZd;O?)r  V-?)r   rh?)r  r5  )r  gK7A`?)r  Dl?)r   V-?)r  r8  )r  g㥛 ?)r  r0  )r  g"~?)r  r6  )r  r6  )r  gMbX?)r	  g(\?)r  gn?)r  goʡ?)r  gK7A?)r  獗n?)r  r9  )r  X9v?)r  r:  )r  r/  )r  r/  )r  +?r   )r  r;  )r  r(  )r  gʡE?)r  y&1?)r  gGz?)r  r<  )r  "~j?)r  gl?)r  r=  )r  r+  )r  r0  )r  r7  )r  g
ףp=
?r   r   )strictr+   )r  rr  rx   )r  rx  )r  r  r  r,   l        (  __conditional_annotations__rc  
__future__r   atexitr  collectionsr!  importlib.utilr   rf   r;   r  rh   r  rw  rJ  r  r  rY  r  r  r  r  r`   r   rJ   r   r:   r  rZ   r^   r   rO   rR   rP   rT   rW   r\   r_   r%   rv   r{   r  rm  rn  r  r   r   r  r  r   r  r   __annotations__r   r   r   r   r  	machinerySourceFileLoaderload_moduler{  r|  r   rk   r=   r   reinit_singlethreadedr   _buildr   r   r   r   r   r   r   r   r  r  pymupdf_dater   r8   rs  FZ_VERSION_MAJORFZ_VERSION_MINORFZ_VERSION_PATCHversionVersionFitzVersionBindVersionDater   format_gr  r  r  r  r  Optionalr  r7   r8  r  r  Unionr6   r  Sequencer  r  r  r   r   r   r   r   r   r   r   r   r  r   r~  r  r+  rG  rX  FzDocument_insert_pdfr  r   r<   r  r  r  r  r  rQ  r  r  rZ  r  r+  r  r   r  r)  r)  r+  ro  r*  r  r  r  r  r/   _selfr  rD   r=  _valuer5   r  
getmembersPDF_SIGNATURE_SHOW_LABELSPDF_SIGNATURE_SHOW_DNPDF_SIGNATURE_SHOW_DATEPDF_SIGNATURE_SHOW_TEXT_NAMEPDF_SIGNATURE_SHOW_GRAPHIC_NAMEPDF_SIGNATURE_SHOW_LOGO PDF_SIGNATURE_DEFAULT_APPEARANCEUCDN_EAST_ASIAN_HPDF_TX_FIELD_IS_MULTILINEUCDN_SCRIPT_ADLAMAnyr*  Base14_fontnamesr"  r  r  r8  r  r  r  rO  r  r  r=  FZ_RECOMPRESS_NEVERFZ_RECOMPRESS_SAMEFZ_RECOMPRESS_LOSSLESSr
  FZ_RECOMPRESS_J2Kr	  r	  FZ_SUBSAMPLE_BICUBIC	PDF_OC_ONPDF_OC_TOGGLE
PDF_OC_OFFr  r  r   r  r{  r  ry  rz  LINK_FLAG_R_VALIDLINK_FLAG_B_VALIDLINK_FLAG_FIT_HLINK_FLAG_FIT_VLINK_FLAG_R_IS_ZOOMr  r  STAMP_Approved
STAMP_AsIsSTAMP_ConfidentialSTAMP_DepartmentalSTAMP_ExperimentalSTAMP_ExpiredSTAMP_FinalSTAMP_ForCommentSTAMP_ForPublicReleaseSTAMP_NotApprovedSTAMP_NotForPublicRelease
STAMP_SoldSTAMP_TopSecretSTAMP_Draftr  r  r  r  TEXT_FONT_SUPERSCRIPTr  r  r  r  TEXT_OUTPUT_TEXTTEXT_OUTPUT_HTMLTEXT_OUTPUT_JSONTEXT_OUTPUT_XMLTEXT_OUTPUT_XHTMLFZ_STEXT_PRESERVE_LIGATURESr
  FZ_STEXT_PRESERVE_WHITESPACEr
  FZ_STEXT_PRESERVE_IMAGESr  FZ_STEXT_INHIBIT_SPACESTEXT_INHIBIT_SPACESFZ_STEXT_DEHYPHENATEr
  FZ_STEXT_PRESERVE_SPANSTEXT_PRESERVE_SPANSFZ_STEXT_MEDIABOX_CLIPr
  $FZ_STEXT_USE_CID_FOR_UNKNOWN_UNICODE TEXT_USE_CID_FOR_UNKNOWN_UNICODEFZ_STEXT_COLLECT_STRUCTURETEXT_COLLECT_STRUCTUREFZ_STEXT_ACCURATE_BBOXESTEXT_ACCURATE_BBOXESFZ_STEXT_COLLECT_VECTORSTEXT_COLLECT_VECTORSFZ_STEXT_IGNORE_ACTUALTEXTTEXT_IGNORE_ACTUALTEXTFZ_STEXT_SEGMENTTEXT_SEGMENTFZ_STEXT_CLIP	TEXT_CLIPFZ_STEXT_LAZY_VECTORSTEXT_LAZY_VECTORSFZ_STEXT_FUZZY_VECTORSTEXT_FUZZY_VECTORSFZ_STEXT_PARAGRAPH_BREAKTEXT_PARAGRAPH_BREAKFZ_STEXT_TABLE_HUNTTEXT_TABLE_HUNTFZ_STEXT_COLLECT_STYLESTEXT_COLLECT_STYLES$FZ_STEXT_USE_GID_FOR_UNKNOWN_UNICODE TEXT_USE_GID_FOR_UNKNOWN_UNICODEr  TEXT_CLIP_RECTFZ_STEXT_ACCURATE_ASCENDERSTEXT_ACCURATE_ASCENDERSFZ_STEXT_ACCURATE_SIDE_BEARINGSTEXT_ACCURATE_SIDE_BEARINGSTEXT_STEXT_SEGMENTTEXT_CID_FOR_UNKNOWN_UNICODETEXTFLAGS_WORDSTEXTFLAGS_BLOCKSTEXTFLAGS_DICTTEXTFLAGS_RAWDICTTEXTFLAGS_SEARCHTEXTFLAGS_HTMLTEXTFLAGS_XHTMLTEXTFLAGS_XMLTEXTFLAGS_TEXTTEXT_ENCODING_LATINTEXT_ENCODING_GREEKTEXT_ENCODING_CYRILLICr  r2  r.  r0  PDF_BM_ColorPDF_BM_ColorBurnPDF_BM_ColorDodgePDF_BM_DarkenPDF_BM_DifferencePDF_BM_ExclusionPDF_BM_HardLight
PDF_BM_HuePDF_BM_LightenPDF_BM_LuminosityPDF_BM_MultiplyPDF_BM_NormalPDF_BM_OverlayPDF_BM_SaturationPDF_BM_ScreenPDF_BM_SoftLightr  r   r  r  r  r  r  r  r  dictkey_ascr  r  r  r  r  r  r  r  r1  r4  r  
dictkey_dar]  r  dictkey_descr  dictkey_effectr  r  re  r  r  r  dictkey_glyphr  r7  r  r>  r  r  r  r5  r2  r  r  r  r  r
  r   rd  r^  r6  r
  r3  r  r  r  r  r  r  r  r   r  r  r8  r  r  r  rY  rN  rM  r  r  r  rO  r  r  r  r  rd  r  r|  r  r#  r  r.  r$  r  r  r  r  rJ  r	  r/  r  r  r  r  ry  r{  r  rl  ry  r  r  r  r1  rB  r4  r  r  r  r  r	  r  re  r  rf
  r  rg
  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  rk  r#  r  r  re  rj  r  rq  rY  r  rf  r  r  r  r  r  r  r  r  r$  rK  r  r  r  r	  r  r  rm  r  ri  r  r_  r>  r@  rV  rE  rH  rC	  r  r  r  r~  r  r`  r+  rh  rg  rS  r{  r  r  rp  r_  r.  r  rz  r  r  r  r  r  r  r  r
  r  r"  r  r!  r  r  r0  r&  rJ  rL  r  r-  rK  rY  r/  r  MSG_BAD_DOCUMENTMSG_BAD_FILETYPEMSG_BAD_LOCATIONr  r  rV  r	  r  r1  r  r  r  MSG_COLOR_COUNT_FAILEDr#  r0  r  r  r  r  r  r  r  r	  r  r  r  r  rK  rM  r  ro  rL  rK  r  r  r  rO  rI  r  r  r  r  r  rj  r2  r  r8  rD  rG  rK  rN  rS  rW  r[  r_  ra  rc  rf  ri  rn  rl  r  r  r  r  r  FzPathWalker2r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rp  PdfFilterOptions2r  	FzDevice2rB  	FzOutput2rJ  r  r^  r  r=  r@  r3  r4  rJ  rL  rR  rO  r}  r  rt  ra  re  rL  rh  rx  r  r  r  rz  r  r  r  r  r  rJ  r6  r  r1  r+  r5  rw  r  rV  r~  r*  r  r  r  r2  r  r`  r  ro  rN  r(  r%  r  r  r  r  r  r  r=  r  r  r  r  r  registerr  r  r   r$  r  rI  r  r  r  r  recover_bbox_quadrecover_char_quadrecover_line_quadrecover_quadrecover_span_quadrF  DeprecationWarningr  rS  __version__r  r  maxsize)rg  r?  s   0@r'   <module>r     s   #       	  	  	  
       ss s 	s
 s s s s s s sl 2::>>2C#DcjjY rzz~~m<cjjQ
 v !  	
      :  	
      <.22  **\9CFBC $  #$@!D  /6' ' :04- 4  ". jjnnm,H:_[O3X	YZH:^BJJ|$<#=	>?b)):: +- 	 !!''E u-..##%	! # & $ # # )   &    -2E2Ec2JK2JQgaj2JKL u55u7M7MuOeOeff U
C/B.D  ES%J`J`bgbxbxz  {Q  {Q  JR  IT  	UUf
 M4
0
2D 2$ 0""J
 ??:&
//$
??5!	c4i	 		)		
		4$4.00*  	
Z< Z<z*c' c'LP	 P	f BO O.+ +Z "'"="=IS ISVf )& )&X|" |"~ t tno od:V :. e, e,NN Nb
 O Od;|j: j:Zus' s'lx xveX eXP` `F	[ [|hB hBVW Wt
a aHt tt KK!E"^^113ME6 899##$455 E5&1 42 )*--).)))* ++), 00	)1
 33)4 ++),$ ""a''' %(G(GGGG 7 7777uf
** " 	A!"OAGGI 
% - * 1 # + ( / ' & ( , " ( 
      // -- 55 -- ++ ++ 11 11 
 	

 		

       
       
           ;;  == 55 33 -- 33 11 #(#M#M  99 55 55 99 %%	*$33*$5555 ++33 #(#M#M  ));; #CC  " ? 
!"
"#  +	+ 
!"
"#  +	+  
!"
"#  	
 ++ # 
"#
  +	+  
!"
"#  	
 ++ 
!"
"#  	
 ++ 
!"
"#  +	+ 
!"
"#  +	+      


        
      	  DY  le}Zg

	L 		 		] 	 	6	G		G	
 	! % 
 ! 
 ::*//1!&&(,7NQ) )A
HA
N	"!3H'UT<
U T:6$
CLI II I/*2 %P.3=l
2>&&<
Vr84n$%P .0j/d(&"JN0I $ *.6(("J% %P7 7t(02/ ;|4)n,"^B)X B
 >. 
)XD$N<KZ7:0\(Tl(%T
H*.+B>:3l? D**6
*,.
2	*Z.(6VBB"(	"*Z,6.H"0FR&#R<8#:L-`3<'B*"D8 20 F( & )? ( %( 0 ! ! ' % %%#*!- / &$(.,  '  	P P  	 		 	H H
 

- 
-. .$.
# 
#2.b" "J2 2jCSLB$(B=ABRVB BJ': ':T' ',DNJ1X$N.bUp8NpU   pf!H0f*($
!
+ + u66 . .>$5?? $0$P/5?? P/f3%eoo 3%l1 1h * 
 

8 $f F FR 1( (VG8Q*d Q*t Q* Q* Q*$ Q*4 Q*ht   $ 4 D Hf/$N,6 ">2D2N) ) (6
p2/dH H@4 4 $)X,     ! 	 	1 	
 f   f    D= = 	=
 = = = = = = = =@{# {#~ 	!!"23	/(&    	 6MD!QeQsUAcE2HTZZ\ I$^  
 $55 #55 #55 #00#55   	( 	U%n  
;-?} M""1%&a(8(8(;'<LVX_b_j_jmr_rY[xzX{  |D	E ]\  H LN  0"Z/J0h]  sM   'AQ 4AQ!9AQ& :AAR QAQQAQQ&ARR ARRARRAR