
    (hy_                         S r SrSrSrSSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSKJr  SS	KJr  S
 rS r " S S5      r " S S\5      rg)z PDF Template Helpers for fpdf.pyz%Mariano Reingart <reingart@gmail.com>z#Copyright (C) 2010 Mariano ReingartzLGPL 3.0    N   )get_stack_level)FPDFException)FPDFc                 $    U S-  U S-  S-  U S-  4$ )Ni       )cols    IC:\Users\13-19\Desktop\PokeDex\pokedex\Lib\site-packages\fpdf/template.py_rgbr      s     5LC3J,c	::    c                     [        U 5      u  pnUS:X  a  US:X  a  US:X  d  US:X  a	  US-  S S3$ US-  S SUS-  S SUS-  S S3$ )Nr      z.3fz g z rg)r   )r
   rgbs       r   _rgb_as_strr      sf    3iGA!	Q16a1fbc'#b!!#gc]!AGC=!c'#c::r   c                      \ rS rSrSrS-S jrS r\S 5       r\S 5       r	S.S\
R                  S	\4S
 jjr   S/S\
R                  S\S\S	\4S jjrS r\rS rS rS rSSSSSSSSSSSSSSSSS.S jrSSSSSSSS.S jrSSSSSSSSS.S jrSSSSSSSSS.S jrSSSSSS .S! jrSSSSSS"S#SSS$.	S% jrSSSSS&SSSSSSS'.S( jrSSSSSSSSSSSSSS).S* jrS0S+ jrS,rg)1FlexTemplate   z
A flexible templating class.

