
     h2                        d Z ddlmZmZmZ ddlmZ ddlZddlm	Z	 ddl
Z
	 ddlmZ ddlmZ  e
j"                  d	      Zd
 ZddZddZddZd Zd Z	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 ddZy# e$ r eZY Xw xY w)zuThis submodule contains tools for creating path objects from SVG files.
The main tool being the svg2paths() function.    )divisionabsolute_importprint_function)parseN)StringIO)PathLike   )
parse_pathz}([\+-]?\d*[\.\d]\d*[eE][\+-]?\d+|[\+-]?\d*[\.\d]\d*)(?:\s*,\s*|\s+|(?=-))([\+-]?\d*[\.\d]\d*[eE][\+-]?\d+|[\+-]?\d*[\.\d]\d*)c                 &    | j                  dd      S )Nd )get)paths    u/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/svgpathtools/svg_to_paths.py
path2pathdr      s    88C    c                     | j                  dd      }| j                  dd      }| j                  dd      }| j                  dd      }| j                  dd      }|t        |      x}}nt        |      }t        |      }t        |      }t        |      }|rd}||z  }||z  }	d	}
|
d
t        ||z         z   dz   t        |      z   z  }
|
dt        ||z         z   dz   t        ||	z         z   dz   t        ||z         z   dz   t        ||z         z   dz   t        |      z   dz   t        ||z         z   z  }
|
dt        ||z
        z   dz   t        ||z         z   dz   t        ||z
        z   dz   t        ||	z         z   dz   t        ||z
        z   dz   t        |      z   z  }
|
dt        ||z
        z   dz   t        ||	z
        z   dz   t        ||z
        z   dz   t        ||z
        z   dz   t        |      z   dz   t        ||z
        z   z  }
|
dt        ||z         z   dz   t        ||z
        z   dz   t        ||z         z   dz   t        ||	z
        z   dz   t        ||z         z   dz   t        |      z   z  }
|
dz   S d	}
|
d
t        ||z
        z   dz   t        |      z   z  }
|
dt        |      z   dz   t        |      z   dz   t        d|z        z   dz   z  }
|
dt        |      z   dz   t        |      z   dz   t        d|z        z   dz   z  }
|
dz   S )zbconverts the parameters from an ellipse or a circle to a string for a 
    Path object d-attributecxr   cyrxNryrg~T~O?r   M C,az 0 1,0    z,0z)r   floatstr)ellipse
use_cubicsr   r   r   r   r   
PATH_KAPPArxKapparyKappar   s              r   ellipse2pathdr(      s    
T1	B	T1	B	T4	 B	T4	 BCA}(R2Y2Y	rB	rB
z/z/ 	S3rBw<#%B//	S3rBw<#%BL(99C?#b7lBSSVYY\_`beg`g\hhknnqtuwqxx{~~  BE  FH  KM  FM  BN  N  	N	S3rG|$$s*Sb\9C?#b2g,NQTTWZ[]`g[gWhhknnqtuwz|u|q}}  AD  D  GJ  KM  GN  N  	N	S3rBw<#%BL(99C?#b7lBSSVYY\_`beg`g\hhknnqtuwqxx{~~  BE  FH  KM  FM  BN  N  	N	S3rG|$$s*Sb\9C?#b2g,NQTTWZ[]`g[gWhhknnqtuwz|u|q}}  AD  D  GJ  KM  GN  N  	N s7N 	S3rBw<#%B//	S3r7]S 3r7*Y6QVDtKK	S3r7]S 3r7*Y6R"WELLs7Nr   c                    t        | t              r| }n%t        j                  | j	                  dd            }t        |      dk(  ryt        |d   d         t        |d   d         k(  xr# t        |d   d         t        |d   d         k(  }|r|r|j                  |d          ddj                  d |D              z   }|s|r|d	z  }|S )
zbconverts the string from a polyline points-attribute to a string for a
    Path object d-attributepointsr   r   r	   r   Lc              3   F   K   | ]  \  }}d j                  ||        yw)z{0} {1}N)format).0xys      r   	<genexpr>z!polyline2pathd.<locals>.<genexpr>c   s!     ?1y''!,?s   !r    )	
