
    jR                        d Z ddlZddlZddlZddlmZmZ ddlm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZm Z  ddl!m!Z!m"Z" ddl#m$Z$ dd	l%m&Z&m%Z% dd
l'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m.Z. ddl/m/Z/ ddl0m1Z1 ej2        ej3        ej4        dZ5ej3        ej2        ej6        ej4        dZ7ej8        ej9        dZ:ej;        ej<        dZ=i de/de(dede)dede!de*dededede%dede,de+ded e-d!e.e/e/e/ed"Z> e?d#          Z@ e?d$          ZA G d% d&eB          ZC G d' d(eC          ZD G d) d*eC          ZE G d+ d,eC          ZF G d- d.eC          ZG G d/ d0eC          ZHd1 ZIdS )2z
Cairo surface creators.

    N   )colornegate_color)apply_filter_after_paintingapply_filter_before_painting	clip_pathfilter_gradient_or_patternlinear_gradientmarkermask
paint_maskparse_all_defspatternprepare_filterradial_gradientuse)	UNITS
PointError	clip_rectnode_format	normalizepaintpreserve_ratiosize	transform)imageinvert_image)Tree)draw_markerspath)circleellipselinepolygonpolylinerect)svg)text)	parse_url)optimizeSpeed
crispEdgesgeometricPrecision)r,   r+   optimizeLegibilityr-   )r-   r.   ar"   clipPathr#   filterr   r$   linearGradientr   r   r!   r   r&   r%   radialGradientr'   r(   )r)   textPathtspanr   )r"   r#   r$   r!   r%   r&   r'   )r0   r1   r2   r   r   r   r3   symbolc                       e Zd ZdZdZedddddddddddddddd            Z	 	 	 	 ddZed	             Z	ed
             Z
d Zd Zd ZddZd ZdS )Surfacea)  Abstract base class for CairoSVG surfaces.

    The ``width`` and ``height`` attributes are in device units (pixels for
    PNG, else points).

    The ``context_width`` and ``context_height`` attributes are in user units
    (i.e. in pixels), they represent the size of the active viewport.

    N`   r   F)file_objurldpiparent_widthparent_heightscaleunsafebackground_colornegate_colorsinvert_imageswrite_tooutput_widthoutput_heightc                    t          d||||d|}|pt          j                    } | |||d||||||	|
rt          nd|rt          nd          }|                                 ||                                S dS )a  Convert an SVG document to the format for this class.

        Specify the input by passing one of these:

        :param bytestring: The SVG source as a byte-string.
        :param file_obj: A file-like object.
        :param url: A filename.

        Give some options:

        :param dpi: The ratio between 1 inch and 1 pixel.
        :param parent_width: The width of the parent container in pixels.
        :param parent_height: The height of the parent container in pixels.
        :param scale: The ouptut scaling factor.
        :param unsafe: A boolean allowing external file access, XML entities
                       and very large files
                       (WARNING: vulnerable to XXE attacks and various DoS).
                       This does NOT restrict fetching of the main SVG input
                       specified via the ``url`` parameter.
                       Applications should validate input URLs to prevent SSRF.


        Specifiy the output with:

        :param write_to: The filename of file-like object where to write the
                         output. If None or not provided, return a byte string.

        Only ``bytestring`` can be passed as a positional argument, other
        parameters are keyword-only.

        )
bytestringr:   r;   r@   N)map_rgba	map_image )r   ioBytesIOr   r   finishgetvalue)clsrH   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   kwargstreeoutputinstances                      W/home/ubuntu/budget-transfer-bot/.venv/lib/python3.11/site-packages/cairosvg/surface.pyconvertzSurface.convert`   s    J  !H#f   )RZ\\3&#t\=%-)9%2<\\&3=ll	? ? ?
 	??$$$     c                 "   d| _         ||c| _        | _        ddg| _        ddg| _        d| _        |j        |                    d          f|i| _        d| _	        |rU|j
        | _
        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        n1i | _
        i | _        i | _        i | _        i | _        i | _        i | _        dx| _        | _        || _        || _        t+          | d          | _        d| _        t1          | |          \  }}}|dd||f}|r|	r||	}}n(|r|r|||z  z  }|}n|	r|r||	|z  z  }|	}n
