
     h/J                     x   d Z ddlmZmZmZ ddlmZ ddlmZ	m
Z
 ddlmZ ddlmZ ddlmZmZ ddlmZ dd	lmZ dd
lZddlmZmZmZ ddlmZ i ddddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1dd2d3d4	Zd;d5Zd6 Zd7 Z 	 	 	 	 	 	 	 d<d8Z!	 	 	 	 	 	 	 d=d9Z"	 	 	 	 	 	 	 d>d:Z#y
)?zhThis submodule: basic tools for creating svg files from path data.

See also the document.py submodule.
    )divisionabsolute_importprint_function)ceil)pathmakedirs)
gettempdir)parse)Drawingtext)time)warnN   )PathLineis_path_segment)open_in_browseraaquabblueccyanddarkbluee fggreenhijkblackllimemmagentanbrownoorangeppinkq	turquoiseredsalmontanpurplevioletwhiteyellowazure)	rstuvwxyzc                 v    | D cg c]  }t         |    }}|rt        |      D ]  \  }}|r	|||<    |S c c}w N)
color_dict	enumerate)r;   default_colorch
color_listidxr   s         r/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/svgpathtools/paths2svg.pystr2colorlistrL   2   sM    +,-R*R.-J-
+ 	0FC"/
3	0  .s   6c                 B    t        | t              xr t        |       dk(  S )N   )
isinstancetuplelen)r   s    rK   is3tuplerR   ;   s    a/CFaK/    c                 x   g }| D ]  }t        |      st        |t              r |j                  |j	                                >t        |t
              r>|j                  |j                  |j                  |j                  |j                  f       	 t        |      }|j                  |j                  |j                  |j                  |j                  f        t        t        |       \  }}}}t        |      }t        |      }	t        |      }
t        |      }||	|
|fS # t        $ r t        d      w xY w)zreturns minimal upright bounding box.

    Args:
        paths_n_stuff: iterable of Paths, Bezier path segments, and
            points (given as complex numbers).

    Returns:
        extrema of bounding box, (xmin, xmax, ymin, ymax)

    z^paths_n_stuff can only contains Path, CubicBezier, QuadraticBezier, Line, and complex objects.)r   rO   r   appendbboxcomplexrealimag
ValueError	TypeErrorlistzipminmax)paths_n_stuffbbsthingcomplexthingxminsxmaxsyminsymaxsxminxmaxyminymaxs               rK   big_bounding_boxrl   ?   s    C 85!Zt%<JJuzz|$w'JJ

EJJ

EJJGH8&u~

