
     hQ                     8   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jd                  ejf                  ejh                  dZ5ejf                  ejd                  ejl                  ejh                  dZ7ejp                  ejr                  dZ:ejv                  ejx                  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 ZIy)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y)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|}|xs t        j                         } | |||d||||||	|
rt        nd|rt        nd      }|j                          ||j                         S y)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).

        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                      l/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/cairosvg/surface.pyconvertzSurface.convert`   s    B  !H#f )RZZ\&#t\=%-)9%2\&3l	?
 	??$$     c                    d| _         ||c| _        | _        ddg| _        ddg| _        d| _        |j                  |j                  d      f|i| _        |rx|j                  | _	        |j                  | _
        |j                  | _        |j                  | _        |j                  | _        |j                  | _        |j                  | _        n1i | _	        i | _
        i | _        i | _        i | _        i | _        i | _        dx| _        | _        || _        || _        t)        | d      | _        d| _        t/        | |      \  }}}|dd||f}|r|	r||	}}n(|r|r|||z  z  }|}n|	r|r||	|z  z  }|	}n
||z  }||z  }| j1                  || j2                  z  || j2                  z        \  | _         | _        | _        d| j4                  | j6                  fv rt9        d      t        j:                  | j                         | _        | j<                  j?                  | j2                  | j2                         | jA                  ||||       | j<                  jC                  dd       |
r< | j<                  jD                  tG        |
        | j<                  jI                          || _%        || _&        | jO                  |       y)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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   rp   rq   viewboxs                   rU   __init__zSurface.__init__   s    
2>/D/ !1v"#Q  HHdhhtn5t<)11DL+55DN*33DM'--DJ'--DJ)11DL(//DKDLDNDMDJDJDLDK377 0dF+#!,T4!8vw?!UF+GM(-6E,.. E//"FUNEeOF /3.B.BD444T555/7+
DJ T[[))899}}TZZ0,,d.N.N	P 	eVWd;Q"(DLL((%0@*ABLL  "		$rW   c                 4    d| j                   t        d   z  z  S )zSurface resolution.r   pt)r<   r   ry   s    rU   points_per_pixelzSurface.points_per_pixel   s     DHHuT{*++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   ro   z#Surface.device_units_per_user_units   s     $$$rW   c                 F    | j                  | j                  ||      }|||fS 5Create and return ``(cairo_surface, width, height)``.)surface_classrS   ry   rp   rq   cairo_surfaces       rU   rn   zSurface._create_surface   s'    **4;;vFeV++rW   c                 z   |r|dd \  }}|d   |_         |d   |_        nd\  }}||_         ||_        t        | |||      \  }}}	}
||z  ||z  }}||}} | j                  j                  | j                  j                           | j                  j	                  | |        |j                  dd      dk7  r8| j                  j                  ||||       | j                  j                          | j                  j                  ||       | j                  j	                  |	|
       ||z  | _
        ||z  | _        y)	z6Set the Cairo context size, set the SVG viewport size.r         )r   r   overflowhiddenvisibleN)image_widthimage_heightr   rt   	translateget_current_pointra   	rectangleclipr?   r\   r]   )ry   rp   rq   r{   rR   rect_xrect_yscale_xscale_ytranslate_xtranslate_y
rect_widthrect_heights                rU   ru   zSurface.set_context_size   s3   $Qq\NFF&qzD '
D!NFF$D &D5C$v6'2+{')6G+;"'K
 > > @Aw088J)Y6LL""66:{KLL7G,{K8''1)G3rW   c                 8    | j                   j                          y)zRead the surface content.N)r[   rN   r   s    rU   rN   zSurface.finish  s    

rW   c                 X    t        ||      }| j                  r| j                  |      S |S )z?Parse a color ``string`` and apply ``map_rgba`` function to it.)r   rI   )ry   stringopacityrgbas       rU   	map_colorzSurface.map_color  s(    VW%&*mmt}}T"==rW   c           	         |j                   dk(  rt        | |       |j                   dk(  ryd|v rt        | |d         dk(  sd|v rt        | |d         dk(  ry| j                  }| j                  }| j
                  | j                  f}|| _        d|v r"t        |d         }|D ]  }||vs||   ||<    t        | |j                  dd	            | _        | j                  j                          t        | |j                  d
      |j                  d             t        |j                  d            j                  }t        |j                  d            j                  }t        |j                  dd            }	|rt        | ||       |s|s|	dk  r&|j                   r| j                  j#                          | j                  j%                  t        | |j                  d      d      t        | |j                  d      d             |j                  d      }
|
dk(  r)| j                  j'                  t(        j*                         |
dk(  r)| j                  j'                  t(        j,                         |j                  d      }|dk(  r)| j                  j/                  t(        j0                         |dk(  r)| j                  j/                  t(        j2                         t5        |j                  dd            j7                         }|r[|D cg c]  }t        | |       }}t9        |      r7t        | |j                  d            }| j                  j;                  ||       t        |j                  dd            }| j                  j=                  |       t?        |j                  d            }tA        |      dk(  rDt        | |d   d      }t        | |d   d      }t        | |d   d      }t        | |d   d      }t        | |j                  d      d      }t        | |j                  d      d      }t        | |j                  d      d      }t        | |j                  d      d      }| j                  j                          | j                  jC                  ||       | j                  jE                  ||||z
  |z
  ||z
  |z
         | j                  jG                          | j                  jI                          t        |j                  d             j                  }|r| jJ                  j                  |      }|ra| j                  j                           |j                  d!      d"k(  rt        | |j                  d      d      }t        | |j                  d      d      }t        | |j                  d      d      }t        | |j                  d      d      }| j                  jC                  ||       | j                  jM                  ||       d#|_         d$| _'        | jQ                  |       d%| _'        d&|_         | j                  jG                          | j                  jI                          | j                  jS                  t(        jT                         tW        jX                  | jZ                  | j\                  | j^                  f      }|j                   t`        v r	 ta        |j                      | |       t        |j                  d'd            }t        |j                  d(d            }|	dk  r|j                   s
