
    G8c
                     .   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlmZ d dlZd dlmZmZmZ d dlmZmZmZmZ d dlmZ d dlmZ d dlm Z  d d	l!m"Z" d d
lm#Z# d dl$m%Z%m&Z&  ejN                  e(      Z) ejT                  dd      d        Z+d Z, e
jZ                  d      Z. ejT                  dd      d        Z/d Z0 ejT                  dd      d        Z1d Z2d Z3 ejT                  dd      d        Z4d Z5 G d d      Z6d Z7 ejT                  d      d/d       Z8d  Z9 ejT                  d      d/d!       Z:d"d#d$d%Z;d& Z<d' Z= G d( d)e      Z> G d* d+e      Z?eZ@d,ZAej                   G d- d.e             ZCy)0    N)BytesIO)Image)_apicbookfont_manager)_BackendFigureCanvasBaseFigureManagerBaseRendererBase)MixedModeRenderer)rgb2hex)UTC)Path)_path)Affine2DAffine2DBasez3.6z a vendored copy of _escape_cdata)alternativec                     t        |       S N)_escape_cdatass    A/usr/lib/python3/dist-packages/matplotlib/backends/backend_svg.pyescape_cdatar   E   s        c                 r    | j                  dd      } | j                  dd      } | j                  dd      } | S )N&&amp;<&lt;>&gt;replacer   s    r   r   r   J   s7    			#wA			#vA			#vAHr   z-(?=-)z"a vendored copy of _escape_commentc                 ,    t         j                  |       S r   )_escape_commentsubr   s    r   escape_commentr(   T   s    q!!r   c                 D    t        |       } t        j                  d|       S )Nz- )r   _escape_xml_commentr'   r   s    r   r&   r&   Y   s    aA""4++r   z!a vendored copy of _escape_attribc                     t        |       S r   )_escape_attribr   s    r   escape_attribr-   ^   s    !r   c                     | j                  dd      } | j                  dd      } | j                  dd      } | j                  dd      } | j                  d	d
      } | S )Nr   r   'z&apos;"z&quot;r   r    r!   r"   r#   r   s    r   r,   r,   c   sW    			#wA			#x A			#x A			#vA			#vAHr   c                 x    d| vrdt        |       z   dz   S d| vrdt        |       z   dz   S dt        |       z   dz   S )Nr0   r/   )r   r,   r   s    r   _quote_escape_attribr2   l   sS    ,/qLC-""S( +,/qLC-""S(+.##c)+r   z#a vendored copy of _short_float_fmtc                     t        |       S r   _short_float_fmtxs    r   short_float_fmtr8   r   s    Ar   c                 `    dj                  |       j                  d      j                  d      S )z
    Create a short string representation of a float, which is %f
    formatting with trailing zeros and the decimal point removed.
    z{0:f}0.)formatrstripr6   s    r   r5   r5   w   s)    
 >>!##C(//44r   c                   T    e Zd ZdZd ZddZi fdZd Zd ZddZ	d	 Z
di fd
Zd Zy)	XMLWriterzM
    Parameters
    ----------
    file : writable text file-like object
    c                     |j                   | _        t        |d      r|j                  | _        d| _        g | _        g | _        d| _        y )Nflushr   z@                                                                )write_XMLWriter__writehasattrrA   _XMLWriter__open_XMLWriter__tags_XMLWriter__data_XMLWriter__indentation)selffiles     r   __init__zXMLWriter.__init__   s?    zz4!DJ%r   c                    | j                   r,|r| j                  d       n| j                  d       d| _         | j                  r=dj                  | j                        }| j                  t	        |             g | _        y y )Nz>
r!   r    )rE   rC   rG   joinr   )rI   indentdatas      r   __flushzXMLWriter.__flush   sa    ;;U#S!DK;;774;;'DLLt,-DK r   c                    | j                          t        |      }g | _        | j                  j	                  |       | j                  | j                  dt        | j                        dz
          | j                  d|z         i ||j                         D ]5  \  }}|s	t        |      }t        |      }| j                  d|d|       7 d| _
        t        | j                        dz
  S )a&  
        Open a new element.  Attributes can be given as keyword
        arguments, or as a string/string dictionary. The method returns
        an opaque identifier that can be passed to the :meth:`close`
        method, to close all open elements up to and including this one.

        Parameters
        ----------
        tag
            Element tag.
        attrib
            Attribute dictionary.  Alternatively, attributes can be given as
            keyword arguments.

        Returns
        -------
        An element identifier.
        N   z<%s =)_XMLWriter__flushr   rG   rF   appendrC   rH   lenitemsr2   rE   )rI   tagattribextrakvs         r   startzXMLWriter.start   s    & 	C 3T''(=T[[)9A)=>?US[!'v''--/ 	0DAq!!$(+A./		0
 4;;!##r   c                     | j                          | j                  | j                  dt        | j                                | j                  dt        |      z         y)z
        Add a comment to the output stream.

        Parameters
        ----------
        comment : str
            Comment text.
        Nz<!-- %s -->
)rV   rC   rH   rX   rF   r&   )rI   comments     r   ra   zXMLWriter.comment   sF     	T''(9T[[)9:;_w'??@r   c                 :    | j                   j                  |       y)z
        Add character data to the output stream.

        Parameters
        ----------
        text : str
            Character data.
        N)rG   rW   )rI   texts     r   rP   zXMLWriter.data   s     	4 r   Nc                    |rK| j                   s
J d|z         t        |      | j                   d   k(  s-J d| j                   d   d|       | j                   sJ d       | j                   j                         }| j                  r| j	                  |       n%| j
                  rd| _        | j                  d       y|r1| j                  | j                  dt        | j                                 | j                  d	|z         y)
a  
        Close the current element (opened by the most recent call to
        :meth:`start`).

        Parameters
        ----------
        tag
            Element tag.  If given, the tag must match the start tag.  If
            omitted, the current element is closed.
        zunbalanced end(%s)zexpected end(z), got zunbalanced end()r   z/>
