
    }f                     X   d Z ddlmZ ddlmZmZ ddlZddlZddlZddl	m
Z
 ddlmZmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZ  ej        e          ZdZdZdZ ed           ed           ed           edd           edd           edd           edd           edd           edd           ed          d
Z ddddZ!d "                    d!          Z# ej$        d"e# d#          Z%i d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdAdCdDi dEdFdGdHdIdJdKdLdMdNdOdNdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddei dfdgdhdidjdkdldkdmdndodpdqdrdsdrdtdudvdudwdxdydzd{d|d}d~ddddddi ddddddddddddddddddddddddddddddddddi ddddddddddddddddddddddddddddddddēddƓi ddȓddʓddʓdd͓ddϓddѓddӓddՓddדddٓddۓddݓddߓddddddddi ddddddddddddddddddddddddd ddddddddd	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*d+d,d-d.d/d0d1d2d3d4d5d6d7Z&d@d8Z'd9 Z( G d: d;e          Z)d< Z*d= Z+ G d> d?          Z,dS (A  z
HTML renderer

The contents of this module are internal to fpdf2, and not part of the public API.
They may change at any time without prior warning or any deprecation period,
in non-backward-compatible ways.
    )
HTMLParser)ascii_lowercaseascii_uppercaseN   )get_stack_level)color_from_hex_stringconvert_to_device_color)TextEmphasisXPosYPos)FPDFException)FontFace)Table)	int2roman      °)h1h2h3h4h5h6)r   r      )color)d   r   -   Courierfamily)   r   r      )r   size_pt         
      )
a
blockquotecoder   r   r   r   r   r   pre   )r)   ddli )z	-    u    - u    u    u    u   　[z]+black#000000navyz#000080darkbluez#00008b
mediumbluez#0000cdbluez#0000ff	darkgreenz#006400greenz#008000tealz#008080darkcyanz#008b8bdeepskybluez#00bfffdarkturquoisez#00ced1mediumspringgreenz#00fa9alimez#00ff00springgreenz#00ff7faquaz#00ffffcyanmidnightbluez#191970
dodgerbluez#1e90fflightseagreenz#20b2aaforestgreenz#228b22seagreenz#2e8b57darkslategrayz#2f4f4fdarkslategrey	limegreenz#32cd32mediumseagreenz#3cb371	turquoisez#40e0d0	royalbluez#4169e1	steelbluez#4682b4darkslatebluez#483d8bmediumturquoisez#48d1ccindigoz#4b0082darkolivegreenz#556b2f	cadetbluez#5f9ea0cornflowerbluez#6495edrebeccapurplez#663399mediumaquamarinez#66cdaadimgrayz#696969dimgrey	slatebluez#6a5acd	olivedrabz#6b8e23	slategrayz#708090	slategreylightslategrayz#778899lightslategreymediumslatebluez#7b68ee	lawngreenz#7cfc00
chartreusez#7fff00
aquamarinez#7fffd4maroonz#800000purplez#800080olivez#808000grayz#808080greyskybluez#87ceeblightskybluez#87cefa
bluevioletz#8a2be2darkredz#8b0000darkmagentaz#8b008bsaddlebrownz#8b4513darkseagreenz#8fbc8f
lightgreenz#90ee90mediumpurplez#9370db
darkvioletz#9400d3	palegreenz#98fb98
darkorchidz#9932ccyellowgreenz#9acd32siennaz#a0522dbrownz#a52a2adarkgrayz#a9a9a9darkgrey	lightbluez#add8e6greenyellowz#adff2fpaleturquoisez#afeeeelightsteelbluez#b0c4de
powderbluez#b0e0e6	firebrickz#b22222darkgoldenrodz#b8860bmediumorchidz#ba55d3	rosybrownz#bc8f8f	darkkhakiz#bdb76bsilverz#c0c0c0mediumvioletredz#c71585	indianredz#cd5c5cperuz#cd853f	chocolatez#d2691etanz#d2b48c	lightgrayz#d3d3d3	lightgreythistlez#d8bfd8orchidz#da70d6	goldenrodz#daa520palevioletredz#db7093crimsonz#dc143c	gainsboroz#dcdcdcplumz#dda0dd	burlywoodz#deb887	lightcyanz#e0fffflavenderz#e6e6fa
darksalmonz#e9967avioletz#ee82eepalegoldenrodz#eee8aa
lightcoralz#f08080khakiz#f0e68c	alicebluez#f0f8ffhoneydewz#f0fff0azurez#f0ffff
sandybrownz#f4a460wheatz#f5deb3beigez#f5f5dc
whitesmokez#f5f5f5	mintcreamz#f5fffa
ghostwhitez#f8f8ffsalmonz#fa8072antiquewhitez#faebd7linenz#faf0e6lightgoldenrodyellowz#fafad2oldlacez#fdf5e6redz#ff0000fuchsiaz#ff00ffmagentadeeppinkz#ff1493	orangeredz#ff4500tomatoz#ff6347hotpinkz#ff69b4coralz#ff7f50
darkorangez#ff8c00lightsalmonz#ffa07aorangez#ffa500	lightpinkz#ffb6c1pinkz#ffc0cbgoldz#ffd700	peachpuffz#ffdab9navajowhitez#ffdeadmoccasinz#ffe4b5bisquez#ffe4c4	mistyrosez#ffe4e1z#ffebcdz#ffefd5z#fff0f5z#fff5eez#fff8dcz#fffacdz#fffaf0z#fffafaz#ffff00z#ffffe0z#fffff0z#ffffff)blanchedalmond
papayawhiplavenderblushseashellcornsilklemonchiffonfloralwhitesnowyellowlightyellowivorywhitec                     | sd S t                               |                                 |           }t          |          j        S N)
COLOR_DICTgetlowerr   	colors255)r   hexcolors     B/var/www/rtfcompare/venv/lib/python3.11/site-packages/fpdf/html.pycolor_as_decimalr      s=     t ~~ekkmmU33H **44    c                 <   	 | d         }|                     d          D ]k}|s|                     d          }t          |          dk    r>|d         r6|d         r.|\  }}|                                | |                                <   ldS # t          $ r Y dS w xY w)zDParse `style="..."` making it's key-value pairs element's attributesstyle;:   r   r   N)splitlenstripKeyError)
elem_attrsr   elementpairattrvalues         r   parse_styler      s    97# {{3'' 	9 	9G ==%%D4yyA~~$q'~d1g~"e+0;;==
4::<<(	9 	9    s   B 
BBc                        e Zd ZdZdZdZddddedded	         j        d
ddf fd	Z		 ddZ
d ZddZddZd Zd Zd Zd Z fdZddZd dZd!dZd Zd Zd Z xZS )"	HTML2FPDFzRender basic HTML to FPDF)brr-   dthrimgr.   tdtrg?Nr,   r&   F)   r   r   r+   Tc                 d   t                                                       || _        |pd | _        || _        t          |t                    rt          |          nt          |          j	        | _
        |
