
    F j                    `   % S 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
JrJrJrJr  SSKJr  SSKJrJrJrJr   SS	KJr  SSKJr  SSKJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'  SSK(J)r)J*r*J+r+J,r,J-r-J.r.J/r/  SSK0J1r1J2r2  SSK3J4r4  SSK5J6r6J7r7  \
(       a  SSKJ8r8  SSKJ9r9  SSK:J;r;  SSK3J<r<  \Rz                  " \>5      r?SSS.r@\R                  " S5      rB\R                  " S5      rC\R                  " S\R                  5      rE\R                  " S5      rFS\\G   S\\G   4S jrH\/ " S S \I5      5       rJ\R                  " S!5      rK1 S"krLS#S$S%SS&S'S(S).rM\R                  S*-  \R                  S+-  S\R                  S,.rO\/SyS-\GS.\GS\I4S/ jj5       rP\/SzS0\GS.\GS\I4S1 jj5       rQ\/S2\GS3\GS\G4S4 j5       rR\/S2\GS5\GS\S\G\G4   4S6 j5       rT\/S7\GS\G4S8 j5       rU\T" S9S:S;S<S=S>S?5      rV\/S@\GS\*\)-  4SA j5       rW\/SB\GS\\I   4SC j5       rX\/SB\GS\I4SD j5       rY\/SE\ISF\IS\\G/\I4   4SG j5       rZ\/SH 4S\GSI\\G/\4   S\4SJ jj5       r[\/SK 4S\\G   SI\\G/\4   S\4SL jj5       r\SM SN SO SP SQ SR SS ST SU SV SW SX.r]\S\G\4   \^SY'   \/ S{SZ\$\"-  S[S\S]\\S\G\4      SS4S^ jj5       r_S_\S\G\4   S`S\S\`4Sa jraS|Sb\\G   Sc\`S\G4Sd jjrbSe\\G   Sf\GS\G4Sg jrc S{S`S\S3\GS_\\S\G\4      S\\G   4Sh jjrd S{S`S\S_\\S\G\4      S\e\\G   \G\\I   \G4   4Si jjrf  S}S`S\S_\\S\G\4      Sj\\I   S\e\I\I\I\I4   4Sk jjrgSl\GS\h\e\G\S\G\4   4      4Sm jri\/ " Sn So5      5       rj\/Sp\GS\,4Sq j5       rk\/Sr\$Ss\GSS4St j5       rl " Su Sv5      rm " Sw Sx\5      rng! \ a    \R4                  " S
5        SS	KJr   GNef = f)~aA  
Utilities to parse SVG graphics into fpdf.drawing objects.

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.

Usage documentation at: <https://py-pdf.github.io/fpdf2/SVG.html>
    N)deepcopy)PathLike)TYPE_CHECKINGAnyCallable