Nz</%s>
)	rF   r   poprG   rV   rE   rC   rH   rX   )rI   rZ   rO   s      r   endzXMLWriter.end   s     ;;: 4s ::; %R8 D.2kk"osCD8 ;;2 22;kkoo;;LL [[DKLL LL++,=S-=>?Y_%r   c                     t        | j                        |kD  r*| j                          t        | j                        |kD  r)yy)z
        Close open elements, up to (and including) the element identified
        by the given identifier.

        Parameters
        ----------
        id
            Element identifier, as returned by the :meth:`start` method.
        N)rX   rF   rg   )rI   ids     r   closezXMLWriter.close   s1     $++#HHJ $++#r   c                 v     | j                   ||fi | |r| j                  |       | j                  d       y)z
        Add an entire element.  This is the same as calling :meth:`start`,
        :meth:`data`, and :meth:`end` in sequence. The *text* argument can be
        omitted.
        F)rO   N)r_   rP   rg   )rI   rZ   rc   r[   r\   s        r   elementzXMLWriter.element   s5     	

3(%(IIdOr   c                      y)zFlush the output stream.N rI   s    r   rA   zXMLWriter.flush	  s    r   )TNT)__name__
__module____qualname____doc__rK   rV   r_   ra   rP   rg   rj   rl   rA   rn   r   r   r?   r?      sB    & !# $BA	!&8 !%R 	r   r?   c           	      (   g }| D ]{  \  }}|dk(  r
|dk(  s|dk(  s|dk(  r|dk(  s
|dk(  r|dk(  r*|dk(  r t        |t              r|j                         }|j                  |d	d
j	                  d |D              d       } d
j	                  |      S )Nscale)rS   )rS   rS   	translate)r   r   rotate)r   matrix(rT   c              3   2   K   | ]  }t        |        y wr   r4   ).0r7   s     r   	<genexpr>z&_generate_transform.<locals>.<genexpr>  s     >1+A.>   ))
isinstancer   	to_valuesrW   rN   )transform_listpartstypevalues       r   _generate_transformr     s    E% AeGO$%6/;&5F?8#8
5, ?OO%E#((>>>@ 	AA 88E?r   c                      t        | xs g       S r   )r   )r   s    r   generate_transformr     s    ~344r   c                 N    dj                  d | j                         D              S )Nz; c              3   0   K   | ]  \  }}| d |   yw)z: Nrn   )r|   r]   r^   s      r   r}   z _generate_css.<locals>.<genexpr>"  s     <TQs"QC[<s   )rN   rY   r[   s    r   _generate_cssr   !  s    99<V\\^<<<r   c                      t        | xs i       S r   )r   r   s    r   generate_cssr   %  s    2&&r   squarebuttround)
projectingr   r   c                 Z    t        | t              st        d| dt        |        d      y )NInvalid type for z metadata. Expected str, not r;   )r   str	TypeErrorr   )infokeys     r   _check_is_strr   -  s8    dC +C50M:,a) * 	* !r   c           	          t        j                  |       r3| D ]-  }t        |t              rt	        d| dt        |       d       y t	        d| dt        |        d      )Nr   z) metadata. Expected iterable of str, not r;   z0 metadata. Expected str or iterable of str, not )npiterabler   r   r   r   )infosr   r   s      r   _check_is_iterable_of_strr   3  s    	{{5 	GDdC("3C5 988<T
|1!F G G	G
 +C5 1004U}A? @ 	@r   c                       e Zd Zd%dd fdZd Zd Zd Zd Zd Zd	 Z	d
 Z
d Zd Zd Zd Zd&dZd Zd Z	 	 d'dZd&dZ	 d&dZ fdZd Zd Zd Zd Zd&dZd Zd Zd&dZd&dZddd Zd(d!Z d" Z!d# Z"d$ Z# xZ$S ))RendererSVGN)metadatac          
      p   || _         || _        t        |      | _        || _        |t        |dd      }t        |t              sd}|| _        i | _	        t        j                         | _        i | _        i | _        d| _        i | _        d| _        d| _        t&        	| Q          t+               | _        t/        |      }t/        |      }|j1                  t2               | j                  j5                  dd|z  d|z  d|d|d	d
ddi      | _        | j9                  |       | j;                          y )NnamerM   r   Fsvgz%sptz0 0 rT   zhttp://www.w3.org/2000/svgz1.1zxmlns:xlinkzhttp://www.w3.org/1999/xlink)widthheightviewBoxxmlnsversionr[   )r   r   r?   writer	image_dpigetattrr   r   basename_groupd	itertoolscount_image_counter_clipd_markers_path_collection_id_hatchd_has_gouraud_n_gradientssuperrK   dict
_glyph_mapr5   rB   	svgPrologr_   	_start_id_write_metadata_write_default_style)
rI   r   r   	svgwriterr   r   r   
str_height	str_width	__class__s
            r   rK   zRendererSVG.__init__?  s'   
	*"y&"5Hh, 'oo/#$ !&%f-
$U+		"**9$J&#,j9.!#AB + D 	X&!!#r   c                     | j                          | j                          | j                  j                  | j                         | j                  j                          y r   )_write_clips_write_hatchesr   rj   r   rA   ro   s    r   finalizezRendererSVG.finalizee  s@    $..)r   c                 z   |i }dddt         j                   dd|}| j                  d|v r$|d   }t        |d       j	                  d|       |j                  d	d       }|t        |t              r|g}nt        |t        j                  t        j                  f      r|j                         g}nt        j                  |      rg }|D ]  }t        |t              r|j                  |       %t        |t        j                  t        j                  f      r |j                  |j                                ot        d
t        |       d       nt        dt        |       d      dj!                  |      |d	<   nd	|vrt#        j$                  d      }|rPt        j                  j'                  t)        |            }|j+                  t,              j                         |d	<   n/t        j                  j/                         j                         |d	<   d }fd}|j1                  dd       }| ||      }j	                  dd|i       dD ]O  }	|j1                  |	d       }
|
 ||      }t        |