| _        t          ddd          | _        |j        | _        |                     |j        pd| j        d           |j        | j        | j        f| _        | j                                         d| _        d| _        d| _        d| _        d| _        d| _        g | _        d| _        g | _        g | _        |j        j	        | _        d	| _         d
| _!        d| _"        g | _#        | j        $                    d          | _%        | j%        &                                | _'        || _(        d	| _)        d	| _*        d	| _+        d	| _,        |si }|tZ          d         k    r-t]          j/        dt`          tc                                 ||d<   |tZ          d         k    r-t]          j/        dt`          tc                                 ||d<   |D ]}|tZ          vrte          d| d          i tZ          || _3        |si }|D ]}|th          vrte          d| d          i th          || _5        |kt]          j/        dt`          tc                                 |6                                D ].\  }}| j5        |         7                    |          | j5        |<   /|	th          d         j8        k    r|t]          j/        dt`          tc                                 | j5        d         7                    |	          | j5        d<   | j5        d         7                    |	          | j5        d<   d	S d	S )aG  
        Args:
            pdf (FPDF): an instance of `fpdf.FPDF`
            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_indents instead
            dd_tag_indent (int): [**DEPRECATED since v2.7.9**] numeric indentation of <dd> elements - Set tag_indents instead
            table_line_separators (bool): enable horizontal line separators in <table>
            ul_bullet_char (str): bullet character preceding <li> items in <ul> lists.
            li_prefix_color (tuple | str | drawing.Device* instance): 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
            tag_indents (dict): mapping of HTML tag names to numeric values representing their horizontal left identation
            tag_styles (dict): mapping of HTML tag names to colors
        c                     | S r    )srcs    r   <lambda>z$HTML2FPDF.__init__.<locals>.<lambda>-  s    3 r   FbiutimesTsizeset_defaultr/   r   Ng?g?)skip_leading_spacesr-   zThe dd_tag_indent parameter is deprecated since v2.7.9 and will be removed in a future release. Set the `tag_indents` parameter instead.