L--|/@/@(--|/@/@B C8 "&c3iE5%u:Du:Du:Du:DtT!!  8 !7 8 88s   AD$$D9c                 0   d}d}d}d}d}|$|dn|}t        j                  t               d      }t        j                  t        j                  |            }t        j
                  |      st        |       |rrt        j                  |      \  }}t        t                     j                  d	d
      }t        j                  |      d   dz   |z   |z   }t        j                  ||      }t        | t              st        |       r| g} | r|s|gt        |       z  }nwt        |      t        |       k(  sJ t        |t              rt!        ||      }n@t        |t"              r0t%        |      D ]"  \  }} t'        |       sdt        |       z   ||<   $ |r|s|gt        |      z  }nwt        |      t        |      k(  sJ t        |t              rt!        ||      }n@t        |t"              r0t%        |      D ]"  \  }} t'        |       sdt        |       z   ||<   $ | s|sJ g }!|r.t        |t              sd|z  }||j                  d      dd }n|r6t)        t+        t        |            }d }"dt)        t+        |"|            z  }n| r|!| z  }!|r|!|z  }!|r|!|z  }!t-        |!      \  }#}$}%}&|$|#z
  }'|&|%z
  }(|'dk(  rd}'|(dk(  rd}(| rH|s!t/        |'|(      |z  })|)gt        |       z  }|)}*n't        |       t        |      k(  sJ t/        |      }*nd}*|rN|s$t/        |'|(      |z  }+|+gt        |      z  }d|+z  },n*t        |      t        |      k(  sJ dt/        |      z  },nd},t/        |*|,      }-|#|	|'z  |-dz  z   z  }#|%|	|(z  |-dz  z   z  }%|'d|	z  |'z  |-z   z  }'|(d|	z  |(z  |-z   z  }(|#d|%d|'d|(}|
%dj1                  |'|      }.dj1                  |(|      }/nn|'|(kD  r5t        |
      |z   }.t        t3        t5        |
|(z  |'z                    |z   }/n4t        t3        t5        |
|'z  |(z                    |z   }.t        |
      |z   }/|.|/f}|L|j7                  d|d         |j7                  d|d         f}|j7                  d|      }0t9        d&|||0d|}1nt9        ||||      }1| rt%        |       D ]  \  }2}3t        |3t              r|3j;                         }4n't        |3      rt        |3      j;                         }4n|3}4|rgd|4i}5||2   D ]9  }6||2   |6   }7|6dk7  s	  |1j<                  |4fi |6|7i |5j?                  |6|7i       ; |1jE                   |1j<                  d&i |5       |1jE                  |1j=                  |4||2   t        ||2         d              |r`t%        |D 9cg c]  }9|9jF                  |9jH                  f c}9      D ].  \  }:};|1jE                  |1jK                  |;||:   ||:                0 |rt        |t              s9t        |t"              r't        |t"              rt        |      t        |      k(  sJ t        |t              rA|g}|s|g}|stM        #|	'z  z   %|	(z  z         }<tO        |<|<dz         j;                         g}nJ|r9t        |t"              rt        |      t        |      k(  s!J |gt        |      z  }n|gt        |      z  }t%        |      D ]  \  }}=||   }3t        |3t              r|3j;                         }4n't        |3      rt        |3      j;                         }4n|3}4d t        |      z   }>|1jP                  jE                  |1j=                  |4|>!             |1jE                  |1jS                  d