|	       j	                  d|	j3                          |
       Q dD ]  }	|j1                  |	d       }|t        |t              r|g}t5        ||	        ||      }j7                  d|	j3                                 |D ]7  }j7                  d       j	                  d|       j9                  d       9 j9                  d|	j3                                  |j1                  dd       }|t        |t              r|g}t5        |d        ||      }j7                  d       j7                  d       |D ]  }j	                  d|        j9                  d       j9                  d       |j;                  |       |rt=        ddj!                  |      z         y ) Nzimage/svg+xmlz&http://purl.org/dc/dcmitype/StillImagezMatplotlib vz, https://matplotlib.org/)FormatTypeCreatorTitletitle)rc   DatezQInvalid type for Date metadata. Expected iterable of str, date, or datetime, not r;   z[Invalid type for Date metadata. Expected str, date, datetime, or iterable of the same, not /SOURCE_DATE_EPOCH)tzinfoc                     | | S j                  d      } j                  ddddd       j                  d       | S )	Nr   zrdf:RDFz http://purl.org/dc/elements/1.1/zhttp://creativecommons.org/ns#z+http://www.w3.org/1999/02/22-rdf-syntax-ns#)zxmlns:dczxmlns:ccz	xmlns:rdfr   zcc:Work)r_   )midr   s    r   ensure_metadataz4RendererSVG._write_metadata.<locals>.ensure_metadata  sL    
,,z*CLL><J,L 
 LL#Jr   r   zdc:typezrdf:resourcer   )	r   Coverager   Descriptionr   
IdentifierLanguageRelationSourcezdc:)r   Contributor	PublisherRightszcc:Agentzdc:titleKeywordsz
dc:subjectzrdf:Bagzrdf:liz.Unknown metadata key(s) passed to SVG writer: ,)mpl__version__r   r   rl   getr   r   datetimedate	isoformatr   r   rW   r   r   rN   osgetenvutcfromtimestampintr$   r   todayrf   lowerr   r_   rg   rj   
ValueError)rI   r   r   r   datesdr   r   urir   r   agentsagentkeywordskeywordr   s                  @r   r   zRendererSVG._write_metadatak  s    H%<s//HI	

 
 hW%E%)NN7N/ ||FD)$$D8#4#4hmm"DE)*T" 	/A!!S)Q#A(9(98=='IJQ[[]3'##'7)1./ /	/   #448J<q!B C C  #xxHV8# 9901D((99#d)D#'<<s<#;#E#E#G #+#4#4#:#:#<#F#F#H 
	 ll64(?!#&CNN9nc-BNCD 	?C<<T*D%c*dC(SYY[M2>	? E 	,C\\#t,F~&#& %fc2!#&CLL3syy{m,- 'Z(z6

:&' JJSYY[M*+!	,& <<
D1(C($:%h
;!#&CLL&LL## 7xg67JJy!JJ|$?LLM XXh/0 1 1 r   c                     | j                   }t        ddd      }|j                  d       |j                  ddd|z         |j	                  d       y )	Nr   r   )stroke-linejoinstroke-linecapdefsstyleztext/cssz*{%s})r   rc   )r   r   r_   rl   rg   )rI   r   default_styles      r   r   z RendererSVG._write_default_style  sQ    %&$'& ' 	VwZg6MN

6r   c                 N   t         j                  d   }|t        t        j                               }t        j                         }|j                  |j                  d             |j                  t        |      j                  d             ||j                         d d S )Nzsvg.hashsaltutf8
   )
r   rcParamsr   uuiduuid4hashlibsha256updateencode	hexdigest)rI   r   contentsaltms        r   _make_idzRendererSVG._make_id  sy    ||N+<tzz|$DNN	V$%	W$$V,-q{{}Sb122r   c                 p    |t               j                  dd      j                  d| j                        z   S )NrS   re   r   )r   rv   rw   r   )rI   	transforms     r   _make_flip_transformz RendererSVG._make_flip_transform  s-    8:++Ar2<<QLLLr   c                 0   |t        |      }|j                         }|t        |      }|j                         ||f}| j                  j	                  |      }|6| j                  d|      }|j                         ||f|f| j                  |<   |S |\  }}|S )z,
        Create a new hatch pattern
        h)tupleget_hatch_color	get_hatchr   r   r  get_hatch_path)rI   gcrgbFaceedgedictkeyoid_s          r   
_get_hatchzRendererSVG._get_hatch  s     GnG!!#;D<<>7D1llw';--W-C&(&7&7&97D%I3$ODLL! 
 FAs
r   c                 >   t        | j                        sy d}| j                  }|j                  d       | j                  j	                         D ]9  \  \  }}}}|j                  d|dddt        |      t        |             | j                  |t               j                  |      j                  dd      j                  d	|      d
      }|d}nt        |      }|j                  dddt        |dz         t        |dz         |       t        |      t        |      t        t        j                  d         ddd}	|d   dk  rt        |d         |	d<   |j                  d|t        |	             |j                  d       < |j                  d       y )NH   r   patternuserSpaceOnUser:   )ri   patternUnitsr7   yr   r         ?      r   FsimplifynonerectrS   )r7   r  r   r   fillzhatch.linewidthr   miter)r$  strokestroke-widthr   r      stroke-opacitypath)r   r   )rX   r   r   r_   valuesr   _convert_pathr   rv   rw   r   rl   r   r   r   rg   )
rI   
HATCH_SIZEr   r*  facer&  r  	path_datar$  hatch_styles
             r   r   zRendererSVG._write_hatches  s   4<< 
V)-)<)<)> #	"% T4#LL-C
O:  ( **
z"55d#3IIa4L	 +  I
 |t}NNC
1$5:a<(	   $FO%fo$'5F(G$H&,'.K ay1}03F1I,-NN#K0  
 JJy!G#	"H 	