stacklevelr.   zThe li_tag_indent parameter is deprecated since v2.7.9 and will be removed in a future release. Set the `tag_indents` parameter instead.z Cannot set indent for HTML tag <z5> (contributions are welcome to add support for this)zCannot set style for HTML tag <zThe heading_sizes parameter is deprecated since v2.7.9 and will be removed in a future release. Set the `tag_styles` parameter instead.)r"   r+   zThe pre_code_font parameter is deprecated since v2.7.9 and will be removed in a future release. Set the `tag_styles` parameter instead.r*   r   )9super__init__pdf	image_mapul_bullet_char
isinstancestrr   r	   r   li_prefix_colorwarn_on_tags_not_matchingdictemphasisfont_size_pt	font_sizeset_fontfont_family
_prev_font_push_local_stack_pre_formatted_pre_startedfollows_trailing_spacefollows_headinghrefalignstyle_stackindentol_typebullet
text_color
font_colorheading_levelheading_aboveheading_below_tags_stacktext_columns_column	paragraph
_paragraphtable_line_separatorstable	table_rowr   td_thDEFAULT_TAG_INDENTSwarningswarnDeprecationWarningr   NotImplementedErrortag_indentsDEFAULT_TAG_STYLES
tag_stylesitemsreplacer   )selfr   r   li_tag_indentdd_tag_indentr  r   r  heading_sizespre_code_fontr  r(  r*  _tagr   	__class__s                   r   r   zHTML2FPDF.__init__
  s6   B 	"7, /3//D_---(99C 	
 *C& u777)co0t~SWXXX?DNDMJ""$$$# 	 ',#$	
.2!  x,,,FF,0022%:"

  	K/555M? #*,,    !.K/555M? #*,,    !.K 	 	C---)qsqqq   . B1A[A 	J 	 	C,,,)pcppp   - ?/>:>$M> #*,,    +0022 R R	T'+s';'C'CD'C'Q'Q$$.u5<<<M> #*,,    '+of&=&E&E$ 'F ' 'DOF# &*_U%;%C%C$ &D & &DOE""" =<r         ?r   c                     |                                   |pd| _        |s| j        s| j        | j        j        z  }| j                            ||d||          | _        d| _	        d| _        d S )Nr/   T)
text_alignline_heightr   
top_marginbottom_marginF)
_end_paragraphr  r  r  r   kr  r  r  r  )r-  r  r8  r9  r:  s        r   _new_paragraphzHTML2FPDF._new_paragraph  s     	[b
 	5$"6 	5$(*4J,00# $!' 1 
 
 '+#$r   c                    d| _         | j        ru| j                                         | j                                        }| j                                         | j                            |           d | _        d| _        d S d S )Nr/   T)	r  r  r  end_paragraphr   _pop_local_stackrenderr
  r  )r-  our_contexts     r   r;  zHTML2FPDF._end_paragraph  s    
? 	/L&&((())++  L!!!H&&{333"DO*.D'''	/ 	/r   c                 t    | j         s|                                  | j                             ||           d S )Nlink)r  r=  write)r-  textrE  s      r   _write_paragraphzHTML2FPDF._write_paragraph  s?     	"!!!d.....r   c                     | j         r| j                             |           n| j                            |           d| _        d S )N)hT)r  lnr  r  )r-  rJ  s     r   _lnzHTML2FPDF._ln  sL    ? 	!O####LOOaO   &*###r   c           	         | j         |                                }|sd S d| j         v r.| j         d         }t          d| d| j        d          d          | j                             d| j                            d                    }|r|                                }t          | j                             d| j                            dd                               }t          | j                             d	d
                    }t          | j                             dd
                    }d}| j                             d          r|t          j
        z  }| j                             d          r|t          j        z  }| j                             d          r|t          j        z  }d }|s|rt          ||| j        j                  }| j                            |||||           d| j         d<   d S | j        d S | j        rj|                    d          o| j        }	d| _        |                    d          }
|	r|
r|dd         }n|	r
|dd          }|                     |           d S t0                              d|          }| j        r*|d         dk    r|                     |dd                     n|                     |           |d         dk    | _        d S )Ninsertedr3  z%Unsupported nested HTML tags inside <z> element: <>r  bgcolorcolspan1rowspanr   r   r   U)r  
fill_colorr   )rG  r  r   rR  rT  T
Fr   r0   )r"  r   r'  r  r   r   upperr   intr
   BIrU  r   r   r  r!  cellr   r  
