
    Rj             	       x   U d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZ d dlmZ d dlmZmZ d dlmZ d dlmZ d dlmZmZ d dlmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( 	 d d	l)m*Z* d d
l+m,Z, n# e-$ r d\  Z*Z,Y nw xY w	 d dl.m/Z/ n(# e-$ r   e	j0        d            G d d          Z/Y nw xY wddl1m2Z2m3Z3m4Z4 ddl5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z< ddl=m>Z>m?Z?m@Z@mAZA ddlBmCZCmDZDmEZEmFZF ddlGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZO ddlPmQZQ ddlRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZm ddlnmoZompZpmqZqmrZr ddlsmtZtmuZumvZvmwZwmxZxmyZy ddlzm{Z{m|Z| ddl}m~Z~ ddlmZmZmZmZmZ ddlmZmZmZmZ ddlmZmZmZmZ dd lmZ dd!lmZ dd"lmZmZmZmZmZmZmZmZmZ dd#lmZ dd$lmZ dd%lmZ dd&lmZmZ dd'lmZmZ dd(lmZmZmZmZmZ dd)lmZmZ dd*lmZmZ dd+lmZ dd,lmZmZ dd-lmZmZmZmZmZmZmZmZ  e d.          Z e$d/          Zerd d0lmZ d d1lmZ dd2lmZ dd3lmZ d4ZeZd5d6d7d8d9d:Z	  ej        eѦ          Z eeӦ                                          j        Zed;z  Zeed<<   deaj        eaj        eaj        d=Zeeeea         f         ed><    G d? d@e          Z	 dLdAeeeef         z  dBee         dCeeef         fdDZdEeeef         dCeeef         fdFZ G dG dHe{e          Ze>ej        e         _        dIdJiZg dKZdS )M    N)defaultdict)contextmanager)datetimetimezone)wraps)splitext)PathPurePath)TYPE_CHECKINGAnyBinaryIOCallableIteratorLiteral
NamedTupleOptional	ParamSpecSequenceType	TypeAliasTypeVarUnion
ValuesViewcastoverload)pkcs12)signerNN)ImagezFPillow could not be imported - fpdf2 will not be able to add any imagec                       e Zd ZdS )r   N)__name__
__module____qualname__     J/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/fpdf/fpdf.pyr   r   <   s        r%   r      )Action
GoToAction	URIAction)DEFAULT_ANNOT_FLAGSAnnotationDictPDFAnnotationPDFEmbeddedFile)BidiParagraphauto_detect_base_direction) WarnOnDeprecatedModuleAttributesdeprecated_parameterget_stack_levelsupport_deprecated_txt_arg)DrawingContextGraphicsContextGraphicsStylePaintedPath)Color
ColorInput
DeviceCMYK
DeviceGray	DeviceRGBPoint	Transformconvert_to_device_color)StandardSecurityHandler)AccessPermissionAlignAngleAnnotationFlagAnnotationNameAssociatedFileRelationshipCharVPosCornerDocumentComplianceEncryptionMethodFileAttachmentAnnotationNameMethodReturnValueOutputIntentSubTypePageLabelStyle
PageLayoutPageModePageOrientationPathPaintRulePDFResourceTypeRenderStyleTextDirectionTextEmphasisTextMarkupTypeTextModeWrapModeXPosYPos)FPDFExceptionFPDFPageFormatExceptionFPDFUnicodeEncodingExceptionPDFAComplianceError)
CORE_FONTSCoreFontFontFace	TextStyle
TitleStyleTTFFont)GraphicsStateMixinStateStackType)	HTML2FPDF)
ImageCacheImageFilter	ImageInfoRasterImageInfoVectorImageInfo)SUPPORTED_IMAGE_FILTERSget_img_info
load_imagepreload_image)FragmentMultiLineBreakTextLineTotalPagesSubstitutionFragment)LinearizedOutputProducer)OutlineSection)	ZOOM_CONFIGSOutputIntentDictionaryOutputProducerPDFICCProfilePDFPagePDFPageLabelResourceCatalogResourceTypesstream_content_for_raster_image)Gradient)FPDFRecorder)	Signature)
StructElemStructureTreeBuilder)Percent	SVGObject)DestinationXYZNamePDFArrayPDFDate	PDFString)Tabledraw_box_borders)TextColumnsTextRegionMixin)
Transition)UnicodeScriptget_unicode_script)FloatTolerance	ImageTypeNumberNumberClassPaddingbuiltin_srgb2014_bytesget_parsed_unicode_rangeget_scale_factorPR)PrivateKeyTypes)Certificate)	Type3Font)ViewerPreferencesz2.8.7)QO@g33333@)
ףp=@r   )gGz8z@r   )d  i  )r   i  )a3a4a5letterlegalfontFPDF_FONT_DIR)defaultsingle
continuoustwoLAYOUT_ALIASESc                   z    e Zd ZU edee         gdf         ed<   eed<   eed<   e	e
z  ed<   dZeed<   d	Zeed
<   dS )ToCPlaceholderFPDFNrender_function
start_pageypage_orientationr'   pagesTreset_page_indices)r!   r"   r#   r   listrx   __annotations__intfloatstrrR   r   r   boolr$   r%   r&   r   r      ss         vtN';<dBCCCCOOOHHHO++++E3NNN######r%   r   formatkreturnc                    t          | t                    rU|                                 } | t          v r'| dk    rt	          j        d           t          |          S t          | d          |t          t          |           d          	 | d         |z  | d         |z  fS # t          $ r}|  d	| }t          d
|           |d}~ww xY w)aO  Return page width and height size in points.

    Throws FPDFPageFormatException

    `format` can be either a 2-tuple or one of 'a3', 'a4', 'a5', 'letter', or
    'legal'.

    If format is a tuple, then the return value is the tuple's values
    given in the units specified on this document in the constructor,
    multiplied by the corresponding scale factor `k`, taken from instance
    variable `self.k`.

    If format is a string, the (width, height) tuple returned is in points.
    For a width and height of 8.5 * 11, 72 dpi is assumed, so the value
    returned is (8.5 * 72, 11 * 72), or (612, 792). Additional formats can be
    added by adding fields to the `PAGE_FORMATS` dictionary with a
    case insensitive key (the name of the new format) and 2-tuple value of
    (width, height) in dots per inch with a 72 dpi resolution.
    r   z9Dimensions for page format A5 were fixed in release 2.8.5T)unknownN)oner   r'   z, zArguments must be numbers: )
isinstancer   lowerPAGE_FORMATSwarningswarnr^   	Exception)r   r   eargss       r&   get_page_formatr      s    , &# 	<\!!~~O    ''%fd;;;;y%c&kkt<<<<Say1}fQi!m++ S S SA%&JD&J&JKKQRRSs   B" "
C,CCfnc                 |     t                     dt          j        dt          j        dt          f fd            }|S )z$Decorator to protect drawing methodsr   kwargsr   c                      | d         }t          |d          r|j        s9|                    d          s$|                    d          st          d           | i |S )Nr   pagedry_run
split_only/No page open, you need to call add_page() first)hasattrr   getr]   )r   r   selfr   s      r&   wrapperzcheck_page.<locals>.wrapper  s~    Awf%%	S9	S ::i((	S -3JJ|,D,D	S   QRRRr4"6"""r%   )r   r   r   r   r   )r   r   s   ` r&   
check_pager     sS     2YY#qv # #a # # # # # Y# Nr%   c            +       *    e Zd ZU dZdZdZdZdZdZ e	j
        de	j                  ZdZd	ZeZej        d
ddfdddeeef         deeef         deeeeef         f         ded         deeeef                  ddf fdZedeeeez  f         fd            Zde j!         e"j#                    dfdedee         de de$de%ddfdZ&dede'de'ddfd Z(d!eddfd"Z)ede*fd#            Z+ede%fd$            Z,edee-         fd%            Z.e.j/        d&e-ez  ddfd'            Z.ede0e1         fd(            Z2	 	 	 	 	 dd)e3d*ee         d+ee         d,ee         d-ee4         d.ee         ddfd/Z5edefd0            Z6edefd1            Z7ede$fd2            Z8d3eddfd4Z9dd6ed7ed8eddfd9Z:d3eddfd:Z;d3eddfd;Z<d3eddfd<Z=dd>e%d3eddfd?Z>edeeef         fd@            Z?deez  dAedBeddfdCZ@	 ddEeez  dFeddfdGZA	 	 	 	 	 ddHe%dIeeee'f                  dJeeeBz           dKee         dLee         ddfdMZCedeeD         fdN            ZEeEj/        dOeeeDz           ddfdP            ZEdQe%ddfdRZFdSeddfdTZGdUeddfdVZHdWeddfdXZIdYeeJe         z  ddfdZZKd[eeJe         z  ddfd\ZLd]eddfd^ZMd_eddfd`ZNddaeeO         ddfdbZPdceddfddZQdeedf         dgeddfdhZRdieddfdjZSddleddfdmZTeU	 	 	 ddneeeVz           doee         dpee$         ddfdq            ZW	 	 	 	 	 	 	 	 ddededse%dtedueeX         dneeeVz           doee         dpee$         ddfdvZYddwZZ	 ddeez  deeeef         z  dse%dtee         dueeX         dxe%ddfdyZ[ddzZ\dd{Z]de$fd|Z^defd}Z_	 dd~e`eaz  ez  eJe`         z  de`de`ddfdZb	 dd~e`eaz  ez  eJe`         z  de`de`ddfdZc	 	 dd~e`eaz  ez  eJe`         z  edz  eez  efz  de`de`ddfdZg	 ddede%de%defdZhdeddfdZideeejz  ekz  efz  ee         z           ddfdZlemeU	 ddee%         deneo         fd                        ZpemeUdeqdend         fd                        ZrdesfdZtemd=d=eujv        dfdededeudee%         denew         f
d            Zx	 	 ddeydee%         de%ddfdZz	 ddedededdfdZ{dedededdfdZ|emdeneo         fd            Z}deeweyf         dddefdZ~eUdededededdf
d            ZeU	 	 	 ddeJeeef                  de%de%deeez           ddf
d            ZeU	 	 ddeJeeef                  de%deeez           ddfd            ZeU	 	 ddededededededdfd            ZeU	 	 	 ddededededeeez           de%deddfd            Zdededededede%eeez  df         z  d~eddfdZ	 ddedededededee         ddfdZeU	 ddededededeeez           ddfd            ZdedededededdfdZeU	 ddedededeeez           ddf
d            ZeU	 	 ddedede$dededeeez           ddfdÄ            ZeU	 	 ddedededede$dedeeez           ddfdȄ            ZeU	 	 	 	 	 	 ddedededededee         dede%de%de%deeez           ddfd̈́            Z	 	 	 	 ddedededededee         dede%deeez           ddfd΄Z	 	 ddeJeeef                  de%deeez           ddfdЄZ edg          	 	 	 ddddd=dҜdee         dedeeez           deeeJee$z  ee$e$f         z           z           deeeeeef         f         eeef         z           dee$         de$ddfdل            Z	 	 	 ddee         deee*f         deddfdۄZdeddfd܄Z	 ddeez  dede%defd߄ZdeddfdZdeddfdZ	 ddeJe         de%ddfdZ	 	 	 	 	 ddedede$dEeez  dee         de$fdZdedefdZ	 	 	 	 	 	 ddee$         dedede$dEeez  dee         deez  fdZ	 ddededededee$z  dee         de'defdZ	 	 	 	 	 	 ddeeeef                  dee         dee         deeO         dee         dee         de'defdZeUdddefdeez  dededededeeez           deeez  df         de'defd            ZeU	 	 	 ddedededededeeez           de'defd            ZeU	 	 	 	 ddedee         dee         dee         dee         de'defd            ZeUdededededede'defd            Zem	 	 	 ddedeez  d eeeef         deeO         de'dend         fd            Zemde'de'dend         fd            ZeU	 	 	 ddeez  dedeJe         d eeeef         deeO         dee$         de'defd            ZeU	 	 	 ddeJeeef                  ded eeeef         dede'defd            ZeUeddedededdfd	                        ZeU	 dd
edee         dee         ddfd            ZeUem	 dd
edee         dee         dend         fd                        ZeUem	 	 	 	 dÐdededee         dee         dend         f
d                        ZeUemdeeef         d
eez  ez  dend         fd                        ZeUemdedend         fd                        ZeUemde'dend         fd                        Z	 	 	 	 	 	 	 	 dĐdee         dee         dee         dee         dee         dee         dee         deeeeeef         eeef         f                  de'ddfdZddZede%fd            ZeUedddrd=dej        ddrddej        ej        fdee         dee         deded          ez  d!ed         d"eez  de%deee$z           d#e%de%d$eez  d%eez  de%fd&                        Zdd=ej        ej        ddrdddf	d'edee         deee$f         d$ed%ede%deee$z           d#e%d(ee         d)e%de%fd*Zdededededdf
d+Zdede%deJe         fd,Zdee         de%deJe         fd-Z̐dd.ededee         fd/Zdede%dene         fd0Zΐd1ede%fd2Zdede%fd3ZАdd4Zde%fd5Zemdend         fd6            Ze%Zee֐d7<   ee         Zee֐d8<   eZee֐d9<   eez  ez  eeef         z  eeef         z  eeef         z  eeeef         z  Zee֐d:<   eUeddrd=ej        dddddddej        ej        ej        dej        dd=fdedee         deded          ez  d"eez  de%d;e%dee$ez           d!ed         d<ee         de%d=e%d$eez  d%eez  d>eݐd?e%d@eez  d#e%d(e$eJe$         z  ez  def(dA                        ZeUeddrdrdej        fdee         dedeee$z           d=e%d>ede%fdB                        ZeUdddddCddDddddej        dfdee         dEee         dFe%dGe$dHee         dIe%dJeeez           dKee         dLee         dMee         d=ee%         d>ee         dNee%         defdO            Z	 	 	 	 	 	 	 	 	 	 ddedeeez           dee         dededeed         z  dz  deee$z           dSee         dee         dPeeeef                  dQe%deez  fdRZ	 	 	 	 	 	 	 	 	 ddedEed.edeeez           dee         dededeee$z           dSee         dee         dPeeeef                  dQe%defdSZdeez  dededTeez  dQe%defdUZ	 	 	 	 	 	 	 	 ddedVed.edeeez           dee         dededeee$z           dSee         dee         dQe%defdWZdedEed.edededXedefdYZ	 ddeez  ejz  ekz  ez  dPeeef         dz  deeeekz  ez  ejz  ez  dz  eez  f         fdZZd[eejz  deeeekz  ez  ejz  ez  dz  eez  f         fd\Zemde'dene         fd]            Zde'defd^ZeUddee         ddfd_            Zdefd`ZdeddfdaZdefdbZdeddfdcZdededdfddZdedefdeZddfddddej        ej        ffdgeez  dhee         diedjee         dkee         dleeO         dmee         deeez  df         ddfdnZeUddfddddej        ej        ffdoedp         dqdrdseeאdr                  diedjee         dkee         dleeO         dmee         deeez  df         ddfdt            ZdduZdeeed5         z           fdvZdwe defdxZ	 ddedededeeez           def
dyZ	 ddedededeeez           def
dzZdeez  ddfd{ZeUe	 ddedededededdfd|                        ZeUe	 ddedededededdfd                        ZeUemdededededend         f
d                        ZeUemdededededend         f
d                        ZeUemdeded~edend         fd                        Z	emdene
         fd            Zemdene
         fd            ZeU	 	 	 dʐded eאe         gdf         de$de%de%ddf
d            Z	 	 	 	 	 	 ddedee         dee         dee         dee         dee         dee         ddfdZeUddede$de%ddfd            Zemdedend         fd            Zemdedend         fd            ZeUemde'de'dene         fd                        Ze	 ddeddeedr                  de%dee         de fd            Zededdeej        e         z  ejz  de%dee         ddfd            Z edg          	 ddeddeeej        e         z  ejz           de%dee         dee          fd            Z xZS (  r   zPDF Generation classz**__z~~z--\z^\[([^][]+)\]\(([^()]+)\)(.*)$NTmmA4
DEPRECATED)enforce_complianceorientationunitr   font_cache_dirr   r   c                   |dk    r(t          j        dt          t                                 t	                                                       d| _        	 d| _        	 i | _        i | _	        i | _
        g | _        t                      | _        d| _        d| _        d| _        |                                  d| _        d| _        d| _        d| _        d| _        d| _        d| _        t3                      | _        d| _        g | _        d| _        d| _        d| _        i | _         d| _!        d| _"        i | _#        d	| _$        	 d
ddd| _%        tM          |          | _'        d| _(        d| _)        d| _*        d| _+        d| _,        d| _-        d| _.        d| _/        d| _0        | j1        | _2        | j3        | _4        | j5        | _6        d| _7        tq          ddd          | _9        d| j'        z  | _:        tv          j<        | _=        t}          || j'                  \  | _?        | _@        | A                    || j?        | j@                   | jB        | _C        d| j'        z  }d| _D        d| _E        d| _F        d| _G        | H                    ||           | jF        | jG        c| _D        | _E        |dz  | _I        | J                    dd|z             | K                    d           d| _L        d| _M        d| _N        d| _O        t          jQ        t          jS                  | _T        d| _U        g | _V        d| _W        d| _X        |rt          jZ        |          nd| _[        | j[        r| j[        j\        dk    r,| j[        j]        dk    r| ^                    d           d| _        | j[        j\        dk    r#| j[        j]        dv r| ^                    d           | j[        j\        dk    r%| j[        j]        dk    r| ^                    d           d| __        d| _`        t                      | _b        t          t                    | _e        d| _f        dS )ak  
        Args:
            orientation (str): possible values are "portrait" (can be abbreviated "P")
                or "landscape" (can be abbreviated "L"). Default to "portrait".
            unit (str, int, float): possible values are "pt", "mm", "cm", "in", or a number.
                A point equals 1/72 of an inch, that is to say about 0.35 mm (an inch being 2.54 cm).
                This is a very common unit in typography; font sizes are expressed in this unit.
                If given a number, then it will be treated as the number of points per unit.  (eg. 72 = 1 in)
                Default to "mm".
            format (str): possible values are "a3", "a4", "a5", "letter", "legal" or a tuple
                (width, height) expressed in the given unit. Default to "a4".
            font_cache_dir (Path or str): [**DEPRECATED since v2.5.1**] unused
        r   zV"font_cache_dir" parameter is deprecated since v2.5.1, unused and will soon be removed
stacklevelFr   NT   latin-1	helveticacouriertimes)arial
couriernewtimesnewroman    d   dashgapphaseg/$?gbX<@g      $@	fullwidthz1.3PDFAr'   1.4)r      z1.7   z2.0)gr   r   DeprecationWarningr3   super__init__single_resources_objectr   r   linksnamed_destinationsembedded_filesrj   image_cache	in_footer_in_unbreakable_lasthalias_nb_pages_anglexmp_metadatapage_durationpage_transitionallow_images_transparencyoversized_imagesoversized_images_ratior   struct_buildertoc_placeholder_outlinein_toc_rendering_toc_allow_page_insertion_toc_inserted_pages_output_intents	_sign_keytitlesection_title_stylescore_fonts_encodingfont_aliasesr   r   font_family
font_style	underlinestrikethroughfont_size_ptfont_stretchingchar_spacingcurrent_fontcurrent_font_is_set_on_pageDEFAULT_DRAW_COLOR
draw_colorDEFAULT_FILL_COLOR
fill_colorDEFAULT_TEXT_COLOR
text_colorpage_backgrounddictdash_pattern
line_widthrY   FILL	text_moder   dw_ptdh_pt_set_orientationcur_orientationdef_orientationxr   l_margint_marginset_marginsc_marginset_auto_page_breakset_display_mode
_page_modeviewer_preferencescompresspdf_versionr   nowr   utccreation_date_security_handler_fallback_font_ids_fallback_font_exact_matchrender_color_fontsrJ   coerce_complianceprofilepart_set_min_pdf_version_current_draw_context_record_text_quad_pointsr   _resource_catalogr   r   _text_quad_pointsbuffer)r   r   r   r   r   r   margin	__class__s          r&   r   zFPDF.__init__,  sn   , \))M6 #*,,    	',$	
 		 *,
  	
  	 68%<<$ #)-&HL&'#2449=.0 %).&#$ CE$(
:<!#, + !#$
 
 "$'' "#%" 	 ,1(111# aQa888$&.! "1!@!@
DJk4:tzBBB#3 $tv-  (((%}  q6z222k***.2 	 # %'/|HL'A'ADH-/*/'(, "%&8999 	
  	1'611d6F6Kq6P6P))%00016.'611d6F6Kv6U6U))%000'611d6F6Kq6P6P))%000?C"(-%2A2C2C :ET9J9J ,0r%   c                     | j         j        S N)rP  font_registryr   s    r&   fontsz
FPDF.fonts  s    %33r%   Fowner_passworduser_passwordencryption_methodpermissionsencrypt_metadatac                     | j         r,| j         j        dk    rt          d| j         j                   t	          | |||||          | _        dS )a  
        Activate encryption of the document content.

        Args:
            owner_password (str): mandatory. The owner password allows to perform any change on the document,
                including removing all encryption and access permissions.
            user_password (str): optional. If a user password is set, the content of the document will be encrypted
                and a password prompt displayed when a user opens the document.
                The document will only be displayed after either the user or owner password is entered.
            encryption_method (fpdf.enums.EncryptionMethod, str): algorithm to be used to encrypt the document.
                Defaults to RC4.
            permissions (fpdf.enums.AccessPermission): specify access permissions granted
                when the document is opened with user access. Defaults to ALL.
            encrypt_metadata (bool): whether to also encrypt document metadata (author, creation date, etc.).
                Defaults to False.
        r   z7Encryption is now allowed for documents compliant with )rZ  r[  
permissionr\  r^  N)rJ  rK  r`   labelrA   rE  )r   rZ  r[  r\  r]  r^  s         r&   set_encryptionzFPDF.set_encryption  ss    0  	 0 8F B B%b$JZJ`bb   "9)'"/-"
 "
 "
r%   textr   r   c                      | j         | g|R i |}|                                 5  |                    |           ddd           dS # 1 swxY w Y   dS )a8  
        Parse HTML and convert it to PDF.
        cf. https://py-pdf.github.io/fpdf2/HTML.html

        Args:
            text (str): HTML content to render
            image_map (function): an optional one-argument function that map `<img>` "src" to new image URLs
            li_tag_indent (int): [**DEPRECATED since v2.7.9**]
                numeric indentation of `<li>` elements - Set `tag_styles` instead
            dd_tag_indent (int): [**DEPRECATED since v2.7.9**]
                numeric indentation of `<dd>` elements - Set `tag_styles` instead
            table_line_separators (bool): enable horizontal line separators in `<table>`. Defaults to `False`.
            ul_bullet_char (str): bullet character preceding `<li>` items in `<ul>` lists.
                Can also be configured using the HTML `type` attribute of `<ul>` tags.
            li_prefix_color (tuple, str, fpdf.drawing.DeviceCMYK, fpdf.drawing.DeviceGray, fpdf.drawing.DeviceRGB): color for bullets
                or numbers preceding `<li>` tags. This applies to both `<ul>` & `<ol>` lists.
            heading_sizes (dict): [**DEPRECATED since v2.7.9**]
                font size per heading level names ("h1", "h2"...) - Set `tag_styles` instead
            pre_code_font (str): [**DEPRECATED since v2.7.9**]
                font to use for `<pre>` & `<code>` blocks - Set `tag_styles` instead
            warn_on_tags_not_matching (bool): control warnings production for unmatched HTML tags. Defaults to `True`.
            tag_indents (dict): [**DEPRECATED since v2.8.0**]
                mapping of HTML tag names to numeric values representing their horizontal left indentation. - Set `tag_styles` instead
            tag_styles (dict[str, fpdf.fonts.TextStyle]): mapping of HTML tag names to `fpdf.fonts.TextStyle` or `fpdf.fonts.FontFace` instances
        N)HTML2FPDF_CLASSlocal_contextfeed)r   rc  r   r   html2pdfs        r&   
write_htmlzFPDF.write_html  s    4 (4'>t>>>v>>!! 	  	 MM$	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   A		AAversionc                 :    t          | j        |          | _        d S rV  )maxrA  )r   rj  s     r&   rM  zFPDF._set_min_pdf_version   s    t/99r%   c                 h    | j         }| j        r|dz  }| j        r|dz  }t          j        |          S )zIThe current text emphasis: bold, italics, underline and/or strikethrough.SU)r  r   r  rW   rI  )r   r  s     r&   emphasiszFPDF.emphasis#  sE     _
 	#J> 	#J":...r%   c                 4    | j         d uo| j         j        dk    S )NTTF)r$  typerX  s    r&   is_ttf_fontzFPDF.is_ttf_font-  s      ,P1B1G51PPr%   c                     | j         S rV  )r>  rX  s    r&   	page_modezFPDF.page_mode1  s
    r%   rv  c                     t          j        |          | _        | j        t           j        k    r|                     d           d S | j        t           j        k    r|                     d           d S d S )N1.61.5)rQ   rI  r>  USE_ATTACHMENTSrM  USE_OC)r   rv  s     r&   rv  zFPDF.page_mode5  sn    "/)44?h666%%e,,,,,_//%%e,,,,, 0/r%   c                 4    | j                                         S rV  )r  valuesrX  s    r&   output_intentszFPDF.output_intents=  s    #**,,,r%   subtypeoutput_condition_identifieroutput_conditionregistry_namedest_output_profileinfoc                     |j         | j        v rt          d|j         z   dz             t          ||||||          | j        |j         <   |                     d           dS )aR  
        Adds desired Output Intent to the Output Intents array:

        Args:
            subtype (OutputIntentSubType, required): PDFA, PDFX or ISOPDF
            output_condition_identifier (str, required): see the Name in
                https://www.color.org/registry.xalter
            output_condition (str, optional): see the Definition in
                https://www.color.org/registry.xalter
            registry_name (str, optional): "https://www.color.org"
            dest_output_profile (PDFICCProfile, required/optional):
                PDFICCProfile | None # (required  if
                output_condition_identifier does not specify a standard
                production condition; optional otherwise)
            info (str, required/optional see dest_output_profile): human
                readable description of profile
        zadd_output_intent: subtype 'z' already exists.r   N)valuer  
ValueErrorrz   rM  )r   r  r  r  r  r  r  s          r&   add_output_intentzFPDF.add_output_intentA  s    4 =D000.>ATT   /E'/
 /
W]+ 	!!%(((((r%   c                 0    | j         | j        z
  | j        z
  S )zT
        Effective page width: the page width minus its horizontal margins.
        )wr8  r_marginrX  s    r&   epwzFPDF.epwi      
 v%55r%   c                 0    | j         | j        z
  | j        z
  S )zT
        Effective page height: the page height minus its vertical margins.
        )hr9  b_marginrX  s    r&   ephzFPDF.ephp  r  r%   c                 *    t          | j                  S )a%  
        Returns the total pages of the document, at the time it is called.

        Do not use this in `fpdf.fpdf.FPDF.header()` or `fpdf.fpdf.FPDF.footer()`,
        as its value will not be the total page count.
        Uses `{nb}` instead, _cf._ `fpdf.fpdf.FPDF.alias_nb_pages()`.
        )lenr   rX  s    r&   pages_countzFPDF.pages_countw  s     4:r%   rS  c                 h    |                      ||           |                     | j        |           dS )z
        Sets the document right, left, top & bottom margins to the same value.

        Args:
            margin (float): margin in the unit specified to FPDF constructor
        N)r:  r<  auto_page_breakr   rS  s     r&   