||z  }||z  }|                     || j        z  || j        z            \  | _         | _        | _        d| j        | j        fv rt;          d          t          j        | j                   | _        | j                             | j        | j                   | !                    ||||           | j        "                    dd           |
r5 | j        j#        tI          |
            | j        %                                 || _&        || _'        | (                    |           dS )au  Create the surface from a filename or a file-like object.

        The rendered content is written to ``output`` which can be a filename,
        a file-like object, ``None`` (render in memory but do not write
        anything) or the built-in ``bytes`` as a marker.

        Call the ``.finish()`` method to make sure that the output is
        actually written.

        Nr   id12ptTzThe SVG size is undefined))cairocontext_widthcontext_heightcursor_positioncursor_d_positiontext_path_widthr;   get
tree_cachereference_countmarkers	gradientspatternsmaskspathsfiltersimages_old_parent_nodeparent_noderS   r<   r   	font_sizestroke_and_fillr   _create_surfacedevice_units_per_user_unitswidthheight
ValueErrorContextcontextr?   set_context_sizemove_toset_source_rgbar   r   rI   rJ   draw)selfrR   rS   r<   parent_surfacer=   r>   r?   rE   rF   rA   rI   rJ   rq   rr   viewboxs                   rU   __init__zSurface.__init__   s    
2>/D/ !1v"#Q  Hdhhtnn5t<  	)1DL+5DN*3DM'-DJ'-DJ)1DL(/DKKDLDNDMDJDJDLDK377 0dF++#!,T4!8!8vw?!UF+G 	M 	(-6EE 	 /,.. EE 	 0//"FFUNEeOF /3.B.BD44T55/7 /7+
DJ T[)))8999}TZ00,d.N	P 	P 	P 	eVWd;;;Q""" 	!(DL(%0@*A*ABBL    "		$rW   c                 2    d| j         t          d         z  z  S )zSurface resolution.r   pt)r<   r   rz   s    rU   points_per_pixelzSurface.points_per_pixel   s     DHuT{*++rW   c                     | j         S )zRatio between Cairo device units and user units.

        Device units are pixels for PNG and SVG, and points for everything
        else. User units are pixels.

        )r   r   s    rU   rp   z#Surface.device_units_per_user_units   s     $$rW   c                 D    |                      | j        ||          }|||fS 5Create and return ``(cairo_surface, width, height)``.)surface_classrS   rz   rq   rr   cairo_surfaces       rU   ro   zSurface._create_surface   s(    **4;vFFeV++rW   c                    |r(|dd         \  }}|d         |_         |d         |_        nd\  }}||_         ||_        t          | |||          \  }}}	}
||z  ||z  }}||}} | j        j        | j                                          | j                            | |            |                    dd          dk    r6| j                            ||||           | j                                         | j        	                    ||           | j                            |	|
           ||z  | _
        ||z  | _        dS )	z6Set the Cairo context size, set the SVG viewport size.r         )r   r   overflowhiddenvisibleN)image_widthimage_heightr   ru   	translateget_current_pointra   	rectangleclipr?   r\   r]   )rz   rq   rr   r|   rR   rect_xrect_yscale_xscale_ytranslate_xtranslate_y
rect_widthrect_heights                rU   rv   zSurface.set_context_size   sa    	'$QqS\NFF&qzD '
D!NFF$D &D5C$v6' 6'2+{')6G+;"'K
 > > @ @AAw00088J))Y66L""66:{KKKL7G,,,{K888''1)G3rW   c                 8    | j                                          dS )zRead the surface content.N)r[   rN   r   s    rU   rN   zSurface.finish  s    
rW   c                 ^    t          ||          }| j        r|                     |          n|S )z?Parse a color ``string`` and apply ``map_rgba`` function to it.)r   rI   )rz   stringopacityrgbas       rU   	map_colorzSurface.map_color  s/    VW%%&*m=t}}T"""=rW   c           	      4    |j         dk    rt           |           |j         dk    rdS d|v rt           |d                   dk    sd|v rt           |d                   dk    rdS  j        } j        } j         j        f}| _        d|v r)t          |d                   }|D ]}||vr||         ||<   t           |                    dd	                     _         j	        
                                 t           |                    d
          |                    d                     t          |                    d                    j        }t          |                    d                    j        }t          |                    dd                    }	|rt           ||           |s|s|	dk     r |j        r j	                                          j	                            t           |                    d          d          t           |                    d          d                     |                    d          }