6r   c                    i }|j                         }|j                         Dd| j                  ||      z  |d<   |zt        |      dk(  rl|d   dk7  rd|sbt	        |d         |d<   nP|d|d<   nHt        |dd       d	k7  rt        |      |d<   t        |      dk(  r|d   dk7  r|st	        |d         |d<   |r/|j                         dk7  rt	        |j                               |d
<   |j                         \  }}|2dj                  d |D              |d<   t	        t        |            |d<   |j                         }|r|j                         }t        |      |d<   |s|d   dk7  rt	        |d         |d<   |dk7  rt	        |      |d<   |j                         dk7  r|j                         |d<   |j                         dk7  rt        |j                            |d<   |S )z=Generate a style string from the GraphicsContext and rgbFace.Nzurl(#%s)r$     r(  r  fill-opacityr"  )r   r   r   opacityr   c              3   2   K   | ]  }t        |        y wr   r4   )r|   vals     r   r}   z.RendererSVG._get_style_dict.<locals>.<genexpr>S  s      26*- %26r~   zstroke-dasharrayzstroke-dashoffsetr&  r)  r'  r   r   r   r   )get_forced_alphar  r  rX   r5   r  r   	get_alpha
get_dashesrN   floatget_linewidthget_rgbget_joinstyleget_capstyle_capstyle_d)	rI   r  r  r[   forced_alphaoffsetseq	linewidthrgbs	            r   _get_style_dictzRendererSVG._get_style_dict9  s   **,<<>%'$//"g*FFF6N#G(9gajC>O()9'!*)E~&!'v!%2%,W%5F6NLA%'!**; ,-=gaj-IF>*BLLNc1 0 @F9mmo?), 261426 *6F%&*:5=*IF&'$$&	**,C&s|F8CFcM+;CF+C'(C)9))D~&!W,,.,<,<,>() F*+6r7H+I'(r   c                 8    t        | j                  ||            S r   )r   rE  )rI   r  r  s      r   
_get_stylezRendererSVG._get_stylef  s    T11"g>??r   c                    |j                         }|j                         \  }}|(| j                  |      }t        |      t	        |      f}n.|*|j
                  \  }}}}	| j                  ||	z   z
  }||||	f}ni S | j                  j                  |      }
|
:| j                  d|      }|||f|f| j                  |<   n||f| j                  |<   n|
\  }
}dd| diS )Npz	clip-pathzurl(#r   )
get_clip_rectangleget_clip_pathr
  ri   r   boundsr   r   r   r  )rI   r  cliprectclippathclippath_transr  r7   r  wr  clipr  s               r   _get_clip_attrszRendererSVG._get_clip_attrsi  s    ((*#%#3#3#5 .!66~FN(|S%89G!!JAq!QQqS!A!QlGI{{w'<--W-C#)1>(BC'HG$(/~G$ID#uSE^,,r   c           
         t        | j                        sy | j                  }|j                  d       | j                  j	                         D ]  \  }}|j                  d|       t        |      dk(  r-|\  }}| j                  ||d      }|j                  d|       nA|\  }}}	}
|j                  d	t        |      t        |      t        |	      t        |
      
       |j                  d        |j                  d       y )Nr   clipPathri      Fr   r*  r   r#  r7   r  r   r   )	rX   r   r   r_   r+  r,  rl   r5   rg   )rI   r   rQ  r  rN  rO  r/  r7   r  rP  r  s              r   r   zRendererSVG._write_clips  s    4;;V++- 	#ID#LLL,4yA~+/(. ..nu / >	v3!
1a&q)&q)*1-+A.  0 JJz"	#  	

6r   c                     |r| j                   j                  d|       y | j                  j                  |d      dz   | j                  |<   | j                   j                  dd|| j                  |   fz         y )NgrU  r   rS   z%s_%d)r   r_   r   r   )rI   r   gids      r   
open_groupzRendererSVG.open_group  sh    KKcc*"ll..q!4q8DLLOKKcgDLLO0D&DEr   c                 :    | j                   j                  d       y )NrZ  )r   rg   )rI   r   s     r   close_groupzRendererSVG.close_group  s    r   c                 *    t         j                  d    S )Nzimage.composite_image)r   r   ro   s    r   option_image_nocompositez$RendererSVG.option_image_nocomposite  s    << 7888r   c           
          |rdd| j                   | j                  f}nd }t        j                  |||||dg dd      j	                  d      S )N           )   M   L   Q   C   zFascii)r   r   r   convert_to_stringdecode)rI   r*  r	  rQ  r!  sketchs         r   r,  zRendererSVG._convert_path  sO    djj$++6DD&&)T8VQ*E3396'?	Cr   c           	         | j                  |      }|d u xr |j                         d u }|j                  xr |}| j                  |||||j	                               }|j                         ,| j                  j                  dd|j                         i        | j                  j                  dd|i| j                  |      d| j                  ||      i |j                         | j                  j                  d       y y )N)rQ  r!  rl  a
xlink:hrefr   r   )r*  )r
  r  should_simplifyr,  get_sketch_paramsget_urlr   r_   rl   rR  rG  rg   )	rI   r  r*  r	  r  trans_and_fliprQ  r!  r/  s	            r   	draw_pathzRendererSVG.draw_path  s    229=4?B$5$5$74$?''0D&&.th'') ' +	 ::<#KKcL"**,#?@ 	@i 	@43G3G3K 	@"&//"g">	@::<#KKOOC  $r   c           	         t        |j                        sy | j                  }| j                  ||t	               j                  dd      z   d      }| j                  ||      }	|t        |	      f}
| j                  j                  |
      }t        |	j                         D ci c]  \  }}|j                  d      r|| c}}      }	|X| j                  d|
      }|j                  d       |j                  d|||		       |j                  d       || j                  |
<    |j                  di | j!                  |       | j#                  |      }dd|z  i}dd| j$                  dz  | j&                  dz  f}|j)                  ||d      D ]]  \  }}t        |      s|dd  \  }}t+        |      |d<   t+        |      |d<   | j-                  ||      |d<   |j                  d|       _ |j                  d
       y c c}}w )Nr  r  Fr   r&  r  r   r*  )ri   r   r   rZ  ro  #%sr   r  )rQ  r!  r7   r  r   user   rZ  )rX   verticesr   r,  r   rv   rE  r   r   r   rY   