||	z  }||	z  }|j                  d)d*      d+k7  }|xr |j                  d,d-      d.k7  } | j                  je                  tf        j                  |j                  d/      t(        jh                               | j                  jk                         }!|!je                  tl        j                  |j                  d0      t(        jh                               |!jo                  tp        j                  |j                  d0      t(        jr                               |!ju                  tv        j                  |j                  d0      t(        jx                               | j                  j{                  |!       | jN                  r| r|j                   t`        v r| j                  j                          t}        |j                  d1d2            \  }"}#|j                  d3      d4k(  r)| j                  jS                  t(        j~                         t        | ||"|      s) | j                  j                  | j                  |#|        t`        |j                      t        k(  r-|d   | _-        |d   | _.        |d   | _/        t        | |d%5       n| j                  j                          | j                  jG                          | j                  j                          | j                  j                  t        | |j                  d6d7                   t}        |j                  d8            \  }"}#t        | ||"|      s) | j                  j                  | j                  |#|        | j                  j                          | j                  jG                          n| s| j                  j                          t        | |       |r4|j                   t        vr"|j                   D ]  }$| jQ                  |$        |s|s|	dk  r||j                   rp| j                  j                          |rt        | ||       || j                  v rt        | |||	       n| j                  j                  |	       |rt        | ||       |j                   d9k(  rddg| _-        ddg| _.        d| _/        | j                  jG                          || _        || _        |\  | _        | _        yc c}w # tb        $ r Y <w xY w):zDraw ``node`` and its children.r(   defsNrp   r   rq   font	font-sizerZ   r   ztransform-origin)transform_originr   r1   r   r   xyzstroke-linecapsquareroundzstroke-linejoinbevelzstroke-dasharray 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   rk   rl   r\   r]   
parse_fontra   rt   saver   r*   fragmentfloatr   children
push_grouprv   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   rg   r?   rm   rx   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
   rw   r   r)   fill_preserveset_line_widthr   new_pathr    INVISIBLE_TAGSpop_group_to_sourcer   rf   r   paint_with_alphar   )%ry   nodeold_parent_nodeold_font_sizeold_context_sizer   attr   r	   r   line_capjoin_cap