|
dk    r$ j	                            t(          j                   |
dk    r$ j	                            t(          j                   |                    d          }|dk    r$ j	                            t(          j                   |dk    r$ j	                            t(          j                   t5          |                    dd                                                    }|r[ fd|D             }t9          |          r>t           |                    d                    } j	                            ||           t          |                    dd                    } j	                            |           t?          |                    d                    }tA          |          dk    r{t           |d         d          }t           |d         d          }t           |d         d          }t           |d          d          }t           |                    d          d          }t           |                    d          d          }t           |                    d          d          }t           |                    d          d          } j	        
                                  j	        !                    ||            j	        "                    ||||z
  |z
  ||z
  |z
              j	        #                                  j	        $                                 t          |                    d!                    j        }|r j%                            |          }|rz j	        
                                  |j        d"          d#k    rt           |                    d          d          }t           |                    d          d          }t           |                    d          d          }t           |                    d          d          } j	        !                    ||            j	        &                    ||           d$|_         d% _'         (                    |           d& _'        d'|_          j	        #                                  j	        $                                  j	        )                    t(          j*                   tW          j,         j-         j.         j/        f          }|j         t`          v r-	 ta          |j                   |           n# tb          $ r Y nw xY wt          |                    d(d                    }t          |                    d)d                    }|	dk     r|j        s
||	z  }||	z  }|                    d*d+          d,k    }|o|                    d-d.          d/k    } j	        2                    tf                              |                    d0          t(          j4                              j	        5                                } | 2                    tl                              |                    d1          t(          j4                             | 7                    tp                              |                    d1          t(          j9                             | :                    tv                              |                    d1          t(          j<                              j	        =                    |             j'        r,|r)|j         t`          v r j	        
                                 t}          |                    d2d3                    \  }!}"|                    d4          d5k    r$ j	        )                    t(          j?                   t           ||!|          s#  j	        jA         B                    |"|            t`          |j                  t          k    r:|d          _-        |d          _.        |d          _/        t           |d&6           n j	        D                                  j	        #                                  j	        
                                  j	        E                    t           |                    d7d8                               t}          |                    d9                    \  }!}"t           ||!|          s#  j	        jA         B                    |"|             j	        F                                  j	        #                                 n|s j	        G                                 t           |           |r-|j         t          vr|j        D ]}# (                    |#           |s|s|	dk     r||j        ru j	        J                                 |rt           ||           | jL        v rt           |||	           n j	        N                    |	           |rt           ||           |j         d:k    rddg _-        ddg _.        d _/         j	        #                                 | _        | _        |\   _         _        dS );zDraw ``node`` and its children.r(   defsNrq   r   rr   font	font-sizerZ   r   ztransform-origin)transform_originr   r1   r   r   xyzstroke-linecapsquareroundzstroke-linejoinbevelzstroke-dasharray c                 0    g | ]}t          |          S rK   )r   ).0dashrz   s     rU   
<listcomp>z Surface.draw.<locals>.<listcomp>a  s#    >>>4d4&&>>>rW   zstroke-dashoffsetzstroke-miterlimit   r   r   r   z	clip-pathclipPathUnitsobjectBoundingBoxgFTr0   zstroke-opacityzfill-opacitydisplayinlinenone
visibilityr   r   zshape-renderingztext-renderingfillblackz	fill-ruleevenodd)draw_as_textzstroke-width1stroker)   )Ptagr   r   rl   rm   r\   r]   
parse_fontra   ru   saver   r*   fragmentfloatr   children
push_grouprw   set_line_capr[   LINE_CAP_SQUARELINE_CAP_ROUNDset_line_joinLINE_JOIN_ROUNDLINE_JOIN_BEVELr   splitsumset_dashset_miter_limitr   lenr   r   restorer   rh   r?   rn   ry   set_fill_ruleFILL_RULE_WINDINGcopydeepcopyr^   r_   r`   TAGSr   set_antialiasSHAPE_ANTIALIASANTIALIAS_DEFAULTget_font_optionsTEXT_ANTIALIASset_hint_styleTEXT_HINT_STYLEHINT_STYLE_DEFAULTset_hint_metricsTEXT_HINT_METRICSHINT_METRICS_DEFAULTset_font_optionsr   FILL_RULE_EVEN_ODDr
   rx   r   r)   fill_preserveset_line_widthr   new_pathr    INVISIBLE_TAGSpop_group_to_sourcer   rg   r   paint_with_alphar   )$rz   nodeold_parent_nodeold_font_sizeold_context_sizer   attr   r	   r   line_capjoin_cap