startswithr  r_   rl   rg   rR  r
  r   r   iter_segmentsr5   rG  )rI   r  marker_pathmarker_transr*  transr  r   r/  r   r  r  r]   r^   rs  r[   rQ  rz  coder7   r  s                        r   draw_markerszRendererSVG.draw_markers  s    4==!&&8:++C66 ' 	 $$R1mE23mm( 91!"h!7  !!t 9 : ;--W-CLL NN6cYeNDJJv%(DMM'"5D00452259,1djjmT[[^4"00TE 1 ; 	5NHd8}}1.q1s.q1s"&//"g">wuV4	5 	

3-9s   $H
c                    t        |      dkD  rt        |d   j                        nd}| j                  |||||      }|d|z  z   dz   |dz   |z  k  }|st         |   |||||||||	|
|||      S | j
                  }g }|j                  d       t        | j                  |||            D ]  \  }\  }}t        |j                               j                  dd      }| j                  ||d	      }d
| j                  || j                  d|      fz  }|j                  d||       |j!                  |        |j#                  d       | j%                  |||||||	|
|||      D ]  \  }}}}}|j'                         }||j                  dd|i       | j)                  |      }|r |j                  di | d|z  t+        |      t+        | j,                  |z
        | j/                  ||      d}|j                  d|       |r|j#                  d       ||j#                  d        | xj                  dz  c_        y )Nr   	   r(     r   r  r  Fr   z	C%x_%x_%srM   r*  )ri   r   rn  ro  r   rZ  rv  )ro  r7   r  r   rx  rS   ry  )rX   rz  _iter_collection_uses_per_pathr   draw_path_collectionr   r_   	enumerate_iter_collection_raw_pathsr   
get_matrixrv   r,  r   r  rl   rW   rg   _iter_collectionrr  rR  r5   r   rG  )!rI   r  master_transformpathsall_transformsoffsetsoffset_trans
facecolors
edgecolors
linewidths
linestylesantialiasedsurlsoffset_positionlen_pathuses_per_pathshould_do_optimizationr   
path_codesir*  r	  r   r  xoyopath_idgc0r  url
clip_attrsr[   r   s!                                   r   r  z RendererSVG.draw_path_collection  sy    .1Z!^3uQx(();;>7J
D q=((1,1/MM 	%7/$e^z:Jd	! ! 
V$-d.M.M %/9 %: 	# A i !5!5!78>>sDII""4U"CA((!T]]2q-A!C CCNN6cQN/c"	# 	

6-1-B-BJJ
JdO.5 	 )BGS' ++-CS,)<=--c2J/J/#go%b)%dkkB&67g6	F NN5N0

3

3)	 , 	  A% r   c                    | j                   }| j                  s~d| _        |j                  dd       |j                  dddidd	d
d
       |j	                  d       |j                  dd       |j                  dddid       |j	                  d       t        j                  |d      }|d   dk(  ry | j                  |      }|j                  |      }|j                  d       t        d      D ]/  }	||	   \  }
}||	dz   dz     \  }}||	dz   dz     \  }}||	   }||k(  r|}|}n?||k(  r|
}|}n5||z
  ||z
  z  }|||z  z
  }d|z   }|||
z  z
  }| |z   ||z
  z  }||z  |z   }|j                  dd| j                  |	fz  dt        |
      t        |      t        |      t        |             |j                  dd
t        t        |      t        |d         d              |j                  dd!t        t        |      d!d              |j	                  d       2 |j	                  d       d"t        
      z   d#z   t              z   }|d$t              z   d#z   t              z   z  }|d%t              z   d#z   t              z   d&z   z  }|j                  d'|t        |      d
d(d)*       |j                  d+d,d!d(d-d.*       |j                  d'|d/| j                  z  d(d0*       |j                  d'|d1| j                  z  d2d(d3*       |j                  d'|d4| j                  z  d2d(d3*       |j	                  d+       | xj                  dz  c_
        y )5NTfiltercolorAddrU  feCompositeinSourceGraphicBackgroundImage
arithmetic1)r[   in2operatork2k3colorMatfeColorMatrixr   ry   z61 0 0 0 0 
0 1 0 0 0 
0 0 1 0 0 
1 1 1 1 0 
0 0 0 0 1 )r[   r+  r   )axisre   r   r(  rS   rV  r  linearGradientzGR%x_%dr  )ri   gradientUnitsx1y1x2y2stop)z
stop-colorzstop-opacity)rA  r   r:   zM r   z L rT   z Zr*  
crispEdges)r   r$  r3  shape-renderingr   rZ  r"  zurl(#colorMat))r&  r'  r  r  zurl(#GR%x_0))r   r$  r  zurl(#GR%x_1)zurl(#colorAdd))r   r$  r  r  zurl(#GR%x_2))r   r   r_   rl   rg   r   averager
  r	  ranger   r5   r   r   )rI   r  pointscolorsr  r   	avg_colorrs  tpointsr  r  r  r  r  x3y3
rgba_colorxbybm1b1m2b2dpaths                           r   draw_gouraud_trianglez!RendererSVG.draw_gouraud_triangle"  s       $DLL   NNo.%%3    JJx LL   NN)3  4
 JJx JJvA.	R=A2259 **62Vq &	)AQZFBa!eq[)FBa!eq[)FBJRxr2g"r'*27^Rx[27^cBh27+"Wr\LL  1 1155.#B',<R,@#B',<R,@  B NN#"))"4$4Z^$D%F G  H NN#7:3F47%9 :  ; JJ'(M&	)P 	

6 '++C/2B22FF)"--36Fr6JJJ'++c14DR4HH4OO#I.$''35 	 	6 	"((++7"24 	 	5 	*T->->>'35 	 	6 	*T->->>.'35 	 	6 	*T->->>.'35 	 	6 	