set_marginzFPDF.set_margin  s9     	(((  !5v>>>>>r%   lefttoprightc                     |                      |           | j        |k     s| j        | j        k    r|| _        || _        |dk    r|}|| _        dS )a  
        Sets the document left, top & optionally right margins to the same value.
        By default, they equal 1 cm.
        Also sets the current FPDF.y on the page to this minimum vertical position.

        Args:
            left (float): left margin in the unit specified to FPDF constructor
            top (float): top margin in the unit specified to FPDF constructor
            right (float): optional right margin in the unit specified to FPDF constructor
        r  N)set_left_marginr   r9  r  )r   r  r  r  s       r&   r:  zFPDF.set_margins  sX     	T"""6C<<46T]22DFB;;Er%   c                 X    | j         |k     s| j         | j        k    r|| _         || _        dS )z
        Sets the document left margin.
        Also sets the current FPDF.x on the page to this minimum horizontal position.

        Args:
            margin (float): margin in the unit specified to FPDF constructor
        N)r7  r8  r  s     r&   r  zFPDF.set_left_margin  s/     6F??df55DFr%   c                     || _         dS )z
        Sets the document top margin.

        Args:
            margin (float): margin in the unit specified to FPDF constructor
        N)r9  r  s     r&   set_top_marginzFPDF.set_top_margin       r%   c                     || _         dS )z
        Sets the document right margin.

        Args:
            margin (float): margin in the unit specified to FPDF constructor
        N)r  r  s     r&   set_right_marginzFPDF.set_right_margin  r  r%   r   autoc                 J    || _         || _        | j        | j        z
  | _        dS )a  
        Set auto page break mode, and optionally the bottom margin that triggers it.
        By default, the mode is on and the bottom margin is 2 cm.

        Detailed documentation on page breaks: https://py-pdf.github.io/fpdf2/PageBreaks.html

        Args:
            auto (bool): enable or disable this mode
            margin (float): optional bottom margin (distance from the bottom of the page)
                in the unit specified to FPDF constructor
        N)r  r  r  page_break_trigger)r   r  rS  s      r&   r<  zFPDF.set_auto_page_break  s*     &*%)-$-)?r%   c                 d    | j         t          j        k    r| j        | j        fn| j        | j        fS )z<Return a pair (width, height) in points units (1/72 of inch))r6  rR   PORTRAITr2  r3  rX  s    r&   default_page_dimensionszFPDF.default_page_dimensions  s7    
 #'??? Z$$*dj)	
r%   page_width_ptpage_height_ptc                 L   t          j        |          | _        | j        t           j        u r|| _        || _        n|| _        || _        | j        | j        z  | _        | j        | j        z  | _        t          | d          r"| 
                    | j        | j                   d S d S )Nr  )rR   rI  r5  r  w_pth_ptr   r  r  r   r<  r  r  )r   r   r  r  s       r&   r4  zFPDF._set_orientation  s      /5kBB?#;;;%DI&DII&DI%DITV#TV#4*++ 	J$$T%94=IIIII	J 	Jr%   r   zoomlayoutc                    |t           v st          |t                    s|| _        n|dk    rt	          d|           t          |t
                    r	|| _        dS t                              t          |                    }|t          |          t          v r	|| _        dS 	 t          j	        t          |                    | _        dS # t          t          f$ r}t	          d|           |d}~ww xY w)a  
        Defines the way the document is to be displayed by the viewer.

        It allows to set the zoom level: pages can be displayed entirely on screen,
        occupy the full width of the window, use the real size,
        be scaled by a specific zooming factor or use the viewer default (configured in its Preferences menu).

        The page layout can also be specified: single page at a time, continuous display, two columns or viewer default.

        Args:
            zoom: either "fullpage", "fullwidth", "real", "default",
                or a number indicating the zooming factor to use, interpreted as a percentage.
                The zoom level set by default is "default".
            layout (fpdf.enums.PageLayout, str): allowed layout aliases are "single", "continuous", "two" or "default",
                meaning to use the viewer default mode.
                The layout set by default is "continuous".
        r   zIncorrect zoom display mode: NzIncorrect layout display mode: )ry   r   r   	zoom_moder]   rP   page_layoutr   r   rI  r  	TypeError)r   r  r  alias_layoutexcs        r&   r=  zFPDF.set_display_mode  s   , <z$'<'<!DNNY F F FGGGfj)) 	%D *--c&kk::L'3v;;.+H+H#/   '1'8V'E'ED$$$"I.   'B&BB s   &&C C7C22C7use_shaping_enginefeatures	directionscriptlanguagec                    |s	d| _         dS 	 ddl}n"# t          $ r}t          d          |d}~ww xY w|r$t	          |t
                    st          d          |si }d}|rTt	          |t                    r|nt          j        |          }|t          j        t          j	        fvrt          d          d||||ddd| _         dS )a<  
        Enable or disable text shaping engine when rendering text.
        If features, direction, script or language are not specified the shaping engine will try
        to guess the values based on the input text.

        Args:
            use_shaping_engine: enable or disable the use of the shaping engine to process the text
            features: a dictionary containing 4 digit OpenType features and whether each feature
                should be enabled or disabled
                example: features={"kern": False, "liga": False}
            direction: the direction the text should be rendered, either "ltr" (left to right)
                or "rtl" (right to left).
            script: a valid OpenType script tag like "arab" or "latn"
            language: a valid OpenType language tag like "eng" or "fra"
        Nr   ziThe uharfbuzz package could not be imported, but is required for text shaping. Try: pip install uharfbuzzz=Features must be a dictionary. See text shaping documentationzPFPDF2 only accept ltr (left to right) or rtl (right to left) directions for now.T)r  r  r  r  r  fragment_directionparagraph_direction)
text_shaping	uharfbuzzImportErrorr]   r   r-  rV   rI  LTRRTL)	r   r  r  r  r  r  r  r  text_directions	            r&   set_text_shapingzFPDF.set_text_shaping  s6   . " 	 $DF	 	 	 	{ 	  	Jx66 	O    	H  		 i775		"))44 
 m&79J%KKK#f  
 #' ' "&#'
 
s    
1,1c                     | j         S rV  )_page_layoutrX  s    r&   r  zFPDF.page_layouta  s      r%   r  c                     |rt          j        |          nd | _        | j        t           j        t           j        fv r|                     d           d S d S )Nry  )rP   rI  r  TWO_PAGE_LEFTTWO_PAGE_RIGHTrM  )r   r  s     r&   r  zFPDF.page_layoute  s[    >ISJ-k:::t!9:;T UUU%%e,,,,, VUr%   r@  c                     || _         dS )a  
        Activates or deactivates page compression.

        When activated, the internal representation of each page is compressed
        using the zlib/deflate method (FlateDecode), which leads to a compression ratio
        of about 2 for the resulting document.

        Page compression is enabled by default.

        Args:
            compress (bool): indicates if compression should be enabled
        N)r@  )r   r@  s     r&   set_compressionzFPDF.set_compressionk  s     !r%   r  c                     || _         dS )aA  
        Defines the title of the document.

        Most PDF readers will display it when viewing the document.
        There is also a related `fpdf.prefs.ViewerPreferences` entry:

            pdf.viewer_preferences = ViewerPreferences(display_doc_title=True)

        Args:
            title (str): the title
        Nr  )r   r  s     r&   	set_titlezFPDF.set_titlez  s     


r%   langc                 F    || _         |r|                     d           dS dS )a  
        A language identifier specifying the natural language for all text in the document
        except where overridden by language specifications for structure elements or marked content.
        A language identifier can either be the empty text string, to indicate that the language is unknown,
        or a Language-Tag as defined in RFC 3066, "Tags for the Identification of Languages".

        Args:
            lang (str): the document main language
        r   N)r  rM  )r   r  s     r&   set_langzFPDF.set_lang  s7     	 	-%%e,,,,,	- 	-r%   subjectc                     || _         dS )zz
        Defines the subject of the document.

        Args:
            subject (str): the document main subject
        N)r  )r   r  s     r&   set_subjectzFPDF.set_subject  s     r%   authorc                     || _         dS )zt
        Defines the author of the document.

        Args:
            author(str): the name of the author
        N)r  )r   r  s     r&   
set_authorzFPDF.set_author  s     r%   keywordsc                     || _         dS )z
        Associate keywords with the document

        Args:
            keywords (str): a space-separated list of words
        N)r  )r   r  s     r&   set_keywordszFPDF.set_keywords  s     !r%   creatorc                     || _         dS )z
        Defines the creator of the document.
        This is typically the name of the application that generates the PDF.

        Args:
            creator (str): name of the PDF creator
        N)r  )r   r  s     r&   set_creatorzFPDF.set_creator  s     r%   producerc                     || _         dS )zProducer of documentN)r  )r   r  s     r&   set_producerzFPDF.set_producer  s     r%   datec                     | j         rt          d          t          |t                    st	          dt          |                     |j        s|                                }|| _        dS )z:Sets Creation of Date time, or current time if None given.zB.set_creation_date() must always be called before .sign*() methodsz#date should be a datetime but is a N)	r  r]   r   r   r  rs  tzinfo
astimezonerD  )r   r  s     r&   set_creation_datezFPDF.set_creation_date  sz    > 	T   $)) 	PN$t**NNOOO{ 	%??$$D!r%   r  c                 |    d|d d         v rt          d          || _        |r|                     d           d S d S )Nz	<?xpacket2   z@fpdf2 already performs XMP metadata wrapping in a <?xpacket> tagr   )r  r  rM  )r   r  s     r&   set_xmp_metadatazFPDF.set_xmp_metadata  sa    ,ss+++R   ) 	-%%e,,,,,	- 	-r%   optr  r  c                     t          j        dt          t                                 |dk    rt	          d| d          || _        dS )a  
        Defines a document option.

        Args:
            opt (str): name of the option to set
            value (str) option value

        .. deprecated:: 2.4.0
            Simply set the `FPDF.core_fonts_encoding` property as a replacement.
        zset_doc_option() is deprecated since v2.4.0 and will be removed in a future release. Simply set the `.core_fonts_encoding` property as a replacement.r   r  zUnknown document option ""N)r   r   r   r3   r]   r  )r   r  r  s      r&   set_doc_optionzFPDF.set_doc_option  sg     	S &((	
 	
 	
 	
 ''' BC B B BCCC#(   r%   image_filterc                     |t           vr-t          d| dd                    t                                t          t          |          | j        _        |dk    r|                     d           dS dS )a  
        Args:
            image_filter (str): name of a the image filter to use
                when embedding images in the document, or "AUTO",
                meaning to use the best image filter given the images provided.
                Allowed values: `FlateDecode` (lossless zlib/deflate compression),
                `DCTDecode` (lossy compression with JPEG)
                `LZWDecode` (Lempel-Ziv-Welch aka LZW compression)
                and `JPXDecode` (lossy compression with JPEG2000).

        [**NEW in 2.8.4**] Note that, when using `LZWDecode`, having NumPy installed
        will improve performances, reducing execution time.
        'z4' is not a supported image filter - Allowed values: r   	JPXDecodery  N)ro   r  joinr   rk   r  r  rM  )r   r  s     r&   set_image_filterzFPDF.set_image_filter  s     666IL I I&(gg.E&F&FI I   )-[,(G(G%;&&%%e,,,,, '&r%   {nb}aliasc                     || _         dS )a5  
        Defines an alias for the total number of pages.
        It will be substituted as the document is closed.

        This is useful to insert the number of pages of the document
        at a time when this number is not known by the program.

        This substitution can be disabled for performances reasons, by calling `alias_nb_pages(None)`.

        Args:
            alias (str): the alias. Defaults to `"{nb}"`.

        Notes
        -----

        When using this feature with the `FPDF.cell` / `FPDF.multi_cell` methods,
        or the `.underline` / `.strikethrough` attributes of `FPDF` class,
        the width of the text rendered will take into account the alias length,
        not the length of the "actual number of pages" string,
        which can causes slight positioning differences.
        N)str_alias_nb_pages)r   r  s     r&   r	  zFPDF.alias_nb_pages  s    , #(r%   label_stylelabel_prefixlabel_startc                 4   d}| j         | j        v r%| j        | j                                                  }n2| j         dk    r'| j        | j         dz
                                           }d}|s|s|r|rU||                                }||                                }|'| j        r| j        j        s|                                }|rt          j	        |d          nd}t          |||          }| j        | j                                      ||           dS )z
        Enable `fpdf.output.PDFPageLabel` to be inserted on every page.
        This will be displayed by some PDF readers to identify pages.
        Nr'   Tcase_sensitive)r   r   get_page_label	get_style
get_prefixr  r   	get_startrO   rI  r~   set_page_label)r   r  r  r  current_page_labelnew_page_labels         r&   r  zFPDF.set_page_label  sH    "9
""!%DI!6!E!E!G!GY]]!%DIM!:!I!I!K!K 	R, 	R+ 	R! A&"4">">"@"@K'#5#@#@#B#BL&( '-1-A-T ' #5">">"@"@K %k$GGGG 
 *+|[QQN
49,,-?PPPPPr%   r   sameduration
transitionc	           	      <	   | j         rt          d          d| _        | j        }	| j        }
| j        }| j        }| j        }| j        }| j	        }| j
        }| j        }| j        }| j        o| j        o| j        | j        j        k    }| j        dk    r| j        r|r|                                  | j        dk    rdn#| j        | j                                                 }d}|s|s|r+|rt+          j        |d          nd}t/          |||          }|                     ||||p| j        |p| j        |                                             | j        | j                                     ||           | j        rt=          | j        t>                    ra | j         | j          | !                    dd| j"        | j#        d	           t=          |tH          tJ          f          sJ  | j         |j&          n(| '                    | j        dd| j"        | j#                   | (                    d
           || _        | (                    || j)        z  dd           |	r| *                    |	|
|           || _        || j+        k    r;|9| (                    |,                                -                                           || _        || j.        k    r;|9| (                    |,                                /                                           || _	        | j        r| j        r| 0                                 | j        |k    r(|| _        | (                    || j)        z  dd           |	r| *                    |	|
|           | j        |k    rB|@|| _        | (                    |,                                -                                           | j        |k    rB|@|| _        | (                    |,                                /                                           || _	        |dk    r| 1                    |           |dk    r| 2                    |           |tg          ddd          k    r+| 4                    |d         |d         |d                    dS dS )u  
        Adds a new page to the document.
        If a page is already present, the `FPDF.footer()` method is called first.
        Then the page  is added, the current position is set to the top-left corner,
        with respect to the left and top margins, and the `FPDF.header()` method is called.

        Args:
            orientation (str): "portrait" (can be abbreviated "P")
                or "landscape" (can be abbreviated "L"). Default to "portrait".
            format (str): "a3", "a4", "a5", "letter", "legal" or a tuple
                (width, height). Default to "a4".
            same (bool): indicates to use the same page format as the previous page.
                Default to False.
            duration (float): optional page’s display duration, i.e. the maximum length of time,
                in seconds, that the page is displayed in presentation mode,
                before the viewer application automatically advances to the next page.
                Can be configured globally through the `.page_duration` FPDF property.
                As of june 2021, onored by Adobe Acrobat reader, but ignored by Sumatra PDF reader.
            transition (Transition child class): optional visual transition to use when moving
                from another page to the given page during a presentation.
                Can be configured globally through the `.page_transition` FPDF property.
                As of june 2021, onored by Adobe Acrobat reader, but ignored by Sumatra PDF reader.
            label_style (str or PageLabelStyle): Defines the numbering style for the numeric portion of each
                page label. Possible values are:
                - "D": Decimal Arabic numerals.
                - "R": Uppercase Roman numerals.
                - "r": Lowercase Roman numerals.
                - "A": Uppercase letters (A to Z for the first 26 pages, followed by AA to ZZ, etc.).
                - "a": Lowercase letters (a to z for the first 26 pages, followed by aa to zz, etc.).
            label_prefix (str): Prefix string applied to the page label, preceding the numeric portion.
            label_start (int): Starting number for the first page of a page label range.
        zCA page cannot be added on a closed document, after calling output()Fr   NTr  )new_pageFstylez2 J.2f wr   r   r   r   r   )5rR  r]   r%  r  rp  r!  r/  r'  r)  r+  r"  r#  r.  r  r  r   r  r   _render_footerr   r  rO   rI  r~   
_beginpager  r  _has_next_pager  r,  r   tupleset_fill_colorrectr  r  r=   r<   	colors255image_outr   set_fontr&  	serializeupperr(  r   headerset_stretchingset_char_spacingr-  _write_dash_pattern)r   r   r   r  r  r  r  r  r  familyrp  sizelwdcfctc
stretchingr#  r.  in_toc_extra_pager  r  s                         r&   add_pagezFPDF.add_page>  s   V ; 	U   ,1(!= ____)
(( ! <.<	D0;; 	
 9q==$"7=;L=!!! INNDD
49(=(L(L(N(N 	  	R, 	R+ 	R %k$GGGG 
 *+|[QQN 	**.$.,,... 	 	
 	
 	
 	
49,,-?PPP 	$.66 ##T%9::		!Qc	:::!"y*&=>>>>>##R\222

(FF   			%		R$&[(((()))  	2MM&(D111 (((R^IIbllnn**,,---(((R^IIbllnn**,,--- % 	$*H 	KKMMM?b   DOIIdf,,,,--- 	2MM&(D111?b  R^ DOIIbllnn**,,---?b  R^ DOIIbllnn**,,---
+++1!!,///4QAQ77777$$V$l5&9<;P     87r%   c                    d| _         | j        r(|                                  |                                  |                                  | j        r(|                                  |                                  d| _         d S )NTF)r  r  _push_local_stack_start_local_contextfooter_end_local_context_pop_local_stackrX  s    r&   r  zFPDF._render_footer  s     	( ""$$$%%''' 	$##%%%!!###r%   r
  c                    | xj         dz  c_         | j        r5| j        r.| xj        dz  c_        t	          | j                  dz   | _         d}|rKt          t                      ||| j                   }|| j        | j         <   |r|                     d           n| j        | j                  }| j	        | _
        | j        | _        d| _        d| _        d| _        |r|s|rt!          d| d	| d
|           nF|rt#          || j                  n| j        | j        f\  }}	|                     |p| j        ||	           |                    | j        | j                   d S )Nr'   T)contentsr  r  indexry  r   r   r   zInconsistent parameters: same=z but orientation=z format=)r   r  r  r  r  r   r}   	bytearrayrM  r8  r7  r9  r   r  r"  r#  r  r   r   r2  r3  r4  r6  set_dimensionsr  r  )
r   r   r   r  r  r  r
  r   r  r  s
             r&   r  zFPDF._beginpage  s    			Q		  	T%C 	$$)$$DJ!+DIH 	)"!%i	  D %)DJty! 1))%000:di(D" 	 f  iTiiKiiagii   4:W///
DJ?W *M> !!3t3]N   	DIty11111r%   c                     dS )a  
        Header to be implemented in your own inherited class

        This is automatically called by `FPDF.add_page()`
        and should not be called directly by the user application.
        The default implementation performs nothing: you have to override this method
        in a subclass to implement your own rendering logic.

        Note that header rendering can have an impact on the initial
        (x,y) position when starting to render the page content.
        Nr$   rX  s    r&   r  zFPDF.header        r%   c                     dS )al  
        Footer to be implemented in your own inherited class.

        This is automatically called by `FPDF.add_page()` and `FPDF.output()`
        and should not be called directly by the user application.
        The default implementation performs nothing: you have to override this method
        in a subclass to implement your own rendering logic.
        Nr$   rX  s    r&   r,  zFPDF.footer!  r5  r%   c                     | j         S )zGet the current page numberr   rX  s    r&   page_nozFPDF.page_no+  s
    yr%   c                 J    | j         | j                                                 S )z
        Return the current page `fpdf.output.PDFPageLabel`.
        This will be displayed by some PDF readers to identify pages.
        `FPDF.set_page_label()` needs to be called first for those to be inserted.
        )r   r   	get_labelrX  s    r&   r  zFPDF.get_page_label/  s     z$)$..000r%   rgbc                     t          |||          }|| j        k    rR|| _        | j        dk    rB|                     | j                                                                                   dS dS dS )a,  
        Defines the color used for all stroking operations (lines, rectangles and cell borders).
        Accepts either a single greyscale value, 3 values as RGB components, a single `#abc` or `#abcdef` hexadecimal color string,
        or an instance of `fpdf.drawing.DeviceCMYK`, `fpdf.drawing.DeviceRGB` or `fpdf.drawing.DeviceGray`.
        The method can be called before the first page is created and the value is retained from page to page.

        Args:
            r (int, tuple, fpdf.drawing.DeviceGray, fpdf.drawing.DeviceRGB): if `g` and `b` are given, this indicates the red component.
                Else, this indicates the grey level. The value must be between 0 and 255.
            g (int): green component (between 0 and 255)
            b (int): blue component (between 0 and 255)
        r   N)r@   r'  r   r  r  r  )r   r<  r=  r>  r'  s        r&   set_draw_colorzFPDF.set_draw_color7  ~     -Q155
(((DOy1}}		O--//5577     )(}r%   c                     t          |||          }|| j        k    rR|| _        | j        dk    rB|                     | j                                                                                   dS dS dS )a/  
        Defines the color used for all filling operations (filled rectangles and cell backgrounds).
        Accepts either a single greyscale value, 3 values as RGB components, a single `#abc` or `#abcdef` hexadecimal color string,
        or an instance of `fpdf.drawing.DeviceCMYK`, `fpdf.drawing.DeviceRGB` or `fpdf.drawing.DeviceGray`.
        The method can be called before the first page is created and the value is retained from page to page.

        Args:
            r (int, tuple, fpdf.drawing.DeviceGray, fpdf.drawing.DeviceRGB): if `g` and `b` are given, this indicates the red component.
                Else, this indicates the grey level. The value must be between 0 and 255.
            g (int): green component (between 0 and 255)
            b (int): blue component (between 0 and 255)
        r   N)r@   r)  r   r  r  r   )r   r<  r=  r>  r)  s        r&   r  zFPDF.set_fill_colorN  rA  r%   c                 2    t          |||          | _        dS )a  
        Defines the color used for text.
        Accepts either a single greyscale value, 3 values as RGB components, a single `#abc` or `#abcdef` hexadecimal color string,
        or an instance of `fpdf.drawing.DeviceCMYK`, `fpdf.drawing.DeviceRGB` or `fpdf.drawing.DeviceGray`.
        The method can be called before the first page is created and the value is retained from page to page.

        Args:
            r (int, tuple, fpdf.drawing.DeviceGray, fpdf.drawing.DeviceRGB): if `g` and `b` are given, this indicates the red component.
                Else, this indicates the grey level. The value must be between 0 and 255.
            g (int): green component (between 0 and 255)
            b (int): blue component (between 0 and 255)
        N)r@   r+  )r   r<  r=  r>  s       r&   set_text_colorzFPDF.set_text_colore  s    4 2!Q::r%   s
normalizedmarkdownc                     | j         st          d          |r|n|                     |          }t          d |                     ||          D                       S )a&  
        Returns the length of a string in user unit. A font must be selected.
        The value is calculated with stretching and spacing.

        Note that the width of a cell has some extra padding added to this width,
        on the left & right sides, equal to the .c_margin property.

        Args:
            s (str): the string whose length is to be computed.
            normalized (bool): whether normalization needs to be performed on the input string.
            markdown (bool): indicates if basic markdown support is enabled
        3No font set, you need to call set_font() beforehandc              3   >   K   | ]}|                                 V  d S rV  )	get_width.0frags     r&   	<genexpr>z(FPDF.get_string_width.<locals>.<genexpr>  s=       
 
!%DNN
 
 
 
 
 
r%   )r  r]   normalize_textsum_preload_bidirectional_text)r   rE  rF  rG  s       r&   get_string_widthzFPDF.get_string_width  sy      	W UVVV7AA!4!4Q!7!7 
 
)-)I)I!X)V)V
 
 
 
 
 	
r%   widthc                     || j         k    r5|| _         | j        dk    r%|                     || j        z  dd           dS dS dS )aF  
        Defines the line width of all stroking operations (lines, rectangles and cell borders).
        By default, the value equals 0.2 mm.
        The method can be called before the first page is created and the value is retained from page to page.

        Args:
            width (float): the width in user unit
        r   r  r  N)r/  r   r  r   )r   rT  s     r&   set_line_widthzFPDF.set_line_width  sZ     DO###DOy1}}		UTV^333344444 $#}r%   
backgroundc                    t          |t          t          j        t          t
          t          t          d          f          r,t          |t
                    r|j        | _	        dS || _	        dS t          dt          |                     )aD  
        Sets a background color or image to be drawn every time `FPDF.add_page()` is called, or removes a previously set background.
        The method can be called before the first page is created and the value is retained from page to page.

        Args:
            background: either a string representing a file path or URL to an image,
                an io.BytesIO containing an image as bytes, an instance of `PIL.Image.Image`, drawing.DeviceRGB
                or a RGB tuple representing a color to fill the background with or `None` to remove the background
        Nzkbackground must be of type str, io.BytesIO, PIL.Image.Image, drawing.DeviceRGB, tuple or None
        got: )r   r   ioBytesIOr   r=   r  rs  r  r,  r  )r   rW  s     r&   set_page_backgroundzFPDF.set_page_background  s     bj%E4::N
 
 	 *i00 2'1';$$$'1$$$#:# #  r%   debug_streamc              #     K   | j         t          d          t                      }|| _         	 |V  d| _         n# d| _         w xY w|                                 }| j        t          | j        | j                  | j        | j	        |f} |j
        | }| j                            || j                   |                     |           |                     d           dS )z
        Create a context for drawing paths on the current page.

        If this context manager is called again inside of an active context, it will
        raise an exception, as base drawing contexts cannot be nested.
        N9cannot create a drawing context while one is already openr   )rN  r]   r5   _current_graphic_stylerP  r>   r7  r   r   r  renderindex_stream_resourcesr   r  rM  )r   r\  contextstarting_stylerender_argsrendereds         r&   drawing_contextzFPDF.drawing_context  s       %1K   !""%,"	.MMM)-D&&D&----4466"$&$&!!FF
 "7>;/ 	55h	JJJ 			(!!%(((((	   ; 	Ashadingc              #   @  K   | j                             t          j        || j                   |                                }| j                             t          j        || j                  }|                     d| d           	 dV  | j        J |                     | j        	                                
                                           dS # | j        J |                     | j        	                                
                                           w xY w)zS
        Create a context for using a shading pattern on the current page.
        z/Pattern cs /z scnN)rP  addrT   SHADINGr   get_patternPATTERNr  r'  r  r   )r   rh  patternpattern_names       r&   use_patternzFPDF.use_pattern  s      	""?#:GTYOOO%%''-11#Wdi
 
 			4,444555	;EEE?...IIdo//117799::::: ?...IIdo//117799::::s   C A	Dc                 L   t                      }| j        |_        | j        |_        | j        | j        k    r| j        |_        | j        | j	        k    r| j        |_        | j
        }|d         dk    r|d         dk    r|d         |d         fnd }||_        |d         |_        |S )Nr   r   r   r   )r7   r  allow_transparencyr/  stroke_widthr'  r&  stroke_colorr)  r(  r.  stroke_dash_patternstroke_dash_phase)r   gs	dash_infor.  s       r&   r_  zFPDF._current_graphic_style  s    __ $ >
 /?d555"oBO?d555 OBM%	  A%%)E*:a*?*? v	% 011 	 ".(1	r%   r7  r   
paint_rulec              #      K   |                                  5 }t          ||          }||j        _        |V  |                    |           ddd           dS # 1 swxY w Y   dS )a  
        Create a path for appending lines and curves to.

        Args:
            x (float): Abscissa of the path starting point
            y (float): Ordinate of the path starting point
            paint_rule (PathPaintRule): Optional choice of how the path should
                be painted. The default (AUTO) automatically selects stroke/fill based
                on the path style settings.
        )r7  r   N)rf  r8   r  ry  add_item)r   r7  r   ry  r\  ctxtpaths          r&   new_pathzFPDF.new_path  s      $ !!## 	 ta(((D$.DJ!JJJMM$		  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   7AA"Ar}  copyc                     |                                  5 }|                    ||           ddd           dS # 1 swxY w Y   dS )a  
        Add a pre-constructed path to the document.

        Args:
            path (drawing.PaintedPath): the path to be drawn.
            copy (bool): if true (the default), the path will be copied before being
                added. This prevents modifications to a referenced object from
                "retroactively" altering its style/shape and should be disabled with
                caution.
        N)rf  r{  )r   r}  r\  r  r|  s        r&   	draw_pathzFPDF.draw_path0  s      !!## 	&tMM$%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s   9= =r   r   r   c                    t          |t          t          f          r|dk    st          d          t          |t          t          f          r|dk    st          d          t          |t          t          f          r|dk    st          d          t	          t          |          t          |          t          |                    }|| j        k    r || _        |                     |||           dS dS )a  
        Set the current dash pattern for lines and curves.

        Args:
            dash (float): The length of the dashes in current units.

            gap (float): The length of the gaps between dashes in current units.
                If omitted, the dash length will be used.

            phase (float): Where in the sequence to start drawing.

        Omitting 'dash' (= 0) resets the pattern to a solid line.
        r   z.Dash length must be zero or a positive number.z-gap length must be zero or a positive number.z(Phase must be zero or a positive number.r   N)r   r   r   r  r-  r.  r  )r   r   r   r   rn  s        r&   set_dash_patternzFPDF.set_dash_patternC  s      4#u.. 	O4199MNNN3e-- 	N#((LMMM53,// 	IEQJJGHHH$(t%**E%LL%
 %
 %
 d''' 'D$$T366666 ('r%   c                     |rF|r(d|| j         z  dd|| j         z  dd|| j         z  dd}nd|| j         z  dd|| j         z  dd}nd}|                     |           d S )N[z.3f z] z dz[] 0 d)r   r  )r   r   r   r   dstrs        r&   r  zFPDF._write_dash_patternb  s     	 FX4$&=XXXsTV|XXX5$&=XXXXE4$&=EEEtvEEEED		$r%   c              #      K   | j         t          d          t                      }|| _         	 |V  d| _         n# d| _         w xY w|                     d           dS )zq
        Create a context for drawing paths for type 3 font glyphs, without writing on the current page.
        Nr^  r   )rN  r]   r5   rM  )r   rb  s     r&   glyph_drawing_contextzFPDF.glyph_drawing_contextl  s       %1K   !""%,"	.MMM)-D&&D&----!!%(((((rg  r   r   c                 H   d}|                                  5 }|                    |           t                      }| j        t	          dd          dd|f} |j        | }| j                            |          D ]\  }}|t          j        k    r'|j	        
                    t          |                     |t          j        k    r|j        
                    |           |t          j        k    r|j        
                    |           	 ddd           n# 1 swxY w Y   |S )z=
        Add a pre-constructed path to the document.
        r   r   r'   N)r  r{  r7   rP  r>   r`  scan_streamrT   X_OBJECTimages_usedrj  r   EXT_G_STATEgraphics_style_usedrm  patterns_used)	r   r}  r   output_streamr|  rc  rd  resource_typeresource_ids	            r&   draw_vector_glyphzFPDF.draw_vector_glyph  sj     '')) 	8TMM$*__N&aK (DK5M.2.D.P.P/ / 8 8*{ !O$<<<$(([)9)9::: O$???,00=== O$;;;&**;7778	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	80 s   C3DDDx1y1x2y2c           
          |                      || j        z  dd| j        |z
  | j        z  dd|| j        z  dd| j        |z
  | j        z  dd           dS )a  
        Draw a line between two points.

        Args:
            x1 (float): Abscissa of first point
            y1 (float): Ordinate of first point
            x2 (float): Abscissa of second point
            y2 (float): Ordinate of second point
        r  r   m  l SNr  r   r  )r   r  r  r  r  s        r&   linez	FPDF.line  s     			DF{R 0 0$&2+!7R 0 0TVR 0 0tv%/0 0 0	
 	
 	
 	
 	
r%   
point_listfillpolygonr  c                    |r(t          j        dt          t                                 |r|t          j        }nI|t	          j        |          nt          j        }|r%|t          j        k    rt          d| d|           d}|D ]G}| 	                    |d         | j
        z  dd	| j        |d
         z
  | j
        z  dd	|            d}H|r| 	                    d           | 	                    d	|j                    dS )a  
        Draws lines between two or more points.

        Args:
            point_list (list of tuples): List of Abscissa and Ordinate of
                                        segments that should be drawn
            fill (bool): [**DEPRECATED since v2.5.4**] Use `style="F"` or `style="DF"` instead
            polygon (bool): If true, close path before stroking, to fill the inside of the polyline
            style (fpdf.enums.RenderStyle, str): Optional style of rendering. Possible values are:

            * `D` or None: draw border. This is the default value.
            * `F`: fill
            * `DF` or `FD`: draw and fill
        zP"fill" parameter is deprecated since v2.5.4, use style="F" or style="DF" insteadr   Nz"Conflicting values provided: fill=z	 & style=mr   r  r  r'   lz h)r   r   r   r3   rU   DFrI  Dr  r  r   r  operator)r   r  r  r  r  r  points          r&   polylinezFPDF.polyline  sO   ,  	M: #*,,     	EMNEE161BK&u---E .. OOOOO    	 	EII8df$XXXDFU1X,=+GXXXhXX   HH 	IIdOOO		&en&&'''''r%   c                 8    |                      ||d|           dS )a  
        Outputs a polygon defined by three or more points.

        Args:
            point_list (list of tuples): List of coordinates defining the polygon to draw
            fill (bool): [**DEPRECATED since v2.5.4**] Use `style="F"` or `style="DF"` instead
            style (fpdf.enums.RenderStyle, str): Optional style of rendering. Possible values are:

            * `D` or None: draw border. This is the default value.
            * `F`: fill
            * `DF` or `FD`: draw and fill
        T)r  r  r  N)r  )r   r  r  r  s       r&   r  zFPDF.polygon  s$    & 	jtTGGGGGr%   r'   dash_lengthspace_lengthc                     t          j        dt          t                                 |                     ||           |                     ||||           |                                  dS )a  
        Draw a dashed line between two points.

        Args:
            x1 (float): Abscissa of first point
            y1 (float): Ordinate of first point
            x2 (float): Abscissa of second point
            y2 (float): Ordinate of second point
            dash_length (float): Length of the dash
            space_length (float): Length of the space between 2 dashes

        .. deprecated:: 2.4.6
            Use `FPDF.set_dash_pattern()` and the normal drawing operations instead.
        zdashed_line() is deprecated since v2.4.6, and will be removed in a future release. Use set_dash_pattern() and the normal drawing operations instead.r   N)r   r   r   r3   r  r  )r   r  r  r  r  r  r  s          r&   dashed_linezFPDF.dashed_line  sy    0 	T &((	
 	
 	
 	
 	k<888		"b"b!!!r%   r  r  round_cornerscorner_radiusc                 6   |t          j        |          nt           j        }|dur|                     |||||||           dS |                     || j        z  dd| j        |z
  | j        z  dd|| j        z  dd| | j        z  dd|j         	           dS )a{  
        Outputs a rectangle.
        It can be drawn (border only), filled (with no border) or both.

        Args:
            x (float): Abscissa of upper-left bounding box.
            y (float): Ordinate of upper-left bounding box.
            w (float): Width.
            h (float): Height.
            style (fpdf.enums.RenderStyle, str): Optional style of rendering. Possible values are:

            * `D` or empty string: draw border. This is the default value.
            * `F`: fill
            * `DF` or `FD`: draw and fill

            round_corners (tuple of str, tuple of fpdf.enums.Corner, bool): Optional draw a rectangle with round corners.
            Possible values are:

            *`TOP_LEFT`: a rectangle with round top left corner
            *`TOP_RIGHT`: a rectangle with round top right corner
            *`BOTTOM_LEFT`: a rectangle with round bottom left corner
            *`BOTTOM_RIGHT`: a rectangle with round bottom right corner
            *`True`: a rectangle with all round corners
            *`False`: a rectangle with no round corners

            corner_radius: Optional radius of the corners
        NFr  r   re )rU   rI  r  _draw_rounded_rectr  r   r  r  )r   r7  r   r  r  r  r  r  s           r&   r  z	FPDF.rect  s    N .3->"5)))KM%%##Aq!Q}mTTTTTIItv:Q 9 9TVaZ46$9Q 9 9DF
Q 9 92;89 9(-9 9    r%   .c                    |}||k     r|}|dk    r|dz  }||dz  k    r||z  }||fx}	}
||z   |f}||z   ||z   f}|||z   f}|du rBt           j        j        t           j        j        t           j        j        t           j        j        f}t          |t                    rJ t          d |D                       }t           j        |v r||z   |f}	|||z   f}
t           j        |v r||z   |z
  |f}||z   ||z   f}t           j        |v r||z   ||z   |z
  f}||z   |z
  ||z   f}t           j        |v r||z   ||z   f}|||z   |z
  f}| 	                    |	d         | j
        z  dd| j        |	d         z
  | j
        z  dd	           | 	                    |d         | j
        z  dd| j        |d         z
  | j
        z  dd
           t           j        |v r%|                     ||z   d|z  z
  |d|z  dd           | 	                    |d         | j
        z  dd| j        |d         z
  | j
        z  dd
           t           j        |v r.|                     ||z   d|z  z
  ||z   d|z  z
  d|z  dd           | 	                    |d         | j
        z  dd| j        |d         z
  | j
        z  dd
           t           j        |v r%|                     |||z   d|z  z
  d|z  dd           | 	                    |
d         | j
        z  dd| j        |
d         z
  | j
        z  dd
           t           j        |v r|                     ||d|z  dd           | 	                    d|j                    d S )Nr      r   Tc              3   >   K   | ]}t          j        |          V  d S rV  )rI   rI  )rM  rcs     r&   rO  z*FPDF._draw_rounded_rect.<locals>.<genexpr>n  s=       7
 7
"$FM"7
 7
 7
 7
 7
 7
r%   r  r  r'    m li  Z      h )rI   	TOP_RIGHTr  TOP_LEFTBOTTOM_RIGHTBOTTOM_LEFTr   r   r  r  r   r  _draw_arc_segmentr  )r   r7  r   r  r  r  r  r<  minpoint_1point_8point_2point_4point_6round_corners_list_point_3_point_5_point_7s                     r&   r  zFPDF._draw_rounded_rectL  s:    q55C66aAa<<HA F"'q5!*q5!a%.a!e*D   &%#)"(	M mT2222216 7
 7
(57
 7
 7
 2
 2

 1111uajG!a%jG?0001uqy!nGAq1u~H!3331ua!eai(GA	1q5)H"4441ua!enG1q519~H 			WQZ$&(UUU0Ctv/MUUUUVVV 			WQZ$&(UUU0Ctv/MUUUUVVV ?000""1q51q5=!QUCCCC 			WQZ$&(UUU0Ctv/MUUUUVVV !333""1q51q5=!a%!a%-Q2NNN 			WQZ$&(UUU0Ctv/MUUUUVVV "444""1a!ea!emQUBDDD 			WQZ$&(UUU0Ctv/MUUUUVVV 111""1aQS999 			'u~''(((((r%   astart_angle	end_anglec                    dz  dz  |z   |z   dt           dt           fddt           dt           ffd}dt           dt          t                    ffd	}dt           dt          t                    ffd
}	 ||          }
 ||          }||
k    r|dt          j        z  z  }d}t	          |t          j        t          ||
z
            dt          j        z  |z  z                      }||
z
  |z  }t          j        |          t          j        ddt          j	        |dz            dz  z  z             dz
  z  dz  }|
} ||          } |	|          }t          |          D ]}|}|}||z  } ||          } |	|          }|d         ||d         z  z   |d         ||d         z  z   g}|d         ||d         z  z
  |d         ||d         z  z
  g}|                     |d         | j        z  dd| j        |d         z
  | j        z  dd|d         | j        z  dd| j        |d         z
  | j        z  dd|d         | j        z  dd| j        |d         z
  | j        z  dd           dS )z
        Draw an arc segment as part of an existing path (no move, no style application).
        Used internally for building complex shapes like rounded rectangles.
        Nr   degr   c                 &    | t           j        z  dz  S Nr  mathpir  s    r&   
deg_to_radz*FPDF._draw_arc_segment.<locals>.deg_to_rad      =3&&r%   anglec                      | dz            } t          j        t          j        |           z  t          j        |           z            }|dk     r|dt           j        z  z  }|S Nh  r   r   r  atan2sincosr  r  etar  r>  r  s     r&   angle_to_paramz.FPDF._draw_arc_segment.<locals>.angle_to_param  s_    Jus{++E*TXe__q0$(5//A2EFFCQwwq47{"Jr%   r  c                 t    t          j        |           z  }t          j        |           z  }|z   |z   gS rV  r  r  r  )r  	a_cos_eta	b_sin_etar  r>  cxcys      r&   evaluatez(FPDF._draw_arc_segment.<locals>.evaluate  s:    DHSMM)IDHSMM)INBN33r%   c                 j    t          j        |           z  }t          j        |           z  }| |gS rV  r  r  r  )r  	a_sin_eta	b_cos_etar  r>  s      r&   derivative_evaluatez3FPDF._draw_arc_segment.<locals>.derivative_evaluate  s4    DHSMM)IDHSMM)IJ	**r%   r   r   r'   r   r  r   c)r   r   r  r  r  ceilabsr  sqrttanranger  r   r  )r   r7  r   r  r  r  r>  r  r  r  	start_etaend_eta
max_curvesnd_etaalphaeta2p2p2_prime_p1p1_primecontrol_point_1control_point_2r  r  r  s      `  `                 @@@r&   r  zFPDF._draw_arc_segment  s    9A	Q	QUU	'E 	'e 	' 	' 	' 	'	% 	E 	 	 	 	 	 	 	 		4% 	4DK 	4 	4 	4 	4 	4 	4 	4 	4 	4
	+U 	+tE{ 	+ 	+ 	+ 	+ 	+ 	+ 	+
 #N;//	 .++iq47{"G
	#g	&9":":a$'kJ>V"WXX
 
 9$)49QTXeai5H5HA5M1M-M#N#NQR#RSVWWXd^^&&t,,q 	 	ABHEMD$B**400H!!uux{'::BqEEHUVKDW<WXO!!uux{'::BqEEHUVKDW<WXOII"1%.b J Jdfq?Q6QUYU[5[b J J"1%.bJ J6:fq?Q6QUYU[5[bJ Ja546>IJ J)-"Q%46(AIJ J J   	 	r%   c                     |t          j        |          nt           j        }|                     |||||j                   dS )a   
        Outputs an ellipse.
        It can be drawn (border only), filled (with no border) or both.

        Args:
            x (float): Abscissa of upper-left bounding box.
            y (float): Ordinate of upper-left bounding box.
            w (float): Width
            h (float): Height
            style (fpdf.enums.RenderStyle, str): Optional style of rendering. Possible values are:

            * `D` or empty string: draw border. This is the default value.
            * `F`: fill
            * `DF` or `FD`: draw and fill
        N)rU   rI  r  _draw_ellipser  )r   r7  r   r  r  r  s         r&   ellipsezFPDF.ellipse  sD    0 .3->"5)))KM1aAu~66666r%   r  c                    ||dz  z   }||dz  z   }|dz  }|dz  }	dt          j        d          dz
  z  |z  }
dt          j        d          dz
  z  |	z  }|                     ||z   | j        z  dd| j        |z
  | j        z  dd||z   | j        z  dd| j        |z
  |z   | j        z  dd||
z   | j        z  dd| j        |z
  |	z   | j        z  dd|| j        z  dd| j        |z
  |	z   | j        z  dd           |                     ||
z
  | j        z  dd| j        |z
  |	z   | j        z  dd||z
  | j        z  dd| j        |z
  |z   | j        z  dd||z
  | j        z  dd| j        |z
  | j        z  dd           |                     ||z
  | j        z  dd| j        |z
  |z
  | j        z  dd||
z
  | j        z  dd| j        |z
  |	z
  | j        z  dd|| j        z  dd| j        |z
  |	z
  | j        z  dd           |                     ||
z   | j        z  dd| j        |z
  |	z
  | j        z  dd||z   | j        z  dd| j        |z
  |z
  | j        z  dd||z   | j        z  dd| j        |z
  | j        z  dd|            d S )	Nr   gUUUUUU?r'   r  r  r  r  z c )r  r  r  r   r  )r   r7  r   r  r  r  r  r  rxrylxlys               r&   r  zFPDF._draw_ellipse  s%    QYQYUUdillQ&'",dillQ&'",		Gtv%K I ITVb[DF,BK I IGtv%NI I-1Vb[2-=,GNI IGtv%NI I-1Vb[2-=,GNI I ;HI I '+frkB&6$&%@HI I I	
 	
 	
 			Gtv%N K KTVb[2-=,GN K KGtv%NK K-1Vb[2-=,GNK KGtv%JK K-1Vb[DF,BJK K K	
 	
 	
 			Gtv%N I ITVb[2-=,GN I IGtv%NI I-1Vb[2-=,GNI I;HI I&*frkB&6$&%@HI I I	
 	
 	
 			Gtv%N V VTVb[2-=,GN V VGtv%NV V-1Vb[2-=,GNV VGtv%UV V-1Vb[DF,BUV VKSV V	
 	
 	
 	
 	
r%   radiusc                 P    |                      ||z
  ||z
  d|z  d|z  |           dS )ad  
        Outputs a circle.
        It can be drawn (border only), filled (with no border) or both.

        WARNING: This method changed parameters in [release 2.8.1](https://github.com/py-pdf/fpdf2/releases/tag/2.8.1)

        Args:
            x (float): Abscissa of upper-left bounding box.
            y (float): Ordinate of upper-left bounding box.
            radius (float): Radius of the circle.
            style (str): Style of rendering. Possible values are:

            * `D` or None: draw border. This is the default value.
            * `F`: fill
            * `DF` or `FD`: draw and fill
        r   N)r  )r   r7  r   r  r  s        r&   circlezFPDF.circle7  s4    0 	QZVQZVUKKKKKr%   numSides	polyWidthrotateDegreesc           
         |dz  }||z   }||z
  }	g }
t          d|dz             D ]}||t          j        t          j        d|z  |z            t          j        |          z             z  z   |	|t          j        t          j        d|z  |z            t          j        |          z             z  z   f}|
                    |           |                     |
|           dS )a  
        Outputs a regular polygon with n sides
        It can be rotated
        Style can also be applied (fill, border...)

        Args:
            x (float): Abscissa of upper-left bounding box.
            y (float): Ordinate of upper-left bounding box.
            numSides (int): Number of sides for polygon.
            polyWidth (float): Width of the polygon.
            rotateDegrees (float): Optional degree amount to rotate polygon.
            style (fpdf.enums.RenderStyle, str): Optional style of rendering. Possible values are:

            * `D` or None: draw border. This is the default value.
            * `F`: fill
            * `DF` or `FD`: draw and fill
        r   r'   r  r  N)r  r  r  radiansr  appendr  )r   r7  r   r  r  r  r  r  centerXcenterYpointsir  s                r&   regular_polygonzFPDF.regular_polygonQ  s   6 Qf*f*,.q(Q,'' 	! 	!AftxcHn122T\-5P5PP( (  $(cHn122T\-5P5PP# #  E
 MM%     	V5)))))r%   r_inr_outcornersrotate_degreesc                    t          j        |          }g }	t          d|dz  dz             D ]}}
||
dz  dk    r|n|t          j        |          z  z   }||
dz  dk    r|n|t          j        |          z  z   }|	                    ||f           |t          j        d|z            z  }~|                     |	d|           dS )a  
        Outputs a regular star with n corners.
        It can be rotated.
        It can be drawn (border only), filled (with no border) or both.

        Args:
            x (float): Abscissa of star's centre.
            y (float): Ordinate of star's centre.
            r_in (float): radius of internal circle.
            r_out (float): radius of external circle.
            corners (int): number of star's corners.
            rotate_degrees (float): Optional degree amount to rotate star clockwise.

            style (fpdf.enums.RenderStyle, str): Optional style of rendering. Possible values are:
            * `D`: draw border. This is the default value.
            * `F`: fill.
            * `DF` or `FD`: draw and fill.
        r   r   r'   r  T)r  r  N)r  r  r  r  r  r  r  )r   r7  r   r  r  r  r  r  thr  r  corner_xcorner_ys                r&   starz	FPDF.star}  s    : \.))02
q7Q;!+,, 	. 	.AQUaZZEETTXb\\IIHQUaZZEETTXb\\IIHx2333$,sW}---BBj$e<<<<<r%   inclination	clockwisestart_from_centerend_at_centerc                    !"#$ |t          j        |          nt           j        }dz  dz  |z   !|z   "dt          dt          fd#dt          dt          f#fd} #|          }t	          j        |           t	          j        |          $dt          dt          t                   f !"$fd	}dt          dt          t                   f $fd
} ||          } ||          }|s||k    r|dt          j        z  z  }n|r||k    r|dt          j        z  z  } ||          }|	rw| 	                    !| j
        z  dd| j        "z
  | j
        z  dd           | 	                    |d         | j
        z  dd| j        |d         z
  | j
        z  dd           nA| 	                    |d         | j
        z  dd| j        |d         z
  | j
        z  dd           d}t          |t	          j        t          ||z
            dt          j        z  |z  z                      }||z
  |z  }t	          j        |          t	          j        ddt	          j        |dz            dz  z  z             dz
  z  dz  }|} ||          } ||          }t#          |          D ]%}|}|}||z  } ||          } ||          }|d         ||d         z  z   |d         ||d         z  z   g}|d         ||d         z  z
  |d         ||d         z  z
  g}d}||dz
  k    r|
s
d|j         }| 	                    |d         | j
        z  dd| j        |d         z
  | j
        z  dd|d         | j
        z  dd| j        |d         z
  | j
        z  dd|d         | j
        z  dd| j        |d         z
  | j
        z  dd|z              '|
r_|	r| 	                    d|j                    dS | 	                    !| j
        z  dd| j        "z
  | j
        z  dd|j                    dS dS )a  
        Outputs an arc.
        It can be drawn (border only), filled (with no border) or both.

        Args:
            x (float): Abscissa of upper-left corner of the bounding box of the full ellipse.
            y (float): Ordinate of upper-left corner of the bounding box of the full ellipse.
            a (float): Major axis diameter (width of bounding box).
            b (float): Minor axis diameter (height of bounding box), if None, equals to a (default: None).
            start_angle (float): Start angle of the arc (in degrees).
            end_angle (float): End angle of the arc (in degrees).
            inclination (float): Inclination of the arc in respect of the x-axis (default: 0).
            clockwise (bool): Way of drawing the arc (True: clockwise, False: counterclockwise) (default: False).
            start_from_center (bool): Start drawing from the center of the ellipse (default: False).
            end_at_center (bool): End drawing at the center of the ellipse (default: False).
            style (fpdf.enums.RenderStyle, str): Optional style of rendering. Allowed values are:

            * `D` or None: draw border. This is the default value.
            * `F`: fill
            * `DF` or `FD`: draw and fill
        Nr   r  r   c                 &    | t           j        z  dz  S r  r  r  s    r&   r  zFPDF.arc.<locals>.deg_to_rad  r  r%   r  c                      | dz            } t          j        t          j        |           z  t          j        |           z            }|dk     r|dt           j        z  z  }|S r  r  r  s     r&   r  z FPDF.arc.<locals>.angle_to_param  s_    Jus{++E*TXe__q0$(5//A2EFFCQwwq47{"Jr%   r  c                     t          j        |           z  }t          j        |           z  }|z  z   |z  z
  |z  z   |z  z   gS rV  r  )	r  r  r  r  r>  	cos_thetar  r  	sin_thetas	      r&   r  zFPDF.arc.<locals>.evaluate  sa    DHSMM)IDHSMM)I Y**Y-BBY**Y-BB r%   c                     t          j        |           z  }t          j        |           z  }| z  |z  z
  | z  |z  z   gS rV  r  )r  r  r  r  r>  r*  r+  s      r&   r  z%FPDF.arc.<locals>.derivative_evaluate  s[    DHSMM)IDHSMM)I 
Y&Y)>>
Y&Y)>> r%   r  r  r  r   r'   r  r   r   r   r  r  z l )rU   rI  r  r   r  r  r  r   r  r  r   r  r  r  r  r  r  r  r  )%r   r7  r   r  r  r  r>  r"  r#  r$  r%  r  r  thetar  r  r  r  start_pointr  r  r  r  r  r  r  r  r  r   r  r  endr*  r  r  r  r+  s%      `  `                         @@@@@r&   arczFPDF.arc  s   H .3->"5)))KM9A	Q	QUU	'E 	'e 	' 	' 	' 	'	% 	E 	 	 	 	 	 	 	 	 
;''HUOO	HUOO		% 	DK 	 	 	 	 	 	 	 	 	 	 		U 	tE{ 	 	 	 	 	 	 	 	 	 #N;//	 .++ 	%W	11q47{"GG 	%7i//TW$Ihy))  	IIdfIIIDFRK46+AIIIIJJJIIq>DF*[[[$&;q>2ITV1S[[[[    IIq>DF*[[[$&;q>2ITV1S[[[[  
 
	#g	&9":":a$'kJ>V"WXX
 
 9$)49QTXeai5H5HA5M1M-M#N#NQR#RSVWWXd^^&&t,,q 	 	ABHEMD$B**400H!!uux{'::BqEEHUVKDW<WXO!!uux{'::BqEEHUVKDW<WXOCAEzz-z*%.**II&q)DF2f N N$&?STCU:UY]Y_9_f N N&q)DF2fN N:>&?STCU:UY]Y_9_fN N!utv~MN N-1Vbe^tv,EMN N NPST     	  		/u~//00000		DF{XXX$&2+)?XXXXX    		 	r%   c
                 D    |                      ||||||||dd|	           dS )a  
        Outputs a solid arc. A solid arc combines an arc and a triangle to form a pie slice
        It can be drawn (border only), filled (with no border) or both.

        Args:
            x (float): Abscissa of upper-left bounding box.
            y (float): Ordinate of upper-left bounding box.
            a (float): Semi-major axis.
            b (float): Semi-minor axis, if None, equals to a (default: None).
            start_angle (float): Start angle of the arc (in degrees).
            end_angle (float): End angle of the arc (in degrees).
            inclination (float): Inclination of the arc in respect of the x-axis (default: 0).
            clockwise (bool): Way of drawing the arc (True: clockwise, False: counterclockwise) (default: False).
            style (str): Style of rendering. Possible values are:

            * `D` or None: draw border. This is the default value.
            * `F`: fill
            * `DF` or `FD`: draw and fill
        TN)r0  )
r   r7  r   r  r  r  r>  r"  r#  r  s
             r&   	solid_arczFPDF.solid_arc:	  sE    > 		
 	
 	
 	
 	
r%   closedc           	      |   t          |          }|dvrt          d          |t          j        |          nt          j        }|                                 5 }|d         }|d         |d         }}t          ||          }	|                    |	           |d         }
|
d         |
d         }}|d         }|d         |d         }}|dk    r|d         }|d         |d         }}t          ||          }t          j	        }|j
        r|j        st          j        }n|j        r|j
        st          j        }||j        _        ||j        _        |dk    r|                    ||||||           n |dk    r|                    ||||||           |                    |           ddd           dS # 1 swxY w Y   dS )	u  
        Outputs a quadratic or cubic Bézier curve, defined by three or four coordinates.

        Args:
            point_list (list of tuples): List of Abscissa and Ordinate of
                                        segments that should be drawn. Should be
                                        three or four tuples. The first and last
                                        points are the start and end point. The
                                        middle point(s) are the control point(s).
            closed (bool): True to draw the curve as a closed path, False (default)
                                        for it to be drawn as an open path.
            style (fpdf.enums.RenderStyle, str): Optional style of rendering. Allowed values are:
            * `D` or None: draw border. This is the default value.
            * `F`: fill
            * `DF` or `FD`: draw and fill
        r   r   zWpoint_list should contain 3 tuples for a quadratic curve or 4 tuples for a cubic curve.Nr   r'   r   r   r   )r  r  rU   rI  r  rf  r8   r{  rS   STROKE_FILL_NONZEROis_drawis_fillSTROKEFILL_NONZEROr  ry  
auto_closecurve_to)r   r  r3  r  r  r|  r  r  r  
dummy_pathr  r  r  p3x3y3p4x4y4r}  rules                        r&   bezierzFPDF.bezierg	  s+   , Z2   .3->"5)))KM
 !!## )	 tABUBqEB$R,,JMM*%%%ABUBqEBABUBqEB{{]A1Br2&&D !4D} 2U] 2$+ 2u} 2$1$(DJ!$*DJ!{{    1b"b"b"555MM$S)	  )	  )	  )	  )	  )	  )	  )	  )	  )	  )	  )	  )	  )	  )	  )	  )	  )	 s   EF11F58F5)uniz2.5.1)unicode_range
variationspalettecollection_font_numberr   fnamerG  rH  rI  rJ  c          
         |st          d          t          t          |                    d                                         }|dvrt          d| d          t	          d          t
          fD ] }	|	|z                                  r|	|z  }
 n!t          d|           ||
j        }d}|t          |          }d	
                    t          |                                                    }t          d
 |D                       rt          d|           |t          |t                    st!          d          t#          d |                                D                       r8|                                D ]!\  }}|                     |||||||           "dS |                                 | }|| j        v s	|t*          v r(t-          j        d| dt1                                 dS t3          | |
||||||          }|| j        |<   |j        r|j        r|                     d           dS dS dS )a!  
        Imports a TrueType or OpenType font and makes it available
        for later calls to the `FPDF.set_font()` method.

        You will find more information on the "Unicode" documentation page.

        Args:
            family (str): optional name of the font family. Used as a reference for `FPDF.set_font()`.
                If not provided, use the base name of the `fname` font path, without extension.
            style (str): font style. "" for regular, include 'B' for bold, and/or 'I' for italic.
            fname (str): font file name. You can specify a relative or full path.
                If the file is not found, it will be searched in `FPDF_FONT_DIR`.
            unicode_range (Optional[Union[str, int, tuple, list]]): subset of Unicode codepoints to embed.
                Accepts CSS-style strings (e.g. "U+1F600-1F64F, U+2600"), integers, tuples, or lists.
                Defaults to None, which embeds the full cmap.
            variations (dict[style, dict]): maps style to limits of axes for the variable font.
            palette (int): optional palette index for color fonts (COLR/CPAL). Defaults to 0 (first palette).
                Only applicable to fonts with CPAL table (color fonts).
            collection_font_number (int): face index for TTC/OTC collections.
        z"fname" parameter is requiredr'   )z.otbz.otfz.otcz.ttfz.ttcz.woffz.woff2z!Unsupported font file extension: z. add_font() used to accept .pkl file as input, but for security reasons this feature is deprecated since v2.5.1 and has been removed in v2.5.3..zTTF Font file not found: Nr   c              3      K   | ]}|d vV  	dS BINr$   rM  r   s     r&   rO  z FPDF.add_font.<locals>.<genexpr>	  s'      66fvT!666666r%   z9Unknown style provided (only B & I letters are allowed): z.Variations, if specified, must be a dictionaryc              3   r   K   | ]2\  }}|                                 d v ot          |t                    V  3dS ))r   BIrP  N)r  r   r-  )rM  keyr  s      r&   rO  z FPDF.add_font.<locals>.<genexpr>	  sW        C 		33O
5$8O8O     r%   )r   r  rK  rG  rH  rI  rJ  z!Core font or font already added 'z': doing nothingr   rx  )r  r   r   r   r	   r   existsFileNotFoundErrorstemr   r  sortedr  anyr   r-  r  allitemsadd_fontrY  ra   r   r   r3   rf   is_cffis_cid_keyedrM  )r   r   r  rK  rG  rH  rI  rJ  extparentfont_file_pathparsed_unicode_range	var_style	axes_dictfontkeyfont_objs                   r&   r]  zFPDF.add_font	  s   @  	><===s5zz""1%++--QQQ[C [ [ [   Cyy-0 	I 	IF&&(( !'% $$G$G$GHHH>#(F#$#;M#J#J u{{}}--..6666666 	SESS  
 !j$// R PQQQ   ","2"2"4"4      -7,<,<,>,> 	 	(IyMM%'#&3#, '/E "     \\^^,U,,dj  Gz$9$9MMGMMM*,,    F "	
 	
 '
7? 	-x4 	-%%e,,,,,	- 	- 	- 	-r%   r!  c                    |s| j         }|                                }t          |t                    r|j        }d                    t          |                                                    }t          d |D                       rt          d|           d|v rd| _
        |                    dd          }nd| _
        d|v rd| _        |                    dd          }nd| _        || j        v rT||z   | j        vrHt          j        d| d	| j        |          d
t"          t%                                 | j        |         }n.|dv r*|r(t          j        d| dt%                                 d}|s| j        }| j         |k    r'| j        |k    rt+          j        | j        |          rdS ||z   }|| j        vr~|t.          vrt1          d| d          | j        r-| j        j        dk    rt7          d| j        j         d          t;          t=          | j                  dz   ||          | j        |<   || _         || _        || _        | j        |         | _        d| _         dS )a;  
        Sets the font used to print character strings.
        It is mandatory to call this method at least once before printing text.

        Default encoding is not specified, but all text writing methods accept only
        unicode for external fonts and one byte encoding for standard.

        Standard fonts use `Latin-1` encoding by default, but Windows
        encoding `cp1252` (Western Europe) can be used with
        `self.core_fonts_encoding = encoding`.

        The font specified is retained from page to page.
        The method can be called before the first page is created.

        Args:
            family (str): name of a font added with `FPDF.add_font`,
                or name of one of the 14 standard "PostScript" fonts:
                Courier (fixed-width), Helvetica (sans serif), Times (serif),
                Symbol (symbolic) or ZapfDingbats (symbolic)
                If an empty string is provided, the current family is retained.
            style (str, fpdf.enums.TextEmphasis): empty string (by default) or a combination
                of one or several letters among B (bold), I (italic), S (strikethrough) and U (underline).
                Bold and italic styles do not apply to Symbol and ZapfDingbats fonts.
            size (float): in points. The default value is the current size.
        r   c              3      K   | ]}|d vV  	dS )BISUNr$   rQ  s     r&   rO  z FPDF.set_font.<locals>.<genexpr>D
  s'      88vV#888888r%   z;Unknown style provided (only B/I/S/U letters are allowed): ro  TFrn  zSubstituting font z by core font z< - This is deprecated since v2.7.8, and will soon be removedr   )symbolzapfdingbatszBuilt-in font z6 only has a single 'style' and can't be bold or italicNzUndefined font: z3 - Use built-in fonts or FPDF.add_font() beforehandr   z@Usage of base fonts is now allowed for documents compliant with z%. Use add_font() to embed a font filer'   )!r  r   r   rW   r  r  rY  r  rZ  r  r  replacer   r  rY  r   r   r   r3   r!  r  r   equalra   r]   rJ  rK  r`   ra  rb   r  r$  r%  )r   r   r  r!  rf  s        r&   r  zFPDF.set_font
  s   >  	&%Fe\** 	 KEu{{}}--..88%88888 	UeUU   %<<!DNMM#r**EE"DN%<<!%DMM#r**EE!&DT&&&6E>+K+KMOV O O4;LV;T O O O"*,,	    &v.FF111e1M. . . .*,,   
 E 	%$D &&5(($T%6== ) F 5.$*$$j((#Hw H H H  
  D$4$<$F$F) UW[WgWm  U  U  U   #+3tz??Q+>"O"ODJw "  Jw/+0(((r%   c                 Z    t          j        | j        |          rdS || _        d| _        dS )zp
        Configure the font size in points

        Args:
            size (float): font size in points
        NF)r   rn  r!  r%  )r   r!  s     r&   set_font_sizezFPDF.set_font_size
  s7      1488 	F +0(((r%   r!  wrap_in_text_objectc                     d|j          d|dd}|rd| d}| j                            t          j        |j         | j                   d| _        |S )z
        Set font and size for current page.
        This step is needed before adding text into page and not needed in set_font and set_font_size.
        /Fr  r   TfBT  ETT)r  rP  rj  rT   FONTr   r%  )r   r   r!  rq  sls        r&   _set_font_for_pagezFPDF._set_font_for_page
  se     1$&00<0000 	rB""?#7KKK+/(	r%   spacingc                 |    | j         |k    rdS || _         | j        dk    r|                     d|dd           dS dS )a\  
        Sets horizontal character spacing.
        A positive value increases the space between characters, a negative value
        reduces it (which may result in glyph overlap).
        By default, no spacing is set (which is equivalent to a value of 0).

        Args:
            spacing (float): horizontal spacing in document units
        Nr   ru  r  z Tc ET)r#  r   r  )r   rz  s     r&   r  zFPDF.set_char_spacing
  sX     ''F#9q==II/G////00000 =r%   r&  c                 |    | j         |k    rdS || _         | j        dk    r|                     d|dd           dS dS )z
        Sets horizontal font stretching.
        By default, no stretching is set (which is equivalent to a value of 100).

        Args:
            stretching (float): horizontal stretching (scaling) in percents.
        Nr   ru  r  z Tz ET)r"  r   r  )r   r&  s     r&   r  zFPDF.set_stretching
  sX     :--F)9q==II2J222233333 =r%   fallback_fontsexact_matchc                 (   g }|D ]~}d}| j         D ]]}|                    dd                              dd          |                                k    r||vr|                    |           d}^|st	          d| d          || _        || _        dS )	a;  
        Allows you to specify a list of fonts to be used if any character is not available on the font currently set.
        Detailed documentation: https://py-pdf.github.io/fpdf2/Unicode.html#fallback-fonts

        Args:
            fallback_fonts: sequence of fallback font IDs
            exact_match (bool): when a glyph cannot be rendered uing the current font,
                fpdf2 will look for a fallback font matching the current character emphasis (bold/italics).
                If it does not find such matching font, and `exact_match` is True, no fallback font will be used.
                If it does not find such matching font, and `exact_match` is False, a fallback font will still be used.
                To get even more control over this logic, you can also override `FPDF.get_fallback_font()`
        FrS  r   rT  TzUndefined fallback font: z! - Use FPDF.add_font() beforehandN)rY  rm  r   r  r]   rF  rG  )r   r}  r~  fallback_font_idsfallback_fontfoundrf  s          r&   set_fallback_fontszFPDF.set_fallback_fonts
  s     (*+ 	 	ME: ! !??3++33C<<@S@S@U@UUU&777)00999 E #````   #4*5'''r%   nullr   namec                    t          |dk    r| j        n|| j        || j        z  z
  || j        z  |          }|/|r|                                rt          d          || j        |<   t          | j                  dz   }|| j        |<   |S )a  
        Creates a new internal link and returns its identifier.
        An internal link is a clickable area which directs to another place within the document.

        The identifier can then be passed to the `FPDF.cell()`, `FPDF.write()`, `FPDF.image()`
        or `FPDF.link()` methods.

        If a name is provided, creates a named destination that can be referenced later.
        Named destinations are more stable than plain links when pages are added or removed.

        Args:
            y (float): optional ordinate of target position.
                The default value is 0 (top of page).
            x (float): optional abscissa of target position.
                The default value is 0 (top of page).
            page (int): optional number of target page.
                -1 indicates the current page, which is the default value.
            zoom (float): optional new zoom level after following the link.
                Currently ignored by Sumatra PDF Reader, but observed by Adobe Acrobat reader.
            name (str, optional): Name for the destination. If provided, creates a named
                destination in the PDF that can be referenced from other parts of the document
                or from external documents.
        r  r  r  r  Nz.Destination name cannot be empty or whitespacer'   )	r   r   r  r   isspacer  r  r  r  )r   r   r7  r   r  r  link
link_indexs           r&   add_linkzFPDF.add_link
  s    @ DII	AJ&TV	
 
 
  S4<<>> S !QRRR,0D#D) __q(
!%
:r%   c                 j    || j         vr&t          d| j        | j        z            | j         |<   d| S )as  
        Retrieves a named destination by its name and creates a link to it.

        Args:
            name (str): The name of the destination to retrieve.

        Returns:
            str: A string with format "#name" that can be used with cell(), write(), image(), or link()

        Raises:
            KeyError: If no destination exists with the given name
        r   r  #)r  r   r  r   )r   r  s     r&   get_named_destinationzFPDF.get_named_destination  sE     t... -;1$)dfBT,U,U,UD#D) 4zzr%   r  c                 V   |rF|Dt          |dk    r| j        n|| j        || j        z  z
  || j        z  |          }|| j        |<   |S |J | j        |         }|dk    r| j        n||_        | j        || j        z  z
  |_        || j        z  |_        ||_	        |r|| j        |<   |S |S )a  
        Defines the page and position a link points to.

        Args:
            link (int, optional): a link identifier returned by `FPDF.add_link()`.
                If None and name is provided, will create or update a named destination.
            y (float): optional ordinate of target position.
                The default value is 0 (top of page).
            x (float): optional abscissa of target position.
                The default value is 0 (top of page).
            page (int): optional number of target page.
                -1 indicates the current page, which is the default value.
            zoom (float): optional new zoom level after following the link.
                Currently ignored by Sumatra PDF Reader, but observed by Adobe Acrobat reader.
            name (str, optional): Name for the destination. If provided, creates or updates a named
                destination in the PDF that can be referenced from other parts of the document
                or from external documents.
        Nr  r  )
r   r   r  r   r  r  page_numberr  r  r  )	r   r  r   r7  r   r  r  destdestinations	            r&   set_linkzFPDF.set_link'  s    8  	DL!!RZZ		TIDF
*Z	  D -1D#D)K j&/3rzz$))t)a$&j0tv:  	,7D#D)K r%   alt_textc           
         d}d}	|rt          |t                    rp|                    d          rK|dd         }
|
| j        vr&t	          d| j        | j        z            | j        |
<   t          |
d          }	nct          |          }nS|| j	        v s#J d| d	t          | j	                   d
            | j	        |         }	|	j        st          d| d          t          	 d|| j        z  | j        || j        z  z
  || j        z  || j        z  ||	d|}| j        | j                                     |           ||                     d|           |S )as  
        Puts a link annotation on a rectangular area of the page.
        Text or image links are generally put via `FPDF.cell`,
        `FPDF.write` or `FPDF.image`,
        but this method can be useful for instance to define a clickable area inside an image.

        Args:
            x (float): horizontal position (from the left) to the left side of the link rectangle
            y (float): vertical position (from the top) to the bottom side of the link rectangle
            w (float): width of the link rectangle
            h (float): height of the link rectangle
            link: can be one of the following:
                - a URL string to create an external link
                - an integer returned by `FPDF.add_link`, defining an internal link to a page
                - a named destination string prefixed with '#' (e.g., '#chapter1')
            alt_text (str): optional textual description of the link, for accessibility purposes
            border_width (int): thickness of an optional black border surrounding the link.
                Not all PDF readers honor this: Acrobat renders it but not Sumatra.
        Nr  r'   r   r  T)encryptzLink with an invalid index: z (doc #links=)zCannot insert link z with no page number assignedLink)r7  r   rT  heightactionr  z/Link)struct_typer  )r  )r   r   
startswithr  r   r  r   r   r*   r  r  r  r  r,   r   r   add_annotation_add_marked_content)r   r7  r   r  r  r  r  r   r  r  	dest_name
link_annots               r&   r  z	FPDF.linkc  s   : '+59 	$$$ ??3'' - $QRRI !(???=K49tv#5> > >/	: %Y===DD 't__FF DJ&&&W$WWS__WWW '&&z$'' $QdQQQ   $	
$&ji!df*$df*tv:	
 	
 	
 	

 	
49,,Z888 $$8$LLLr%   	file_pathbytesbasenamemodification_date	mime_typeassociated_file_relationshipc           	      8   |r|rt          d          |rt          d          t          |          }|                    d          5 }|                                }ddd           n# 1 swxY w Y   |j        }|                                }	|+t          j        |	j                  	                                }n"|st          d          |st          d          |t          j        |          d         pd}|                                }|t          j        |          nd}
t          d	 | j        D                       }||v rt          | d
          | j        r| j        j        dk    r| j        j        dk    rt)          d| j        j                   | j        j        dk    s| j        j        dk    r|| j        j        p|dk    s'|                                                    d          r't0                              d| j        j        |           nt)          | j        j         d          | j        j        dv r|
t          j        }
t7          d|||||
d|}| j                            |           |                     d           |S )az  
        Embed a file into the PDF as an attachment (and, for PDF/A-3 or PDF/A-4f, as an
        Associated File).

        Args:
            file_path (str or Path): filesystem path to the existing file to embed
            bytes (bytes): optional, as an alternative to file_path, bytes content of the file to embed
            basename (str): optional, required if bytes is provided, file base name
            creation_date (datetime): date and time when the file was created
            modification_date (datetime): date and time when the file was last modified
            desc (str): optional description of the file
            mime_type: MIME type of the embedded content (e.g., "application/pdf", "text/csv", "image/png")
            associated_file_relationship: For PDF/A-3/A-4f, the AF relationship to declare in the FileSpec
                (e.g., "Data", "Source", "Alternative", "Supplement", or "Unspecified").

            **kwargs:
            desc (str): Optional human-readable description for the FileSpec.
            creation_date (datetime): Original creation time of the file.
            compress (bool): enabled zlib compression of the file - False by default
            checksum (bool): insert a MD5 checksum of the file content - False by default

        Returns: a PDFEmbeddedFile instance, with a .basename string attribute representing the internal file name
        z+'bytes' cannot be provided with 'file_path'z.'basename' cannot be provided with 'file_path'rbNz2'bytes' is required if 'file_path' is not providedz5'basename' is required if 'file_path' is not providedr   zapplication/octet-streamc              3   >   K   | ]}|                                 V  d S rV  )r  )rM  files     r&   rO  z"FPDF.embed_file.<locals>.<genexpr>  s;       )
 )
 $DMMOO)
 )
 )
 )
 )
 )
r%   z' has already been embedded in this filer   r'   z<Embedding files is not allowed for documents compliant with r   r   zapplication/pdfz.pdfzE%s: ensure the embedded PDF '%s' is itself PDF/A to remain compliant.zB permits embedding only PDF files, which must themselves be PDF/A.r5  )r  r0  r  r  af_relationshipr   r$   )r  r	   openreadr  statr   fromtimestampst_mtimer  	mimetypes
guess_typer   rG   rI  setr  rJ  rK  rL  r`   ra  conformanceendswithLOGGERwarningUNSPECIFIEDr.   r  rM  )r   r  r  r  r  r  r  r   
input_filestatsr  already_embedded_basenamesembedded_files                r&   
embed_filezFPDF.embed_file  s^   B  	 P !NOOO S !QRRRYI%% *"))* * * * * * * * * * * * * * * ~HNN$$E ($,$:5>$J$J$U$U$W$W! W !UVVV  K   !,X66q9W=WIOO%%	 ,7 '-.JKKK 	
 &) )
 )
(,(;)
 )
 )
 &
 &
" 111QQQRRR 	M 0 8F B B$)))kSWScSikk   $)) %**t/?/K/S!222x~~7G7G7P7P8 82 NN_(.     .+1uuu   $.."*&@&LO' 
/+
 
 
 
 	""=111!!%(((s   	A**A.1A.flagsc                 d    | j         |fi |}	|	                    d           t          d|| j        z  | j        || j        z  z
  || j        z  || j        z  |	                                |rt          j        |          nd|          }
| j        | j	                 
                    |
           |
S )a5  
        Puts a file attachment annotation on a rectangular area of the page.

        Args:
            file_path (str or Path): filesystem path to the existing file to embed
            x (float): horizontal position (from the left) to the left side of the link rectangle
            y (float): vertical position (from the top) to the bottom side of the link rectangle
            w (float): optional width of the link rectangle
            h (float): optional height of the link rectangle
            name (fpdf.enums.FileAttachmentAnnotationName, str): optional icon that shall be used in displaying the annotation
            flags (Tuple[fpdf.enums.AnnotationFlag], Tuple[str]): optional list of flags defining annotation properties
            bytes (bytes): optional, as an alternative to file_path, bytes content of the file to embed
            basename (str): optional, required if bytes is provided, file base name
            creation_date (datetime): date and time when the file was created
            modification_date (datetime): date and time when the file was last modified
            desc (str): optional description of the file
            compress (bool): enabled zlib compression of the file - False by default
            checksum (bool): insert a MD5 checksum of the file content - False by default
        FFileAttachmentN)	file_specr  r  )r  set_globally_enclosedr,   r   r  r  rL   rI  r   r   r  )r   r  r7  r   r  r  r  r  r   r  
annotations              r&   file_attachment_annotationzFPDF.file_attachment_annotation  s    > (	<<V<< 	++E222#JIDF
"JJ#--//>BL-4T:::	
 	
 	

 	
49,,Z888r%   c                     t          d|| j        z  | j        || j        z  z
  || j        z  || j        z  f||rt          j        |          ndd|}| j        | j                                     |           |S )u  
        Puts a text annotation on a rectangular area of the page.

        Args:
            x (float): horizontal position (from the left) to the left side of the link rectangle
            y (float): vertical position (from the top) to the bottom side of the link rectangle
            text (str): text to display
            w (float): optional width of the link rectangle
            h (float): optional height of the link rectangle
            name (fpdf.enums.AnnotationName, str): optional icon that shall be used in displaying the annotation
            flags (Tuple[fpdf.enums.AnnotationFlag], Tuple[str]): optional list of flags defining annotation properties
            title (str): the text label that shall be displayed in the title bar of the annotation’s
                pop-up window when open and active. This entry shall identify the user who added the annotation.
        TextN)r0  r  )r,   r   r  rF   rI  r   r   r  )	r   r7  r   rc  r  r  r  r   r  s	            r&   text_annotationzFPDF.text_annotationD  s    2 $JIDF
"JJ	
 04>&t,,,$	
 	
 	
 	

 	
49,,Z888r%   c                 f   | j         st          d          | j        s<| j        J |                     |                     | j        | j                             || j        }|| j        }|| j	        }|| 
                    |dd          }| j        | j        J t          d|| j        z  | j        || j        z  z
  || j        z  || j        z  f|d| j                                         d| j        j         d	| j        d
dd|}| j        | j                                     |           |S )a0  
        Puts a free text annotation on a rectangular area of the page.

        Args:
            text (str): text to display
            x (float): optional horizontal position (from the left) to the left side of the link rectangle.
                Default value: None, meaning the current abscissa is used
            y (float): vertical position (from the top) to the bottom side of the link rectangle.
                Default value: None, meaning the current ordinate is used
            w (float): optional width of the link rectangle. Default value: None, meaning the length of text in user unit
            h (float): optional height of the link rectangle. Default value: None, meaning an height equal
                to the current font size
            flags (Tuple[fpdf.enums.AnnotationFlag], Tuple[str]): optional list of flags defining annotation properties
            color (tuple): a tuple of numbers in the range 0.0 to 1.0, representing a colour used for the annotation background
            border_width (float): width of the annotation border
        rI  NTFrF  rG  FreeText(z /Fr  r  z Tf))r0  default_appearance)r  r]   r%  r$  r  ry  r!  r7  r   	font_sizerS  r'  r,   r   r  r  r  r   r   r  )r   rc  r7  r   r  r  r   r  s           r&   free_text_annotationzFPDF.free_text_annotationj  so   4  	W UVVV/ 	U$000IId--d.?ARSSTTT9A9A9A9%%dte%LLA*t/@/L/LL#JIDF
"JJ	
 t4?#<#<#>#>tt4CTCVttY]Yjtttt	
 	
 	
 	

 	
49,,Z888r%   r  c                     d}t          |t                    rd}t          ||| j        z  | j        || j        z  z
  || j        z  || j        z  fd|i|}| j        | j                                     |           |S )a  
        Puts an Action annotation on a rectangular area of the page.

        Args:
            action (fpdf.actions.Action): the action to add
            x (float): horizontal position (from the left) to the left side of the link rectangle
            y (float): vertical position (from the top) to the bottom side of the link rectangle
            w (float): width of the link rectangle
            h (float): height of the link rectangle
        r(   r  r  )r   r)   r,   r   r  r   r   r  )	r   r  r7  r   r  r  r   annotation_action_typer  s	            r&   
add_actionzFPDF.add_action  s     "*fj)) 	,%+"#"JIDF
"JJ
 
 
 
 

 	
49,,Z888r%   	Highlightr'   r'   r   rs  colormodification_timec           	   +      K   | j         rt          d          d| _         dV  | j                                        D ]\  }} | j        ||f||||d| t          t                    | _        d| _         dS )u/  
        Context manager that adds a single highlight annotation based on the text lines inserted
        inside its indented block.

        Args:
            text (str): text of the annotation
            title (str): the text label that shall be displayed in the title bar of the annotation’s
                pop-up window when open and active. This entry shall identify the user who added the annotation.
            type (fpdf.enums.TextMarkupType, str): "Highlight", "Underline", "Squiggly" or "StrikeOut".
            color (tuple): a tuple of numbers in the range 0.0 to 1.0, representing a colour used for
                the title bar of the annotation’s pop-up window. Defaults to yellow.
            modification_time (datetime): date and time when the annotation was most recently modified
        zhighlight() cannot be nestedTN)quad_pointsr  r   r  F)rO  r]   rQ  r\  add_text_markup_annotationr   r   )r   rc  rs  r  r  r   r   r  s           r&   	highlightzFPDF.highlight  s      , ( 	@ >???(,%!%!7!=!=!?!? 		 		D++D+ ("3      "-T!2!2(-%%%r%   c              /      K   t          j        dt          t                                  | j        |i |5  d V  d d d            d S # 1 swxY w Y   d S )Nz:add_highlight() has been renamed to highlight() in v2.5.5.r   )r   r   r   r3   r  )r   r   r   s      r&   add_highlightzFPDF.add_highlight  s      H&((	
 	
 	
 	

 T^T,V,, 	 	EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A

AAr  c                    |                      d           t          j        |          j        }|| j        }|| j        }t          |ddd                   }t          |ddd                   }	t          |ddd                   }
t          |ddd                   }t          |f||	||
|z
  ||	z
  |||d|}| j	        |         
                    |           |S )u  
        Adds a text markup annotation on some quadrilateral areas of the page.

        Args:
            type (fpdf.enums.TextMarkupType, str): "Highlight", "Underline", "Squiggly" or "StrikeOut"
            text (str): text of the annotation
            quad_points (tuple): array of 8 × n numbers specifying the coordinates of n quadrilaterals
                in default user space that comprise the region in which the link should be activated.
                The coordinates for each quadrilateral are given in the order: x1 y1 x2 y2 x3 y3 x4 y4
                specifying the four vertices of the quadrilateral in counterclockwise order
            title (str): the text label that shall be displayed in the title bar of the annotation’s
                pop-up window when open and active. This entry shall identify the user who added the annotation.
            color (tuple): a tuple of numbers in the range 0.0 to 1.0, representing a colour used for
                the title bar of the annotation’s pop-up window. Defaults to yellow.
            modification_time (datetime): date and time when the annotation was most recently modified
            page (int): index of the page where this annotation is added
        rx  Nr   r   r'   )r0  r7  r   rT  r  r  r  r  )rM  rX   rI  r  rD  r   r  rl  r,   r   r  )r   rs  rc  r  r  r  r   r   x_miny_minx_maxy_maxr  s                r&   r  zFPDF.add_text_markup_annotation  s   8 	!!%((($T**0$ $ 2<9DK1%&&K1%&&K1%&&K1%&&#
%-5=/#
 
 
 

 	
4''
333r%   coordsborder_widthc                     t           fd|D             d          }t          |ddd                   }t          |ddd                   }t          |ddd                   }	t          |ddd                   }
t          	 d	||
|	|z
  |
|z
  ||||d|} j         j                                     |           |S )
u  
        Adds add an ink annotation on the page.

        Args:
            coords (tuple): an iterable of coordinates (pairs of numbers) defining a path
            text (str): textual description
            title (str): the text label that shall be displayed in the title bar of the annotation’s
                pop-up window when open and active. This entry shall identify the user who added the annotation.
            color (tuple): a tuple of numbers in the range 0.0 to 1.0, representing a colour used for
                the title bar of the annotation’s pop-up window. Defaults to yellow.
            border_width (float): thickness of the path stroke.
        c              3   V   K   | ]#\  }}|j         z  j        |z
  j         z  fV  $d S rV  )r   r  )rM  r7  r   r   s      r&   rO  z&FPDF.ink_annotation.<locals>.<genexpr>8  s?      QQATVdfqjDF%:;QQQQQQr%   r$   r   Nr   r'   Ink)r7  r   rT  r  ink_listr0  r  r  )r  )rQ  r  rl  r,   r   r   r  )r   r  rc  r  r  r   r  r  r  r  r  r  s   `           r&   ink_annotationzFPDF.ink_annotation#  s    * QQQQ&QQQSUVVHQTTN##HQTTN##HQTTN##HQTTN###
%-5=%
 
 
 

 	
49,,Z888r%   c                    | j         st          d          |                     |          }| j        J | j        s3|                     |                     | j        | j                             d|| j        z  dd| j	        |z
  | j        z  ddg}| j
        t          j        k    r'|                    d| j
         d| j        dd           |                    | j                            |           d	           |d
k    r| j        s| j        s| j        r|                     |dd          }|d
k    rb| j        r*|                    |                     |||                     | j        r*|                    |                     |||                     | j        r'| j        }|d|z  z  }|                     ||||           g }| j        | j        k    rH| j        J |                    | j                                                                                    |rdg|z   |z   dgz   }|                     d                    |                     dS )a  
        Prints a character string. The origin is on the left of the first character,
        on the baseline. This method allows placing a string precisely on the page,
        but it is usually easier to use the `FPDF.cell()`, `FPDF.multi_cell() or `FPDF.write()` methods.

        Args:
            x (float): abscissa of the origin
            y (float): ordinate of the origin
            text (str): string to print
            txt (str): [**DEPRECATED since v2.7.6**] string to print

        Notes
        -----

        `text()` lacks many of the features available in `FPDF.write()`,
        `FPDF.cell()` and `FPDF.multi_cell()` like markdown and text shaping.
        rI  Nru  r  r   Td Tr r  rv  r   TFr  g?qQ)r  r]   rP  r$  r%  r  ry  r!  r   r  r1  rY   r0  r  r/  encode_textr  r   rO  rS  _do_underline_do_strikethroughr  _add_quad_pointsr)  r+  r  r   r  )r   r7  r   rc  rx  r  r  attr_ls           r&   rc  z	FPDF.textL  s}   (  	W UVVV""4(( ,,,/ 	UIId--d.?ARSSTTTCAJCCCdfqjDF%:CCCCD>X]**IIE$.EEdoEEEEFFF
		T&22488===>>>BJJDNJd.@J* %%dte%LLArzz> ;IId00Aq99:::% ?IId44Q1==>>>, 2NS1W%%aAq111?do--?...MMT_6688>>@@BCCC 	-"$u,B		#((2,,r%   r  c                    t          j        dt          t                                 || j        }|| j        }| j        dk    r|                     d           || _        |dk    r|t          j	        dz  z  }t          j
        |          }t          j        |          }|| j        z  }| j        |z
  | j        z  }d|dd	|dd	| dd	|dd	|d
d	|d
d| d
d	| d
d}|                     |           dS dS )zR
        .. deprecated:: 2.1.0
            Use `FPDF.rotation()` instead.
        zrotate() can produces malformed PDFs and is deprecated since v2.1.0. It will be removed in a future release. Use the rotation() context manager instead.r   Nr   r  r  q z.5Fr  z.2Fz cm 1 0 0 1 z cm)r   r   r   r3   r7  r   r
  r  r  r  r  r  r   r  )	r   r  r7  r   crE  r  r  outputs	            r&   rotatezFPDF.rotate  sm    	> &((	
 	
 	
 	
 9A9A;!IIcNNNA::TWs]"EAATVB&1*&B2QK 2 2QK 2 2aRK 2 2aK 2 2bK 2 2rK 2 2312 2&(S12 2 2  IIf :r%   c              #      K   || j         }|| j        }|                     t          j        |                               ||                    5  dV  ddd           dS # 1 swxY w Y   dS )a  
        Method to perform a rotation around a given center.
        It must be used as a context-manager using `with`:

            with rotation(angle=90, x=x, y=y):
                pdf.something()

        The rotation affects all elements which are printed inside the indented
        context (with the exception of clickable areas).

        Args:
            angle (float): angle in degrees
            x (float): abscissa of the center of the rotation
            y (float): ordinate of the center of the rotation

        Notes
        -----

        Only the rendering is altered. The `FPDF.get_x()` and `FPDF.get_y()` methods are
        not affected, nor the automatic page break mechanism.
        The rotation also establishes a local graphics state, so that any
        graphics state settings changed within will not affect the operations
        invoked after it has finished.
        N)r7  r   	transformr?   
rotation_dabout)r   r  r7  r   s       r&   rotationzFPDF.rotation  s      : 9A9A^^I0%88>>q!DDEE 	 	EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A##A'*A'axayc           	   #     K   d}|| j         }|| j        }t          t          t	          j        |t          j        dz  z            |          |           }t          t          t	          j        |t          j        dz  z            |          |           }|                     t          j	        | |           
                    ||                    5  dV  ddd           dS # 1 swxY w Y   dS )a  
        Method to perform a skew transformation originating from a given center.
        It must be used as a context-manager using `with`:

            with skew(ax=15, ay=15, x=x, y=y):
                pdf.something()

        The skew transformation affects all elements which are printed inside the indented
        context (with the exception of clickable areas).

        Args:
            ax (float): angle of skew in the horizontal direction in degrees
            ay (float): angle of skew in the vertical direction in degrees
            x (float): abscissa of the center of the skew transformation
            y (float): ordinate of the center of the skew transformation
        l        Nr  )r7  r   rl  r  r  r  r  r  r?   shearingr  )r   r  r  r7  r   lim_vals         r&   skewz	FPDF.skew  s%     2 9A9ATXbDGcM233W==xHHTXbDGcM233W==xHH^^I.sRC88>>q!DDEE 	 	EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   C))C-0C-originc           
   #   R  K   |\  }}	 t          |t          t          f          r't          t          j        |          j                  }nt          |          }n# t          $ r t          |          }Y nw xY wt          j        t          j	        |dz                      }t          j
        t          j	        |dz                       }|                     t          |||| dd                              ||                    5  dV  ddd           dS # 1 swxY w Y   dS )a+  
        Method to perform a reflection transformation over a given mirror line.
        It must be used as a context-manager using `with`:

            with mirror(origin=(15,15), angle="SOUTH"):
                pdf.something()

        The mirror transformation affects all elements which are rendered inside the indented
        context (with the exception of clickable areas).

        Args:
            origin (float, Sequence(float, float)): a point on the mirror line
            angle: (fpdf.enums.Angle): the direction of the mirror line
        r   r   N)r   r   rD   r   rI  r  r  r  r  r  r  r  r?   r  )r   r  r  r7  r   r-  r  r>  s           r&   mirrorzFPDF.mirror  s`     & 1	!%#u.. %el511788e 	! 	! 	!%LLEEE	! HT\%!),,--Xdl519--...^^IaAr1a88>>q!DDEE 	 	EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s$   AA A87A8
DD #D r  c              #   l  K   |                                  5  t          j        | j        | j                                       d| j                  }|                                |z  |z  }|                    d          \  }}|                     |           dV  ddd           dS # 1 swxY w Y   dS )a  
        Apply a transformation matrix to the current graphics state.
        This context manager isolates the transformation so it doesn't affect
        rendering outside the 'with' block.

        It automatically handles the conversion from FPDF's User Units (usually mm, top-left origin)
        to PDF Device Units (points, bottom-left origin).

        Args:
            transform (fpdf.drawing_primitives.Transform): The transformation matrix to apply.
        r   N)	rf  r?   scalingr   	translater  inverser`  r  )r   r  user_to_pdfadjusted_transformcommandr  s         r&   r  zFPDF.transform  s       !! 	 	#+DFTVG<<FFq$)TTK!,!4!4!6!6!B[!P+22488JGQIIgEEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   BB))B-0B-c              +      K   | j         rt          d          |                                   | j        di | dV  |                                  |                                  dS )a2  
        Creates a local graphics state, which won't affect the surrounding code.
        This method must be used as a context manager using `with`:

            with pdf.local_context():
                set_some_state()
                draw_some_stuff()

        The affected settings are those controlled by GraphicsStateMixin and drawing.GraphicsStyle:

        * allow_transparency
        * auto_close
        * blend_mode
        * char_vpos
        * char_spacing
        * dash_pattern
        * denom_lift
        * denom_scale
        * draw_color
        * fill_color
        * fill_opacity
        * font_family
        * font_size
        * font_size_pt
        * font_style
        * font_stretching
        * intersection_rule
        * line_width
        * nom_lift
        * nom_scale
        * paint_rule
        * strikethrough
        * stroke_cap_style
        * stroke_join_style
        * stroke_miter_limit
        * stroke_opacity
        * sub_lift
        * sub_scale
        * sup_lift
        * sup_scale
        * text_color
        * text_mode
        * text_shaping
        * underline

        Font size can be specified in document units with `font_size` or in points with `font_size_pt`.

        Args:
            **kwargs: key-values settings to set at the beginning of this context.
        z@cannot create a local context inside an unbreakable() code blockNr$   )r  r]   r*  r+  r-  r.  )r   r   s     r&   rf  zFPDF.local_context$  s      j  	R   	   !!++F+++!!!r%   r  r  r/  r'  r)  r+  r.  c	                    d|	v r$|t          d          |	d         | j        z  }|	d= d}
|	                                D ]\  }}|dv rt          d| d          |t          j        v r=|
t                      }
t          |
||           |dk    r|                     d           g|d	v rt          | ||           }t          d|           |
rc| j                            |
          }|J | j        	                    t          j        || j                   |                     d
| d           n|                     d           |||.|                     |p| j        || j        n||p| j                   ||                     |           ||                     |           ||                     |           ||                     |           |t-          |t.                    rU|                     |                    dd          |                    dd          |                    dd                     dS |                     |d         |d         |d                    dS dS )z
        This method starts a "q/Q" context in the page content stream,
        and inserts operators in it to initialize all the PDF settings specified.
        r  Nz0font_size & font_size_pt cannot be both provided)rt  rv  ru  rs  zUnsupported setting: zH - This can be controlled through dash_pattern / draw_color / line_width
blend_moder   )	char_vposr#  r$  
denom_liftdenom_scaler"  nom_lift	nom_scaler   sub_lift	sub_scalesup_lift	sup_scaler1  r  r  r%  zq /z gsr  r   r   r   r   r'   r   )r  r   r\  r7   MERGE_PROPERTIESsetattrrM  rP  register_graphics_stylerj  rT   r  r   r  r  r  r  r!  rV  r@  r  rD  r   r-  r  r   )r   r  r  r!  r/  r'  r)  r+  r.  r   rw  rU  r  gs_names                 r&   r+  zFPDF._start_local_contextc  s    $ &   ' !STTT!+.7L{# ,,.. %	@ %	@JC    !yCyyy   m444:&BC''',&&--e444   & c5)))) !>!>!>??? 	,DDRHHG&&&"&&'BGTYWWWII(G((())))IIcNNN #%'MM/t/#-#5:1 1	   !
+++!
+++!
+++!
+++#,-- Y%% $$VQ// $$UA.. $$Wa00     %%l1o|AUVXXXXX $#r%   c                 0    |                      d           dS )zN
        This method ends a "q/Q" context in the page content stream.
        r  N)r  rX  s    r&   r-  zFPDF._end_local_context  s     			#r%   c                     | j         S )a  
        Whenever a page break condition is met, this `@property` method is called,
        and the break is issued or not depending on the returned value.

        The default implementation returns `self.auto_page_break`,
        a value according to the mode selected by `FPDF.set_auto_page_break()`.

        This method is called automatically and should not be called directly by the application.

        Detailed documentation on page breaks: https://py-pdf.github.io/fpdf2/PageBreaks.html
        )r  rX  s    r&   accept_page_breakzFPDF.accept_page_break  s     ##r%   borderr   r'   lnaligncenternew_xnew_yc                 >   | j         st          d          t          |t                    st          |t                    rt	          d          t          |t
                    r(|dvr$t          j        dt                                 d}t          j
        |          }t          j
        |          }t          j
        |          }|t          j        k    rt	          d          |dk    r|d	k    rt          j        }t          j        }nQ|dk    rt          j        }t          j        }n2|d
k    rt          j        }t          j        }nt	          d| d          t          j        d| d|j         d|j         dt(          t                                 |                     |          }| j        r|                     ||
          n|                     ||
          }|| j        n|}|                     t7          |d	d	|||d          |||||||	|
	  	        S )a
  
        Prints a cell (rectangular area) with optional borders, background color and
        character string. The upper-left corner of the cell corresponds to the current
        position. The text can be aligned or centered. After the call, the current
        position moves to the selected `new_x`/`new_y` position. It is possible to put a link
        on the text. A cell has an horizontal padding, on the left & right sides, defined by
        the.c_margin property.

        If automatic page breaking is enabled and the cell goes beyond the limit, a
        page break is performed before outputting.

        Args:
            w (float): Cell width. Default value: None, meaning to fit text width.
                If 0, the cell extends up to the right margin.
            h (float): Cell height. Default value: None, meaning an height equal
                to the current font size.
            text (str): String to print. Default value: empty string.
            border: Indicates if borders must be drawn around the cell.
                The value can be either a number (`0`: no border ; `1`: frame)
                or a string containing some or all of the following characters
                (in any order):
                `L`: left ; `T`: top ; `R`: right ; `B`: bottom. Default value: 0.
            new_x (fpdf.enums.XPos, str): New current position in x after the call. Default: RIGHT
            new_y (fpdf.enums.YPos, str): New current position in y after the call. Default: TOP
            ln (int): **DEPRECATED since 2.5.1**: Use `new_x` and `new_y` instead.
            align (fpdf.enums.Align, str): Set text alignment inside the cell.
                Possible values are: `L` or empty string: left align (default value) ;
                `C`: center; `X`: center around current x position; `R`: right align
            fill (bool): Indicates if the cell background must be painted (`True`)
                or transparent (`False`). Default value: False.
            link (str): optional link to add on the cell, internal
                (identifier returned by `FPDF.add_link`) or external URL.
            center (bool): center the cell horizontally on the page.
            markdown (bool): enable minimal markdown-like markup to render part
                of text as bold / italics / strikethrough / underlined.
                Supports `\` as escape character. Default to False.
            txt (str): [**DEPRECATED since v2.7.6**] String to print. Default value: empty string.

        Returns: a boolean indicating if page break was triggered
        rI  jParameter 'w' and 'h' must be numbers, not strings. You can omit them by passing string content with text=r!  HInteger values for "border" parameter other than 1 are currently ignoredr   r'   zGcell() only produces one text line, justified alignment is not possibler   r   r   "Invalid value for parameter "ln" (z"), must be an int between 0 and 2.=The parameter "ln" is deprecated since v2.5.2. Instead of ln= use new_x=XPos., new_y=YPos.rM  NF
text_widthnumber_of_spacesr#  r  	max_widthtrailing_nl)r%  r&  r  r  r$  prevent_font_change)r  r]   r   r   r  r   r   r   r3   r[   rI  r\   rC   JRIGHTTOPLMARGINNEXTLEFTr  r   rP  r  rR  _preload_font_stylesr  _render_styled_text_lineru   )r   r  r  rc  r   r"  r#  r  r  r$  rG  r%  r&  styled_txt_fragsline_heights                  r&   cellz	FPDF.cell  s   r  	W UVVVa 	As!3!3 	J   fc"" 	vV';';MZ*,,    FE""E""U##EGY   Qww
q	q		 7 7 7 7   Ma&(a a:?*a aSXS]a a a #*,,    ""4((  ;D,,T8<<<**4:: 	
 )*	dnnq,, !""!    (# - 
 
 	
r%   	text_linepaddingr3  c                 T   t          |t                    r)|dvr%t          j        dt	                                 d}n9t          |t
                    r$t          |                              d          rd}|	t          dddd          }	t          d          x}}|	j
        dk    r| j        }|	j        dk    r| j        }|j        }|s9t          |j                  D ]$\  }}|                    |dk              }||z  }%|j        }||j        st%          d	          ||z   |z   }n|dk    r| j        | j        z
  | j        z
  }|r| j        | j        |z
  d
z  z   | _        n(|j        t2          j        k    r| xj        |d
z  z  c_        d}|                                }|D ]#}t9          j        |j        |          r|j        }$||}|                     |          }g }| j         }| j        |	j
        z
  |z  }| j        |z   |	j        z   |z  }| j!        | j"        z
  |	j#        z   |z  }| j!        | j"        |z   z
  |	j$        z
  |z  }|r8|dk    rdnd}|%                    |dd|dd||z
  dd||z
  dd| 	           n1|dk    r+|%                    |dd|dd||z
  dd||z
  dd           t          |t
                    rd|v r%|%                    |dd|dd|dd|dd           d|v r%|%                    |dd|dd|dd|dd           d|v r%|%                    |dd|dd|dd|dd           d|v r%|%                    |dd|dd|dd|dd           | j&        r"| '                    | j        | j"        ||           | j        }d}dx}}d} tP          j)        }!| j*        }"| j+        }#| j,        }$| j-        }%| j.        }&| j/        }'d}(| j0        })|r|j        t2          j1        k    r	||z
  |z
  }*n*|j        t2          j2        t2          j        fv r	||z
  d
z  }*n|}*||*z  }d}+|j        t2          j3        k    r|j4        r||z
  |z
  |z
  |j4        z  }+|%                    d| j        |*z   |z  dd| j!        | j"        z
  d|z  z
  d|z  z
  |z  dd           g },g }-t          |          D ]\  }}t          |tj                    r%| j6        | j7                 8                    |           |j9        |)k    rF|j9        })|)J |%                    |):                                ;                                           d}(|+r|j.        dk    r|+dz  |j.        z  }n|+}|&|j.        k    r%|j.        }&|%                    |j.        dd           |'|j/        k    r%|j/        }'|%                    |j/        dd           | j<        s|
ro|j=        }"|j+        }#|j,        }$|%                    d |"j>         d|#dd!           | j?        @                    t          jB        |"j>        | j7                   |jC        }!n|j=        x}"| _*        |j+        x}#| _+        |j,        x}$| _,        | D                    | E                    |"|#                     |jC        }!ns|"|j=        k    s!|#|j+        k    s|$|j,        k    s|!|jC        k    rG|j=        }"|j+        }#|j,        }$|%                    | E                    |"|#d"                     |jC        }!|jF        }.|.| k    r|%                    |.dd#           |.} |j-        t          jH        k    s|j-        |%k    r-|j-        }%|%                    |j-         d$|jI        dd%           |J                    |||+| j        |*z   |z   | j"        d|z  d|z  z   z   | j!                  }/|/r|%                    |/           |                    |dk              |+|jK        L                    d          z  z   }0|jM        r.|,%                    | j        |*z   |z   |0|j=        |j        f           |jN        r.|-%                    | j        |*z   |z   |0|j=        |j        f           |jO        rE| O                    | j        |*z   |z   | j"        d|z  z   d|j        z  z
  |0|j        |jO        &           |jP        s|}||0z  }|%                    d'           |,rF|,D ]C\  }1}2}3}4|%                    | Q                    |1| j"        d|z  z   d|4z  z   |2|3                     D|-rF|-D ]C\  }1}2}3}4|%                    | R                    |1| j"        d|z  z   d|4z  z   |2|3                     D|r<| O                    | j        |*z   | j"        d|z  z   d|j        z  z
  ||j        |           |r|dk    sZ| dk    sT|!tP          j)        k    sD|"| j*        k    s9|#| j+        k    s.|$| j,        k    s#|%| j-        k    s|(s|&| j.        k    s|'| j/        k    rd(dS                    |           d)}5ndS                    |          }5| D                    |5           |p| j        | _T        |t          jV        k    r| xj        |z  c_        n|t          jW        k    r|| _        n|t          jX        k    r||z   | _        n|t          jY        k    r|r||z   |z
  | _        ng|| _        n_|t          jZ        k    r||d*z  z   | _        nA|t          j[        k    r| j        | _        n$|t          j\        k    r| j        | j        z
  | _        |t          j^        k    r| xj"        |z  c_"        |t          j_        k    r| j`        | _"        |t          ja        k    r| j!        | jb        z
  | _"        |S )+a  
        Prints a cell (rectangular area) with optional borders, background color and
        character string. The upper-left corner of the cell corresponds to the current
        position. The text can be aligned, centered or justified. After the call, the
        current position moves to the requested new position. It is possible to put a
        link on the text.

        If automatic page breaking is enabled and the cell goes beyond the limit, a
        page break is performed before outputting.

        Args:
            text_line (TextLine instance): Contains the (possibly empty) tuple of
                fragments to render.
            h (float): Cell height. Default value: None, meaning an height equal
                to the current font size.
            border: Indicates if borders must be drawn around the cell.
                The value can be either a number (`0`: no border ; `1`: frame)
                or a string containing some or all of the following characters
                (in any order):
                `L`: left ; `T`: top ; `R`: right ; `B`: bottom. Default value: 0.
            new_x (fpdf.enums.XPos): New current position in x after the call.
            new_y (fpdf.enums.YPos): New current position in y after the call.
            fill (bool): Indicates if the cell background must be painted (`True`)
                or transparent (`False`). Default value: False.
            link (str): optional link to add on the cell, internal
                (identifier returned by `FPDF.add_link`) or external URL.
            center (bool): center the cell horizontally on the page.
            padding (Padding or None): optional padding to apply to the cell content.
                If padding for left and right is non-zero then c_margin is ignored.
            prevent_font_change (bool): ensure no font settings (family / size / style)
                change during this call.

        Returns: a boolean indicating if page break was triggered
        r!  r)  r   r'   LTRBNr   )
initial_cszA'text_line' must have fragments if 'text_line.text_width' is Noner   rS  fr  r  r  z re SLr  r  Tr   g        Fru  g      ?g333333?r  Tr   z Tzz Tcrs  rt  )rq  z Tsr  r  )r7  r   r  r  r  ETr  z Qg       @)cr   r   r   r   r3   r   r  
issupersetr   r   r  r;  r  r/  	enumerate	fragmentsrK  r1  r  r  r  r7  r8  r  r#  rC   Xget_ordered_fragmentsr   greater_thanr  _perform_page_break_if_need_ber   r  r   r  bottomr  rO  r  rH   LINEr$  r!  r  r1  r"  r#  r)  r   Cr4  r0  rv   r   r   add_text_substitutionr+  r  r   r%  r   r  rP  rj  rT   rw  r  r  ry  liftrY   r0  r/  render_pdf_text
characterscountr  r   r  rt  r  r  r  r  r[   r5  STARTENDWCONTCENTERr7  RMARGINr\   r8  TMARGINr9  BMARGINr  )6r   r?  r  r   r%  r&  r  r  r$  r@  r3  
l_c_margin
r_c_marginstyled_txt_widthr  rN  unscaled_widthr  max_font_sizerJ  page_break_triggeredrx  r   r  r  r  rO  ops_starts_width
current_wsfrag_wscurrent_liftcurrent_char_vposr$  current_font_size_ptcurrent_font_stylecurrent_text_modecurrent_font_stretchingcurrent_char_spacingfill_color_changedlast_used_colordxword_spacing
underlinesstrikethroughsrS  r_text
frag_widthstart_xrT  r   r  rE  s6                                                         r&   r;  zFPDF._render_styled_text_linea  sY   ^ fc"" 	vV';';MZ*,,    FF$$ 	V)?)?)G)G 	F?aAq))G"'((*
Z<1J=AJ$/ 	3$Y%899 3 34!%16!B!B N2  9&  W   !:-
:AA!VV&/A 	]dhla%77DFF_''FFa!eOFF 3355	 	/ 	/D*4>=II / $9A#BB1EEF %*!gm+q0v,1&DFQJ''.8A= 	V!BIIWWWCWWWeDjWWWvczWWWSUWWXXXXq[[IITTTCTTTeDjTTTvczTTTTUUU fc"" 	Uf}}		TOOOOOODOOOvOOOOPPPf}}		TMMMMMMEMMMMMMMNNNf}}		UQQQQQQUQQQQQQQRRRf}}		TSSSSSSuSSS6SSSSTTT( 	8!!$&$&!Q777&""
W$M(#0!_ N"&"6#0"/ _	%'))^&66UWeg$666**a/rMG"#L%'))i.H)
NZ/2BB. / IIRtv{a'. R RFTVOcAg-m0CCqHQR R R   PRJSUN$Y// l& l&4d$BCC FJty)??EEE?o55&*oO*666IIo7799??AABBB)-& +D$8C$?$?*S043GGGG*G*d.BBB.2.B+II!5>>>>???'4+<<<+/+<(II!2;;;;<<<7 +7* ;'+y/3/@,-1_*		"U|~"U"U8L"U"U"U"UVVV.22+0,.$)   -1N)) <@9Dt'8CGCTT,t/@?CN*T_		 33 , 4    -1N)) DI--+t/@@@)T_<<(DN:: $(9L+/+<()-&II//(005 0     )-%y<''II....///#'LNhm33~):::(,%IILLT_LLLLMMM-- FRK')FcAgm(;;<F   &IIf%%%!^^ Av ,   4?#8#8#=#==>
 > %%"w.
DIt~V   % "))"w.
DIt~V   9 II&2+/&C!G,dn0DE$.!Y     ' )!(J:%IIdOOO  7A  3GUD)II**#TVsQw%73?%KUTX    
  7E  3GUD)II..#TVsQw%73?%KUTX    
  		FRKFQw  .) %N    	
 c!!3&&$554#444'4+<<<%88$66% 7*d.BBB'4+<<<)")))HHRLLIIaLLL )4> DJFFaKFFFdj  DFFdhw&DFFdj   ! 7*Z7 dk!!w},DFFdl""]DFFdl""Vdm+DF DIFFaKFFDL  ]DFDL  Vdm+DF##r%   c                 8   | j         | j                                     || j        z  | j        |z
  | j        z  ||z   | j        z  | j        |z
  | j        z  || j        z  | j        |z
  |z
  | j        z  ||z   | j        z  | j        |z
  |z
  | j        z  g           d S rV  )rQ  r   extendr   r  r   r7  r   r  r  s        r&   r  zFPDF._add_quad_points  s    ty)00DF
!tv%Q$& !tv%DF
!a46)Q$& !a46)		
 	
 	
 	
 	
r%   c                 n   | j         s|                     ||          S | j         d         r| j         d         nt          |          }t          ||          }|                                }|j        | j         d<   g }|D ](\  }}|| j         d<   ||                     ||          z  })t          |          S )zh "
        Break the text into bidirectional segments and preload font styles for each fragment
        r  )rc  base_directionr  r  )r  r:  r0   r/   get_bidi_fragmentsr}  r  )	r   rc  rG  r  	paragraphdirectional_segmentsrJ  	bidi_textbidi_directions	            r&   rR  z FPDF._preload_bidirectional_text  s       	=,,T8<<<  -2Dk**+D11 	 "t<OPPP	(;;==3<3K/0$&	)= 	H 	H%I~6DD23229hGGGIIYr%   c                    |st                      S | j        }| j        r|dz  }| j        r|dz  }t          |                     ||                    }|r| j        }d| _        t          d |D                       r|                     d           t          d |D                       r|                     d           t          d	 |D                       r|                     d
           t          d |D                       r|                     d           |D ]!}| j        |j	        |j        z            |_
        "|                     |           || _        |S )aS  
        When Markdown styling is enabled, we require secondary fonts
        to ender text in bold & italics.
        This function ensure that those fonts are available.
        It needs to perform Markdown parsing,
        so we return the resulting `styled_txt_frags` tuple
        to avoid repeating this processing later on.
        ro  rn  r   c              3   ,   K   | ]}|j         d k    V  dS )rS  Nr  rL  s     r&   rO  z,FPDF._preload_font_styles.<locals>.<genexpr>  )      GGd4?c)GGGGGGr%   rS  r  c              3   ,   K   | ]}|j         d k    V  dS )rT  Nr  rL  s     r&   rO  z,FPDF._preload_font_styles.<locals>.<genexpr>  r  r%   rT  c              3   ,   K   | ]}|j         d k    V  dS rO  r  rL  s     r&   rO  z,FPDF._preload_font_styles.<locals>.<genexpr>  s)      HHt4?d*HHHHHHr%   rP  c              3   ,   K   | ]}|j         d k    V  dS )r   Nr  rL  s     r&   rO  z,FPDF._preload_font_styles.<locals>.<genexpr>
  s)      FFT4?b(FFFFFFr%   r   )r  r  r  r   _parse_charsr   rZ  r  rY  r  r   )r   rc  rG  prev_font_styler<  r   rN  s          r&   r:  zFPDF._preload_font_styles  s     	77N/> 	#s"O 	#s"O !2!24!B!BCC 	9D DIGG6FGGGGG )C(((GG6FGGGGG )C(((HH7GHHHHH *D)))FF5EFFFFF (B'''( K K Jt'7$/'IJ		MMM000DIr%   charc                      t          j        |           fd j        D             }|sdS t           fd|D             d          }|r|S  j        rdS |d         S )z
        Returns which fallback font has the requested glyph.
        This method can be overridden to provide more control than the `select_mode` parameter
        of `FPDF.set_fallback_fonts()` provides.
        c                 V    g | ]%}t                    j        |         j        v #|&S r$   )ordrY  cmap)rM  font_idr  r   s     r&   
<listcomp>z*FPDF.get_fallback_font.<locals>.<listcomp>  s>     
 
 
4yyDJw/444 444r%   Nc              3   H   K   | ]}j         |         j        k    |V  d S rV  )rY  rp  )rM  r   rp  r   s     r&   rO  z)FPDF.get_fallback_font.<locals>.<genexpr>#  s7      WWdD1A1Jh1V1VT1V1V1V1VWWr%   r   )rW   rI  rF  nextrG  )r   r  r  fonts_with_charfont_with_matching_emphasisrp  s   ``   @r&   get_fallback_fontzFPDF.get_fallback_font  s      &u--
 
 
 
 
2
 
 

  	4&*WWWWWoWWW'
 '
# ' 	/..* 	4q!!r%   c           	   #      K   |sщ j         sʉ j        sÉ j        rt          |                     j                            D ]f\  }}|dk    r/t           j                                          j                  V  |r*t          |                                  j                  V  gdS t          |                                  j                  V  dS g d j	        v d j	        v t           j                  t           j                  dddt          f fd} j        r j        j        }ng }d}d}|r{|r!|d          j        k    r|dz  }|dd         }&|r|r|dd          j         j         j         j        fv }	|	rO|dz  dk    rFt+          |dz
            D ]}
                     j                   rr |            V  dd}d}t+          |          D ]}
                     j                   d}|dd          j         j         j         j        fv }|r|rd	}|d         }t/          |d                   }|t0          j        t0          j        fvrrr |            V  | j        r|dt7           j                            j        k    r}r |            V                                   }rdnd
rdnd
z   |_	        |_        |_        t           j        | j                  V  |t7           j                  d         }|r|rrd         |k    rt7          |          dk     s|d         |k    rrr |            V  |dd          j        k    r |dd          j        k    r |dd          j        k    r |dd          j        k    r |dd         } j                            |          }|r|                                \  }}}r |            V                                   } j        |_         j         rtC           j                   |_"        	 tG          |          } $                    |          }n# tJ          $ r Y nw xY wt          tM          |          | j        |          V  p j        r|d         dk    rtO          |d                   |vrrdnd
rdnd
z   } (                    |d         |          }|rd|k    r'                    |d                    |dd         }r |            V  |                    |d                    |dd         })rr |            V  d                    |d                    |dd         }|r|r|dz  }|dk    r |            V  |{|r0|r.t+          |          D ]}
                     j                   d}r |            V  dS dS )zSplit text into fragmentsr   NrS  rT  r   c                  ~   
                                 } rdndrdndz   | _        | _        	| _        rmd                    d D                       }                    dd                              dd          }|| _        || _        
j                 | _        d d t          | 
j
                  }g |S )NrS  r   rT  c              3   "   K   | ]
}|d v |V  dS rO  r$   )rM  r  s     r&   rO  z2FPDF._parse_chars.<locals>.frag.<locals>.<genexpr>P  s&      PPaA$KKKKKKPPr%   )_get_current_graphics_stater  r   r  r  rm  r  rY  r$  rs   r   )gstater  r   fragmentcurrent_fallback_fontcurrent_text_scriptin_bold
in_italicsin_strikethroughin_underliner   txt_frags       r&   rN  zFPDF._parse_chars.<locals>.fragI  s    5577F(/!7R:<UCCSU VF#3F +F$ +PP+@PPPPP.66sB??GGRPP%+"$)!&*j1F&G#(,%&*# H
 HOr%   r'   r   Fr   r  r   r8  )r  
))r  rF  r  rI  splitrv   r  r   rs   r  r   r   r  rt  r$  r  MARKDOWN_ESCAPE_CHARACTERMARKDOWN_BOLD_MARKERMARKDOWN_ITALICS_MARKERMARKDOWN_STRIKETHROUGH_MARKERMARKDOWN_UNDERLINE_MARKERr  r  r   r   COMMONUNKNOWNr  MARKDOWN_LINK_REGEXmatchgroupsMARKDOWN_LINK_UNDERLINEMARKDOWN_LINK_COLORr@   r+  r   r  r  r   r  r  )r   rc  rG  seqfragment_textrN  font_glyphsescape_next_marker
escape_runis_escape_targetr  	is_markerhalf_markertext_scriptr  is_link	link_text	link_destr   r  r  r  r  r  r  r  r  r  s   `                    @@@@@@@r&   r  zFPDF._parse_chars,  s<      	 1 	$:Q 	& *3JJt677+ +  &C Qww< 3 <<>> F    
 % &)4+K+K+M+Mtv     4!A!A!C!CTVLLLLLF t.$/1
!%d&8!9!9!$.11 $"	h 	 	 	 	 	 	 	 	 	 	 	 	 	,  	+0KKK
 B	! DGt'EEEa
ABBx J #'8-062	0 $  $ 	
Q!(;(;":>22 H H (FGGGG, 5# )"&$&&LLL04-)*&!"Jz** D DAOOD$BCCCC
RaR),2.	% I  ". "!	q'K,T!W55K$%##  
  ! 3 !$&&LLL&1#& 6#d566674;RRR %"dff!==??F07)?R)1r)F% ,<F('3F$8/    
  D$; < < > >?D  )%)1")D)DTQ$q'[*@*@ %"dffBQBx4#<<<&-+BQBx4#???)3^
BQBx4#EEE/?+?(BQBx4#AAA+7'78D288>> 181A1A.Iy$ %"dff!==??F'+'CF$/ ,C 4- -)"9~~$(MMtM$<$<		%   "Y&	       DGtOOCQLLK<W<W '/R:4MCC2N $ 6 6tAw F F  
$(=== Q000#ABBx  %"dff,9)OODG,,,8D$ - !$&&LLL(,%OODG$$$8D !. !"a'"%**$&&LLLE  B	!F  	
 	:&& @ @ >????J 	$&&LLLLL	 	s   %R 
RRr  c                 F    | j         |z   | j        k    o| j         o| j        S )a  
        Let you know if adding an element will trigger a page break,
        based on its height and the current ordinate (`y` position).

        Detailed documentation on page breaks: https://py-pdf.github.io/fpdf2/PageBreaks.html

        Args:
            height (float): height of the section that would be added, e.g. a cell

        Returns: a boolean indicating if a page break would occur
        )r   r  r  r  )r   r  s     r&   will_page_breakzFPDF.will_page_break  s2     FVOd55 'N"'&	
r%   c                     |                      |          rCt                              d| j        | j        || j                   |                                  dS dS )Nz;Page break on page %d at y=%d for element of height %d > %dTF)r  r  debugr   r   r  _perform_page_breakr   r  s     r&   rN  z#FPDF._perform_page_break_if_need_be  sb    "" 		LLM	'   $$&&&4ur%   c                 6   | j         }g }|                                 rc|                    |                                            |                                  |                                  |                                 cd| _        |                                  |                     d           |                                  t          |          D ]<}|                                  d|_         | j
        di |                                 =|| _         dS )z
        Performs a page break, taking care to preserve self.x
        and a potential existing `fpdf.fpdf.FPDF.local_context()`.
        A call to `fpdf.fpdf.FPDF.will_page_break()` should be performed beforehand.
        FT)r  Nr$   )r7  !_is_current_graphics_state_nestedr  r  r.  r-  r%  r*  r(  reversedr+  	as_kwargs)r   r7  gs_stackprev_gss       r&   r  zFPDF._perform_page_break  s&    F *,4466 	&OOD<<>>???!!### ##%%% 4466 	& ,1(   4   )) 	= 	=G""$$$27G/%D%<<(9(9(;(;<<<<r%   c                 "    | j         | j        k    S rV  )r  r   rX  s    r&   r  zFPDF._has_next_page,  s    $)++r%   c              #     K   t          | j        t          j                  sd V  d S d | _        | j        | j        | j        | j        f\  }}}}| j        | j                 j	        pt                      }|                                  	 d V  |                                  t          |dz   | j        dz             D ]
}| j        |= || _        || j        | j                 _	        |                     ||           | `d S # |                                  t          |dz   | j        dz             D ]
}| j        |= || _        || j        | j                 _	        |                     ||           | `w xY w)Nc                      d S rV  r$   )r   r   s     r&   <lambda>z'FPDF._disable_writing.<locals>.<lambda>6  s    D r%   r'   )r   r  types
MethodTyper   r  r7  r   r   annotsr   r*  r.  r  set_xy)r   	prev_pageprev_pages_countprev_xprev_yr  ps          r&   _disable_writingzFPDF._disable_writing/  s     $)U%566 	 EEEF00	IFF	7
3	#VV DI&-;   	EEE!!###+a/1AA1EFF " "JqMM!DI+1DJty!(KK'''			 !!###+a/1AA1EFF " "JqMM!DI+1DJty!(KK'''	MMMMs   	C? ?A2E1MultiCellPageBreakResultMultiCellLinesResultMultiCellHeightResultMultiCellResultr   max_line_heightprint_shwrapmoder   r  c                    t          j        |          }t          j        |          }|r(t	          j        dt          t                                 |s|rb|                                 5  | 	                    ||||||||	|
|||||dd|rt          j        n|||          cddd           S # 1 swxY w Y   | j        st          d          t          |t                    st          |t                    rt!          d          t#          j        |          }t%          j        |          }|	dk    r|	d	k    rt"          j        }t$          j        }np|	d
k    rt"          j        }t$          j        }nQ|	dk    rt"          j        }t$          j        }n2|	dk    rt"          j        }t$          j        }nt!          d|	 d          t	          j        d|	 d|j         d|j         dt          t                                 t3          j        |          }d}|| j        }|d	k    r| j        | j        z
  | j        z
  }| j        | j        }}||j        z
  |j         z
  x}}g }|j         s|!                    | j"                   |j        s|!                    | j"                   |t2          j#        k    r| xj        |j         z  c_        | xj        |j$        z  c_        |r;|t2          j#        k    r
| j        dz  n| j%        | j&        |z
  dz  z   | _        | j        }| '                    |          }|(                    dd          }| j)        r| *                    ||          n| +                    ||          }| j,        }| j-        }| j.        }d	}g }t_          ||||||          } | 0                                }!|!+|!                    |!           | 0                                }!|!+|stc          g d	d	|||d          g}|
te          |          d
k    r|}"ntg          ||
          }"|p|}#d}ti          |          D ]\  }$}!| 5                    ||j6        z             }%|%rd}| xj        |j$        z  c_        |#r|$d	k    s|%r| j        }&|j6        | j7        z   }'tq          | j9        |&z
  |'z
  |"z            }(tg          |(te          |          |$z
            })tu          ||$|"z  z
  |)|"z            }*| j        |t2          j#        k    r|dz  nd	z
  }+tw          | |+|j         z
  | j        |j$        z
  |+|z   |j        z   | j        |*z   |j6        z   ||r| j<        nd           |$te          |          d
z
  k    },| =                    |!|"|,r|nt"          j        |,r|nt$          j        d	d|t          d	|j        d	|j                   |	  	         ||"z  }|,s|t2          j#        k    r|| _        ||k     r%|t$          j        k    r| xj        ||z
  z  c_        |}|r|t$          j        k    r| j        }|d         }-|-r5|-j>        r.|t$          j?        t$          j        fv r| @                                 |t$          j        k    r|| _        n%|t$          j        k    r| xj        |j6        z  c_        |r|| _-        || _,        || _.        |t"          j        k    r| xj        |j        z  c_        n%|t"          j        k    r| xj        |j         z  c_        t          j        |          }d}.|t          jA        z  r|.|fz  }.|t          j        z  r[g }/|D ]P}!g }0|!jB        D ]}1|0C                    |1jD                   |/!                    dE                    |0                     Q|.|/fz  }.|t          jF        z  r|.||j$        z   |j6        z   fz  }.te          |.          d
k    r|.d	         S |.S )ab  
        This method allows printing text with line breaks. They can be automatic
        (breaking at the most recent space or soft-hyphen character) as soon as the text
        reaches the right border of the cell, or explicit (via the `\n` character).
        As many cells as necessary are stacked, one below the other.
        Text can be aligned, centered or justified. The cell block can be framed and
        the background painted. A cell has an horizontal padding, on the left & right sides,
        defined by the.c_margin property.

        Args:
            w (float): cell width. If 0, they extend up to the right margin of the page.
            h (float): height of a single line of text.  Default value: None, meaning to use the current font size.
            text (str): string to print.
            border: Indicates if borders must be drawn around the cell.
                The value can be either a number (`0`: no border ; `1`: frame)
                or a string containing some or all of the following characters
                (in any order):
                `L`: left ; `T`: top ; `R`: right ; `B`: bottom. Default value: 0.
            align (fpdf.enums.Align, str): Set text alignment inside the cell.
                Possible values are:
                `J`: justify (default value); `L` or empty string: left align;
                `C`: center; `X`: center around current x position; `R`: right align
            fill (bool): Indicates if the cell background must be painted (`True`)
                or transparent (`False`). Default value: False.
            split_only (bool): **DEPRECATED since 2.7.4**:
                Use `dry_run=True` and `output=("LINES",)` instead.
            link (str): optional link to add on the cell, internal
                (identifier returned by `add_link`) or external URL.
            new_x (fpdf.enums.XPos, str): New current position in x after the call. Default: RIGHT
            new_y (fpdf.enums.YPos, str): New current position in y after the call. Default: NEXT
            ln (int): **DEPRECATED since 2.5.1**: Use `new_x` and `new_y` instead.
            max_line_height (float): optional maximum height of each sub-cell generated
            markdown (bool): enable minimal markdown-like markup to render part
                of text as bold / italics / strikethrough / underlined.
                Supports `\` as escape character. Default to False.
            print_sh (bool): Treat a soft-hyphen (\u00ad) as a normal printable
                character, instead of a line breaking opportunity. Default value: False
            wrapmode (fpdf.enums.WrapMode): "WORD" for word based line wrapping (default),
                "CHAR" for character based line wrapping.
            dry_run (bool): if `True`, does not output anything in the document.
                Can be useful when combined with `output`.
            output (fpdf.enums.MethodReturnValue): defines what this method returns.
                If several enum values are joined, the result will be a tuple.
            txt (str): [**DEPRECATED since v2.7.6**] string to print.
            center (bool): center the cell horizontally on the page.
            padding (float or Sequence): padding to apply around the text. Default value: 0.
                When one value is specified, it applies the same padding to all four sides.
                When two values are specified, the first padding applies to the top and bottom, the second to
                the left and right. When three values are specified, the first padding applies to the top,
                the second to the right and left, the third to the bottom. When four values are specified,
                the paddings apply to the top, right, bottom, and left in that order (clockwise)
                If padding for left or right ends up being non-zero then respective c_margin is ignored.

        Center overrides values for horizontal padding

        Using `new_x=XPos.RIGHT, new_y=XPos.TOP, maximum height=pdf.font_size` is
        useful to build tables with multiline text in cells.

        Returns: a single value or a tuple, depending on the `output` parameter value
        zcThe parameter "split_only" is deprecated since v2.7.4. Use instead dry_run=True and output="LINES".r   F)r  r  rc  r   r#  r  r  r"  r  rG  r  r%  r&  r  r   r   r  r$  r@  NrI  r(  r   r   r'   r   r   r*  z"), must be an int between 0 and 3.r+  r,  r-  rM  r   )r#  r  r  r.  T)r  r%  r&  r   r  r  r@  r3  r  r$   )Gr   newrZ   rI  r   r   r   r3   r  
multi_cellrM   LINESr  r]   r   r   r  r[   r\   r5  r8  r7  r9  r6  r  rC   r  r  r  r7  r   r  r  r  r;  rK  r  r8  r  rP  rm  r  rR  r:  r$  r  r  rt   get_lineru   r  r  rI  rN  rO  r  r   r  rl  r   r)  r;  r2  LASTr"  
PAGE_BREAKrJ  rz  rU  r  HEIGHT)2r   r  r  rc  r   r#  r  r   r  r"  r  rG  r  r%  r&  r  r   r  r$  r@  rc  r  r  maximum_allowed_widthclearance_marginsnormalized_stringstyled_text_fragmentsprev_current_fontr  prev_underlinetotal_height
text_linesmulti_line_breakr?  r=  box_requiredtext_line_indexstart_of_new_pagetop_gap
bottom_gaplines_before_break	num_lines
box_heightr7  is_last_line	last_linereturn_valueoutput_linesrU  rN  s2                                                     r&   r  zFPDF.multi_cell[  s`	   j +g&&?8,, 	MD #*,,     	j 	&&((  !$3%%%!$6@L,22f!#' '                 ,  	W UVVVa 	As!3!3 	J   E""E""Qww
	q	q		q
 7 7 7 7   Ma&(a a:?*a aSXS]a a a #*,,    U##$9A 66&/A 
 %&$5$DD)+| 	4$$T]333} 	4$$T]333EGFFgl"FF'+  	#uw..

DMTXPQ\UVDV4V F VF ""4(( LLr22  HD,,->III**+<hGG 	 !-/%'
)!!
 
 
 %--//	%i((((1133I %  	 %& %  
J "c*oo&:&:KKa11K~v$*3J*?*? *	  *	 &OY $ C CADV W W  &'+$'+% A!5!59J!5&$^dm;
%($&7*:Z*GK)W%X%X" 2C
OOo4UVV	 +55y;7N 
 Fu'7'7a!eeQ? $FW[(EGM)FZ''.8'+5DOO   +c*oo.AAL))+:ee+:ee7=!W\BB$, * 
 
 
 K'L  EUW$4$4!	!!!l**L 	ETX$5$5 VFrN	 	. 	5TY	<R3R3RGGIIIDHDFFdiFFgn$FF 	,-DO 1D+DNDJFFgm#FFFdiFFgl"FF")&11%00 	4133L%++ 	,&(L' 9 9	(*
%/ 7 7D%%do6666##BGGJ$7$78888\O+L%,, 	K\GK7'.HJJL|!!?"s   +6B..B25B2c           
         t          j        |          }| j        st          d          t	          |t
                    rt          d          || j        }d}|                     |          	                    dd          }| j
        r|                     |d          n|                     |d          }g }	t          |fd| j        | j        f||          }
| j        | j        z
  | j        z
  }||
                                }| j        | j        z
  | j        z
  }||+|	                    |           |
                                }|+|	sdS t+          |	          D ]S\  }}|d	k    r|                                  |                     ||d	t0          j        t4          j        d|
          }|p|}T||j        r|                                  |S )a  
        Prints text from the current position.
        When the right margin is reached, a line break occurs at the most recent
        space or soft-hyphen character, and text continues from the left margin.
        A manual break happens any time the \n character is met,
        Upon method exit, the current position is left just at the end of the text.

        Args:
            h (float): line height. Default value: None, meaning to use the current font size.
            text (str): text content
            link (str): optional link to add on the text, internal
                (identifier returned by `FPDF.add_link`) or external URL.
            print_sh (bool): Treat a soft-hyphen (\u00ad) as a normal printable
                character, instead of a line breaking opportunity. Default value: False
            wrapmode (fpdf.enums.WrapMode): "WORD" for word based line wrapping (default),
                "CHAR" for character based line wrapping.
            txt (str): [**DEPRECATED since v2.7.6**] text content
        rI  zbParameter 'h' must be a number, not a string. You can omit it by passing string content with text=NFr  r   c                     S rV  r$   )_heightr1  s    r&   r  zFPDF.write.<locals>.<lambda>  s    I r%   )r  r  r   )r  r   r%  r&  r  r  )rZ   rI  r  r]   r   r   r  r  rP  rm  r  rR  r:  rt   r;  r  r7  r  r  r8  r  rI  r"  r;  r[   rY  r\   r6  r2  )r   r  rc  r  r  r  rc  r  r  r  r  first_widthr?  
full_widthr  r
  r1  s                   @r&   writez
FPDF.write  s-   8 ?8,, 	W UVVVa 	H   9A$ //55==dBGG  ED,,->FFF**+<eDD 	 &(
)!%%%%]DM*
 
 
 ftvo5	$--//	Vdm+dm;
	%i((((1133I %  	5*3J*?*? 	D 	D&OY""			44jh 5  H $8#C8   Y%: GGIII##r%   
   r9  imgimg_fill_widthncolsgutterbalance
text_alignr=  r8  r  skip_leading_spacesc                 @    t          | |||||pd||||	|
|||          S )a  Establish a layout with multiple columns to fill with text.
        Args:
            text (str, optional): A first piece of text to insert.
            ncols (int, optional): the number of columns to create. (Default: 1).
            gutter (float, optional): The distance between the columns. (Default: 10).
            balance: (bool, optional): Specify whether multiple columns should end at approximately
                the same height, if they don't fill the page. (Default: False)
            text_align (Align or str, optional): The alignment of the text within the region.
                (Default: "LEFT")
            line_height (float, optional): A multiplier relative to the font size changing the
                vertical space occupied by a line of text. (Default: 1.0).
            l_margin (float, optional): Override the current left page margin.
            r_margin (float, optional): Override the current right page margin.
            print_sh (bool, optional): Treat a soft-hyphen (\u00ad) as a printable character,
                instead of a line breaking opportunity. (Default: False)
            wrapmode (fpdf.enums.WrapMode, optional): "WORD" for word based line wrapping,
                "CHAR" for character based line wrapping. (Default: "WORD")
            skip_leading_spaces (bool, optional): On each line, any space characters at the
                beginning will be skipped if True. (Default: False)
        r  )rc  r  r  r  r  r	  r
  r=  r8  r  r  r  r  )r   )r   rc  r  r  r  r  r	  r
  r=  r8  r  r  r  r  s                 r&   text_columnszFPDF.text_columns  sJ    J )<R!# 3
 
 
 	
r%   dimskeep_aspect_ratioc                    | j         st          d          |r(t          j        dt          t                                 t          | j        ||
          \  }}}t          |t                    r2| 
                    |t          t          |          ||||||||	|          S t          rt          |t                    rJ |                     ||||||||||	|
|          S )a  
        Put an image on the page.

        The size of the image on the page can be specified in different ways:
        * explicit width and height (expressed in user units)
        * one explicit dimension, the other being calculated automatically
          in order to keep the original proportions
        * no explicit dimension, in which case the image is put at 72 dpi.
        * explicit width and height (expressed in user units) and `keep_aspect_ratio=True`

        **Remarks**:
        * if an image is used several times, only one copy is embedded in the file.
        * when using an animated GIF, only the first frame is used.

        Args:
            name: either a string representing a file path to an image, an URL to an image,
                bytes, an io.BytesIO, or a instance of `PIL.Image.Image`
            x (float, fpdf.enums.Align): optional horizontal position where to put the image on the page.
                If not specified or equal to None, the current abscissa is used.
                `fpdf.enums.Align.C` can also be passed to center the image horizontally;
                and `fpdf.enums.Align.R` to place it along the right page margin
            y (float): optional vertical position where to put the image on the page.
                If not specified or equal to None, the current ordinate is used.
                After the call, the current ordinate is moved to the bottom of the image
            w (float): optional width of the image. If not specified or equal to zero,
                it is automatically calculated from the image size.
                Pass `pdf.epw` to scale horizontally to the full page width.
            h (float): optional height of the image. If not specified or equal to zero,
                it is automatically calculated from the image size.
                Pass `pdf.eph` to scale horizontally to the full page height.
            type (str): [**DEPRECATED since 2.2.0**] unused, will be removed in a later version.
            link (str): optional link to add on the image, internal
                (identifier returned by `FPDF.add_link`) or external URL.
            title (str): optional. Currently, never seem rendered by PDF readers.
            alt_text (str): optional alternative text describing the image,
                for accessibility purposes. Displayed by some PDF readers on hover.
            dims (Tuple[float]): optional dimensions as a tuple (width, height) to resize the image
                before storing it in the PDF. Note that those are the **intrinsic** image dimensions,
                but the image will still be rendered on the page with the width (`w`) and height (`h`)
                provided as parameters. Note also that the `.oversized_images` attribute of FPDF
                provides an automated way to auto-adjust those intrinsic image dimensions.
            keep_aspect_ratio (bool): ensure the image fits in the rectangle defined by `x`, `y`, `w` & `h`
                while preserving its original aspect ratio. Defaults to False.
                Only meaningful if both `w` & `h` are provided.

        If `y` is provided, this method will not trigger any page break;
        otherwise, auto page break detection will be performed.

        Returns: an instance of a subclass of `ImageInfo`.
        r   zL"type" parameter is deprecated since v2.2.0, unused and will soon be removedr   )r   r]   r   r   r   r3   rr   r  r   rn   _vector_imager   r   r   _raster_image)r   r  r7  r   r  r  rs  r  r  r  r  r  r  r  s                 r&   r  z
FPDF.image5  s    @ y 	S QRRR 	M6 #*,,    ((8$EEc4dO,, 	%%Y$$!    	2!#y11111!!
 
 	
r%   c           
         d|v r|                      d           |                    ||| j                  \  }}|,|                     |           | j        }| xj        |z  c_        || j        }t          |t                    s|                     |||||          }t          rt          |          }|r|                    ||||          \  }}}}| j        r.|d         dk    r"|s |                     |||||| j                  }t          ||||||| j        | j                  }|	s|
rE|                     |	|
          5  |                     |           d d d            n# 1 swxY w Y   n|                     |           |r|                     |||||           | j                            t*          j        |d         | j                   ||d	<   ||d
<   |S )Nsmaskr   )scaleusagesr'   )r  pdf_height_to_flipr  r  r  rendered_widthrendered_height)rM  size_in_document_unitsr   rN  r   r7  r   r   
x_by_alignr   r   scale_inside_boxr  _downscale_imager   r  _marked_sequencer  r  rP  rj  rT   r  r   )r   r  r  r  r7  r   r  r  r  r  r  r  r  stream_contents                 r&   r  zFPDF._raster_image  sf    d??%%e,,, **1atv*>>1 9//222AFFaKFF9A![)) 	B1a/@AAA 	aA 	;..q!Q::JAq!Q  	NT(^q%8%8%8((sD!Qdf(MMD8!Q1/tvRVRX
 
 
  	&H 	&&&UX&FF * *		.)))* * * * * * * * * * * * * * * IIn%%% 	(IIaAq$'''""$d3i	
 	
 	
 "#"#s   E''E+.E+img_infoc                 8   |r|                     dd||          \  }}}}t          j        |          }|t          j        k    r| j        |z
  dz  S |t          j        k    r| j        |z
  | j        z
  S |t          j        k    r| j        S t          d|           )Nr   r   z*Unsupported 'x' value passed to .image(): )
r  rC   rI  rQ  r  r   r  rE  r8  r  )r   r7  r  r  r!  r  r  s          r&   r  zFPDF.x_by_align  s      	?!221aA>>JAq!QLOO<<FQJ!##<<6A:--<<= IaIIJJJr%   svgc                    |j         s_|j        rX|j        rQt          j        dt                                 t          d          t          d          |j        |j        g|_         |dk    r|dk    r|j        rn|j        rgt          |j        t                    r|j        | j	        z  dz  n|j        }t          |j        t                    r|j        | j
        z  dz  n|j        }n|j         r|j         \  }}}}nt          |t                    rdn|}t          | d          |dk    s|dk    rW|j        r|j        r|j        |j        }}n#|j         r|j         \  }}}}nt          d          |dk    r	||z  |z  }n||z  |z  }|,|                     |           | j        }| xj        |z  c_        || j        }t          |t                     s|                     |||||          }t          |          }|r|                    ||||          \  }}}}|                    d||d	
          \  }}}|j        J |j        t+          j        ||          z  |_        | j        | j        }}	 |                     dd           |	s|
rG|                     |	|
          5  |                     |d           d d d            n# 1 swxY w Y   n|                     |d           |                     ||           n# |                     ||           w xY w|r|                     |||||           t7          ||          S )NzI<svg> has no "viewBox", using its "width" & "height" as default "viewBox"r   r   r   z<svg>zT has no "viewBox" nor "height" / "width": w= and h= must be provided to FPDF.image()zY<svg> has no "viewBox" nor "height" / "width": w= and h= must be provided to FPDF.image()r'   T)r  rT  r  ignore_svg_top_attrsr  F)r  )r  r  )viewboxrT  r  r   r   r3   r   r   r   r  r  r  r  rN  r   r7  r   r  r  transform_to_rect_viewportr  r?   translationr  r  r  r  rn   )r   r  r#  r  r7  r   r  r  r  r  r  r  r  svg_id	svg_width
svg_heightr}  old_xold_ys                      r&   r  zFPDF._vector_image  s    { 	Fsy 	FSZ 	FM[*,,    !88U1XXsy#*ECK66a1ffy SZ  "#)W55#CI(3..  "#*g66$CJ)C// 
   [
1a$.tU$;$;E sss   !VVqAvvy SZ (+	3::		 .1k+1i o   Avv	MJ.
NY. 9//222AFFaKFF9A![)) 	B1a/@AAA!HH 	;..q!Q::JAq!Q331QT 4 
 

1d ~))))*?1*E*EEvtvu
	&KK1 1 1 ***JJ 5 5NN4eN4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 t%000KKu%%%%DKKu%%%% 	(IIaAq$'''aCCCCs0   41L %K	=L 	KL KL Lr  c           	      L   | j         j        }||z  ||z  }	}d| }
t          |d                   }t          |d                   }| j        J ||| j        z  k    r||	| j        z  k    rt          ||z  ||	z            | j        z  }| j                                                            d          r"t          	                    d|||||	|           nK| j                                        dk    rt          || j        z            t          |	| j        z            f}|dxx         dz  cc<   |d         d	k    rq| j        j        }|                                D ]P\  \  }}}|t          j        k    r8|d
         |v r.|                    t#          t$          |d
                              Q|                    |
          }|rt#          t(          |          }t          |d                   }t          |d                   }||z  |d	         |d         z  k     ra|                    t-          ||pt/          |          | j         j        |                     t                              d|
|d
         |           |dxx         dz  cc<   nt)          t-          ||pt/          |          | j         j        |                    }t5          |          dz   |d
<   d|d<   |||
<   t                              d|
||d
                    nt7          d| j                   |S )Nzlowres-r  r  r   zOVERSIZED: Image %s with size %.1fx%.1fpx is rendered at size %.1fx%.1fpt. Set pdf.oversized_images = 'DOWNSCALE' to reduce embedded image size by a factor %.1f	downscaler  r'   r   r  z>OVERSIZED: Updated low-res image with name=%s id=%d to dims=%szAOVERSIZED: Generated new low-res image with name=%s dims=%s id=%dz/Invalid value for attribute .oversized_images: )r  imagesr   r  r  r  r   r  r  r  roundrP  resources_per_pager\  rT   r  remover   r   r   rm   updaterp   rq   r  r  r  r  )r   r  r  r  r  r  r  r0  width_in_ptheight_in_ptlowres_namefactorr  r2  r  rtyperesourcelowres_infolowres_wlowres_hs                       r&   r  zFPDF._downscale_imageG  s    !($%Iq5y\&&&$s)$s)$000d9999L4#>>>> AOQ%5669TT  $**,,77?? Cq      &,,..+==+(CCDD,)DDEE X!#>Q&&)-)?)R&0B0H0H0J0J B B,
EH O$<<<chAVAV$OODd3i,@,@AAA$jj55 &==D$T#Y//H$T#Y//H(*T!WtAw->>>( $ # 7z$'7'7 $ 0 = $	    \' I 	   NNNa'NNNN*$ 3:d#3#3 ,9 	  D !$FaDI%&DN*.F;'LL[#S		    !]dF[]]   r%   c                 ~    t          j        dt          t                                 t	          | j        ||          S )z
        Read an image and load it into memory.

        .. deprecated:: 2.7.7
            Use `fpdf.image_parsing.preload_image` instead.
        zFPDF.preload_image() is deprecated since v2.7.7 and will be removed in a future release. Use `fpdf.image_parsing.preload_image` instead.r   )r   r   r   r3   rr   r  )r   r  r  s      r&   rr   zFPDF.preload_image  sQ     	B &((	
 	
 	
 	
 
 
 	
r%   glyph_image_bytesc                 0    t          | j        |d           S )N)r  r  r  )rr   r  )r   r?  s     r&   preload_glyph_imagezFPDF.preload_glyph_image  s'    
 ("
 
 
 	
r%   c              +     K   | j                             | j                  } | j        dd|d|}| j        }|                     d| d           |V  | j        |k    rt          d          |                     d           dS )	
        Can receive as named arguments any of the entries described in section 14.7.2 'Structure Hierarchy'
        of the PDF spec: iD, a, c, r, lang, e, actualText
        z/Figure)r  mcidz/P <</MCID z>> BDCz-A page jump occurred inside a marked sequenceEMCNr$   )r  next_mcid_for_pager   r  r  r]   )r   r   rD  struct_elemr   s        r&   r  zFPDF._marked_sequence  s       "55di@@.d. 
!
 
06
 
 Y
		,,,,---9
"" OPPP		%r%   c                      | j         j        dd| j        i|\  }}|| j        | j                 _        |                     d           |S )rC  r  r   r$   )r  add_marked_contentr   r   struct_parentsrM  )r   r   rG  spids       r&   r  zFPDF._add_marked_content  se    
 CD/B 
 
	
%+
 
T 04
49,!!%(((r%   c                     | j         | _        || xj        |z  c_        dS | j        r| xj        | j        z  c_        dS | xj        | j        z  c_        dS )a  
        Line Feed.
        The current abscissa goes back to the left margin and the ordinate increases by
        the amount passed as parameter.

        Args:
            h (float): The height of the break.
                By default, the value equals the height of the last printed text line
                (except when written by `.text()`). If no text has been written yet to
                the document, then the current font height is used.
        N)r8  r7  r   r  r  r  s     r&   r"  zFPDF.ln  s[     =FFaKFFFF[ 	%FFdk!FFFFFFdn$FFFFr%   c                     | j         S )z-Returns the abscissa of the current position.)r7  rX  s    r&   get_xz
FPDF.get_x  s	    vr%   c                 4    |dk    r|n	| j         |z   | _        dS )z
        Defines the abscissa of the current position.
        If the value provided is negative, it is relative to the right of the page.

        Args:
            x (float): the new current abscissa
        r   N)r  r7  )r   r7  s     r&   set_xz
FPDF.set_x  s!     1ff$&1*r%   c                 <    | j         rt          d          | j        S )z-Returns the ordinate of the current position.z?Using get_y() inside an unbreakable() code block is error-prone)r  r]   r   rX  s    r&   get_yz
FPDF.get_y  s+     	Q   vr%   c                 L    | j         | _        |dk    r|n	| j        |z   | _        dS )z
        Moves the current abscissa back to the left margin and sets the ordinate.
        If the value provided is negative, it is relative to the bottom of the page.

        Args:
            y (float): the new current ordinate
        r   N)r8  r7  r  r   )r   r   s     r&   set_yz
FPDF.set_y  s*     1ff$&1*r%   c                 Z    |                      |           |                     |           dS )a,  
        Defines the abscissa and ordinate of the current position.
        If the values provided are negative, they are relative respectively to the right and bottom of the page.

        Args:
            x (float): the new current abscissa
            y (float): the new current ordinate
        N)rT  rP  )r   r7  r   s      r&   r  zFPDF.set_xy  s&     	

1

1r%   c                    | j         sw| j        rp	 |                    | j                                      d          S # t          $ r5}t          |j        ||j                 | j        | j        z             |d}~ww xY w|S )z7Check that text input is in the correct format/encodingr   )
text_index	character	font_nameN)	rt  r  encodedecodeUnicodeEncodeErrorr_   startr  r  )r   rc  errors      r&   rP  zFPDF.normalize_text+  s      	D$< 	{{4#;<<CCINNN%   2${"5;/".@   	 s   ,= 
A<0A77A<sha256pkcs_filepathpasswordhashalgocontact_infolocationsigning_timereasonc	                    t           st          d          t          |d          5 }	t          j        |	                                |          \  }
}}ddd           n# 1 swxY w Y   |J |                     |
||||||||	  	         dS )aE  
        Args:
            pkcs_filepath (str): file path to a .pfx or .p12 PKCS12,
                in the binary format described by RFC 7292
            password (bytes-like): the password to use to decrypt the data.
                `None` if the PKCS12 is not encrypted.
            hashalgo (str): hashing algorithm used, passed to `hashlib.new`
            contact_info (str): optional information provided by the signer to enable
                a recipient to contact the signer to verify the signature
            location (str): optional CPU host name or physical location of the signing
            signing_time (datetime): optional time of signing
            reason (str): optional signing reason
            flags (Tuple[fpdf.enums.AnnotationFlag], Tuple[str]): optional list of flags defining annotation properties
        Pendesive.signer not available - PDF cannot be signed - Try: pip install endesiver  N)	rU  certextra_certsrb  rc  rd  re  rf  r  )r   EnvironmentErrorr  r   load_key_and_certificatesr  sign)r   r`  ra  rb  rc  rd  re  rf  r  	pkcs_filerU  ri  rj  s                r&   sign_pkcs12zFPDF.sign_pkcs12:  s    8  	"b   -&& 	)0NN$$h  #C{	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 		#%% 	 
	
 
	
 
	
 
	
 
	
s   ,AA#&A#rU  r   ri  r   rj  c
                 z   t           st          d          | j        rt          d          || _        || _        ||ng | _        || _        |p| j        | _        t          dddddd|	dt          ||t          | j                  |          		  	        }
| j        | j                                     |
           dS )
a  
        Args:
            key: certificate private key
            cert (cryptography.x509.Certificate): certificate
            extra_certs (list[cryptography.x509.Certificate]): list of additional PKCS12 certificates
            hashalgo (str): hashing algorithm used, passed to `hashlib.new`
            contact_info (str): optional information provided by the signer to enable
                a recipient to contact the signer to verify the signature
            location (str): optional CPU host name or physical location of the signing
            signing_time (datetime): optional time of signing
            reason (str): optional signing reason
            flags (Tuple[fpdf.enums.AnnotationFlag], Tuple[str]): optional list of flags defining annotation properties
        rh  z).sign* methods should be called only onceNWidgetSigr   	signature)rc  rd  r  rf  )
field_typer7  r   rT  r  r  r  r  )r   rk  r  r]   
_sign_cert_sign_extra_certs_sign_hashalgorD  
_sign_timer-   r   r   r   r   r  )r   rU  ri  rj  rb  rc  rd  re  rf  r  r  s              r&   rm  z	FPDF.signm  s    :  	"b   > 	M KLLL0;0GR&$0$FD4F")!$/**	  
 
 

  	
49,,Z88888r%   c                      j         }|J  j         j        }}|j        |j        c _         _        d _                             |j         j         j                   |	                      j
                   d _        |j        |j        z   dz
  } j        |k    rA j        s: j        |k    rdnd}d| d}|d j         d	|j         d
z  }t          |           j        rc                                   fdt!           j                  D             }t#          t%          |                    }i }t!          |j        dz    j        t)          |          z   dz             D ]}	|	 j        v r-|                     j                            |	                     |                    d          x}
 j        |	<   |	||
                                <   |
                    |	           |j        du r|	|
                                _        t)          |          dk    sJ dt)          |                        j                                        D ].}|j        J |                    |j                  }|||_        / j
        D ]X}|                    |j                  }|:|j         !                    |          |_         ||_        |j"        r||j"        _#        Y j$        j%        }tM          tN                    }|(                                D ]%\  \  }}}|                    ||          |f}|||<   &| j$        _%        ||c _         _        d S )NTFr'   manyfewzKThe rendering function passed to FPDF.insert_toc_placeholder triggered too z page breaks: zToC ended on page z' while it was expected to span exactly z pagesc                 h    g | ].}j                             t          j                             /S r$   )r   popr  )rM  r  r   s     r&   r  z2FPDF._insert_table_of_contents.<locals>.<listcomp>  s<       45
s4://  r%   r   z#new_pages: r8  ))r  r   r   r   r  r4  r   r2  r3  r   r  r   r  r]   r  r  r  r   r  r  r  r  r}  r1  	set_indexr   r  str  r}  r  r   r  rm  rG  _page_numberrP  r2  r   r  r\  )r   tocpr  r  expected_final_pagetoo	error_msg	new_pagesindices_remap
page_indexr   r  	new_indexsectionr2  new_resources_per_pager  r  r:  rU  s   `                   r&   _insert_table_of_contentszFPDF._insert_table_of_contents  s   # Itv6	 OTV	46 $d3TZLLLT4=111 %"o
:Q>9+++D4R+ I(;;;&&CyfiyyyIrdirr`d`jrrrrI	***# 0	O!!!   9>t?W9X9X  I Xi0011I,.M#!#T%5I%F%J  : :
 ++$$TZ^^J%?%?@@@09a0@0@@tz*-.8djjll+z****e33/9D'')),y>>Q&&&(Gs9~~(G(G&&&
))++ 1 1'333)--d.>??	('0D$= 	 	)--g.ABB	(#*<#7#7Y#7#G#GGL*3G'*  &  +8 "&!7!J C   # ;M:R:R:T:T 7 76,mh$((kBBMR.6&s++8ND"5%v	4666r%   c                     dS )aA  
        This method can be overridden in inherited classes
        in order to define a custom file identifier.
        Its output must have the format "<hex_string1><hex_string2>".
        If this method returns a falsy value (None, empty string),
        no /ID will be inserted in the generated PDF document.
        r  r$   rX  s    r&   file_idzFPDF.file_id  s	     rr%   rR  c                 D   t          j        dd          }|                    |           | j        r@|                    | j                            d                              d                     |                                                                }d| d| dS )	Nmd5F)usedforsecurityz%Y%m%d%H%M%Sutf8<z><>)hashlibr  r4  rD  strftimerZ  	hexdigestr  )r   rR  id_hashhash_hexs       r&   _default_file_idzFPDF._default_file_id  s     +eU;;;v 	WNN4-66~FFMMfUUVVV$$&&,,..*8**x****r%   c                     || j         }|J || j        z  dd| j        |z
  |j        dz  | j        z  z   | j        z  dd|| j        z  dd|j         dz  | j        z  ddS )zr
        Draw an horizontal line under some text,
        starting from (x, y) with a length equal to 'w'
        Nr  r     re f)r$  r   r  upr  utr!  r   r7  r   r  r   s        r&   r  zFPDF._do_underline       <$D46z  > >
TWt^dn<<FM> >46z > > x$!22=> > >	
r%   c                     || j         }|J || j        z  dd| j        |z
  |j        dz  | j        z  z   | j        z  dd|| j        z  dd|j         dz  | j        z  ddS )zt
        Draw an horizontal line through some text,
        starting from (x, y) with a length equal to 'w'
        Nr  r  r  r  )r$  r   r  spr  ssr!  r  s        r&   r  zFPDF._do_strikethrough  r  r%   c                    | j         rt          d          t          |t                    s9t          |t                    st	          |          }|                    d          }| j        st          d          | j        | j                 j        }t          |t                    r,|
                    |           |                    d           d S ||dz   z  }d S )NzGContent cannot be added on a finalized document, after calling output()latin1r   r     
)rR  r]   r   r  r   rZ  r   r   r0  r2  rz  r  )r   rE  page_contentss      r&   r  z	FPDF._out)  s    ; 	Y   !U## 	#a%% FF""Ay 	S QRRR
49-6mY// 	'  ###  &&&&&QY&MMMr%   c                 ^   |dz  }|}dddddddd	d
dddd}|}	t          |	          dz  dk    rd|	 }	d|	                                 d}	t          dt          |	          d          D ]}
|	|
         }|	|
dz            }||vrt          d| d          ||vrt          d| d          d                    d t          ||         ||                   D                       }t          |          D ]6\  }}|dk    r|n|}|dz  dk    r|                     ||||d           ||z  }7dS )z/Barcode I2of5 (numeric), adds a 0 if odd lengthr   nnwwnwnnnwnwnnwwwnnnnnwnwwnwnnnwwnnnnnwwwnnwnnwnwnnnwn)0123456789AZr   r   r  AAZAr'   zChar "z" invalid for I25:z" invalid for I25: r   c              3   (   K   | ]\  }}| | V  d S rV  r$   )rM  cbcss      r&   rO  z'FPDF.interleaved2of5.<locals>.<genexpr>h  s?         &B2r     r%   r  r  N)r  r   r  RuntimeErrorr  ziprI  r  )r   rc  r7  r   r  r  narrowwidebar_charcoder  char_bar
char_spacer  	bar_indexr  r/  s                    r&   interleaved2of5zFPDF.interleaved2of5;  s    Q 
 
  t99q=At::D %DJJLL$$$q#d))Q'' 	  	 AAwHa!eJx''"#HH#H#H#HIII))"#KJ#K#K#KLLL ''  *-hx.@(:BV*W*W    C $-S>>    	4'+s{{VV
 q=A%%IIaJ3777Z 	  	 r%         ?r  c                    ||dz  d}|                     d          r|                    d          s"t          j        dt	                                 i dddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'i d(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdT
}|                                D ]r}||vrt          dU| dV          t          ||                   D ]8\  }	}
|	dWz  dXk    r|                     ||||
         |d$           |||
         z  }9||dY         z  }sdZS )[zBarcode 3of9r   )r  r  *zpCode 39 input must start and end with a '*' character to be valid. This method does not insert it automatically.r   r  	nnnwwnwnnr  	wnnwnnnnwr  	nnwwnnnnwr  	wnwwnnnnnr  	nnnwwnnnwr  	wnnwwnnnnr  	nnwwwnnnnr  	nnnwnnwnwr  	wnnwnnwnnr  	nnwwnnwnnr  	wnnnnwnnwrS  	nnwnnwnnwrQ  	wnwnnwnnnr  	nnnnwwnnwE	wnnnwwnnnr  	nnwnwwnnnG	nnnnnwwnwH	wnnnnwwnnrT  	nnwnnwwnnr4  	nnnnwwwnnK	wnnnnnnwwrE  	nnwnnnnwwM	wnwnnnnwnN	nnnnwnnwwO	wnnnwnnwnr   	nnwnwnnwnr  	nnnnnnwwwr   	wnnnnnwwnrn  	nnwnnnwwnrF  	nnnnwnwwnro  	wwnnnnnnwV	nwwnnnnnwW	wwwnnnnnnrK  	nwnnwnnnw	wwnnwnnnn	nwwnwnnnn	nwnnnnwnw	wwnnnnwnn	nwwnnnwnn	nwnnwnwnn	nwnwnwnnn	nwnwnnnwn	nwnnnwnwn	nnnwnwnwn)
Yr  -rM  r  r  $/+%zInvalid char "z" for Code39r   r   r  N)	r  r  r   r   r3   r  r  rI  r  )r   rc  r7  r   r  r  dimcharsr  r  ds              r&   code39zFPDF.code39v  s    AE""s## 	4==+=+= 	ME +,,   -
-
-
 -
 	-

 -
 -
 -
 -
 -
 -
 -
 -
 -
 -
 -
  !-
" #-
 -
$ %-
& '-
( )-
* +-
, --
. /-
0 1-
2 3-
4 5-
6 7-
8 9-
: ;-
< =-
> ?-
@ A-
B C-
D E-
 -
F Y-
 -
 -
`  	 	A~~"#CA#C#C#CDDD!%(++  1q5A::IIaCFAs333SVSMAA	 	r%   c              #      K   |                      d|| j        z  dd| j        |z
  |z
  | j        z  dd|| j        z  dd|| j        z  dd	           dV  |                      d           dS )a}  
        Context manager that defines a rectangular crop zone,
        useful to render only part of an image.

        Args:
            x (float): abscissa of the clipping region top left corner
            y (float): ordinate of the clipping region top left corner
            w (float): width of the clipping region
            h (float): height of the clipping region
        r  r  r  z re W nNr  r  r{  s        r&   	rect_clipzFPDF.rect_clip  s       			+QZW + +tvzA~&?W + +a$&jW + +tv:*+ + +	
 	
 	
 			#r%   c              #      K   |                      d           |                     ||||d           dV  |                      d           dS )a]  
        Context manager that defines an elliptic crop zone,
        useful to render only part of an image.

        Args:
            x (float): abscissa of the clipping region top left corner
            y (float): ordinate of the clipping region top left corner
            w (float): ellipse width
            h (float): ellipse height
        r  zW nNr  )r  r  r{  s        r&   elliptic_clipzFPDF.elliptic_clip  sO       			#1aAu---		#r%   c              #   t   K   |                      ||||          5  dV  ddd           dS # 1 swxY w Y   dS )aF  
        Context manager that defines a circular crop zone,
        useful to render only part of an image.

        Args:
            x (float): abscissa of the clipping region top left corner
            y (float): ordinate of the clipping region top left corner
            r (float): radius of the clipping region
        N)r  )r   r7  r   r<  s       r&   
round_clipzFPDF.round_clip  s       1a++ 	 	EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   -11c              #     K   | j         | j        }}t          | d          }d|_        d| _        t
                              d           |V  |j        |z
  |j         |z
  | j        z  z   }||z   | j        k    s|j         |k    rbt
                              d           |	                                 |j
                                         |                                 d|_        d| _        t
                              d           dS )a  
        Ensures that all rendering performed in this context appear on a single page
        by performing page break beforehand if need be.

        Detailed documentation on page breaks: https://py-pdf.github.io/fpdf2/PageBreaks.html

        Notes
        -----

        Using this method means to duplicate the FPDF `bytearray` buffer:
        when generating large PDFs, doubling memory usage may be troublesome.
        Fr  TzStarting unbreakable blockz.Performing page jump due to unbreakable heightzEnding unbreakable blockN)r   r   r   rc  r  r  r  r  r  rewindpdfr  replayr   r  r  recordery_scrolls        r&   unbreakablezFPDF.unbreakable  s      !Itv6	>>>(-%#1222:&(-)*Ctx)OOHt666(-):S:SLLIJJJOO L,,...OO,0H)$/00000r%   c              #      K   | j         | j        }}t          | d          }d|_        |V  |j        |z
  |j         |z
  | j        z  z   }||z   | j        k    s|j         |k    rd|_        |                                 dS )z
        All rendering performed in this context is made on a dummy FPDF object.
        This allows to test the results of some operations on the global layout
        before performing them "for real".
        Fr  TN)r   r   r   rc  r  r  r  r  s        r&   offset_renderingzFPDF.offset_rendering  s       !Itv6	>>>(-%:&(-)*Ctx)OOHt666(-):S:S,0H)r%   render_toc_functionr   allow_extra_pagesr   c                    |dk     rt          d|           t          |          st          dt          |                     | j        rt          d| j        j                   t          || j        | j	        | j
        ||          | _        || _        t          |          D ]}|                                  dS )a  
        Configure Table Of Contents rendering at the end of the document generation,
        and reserve some vertical space right now in order to insert it.
        At least one page break is triggered by this method.

        Args:
            render_toc_function (function): a function that will be invoked to render the ToC.
                This function will receive 2 parameters: `pdf`, an instance of FPDF, and `outline`,
                a list of `fpdf.outline.OutlineSection`.
            pages (int): the number of pages that the Table of Contents will span,
                including the current one that will. As many page breaks as the value of this argument
                will occur immediately after calling this method.
            allow_extra_pages (bool): If set to `True`, allows for an unlimited number of
                extra pages in the ToC, which may cause discrepancies with pre-rendered
                page numbers. For consistent numbering, using page labels to create a
                separate numbering style for the ToC is recommended.
            reset_page_indices (bool): Whether to reset the pages indices after the ToC. Default to True.
        r'   z3'pages' parameter must be equal or greater than 1: z,The first argument must be a callable, got: zIA placeholder for the table of contents has already been defined on page N)r  callabler  rs  r  r]   r   r   r   r   r5  r  r  r  )r   r#  r   r$  r   r  s         r&   insert_toc_placeholderzFPDF.insert_toc_placeholder%  s   4 199MeMM   +,, 	ZtDW?X?XZZ    	> 0;> >    .IF  
  
 *;&u 	' 	'A$$&&&&	' 	'r%   level0level1level2level3level4level5level6c           	          t          |||||||g          D ]E\  }}	|	>t          |	t                    st          dt	          |	                     |	| j        |<   FdS )a  
        Defines a style for section titles.
        After calling this method, calls to `FPDF.start_section` will render section names visually.

        Args:
            level0 (TextStyle): style for the top level section titles
            level1 (TextStyle): optional style for the level 1 section titles
            level2 (TextStyle): optional style for the level 2 section titles
            level3 (TextStyle): optional style for the level 3 section titles
            level4 (TextStyle): optional style for the level 4 section titles
            level5 (TextStyle): optional style for the level 5 section titles
            level6 (TextStyle): optional style for the level 6 section titles
        Nz0Arguments must all be TextStyle instances, got: )rI  r   rd   r  rs  r  )
r   r(  r)  r*  r+  r,  r-  r.  r1  levels
             r&   set_section_title_styleszFPDF.set_section_title_stylesX  s    2 &VVVVVVD
 
 	9 	9LE5  !%33 #X4PU;;XX   49)%0	9 	9r%   r0  strictc                    |dk     rt          d          |rF| j        r?|| j        d         j        dz   k    r&t          d| d| j        d         j         d          t          | j        | j        | j        | j        z  z
            }d	}| j        r| j        |         }|j	        | j
        }|j	        | _
        t          j        }t          |j        t          t          f          rt          j        |j                  }|                     | j        | j        |t(          j        t,          j        d
t0          j        |t5          |j        pdt          |j        t8          t:          f          r|j        nd|j        pd          	  	        }	|j	        || _
        |	r|                                  |                      |          5 }
|
}| !                    |          5  |                     | j        | j        ||t(          j        t,          j        |j        t          j"        k               d	d	d	           n# 1 swxY w Y   d	d	d	           n# 1 swxY w Y   | j        #                    tI          ||| j        ||                     d	S )a  
        Start a section in the document outline.
        If section_title_styles have been configured,
        render the section name visually as a title.

        Args:
            name (str): section name
            level (int): section level in the document outline. 0 means top-level.
            strict (bool): whether to raise an exception if levels increase incorrectly,
                for example with a level-3 section following a level-1 section.
        r   z)"level" mut be equal or greater than zeror  r'   z+Incoherent hierarchy: cannot start a level z section after a level z oner  NT)r  r  rO  )	r  r  rc  r%  r&  r   r  r#  r@  r  )r  r  rc  r#  r%  r&  r$  )%r  r  r0  r   r   r  r   r   r  size_ptr!  rC   rE  r   r8  r   rI  r  r  r  r[   r7  r\   r8  rM   r  r   r9  r   r   r  r(  r  use_text_stylerQ  r  rx   )r   r  r0  r2  r  outline_struct_elem
text_styleprev_font_size_ptr#  rc  rG  s              r&   start_sectionzFPDF.start_section{  s    199HIII 	dm 	b0A0G!0K(K(Kyeyy\`\ijl\m\syyy   diTY$&-HIII"$ /	259J!-$($5!$.$6!GE*-s|<< :Z%899#'??(.li(3"+0q &j&9C<HH
++%.3!   $3 $ $ & !-% ! $  &&T&22 k&1#((44 	 	OO(.!#"l"i)2eg= $   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	               	4	49LMM	
 	
 	
 	
 	
s7   IAH8,I8H<	<I?H<	 IIIr7  c              #     K   d }|r|j         r|                     |j                    |j        rat          |j        t          t
          f          r | j        }|j        | _        | j        | _        n t                              d|j                   | 	                    |          5  d V  d d d            n# 1 swxY w Y   |r!|j
        r|                     |j
                   ||| _        | j        | _        d S d S )Nz@Unsupported '%s' value provided as l_margin to .use_text_style())r9  r"  r8  r   r   r   r7  r  r  use_font_facer  )r   r7  prev_l_margins      r&   r5  zFPDF.use_text_style  sO      	" -
+,,," 	j1E3<@@ $(MM$.$7DM!]DFFLLZ"+   
++ 	 	EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	)*- 	)GGJ'((($)DM]DFFF %$s   %B66B:=B:	font_facec              #     K   |sdV  dS | j         | j        | j        f}|                     |j        p| j         |j        |j        j        n| j        |j        p| j                   d| _        | j	        }|j
        *|j
        | j	        k    r|                     |j
                   | j        }|j        |                     |j                   dV  |j        |J |                     |           || _	         | j        |  dS )a  
        Sets the provided `fpdf.fonts.FontFace` in a local context,
        then restore font settings back to they were initially.
        This method must be used as a context manager using `with`:

            with pdf.use_font_face(FontFace(emphasis="BOLD", color=255, size_pt=42)):
                put_some_text()

        Known limitation: in case of a page jump in this local context,
        the temporary style may "leak" in the header() & footer().
        NF)r  r  r!  r  r   rp  r  r4  r%  r+  r  rD  r)  r  )r   r=  	prev_fontprev_text_colorprev_fill_colors        r&   r;  zFPDF.use_font_face  s4       	EEEF%t8IJ	0 0 %1 "((_2!2	
 	
 	
 ,1(/?&9?do+M+M	000/+	 4555+"...000)y!!!!r%   c              /   Z   K   t          | g|R i |}|V  |                                 dS )ao  
        Inserts a table, that can be built using the `fpdf.table.Table` object yield.
        Detailed usage documentation: https://py-pdf.github.io/fpdf2/Tables.html

        Args:
            rows: optional. Sequence of rows (iterable) of str to initiate the table cells with text content.
            align (str, fpdf.enums.Align): optional, default to CENTER. Sets the table horizontal position
                relative to the page, when it's not using the full page width.
            borders_layout (str, fpdf.enums.TableBordersLayout): optional, default to ALL. Control what cell
                borders are drawn.
            cell_fill_color (int, tuple, fpdf.drawing.DeviceCMYK, fpdf.drawing.DeviceGray, fpdf.drawing.DeviceRGB): optional.
                Defines the cells background color.
            cell_fill_mode (str, fpdf.enums.TableCellFillMode): optional. Defines which cells are filled
                with color in the background.
            col_widths (int, tuple): optional. Sets column width. Can be a single number or a sequence of numbers.
            first_row_as_headings (bool): optional, default to True. If False, the first row of the table
                is not styled differently from the others.
            gutter_height (float): optional vertical space between rows.
            gutter_width (float): optional horizontal space between columns.
            headings_style (fpdf.fonts.FontFace): optional, default to bold.
                Defines the visual style of the top headings row: size, color, emphasis...
            line_height (number): optional. Defines how much vertical space a line of text will occupy.
            markdown (bool): optional, default to False. Enable markdown interpretation of cells textual content.
            text_align (str, fpdf.enums.Align): optional, default to JUSTIFY. Control text alignment inside cells.
            v_align (str, fpdf.enums.VAlign): optional, default to CENTER. Control vertical alignment of cells content.
            width (number): optional. Sets the table width.
            wrapmode (fpdf.enums.WrapMode): "WORD" for word based line wrapping (default),
                "CHAR" for character based line wrapping.
            padding (number, tuple, Padding): optional. Sets the cell padding. Can be a single number or a sequence
                of numbers, default:0
                If padding for left or right ends up being non-zero then the respective c_margin is ignored.
            outer_border_width (number): optional. The outer_border_width will trigger rendering of the outer
                border of the table with the given width regardless of any other defined border styles.
            num_heading_rows (number): optional. Sets the number of heading rows, default value is 1. If this value is not 1,
                first_row_as_headings needs to be True if num_heading_rows>1 and False if num_heading_rows=0. For backwards compatibility,
                first_row_as_headings is used in case num_heading_rows is 1.
            repeat_headings (fpdf.enums.TableHeadingsDisplay): optional, indicates whether to print table headings on every page, default to 1.
        N)r   r`  )r   r   r   tables       r&   rC  z
FPDF.table  s@      R d,T,,,V,,r%   )	linearizeoutput_producer_classrD  rE  c                    d S rV  r$   r   r  rD  rE  s       r&   r  zFPDF.output1  s	     Cr%   c                    d S rV  r$   rG  s       r&   r  zFPDF.output9  s	     sr%   )r  z2.2.0c                   t          j                     | j        sJ| j        dk    r|                                  |                                  | j        r|                                  | j        r| j	        
                                D ]}|                                D ]}|j                            |                                                    d          |                    t#          | j                                                d                    |_        | j                                        D ]:\  }}t+          |t,                    r |j        r|j                                         ;| j        r| j        j        dk    rt7          | j                  dk    rA|                     t<          j        dddtA          tC                      dd	          d
           | j        j"        dk    rD| j        j#        dk    r4t7          | j$                  dk    rtK          | j        j&         d          |rtN          } ||           }|(                                | _        |ret+          |t"          tR          j*        f          r(tW          |          ,                    | j                   n|-                    | j                   dS | j        S )a  
        Output PDF to some destination.
        The method first calls [close](close.md) if necessary to terminate the document.
        After calling this method, content cannot be added to the document anymore.

        By default the bytearray buffer is returned.
        If a `name` is given, the PDF is written to a new file.

        Args:
            name (str): optional File object or file path where to save the PDF under
            output_producer_class (class): use a custom class for PDF file generation
        r   r   r   sRGBzIEC 61966-2-1:1999zhttp://www.color.orgr   r=   )r0  r  	alternatezsRGB2014 (v2))r  r  r  r  r  r   r  z$ requires at least one embedded fileN).r   cache_clearrR  r   r(  r  r  r  r  r   r}  get_text_substitutionsr0  rm  get_placeholder_stringrZ  render_text_substitutionr   r  rY  r\  r   rf   
color_fontload_glyphsrJ  rK  r  r  r  rN   r   r|   r   rL  r  r  r`   ra  rw   	bufferizeosPathLiker	   write_bytesr  )	r   r  rD  rE  r   substitution_itemr  r   output_producers	            r&   r  zFPDF.outputA  s   * 	&((({ /	6yA~~!!!# 1..000& 
 J--// 	 	D-1-H-H-J-J  )(,(=(=-DDFFMM )  .FF #D$4 5 5 $fY//) )  :++-- 2 24dG,, 2 2O//111 D$4$<$F$Ft+,,11**+04:)=&<,9%;%=%=&1- - -
 - +    $)Q..(4;;D/00A55-+1WWW    A(@%33D99O)3355DK 	$bk 233 (T

&&t{3333

4;'''4{r%   )NNNNN)r  )r   )r   )TNNNNrV  )r  )NNN)r   r   Fr   NNNN)r   N)T)r  r  )FF)NT)r   r   r   )FFN)FN)r'   r'   )NFr   )r   N)Nr   FFFN)Nr   FN)Nr   N)Nr   r   )r   r   r  r  N)Nr   r   r  r  N)NNNNNN)r'   r'   N)NNNN)r  r  N)r  NN)r   r  r'   )r   r   )r   r   NN)NNNNNNNN)
NNr   r   r   r   NNNF)	NNr   r   r   NNNF)NNr   r   r   NNF)r'   r  )r  r  )r'   FT)r   T(  r!   r"   r#   __doc__r  r  r  r  r  recompileDOTALLr  r  r  ri   re  rR   r  r   r   r   r  r   r   rJ   r   propertyr-  rb   rf   rY  rK   RC4rB   r[  r   r   rb  r   ri  rM  rW   rp  rt  rQ   rv  setterr   rz   r~  rN   r|   r  r  r  r  r  r:  r  r  r  r<  r  r4  r=  rV   r  rP   r  r  r  r  r  r   r  r  r  r  r   r  r  r  r  r	  r   rO   r  r   r(  r  r  r  r,  r9  r  r   r9   r@  r  r;   r<   r=   rD  rS  rV  r   r   r[  r   r   r5   rf  r   rp  r7   r_  rS   AUTOr8   r~  r6   r  r  r  r  r  r  rU   r  r  r  r  rI   r  r  r  r  r  r  r!  r0  r2  rE  r2   r
   r]  r  rp  ry  r  r  r  r  r  r   r  r,   r  r	   r  r.   r  r+   rL   rE   r  rF   r  r  r(   r  rX   r  r  r  r  r4   rc  r  r  r  rD   r  r?   r  rf  r:   r+  r-  r  rC   rE  r[   r5  r\   r6  r>  ru   r   r;  r  rs   rR  r:  r  r  r  rN  r  r  r  r  r   r   r   r  r  r  r4  r8  rZ   WORDrM   r  r  r  r   r  r   rm   rn   r  r  r  r   r  r  rr   rA  r   r  r  r"  rN  rP  rR  rT  r  rP  PRINTLOCKEDro  rm  r  r  r2  r  r  r  r  r  r  r  r  r  r   r   r"  r   rx   r'  rd   r1  r9  r5  rc   r;  r   rC  r   r{   r   r  rS  rT  __classcell__)rT  s   @r&   r   r     s}7        "$(! $ $$"*%F	RR"O 4C3K"&260<j0 HLj0 j0 j03/0j0 CJj0 c5../	j0
  -j0 %U30B+B%CDj0 
j0 j0 j0 j0 j0 j0X 4tCG!334 4 4 4 X4 (,.>.B/+/11!&$
 $
$
  }$
 ,	$

 $
 $
 
$
 $
 $
 $
L s  3  #  $        <:C :D : : : : /, / / / X/ QT Q Q Q XQ 8H-    X -8c> -d - - - - -
+A B - - - X- 6:*.'+7;"&) &)$&) &.c]&) #3-	&)
  }&) &m4&) sm&) 
&) &) &) &)P 6U 6 6 6 X6 6U 6 6 6 X6 S    X? ?4 ? ? ? ?  E %     &
e 
 
 
 
 
U t    u     @ @ @e @D @ @ @ @  
ue|)< 
 
 
 X
J?*J J 	J
 
J J J J, #' 'Ek' ' 
	' ' ' 'V $(-137 $"&M
 M
 M
 4S>*M
 C-/0	M

 M
 3-M
 
M
 M
 M
 M
^ !Xj1 ! ! ! X! -xj0@'A -d - - - -
! ! ! ! ! !s t    -S -T - - - -3 4    x}!4     !S8C=%8 !T ! ! ! !3 4    !S !T ! ! ! !
" 
"hx&8 
"D 
" 
" 
" 
"-S -T - - - -)'*?"@ ) )QU ) ) ) )0-S -T - - - -.( (C (T ( ( ( (0  7;&*%)	 Q  QcN23 Q sm Q c]	 Q
 
 Q  Q  Q Z QH +/6:&*%)X XX X 	X
 X Z(X cN23X smX c]X 
X X X Xv   ( ,2 ,2?*,2 eE5L)),2 	,2
 5/,2 Z(,2 ,2 
,2 ,2 ,2 ,2\          1 1 1 1 1 WY %#%(88=CMS	   0 WY %#%(88=CMS	   D ; ;  v 	
  ; ; ; 
; ; ; ;: BG
 

"&
:>
	
 
 
 
.5E 5d 5 5 5 5"3>E#9I#Ee#TU	   4 -1() ()$TN()	.	!() () () Z ^()T ;8 ; ; ; ; Z ^;     4  $1$6'+       "	 
 tn  
+	      ^ 4 (,	& && tn& 	&
 
& & & &( ?@7 77$)76;7	7 7 7 7> E % D     )x'? ) ) ) ^)&+67?J	   B 
u 
% 
U 
 
$ 
 
 
 Z
  -1.( .(U5%<01.( .( 	.(
 c)*.( 
.( .( .( Z.(`  -1	H HU5%<01H H c)*	H
 
H H H ZH(  "  " "  "  	" 
 "  "  "  
"  "  "  Z" H  .2# - -- - 	-
 - c)*- - - 
- - - Z-^X)X) X) 	X)
 X) X) eFSL#$566X) X) 
X) X) X) X)B "K KK K 	K
 K K E?K 
K K K KZ  .27 77 7 	7
 7 c)*7 
7 7 7 Z74'
'
 '
%*'
/4'
@C'
	'
 '
 '
 '
R  .2L LL L 	L
 c)*L 
L L L ZL2   !-1(* (*(* (* 	(*
 (* (* c)*(* 
(* (* (* Z(*V  !"-1%= %=%= %= 	%=
 %= %= %= c)*%= 
%= %= %= Z%=N  ""'#-1R RR R 	R
 R R E?R R R  R R c)*R 
R R R ZRv "-1+
 +
+
 +
 	+

 +
 +
 E?+
 +
 +
 c)*+
 
+
 +
 +
 +
` -1	J  J U5%<01J  J  c)*	J 
 
J  J  J  J X +,-- !%*.	h- PTOS!%&'h- h- h-h- h- h'	h-  hsSy5c?/J&K KLh- T#tCJ'7"784U
;KKLh- #h- !$h- 
h- h- h- .-h-X !%*,	e1 e1e1 S,&'e1 	e1
 
e1 e1 e1 e1N
1% 
1D 
1 
1 
1 
1  %)	    "	
 
   "1 1$ 1 1 1 1 4 44 4 4 4 4 BF6 6&sm6:>6	6 6 6 6B ""0 00 0 	0
 Ek0 sm0 
0 0 0 0d# #    0 #"": :sm: : 	:
 : ck: sm: 
#	: : : :F #'I II I 	I
 I CiI 3-I I 
I I I IZ 15!%"&04#'6:d dE#t),-d d 3-	d
 $H-d C=d '/smd d 
d d d dL  =A2E- -:- - 	-
 - - 3c9:- ^c)3./- - 
- - - Z-^  /3# ## # 	#
 # # ~+,# # 
# # # Z#J  "!!!3 33 E?3 E?	3
 E?3 E?3 3 
3 3 3 Z3j !&+05:?DPS	   Z8  &1,504$. $.$. s"$. UE5()	$.
 $H-$. $. 
$$. $. $. ^$.L 3 # (4.    ^  -604"2 2s"2 2 e_	2
 UE5()2 $H-2 sm2 2 
2 2 2 Z2h  ,5& &ue|,-& & UE5()	&
 & & 
& & & Z&P /  / e /  / S / $ /  /  /    Z/ b LP" ""'":B5/"	" " " Z"H LP    ' :B5/ 	$      ^ Z D  !!   E?	
 E? 
$   ^ ZB E5L)27#+2E	$   ^ ZB 9 $    ^ Z( ; c ; htn ;  ;  ;  ^ Z; ~ &*$((,&*+/+/+/ fY fYc]fY SMfY uo	fY
 UOfY Z(fY Z(fY Z(fY %ue+,d3:.>>?
fY fY 
fY fY fY fYP    $4 $ $ $ X$  "!&'$0"W$& J H}
 }
E?}
 E?}
 	}

 #}
 L!}
 U{}
 }
 sSy!}
 }
 }
 Tz}
 Tz}
 
}
 }
 }
   Z}
D ""#jh$&%)$)`$ `$`$ E?`$ c3h	`$
 `$ `$ `$ sSy!`$ `$ '"`$ "`$ 
`$ `$ `$ `$D
% 
E 
e 
 
$ 
 
 
 
  #' 	(	       0) SM) -1) 	(	)  )  )  ) V" "c "# "x} " " " "0C C C(9K C C C CJ
e 
 
 
 
 
$ $       8, , , , , (4.    ^: +/i...&*3i)///',9,,, 	!
	
	  (*>>
?	@ (*??
@		A
 $&;;
<	= (*>@UU
V	W Y     "&'"W $($0+/ J I%]*;*F12)J JJ E?J 	J
 #J U{J J J sSy!J L!J "%J J J TzJ TzJ  !J" #J$ ''%J& 'J( x}$w.)J* 
+J J J   ZJX
  "$&%]R$ R$E?R$ R$ sSy!	R$
 R$ R$ 
R$ R$ R$   ZR$h  #!$"$,2'($($(#('/}.33
 3
sm3
 c]3
 	3

 3
 3
 3
 US[)3
 e_3
 5/3
 5/3
 4.3
 8$3
 &d^3
 
3
 3
 3
 Z3
p &*!35$&#"&.2"'j
 j
j
 EEM"j
 E?	j

 j
 j
 GL))D0j
 sSy!j
 }j
 3-j
 uUE\*+j
  j
 
?	*j
 j
 j
 j
b &*!$&#"&.2"'7 77 7 	7
 EEM"7 E?7 7 7 sSy!7 }7 3-7 uUE\*+7  7 
7 7 7 7rK3;K K 	K
 "O3K  K 
K K K K0 &*!$&#"&"'XD XDXD XD 	XD
 EEM"XD E?XD XD XD sSy!XD }XD 3-XD  XD 
XD XD XD XDtZZ Z 	Z
 Z Z Z 
Z Z Z Z~ ,0
 
EkH$u,t3
 E5L!D(
 
EE!H,t3d:/)	+
	
 
 
 
<	
UX5E 	
%EE!H,t3d:/)	+K 	
 	
 	
 	
  *1E    ^ 
C 
J 
 
 
 
 % %HUO %t % % % Z%(u    -u - - - - -u    	-u 	- 	- 	- 	- 	-
 
% 
D 
 
 
 
3 3    $ %) &*"&+/ $ !3
1
 1
Tz1
 5/1
 	1

 sm1
 3-1
 x(1
 1
 ^c)3./1
 
1
 1
 1
 1
f 
 6: &*"&+/ $ !3
99 99'(99 99 d=12	99
 99 sm99 3-99 x(99 99 ^c)3./99 
99 99 99 Z99vB. B. B. B.H#"34    +y +S + + + +" RV
 

 
%*
2:8g;M2N
	
 
 
 
$ RV
 

 
%*
2:8g;M2N
	
 
 
 
"'cEk 'd ' ' ' '$ FH7  7 7 !7 &+7 057 >C7 	7  7  7    Z7 r HID DD!D&+D05D@ED	D D D   ZDL 5 U u  8D>    ^ Z( u  5 U xPT~    ^ Z  E e  (4.    ^ Z 1Xl3 1 1 1 ^1> (<"8    ^  "'#'0' 0'%vtN/C&Dd&JK0' 0'  	0'
 !0' 
0' 0' 0' Z0'j '+&*&*&*&*&*!9 !9!9 #!9 #	!9
 #!9 #!9 #!9 #!9 
!9 !9 !9 !9F F
 F
# F
c F
t F
t F
 F
 F
 ZF
P # #x~ # # # ^#. %"x %"HTN %" %" %" ^%"N )3 )# )(5/ ) ) ) ^ Z)V  ')  6D  wr{# 	
  $N3 
   X 
  6D  BK$$x/ 	
  $N3 
   X ,-.. =?L  6DL L LsR[--89L 	L
  $N3L 
)	L L L /.L L L L Lr%   r   zFPDF.add_highlightF)
r   r[   r\   r   rl   rm   rn   rY   re   r   rV  )r  rY  loggingr  r  rS  rY  sysr  r   collectionsr   
contextlibr   r   r   	functoolsr   os.pathr   pathlibr	   r
   typingr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ,cryptography.hazmat.primitives.serializationr   endesiver   r  	PIL.Imager   r   actionsr(   r)   r*   annotationsr+   r,   r-   r.   bidir/   r0   deprecationr1   r2   r3   r4   drawingr5   r6   r7   r8   drawing_primitivesr9   r:   r;   r<   r=   r>   r?   r@   
encryptionrA   enumsrB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   errorsr]   r^   r_   r`   rY  ra   rb   rc   rd   re   rf   graphics_staterg   rh   htmlri   image_datastructuresrj   rk   rl   rm   rn   image_parsingro   rp   rq   rr   
line_breakrs   rt   ru   rv   linearizationrw   outlinerx   r  ry   rz   r{   r|   r}   r~   r   r   r   rn  r   r  r   rm  r   structure_treer   r   r#  r   r   syntaxr   r   r   r   r   rC  r   r   text_regionr   r   transitionsr   unicode_scriptr   r   utilr   r   r   r   r   r   r   r   r   r   /cryptography.hazmat.primitives.asymmetric.typesr   cryptography.x509r   font_type_3r   prefsr   FPDF_VERSION__version__r   	getLoggerr!   r  __file__resolvera  HEREr   r   SINGLE_PAGE
ONE_COLUMNTWO_COLUMN_LEFTr   r-  r   r   r  r   r   r   r   modulesrT  __pdoc____all__r$   r%   r&   <module>r     sd
    				       				 				 



   # # # # # # % % % % % % ' ' ' ' ' ' ' '             " " " " " " " "                                     ( CCCCCC      NFFFF 	   HMP            3 2 2 2 2 2 2 2 2 2            < ; ; ; ; ; ; ;            Q P P P P P P P P P P P	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 0 / / / / /                                                         :            R Q Q Q Q Q Q Q Q Q Q Q Q Q Q Q > > > > > > > >                                          4 3 3 3 3 3 # # # # # #
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
       " " " " " "       < < < < < < < < # # # # # # # # F F F F F F F F F F F F F F * * * * * * * * 5 5 5 5 5 5 5 5 # # # # # # = = = = = = = =	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 IcNNGCLL )OOOOOO------&&&&&&(((((( 


  + 
	8	$	$tH~~&Vmt # # #$'%	3 3S(:../   $ $ $ $ $Z $ $ $ =A(S (S%u%%(S*25/(S
5%<(S (S (S (SV8AqD> hq!tn     pa pa pa pa pa pa pa palC #CH   !%(  s$   9B 
BBB "CC