Allows to apply one or several template definitions to any page of
a document in any combination.
Nc           	      \   [        U[        5      (       d  [        S5      eXl        SU l        U(       a  U R                  U5        U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S.U l        0 U l        g)a  
Arguments: pdf (fpdf.FPDF() instance): All content will be added to this object.

    elements (list of dicts): A template definition in a list of dicts.
        If you omit this, then you need to call either load_elements()
        or parse_csv() before doing anything else.
z('pdf' must be an instance of fpdf.FPDF()N)TLIBEBCC39W)
isinstancer   	TypeErrorpdfsplitting_pdfload_elements_text_line_image_rect_ellipse_barcode_code39_writehandlerstexts)selfr$   elementss      r   __init__FlexTemplate.__init__!   s     #t$$FGG!x(--<<	
 
r   c                 L   0 S[         [        S5      4_S[         [        S5      4_S[        [        4_S[        [        4_S[        [        4_S[        [        4_S[         [        S5      4_S	[        [        4_S
[        _S[        _S[        _S[        _S[        _S[         [        S5      4_S[         [        S5      4_S[        _S[
        [        S5      4_[        [        4[         [        S5      4S.EnXl        / U l        U GH  nSU;  a  SUS'   S Hh  nXC;  d  M
  US   S:X  aH  US:X  a  SU;   a
  US   US'   M)  US:X  a  SU;   a
  US   US'   M?  US:X  a  SU;   a  US   US   -   US'   M[  [        SU S35      e   SU;  a  US   S;   a  SUS'   O[        S5      eS	U;  a  US   S:X  a  SU;   a  US   US	'   UR                  5        H  u  pEXC;   d  M  [        X4   U5      (       a  M!  [        U[        5      (       a  UR                  O/SR                  U Vs/ s H  nS UR                   S 3PM     sn5      n[        S!U S"U S#[        X4   5      R                   S$35      e   U R                  R                  US   R                  5       5        GM     gs  snf )%zq
Load a template definition.

Arguments:

    elements (list of dicts): A template definition in a list of dicts
nameNtypex1y1x2y2fontsizebolditalic	underline
foreground
backgroundaligntextpriority	multiline)rotatewrapmoder   )r6   r7   r8   r9   r;   r    xyhzMandatory key 'z' missing in input datar   r    z(Mandatory key 'x2' missing in input datawz or 'zValue of element item 'z
' must be z, not ''.)strr7   intfloatobjectboolr2   keysKeyErroritemsr"   __name__joinr#   appendlower)r1   r2   
key_configektrI   ttypes           r   r&   FlexTemplate.load_elements;   s   
S$t*%
 S$t*%
 3,	

 3,
 3,
 3,
 S$t*%
 S%L
 F
 f
 
 #
 #
 c4:&
  S$t*%!
" #
$ $T
+%
& Eld4j))

. !	A? !*7:yE) 9&'fAdG$9&'fAdG$9&'g#&6AdG$"_QC7N#OPP 8" 1}V9-AdG"#MNNQ;1V9#5!8 !#AfI"((*6*QT1"5"5 &a.. 

#[[Q)GQAajj\*;Q)GH 
 $1!JugWTRSRVZM`M`Laacd  + IIQvY__./O D *Hs   "J!c                 l    U SS S;   a  [        U S5      $ U S   S:X  a  [        U S5      $ [        U 5      $ )z#Allow hex and oct values for colorsN   )0x0X   r   0   rQ   )ss    r   _parse_colorcodeFlexTemplate._parse_colorcode   s>     Ra5L q":Q43;q!91vr   c                 6    [        U 5      nUS:  a  gUS:  a  gg )Nr   TFri   )rj   is     r   _parse_multilineFlexTemplate._parse_multiline   s"    Fq5q5r   infileencodingc                 l   [        XS9 n[        R                  " U5      nU H  nUR                  S5      nU(       aW  [	        U[
        5      (       aB  UR                  5       R                  S5      (       a  [        USS S5      US'   O[        S5      eUR                  S5      nU(       d  M  [	        U[
        5      (       d  M  UR                  5       R                  S5      (       a  [        USS S5      US'   M  [        S	5      e   U R                  U5        SSS5        g! , (       d  f       g= f)
a_  
Load the template definition from a JSON file.
The data must be structured as an array of objects, with names and values exactly
equivalent to what would get supplied to load_elements(),

Arguments:

    infile (string or path-like object): The filepath of the JSON file.

    encoding (string): The character encoding of the file. Default is UTF-8.
rr   rA   #r   Nrf   z;If foreground is a string, it must have the form '#rrggbb'.rB   z;If background is a string, it must have the form '#rrggbb'.)openjsonloadgetr"   rP   r[   
startswithrQ   
ValueErrorr&   )r1   rq   rr   fdatadfgvalbgvals           r   
parse_jsonFlexTemplate.parse_json   s     &,99Q<Dl+Zs33{{}//44*-eABi*<,(Y  l+5Zs33{{}//44*-eABi*<,(Y  " t$' -,,s   B!D%/D%AD%%
D3	delimiterdecimal_sepc                   ^ S!U4S jjnS[         S4S[         S4SUS4SUS4SUS4SUS4S	[         S
4SUS
4S[        S
4S[        S
4S[        S
4SU R                  S
4SU R                  S
4S[         S
4S[         S
4S[        S
4SU R                  S
4SUS
4S[         S
44n/ U l        Uc  [
        R                  " 5       n[        XS9 n[        R                  " XrS9 H  nUR                  S/[        U5      [        U5      -
  -  5        0 n	[        X5       Hn  u  pU
R                  5       nU(       dB  US   (       a&  US   S:X  a  US   S;   a  M:  [        SUS    S 35      eUS   S:X  a  SU	S'   M\  M^  US   " U5      XS   '   Mp     U R                  R                  U	5        M     SSS5        U R                   V
s/ s H  oS   R!                  5       PM     sn
U l        g! , (       d  f       NA= fs  sn
f )"a  
Load the template definition from a CSV file.

Arguments:

    infile (string or path-like object): The filepath of the CSV file.

    delimiter (single character): The character that separates the fields in the CSV file:
        Usually a comma, semicolon, or tab.

    decimal_sep (single character): The decimal separator used in the file.
        Usually either a point or a comma.

    encoding (string): The character encoding of the file.
        Default is the system default encoding.
c                 h   > [        U R                  5       =(       d    UR                  TS5      5      $ )z-Convert to float with given decimal separator.)rR   stripreplace)rj   defaultr   s     r   _varsep_float-FlexTemplate.parse_csv.<locals>._varsep_float   s(     !'').w77SIJJr   r6   Tr7   r8   r9   r:   r;   r<   Fr=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   Nrt   )r    rc   r   r   rL   zMandatory value 'z' missing in csv data)rg   )rP   rQ   rk   ro   r2   localegetpreferredencodingrv   csvreaderextendlenzipr   r   rZ   r[   rU   )r1   rq   r   r   rr   r   r\   r|   rowkargsvalcfgvss      `         r   	parse_csvFlexTemplate.parse_csv   s   0	K S$S$=$'=$'=$'=$'S% ]E*S% sE"#u%400%8400%8c5!S% e$$//7}e,e$)

, 224H&,zz!9

B43z?SX#=>? #C 4HCBq6"1v~#a&M2I $&3&7Ax?T$U'" !" !Vz101E*- 2
 ),Ar
!f! !5" $$U++ : -. 59MMBMS[&&(MB	/ -,. Cs   C G!<G2!
G/c                     [        U[        5      (       d   S[        U5      R                   S35       eUR	                  5       U R
                  ;  a  [        SU 35      eX R                  UR	                  5       '   g )N!name must be of type 'str', not 'rO   z%Element not loaded, cannot set item: )r"   rP   r7   rX   r[   rU   r   r0   )r1   r6   values      r   __setitem__FlexTemplate.__setitem__  su    #
 
 	G.tDz/B/B.C2F	G 
 ::<tyy("Gv NOO#(

4::< r   c                     [        U[        5      (       d   S[        U5      R                   S35       eUR	                  5       U R
                  ;   $ )Nr   rO   )r"   rP   r7   rX   r[   rU   )r1   r6   s     r   __contains__FlexTemplate.__contains__  sS    #
 
 	G.tDz/B/B.C2F	G 
 zz|tyy((r   c                 <  ^ [        U[        5      (       d   S[        U5      R                   S35       eXR                  ;  a  [        U5      eUR                  5       mTU R                  ;   a  U R                  T   $ [        U4S jU R                   5       S 5      $ )Nr   rO   c              3   ^   >#    U  H"  oS    R                  5       T:X  d  M  US   v   M$     g7f)r6   rD   Nr[   ).0rI   keys     r   	<genexpr>+FlexTemplate.__getitem__.<locals>.<genexpr>%  s'     J161Bc1IYQvYs   --)
r"   rP   r7   rX   rU   rV   r[   r0   nextr2   )r1   r6   r   s     @r   __getitem__FlexTemplate.__getitem__  s    #
 
 	G.tDz/B/B.C2F	G 
 yy 4. jjl$**::c?"JJD
 	
r   c                 T  ^ [        U4S jU R                   5       5      nU R                  (       d)  [        5       U l        U R                  R	                  5         SnUR                  S5      (       a  US-  nUR                  S5      (       a  US-  nUR                  S5      (       a  US-  nU R                  R                  US	   XCS
   5        U R                  R                  US   US   -
  US   US   -
  [        U5      UR                  SS5      SSUR                  SS5      S9$ )a  
Split a string between words, for the parts to fit into a given element
width. Additional splits will be made replacing any '\n' characters.

Arguments:

    text (string): The input text string.

    element_name (string): The name of the template element to fit the text inside.

Returns:
    A list of substrings, each of which will fit into the element width
    when rendered in the element font style and size.
c              3   v   >#    U  H.  nUS    R                  5       TR                  5       :X  d  M*  Uv   M0     g7f)r6   Nr   )r   elementelement_names     r   r   /FlexTemplate.split_multicell.<locals>.<genexpr>7  s8      
(v$$&,*<*<*>> G(s   )9	9r   r>   r   r?   r   r@   Ur<   r=   r:   r8   r;   r9   rC   TLINESrH   WORD)rM   rK   rD   rC   dry_runoutputrH   )	r   r2   r%   r   add_pagery   set_font
multi_cellrP   )r1   rD   r   r   styles     `  r   split_multicellFlexTemplate.split_multicell(  s     
==
 

 !!!%D'');;vSLE;;x  SLE;;{##SLE##GFOUFOL!!,,dmgdm+dmgdm+T++gr*[[V4 - 
 	
r   r   r   	helvetica
         ?Fr   )r8   r9   r:   r;   rD   r<   r=   scaler>   r?   r@   rC   rA   rB   rF   rH   c          
      <   U(       d  g U R                   nUR                  [        U5      :w  a  UR                  " [	        U5      6   Uc  SnO3SnUR
                  [        U5      :w  a  UR                  " [	        U5      6   UR                  5       R                  5       nSnS HE  nUR                  SU S35      (       d  M  UR                  SU S35      (       d  M;  USS	 nUU-  nMG     U	(       a  US
-  nU
(       a  US-  nU(       a  US-  nUR                  UUXx-  5        UR                  X5        X1-
  XB-
  nnUc  UR                  UUUSUUS9  g U(       a  UR                  UUUSUUUS9  g UR                  UUUUUSSS9S   nUR                  UUUSUUS9  g )NFTr   r   r   r   <></   r   r   r   r   )rM   rK   rD   borderrC   fill)rM   rK   rD   r   rC   r   rH   r   )rM   rK   rD   rC   rH   r   r   )r$   
text_colorr   set_text_colorr   
fill_colorset_fill_colorr   r[   rz   endswithr   set_xycellr   )r1   r8   r9   r:   r;   rD   r<   r=   r   r>   r?   r@   rC   rA   rB   rF   rH   ___r$   r   r   tagwidthheights                            r   r'   FlexTemplate._textQ  s   * hh>>[44Z 01DD~~Z!88""D$45zz|!!# C3%qz**t}}r#a[/I/IAbz ! SLESLESLET5$,/

2vHHuT!5tHTNN!   >>! "  D HHuT!5tHTr   )r8   r9   r:   r;   r=   r   rA   c                8   U R                   R                  R                  5       R                  5       [	        U5      :w  a"  U R                   R
                  " [        U5      6   U R                   R                  XV-  5        U R                   R                  XX45        g N)	r$   
draw_color	serializer[   r   set_draw_colorr   set_line_widthline)
r1   r8   r9   r:   r;   r=   r   rA   r   r   s
             r   r(   FlexTemplate._line  sj     88((*002k*6MMHH##T*%56-bb%r   )r8   r9   r:   r;   r=   r   rA   rB   c                z   U R                   nUR                  R                  5       R                  5       [	        U5      :w  a  UR
                  " [        U5      6   Uc  SnO3SnUR                  [	        U5      :w  a  UR                  " [        U5      6   UR                  XV-  5        UR                  XX1-
  XB-
  US9  g NDFD)r   )r$   r   r   r[   r   r   r   r   r   r   rectr1   r8   r9   r:   r;   r=   r   rA   rB   r   r   r$   r   s                r   r*   FlexTemplate._rect  s     hh>>##%++-Z1HHZ 01EE~~Z!88""D$454<("'7r   c                z   U R                   nUR                  R                  5       R                  5       [	        U5      :w  a  UR
                  " [        U5      6   Uc  SnO3SnUR                  [	        U5      :w  a  UR                  " [        U5      6   UR                  XV-  5        UR                  XX1-
  XB-
  US9  g r   )r$   r   r   r[   r   r   r   r   r   r   ellipser   s                r   r+   FlexTemplate._ellipse  s     hh>>##%++-Z1HHZ 01EE~~Z!88""D$454<(BBGRWE:r   )r8   r9   r:   r;   rD   c          	      V    U(       a"  U R                   R                  XQX#U-
  XB-
  SS9  g g )Nr   )rM   rK   link)r$   image)r1   r8   r9   r:   r;   rD   r   r   s           r   r)   FlexTemplate._image  s(    HHNN4R7bgBNG r   interleaved 2of5 ntr   )	r8   r9   r:   r;   rD   r<   r=   r   rA   c       	         ,   U R                   nUR                  R                  5       R                  5       [	        U	5      :w  a  UR
                  " [        U	5      6   UR                  5       R                  5       nUS:X  a  UR                  XQX'U-  XB-
  S9  g g )Nr   )rM   rK   )	r$   r   r   r[   r   r   r   r   interleaved2of5)r1   r8   r9   r:   r;   rD   r<   r=   r   rA   r   r   r$   s                r   r,   FlexTemplate._barcode  s     hh>>##%++-Z1HHZ 01zz|!!#(("uH )r   g      ?)r8   r9   r;   rD   r=   r   rA   rI   rJ   rM   rK   c                V   Uc	  U	c  U
c  Ub"  [         R                  " S[        [        5       S9  U R                  nUR
                  R                  5       R                  5       [        U5      :w  a  UR                  " [        U5      6   X2-
  nUS::  a  SnUR                  XAX%U-  U5        g )NzVcode39 arguments x/y/w/h are deprecated since v2.4.4, please use x1/y1/y2/size instead
stacklevelr      )warningswarnDeprecationWarningr   r$   r   r   r[   r   r   r   code39)r1   r8   r9   r;   rD   r=   r   rA   rI   rJ   rM   rK   r   r   r$   s                  r   r-   FlexTemplate._code39  s      =AMQ]amMM8 #*, hh>>##%++-Z1HHZ 01G6A

4Rq1r   )r8   r9   r:   r;   rD   r<   r=   r   r>   r?   r@   r   rA   c                   U(       d  g U R                   nUR                  [        U5      :w  a  UR                  " [	        U5      6   UR                  5       R                  5       nSnS HE  nUR                  SU S35      (       d  M  UR                  SU S35      (       d  M;  USS nUU-  nMG     U	(       a  US-  nU
(       a  US	-  nU(       a  US
-  nUR                  UUXx-  5        UR                  X5        UR                  SX\5        g )Nr   r   r   r   r   r   r   r   r   r   r   )r$   r   r   r   r   r   r[   rz   r   r   r   write)r1   r8   r9   r:   r;   rD   r<   r=   r   r>   r?   r@   r   rA   r   r   r$   r   r   s                      r   r.   FlexTemplate._write  s    & hh>>[44Z 01zz|!!# C3%qz**t}}r#a[/I/IAbz ! SLESLESLET5$,/

2		!T r   c           	         [        U R                  S S9nU R                  R                  5          U GH  nUR	                  5       nU R
                  R                  US   R                  5       UR                  SS5      5      US'   US:w  aD  US   U-  US'   US   U-  US'   US   US	   US   -
  U-  -   US	'   US   US
   US   -
  U-  -   US
'   U(       a  US   U-   US'   US	   U-   US	'   U(       a  US   U-   US'   US
   U-   US
'   XGS'   US   R                  5       nU(       a  U R                  R                  X1U5         SU;   aO  US   (       aE  U R                  R                  US   US   US   5         U R                  U   " S0 UD6  SSS5        OU R                  U   " S0 UD6  SSS5        GM  SU;   aQ  US   (       aG  U R                  R                  US   US   US   5         U R                  U   " S0 UD6  SSS5        GM  U R                  U   " S0 UD6  GM     SSS5        0 U l        g! , (       d  f       N= f! , (       d  f       GM*  = f! , (       d  f       GM=  = f! , (       d  f       NM= f)a0  
Add the contents of the template to the PDF document.

Arguments:

    offsetx, offsety (float): Place the template to move its origin to the given coordinates.

    rotate (float): Rotate the inserted template around its (offset) origin.

    scale (float): Scale the inserted template by this factor.
c                     U S   $ )NrE   r	   )rI   s    r   <lambda>%FlexTemplate.render.<locals>.<lambda>M  s    a
mr   )r   r6   rD   r   r   r8   r9   r:   r;   r   r7   rG   Nr	   )sortedr2   r$   local_contextcopyr0   ry   r[   upperrotationr/   )	r1   offsetxoffsetyrG   r   sorted_elementsr   elehandler_names	            r   renderFlexTemplate.renderA  sa    !4KLXX##%*lln"jjnnS[->->-@#''&RTBUVFC< #D	E 1CI #D	E 1CI #D	c$i'$-.G5-P QCI #D	c$i'$-.G5-P QCI #D	G 3CI #D	G 3CI #D	G 3CI #D	G 3CI$G"6{002**6GD#s?s8}!%!2!23x=#d)SQUY!W $l ; Bc B "X!W !MM,7>#> ED  33x=!XX..s8}c$iTS MM,7>#> TS l3:c:9 + &< 
 "X!W ED TS5 &%sU   DI37I<H<	I0AI31I %I3<
I
I
I	I3 
I0*	I33
J)r2   r/   rU   r$   r%   r0   r   )zutf-8),r   N)        r  r  r   )rX   
__module____qualname____firstlineno____doc__r3   r&   staticmethodrk   ro   osPathLikerP   r   r   r   setr   r   r   r'   r(   r*   r+   r)   r,   r-   r.   r  __static_attributes__r	   r   r   r   r      s   4H0T    % % %H MCMC MC 	MC
 MC^) C)
'
X %FUV &( 88 ;2 !ab H "I2 



2L &!P+r   r   c                   Z   ^  \ rS rSrSr          SU 4S jjrS rSU 4S jjrSrU =r	$ )	Templateio  zf
A simple templating class.

Allows to apply a single template definition to all pages of a document.
c                   > U(       a"  [         R                  " S[        [        5       S9  S H2  n[	        [        5       U   [        5      (       a  M%  [        SU S35      e   [        X4US9nUR                  U5        UR                  U5        UR                  U	5        UR                  U5        UR                  U
5        [        TU ]=  XS9  g)	a5  
Arguments:

    infile (str): [**DEPRECATED since 2.2.0**] unused, will be removed in a later version

    elements (list of dicts): A template definition in a list of dicts.
        If you omit this, then you need to call either load_elements()
        or parse_csv() before doing anything else.

    format (str): The page format of the document (eg. "A4" or "letter").

    orientation (str): The orientation of the document.
        Possible values are "portrait"/"P" or "landscape"/"L"

    unit (str): The units used in the template definition.
        One of "mm", "cm", "in", "pt", or a number for points per unit.

    title (str): The title of the document.

    author (str): The author of the document.

    subject (str): The subject matter of the document.

    creator (str): The creator of the document.
zD"infile" is deprecated since v2.2.0, unused and will soon be removedr   )formatorientationunittitleauthorsubjectcreatorkeywordsz
Argument "z" must be of type str.)r  r  r  )r$   r2   N)r   r   r   r   r"   localsrP   r#   r   	set_title
set_authorset_creatorset_subjectset_keywordssuperr3   )r1   rq   r2   r  r  r  r  r   r!  r"  r#  argr$   	__class__s                r   r3   Template.__init__x  s    L MMV"*,
	
C fhsmS11*SE1G HII	
 &Eev  "S4r   c                     U R                   R                  (       a  U R                  5         U R                   R                  5         g)z5Finish the current page, and proceed to the next one.N)r$   pager  r   )r1   s    r   r   Template.add_page  s&    88==KKMr   c                 $  > U(       a"  [         R                  " S[        [        5       S9  U R                  R                  SSSS9  U R                  R                  SSS	9  [        TU ]!  5         U(       a  U R                  R                  U5        g
g
)a1  
Finish the document and process all pending data.

Arguments:

    outfile (str): If given, the PDF file will be written to this file name.
        Alternatively, the `.pdf.output()` method can be manually called.

    dest (str): [**DEPRECATED since 2.2.0**] unused, will be removed in a later version.
zB"dest" is deprecated since v2.2.0, unused and will soon be removedr   r   r   rf   )r   r=   Fr   )marginN)
r   r   r   r   r$   r   set_auto_page_breakr*  r  r   )r1   outfiledestr,  s      r   r  Template.render  st     MMT"*,
 	+Sr:$$U1$5HHOOG$ r   r	   )
NNA4portraitmmr   r   r   r   r   )NN)
rX   r  r  r  r  r3   r   r  r  __classcell__)r,  s   @r   r  r  o  s=     ?5B% %r   r  )r  
__author____copyright____license__r  r   rw   r   r   deprecationr   errorsr   fpdfr   r   r   r   r  r	   r   r   <module>rA     sN    &4
5 & & & ( ! ;;S	 S	lf%| f%r   