startswithr  endswith_write_data_WS_SUB_PATsubr  )r-  data	td_th_tagr  rQ  rR  rT  r  r   s_nle_nls              r   handle_datazHTML2FPDF.handle_data  s   :!::<<D TZ'' Ju-	)jIjjSWScdfSgjjj   JNN7DGKK,@,@AAE &&
y$'++i*F*FGG G $*..C8899G$*..C8899GHz~~c"" +LN*z~~c"" +LN*z~~c"" +LN*E (  %'AT   NeWg      &*DJz"""Z#D  	: ??4((>T->D %D==&&D    AbDz  ABBx T"""""??3--D* 'tAw#~~  abb****  &&&*.r(c/D'''r   c                 B   | j         r|                     |           d S | j        r@| j        j        rt          d          | j                            || j        dz
  d           t                              d| j	        d|           | 
                    |           d S )NzCombining write_html() & section styles is currently not supported. You can open up an issue on github.com/py-pdf/fpdf2 if this is something you would like to see implemented.r   F)strictzwrite: '%s' h=.2f)r  put_linkr  r   section_title_stylesr'  start_sectionLOGGERdebugrJ  rH  )r-  rb  s     r   r_  zHTML2FPDF._write_data  s    9 	(MM$! S80 -G   &&tT-?!-CE&RRRLL6$&666===!!$'''''r   c           
         d| _         t          |          }t                              d||           t	          |           | j                            |           |dk    r|                     d           d}|dk    r&|                     dd| j        d         z  z              |dk    rd}|d	k    rd
}|dv r(| j	        d| j	        |<   n| 
                    |d           |dk    rS|d         | _        	 t          | j                  }| j                            |          | _        n# t          $ r Y nw xY w|dk    r|                     d           |dk    rd }d|v r3|                    d          d                                         }|dvrd }d }d|v r4	 t%          |                    d                    }n# t          $ r Y nw xY w|                     ||           |t(          v rF| j        | j        j        z  }| j                            t1          | j        | j        | j                             t          |dd                    | _        | j        |         }|j        p| j        | j        j        z  }|r|                    d          }|dvrd }nd }|                     ||| j        |z  z   | j        |z             d }	d|v rtA          |d                   }	n|j!        r|j!        j"        }	|	r
 | j#        |	  | $                    |j%        p| j        |j        p| j                   |dk    r| j        &                    d           |dk    r| j                            t1          | j        | j        | j                             | j        |         }|j!        r | j#        |j!        j"          | $                    |j%        p| j        |j        p| j                   |dk    r| j                            t1          | j        | j        | j                             | j        |         }|j!        r | j#        |j!        j"          | $                    |j%        p| j        |j        p| j                   d| _'        |                                  d| _         |d k    r| j        |         }|j!        r | j#        |j!        j"          | $                    |j%        p| j        |j        p| j                   | xj(        dz  c_(        |                     d!d!"           | j        d          r#|                     d| j        d          z             |d#k    r| xj(        dz  c_(        d$|v rtS          |d$                   n| j*        }
| j+                            |
           d }d|v r4	 t%          |                    d                    }n# t          $ r Y nw xY w|                     |%           |d&k    r| xj(        dz  c_(        d'|v rt          |d'                   nd}| j+                            |dz
             | j,                            |                    d$d(                     d }d|v r4	 t%          |                    d                    }n# t          $ r Y nw xY w|                     |%           |d)k    r| -                    d*            | j#        | j.          | j+        r| j+        | j(        dz
           }n| j*        }t_          |t`                    s?|dz  }|| j+        | j(        dz
  <   | j,        | j(        dz
           }tc          ||           d+}d| j        d)         z  | j(        z  }|                     | | d,            | j#        | j          |d-k    r| j                            t1          | j        | j        | j                             d|v rtA          |d                   }	|	| _        d.|v rC|                    d.          2                                }| $                    |           || _        d/|v r't          |                    d/                    | _        | $                                  | j#        | j          |d0k    rB|                    d1          }|rP|d2         d3k    r(| j        j3        t          |d d2                   z  d4z  }nt          |          | j        j        z  }d5|vr| j4        rd6nd7}n#t          |d5                   r| j4        rd8nd9}nd:}|                    dd;                                          }d<|v rt%          |d<                   nd }t%          |                    d=d                    }tk          | j        ||| j6        | j7        z  ||||>          | _8        | -                                 |d?k    rW| j8        sts          d@          dA |:                                D             | _;        | j8        <                                | _=        |dBv rr| j=        sts          dC| dD          dE |:                                D             | _	        || j	        dF<   |dGk    rd| j	        vr
dH| j	        d<   d| j	        d<   nAt}          | j8        j?                  dk    r$| j=        j@        sd| j8        _A        d| j8        _B        dI|v r"t          C                    dJ|dI         |           d1|v r|d1         }t}          | j8        j?                  dk    r[|d2         d3k    r
|d d2         }| j8        jD        sg | j8        _D        | j8        jD                            t          |                     nt          C                    dK||           |dLk    rdM|v rt          |                    d1d                    | j        j        z  }t          |                    dId                    | j        j        z  }| j=        rm|s|rt          C                    dN           | jE        rt          C                    dO           | j=        F                    |dM         dP           d| j	        dQ<   d S | j        jG        |z   | j        jH        k    r| j        &                    d           | j        I                                | j        J                                }}| jE        r8| jE        d                                         dRk    r| j        jK        d*z  |d*z  z
  }t                              dS|dM         ||||           | j        L                    | M                    |dM                   ||||| j        T          }| j        N                    ||jO        z              |d;k    r|                     dRU           |dVk    rV| P                                 | j        Q                    | jR        t          |                    dWd                    X           |dYk    rdZ| j        _S        |d[k    rd\| j        _S        d S d S )]NFzSTARTTAG %s %sr   rW  r   r-       strongemr   r   Tr(   r  pager   pr  r   )LRJCzline-height)r  r8  )r   r"   r   r   )r  r9  r:  r   r   r   r   )samer*   r+   r)      )r9  r:  ultype)r8  olstartrS  r.   r   z. r0   fontfacer   r   widthrO  %r   borderHORIZONTAL_LINESSINGLE_TOP_LINEALLNO_HORIZONTAL_LINESNONEcentercellpaddingcellspacing)r  borders_layoutr8  r  paddinggutter_widthgutter_heightr   z+Invalid HTML: <tr> used outside any <table>c                 >    i | ]\  }}|                                 |S r   r   .0r<  vs      r   
<dictcomp>z-HTML2FPDF.handle_starttag.<locals>.<dictcomp>  s&    >>>1qwwyy!>>>r   r   thzInvalid HTML: <z> used outside any <tr>c                 >    i | ]\  }}|                                 |S r   r  r  s      r   r  z-HTML2FPDF.handle_starttag.<locals>.<dictcomp>  s&    AAA41a!''))QAAAr   r3  r  CENTERheightz4Ignoring unsupported height="%s" specified on a <%s>zEIgnoring width="%s" specified on a <%s> that is not in the first <tr>r   r   z<Ignoring unsupported "width" / "height" set on <img> elementz$Ignoring unsupported <img> alignment)r   img_fill_widthrN  ry  z'image "%s" x=%d y=%d width=%d height=%drD  )r  tocpages)r  supSUPra  SUB)Tr  r  rm  rn  r   r  appendrH  r(  r"  	set_styler  rY  r   add_link
ValueErrorr   rX  floatr=  HEADING_TAGSr  r<  r  r   r  r  r  r*  r"   r  r  r   r   r   set_text_colorr  r   add_pager  r  	ul_prefixr   r  r  rL  r  r   r   	ol_prefixr   epwr  r   rJ  TABLE_LINE_HEIGHTr   r   r+  r   rowr!  r   rowscells_first_row_as_headings_num_heading_rowswarning_col_widthsr  r\  ypage_break_triggerget_xget_ywimager   set_yrendered_heightr;  insert_toc_placeholder
render_toc	char_vpos)r-  r3  attrsrt  r  r8  prev_font_height	tag_stylehsizer   bullet_charr  r  r  r  r  r  r  r  spacingr  xr  infos                           r   handle_starttagzHTML2FPDF.handle_starttag  s{   !U%sE222E$$$$;;!!$'''C$;;!!$D4DT4J)J"JKKK(??C$;;C/!!z%"&
3sD)))#::fDI49~~ H--4-88		   $;;!!$'''#::E%		'**1-3355 444 EK%%"'		-(@(@"A"AKK!   DeEEE,#~
:##+ N/     "%SWD,I&8$.DHJFE 		'** 444 E+d.@5.HH"058     
 E%(w88 2!1 ,##U++MM ';4+;&8$.     $;;H4(((&==##+ N/     ,I @##Y_%>??MM ';4+;&8$.     %<<##+ N/     ,I @##Y_%>??MM ';4+;&8$.     #'D!!! $D,,I @##Y_%>??MM ';4+;&8$.     KK1KK1A>>>- Q%%h1A,1O&OPPP$;;KK1KK,2eOO	%-(((AT  K{+++K%%"'		-(@(@"A"AKK!   DK888$;;KK1KK+2e+;+;Cg'''EKuqy)))L		&# 6 6777K%%"'		-(@(@"A"AKK!   DK888$;;HHQKKKD!566{ -T[1_5 ,fc** ;!/5DK!O,,t{Q7%gv66::: 0 66DF!!V"6V"6"6"6777D11&==##+ N/     %(w88"'yy((..00d####' !$UYYv%6%6!7!7MMOOOD11'>>IIg&&E 49## HL3uSbSz??:S@EEJJ3Eu$$ 1+&&* 
 U8_%% (!7REE=R  "(IIgx006688E5Be5K5KeE-0111QUGEIImQ7788G- FT%;;$%	 	 	DJ HHJJJ$;;: S#$QRRR>>>>>DG!Z^^--DN,> T#$Rc$R$R$RSSSAA5;;==AAADJ #DJud{{$*,,*2DJw'"&
3TZ_%%**4>3G* 5:
1/0
,5  J(O  
 %gtz''1,,RyC'' %crc
:1 413
.J*11#e**====NN_  
 %<<EUNN		'1--..;E8Q//0048:=F~ 	 F NNV   : KNN#IJJJ##eT#JJJ)-
:&xzF"TX%@@@!!t!,,,8>>##TX^^%5%5qAz /djm1133s::HJNUQY.LL9e   8>>uU|,,aE6	 "  D HNN1t33444(??c***%<<!!!H++s599Wa+@+@'A'A ,    %<<!&DH%<<!&DH <sH   54D* *
D76D7"F> >
G
G/"W 
WW;"Z 
Z+*Z+c           	      	   t                               d|           | j        rj|| j        d         k    rY| j        d         | j        v rE| j                                         | j        r%|| j        d         k    r| j        d         | j        v E| j        s#| j        rt                               d|           nY|| j        d         k    r| j                                         n.| j        r't                               d|| j        d                    |t          v rod | _        | j	                                        }| 
                    |j        |j                    | j        |j        j          |                                  d| _        |dk    rM| j	                                        }| 
                    |j        |j                    | j        |j        j          |dk    ro|                                  | j	                                        }| 
                    |j        |j                    | j        |j        j          d| _        d| _        |d	k    r3|                                   | j        | j          | xj        d
z  c_        |dv rd}|dk    rd}|dv r| j        |                     |d           |dk    rd| _        |dk    r|                                  d| _        |dv r\|                                  | xj        d
z  c_        |dk    r| j                                         | j                                         |dk    r:| j                                         d | _        |                     | j                   |dk    rd | _         d | _!        |dv rd| j        vrqtE          | j        #                    d| j         #                    dd                               }|rtI          |          nd }| j!        %                    d|           d | _        |dk    r^| j	                                        }|j        j        | _        | 
                    |j        |j                    | j        |j        j          |dk    r|                                  |dk    rd| j&        _'        |d k    rd| j&        _'        d S d S )!Nz	ENDTAG %srO  z8Unexpected HTML end tag </%s>, start tag may be missing?z1Unexpected HTML end tag </%s>, start tag was <%s>Tr*   r+   Fr)   r   )rq  r   r   rr  r   r   r(   r/   ru  )r}  r  r  r   r   r  rN  rQ  )rV  )rG  r   r  r  r  LINEra  )(rm  rn  r  HTML_UNCLOSED_TAGSpopr  r  r  r  r  r  r   r"   r  r   r   r;  r  r  r  r  r  r"  r  r  r  r  r  r   rA  rL  rJ  r   r!  r   r   r   r\  r   r  )r-  r3  	font_facerQ  r   s        r   handle_endtagzHTML2FPDF.handle_endtagJ  s   [#&&&	#t'+++ $(???  """	 	#t'+++ $(???  	- NPS   D$R(((  """"+ 	NNC $  
 ,!%D(,,..IMM)*I,=>>>D!:;;!!!#'D &==(,,..IMM)*I,=>>>D!:;;%<<!!!(,,..IMM)*I,=>>>D!:;;"'D %D,!!!D11KK1KK"""C$;;C/!!:)sE***#::DI#::!!!DJ,!!!KK1KKd{{  """KOO'>>JDJHHTV$;;DG!DN,++*JNN9dgkk)T.J.JKK  9@IG4444T##5#999DJ&==(,,..I'o7DOMM)*I,=>>>D!:;;(??!!!%<<!'DH%<<!'DH <r   c                 L   t                                          |           | j        rH| j        d         | j        v r4| j                                         | j        r| j        d         | j        v 4|                                  | j                                         | j        d         r@| j        d         | _	        | 
                    | j        d         | j        d         d           | j        r/| j        r*t                              d| j        d                    d S d S d S )NrO  r   r   r   Tr   zMissing HTML end tag for <%s>)r   feedr  r  r  r;  r   r@  r	  r  r  r  rm  r  )r-  rb  r4  s     r   r  zHTML2FPDF.feed  s-   T 	#4#3B#74;R#R#R  """  	#4#3B#74;R#R#R!!###?1 	Y OA.DMMM$/!,4?13ESWMXXX 	R > 	RNN:D<LR<PQQQQQ	R 	R 	R 	Rr   c                 T    |r| _         |r| _        | j        j        z   _        d                     fddD                                                       }t                              d j        d j         |            j        j	        }|sd j        _	         j         |f j        j          j        j
        fk    r& j                             j         | j                    j         j        j        k    r j                             j                   | j        _	        d S )Nr/   c              3   P   K   | ] }j                             |          |V  !d S r   r  r   r  sr-  s     r   	<genexpr>z%HTML2FPDF.set_font.<locals>.<genexpr>  8      KKadm6G6G6J6JKKKKKKKr   r   zset_font: %s style=%s h=ri  r   )r  r  r   r<  rJ  joinrX  rm  rn  rt  