||   "            }?|?jE                  tU        jV                  d#|>z   |=              |r|1S |1jY                          t[        |      j]                         }@t_        |d$      5 }A|Aja                  @       ddd       |r	 tc        |       yy# t@        $ r}8tC        t        |8             Y d}8~8Id}8~8ww xY wc c}9w # 1 sw Y   IxY w#  te        d%       te        |       Y yxY w)'a-  Creates (and optionally displays) an SVG file.

    REQUIRED INPUTS:
        :param paths - a list of paths

    OPTIONAL INPUT:
        :param colors - specifies the path stroke color.  By default all paths
        will be black (#000000).  This paramater can be input in a few ways
        1) a list of strings that will be input into the path elements stroke
            attribute (so anything that is understood by the svg viewer).
        2) a string of single character colors -- e.g. setting colors='rrr' is
            equivalent to setting colors=['red', 'red', 'red'] (see the
            'color_dict' dictionary above for a list of possibilities).
        3) a list of rgb 3-tuples -- e.g. colors = [(255, 0, 0), ...].

        :param filename - the desired location/filename of the SVG file
        created (by default the SVG will be named 'disvg_output.svg' or
        'disvg_output_<timestamp>.svg' and stored in the temporary
        directory returned by `tempfile.gettempdir()`.  See `timestamp`
        for information on the timestamp.

        :param stroke_widths - a list of stroke_widths to use for paths
        (default is 0.5% of the SVG's width or length)

        :param nodes - a list of points to draw as filled-in circles

        :param node_colors - a list of colors to use for the nodes (by default
        nodes will be red)

        :param node_radii - a list of radii to use for the nodes (by default
        nodes will be radius will be 1 percent of the svg's width/length)

        :param text - string or list of strings to be displayed

        :param text_path - if text is a list, then this should be a list of
        path (or path segments of the same length.  Note: the path must be
        long enough to display the text or the text will be cropped by the svg
        viewer.

        :param font_size - a single float of list of floats.

        :param openinbrowser -  Set to True to automatically open the created
        SVG in the user's default web browser.

        :param timestamp - if true, then the a timestamp will be
        appended to the output SVG's filename.  This is meant as a
        workaround for issues related to rapidly opening multiple
        SVGs in your browser using `disvg`. This defaults to true if
        `filename is None` and false otherwise.

        :param margin_size - The min margin (empty area framing the collection
        of paths) size used for creating the canvas and background of the SVG.

        :param mindim - The minimum dimension (height or width) of the output
        SVG (default is 600).

        :param dimensions - The (x,y) display dimensions of the output SVG.
        I.e. this specifies the `width` and `height` SVG attributes. Note that 
        these also can be used to specify units other than pixels. Using this 
        will override the `mindim` parameter.

        :param viewbox - This specifies the coordinated system used in the svg.
        The SVG `viewBox` attribute works together with the the `height` and 
        `width` attrinutes.  Using these three attributes allows for shifting 
        and scaling of the SVG canvas without changing the any values other 
        than those in `viewBox`, `height`, and `width`.  `viewbox` should be 
        input as a 4-tuple, (min_x, min_y, width, height), or a string 
        "min_x min_y width height".  Using this will override the `mindim` 
        parameter.

        :param attributes - a list of dictionaries of attributes for the input
        paths.  Note: This will override any other conflicting settings.

        :param svg_attributes - a dictionary of attributes for output svg.
        
        :param svgwrite_debug - This parameter turns on/off `svgwrite`'s 
        debugging mode.  By default svgwrite_debug=False.  This increases 
        speed and also prevents `svgwrite` from raising of an error when not 
        all `svg_attributes` key-value pairs are understood.
        
        :param paths2Drawing - If true, an `svgwrite.Drawing` object is 
        returned and no file is written.  This `Drawing` can later be saved 
        using the `svgwrite.Drawing.save()` method.

    NOTES:
        * The `svg_attributes` parameter will override any other conflicting 
        settings.

        * Any `extra` parameters that `svgwrite.Drawing()` accepts can be 
        controlled by passing them in through `svg_attributes`.

        * The unit of length here is assumed to be pixels in all variables.

        * If this function is used multiple times in quick succession to
        display multiple SVGs (all using the default filename), the
        svgviewer/browser will likely fail to load some of the SVGs in time.
        To fix this, use the timestamp attribute, or give the files unique
        names, or use a pause command (e.g. time.sleep(1)) between uses.

    SEE ALSO:
        * document.py
    g{Gzt?gMbP?z#000000z#ff0000   NTzdisvg_output.svg.r   r   _)rG   rgbz%s %s %s %s       c                 f    t        j                  d| j                               j                         S )Nz	\d*\.?\d*)researchstripgroup)r;   s    rK   strip_unitszdisvg.<locals>.strip_units  s"    99\17795;;==rS   z	0 0 %s %sr   z{}{}widthheightdebug)filenamesizer}   )r~   r   r}   viewBoxr   none)strokestroke_widthfill)r   tp)r   id)	font_size#r?   z4Failed to open output SVG in browser.  SVG saved to: )3os_pathjoinr	   abspathdirnameexistsr   splitextstrr   replacesplitrO   r   r   rQ   rL   r\   rF   rR   rP   maprl   r_   formatintr   getr   r   r   update	Exceptionr   addrX   rY   circlerW   r   defsr   txtTextPathsavemd_xml_parsetoprettyxmlopenwriter   print)Bpathscolorsr~   stroke_widthsnodesnode_colors
node_radiiopeninbrowser	timestampmargin_sizemindim
dimensionsviewboxr   	text_pathr   
attributessvg_attributessvgwrite_debugpaths2Drawingbaseunit_default_relative_node_radius_default_relative_stroke_width_default_path_color_default_node_color_default_font_sizer   fbnamefexttstamp
stfilenamerJ   r   stuff2boundrz   rh   ri   rj   rk   dxdyswmax_stroke_widthr:   max_node_diameterextra_space_for_styleszxszyr}   dwgr"   r.   psgood_attribskeyvalr   rB   i_ptptposr;   pathidtxter	xmlstringr   sB                                                                     rK   disvgr   a   s   \ %)!%)"##%-D9	<<
.@Aoogooh78G>>'" ''1TV$$S"-]]6*1-3f<tC
<<4 %/%"8)*SZ7Fv;#e*,,,&#&&v5HJFD)'/ 5FC{&+c!fns5
 ./#e*<K{#s5z111+s++K:MOK.'4 :FC{+03q6>C(: E>K'3'#g-G s+Aa0J	3sJ/0
	>c+z&B CC5 K5 K9$K!1+!>dD$D[D[7B7B  R[#AA!#SZ#% 5zS%7777#&}#5   BK"??SU^
$%aC!5zS_444$%c*o$5! ! #$46G HB!6q!888B!6q!888
amB!666
amB!666#'r26>--H-C--H-CBw&kH,#d6B;#3456A#d6B;#3456A&kH,#X
 !$((*Q-@$((:a=AC
""7N; (xj (&( xj%' e$ 	/DAq!T"SSU #!WYY[ #Ry%a= )C$Q-,Ccz)$CHHR6C:6(//c
;) 0<01F1I.1-2B.C&, ! . /+	/4 !U"CAFFAFF#3"CD 	NHD"GGCJJr:d#3+d:KJLM	N $$D$)?)3It)D),Y3t9)D	F F dC 6D/0	d[^3TKN5JK!#sQw/1134	i.y>SY666!*c$i 7I/03t9<	o 	3FC#A!T"SSU #!WYY[ CH_FHHLLB623GGCHHR9S>HBCEIIcll3v:q12	3  
HHJ X&224I	h	 		 	H% {  ) ) QLL) #D\ 	HI(Os6   +(`?7a*a/2a; ?	a'a""a'/a8;bc                     |J t        | fi d|d|d|d|d|d|d|d|d	|	d
|
d|d|d|d|d|d|d|d|d|d|S )zCreate SVG and write to disk.

    Note: This is identical to `disvg()` except that `openinbrowser`
    is false by default and an assertion error is raised if `filename
    is None`.

    See `disvg()` docstring for more info.
    r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s                        rK   wsvgr     s      	Av 	A 	A,	A49	A(	A5?	A  -	A 9B	A )		A 28		A
 '	A
 18	A
 ?C	A %	A 1:	A '	A 8F	A !/	A  -	A 8@	A 	ArS   c                     t        | fi d|d|d|d|d|d|d|d|d	|	d
|
d|d|d|d|d|d|d|d|d|d|S )zCreate and return `svg.Drawing` object.

    Note: This is identical to `disvg()` except that `paths2Drawing`
    is true by default and an assertion error is raised if `filename
    is None`.

    See `disvg()` docstring for more info.
    r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s                        rK   r   r     s      	Av 	A 	A,	A49	A(	A5?	A  -	A 9B	A )		A 28		A
 '	A
 18	A
 ?C	A %	A 1:	A '	A 8F	A !/	A  -	A 8@	A 	ArS   rD   )NNNNNNNTN皙?X  NNNNNNNFFpx)NNNNNNNFFr   r   NNNNNNNFFr   )NNNNNNNFFr   r   NNNNNNNFTr   )$__doc__
__future__r   r   r   mathr   osr   r   r   tempfiler	   xml.dom.minidomr
   r   svgwriter   r   r   r   warningsr   rv   r   r   r   	misctoolsr   rE   rL   rR   rl   r   r   r   r   rS   rK   <module>r      s   A @  (  1 )   	 . - &c6 66 : 2	
 2 7 2 2 2 7 6 9 7 8 6  ;!" 3
80"D AE37:=:>59.3(,IX
 @D26;>9=48-2'+A8 59>BBG:>59BFEIArS   