dash_arraydashdashesoffsetmiter_limitrect_valuestoprightbottomleftr   r   rp   rq   r   r!   save_cursorstroke_opacityfill_opacityr   r   font_optionspaint_sourcepaint_colorchilds%                                        rU   rx   zSurface.draw  s
    88u4& 88v _dDM!:a!?T!d4h&@A&E **--t/B/BBT>d6l+D *d? $S	DI* dDHH[&$AB 	$((;'!XX&89	;
 &)*33DHHX./88A./4w/dw{t}}LL##% 	txx}c*txx}c*	,
 88,-xLL%%e&;&;<wLL%%e&:&:;88-.wLL&&u'<'<=wLL&&u'<'<=txx(:B?@FFH
3=>4d4&>F>6{dDHH-@$AB%%ff5DHH%8!<=$$[1   01{q t[^S1C{1~s3E$A4Fk!nc2DT488C=#.AT488C=#.Atxx0#6E$ 2C8FLLLL""1a(LL""c54<%/#1FHLL  "LLdhh{34==	::>>),D!!#488O,0CCT488C=#6AT488C=#6A txx'8#>E!$(:C@FLL**1a0LL&&uf5',$		$'+$%$$& !!#**5+B+BCmm!!4#9#9!!#$
 88tTXXtT* txx(8!<=TXXna89Q;t}}g%NG#L ((9h/69Mtxxi@HL 	""?#6#6HH&')@)@$B 	C ||446"">#5#5HH%&(?(?$A 	B##O$7$7HH%&(@(@%B 	C%%&7&;&;HH%&(B(B'D 	E%%l3 GD0@LL(-dhhvw.G(H%L+xx$	1**5+C+CD&tT<N,,,^^K>@DHH~%'21~$)4Q&'21~$T4d3**,LL  " LLLL''T488NC89;(-dhhx.@(A%L+&$n>,,,^^K@BLL!LL  "LL!!# 	T4  txx~5 !		% ! dw{t}}LL,,.,T4Atzz!4tW5--g6+D$@ 88v$%q6D &'VD"#$D *&2B/D/g ?r  s   q q	 		qq)N)	NNNr   NNNNN)r   )__name__
__module____qualname____doc__r   classmethodrV   r|   propertyr   ro   rn   ru   rN   r   rx   rK   rW   rU   r8   r8   R   s     M+%$Db!Qu!%U#d"	+% +%Z :>26;?AESj , , % %,
42>
VCrW   r8   c                   (    e Zd ZdZej
                  Zy)
PDFSurfacez$A surface that writes in PDF format.N)r   r   r   r  r[   r  r   rK   rW   rU   r  r    s    .$$MrW   r  c                   (    e Zd ZdZej
                  Zy)	PSSurfacez+A surface that writes in PostScript format.N)r   r   r   r  r[   r  r   rK   rW   rU   r  r    s    5OOMrW   r  c                       e Zd ZdZd Zy)
EPSSurfacez8A surface that writes in Encapsulated PostScript format.c                 p    t        j                  | j                  ||      }|j                  d       |||fS )r   T)r[   r  rS   set_epsr   s       rU   rn   zEPSSurface._create_surface  s3    UFCd#eV++rW   N)r   r   r   r  rn   rK   rW   rU   r	  r	    s
    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   rn   zPNGSurface._create_surface
  sE    E%L!U6]#**5+>+>vNeV++rW   c                     | j                   %| j                  j                  | j                          t        |          S )zRead the PNG surface content.)rS   r[   write_to_pngsuperrN   )ry   	__class__s    rU   rN   zPNGSurface.finish  s0    ;;"JJ##DKK0w~rW   )r   r   r   r  ro   rn   rN   __classcell__)r  s   @rU   r  r    s    ."#,   rW   r  c                   ,    e Zd ZdZdZej                  Zy)
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  ro   r[   r  r   rK   rW   rU   r  r    s     #$$$MrW   r  c                 @   ddddddd}ddg}dg}g d}| j                         D ]v  }|dk(  r	|d   r|dxx   d	|z   z  cc<   ||v r||d
<   )||v r||d<   3||v r||d<   =|d   s0|j                  d      }|d   |d<   t        |      dkD  r|d   |d<   r||d<   x |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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>rG     s9  
  	  'C C C C% % % '  $ B B    ))&&.. &&))....	  ////  00// 
f 	 w	
 g U D o f D D w  w o  D!" 
3#$ +0  H I	    !
]Cf ]C@% %
$ $
, ,   $% %rW   