3Qr   c                      | j                   j                  di | j                  |       |j                         }t	        ||      D ]  \  }}| j                  ||||        | j                   j                  d       y )NrZ  ry  )r   r_   rR  frozenzipr  rg   )rI   r  triangles_arraycolors_arrayr	  tricols          r   draw_gouraud_trianglesz"RendererSVG.draw_gouraud_triangles  sr    :!5!5b!9:$$&	O\: 	@HC&&r3Y?	@r   c                      yrp   rn   ro   s    r   option_scale_imagezRendererSVG.option_scale_image      r   c                      | j                   dz  S )N      R@)r   ro   s    r   get_image_magnificationz#RendererSVG.get_image_magnification  s    ~~$$r   c           
         |j                   d d \  }}|dk(  s|dk(  ry | j                  |      }|r | j                  j                  di | |j	                         }	|	| j                  j                  dd|	i       i }
|j                         }t        j                  d   rt               }t        j                  |      j                  |d	       |xs  | j                  d
|j                               }dt        j                  |j                               j!                  d      z   |
d<   n| j"                  t%        d      dj'                  | j"                  t)        | j*                              }t,        j/                  d|       t        j                  |      j                  |       |xs d| j                  d
|      z   }||
d<   ||
d<   |d|z  | j0                  z  }d|z  | j0                  z  }| j                  j3                  d
t5        ddd| ffg      t7        |      t7        | j8                  |z
  |z
         t7        |      t7        |      |
       n|j;                         }|dk7  rt7        |      |
d<   t=               j?                  d|z  d|z        |z   t=               jA                  ||      j?                  dd      jA                  d| j8                        z   }t5        d|jC                         fg      |
d<   d|
d<   | j                  j3                  d
t7        |      t7        |      |
       |	| j                  jE                  d       |r| j                  jE                  d       y y ) NrV  r   rZ  rn  ro  r   zsvg.image_inlinepng)r<   imagezdata:image/png;base64,
ri  zLCannot save image data to filesystem when writing SVG to an in-memory bufferz{}.image{}.pngz$Writing image file for inclusion: %sIm_ri   r  )rv   )rS   re   rw   )r	  r7   r  r   r   r[   r  r4  r  rb  ry   r	  z5image-rendering:crisp-edges;image-rendering:pixelatedr   )r   r   r[   ry  )#shaperR  r   r_   rr  get_gidr   r   r   r   	fromarraysaver  getvaluebase64	b64encoderk  r   r   r<   nextr   _logr   r   rl   r   r5   r   r8  r   rv   rw   r  rg   )rI   r  r7   r  imr	  r  rP  r  r  r[   r  buffilenamealphaflippeds                   r   
draw_imagezRendererSVG.draw_image  sF    xx|16Q!V))"-
 DKK0Z0jjl?KKc<*=>jjl<<*+)COOB$$S$7?w?C*  077@A <  }}$  "F G G'..tD$7$78:HII<hGOOB$$X.Aw!AAC#+F< tq4>>)Aq4>>)AKK-&q1"g(>/@ A"1%"T[[1_q%8#9:&q)2B12E    LLNE|$4U$;y! 
  q#'2
1asD!3,-  #6GNN,-.#0F;, 7O KK&q)2B12E   
 ?KKOOC KKOOC  r   c           	      r   | j                   }|r|j                  d       |j                         D ]X  \  }\  }}| j                  |      }| j	                  t        |dz  |      d      }|j                  d||t        dg             Z |j                  d       | j                  j                  |       yy)	zn
        Emit definitions for not-yet-defined glyphs, and record them as having
        been defined.
        r   @   Fr   r*  )rv   )g      ?)ri   r   r	  N)r   r_   rY   _adjust_char_idr,  r   rl   r   rg   r   r  )rI   glyph_map_newr   char_idrz  codesr/  s          r   _update_glyph_map_defsz"RendererSVG._update_glyph_map_defs  s    
 LL .;.A.A.C K**(E..w7 ..B. / @	w)13G2HI  KK JJvOO""=1 r   c                 &    |j                  dd      S )Nz%20r  r#   )rI   r  s     r   r  zRendererSVG._adjust_char_id  s    uc**r   c	           	         | j                   }	|	j                  |       | j                  }
| j                  }t	        |j                               }|j                         }i }|dk7  r||d<   |j                         r|j                         n|j                         d   }|dk7  rt        |      |d<   ||j                  z  }t        |      t        d||ffd| ffd|| ffg      d	}|	j                  d
|       |s|j                  |      }|j                  |||
d      }|\  }}}| j!                  |       |D ]G  \  }}}}dd|z  i}|dk7  rt        |      |d<   |dk7  rt        |      |d<   |	j#                  d|       I n|dk(  r|j%                  |||
d      }n|j'                  |||
d      }|\  }}}| j!                  |       |D ]C  \  }}}}| j)                  |      }|	j#                  dt        d||ffd|ffg      dd|z  i       E |D ]7  \  }}t+        ||      }| j-                  |d      }|	j#                  d|       9 |	j/                  d
       y)a]  
        Draw the text by converting them to paths using the textpath module.

        Parameters
        ----------
        s : str
            text to be converted
        prop : `matplotlib.font_manager.FontProperties`
            font property
        ismath : bool
            If True, use mathtext parser. If "TeX", use *usetex* mode.
        #000000r$  r(  rS   r4  rw   rx   rv   r   r	  rZ  r   T)	glyph_mapreturn_new_glyphs_onlyro  rv  rb  r7   r  rx  TeX)r	  r[   Fr   r*  rW  N)r   ra   r   