font_styler  set_font_size)r-  r   r   r   r   	prev_pages   `     r   r  zHTML2FPDF.set_font  s    	&%D 	'!DNDHJ&DFKKKK?KKKKKQQSS<<<<d>NPUVVVHM	 	DHMe$)=tx?R(SSSHd.t~FFF>TX///H""4>222!r   c                 :    |r| j         |                                <   d                     fddD                       }t                              d|            j        j        }d j        _         j                            |           | j        _        d S )Nr/   c              3   P   K   | ] }j                             |          |V  !d S r   r  r  s     r   r  z&HTML2FPDF.set_style.<locals>.<genexpr>  r  r   r   zSET_FONT_STYLE %sr   )r   )r  r   r  rm  rn  r   rt  r  )r-  r3  enabler   r  s   `    r   r  zHTML2FPDF.set_style  s     	0)/DM#))++&KKKK?KKKKK(%000HM	&&&!r   c                     | j         j        }d| j         _        | j                             |||           || j         _        d S )Nr   )r   rt  r  )r-  rgr   r  s        r   r  zHTML2FPDF.set_text_color  s;    HM	1a(((!r   c                 b   | j         d         }|j        r | j        |j        j          |                     |j        p| j        |j        p| j                   | 	                    dd           | 
                    || j                   | 	                    dd            | j        | j          d S )Nr(   rz  r   TrD  F)r*  r   r  r   r  r   r  r"   r  r  rH  r  r  )r-  rG  r  s      r   rj  zHTML2FPDF.put_link  s    OC(	? 	<D!:;;#7t'7"4dn 	 	
 	
 	
 	sD!!!d333sE"""T_----r   c           	      t   |                                  |D ]}|                    |j                  }d|j        z  dz   d|j         }|ddd|j        dz  z
  t          |j                  z
  z   d|j         z  }|                    |j        |j        |t          j
        t          j        |           dS )zTThis method can be overriden by subclasses to customize the Table of Contents style.rs  r0   r   .<   )r  rJ  rG  new_xnew_yrE  N)rK  r  page_numberlevelnamer   
multi_cellr  r  r   LMARGINr   NEXT)r-  r   outlinesectionrE  rG  s         r   r  zHTML2FPDF.render_toc  s     	 	G<<W%8<99DGM)A->>>>D`rGM!O3c',6G6GGH``7K^```DNN'-li     		 	r   c                      t          |          r   )RuntimeError)r-  messages     r   errorzHTML2FPDF.error  s    7###r   )Nr5  r   r   r   )NNF)NF)Nr   r   )__name__
__module____qualname____doc__r  r  BULLET_WIN1252r)  r   r   r=  r;  rH  rL  rf  r_  r  r  r  r  r  r  rj  r  r  __classcell__r4  s   @r   r   r     s       J
 #%#(/6"&W W W W W Wt HI% % % %"
/ 
/ 
// / / /
+ + + +>: >: >:@( ( (n' n' n'`	X( X( X(t
R 
R 
R 
R 
R" " " ""	" 	" 	" 	"" " " ". . .  "$ $ $ $ $ $ $r   r   c                     | dk    rt           S | dk    rt          S t          |           dk    r| S t          d|            )Ncirclediscr   Unsupported type: )DEGREE_WIN1252r  r   r'  )ul_types    r   r  r    sQ    (&
7||q
<7<<
=
==r   c                    | dk    r|S | dk    rt           |dz
           S | dk    rt          |dz
           S | dk    rt          |          S | dk    r!t          |                                          S t	          d|            )NrS  r(   r   Ar[  r   r  )r   r   r   r   r'  )r  indexs     r   r  r     s    #~~#~~uqy))#~~uqy))#~~#~~%%'''
<7<<
=
==r   c                   "     e Zd ZdZ fdZ xZS )	HTMLMixinzc
    [**DEPRECATED since v2.6.0**]
    You can now directly use the `FPDF.write_html()` method
    c                      t                      j        |i | t          j        dt          t                                 d S )Nz[The HTMLMixin class is deprecated since v2.6.0. Simply use the FPDF class as a replacement.r   )r   r   r$  r%  r&  r   )r-  argskwargsr4  s      r   r   zHTMLMixin.__init__  sU    $)&)))> &((	
 	
 	
 	
 	
 	
r   )r  r  r  r  r   r  r  s   @r   r  r    sB         
	
 	
 	
 	
 	
 	
 	
 	
 	
r   r  )r4   )-r  html.parserr   stringr   r   loggingrer$  deprecationr   drawingr   r	   enumsr
   r   r   errorsr   fontsr   r   r   utilr   	getLoggerr  rm  r  r   r  r)  r#  r  	_WS_CHARScompiler`  r   r   r   r   r  r  r  r   r   r   <module>r     s    # " " " " " 3 3 3 3 3 3 3 3             ( ( ( ( ( ( C C C C C C C C + + + + + + + + + + ! ! ! ! ! !                  		8	$	$3		$	$	$(...HI&&&
(b
1
1
1
(b
1
1
1
(b
1
1
1
(b
1
1
1
(b
1
1
1
(a
0
0
089%%%   

   GG 	> bj*Y***++UYU
IU 	U )	U
 IU U YU IU 	U 9U YU U IU 9U IU  I!U" I#U U$ )%U& Y'U( 9)U* 	+U, Y-U. Y/U0 1U2 i3U4 5U6 7U8 9U: Y;U< y=U> i?U@ iAUB CUD iEU U UF YGUH 	IUJ yKUL yMUN OUP QUR SUT UUV iWUX iYUZ y[U\ ]U^ )_U` )aUb icUd ieUf YgU U Uh IiUj IkUl ymUn IoUp )qUr ysUt 9uUv 9wUx IyUz ){U| I}U~ )U@ AUB )CUD 9EUF iGUH YIU U UJ 	KUL 	MUN OUP 9QUR YSUT iUUV )WUX YUZ Y[U\ I]U^ _U` aUb icUd yeUf gUh IiUj kU U Ul 
9mUn oUp qUr ysUt iuUv wUx YyUz y{U| }U~ IU@ AUB CUD 	EUF )GUH iIUJ YKUL )MU U UN YOUP QUR 	SUT YUUV )WUX YYUZ Y[U\ )]U^ _U` )aUb icUd IeUf YgUh IiUj ykUl 
9mUn yoU U Up yqUr 	sUt uUv iwUx yyUz Y{U| )}U~ 9U@ iAUB CUD IEUF IGUH IUJ 9KUL 	MUN iOUP QU UR  iU U U
p5 5 5 59 9 9$o$ o$ o$ o$ o$
 o$ o$ o$d> > >> > >
 
 
 
 
 
 
 
 
 
r   