Ë
    W¨œj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    új/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/svgpathtools/svg_to_paths.pyÚ
path2pathdr      s   € Ø�8‰8�C˜ÓÐó    c                 ó   — | j                  dd«      }| j                  dd«      }| j                  dd«      }| j                  dd«      }| j                  dd«      }|�t        |«      x}}nt        |«      }t        |«      }t        |«      }t        |«      }|�râd}||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ß  € ð 
�‰�T˜1Ó	€BØ	�‰�T˜1Ó	€BØ	�‰�T˜4Ó	 €BØ	�‰�T˜4Ó	 €BØ�‰�C˜Ó€Aà€}Ü˜“(Ðˆ‰Rä�2‹YˆÜ�2‹Yˆä	ˆr‹€BÜ	ˆr‹€Bâàˆ
Ø�z‘/ˆØ�z‘/ˆð ˆà	ˆS”3�r˜B‘w“<Ñ #Ñ%¬¨B«Ñ/Ñ/ˆà	ˆS”3�r˜B‘w“<Ñ #Ñ%¬¨B°©LÓ(9Ñ9¸CÑ?Ä#ÀbÈ7ÁlÓBSÑSÐVYÑYÔ\_Ð`bÐegÑ`gÓ\hÑhÐknÑnÔqtÐuwÓqxÑxÐ{~Ñ~ô  BEð  FHð  KMñ  FMó  BNñ  Nñ  	Nˆà	ˆS”3�r˜G‘|Ó$Ñ$ sÑ*¬S°°b±«\Ñ9¸CÑ?Ä#ÀbÈ2ÁgÃ,ÑNÐQTÑTÔWZÐ[]Ð`gÑ[gÓWhÑhÐknÑnÔqtÐuwÐz|Ñu|Óq}Ñ}ð  ADñ  Dô  GJð  KMó  GNñ  Nñ  	Nˆà	ˆS”3�r˜B‘w“<Ñ #Ñ%¬¨B°©LÓ(9Ñ9¸CÑ?Ä#ÀbÈ7ÁlÓBSÑSÐVYÑYÔ\_Ð`bÐegÑ`gÓ\hÑhÐknÑnÔqtÐuwÓqxÑxÐ{~Ñ~ô  BEð  FHð  KMñ  FMó  BNñ  Nñ  	Nˆà	ˆS”3�r˜G‘|Ó$Ñ$ sÑ*¬S°°b±«\Ñ9¸CÑ?Ä#ÀbÈ2ÁgÃ,ÑNÐQTÑTÔWZÐ[]Ð`gÑ[gÓWhÑhÐknÑnÔqtÐuwÐz|Ñu|Óq}Ñ}ð  ADñ  Dô  GJð  KMó  GNñ  Nñ  	Nˆð ˆs‰7€Nð ˆØ	ˆS”3�r˜B‘w“<Ñ #Ñ%¬¨B«Ñ/Ñ/ˆØ	ˆS”3�r“7‰]˜SÑ ¤3 r£7Ñ*¨YÑ6¼¸QÀ¹V»ÑDÀtÑKÑKˆØ	ˆS”3�r“7‰]˜SÑ ¤3 r£7Ñ*¨YÑ6¼¸RÀ"¹W»ÑEÈÑLÑLˆàˆs‰7€Nr   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"   è ø€ Ð?¹±°°1�y×'Ñ'¨¨!×,¹ù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ÒØä�F˜1‘I˜a‘LÓ!¤U¨6°"©:°a©=Ó%9Ñ9ò :Ü�F˜1‘I˜a‘LÓ!¤U¨6°"©:°a©=Ó%9Ñ9ð ñ ‘fØ�‰�f˜Q‘iÔ àˆc�h‰hÑ?¹Ó?Ó?Ñ?€AÙ‘VØ	ˆS‰ˆØ€Hr   c                 ó   — t        | |«      S )zøconverts 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 )z°Converts 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¸Ó*:Ó$;€q€AÜ�—‘˜' 1Ó%Ó&¬¨d¯h©h°xÀÓ.CÓ(D€q€Aàˆt�y‰y‹{Ñ˜d d§i¡i£kÒ1ð �X‰X�d˜DÓ!ˆØ�X‰X�d˜DÓ!ˆØˆ:Ø’�rˆBØˆ:Ø’�rˆBÜ�r“œE "›IˆBˆà×Ñ˜a "™f aÓ(ˆØ	ˆZ×Ñ˜q 1™u r™z¨1Ó-Ñ-ˆØ	Ð#×*Ñ*¨2¨r°1°Q±3¸¸"¹Ó=Ñ=ˆØ	ˆZ×Ñ˜q ™s A a¡C¨¡FÓ+Ñ+ˆØ	Ð#×*Ñ*¨2¨r°1°Q±3°r±6¸1¸Q¹3Ó?Ñ?ˆØ	ˆZ×Ñ˜q ™t Q q¡SÓ)Ñ)ˆØ	Ð#×*Ñ*¨2¨r°1°a¸±c¸"±fÓ=Ñ=ˆØ	ˆZ×Ñ˜q ! B¡$Ó'Ñ'ˆØ	Ð$×+Ñ+¨B°°A°b±D¸!Ó<Ñ<ˆØˆà�ˆ€BØ�‰U�Aˆ€BØ�‰U�A˜‘Eˆ€BØ��A‘ˆ€Bð
ß‰F�2�r˜2˜r 2 r¨2¨rÓ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   € àˆa�h‰h�l‰l˜4 Ó%Ñ%¨Ñ+¨a¯h©h¯l©l¸4ÀÓ.EÑEØ
ñ	Ø—‘—‘˜T 3Ó'ñ	(Ø*-ñ	.Ø01·±·±¸TÀ3Ó0Gñ	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Ó   sf   € ä�G×&Ñ&×+Ñ+Ó-Ó.ˆÜ'+¨G×,>Ñ,>×,EÑ,EÓ,GÔ'HÓIÑ'H �#—)“)Ð'HˆÐIÜ”Dœ˜T 6Ó*Ó+Ó,Ð,ùò 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‚   £   s‡  € ôV Ð0´#Ó6Òe¼*ÐEVÔXdÓ:e€MÙ>KœŸ™Ÿ™Ð(9Ô:ÐQbÐä
Ð!Ó
"€Cò-ð %(×$<Ñ$<¸VÔ$DÓEÑ$D˜b‰X�b�\Ð$D€EÐEÙ#(Ó)¡5˜R��C“ 5€IÐ)Ø %Ðñ "Ø(+×(@Ñ(@ÀÔ(LÓMÑ(L "‘˜"•Ð(LˆÐMØ±5Ó9±5¨R”n RÕ(°5Ñ9Ñ9ˆ	Ø! UÑ*Ð!ñ !Ø(+×(@Ñ(@ÀÔ(KÓLÑ(K "‘˜"•Ð(KˆÐLØ¹Ó>¹°"”m B¨Õ-¸Ñ>Ñ>ˆ	Ø! UÑ*Ð!áØ(+×(@Ñ(@ÀÔ(HÓIÑ(H "‘˜"•Ð(HˆÐIØÙ?DóFÙ?D¸!ð ˜Q˜t™W‘} sÑ*¨Q¨t©WÑ4ØñØ˜t™Wñ%Ø'*ñ+Ø-.¨t©Wó5Ø?DñFñ 	Fˆ	à! UÑ*Ð!á Ø+.×+CÑ+CÀIÔ+NÓOÑ+N R‘H˜R•LÐ+NˆÐOØ±Ó9±¨1”m AÕ&°Ñ9Ñ9ˆ	Ø! XÑ-Ð!áØ*-×*BÑ*BÀ8Ô*LÓMÑ*L B‘8˜B•<Ð*LˆÐMØ±Ó8±¨1”m AÕ&°Ñ8Ñ8ˆ	Ø! WÑ,Ð!á"Ø-0×-EÑ-EÀfÔ-MÓNÑ-M r‘h˜r•lÐ-Mˆ
ÐNØ©ZÓ8©Z¨”j •m¨ZÑ8Ñ8ˆ	Ø! ZÑ/Ð!áÙ! #×":Ñ":¸5Ó"AÀ!Ñ"DÓEˆØ�
‰
ŒÙ,5Ó6©I q”Z •]¨Iˆ	Ð6ØÐ3°^ÐCÐCà�
‰
ŒÙ,5Ó6©I q”Z •]¨Iˆ	Ð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 )z“Convenience 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Ø,BØ0JØ/HØ1LôNð Nr   c           
      ó>   — t        | «      }t        ||||||||¬«      S )z�Convenience 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Ø,BØ0JØ/HØ1Lô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4ðT &*Ø(,Ø)-Ø&*Ø*.Ø)-Ø+/óNð, &+Ø(,Ø)-Ø&*Ø*.Ø)-Ø+/ôNøðk ò Ø‚Lðús   ¢A7 Á7BÂ B