NamedTupleOptional)
parse_path   )GradientSpreadMethodGradientUnitsPathPaintRuleStrokeCapStyle)
fromstringzYdefusedxml could not be imported - fpdf2 will not be able to sanitize SVG images provided)html)	BoundingBoxClippingPathGradientPaintGraphicsContextGraphicsStylePaintedPathPathPenTextTextRun)
DeviceGray	DeviceRGBPoint	Transformcolor_from_hex_stringcolor_from_rgb_stringforce_nodocument)
ImageCacheVectorImageInfo)stream_content_for_raster_image)shape_linear_gradientshape_radial_gradient)Element)
Renderable)FPDF)ResourceCatalogzhttp://www.w3.org/2000/svgzhttp://www.w3.org/1999/xlink)svgxlinkz(?:\s+,\s+|\s+,|,\s+|\s+|,)zf(matrix|rotate|scale|scaleX|scaleY|skew|skewX|skewY|translate|translateX|translateY)\(([\d\.,\s+-]+)\)z	/\*.*?\*/z(?s)([^{}]+)\{([^{}]*)\}valuereturnc                 l    U c  g [        U [        5      (       a  U R                  5       nU(       d  g U$ U $ N)
isinstancestrstrip)r-   strippeds     Y/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/fpdf/svg.py_normalize_css_valuer6   X   s2    }%;;=L    c                       \ rS rSrSrSrg)Percentc   z$class to represent percentage values N)__name__
__module____qualname____firstlineno____doc____static_attributes__r;   r7   r5   r9   r9   c   s    .r7   r9   z2\s*(?P<value>[-+]?[\d\.]+)\s*(?P<unit>%|[a-zA-Z]*)>   %chemexiclhvbvhvivwcapremrlhvmaxvminH   gbX<@gjZ@   g      ?gjZ?)incmmmptpcpxQih  i  )deggradradturn
length_strdefault_unitc                 (   [         R                  U 5      nUc  [        SU  S35      SeUR                  5       u  p4U(       d  Un [	        U5      [
        U   -  $ ! [         a-    U[        ;   a  [        U  SU 35      Se[        U  SU 35      Sef = f)z7Convert a length unit to our canonical length unit, pt.NzUnable to parse 'z' as a lengthz" uses unsupported relative length z contains unrecognized unit )unit_splittermatch
ValueErrorgroupsfloatabsolute_length_unitsKeyErrorrelative_length_units)r^   r_   rb   r-   units        r5   resolve_lengthrj      s     
+E},ZLFGTQ,,.KEVU|3D999 V((,@G J<'CD6JKQUUVs   A 7B	angle_strc                     [         R                  U 5      nUb  UR                  5       u  p4OU nW(       d  Un [        U5      [        U   -  $ ! [
         a    [        SU  SU 35      Sef = f)z;Convert an angle value to our canonical angle unit, radiansNzangle z has unknown unit )ra   rb   rd   re   angle_unitsrg   rc   )rk   r_   mr-   ri   s        r5   resolve_anglero      s{     	I&A}hhjtQU|k$/// Q6),>tfEFDPQs   A A*spacenamec                 N     S[         U     S3n U  U 3$ ! [         a    Sn  Nf = f)zECreate an XML namespace string representation for the given tag name.{} )_HANDY_NAMESPACESrg   )rp   rq   s     r5   xmlnsrw      sC    &u-.b1 WTF  s    $$namesc                 >    0 nU H  nX2[        X5      '   X2U'   M     U$ )z>Create a lookup for the given name in the given XML namespace.)rw   )rp   rx   resultrq   s       r5   xmlns_lookupr{      s.     F%)uU!"t  Mr7   qualified_tagc                 B    U R                  S5      nUS:  a  XS-   S $ U $ )z8Remove the xmlns namespace from a qualified XML tag namert   r   r   N)index)r|   is     r5   
without_nsr      s0     	C AAvUW%%r7   r+   rectcircleellipselinepolylinepolygoncolorstrc                      [         R                  U    n U R                  S5      (       a  [	        U 5      $ U R                  S5      (       a  [        U 5      $ [        SU  35      e! [         a     N\f = f)N#rgbz unsupported color specification )r   
COLOR_DICTrg   
startswithr   r    rc   r   s    r5   svgcolorr      sv    ??8, 3$X..5!!$X..
7zB
CC  s   A% %
A21A2incomingc                 T    [        U 5      nUS:  a  [        SU  S35      eUS:X  a  g U$ )Nr   zstroke width z cannot be negative)rj   rc   r   vals     r5   convert_stroke_widthr      s7    

"C
Qw=
2EFGG
axJr7   c                 F    [        U 5      nUS:  a  [        SU  S35      eU$ )N      ?zmiter limit z cannot be less than 1)re   rc   r   s     r5   convert_miterlimitr      s,    
/C
Sy<z1GHIIJr7   min_valmax_valc                 4   ^ ^ S[         S[        4UU 4S jjnU$ )Nr-   r.   c                 >   > [        U 5      nUT:  a  T$ UT:  a  T$ U$ r0   re   )r-   r   r   r   s     r5   	converterclamp_float.<locals>.converter  s)    El=N=N
r7   )r2   re   )r   r   r   s   `` r5   clamp_floatr     s#        r7   c                     U $ r0   r;   )r-   s    r5   <lambda>r     s    r7   r   c                 >    U S;   a  [         R                  $ U" U 5      $ )N)inheritcurrentColor)r   INHERITr-   r   s     r5   inheritabler     s$     ++$$$Ur7   c                     U $ r0   r;   )noops    r5   r   r     s    r7   c                     U c  g [        U [        5      (       a  U R                  5       (       d  g U S:X  a  g [        X5      $ )Nnone)r1   r2   r3   r   r   s     r5   optionalr     s;    
 }%ekkmmu((r7   c                 f    SU (       a  U R                  S5      (       d  [        U [        5      4$ S 4$ )N
fill_colorurl(r   r   r   r   s    r5   r   r   .  s5     !4!4V!<!< Xx(
 r7   c                     S[        U 5      4$ )Nintersection_ruler   )fillrulestrs    r5   r   r   7  s    &9;{;S%Tr7   c                 2    S[        U [        SS5      5      4$ )Nfill_opacity        r   r   r   )filopstrs    r5   r   r   9  s    Hk#s34&r7   c                 f    SU (       a  U R                  S5      (       d  [        U [        5      4$ S 4$ )Nstroke_colorr   r   r   s    r5   r   r   >  s5     !4!4V!<!< Xx( 
  r7   c                 &    S[        U [        5      4$ )Nstroke_width)r   r   )valuestrs    r5   r   r   G  s    H23&r7   c                      S[        U S 5      4$ )Nstroke_dash_patternc                 z    [         R                  U 5       Vs/ s H  o(       d  M  [        U5      PM     sn$ s  snf r0   )NUMBER_SPLITsplitre   )daitems     r5   r   <lambda>.<locals>.<lambda>P  s+    0B0B20FO0F$d0FOOs   
88)r   )	dasharrays    r5   r   r   L  s    O	
+r7   c                 &    S[        U [        5      4$ )Nstroke_dash_phase)r   re   )dashoffs    r5   r   r   U  s    GU#*r7   c                     S[        U 5      4$ )Nstroke_cap_styler   )capstrs    r5   r   r   Z  s    &8+f:M%Nr7   c                     S[        U 5      4$ )Nstroke_join_styler   )joinstrs    r5   r   r   \  s    (;[=Q'Rr7   c                 &    S[        U [        5      4$ )Nstroke_miter_limit)r   r   )limstrs    r5   r   r   ^  s    F./)r7   c                 2    S[        U [        SS5      5      4$ )Nstroke_opacityr   r   r   )stropstrs    r5   r   r   c  s    Hk#s34(r7   )fillz	fill-rulezfill-opacitystrokezstroke-widthzstroke-dasharrayzstroke-dashoffsetzstroke-linecapzstroke-linejoinzstroke-miterlimitzstroke-opacitysvg_attr_mapstylablesvg_elementr'   computed_stylec                 .   Ub  UnO]0 n[         R                  " UR                  R                  SS5      5      R	                  5        H  u  pE[        U5      nUc  M  XcU'   M     SU R                  l        [        R	                  5        Hg  u  px[        UR                  U5      5      n	U	c$  [        UR                  R                  U5      5      n	U	c  MK  [        U R                  /U" U	5      Q76   Mi     [        UR                  S5      5      n
U
c$  [        UR                  R                  S5      5      n
U
b+  [        U
5      nXR                  l        XR                  l        UR                  R                  S5      nU(       a  [        U5      U l        gg)zKApply the known styles from `svg_element` to the pdf path/group `stylable`.Nstyleru   Fopacity	transform)r   parse_css_styleattribgetitemsr6   r   
auto_closer   setattrre   r   r   convert_transformsr   )r   r   r   r   keyr-   
norm_value	attr_namer   
attr_valueopacity_strr   tfstrs                r5   apply_stylesr   j  s_    !..""7B/

%'JC .e4J%'c
 !&HNN , 2 2 4	)%))I*>?
-k.@.@.D.DY.OPJ!HNN;Yz%:; !5 'uyy';<K*;+=+=+A+A)+LM$&-#(/%"";/E/6 r7   	style_maptagc                     U R                  S5      =(       d    SR                  5       nUS;   a  gUR                  R                  S5      n[        US:H  5      $ )Nwhite-spaceru   )prezpre-wrapzbreak-spacesTz+{http://www.w3.org/XML/1998/namespace}spacepreserve)r   r3   r   bool)r   r   ws	xml_spaces       r5   _preserve_wsr     sM    
--
&
,"	3	3	5B	00

LMI	Z'((r7   sr   c                 L    U c  gU(       a  U $ [         R                  " SSU 5      $ )z
Collapse sequences of whitespace characters (spaces, tabs, etc.) to a single space
In some cases, like with `pre` tags, whitespace should be preserved.
ru   z\s+ )resub)r   r   s     r5   _collapse_wsr     s'    
 	y66&#q!!r7   
font_stylefont_weightc                 J   SnSnU(       aO  UR                  5       R                  5       nUS;   =(       d%    UR                  5       =(       a    [        U5      S:  nU (       a#  U R                  5       R                  5       nUS;   nU(       a  U(       a  gU(       a  gU(       a  gg)	NF)boldbolderiX  )italicobliqueBIBIru   )r3   lowerisdigitint)r   r   br   fwfss         r5   _svg_font_style_to_emphasisr    s    AA &&($$I)H#b'S.%%'''Qr7   c                 2   Ub  [        UR                  U5      5      nUb  U$ UcO  [        R                  " U R                  R                  SS5      5      n[        UR                  U5      5      nUb  U$ [        U R                  R                  U5      5      $ )zJReturn the value for a given attribute, honoring computed style overrides.r   ru   )r6   r   r   r   r   )r   rq   r   r-   inlines        r5   _get_attr_or_styler    s     $Y]]4%89L%%cjjnnWb&AB$VZZ%56L

t 455r7   c                 r   [        U SU5      nU(       a  / nUR                  S5       HM  nUR                  5       R                  SS5      R                  SS5      nU(       d  M<  UR	                  U5        MO     U(       a  SR                  U5      OSnOSn[        U SU5      =(       d    Sn[        U SU5      =(       d    Sn[        Xx5      n	[        U S	U5      n
U
b  [        U
5      OSn[        U S
U5      =(       d    SR                  5       R                  5       nUS;  a  SnXiUb  [        U5      U4$ SU4$ )zUReturns (font_family or None, font_style_emphasis, font_size_pt or None, text_anchor)font-family,"ru   'N
font-stylefont-weight	font-sizetext-anchorstart)r  middleend)
r  r   r3   replaceappendjoinr  rj   r  re   )r   r   family_valuecleanedr   r4   familyr   r   emphasisr  size_pttas                r5   _parse_font_attrsr'    s(    &c=)DL &&s+Dzz|++C4<<S"EHxx( , '.'"4 $CyAGRJ$S-CIrK*:CH 
Ci	8B nr$ 
 S-
;
Fw	M	M	O	U	U	WB	++w/BU7^bPPbPPr7   	font_sizec           	         ^ ^^ S[         4S[        S[        S[        [        /[        4   S[        4UUU 4S jjjnU" SS5      nU" SS5      nU" S	S5      nU" S
S5      nXEXg4$ )z0x,y (default 0,0) and optional dx,dy (default 0)r   rq   defaultresolverr.   c                   > S nT
b  U T
;   a  T
U    nOU TR                   ;   a  TR                   U    nU(       d  U$ [        R                  UR                  5       5      nU(       a
  US   (       d  U$ US   n[        R                  U5      nU(       a  UR                  S5      nUR                  S5      =(       d    SR                  5       nUR                  5       S;   a6  T	c$  [        R                  SUTR                  U 5        U$  [        U5      T	-  $ UR                  5       S:X  a8  T	c#  [        R                  STR                  U 5        U$  [        U5      T	-  S	-  $  [        U" U5      5      $ ! [        [        4 a    Us $ f = f! [        [        4 a    Us $ f = f! [         a'    [        R                  S
UTR                  U 5        Us $ f = f)Nr   r-   ri   ru   >   rD   rM   zCIgnoring relative %s length on <%s %s> because font size is unknownrE   zCIgnoring relative ex length on <%s %s> because font size is unknowng      ?z+Ignoring unsupported length '%s' on <%s %s>)r   r   r   r3   ra   	fullmatchgroupr  LOGGERwarningr   re   	TypeErrorrc   )rq   r*  r+  attrpartstokenrb   	value_strri   r(  r   r   s            r5   first_number%_parse_xy_delta.<locals>.first_number  s   
  TY%6T?DSZZ::d#DN""4::<0E!HNa''.G,IKK'-2446Dzz|},$NN]	 #N# +i77 zz|t#$NN]
 #N# +i7#==		%)) ":. #"N# ":. #"N#  	NN=	 N	s6   E3 F "F# 3FFF F #.GGxydxdy)rj   r2   re   r   )r   r   r(  r6  r8  r9  r:  r;  s   ```     r5   _parse_xy_deltar<    s     +9666 C5%<(6 
	6 6p 	S#AS#A	dC	 B	dC	 B<r7   css_textc                 p   / nU (       d  U$ [         R                  SU 5      n[        R                  U5       H  u  p4[        R
                  " U5      nU(       d  M$  0 nUR                  5        H  u  px[        U5      n	U	c  M  XU'   M     U(       d  M\  UR                  S5       V
s/ s H  oR                  5       PM     nn
U Hf  n
U
R                  S5      (       d  M  U
SS  R                  SS5      S   R                  5       nU(       d  MJ  UR                  U[        U5      45        Mh     M     U$ s  sn
f )Nru   r  .r   :r   )CSS_COMMENT_REr   CSS_BLOCK_REfindallr   r   r   r6   r   r3   r   r  dict)r=  stylesr"  selector_blockbodydeclarations
normalizedr   r-   r   selector	selectors
class_names                r5   _extract_css_class_stylesrM  4  s   /1F  X.G , 4 4W =++D1
&,,.JC-e4J%",3 / 6D6J6J36OP6O(^^%6O	P!H&&s++!!"++C3A6<<>JMM:tJ'789 " !>& M Qs   &D3c                      \ rS rSrSr\SSSS\S\4S jj5       r\	SSSS\S\4S jj5       r
\	SSSS\S\4S	 jj5       r\	SSSS\S\4S
 jj5       r\	SSS\4S j5       r\	SSS\4S j5       r\	SSSS\S\4S jj5       rSrg)ShapeBuilderiP  zNA namespace within which methods for converting basic shapes can be looked up.r   r'   clipping_pathr.   c                 R    [        5       nU(       a
  [        5       n[        X 5        U$ )z.Create a new path with the appropriate styles.)r   r   r   )r   rP  paths      r5   new_pathShapeBuilder.new_pathT  s"     }>DTr7   c                 ,   [        UR                  R                  SS5      5      n[        UR                  R                  SS5      5      nUR                  R                  S5      =(       d    SnUR                  S5      (       a  [	        USS 5      nO[        U5      nUR                  R                  S5      =(       d    SnUR                  S5      (       a  [	        USS 5      nO[        U5      nUR                  R                  S	5      =(       d    S
n	UR                  R                  S5      =(       d    S
n
U	S:X  a  Sn	U
S:X  a  Sn
Xs=:X  a  S
:X  a  O  OS=pO<U	S
:X  a  [        U
5      =pO)U
S
:X  a  [        U	5      =pO[        U	5      n[        U
5      nUS:  d  US:  d  US:  d  US:  a  [        SU 35      eUS:X  d  US:X  a
  [        5       $ XS-  :  a  US-  nXS-  :  a  US-  nU R                  X5      nUR                  X4XhX5        U$ )z&Convert an SVG <rect> into a PDF path.r8  0r9  widthrB   Nheightrxautoryr   r   z	bad rect    )
rj   r   r   endswithr9   re   rc   r   rS  	rectangle)clsr   rP  r8  r9  	width_strrW  
height_strrY  rx_strry_strrZ  r\  rR  s                 r5   r   ShapeBuilder.rect]  s    3::>>#s343::>>#s34JJNN7+2s	c""%,Ys^%<E"9-EZZ^^H-4
s##&-j"o&>F#J/F%/%/VFVF
 %v%KBvFm#BvFm#BvBvBAI6A:26rAvy.//QJFaK= B!!B||C/qUB3r7   c                    [        UR                  R                  SS5      5      n[        UR                  R                  SS5      5      n[        UR                  S   5      nU R                  X5      nUR	                  X4U5        U$ )z(Convert an SVG <circle> into a PDF path.cxr   cyr)re   r   r   rS  r   )r`  r   rP  rg  rh  ri  rR  s          r5   r   ShapeBuilder.circle  si     3::>>$*+3::>>$*+#**S/"||C/BAr7   c                     [        UR                  R                  SS5      5      n[        UR                  R                  SS5      5      nUR                  R                  S5      =(       d    SnUR                  R                  S5      =(       d    SnU R                  X5      nXVs=:X  a  S:X  d  O  US:X  d  US:X  a  U$ US:X  a  [        U5      =pO)US:X  a  [        U5      =pO[        U5      n[        U5      n	UR	                  X4X5        U$ )z)Convert an SVG <ellipse> into a PDF path.rg  r   rh  rZ  r[  r\  rV  )re   r   r   rS  r   )
r`  r   rP  rg  rh  rc  rd  rR  rZ  r\  s
             r5   r   ShapeBuilder.ellipse  s     3::>>$*+3::>>$*+%/%/||C/&&FcMv}KVFm#BvFm#BvBvBRR$r7   c                 ,   [        UR                  S   5      n[        UR                  S   5      n[        UR                  S   5      n[        UR                  S   5      nU R                  U5      nUR                  X#5        UR	                  XE5        U$ )z&Convert an SVG <line> into a PDF path.x1y1x2y2)re   r   rS  move_toline_to)r`  r   rn  ro  rp  rq  rR  s          r5   r   ShapeBuilder.line  s{     3::d#$3::d#$3::d#$3::d#$||C RRr7   c                 b    U R                  U5      nSUR                  S   -   n[        X#5        U$ )z*Convert an SVG <polyline> into a PDF path.MpointsrS  r   svg_path_converter)r`  r   rR  rw  s       r5   r   ShapeBuilder.polyline  s2     ||C szz(++4(r7   c                 h    U R                  X5      nSUR                  S   -   S-   n[        X45        U$ )z)Convert an SVG <polygon> into a PDF path.rv  rw  Zrx  )r`  r   rP  rR  rw  s        r5   r   ShapeBuilder.polygon  s7     ||C/szz(++c14(r7   r;   NF)r<   r=   r>   r?   r@   staticmethodr   r   rS  classmethodr   r   r   r   r   r   rA   r;   r7   r5   rO  rO  P  s   Xi     1y 1 1+ 1 1f  4 K   ) D [  0 
y 
[ 
 
 9    ) D [  r7   rO  r   c           	      2   [         R                  U 5      n[        R                  " 5       nU GH  u  p4UR	                  5       nUS:X  a;  [        S [        R                  U5       5       5      u  pVpxp[        XVXxX5      U-  nMW  US:X  a  [        R                  U5      tp[        U5      n[        R                  " US9nU(       aL  [        U5      S:X  a+  UR                  [        US   5      [        US   5      5      nO[        SU S	U S
35      eX-  nM  US:X  a  [        R                  U5      n[        U5      S:X  a  [        US   5      n[        US   5      nO-[        U5      S:X  a  [        US   5      =pO[        SU  35      e[        R                  " XS9U-  nGMy  US:X  a$  [        R                  " [        U5      SS9U-  nGM  US:X  a$  [        R                  " S[        U5      S9U-  nGM  US:X  a  [        R                  U5      n[        U5      S:X  a  [        US   5      n[        US   5      nO.[        U5      S:X  a  [        US   5      nSnO[        SU  35      e[        R                  " [         R"                  " U5      [         R"                  " U5      S9U-  nGM  US:X  a8  [        R                  " [         R"                  " [        U5      5      SS9U-  nGM  US:X  a8  [        R                  " S[         R"                  " [        U5      5      S9U-  nGM  US:X  a  [        R                  U5      n[        U5      S:X  a  [%        US   5      n[%        US   5      nO.[        U5      S:X  a  [%        US   5      nSnO[        SU  35      e[        R&                  " UUS9U-  nGM  US:X  a$  [        R&                  " [%        U5      SS9U-  nGM  US:X  d  GM  [        R&                  " S[%        U5      S9U-  nGM     U$ )z8Convert SVG/CSS transform functions into PDF transforms.matrixc              3   8   #    U  H  n[        U5      v   M     g 7fr0   r   ).0ns     r5   	<genexpr>%convert_transforms.<locals>.<genexpr>  s     $P7O!U1XX7Os   rotate)thetar]  r   r   zrotation transform (z) is malformedscalezbad scale transform r8  r9  scaleXscaleYskewzbad skew transform skewXskewY	translatezbad translation transform 
translateX
translateY)TRANSFORM_GETTERrC  r   identityr3   tupler   r   ro   rotationlenaboutre   rc   scalingshearingmathtanrj   translation)r   parsedr   tf_typeargsar  cdefr  r  r  sxsyr8  r9  s                     r5   r   r     s    %%e,F""$Izz|h$$P|7I7I$7O$PPA!!!a3i?I (..t4ME!%(E ))6H u:?'~~eE!HouU1XOH$-gYav^L  !,I%%d+D4yA~47^47^TaQ.(R #7w!?@@!))B5	AI !))E$K1=	II !))At=	II%%d+D4yA~"47+"47+Ta"47+ #6ug!>??!**TXXb\TXXb\JYVI""TXXmD.A%BaH9T  ""Q$((=3F*GH9T  #%%d+D4yA~"47+"47+Ta"47+ #=eW!EFF!--Q7)CI$!--t0DJYVI$!--^D5IJYVIg  j r7   pdf_pathsvg_pathc                 h    [        U 5      n[        X5        UR                  (       d  [        S5      eg )Nz"Path does not start with move item)r   r
   first_is_moverc   )r  r  pens      r5   ry  ry  7  s.    
(
Cx=>> r7   c                      \ rS rSrSr\SS.S\\\   -  S\S\S\S	S 4
S
 jj5       r	 SDS\\
-  S\\   S	S4S jjr\S\\   S\S	S4S j5       rSES jrSSS	\\\4   4S jr\\SFS\S\S	\4S jj5       5       r\\SSS	\\\\\-  4      4S j5       5       r\\S\\   S	\\   4S j5       5       r\SGS j5       r\SGS j5       r\ SDS\S SS!\\\\4      S	S4S" jj5       r\SES# j5       r \SES$ j5       r! SHS%S&S'\"S	\\\\#4   4S( jjr$  SIS)\S*\\%-  S+\\%-  S'\"S,\"S	\\\\#4   4S- jjr&   SJS%S&S.\\   S/\\   S0\\"   S	S4
S1 jjr'\SKS2 j5       r(\S3SS	\#4S4 j5       r)\  SLS5SS6\\#   S7\\\\4      S	\#4S8 jj5       r*\S9SS	\4S: j5       r+\S;SS	\4S< j5       r,\S;SS=\\   S	S4S> j5       r-\ SDS\S SS!\\\\4      S	S4S? jj5       r.\SMS@ j5       r/\ SDSASS7\\\\4      S	\\   4SB jj5       r0SCr1g)N	SVGObjecti?  zM
A representation of an SVG that has been converted to a PDF representation.
zutf-8encodingfilenamer  r  kwargsr.   c                    [        USUS9 nU " UR                  5       /UQ70 UD6sSSS5        $ ! , (       d  f       g= f)a  
Create an `SVGObject` from the contents of the file at `filename`.

Args:
    filename (path-like): the path to a file containing SVG data.
    *args: forwarded directly to the SVGObject initializer. For subclass use.
    encoding (str): optional charset encoding to use when reading the file.
    **kwargs: forwarded directly to the SVGObject initializer. For subclass use.

Returns:
    A converted `SVGObject`.
ri  r  N)openread)r`  r  r  r  r  svgfiles         r5   	from_fileSVGObject.from_fileD  s6    ( (C(3ww||~777 433s   0
>Nsvg_textimage_cachec                 6   X l         0 U l        0 U l        0 U l        S U l        S U l        [        U5      nUR                  [        SS5      ;  a  [        SUR                   35      eU R                  U5        U R                  U5        U R                  U5        g )Nr+   zroot tag must be svg, not )r  cross_referencescss_class_stylesgradient_definitionsrW  rY  parse_xml_strr   r{   rc   _collect_css_stylesextract_shape_infoconvert_graphics)selfr  r  svg_trees       r5   __init__SVGObject.__init__[  s     '02;= 	! 15
15+H5<<|E5999(,,HII  *)h'r7   r   
referencedc                 j    U(       a,  UR                  S5      (       d  SU-   OUnX R                  U'   g g )Nr   )r   r  )r  r   r  s      r5   update_xrefSVGObject.update_xrefp  s1    #&>>##6#6#)CC)3!!#& r7   r'   c                 <   UR                  5        H  nUR                  [        SS5      ;   d  M  SR                  UR	                  5       =(       d    / 5      n[        U5       H2  u  pEU R                  R                  U0 5      nUR                  U5        M4     M     g )Nr+   r   ru   )	iterr   r{   r   itertextrM  r  
setdefaultupdate)r  root_tagnoder=  rL  rH  existings          r5   r  SVGObject._collect_css_stylesv  su    MMODxx<w77774==?#8b90I(0S,J#44??
BOHOOL1 1T $r7   r   c                    0 nU R                   (       an  UR                  R                  S5      nU(       aL  UR                  5        H8  nU R                   R                  U5      nU(       d  M'  UR	                  U5        M:     [
        R                  " UR                  R                  SS5      5      nUR                  5        H2  u  px[        U5      n	U	b  XU'   M  Xr;   d  M   UR                  US 5        M4     Sn
U
 HN  nXR                  ;   d  M  [        UR                  R                  U5      5      n	U	c  M=  UR                  X5        MP     U$ )Nclassr   ru   )r  r  r  r  r  r   )r  r   r   r   r  r   r   r   r6   popr  )r  r   r   
class_attrrL  class_stylesr  r   r-   r   inheritable_attrsr2  s               r5   _style_map_forSVGObject._style_map_for~  s   $&	  0J","2"2"4J#'#8#8#<#<Z#HL#|!((6 #5 %%cjjnnWb&AB ,,.JC-e4J%!+#!c4( )
 &Dzz!1#**..2FG
)((:	 &
 r7   r-   r*  c                 $   U b  U S:X  a  Un U R                  5       n U R                  S5      (       a  [        U SS 5      S-  $  [        U 5      $ ! [         a6     [	        U 5      s $ ! [         a    [
        R                  SU 5          gf = ff = f)z@Convert SVG gradient coordinate (percentage or number) to float.Nru   rB   rX        Y@z1Could not parse gradient coordinate '%s', using 0r   )r3   r^  re   rc   rj   r/  r0  )r-   r*  s     r5   _convert_gradient_coordinate&SVGObject._convert_gradient_coordinate  s     =ERKE>>#s$u,,		< 	%e,, G 		s0   
A 
B
A'$B' BB
BBgradient_elementc                    / nU  GH  n[        UR                  5      nUS:w  a  M!  UR                  R                  S5      nUc  [        R                  S5        MV  UR                  5       nUR                  S5      (       a  [        USS 5      S-  nO[        U5      n[        S[        S	U5      5      nSnS	nUR                  R                  S
S5      nU(       aK  [        R                  " U5      n	U	R                  S5      nU	R                  S5      n
U
(       a   [        U
5      nUc  UR                  R                  SS5      nSUR                  ;   a.   [        UR                  R                  S5      =(       d    S5      n [        U5      nUS	:  al  [        U[         5      (       a,  [!        UR"                  UR$                  UR&                  U5      n[        U[(        5      (       a  [)        UR$                  U5      nUR+                  X[45        GM     U$ ! [         a    [        R                  SU
5         GNf = f! [         a     Nf = f! [        [,        4 a"  n[        R                  SXl5         SnAGMy  SnAff = f)z,Parse <stop> children of a gradient element.stopoffsetNz%Found <stop> without offset, skippingrB   rX  r  r   r   r   ru   z
stop-colorzstop-opacityzInvalid stop-opacity value: %sblack1z#Could not parse stop color '%s': %s)r   r   r   r   r/  r0  r3   r^  re   maxminr   r   rc   r   r1   r   ri  gr  r   r  rg   )r  stopsstop_elementtag_name
offset_strr  
stop_colorstop_opacityr   
style_dictstop_opacity_str	color_objr  s                r5   _parse_gradient_stopsSVGObject._parse_gradient_stops  s<    =?,L!,"2"23H6!%,,00:J!FG#))+J""3''z#2/%7z*c#v./FJL ''++GR8E!11%8
'^^L9
#->>.#A #',-='> !)0044\7K
!4!44#()<)<)@)@)P)WTW#XL$Z0	#%!)Y77$-%KKikk<%	 ")Z88$.y{{L$I	f01k -v = & <>N "  ) DjTs=   H-IBI H>=H>
IIJ!I>>J	url_valuec                     U (       a  [        U [        5      (       d  g[        R                  " SU 5      nU(       a  SUR	                  S5      -   $ g)z)Extract gradient ID from url(#id) format.Nzurl\(\s*["\']?\s*#([^)"\'\s]+)r   r   )r1   r2   r   searchr.  )r  rb   s     r5   _extract_gradient_idSVGObject._extract_gradient_id  s@     
9c : :		;YGQ''r7   c           	      x   UR                   R                  S5      nU(       d  [        R                  S5        gUR	                  S5      (       d  SU-   nUR                   R                  SS5      nUR                   R                  SS5      nUR                   R                  SS	5      nUR                   R                  S
S5      nU R                  US5      nU R                  US5      nU R                  US5      n	U R                  US5      n
UR                   R                  SS5      nUS:X  a  [        R                  nO[        R                  nUR                   R                  SS5      n [        R                  " U5      nSnUR                   R                  S5      nU(       a   [        U5      nU R!                  U5      nU(       d  [        R                  SU5        g[#        UUU	U
UUS9n[%        UUU=(       d    [&        R(                  " 5       US9nUU R*                  U'   [        R-                  SU[/        U5      5        g! [        [        4 a)    [        R                  n[        R                  SU5         Nf = f! [        [        [        4 a!  n[        R                  SU5         SnAGNSnAff = f)zFParse a <linearGradient> element and store it in gradient_definitions.idz5Found <linearGradient> without id attribute, skippingNr   rn  0%ro  rp  z100%rq  rV  r  gradientUnitsobjectBoundingBoxuserSpaceOnUsespreadMethodpadz$Invalid spreadMethod '%s', using PADgradientTransform%Could not parse gradientTransform: %sz1Linear gradient '%s' has no valid stops, skipping)rn  ro  rp  rq  r  spread_methodgradientunitsgradient_transformr  z)Parsed linear gradient '%s' with %d stops)r   r   r/  r0  r   r  r   USER_SPACE_ON_USEOBJECT_BOUNDING_BOXr   coercerc   AttributeErrorPADr   r1  r  r%   r   r   r  r  debugr  )r  grad_elementgrad_idrn  ro  rp  rq  x1_valy1_valx2_valy2_val	units_strr  
spread_strr  r   transform_strr  r  r  gradient_paints                        r5   _parse_linear_gradient SVGObject._parse_linear_gradient  sv    ".!4!4!8!8!>NNRS!!#&&GmG  $$T40  $$T40  $$T62  $$T40222s;222s;222s;222s; ''++O=PQ	((!33E!55E!((,,^UC
	O077
CM
 	$++//0CDK.}=	 **<8NNNPWX('
 '(@I,>,>,@'	
 .<!!'*@'3u:VI N+ 	O044MNNA:N	O 	: KFJJKs*   ,I 'J 6J ?J J9J44J9c                 b   UR                   R                  S5      nU(       d  [        R                  S5        gUR	                  S5      (       d  SU-   nUR                   R                  SS5      nUR                   R                  SS5      nUR                   R                  SS5      nUR                   R                  S	U5      nUR                   R                  S
U5      nUR                   R                  SS5      nU R                  US5      n	U R                  US5      n
U R                  US5      nU R                  U[        U	5      5      nU R                  U[        U
5      5      nU R                  US5      nUS::  a  [        R                  SX+5        gUR                   R                  SS5      nUS:X  a  [        R                  O[        R                  nUR                   R                  SS5      n [        R                  " U5      nSnUR                   R                  S5      nU(       a   [        U5      nU R#                  U5      nU(       d  [        R                  SU5        g[%        U	U
UUUUUUS9n['        UUU=(       d    [(        R*                  " 5       US9nUU R,                  U'   [        R/                  SU[1        U5      5        g! [        [        4 a    [        R                  n Nf = f! [        [        [         4 a   n[        R                  SU5         SnANSnAff = f)zFParse a <radialGradient> element and store it in gradient_definitions.r  z5Found <radialGradient> without id attribute, skippingNr   rg  z50%rh  ri  fxfyfrr  z0.5rV  r   z4Radial gradient '%s' has invalid radius %s, skippingr  r  r   r  r  r  r  z1Radial gradient '%s' has no valid stops, skipping)rg  rh  ri  r  r  r  r  r  r  z)Parsed radial gradient '%s' with %d stops)r   r   r/  r0  r   r  r2   r   r
  r  r   r  rc   r  r  r   r1  r  r&   r   r   r  r  r  r  )r  r  r  rg  rh  ri  r  r  r  cx_valcy_valr_valfx_valfy_valfr_valr  r  r  r  r   r  r  r  r  r  s                            r5   _parse_radial_gradient SVGObject._parse_radial_gradientH  s    %%))$/NNRS!!#&&GmG  $$T51  $$T51##C/  $$T2.  $$T2.  $$T40222u=222u=11!U;222s6{C222s6{C222s;A:NNF  ''++O=PQ	 ,, ++22 	 "((,,^UC
	5077
CM 	$++//0CDK.}=	 **<8NNNPWX('	
 '(@I,>,>,@'	
 .<!!'*@'3u:VG N+ 	5044M	5 	: KFJJKs*   6K 1K9  K65K69L.L))L.r   r   r   c                    [        USU5      nU(       a[  U R                  U5      nU(       aC  XPR                  ;   a4  U R                  U   UR                  l        [
        R                  SU5        [        USU5      nU(       a^  U R                  U5      nU(       aE  XPR                  ;   a5  U R                  U   UR                  l        [
        R                  SU5        gggg)zPApply gradient paint to fill or stroke if a url(#gradientId) reference is found.r   zApplied gradient %s to fillr   zApplied gradient %s to strokeN)r  r  r  r   r   r/  r  r   )r  r   r   r   
fill_valuer  stroke_values          r5   _apply_gradient_paintSVGObject._apply_gradient_paint  s     (VYG
//
;G7&?&??,0,E,Eg,N):GD)+xK//=G7&?&??.2.G.G.P+<gF @w r7   c                    UR                  S5      nUR                  S5      nUR                  S5      nUR                  SS5      nUS:X  a  SU l        OSU l        SU l        UbJ  UR                  5         UR	                  S5      (       a  [        USS	 5      U l        O[        U5      U l        SU l        UbJ  UR                  5         UR	                  S5      (       a  [        USS	 5      U l        O[        U5      U l        Uc  SU l        gUR                  5       n[        R                  U5       Vs/ s H  n[        U5      PM     snu  pxpU	S
:  d  U
S
:  a  [        SU 35      eXxX/U l        gs  snf )z&Collect shape info from the given SVG.rW  rY  viewBoxpreserveAspectRatioTr   NrB   rX  r   z)invalid negative width/height in viewbox )r   preserve_arrW  r3   r^  r9   rj   rY  viewboxr   r   re   rc   )r  r  ra  rb  r1  r0  numvxvyrK   rI   s              r5   r  SVGObject.extract_shape_info  sW    LL)	\\(+
,,y)ll#8$?& #D#D
 OO!!#&&$Ys^4
+I6
!""3''%j"o6,Z8?DLmmoG4@4F4Fw4OP4OSeCj4OPNBBQBF #LWI!VWWB+DL	 Qs   5E4c                     [        5       nSUR                  l        SUR                  l        [        R
                  UR                  l        U R                  X5        X l        g)zFConvert the graphics contained in the SVG into the PDF representation.NF)	r   r   r   r   r   BUTTr   build_group
base_group)r  r  r9  s      r5   r  SVGObject.convert_graphics  sO     %&
(,
%&+
#,:,?,?
).$r7   pdfr)   align_viewboxc                 f    U R                  UR                  UR                  UR                  U5      $ )a  
Size the converted SVG paths to the page viewport.

The SVG document size can be specified relative to the rendering viewport
(e.g. width=50%). If the converted SVG sizes are relative units, then this
computes the appropriate scale transform to size the SVG to the correct
dimensions for a page in the current PDF document.

If the SVG document size is specified in absolute units, then it is not scaled.

Args:
    pdf (fpdf.fpdf.FPDF): the pdf to use the page size of.
    align_viewbox (bool): if True, mimic some of the SVG alignment rules if the
        viewbox aspect ratio does not match that of the viewport.

Returns:
    The same thing as `SVGObject.transform_to_rect_viewport`.
)transform_to_rect_viewportkepweph)r  r;  r<  s      r5   transform_to_page_viewport$SVGObject.transform_to_page_viewport  s'    , ..suucggswwVVr7   r  rW  rY  ignore_svg_top_attrsc                    U(       a-  [        U[        5      (       a  [        U5      nOe[        U5      nOY[        U R                  [        5      (       a%  U(       d  [	        S5      eU R                  U-  S-  nOU R                  =(       d    UnU(       a-  [        U[        5      (       a  [        U5      nOe[        U5      nOY[        U R
                  [        5      (       a%  U(       d  [	        S5      eU R
                  U-  S-  nOU R
                  =(       d    UnUS:X  a  [        R                  " 5       nO[        R                  " SU-  5      nU R                  (       a  U R                  u  ppUS:X  d  US:X  a  SS[        5       4$ Xk-  nX|-  nU(       d"  U R                  (       a  X:w  a  [        X5      =pU[        R                  " U	* U
* S9-  [        R                  " XS9-  nU(       a0  U[        R                  " US-  US-  U-  -
  US-  US-  U-  -
  S9-  nXR                  l        Xa-  Xq-  U R                  4$ )a  
Size the converted SVG paths to an arbitrarily sized viewport.

The SVG document size can be specified relative to the rendering viewport
(e.g. width=50%). If the converted SVG sizes are relative units, then this
computes the appropriate scale transform to size the SVG to the correct
dimensions for a page in the current PDF document.

Args:
    scale (Number): the scale factor from document units to PDF points.
    width (Number): the width of the viewport to scale to in document units.
    height (Number): the height of the viewport to scale to in document units.
    align_viewbox (bool): if True, mimic some of the SVG alignment rules if the
        viewbox aspect ratio does not match that of the viewport.
    ignore_svg_top_attrs (bool): ignore <svg> top attributes like "width", "height"
        or "preserveAspectRatio" when figuring the image dimensions.
        Require width & height to be provided as parameters.

Returns:
    A tuple of (width, height, `fpdf.drawing.GraphicsContext`), where width and
    height are the resolved width and height (they may be 0. If 0, the returned
    `fpdf.drawing.GraphicsContext` will be empty). The
    `fpdf.drawing.GraphicsContext` contains all of the paths that were
    converted from the SVG, scaled to the given viewport size.
z?SVG "width" is a percentage, hence a viewport width is requiredd   zASVG "height" is a percentage, hence a viewport height is requiredr   r   r  r]  )r1   r9   re   rW  rc   rY  r   r  r  r1  r   r0  r  r  r9  r   )r  r  rW  rY  r<  rD  vp_width	vp_heightr   r3  r4  rK   rI   w_ratioh_ratios                  r5   r>  $SVGObject.transform_to_rect_viewport  s   H  %)) < <

G,, U  zzE)C/Hzz*UH&'**!&M	!&M	W-- W  f,s2I-vIA:!**,I!))!e)4I<<!\\NBBaR1W!_...mGnG'D,<,<'BT$'$99 ''2#"56##g9:  %	(=(=lb1f%77!mrAv&88) 	
 %.!!2DOOCCr7   r8  r9  debug_streamc                    UR                   U l         U R                  U5      u    pVUR                  UR                  p UbL  UbI  UR	                  SS5        UR
                  c   eUR
                  [        R                  " X#5      -  Ul        UR                  Xd5        UR	                  Xx5        g! UR	                  Xx5        f = f)a  
Directly draw the converted SVG to the given PDF's current page.

The page viewport is used for sizing the SVG.

Args:
    pdf (fpdf.fpdf.FPDF): the document to which the converted SVG is rendered.
    x (Number): abscissa of the converted SVG's top-left corner.
    y (Number): ordinate of the converted SVG's top-left corner.
    debug_stream (io.TextIO): *DEPRECATED* the stream to which rendering debug info will be
        written.
Nr   )	r  rB  r8  r9  set_xyr   r   r  	draw_path)	r  r;  r8  r9  rL  _rR  old_xold_ys	            r5   draw_to_pageSVGObject.draw_to_pageZ  s    & ??44S9
1uuceeu		%}

1a ~~111!%)2G2G2M!MMM$- JJu$CJJu$s   A B0 0Cc                    U GH  nUR                   [        SS5      ;   a  U R                  U5        M1  UR                   [        SS5      ;   a(  [        R	                  S5        U R                  U5        Ms  UR                   [        SS5      ;   a  U R                  U5        M  UR                   [        SS5      ;   a  U R                  U5        M  UR                   [        ;   a  U R                  U5        M  UR                   [        SS5      ;   a  U R                  U5        GM"  UR                   [        SS5      ;   a  U R                  U5        GMP  UR                   [        SS	5      ;   a-   UR                  S
   nU H  nU R                  XC5        M     GM  UR                   [        SS5      ;   a  GM  [        R	                  S[        UR                   5      5        GM     g! [         a    Sn Nwf = f)z:Produce lookups for groups and paths inside the <defs> tagr+   r  r  SIgnoring unsupported SVG tag: <a> (contributions are welcome to add support for it)rR  imagelinearGradientradialGradientclipPathr  Nr   TIgnoring unsupported SVG tag: <%s> (contributions are welcome to add support for it))r   r{   r8  r/  r0  
build_pathbuild_image
shape_tagsbuild_shaper  r&  r   rg   build_clipping_pathr   )r  defschildclip_idchild_s        r5   handle_defsSVGObject.handle_defs~  s    EyyL44  'l5#66 i   'l5&99&l5'::  'j(  'l52BCC++E2l52BCC++E2l5*==##ll40G $F,,V= $l5'::juyy)? .   #"G#s   .G&&G54G5xrefc                 ^   U R                  U5      n[        5       n[        X1U5        [        SSS5       H  n UR                  U   n  O   [        SU S35      e UR                  U R                  U   5        SUR                  ;   d  S	UR                  ;   ab  [        UR                  R                  SS
5      5      [        UR                  R                  S	S
5      5      pv[        R                  " XgS9Ul        U$ ! [
         a     M  f = f! [
         a    [        SU SU 35      Sef = f)z?Resolve a cross-reference to an already-seen SVG element by ID.r,   hrefr  zuse z% doesn't contain known xref attributez references nonexistent ref id Nr8  r9  r   r  )r  r   r   r{   r   rg   rc   add_itemr  re   r   r   r  r   )r  rg  r   	pdf_group	candidaterefr8  r9  s           r5   
build_xrefSVGObject.build_xref  s.    ''-	#%	Yi0%gvt<Ikk), = tD6)NOPP	t44S9: $++!3 a015a9P3Qq"+"7"7!"AI '    	tf;C5A	s   C>D >
DDD,r.  rk  inherited_stylec                 (   U R                  U5      n[        U=(       d    0 5      nUR                  U5        Uc
  [        5       n[	        X!U5        U Vs/ s H   ofR
                  [        SS5      ;   d  M  UPM"     sn H  nU R                  U5        M     U GHE  nUR
                  [        SS5      ;   a  U R                  U5        M1  UR
                  [        SS5      ;   a  MM  UR
                  [        SS5      ;   a%  UR                  U R                  USU5      S5        M  UR
                  [        SS5      ;   a:  [        R                  S5        UR                  U R                  USU5      S5        M  UR
                  [        SS	5      ;   a$  UR                  U R                  U5      S5        GM  UR
                  [        ;   a$  UR                  U R                  U5      S5        GMV  UR
                  [        SS
5      ;   a$  UR                  U R                  U5      S5        GM  UR
                  [        SS5      ;   a$  UR                  U R!                  U5      S5        GM  UR
                  [        SS5      ;   a0  U R#                  Xe5      nU(       a  UR                  US5        GM  GM  [        R                  S[%        UR
                  5      5        GMH     U R'                  UR(                  R+                  S5      U5        U$ s  snf )z+Handle nested items within a group <g> tag.Nr+   ra  r   r  Fr  rV  rR  userW  textr[  r  )r  rD  r  r   r   r   r{   re  rj  r8  r/  r0  r\  r^  r_  rn  r]  
build_textr   r  r   r   )r  r.  rk  rp  local_stylemerged_stylerb  	text_paths           r5   r8  SVGObject.build_group  sv    ))%0O1r2K(')IY|4  %
$e		\%5P(PEu
E U#

 EyyL77  'l5'::l5#66""4#3#3E4#NPUVl5#66 i ""4#3#3E4#NPUVl5&99""4??5#95Aj(""4#3#3E#:EBl5%88""4??5#95Al5'::""4#3#3E#:EBl5&99 OOE@	&&y%8  juyy)9 B 	))$/;Q
s   L5LrR  c                 D   U R                  U5      n[        5       n[        X1U5        U R                  X1U5        U R	                  X1U5        UR
                  R                  S5      nUb  [        X45        U R                  UR
                  R                  S5      U5        U$ )z1Convert an SVG <path> tag into a PDF path object.r  r  )	r  r   r   r+  apply_clipping_pathr   r   ry  r  )r  rR  r   r  r  s        r5   r\  SVGObject.build_path  s     ''-	=XY/""89=  ;;;??3'x2.9r7   shapec                 ^   U R                  U5      n[        [        [        UR                     5      nU" U5      n[        U[        5      (       d   e[        XAU5        U R                  XAU5        U R                  XAU5        U R                  UR                  R                  S5      U5        U$ )zConvert an SVG shape tag into a PDF path object. Necessary to make xref (because ShapeBuilder doesn't have access to this object.)r  )r  getattrrO  r^  r   r1   r   r   r+  rz  r  r   r   )r  r|  r   shape_builder
shape_paths        r5   r_  SVGObject.build_shape  s     ''.	j.CD"5)
*k2222Z	2"":i@  I>))$/<r7   rc  c                 2   UR                   [        ;   aH  U R                  U5      n[        [        [        UR                      5      nU" US5      n[        XQU5        OUR                   [        SS5      ;   af  U R                  U5      n[        5       n[        XQU5        [        R                  Ul
        UR                  R                  S5      nUb  [        XV5        O*[        R                  S[!        UR                   5      5        g U R#                  X%5        g )NTr+   rR  r  zaIgnoring unsupported <clipPath> child tag: <%s> (contributions are welcome to add support for it))r   r^  r  r~  rO  r   r{   r   r   
DONT_PAINT
paint_ruler   r   ry  r/  r0  r   r  )r  r|  rc  r   r  clipping_path_shaper  s          r5   r`  SVGObject.build_clipping_path  s    99
"++E2I#L*UYY2GHM"/t"<,Y?YY,uf55++E2I"--,Y?-:-E-E*||'',H#"#6ANNs599% 6r7   c                     S nU(       a  SU;   a  US   nUc  UR                   R                  S5      nU(       a4  [        R                  " SU5      nUc   eU R                  US      Ul        g g )Nz	clip-pathzurl\((\#\w+)\)r   )r   r   r   r  r  rP  )r  r   r   r   
clip_valueclipping_path_ids         r5   rz  SVGObject.apply_clipping_path3  sx     
	1";/J$++//<J!yy):JG#///%)%:%:;KA;N%OH" r7   c           
         S n[        SS5       H#  nX1R                  ;   d  M  UR                  U   n  O   U(       d  [        S5      e[        UR                  R	                  SS5      5      n[        UR                  R	                  SS5      5      nSUR                  ;   a  [
        R                  S5        S	UR                  ;   a  [
        R                  S
5        SUR                  ;   a  [
        R                  S5        [        U[        UR                  R	                  SS5      5      [        UR                  R	                  SS5      5      UUU S9nU R                  UR                  R	                  S5      U5        U$ )Nr,   ri  z#<image> is missing a href attributerW  r   rY  r/  zu"preserveAspectRatio" defined on <image> is currently not supported (contributions are welcome to add support for it)r   zg"style" defined on <image> is currently not supported (contributions are welcome to add support for it)r   zk"transform" defined on <image> is currently not supported (contributions are welcome to add support for it)r8  rV  r9  ri  r8  r9  rW  rY  svg_objr  )	r{   r   rc   re   r   r/  r0  SVGImager  )r  rW  ri  r   rW  rY  	svg_images          r5   r]  SVGObject.build_imageD  sC   0Cll"||C( 1 BCCell&&w23u||''!45 ELL0NN H ell"NNy %,,&NN} ELL$$S#./ELL$$S#./
	 	))$/;r7   text_tagc                   ^"^#^$^%^&^'^( U R                  U5      n[        U=(       d    0 5      nUR                  U5        [        5       n[	        XQU5        U R                  XQU5        [        XA5      n[        X5      u  m$m#pxT$c  Sm$Ub  UO
[        S5      m%[        XT%S9u  ppX-   nX-   n/ m(Sm&Sm'S[        S   S[        [        [        [        4      S	[        [           4S
 jm"      S!S[        S[        [           S[        [           S[        [           S[        S[        S[        S[        [           S[        [           S[        S   S[        [        [        [        4      S	S4U"U#U$U%U&U'U(4S jjjnU" UR                   =(       d    ST$T#UUSSS9  U GHO  nUR"                  [%        SS5      ;   Ga0  U R                  U5      n[        U5      nUR                  U5        [        UU5      u  nnnnUb  UOT%n[        UUUS9u  nnnn[        UU5      nSR'                  UR)                  5       5      nUR*                  =(       d    SnU(       a&  UR-                  U5      (       a  US[/        U5      *  nOUnSn Sn!SUR0                  ;   d	  Ub  SU;   a  Un SUR0                  ;   d	  Ub  SU;   a  Un!U" UUUUUUUU U!UUS9  U" UR*                  =(       d    ST$T#UUSSS9  GMO  GMR     T((       a#  UR3                  [5        UU[7        T(5      US9SS9  U R9                  UR0                  R;                  S 5      U5        U$ )"z
Convert <text> (and simple <tspan>) into a PaintedPath with Text runs.
- Uses Text baseline at (x,y)
- Honors x/y and dx/dy on <text> and direct child <tspan>
- Flattens nested tspans; advanced per-character positioning is not implemented
N
sans-serif16px)r(  r   r   r'   style_map_for_tagr.   c                    ^ U b  Uc  g [        5       m[        TX5        [        R                  TR                  l        [        U4S j[        R                   5       5      nU(       d  g [        TR                  5      $ )Nc              3   p   >#    U  H+  n[        TR                  U5      [        R                  Lv   M-     g 7fr0   )r~  r   r   r   )r  propcontexts     r5   r  ?SVGObject.build_text.<locals>._style_for_run.<locals>.<genexpr>  s.      :D t,M4I4II:s   36)	r   r   r   r   r   r   anyMERGE_PROPERTIESr   )r   r  	overridesr  s      @r5   _style_for_run,SVGObject.build_text.<locals>._style_for_run  sk     {/7%'G#9'4'<'<GMM$ ):: I GMM**r7   raw_textr#  r$  sizer   dx_extrady_extraabs_xabs_y	style_tagc                 H  > U =(       d    Sn[        XS9nU(       a  UnOUR                  5       nU(       a=  UnUS S R                  5       (       a  SU-   nUSS  R                  5       (       a  US-   nO<US S R                  5       (       d  USS  R                  5       (       a
  T(       a  SnOSnU(       d  TU-  mTU-  mg Ub  UOTnU=(       d    T=(       d    SnUb  UOT=(       d    SnTU-   nTU-   nSmSmT" X5      nTR                  [	        UUUUUUUUUS9	5        g )	Nru   )r   r   r   rX  r  r   )	rs  r#  r$  r  r:  r;  r  r  	run_style)r   r3   isspacer  r   )r  r#  r$  r  r   r  r  r  r  r  r  raw	collapsedcontenttrimmedrun_size
run_familyrun_emphasisrun_dxrun_dyr  r  	base_emphbase_familydefault_font_size
pending_dx
pending_dy	text_runss                        r5   _add_run&SVGObject.build_text.<locals>._add_run  sC    .bC$S<I##//+%G2Aw(("%-23x''))")C-BQ))SX-=-=-?-?Y"%"$h&
h&
#/t5FH>;>,J(0(<H)RPRL(*F(*FJJ&yDI %)!'
r7   ru   )r   r  r  r+   tspanr8  r9  )r   r  r  r  r  r  r  )r8  r9  r  text_anchorF)cloner  )r   r   NNNN)r  rD  r  r   r   rz  r   r'  rj   r<  r	   r2   r   r   re   r   rs  r   r{   r   r  tailr^  r  r   add_path_elementr   r  r  r   ))r  r  rp  ru  effective_stylerR  preserve_parent	base_sizebase_anchorbase_xbase_ybase_dxbase_dyanchor_xanchor_yr  rb  child_local_stylechild_effective_stylefamemphr  _anchorrun_font_sizer8  r9  r:  r;  child_preserveraw_itertext	tail_textrun_textr  r  r  r  r  r  r  r  r  s)                                     @@@@@@@r5   rt  SVGObject.build_textg  s    ))(34"5{+}T[1  A&A9J:
6Y	 &K".IN64J 	 ,;1B,
( ###%	

	+)$	+9A$sCx.9Q	+m$	+, "!%)%)-1:>9	9	SM9	 sm9	 5/	9	
 9	 9	 9	 E?9	 E?9	  	*9	  (S#X79	 9	 9	x 	MMR$"	
 EyyL88$($7$7$>!(,_(=%%,,->?+<0,(T4 )-(8>O.0M 1b" "..CU!K!wwu~~'78!JJ,"	!6!6y!A!A+,=s9~o>H+H%,,&%1c=N6NE%,,&%1c=N6NE+#&7 JJ$","&* s v !!#I. +	  "  	,,T2D9r7   )	r9  r  r  r  rY  r  r0  r1  rW  r0   )r  r'   r.   N)rV  )r  r'   r.   N)T)TF)NNN)ra  r'   r.   NNN)rW  r'   r.   r  )2r<   r=   r>   r?   r@   r  r2   r   r   r  bytesr	   r"   r  r!   r  r  rD  r  r  re   r  listr  r   r   r  r  r  r&  r   r+  r  r  r   r   rB  r9   r>  rS  re  rn  r8  r\  r_  r`  rz  r]  rt  rA   r;   r7   r5   r  r  ?  s    
  	8%8 8 	8
 8 
8 8. JN(e(2::2F(	(* 4x} 4# 4$ 4 4
2) S#X > C #    * A#A	eE9z112	3A  AF  (3-    AW AWF KW KWZ 
 /3	GG G DcN+	G
 
G G* %, %,N 	% 	% 26WW*.W	ue_,	-W: #%*`D`D w`D 	`D
 `D #`D 
ue_,	-`DJ "!'+ % % E? % E?	 %
 tn % 
 %H $ $P y _  >  0448	77 O,7 "$sCx.1	7
 
7 7r y [   
 
{ 
 
 7 7Xc] 7t 7 7, 
 /3	PP P DcN+	P
 
P P     D OSA!A4<T#s(^4LA	+	A Ar7   r  c                       \ rS rSr% \\S'   \\S'   \\S'   \\S'   \\S'   \\S'   SS S	\\	\
4   S
S 4S jr\SSS\SSS\S
\\S\4   4
S j5       r\S
\4S j5       rS\S
\\\4   4S jrSrg)r  i,  ri  r8  r9  rW  rY  r  r  _memor.   c           	          [        U R                  U R                  U R                  U R                  U R
                  U R                  S9$ )Nr  )r  ri  r8  r9  rW  rY  r  )r  r  s     r5   __deepcopy__SVGImage.__deepcopy__4  s9    ffff**;;LL
 	
r7   resource_registryr*   r   	last_itemr(   initial_pointc           	         U R                   =(       a    U R                   R                  nU(       d  [        S5      eSSKJn  U" XPR
                  5      u    px[        U[        5      (       a  [        R                  S5        SX44$ UR                  U R                  U R                  5      u  p[        UU R                  U R                  U	U
SS9nXU4$ )NzHfpdf2 bug - Cannot render a raster image without a SVGObject.image_cacher   )preload_imagez{Inserting .svg vector graphics in <image> tags is currently not supported (contributions are welcome to add support for it)ru   T)infor8  r9  whkeep_aspect_ratio)r  r  AssertionErrorimage_parsingr  ri  r1   r#   r/  r0  size_in_document_unitsrW  rY  r$   r8  r9  )r  r  r   r  r  r  r  rP  r  r  r  stream_contents               r5   renderSVGImage.render@  s     ll?t||'?'? Z  	1";		:
1dO,,NN N y//**4::t{{C8ffff"
 -77r7   c                 B    [        U R                  U R                  5      $ r0   )r   r8  r9  )r  s    r5   	end_pointSVGImage.end_pointc  s    TVVTVV$$r7   r  c           	      V   U R                   nU R                  nU R                   U R                  -   nU R                  U R                  -   n[        R
                  " [        X#5      [        XC5      [        X%5      [        XE5      /5      nU[        U R                   U R                  5      4$ r0   )r8  r9  rW  rY  r   from_pointsr   )r  r  x0y0rn  ro  bboxs          r5   bounding_boxSVGImage.bounding_boxh  s    VVVVVVdjj VVdkk!&&bbbb	
 U466466***r7   r;   N)r<   r=   r>   r?   r2   __annotations__re   r  rD  r
  r   r  r!   r   r   r  r  propertyr  r   r  rA   r;   r7   r5   r  r  ,  s    
IHHLM	
: 	
d38n 	
 	
  8, 8  8  	 8
  8 
sL%'	( 8  8D %5 % %+% +E+u2D,E +r7   r  )rV   )rZ   r0   r~  r  )or@   loggingr  r   warningscopyr   osr   typingr   r   r   r   r	   fontTools.svgLib.pathr
   enumsr   r   r   r   defusedxml.ElementTreer   r  ImportErrorwarnxml.etree.ElementTreeru   r   drawingr   r   r   r   r   r   r   r   r   drawing_primitivesr   r   r   r   r   r    r!   image_datastructuresr"   r#   outputr$   patternr%   r&   r'   r(   fpdfr)   r*   	getLoggerr<   r/  rv   compiler   r  DOTALLrA  rB  r2   r6   re   r9   ra   rh   rf   taurm   rj   ro   rw   rD  r{   r   r^  r   r   r   r   r   r   r   r  r   r   r   r   r  r  r  r'  r<  r  rM  rO  r   ry  r  r  r;   r7   r5   <module>r     sD     	    E E V UBB 
 
 
   > 3 A-#' 
		8	$ (+ 
 zz89::m  L"))4zz56 (3-  /e / / 

PQ * 




		  88c>HHsNHH	 Vs V# V V V( QS Q Q Q Q"  C C    S T#s(^   c c   	68Y
I

 Ds Dy:5 D D 3 8E?       	 	 	8SE5L3I 	 	 2E#SE3J/  <M
)C=
)%-seSj%9
)
) 
)" U


 OR
o; d38n ;|  04$7O+$7$7 T#s(^,$7 
	$7 $7N)DcN ) )t )	"HSM 	"T 	"c 	"HSM  PS * FJ6	66*24S>*B6c]6" ;?Q	Q'S#X7Q
8C=#x34QH +/!%D	DS#X'D D 5%%&	DN U3S#X;N5O0P 8   D `c `i ` `F ? ? ? ? ?j jZJ+z J+_8  BMMc BABs   N N-,N-