isinstancer"   COORD_PAIR_TMPLTfindallr   lenr!   appendjoin)polyline
is_polygonr*   closedr   s        r   polyline2pathdr<   O   s     (C !))(,,x*DE
6{aF1IaL!U6":a=%99 :F1IaL!U6":a=%99  ffQi chh????AV	SHr   c                     t        | |      S )zconverts the string from a polygon points-attribute to a string 
    for a Path object d-attribute.
    Note:  For a polygon made from n points, the resulting path will be
    composed of n lines (even if some of these lines have length zero).
    )r<   )r9   r:   s     r   polygon2pathdr>   i   s     (J//r   c           
         t        | j                  dd            t        | j                  dd            }}t        | j                  dd            t        | j                  dd            }}d| j                         v sd| j                         v rA| j                  dd      }| j                  dd      }||xs d	}||xs d	}t        |      t        |      }}d
j                  ||z   |      }|dj                  ||z   |z
  |      z  }|dj                  ||||z   ||z         z  }|dj                  ||z   ||z   |z
        z  }|dj                  ||||z   |z
  ||z         z  }|dj                  ||z   ||z         z  }|dj                  |||||z   |z
        z  }|dj                  |||z         z  }|dj                  ||||z   |      z  }|S ||}	}||z   |}}
||z   ||z   }}|||z   }}dj                  ||	|
|||||      }|S )zConverts an SVG-rect element to a Path d-string.
    
    The rectangle will start at the (x,y) coordinate specified by the 
    rectangle object and proceed counter-clockwise.r0   r   r1   widthheightr   r   Ng        zM {} {} zL {} {} zA {} {} 0 0 1 {} {} zA {} {} 0 0 1 {} {} zz M{} {} L {} {} L {} {} L {} {} z)r!   r   keysr.   )rectr0   r1   whr   r   r   x0y0x1y1x2y2x3y3s                   r   
rect2pathdrN   r   sD   
 #q!"E$((3*:$;qA'1%&dhhx.C(DqAtyy{ddiik1 XXdD!XXdD!:rB:rBrE"IBa"fa(	Zq1urz1--	#**2r1Q3"==	ZqsAaCF++	#**2r1Q3r61Q3??	ZqtQqS))	#**2r1ac"f==	Zq!B$''	$++BAbD!<<BUABUAEBAB
F2r2r2r2r2  Hr   c                     d| j                   j                  dd      z   dz   | j                   j                  dd      z   dz   | j                   j                  dd      z   dz   | j                   j                  dd      z   S )	Nr   rH   0r   rI   r,   rJ   rK   )attribr   )ls    r   
line2pathdrS      sv    ahhll4%%+ahhll4.EE
	T3'	(*-	.01T30G	Hr   c                 (   t        | t              xs t        | t              }|rt        j                  j                  |       n| } t        |       }	d }
|	j                  d      D cg c]
  } |
|       }}|D cg c]  }|d   	 }}|}|rE|	j                  d      D cg c]
  } |
|       }}||D cg c]  }t        |       c}z  }||z  }|rF|	j                  d      D cg c]
  } |
|       }}||D cg c]  }t        |d       c}z  }||z  }|r]|	j                  d      D cg c]
  } |
|       }}||D cg c]%  }d|d	   z   d
z   |d   z   dz   |d   z   d
z   |d   z   ' c}z  }||z  }|rE|	j                  d      D cg c]
  } |
|       }}||D cg c]  }t        |       c}z  }||z  }|rE|	j                  d      D cg c]
  } |
|       }}||D cg c]  }t        |       c}z  }||z  }|rE|	j                  d      D cg c]
  } |