_text2pathr   r<  get_size_in_pointsr7  r8  r5   
FONT_SCALEr   r   r_   	_get_fontget_glyphs_with_fontr  rl   get_glyphs_texget_glyphs_mathtextr  r   r,  rg   ) rI   r  r7   r  r   propangleismathmtextr   r  	text2pathcolorfontsizer   r  
font_scaler[   font_glyphs
glyph_infor  rectsglyph_id	xposition	ypositionrv   r  vertsr  r*  r/  s                                    r   _draw_text_as_pathzRendererSVG._draw_text_as_path  s    qOO	OO	

%**,I!E&M"$"5"5"7RZZ\!_A:/6E)	 4 44
"5),q!f%UF9%:
{34.6 7
 	S(&&t,D44a9T 5 KG/6,Ju''69C 55)Y&(89#"29"=F3K#"29"=F3KuV45 #22!y 3 O $77!y 8 O/6,Ju''68B <4Iu..w71$y)&<= 5(+3  )%'/:  << !& 4uE5) ..te.D	v34
 	

3r   c	                 *  ' | j                   }	t        |j                               }
i }|
dk7  r|
|d<   |j                         r|j	                         n|j                         d   }|dk7  rt        |      |d<   |si }g }|j                         dk7  r|j                  |j                                |j                         dk7  r|j                  |j                                t        j                  |j                            }|dk7  r|j                  |        d ''fd	}|j                  t        |j                                d
dj                  t        j!                   ||                  g       dj                  |      |d<   |j#                         dk7  r|j#                         |d<   t%        |      |d<   |r<|dk(  s|j'                         dk(  r#|j)                         }|j+                  |j-                               \  }}| j.                  |z
  }t1        j2                  |      }t1        j4                  t1        j6                  |      t1        j8                  |      g      }t1        j:                  |||z
  ||z
  g      }|||d   z  z   }|||d   z  z   }dddd}||j=                            |d<   t        |      |d<   t        |      |d<   t%        |      |d<   t?        d| ||ffg      |d<   nt?        d||ffd| ffg      |d<   |	jA                  d||       y |	jC                  |       | jD                  jF                  jI                  |d|      \  }}}}}|	jK                  dt%        |      t?        d||ffd| ffg              |	jK                  d       i }|D ]1  \  }}} }!}"t        jL                  |      }#g }|#jN                  dk7  r|j                  |#jN                         |#jP                  dk7  r|j                  |#jP                         |#jR                  dk7  r|j                  |#jR                          |j                  t        |       d
|#jT                  g       ddj                  |      i}|#jV                  dk7  r|#jV                  |d<   t%        |      }| d!k(  rd"} |jY                  |g       j                  |!|" | f       4 |j[                         D ]  \  }}$|$j]                          t_        |$D %ch c]  \  }}}%|
 c}%}}      dk(  rta        |$d   d         }&ndj                  d# |$D              }&|dj                  d$ |$D              |&d%}|	jA                  d&d'j                  d( |$D              |        |	jc                  d       |D ]E  \  }}}}|	jA                  d)t        |      t        | dz
        t        |      t        |      *       G |	jc                  d       y c c}%}}w )+Nr  r$  r(  rS   r4  normali  c              3   t  K   ddd}| t         j                  v r|j                  | |       } t         j                  j	                  |       D cg c]  }|j                  ||       }}|j                  |        |D ]&  }|t         j                  v r| t        |       ( y t        |        y c c}w w)Nz
sans-serif)sansz
sans serif)fmfont_family_aliasesr   FontManager_expand_aliasesrW   repr)fnnormalize_namesr  aliasesrn  s        r   _format_font_namez9RendererSVG._draw_text_as_text.<locals>._format_font_name  s     (".# /// ),,R4B
 66r:67++Aq1G  NN2&$ * 6 66"#G #'q'M* r(N#s   AB8B3&AB8c              3   \   K   | j                         D ]  } |      E d {     y 7 wr   )
get_family)r  fr  s     r   _get_all_namesz6RendererSVG._draw_text_as_text.<locals>._get_all_names  s.     * 4A033343s   ,*,pxz, rT   r
  zfont-stretchr   r   anchorr_   rg   middle)leftrightcenterztext-anchorr7   r  rx   r	  rw   rc   r   r  rZ  r         c              3   8   K   | ]  }t        |d            yw)rS   N)r   r|   cs     r   r}   z1RendererSVG._draw_text_as_text.<locals>.<genexpr>  s     !;#ad)!;   c              3   8   K   | ]  }t        |d            yw)r   Nr4   r-  s     r   r}   z1RendererSVG._draw_text_as_text.<locals>.<genexpr>  s     !HQ"21Q4"8!Hr/  )r   r7   r  tspanrM   c              3   8   K   | ]  }t        |d            yw)rV  N)chrr-  s     r   r}   z1RendererSVG._draw_text_as_text.<locals>.<genexpr>  s     5!C!I5r/  r#  rX  )2r   r   r<  r7  r8  r5   	get_stylerW   get_variantr  weight_dict