dash_arraydashesoffsetmiter_limitrect_valuestoprightbottomleftr   r   rq   rr   r   r!   save_cursorstroke_opacityfill_opacityr   r   font_optionspaint_sourcepaint_colorchilds$   `                                   rU   ry   zSurface.draw  s    8u4&&& 8vF __dDM!:!:a!?!?T!!d4h&@&@A&E&EF *-t/BBT>>d6l++D * *d?? $S	DIdDHH[&$A$ABB 	$((;''!XX&899	; 	; 	; 	;
 &))**3DHHX..//8A..// 	04w/// 	&d 	&w{{t}{L##%%% 	txx}}c**txx}}c**	, 	, 	,
 88,--xL%%e&;<<<wL%%e&:;;;88-..wL&&u'<===wL&&u'<===txx(:B??@@FFHH
 	6>>>>:>>>F6{{ 6dDHH-@$A$ABB%%ff555DHH%8!<<==$$[111   0 011{q  t[^S11C{1~s33E$A44Fk!nc22DT488C==#..AT488C==#..Atxx00#66E$ 2 2C88FLL""1a(((L""c54<%/#1FH H HL  """Ldhh{3344=	 	D:>>),,D D!!###48O,,0CCCT488C==#66AT488C==#66A txx'8'8#>>E!$(:(:C@@FL**1a000L&&uf555',$		$'+$%$$&&& !!###**5+BCCCm!4#9!#$ $
 8tTXtT****   
 txx(8!<<==TXXna8899Q;;t};g%NG#L ((9h//69Mtxxi@@HL 	""?#6#6HH&'')@$B $B 	C 	C 	C |4466"">#5#5HH%&&(?$A $A 	B 	B 	B##O$7$7HH%&&(@%B %B 	C 	C 	C%%&7&;&;HH%&&(B'D 'D 	E 	E 	E%%l333  	$G 	$D0@0@L(-dhhvw.G.G(H(H%L+xx$$	11**5+CDDD&tT<NN @,,^^K>>@ @DH~%%'21~$)4Q&'21~$T4d33333**,,,L  """ LL''T488NC8899; ; ;(-dhhx.@.@(A(A%L+&$n> > B,,^^K@@B BL!!!L  """" 	$L!!### 	T4     	!tx~55 ! !		%      		Ad 		Aw{{t}{L,,... B,T4AAAtz!!4tW5555--g666 A+D$@@@ 8v$%q6D &'VD"#$D *&2B/D///s   ^# #
^0/^0)N)	NNNr   NNNNN)r   )__name__
__module____qualname____doc__r   classmethodrV   r}   propertyr   rp   ro   rv   rN   r   ry   rK   rW   rU   r8   r8   R   s#         M/%$Db!Qu!%U#d"	/% /% /% /% [/%b :>26;?AET T T Tl , , X, % % X%, , ,
4 4 42  > > > >
VC VC VC VC VCrW   r8   c                        e Zd ZdZej        ZdS )
PDFSurfacez$A surface that writes in PDF format.N)r  r  r  r  r[   r	  r   rK   rW   rU   r	  r	    s        ..$MMMrW   r	  c                        e Zd ZdZej        ZdS )	PSSurfacez+A surface that writes in PostScript format.N)r  r  r  r  r[   r  r   rK   rW   rU   r  r    s        55OMMMrW   r  c                       e Zd ZdZd ZdS )
EPSSurfacez8A surface that writes in Encapsulated PostScript format.c                 l    t          j        | j        ||          }|                    d           |||fS )r   T)r[   r  rS   set_epsr   s       rU   ro   zEPSSurface._create_surface  s8    UFCCd###eV++rW   N)r  r  r  r  ro   rK   rW   rU   r  r    s)        BB, , , , ,rW   r  c                   ,     e Zd ZdZdZd Z fdZ xZS )
PNGSurfacez$A surface that writes in PNG format.r   c                     t          t          |                    }t          t          |                    }t          j        t          j        ||          }|||fS r   )intr   r[   ImageSurfaceFORMAT_ARGB32r   s       rU   ro   zPNGSurface._create_surface  sL    E%LL!!U6]]##*5+>vNNeV++rW   c                     | j         | j                            | j                    t                                                      S )zRead the PNG surface content.)rS   r[   write_to_pngsuperrN   )rz   	__class__s    rU   rN   zPNGSurface.finish  s7    ;"J##DK000ww~~rW   )r  r  r  r  rp   ro   rN   __classcell__)r  s   @rU   r  r    sS        .."#, , ,                 rW   r  c                   $    e Zd ZdZdZej        ZdS )
SVGSurfacezA surface that writes in SVG format.

    It may seem pointless to render SVG to SVG, but this can be used
    with ``output=None`` to get a vector-based single page cairo surface.

    r   N)r  r  r  r  rp   r[   r  r   rK   rW   rU   r  r    s(          #$$MMMrW   r  c                 v   ddddddd}ddg}dg}g d}|                                  D ]}|dk    r	|d         r|dxx         d	|z   z  cc<   %||v r||d
<   /||v r||d<   9||v r||d<   C|d         s?|                     d          }|d         |d<   t          |          dk    r|d         |d<   ||d<   |S )Nr   normal)font-familyr   
font-stylefont-variantfont-weightline-heightitalicobliquez
small-caps)boldbolderlighter100200300400500600700800900r   r   r!  r"  r   /r   r   r#  )r   r   )valueretfont_stylesfont_variantsfont_weightselementpartss          rU   r   r   (  s>   2X#H"$ $C Y'K!NM7 7 7L ;;== - -h 	-#-/## 'C%%")C$$!(C{# -c**#(8K u::>>).qC&%,M""JrW   )Jr  r   rL   	cairocffir[   colorsr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   helpersr   r   r   r   r   r   r   r   r   r   r   parserr   r!   r    shapesr"   r#   r$   r%   r&   r'   r(   r)   r;   r*   ANTIALIAS_FASTANTIALIAS_NONEANTIALIAS_BESTr   ANTIALIAS_GOODr   HINT_STYLE_NONEHINT_STYLE_FULLr   HINT_METRICS_OFFHINT_METRICS_ONr   r   	frozenset	PATH_TAGSr   objectr8   r	  r  r  r  r  r   rK   rW   rU   <module>rK     s   
  				     ' ' ' ' ' ' ' 'C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C% % % % % % % % % % % % % % % % % % % % % % ' & & & & & & &       $ $ $ $ $ $ $ $ B B B B B B B B B B B B B B B B                   )&.  &)..	   //   0/  
f 	 w	
 g U D o f D D w  w o  D!" 
3#$ +  0 I H I I	    ! !
bC bC bC bC bCf bC bC bCJ% % % % % % % %
$ $ $ $ $ $ $ $
, , , , , , , ,               $% % % % % % % %    rW   