|       }}||D cg c]  }t        |       c}z  }||z  }|rG |
|	j                  d      d         }|	j                          |D cg c]  }t        |       }}|||fS |	j                          |D cg c]  }t        |       }}||fS c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w )a  Converts an SVG into a list of Path objects and attribute dictionaries. 

    Converts an SVG file into a list of Path objects and a list of
    dictionaries containing their attributes.  This currently supports
    SVG Path, Line, Polyline, Polygon, Circle, and Ellipse elements.

    Args:
        svg_file_location (string or file-like object): the location of the
            svg file on disk or a file-like object containing the content of a
            svg file
        return_svg_attributes (bool): Set to True and a dictionary of
            svg-attributes will be extracted and returned.  See also the 
            `svg2paths2()` function.
        convert_circles_to_paths: Set to False to exclude SVG-Circle
            elements (converted to Paths).  By default circles are included as 
            paths of two `Arc` objects.
        convert_ellipses_to_paths (bool): Set to False to exclude SVG-Ellipse
            elements (converted to Paths).  By default ellipses are included as 
            paths of two `Arc` objects.
        convert_lines_to_paths (bool): Set to False to exclude SVG-Line elements
            (converted to Paths)
        convert_polylines_to_paths (bool): Set to False to exclude SVG-Polyline
            elements (converted to Paths)
        convert_polygons_to_paths (bool): Set to False to exclude SVG-Polygon
            elements (converted to Paths)
        convert_rectangles_to_paths (bool): Set to False to exclude SVG-Rect
            elements (converted to Paths).

    Returns: 
        list: The list of Path objects.
        list: The list of corresponding path attribute dictionaries.
        dict (optional): A dictionary of svg-attributes (see `svg2paths2()`).
    c                    t        | j                  j                               }t        | j                  j                               D cg c]  }|j                   }}t        t        t        ||                  S c c}w )z4Converts DOM elements to dictionaries of attributes.)list
attributesrB   valuesvaluedictzip)elementrB   valrX   s       r   dom2dictzsvg2paths.<locals>.dom2dict   sc    G&&++-.'+G,>,>,E,E,G'HI#))IIDT6*+,, Js   	A<r   r   r9   polygonTliner   rH   r   rI   r,   rJ   rK   r#   circlerC   svgr   )r3   r"   FilePathLikeosr   abspathr   getElementsByTagNamer<   r>   r(   rN   unlinkr
   )svg_file_locationreturn_svg_attributesconvert_circles_to_pathsconvert_ellipses_to_pathsconvert_lines_to_pathsconvert_polylines_to_pathsconvert_polygons_to_pathsconvert_rectangles_to_pathsfrom_filepathdocr^   elpaths	d_stringsattribute_dictionary_listplinsplpgonspglinesrR   ellipsesecirclesc
rectanglesr   svg_attributesr   	path_lists                                 r   	svg2pathsr      sV   V 0#6e*EVXd:eM>K(9:Qb
!
"C- %($<$<V$DEbXb\EEE#()RC)I) % "(+(@(@(LM""MM59RnR(99	!U*! !(+(@(@(KL""LL>"mB->>	!U*!(+(@(@(HI""II?DF:; QtW}s*QtW4tW%'*+-.tW5 F 	F	!U*! +.+C+CI+NORHRLOO91mA&99	!X-!*-*B*B8*LMB8B<MM81mA&88	!W,!"-0-E-Ef-MNrhrlN
NZ8jm88	!Z/!!#":":5"A!"DE

,56qZ]6	63^CC

,56qZ]6	6333_ F) N9 M> JF
 P9 N8 O8 7 7s`   'K<K	!K7K(K>K0K"*K'K,%K1K6,K;L 3L?L
,Lc           
      (    t        | |||||||      S )zConvenience function; identical to svg2paths() except that
    return_svg_attributes=True by default.  See svg2paths() docstring for more
    info.rh   ri   rj   rk   rl   rm   rn   ro   )r   r   s           r   
svg2paths2r     s+     '8+@.F/H,B0J/H1LN Nr   c           
      >    t        |       }t        ||||||||      S )zConvenience function; identical to svg2paths() except that it takes the
    svg object as string.  See svg2paths() docstring for more
    info.r   )r   r   )	
svg_stringri   rj   rk   rl   rm   rn   ro   svg_file_objs	            r   svgstr2pathsr   !  s4     J'L|+@.F/H,B0J/H1LN Nr   )F)T)FTTTTTT)TTTTTTT)__doc__
__future__r   r   r   xml.dom.minidomr   rd   ior   rer   rc   ImportErrorr"   parserr
   compiler4   r   r(   r<   r>   rN   rS   r   r   r    r   r   <module>r      s   1 A @ ! 	  	+
  2::< .b40'T %*'+(,%))-(,*.f4T &*(,)-&**.)-+/N, &+(,)-&**.)-+/Nk  Ls   A7 7B B