get_weightextendget_sizerN   r   fromkeysget_stretchr   get_rotation_modeget_transformr	  get_unitless_positionr   r   deg2radarraysincosdotget_har   rl   ra   r  mathtext_parserparser_   ttfFontPropertyr   variantweightr   stretch
setdefaultrY   sortrX   r   rg   )(rI   r  r7   r  r   r  r  r  r  r   r  r   r  r[   
font_partsrI  r#  r	  axay	angle_raddir_vertv_offsetha_mpl_to_svgr   r   descentglyphsr  spansr
  r  thetextnew_xnew_yentrycharstysr  s(                                          @r   _draw_text_as_textzRendererSVG._draw_text_as_textk  s   

%I!E&M"$"5"5"7RZZ\!_A:/6E)FJ~~8+!!$.."23!X-!!$"2"2"45^^DOO$56F}!!VH.#B4 #DMMO45R8		$--t(<=> 
  HHZ0E&M!X-(,(8(8(:n%+E2F7O%1*(?(?(AX(M
 "//1	",,U-H-H-JKB[[2%
 JJu-	88RVVI%6y8I$JK66(a"fB,@A(Xa[00(Xa[00)05+3!5'4U\\^'Dm$.r2s.r2s"/"6w&9B/0;2 '3{# ': 1a&)y);+ ',{# NN61VN4 NN1 //55aTB 2E67FE
 LL,U3#6)Aq62&%	284 $5   LL  E9? M5h**40
;;(*%%ekk2==H,%%emm4<<3&%%8!!'12"5zzn#   *!56==H,,1MME.)%e,b="G  +22EE673KL'M* !& #u

//gaA/0A5U1Xa[)B!;U!;;B #!H%!HH GG5u55!  ##& JJv', #1eV&q)&r!t,*51+F3   JJsO7 0s   X)r  c          	      4    | j                  ||||||d       y )Nr  )r  )r  )rI   r  r7   r  r   r  r  r  s           r   draw_texzRendererSVG.draw_tex  s    Aq!T5Gr   c	           
         | j                  |      }	|	r | j                  j                  di |	 |j                         ,| j                  j                  dd|j                         i       t        j
                  d   dk(  r| j                  ||||||||       n| j                  ||||||||       |j                         | j                  j                  d       |	r| j                  j                  d       y y )NrZ  rn  ro  zsvg.fonttyper*  ry  )	rR  r   r_   rr  r   r   r  r^  rg   )
rI   r  r7   r  r   r  r  r  r  r  s
             r   	draw_textzRendererSVG.draw_text!  s     ))"-
 DKK0Z0::<#KKcL"**,#?@<<'61##B1aufeL##B1aufeL::<#KKOOC KKOOC  r   c                      yrp   rn   ro   s    r   flipyzRendererSVG.flipy8  r  r   c                 2    | j                   | j                  fS r   )r   r   ro   s    r   get_canvas_width_heightz#RendererSVG.get_canvas_width_height<  s    zz4;;&&r   c                 <    | j                   j                  |||      S r   )r  get_text_width_height_descent)rI   r   r  r  s       r   rh  z)RendererSVG.get_text_width_height_descent@  s    <<QfMMr   )Nr  r   )NNNN)FN)%rq   rr   rs   rK   r   r   r   r  r
  r  r   rE  rG  rR  r   r\  r^  r`  r,  rt  r  r  r  r  r  r  r  r  r  r  r^  r`  rb  rd  rf  rh  __classcell__r   s   @r   r   r   >  s    $$!$$Ly1v3M$*X+Z@-..F9 GK!C!" GK%N8&tBH%M!^2&+Obpd ;? H!.'Nr   r   c                        e Zd ZdddZdZ ej                  dd      dddd       Z ej                  dd      d	        Zd
 Z	 fdZ
 xZS )FigureCanvasSVGzScalable Vector Graphics)r   svgzr  z3.5argsN)bbox_inches_restorer   c                   t        j                  |dd      5 }t        j                  |      s t        j                  d      |      }| j
                  j                  }d| j
                  _        | j
                  j                         \  }}|dz  |dz  }
}	t        | j
                  |||t        |	|
|||      |      }| j
                  j                  |       |j                          ddd       y# 1 sw Y   yxY w)a  
        Parameters
        ----------
        filename : str or path-like or file-like
            Output target; if a string, a file will be opened for writing.

        metadata : dict[str, Any], optional
            Metadata in the SVG file defined as key-value pairs of strings,
            datetimes, or lists of strings, e.g., ``{'Creator': 'My software',
            'Contributor': ['Me', 'My Friend'], 'Title': 'Awesome'}``.

            The standard keys and their value types are:

            * *str*: ``'Coverage'``, ``'Description'``, ``'Format'``,
              ``'Identifier'``, ``'Language'``, ``'Relation'``, ``'Source'``,
              ``'Title'``, and ``'Type'``.
            * *str* or *list of str*: ``'Contributor'``, ``'Creator'``,
              ``'Keywords'``, ``'Publisher'``, and ``'Rights'``.
            * *str*, *date*, *datetime*, or *tuple* of same: ``'Date'``. If a
              non-*str*, then it will be formatted as ISO 8601.

            Values have been predefined for ``'Creator'``, ``'Date'``,
            ``'Format'``, and ``'Type'``. They can be removed by setting them
            to `None`.

            Information is encoded as `Dublin Core Metadata`__.

            .. _DC: https://www.dublincore.org/specifications/dublin-core/

            __ DC_
        rP  zutf-8)encodingr  )r   r   )ro  N)r   open_file_cmfile_requires_unicodecodecs	getwriterfiguredpiget_size_inchesr   r   drawr   )rI   r  ro  r   rn  fhrw  r   r   rP  r  renderers               r   	print_svgzFigureCanvasSVG.print_svgK  s    D #@ 	 B..r2.V%%g.r2++//C DKKO KK779ME62:v{qA(UFCAq"hG$79H KKX&	  	  	 s   CC55C>c                     t        j                  |d      5 }t        j                  d|      5 } | j                  |fi |cd d d        cd d d        S # 1 sw Y   nxY wd d d        y # 1 sw Y   y xY w)NwbrP  )modefileobj)r   rr  gzipGzipFiler|  )rI   r  rn  kwargsrz  
gzipwriters         r   
print_svgzzFigureCanvasSVG.print_svgz{  sg    $/ 	8233	87A!4>>*77	8 	8 	8 	8 	8 	8 	8s"   A*A	A*A	A**A3c                      y)Nr   rn   ro   s    r   get_default_filetypez$FigureCanvasSVG.get_default_filetype  s    r   c                 T    | j                   j                          t        |          S r   )rv  draw_without_renderingr   ry  )rI   r   s    r   ry  zFigureCanvasSVG.draw  s    **,w|~r   )rq   rr   rs   	filetypes	fixed_dpir   delete_parameterr|  r  r  ry  ri  rj  s   @r   rl  rl  E  sq    235I IT5&)=A-  *- ^ T5&)8 *8
 r   rl  z<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
c                   (    e Zd Zej                  ZeZy)_BackendSVGN)rq   rr   rs   r   r   backend_versionrl  FigureCanvasrn   r   r   r  r    s    ooO"Lr   r  r   )Dr  rt  r   r  r   ior   r   loggingr   rer   numpyr   PILr   
matplotlibr   r   r   r   r  matplotlib.backend_basesr   r	   r
   r   !matplotlib.backends.backend_mixedr   matplotlib.colorsr   matplotlib.datesr   matplotlib.pathr   r   matplotlib.transformsr   r   	getLoggerrq   r  
deprecatedr   r   compiler*   r(   r&   r-   r,   r2   r8   r5   r?   r   r   r   r   r?  r   r   r   rl  FigureManagerSVGr   exportr  rn   r   r   <module>r     s           	 	     6 6B B ? %      8 w"R $FG H !bjj+  $HI" J",
 $GH I+ $IJ K5L L^ 5 5= ' ' &vH*@DN, DNN A& AH % 	 
#( # #r   