
    BPc;#                       d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZ d	d
lmZ  G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d d e          Z G d! d"e          ZdS )#z
Provide extra utility to each svg element type specific to its type.

This is useful for having a common interface for each element which can
give path, transform, and property access easily.
    )annotationsN)Optional)etree   )
StyleSheet)Vector2d
VectorLikeDirectedLineSegment   )BaseElementc                      e Zd ZdZdZdS )Defsz'A header defs element, one per documentdefsN__name__
__module____qualname____doc__tag_name     6/usr/share/inkscape/extensions/inkex/elements/_meta.pyr   r   )   s        11HHHr   r   c                  "    e Zd ZdZdZd Zd ZdS )StyleElementz9A CSS style element containing multiple style definitionsstylec                R    t          j        t          |                    | _        dS z.Sets the style content text as a CDATA sectionNr   CDATAstrtextselfcontents     r   set_textzStyleElement.set_text4       KG--			r   c                8    t          | j        | j                  S )z0Return the StyleSheet() object for the style tag)callback)r   r!   r%   r#   s    r   
stylesheetzStyleElement.stylesheet8   s    $)dm<<<<r   N)r   r   r   r   r   r%   r*   r   r   r   r   r   /   s=        CCH. . .= = = = =r   r   c                      e Zd ZdZdZd ZdS )ScriptzA javascript tag in SVGscriptc                R    t          j        t          |                    | _        dS r   r   r"   s     r   r%   zScript.set_textB   r&   r   N)r   r   r   r   r   r%   r   r   r   r,   r,   =   s.        !!H. . . . .r   r,   c                      e Zd ZdZdZdS )DesczDescription elementdescNr   r   r   r   r0   r0   G   s        HHHr   r0   c                      e Zd ZdZdZdS )TitlezTitle elementtitleNr   r   r   r   r3   r3   M   s        HHHr   r3   c                  p    e Zd ZdZdZ ed           Zed             Zd ZddZ	ddZ
ddZd ZddZdS )	NamedViewzBThe NamedView element is Inkscape specific metadata about the filezsodipodi:namedviewc                ,    |                      d          S )Nzinkscape:current-layer)getr)   s    r   <lambda>zNamedView.<lambda>X   s    $((3K*L*L r   c                    t          | j                            |                     d          pd          | j                            |                     d          pd                    S )z.Returns view_center in terms of document unitszinkscape:cxr   zinkscape:cy)r   rootviewport_to_unitr8   r)   s    r   centerzNamedView.centerZ   s^     I&&txx'>'>'C!DDI&&txx'>'>'C!DD
 
 	
r   c                ,    |                      d          S )zReturns a list of guidessodipodi:guidefindallr)   s    r   
get_guideszNamedView.get_guidesb   s    ||,---r   TNc                L   |du r$t                                          d|d          }nC|du r$t                                          |dd          }n t                      j        g ||R  }|r#|                    dt          |                     |                     |          S )ap  Creates a new guide in this namedview

        Args:
            position: a float containing the y position for ``orient is True``, or
                the x position for ``orient is False``

                .. versionchanged:: 1.2
                    Alternatively, the position may be given as Tuple (or VectorLike)
            orient: True for horizontal, False for Vertical

                .. versionchanged:: 1.2
                    Tuple / Vector specifying x and y coordinates of the normal vector
                    of the guide.
            name: label of the guide

        Returns:
            the created guideTr   )r   r   Fr   r   inkscape:label)Guidemove_tosetr    add)r#   positionorientnameelems        r   	new_guidezNamedView.new_guidef   s    $ T>>77??1h77DDu__77??8Q77DD"577?5H5f555D 	2HH%s4yy111xx~~r   rJ   r	   orientationreturnOptional[Guide]c                    t                                          |d         |d         |          }|                     |          |                     |          ndS )zUAdd a guide iif there is no guide that looks the same.

        .. versionadded:: 1.2r   r   N)rF   rG   get_similar_guiderI   )r#   rJ   rO   rM   s       r   new_unique_guidezNamedView.new_unique_guide   sL     wwx{HQKEE!%!7!7!=!=!Etxx~~~4Or   otherrF   c                r    |                                  D ]!}t                              ||          r|c S "dS )zCheck if the namedview contains a guide that looks identical to one
        defined by (position, orientation). If such a guide exists, return it;
        otherwise, return None.

        .. versionadded:: 1.2N)rB   rF   guides_coincident)r#   rU   guides      r   rS   zNamedView.get_similar_guide   sH     __&& 	 	E&&ue44 tr   c                ,    |                      d          S )z6Returns a list of pages

        .. versionadded:: 1.2inkscape:pager@   r)   s    r   	get_pageszNamedView.get_pages   s     ||O,,,r   c                    t          ||||          }|r#|                    dt          |                     |                     |          S )zCCreates a new page in this namedview

        .. versionadded:: 1.2)widthheightxyrE   )PagerH   r    rI   )r#   r_   r`   r]   r^   labelrM   s          r   new_pagezNamedView.new_page   sM     %!q999 	3HH%s5zz222xx~~r   )TN)rJ   r	   rO   r	   rP   rQ   )rU   rF   rP   rQ   N)r   r   r   r   r   propertycurrent_layerr=   rB   rN   rT   rS   r[   rc   r   r   r   r6   r6   S   s        LL#HHLLMMM
 
 X
. . .   8P P P P	 	 	 	- - -     r   r6   c                       e Zd ZdZdZedd            Z ed           Z ed           Zedd            Z	e
 fd	            ZddZed             Z xZS )rF   zAn inkscape guider?   rP   r   c                J    t          |                     d          d          S )z9Vector normal to the guide

        .. versionadded:: 1.2rO   rD   fallbackr   r8   r)   s    r   rO   zGuide.orientation   s#    
 //&AAAAr   c                F    | j         d         dk    o| j         d         dk    S Nr   r   rO   r)   s    r   r9   zGuide.<lambda>   %    T%a(A-J$2B12E2J r   c                F    | j         d         dk    o| j         d         dk    S rm   rn   r)   s    r   r9   zGuide.<lambda>   ro   r   c                J    t          |                     d          d          S )zPosition of the guide handle. The y coordinate is flipped and relative
        to the bottom of the viewbox, this is a remnant of the pre-1.0 coordinate system
        rJ   )r   r   ri   rk   r)   s    r   pointzGuide.point   s#    
 ,,v>>>>r   c                j     t                      j        di |}|                    |||           |S )N)angler   )supernewrG   )clspos_xpos_yrt   attrsrX   	__class__s         r   rv   z	Guide.new   s;    $$e$$eU%000r   Nc                b   |                      dt          |          ddt          |          d           t          |t                    rd|vrt          |          }t          |t          t          f          rMt          j        t          j        |                    t          j        t          j        |                     f}t          |t          t          f          r2t          |          dk    rd                    d |D                       }||                      d|           | S )a+  
        Move this guide to the given x,y position,

        Angle may be a float or integer, which will change the orientation. Alternately,
        it may be a pair of numbers (tuple) which will set the orientation directly.
        If not given at all, the orientation remains unchanged.
        rJ   g,r   c              3     K   | ]}|d V  	dS )r}   Nr   ).0is     r   	<genexpr>z Guide.move_to.<locals>.<genexpr>   s&      55!XX555555r   NrO   )rH   float
isinstancer    intmathsinradianscostuplelistlenjoin)r#   rx   ry   rt   s       r   rG   zGuide.move_to   s    	eAAAuAAABBBeS!! 	%%eeeS\** 	TXdl51122TXdl5>Q>Q5R5R4RSEeeT]++ 	6E

aHH55u55555EHH]E***r   c           
     ~   | j         | j         j        z  }|j         |j         j        z  }| j        }|j        } t          ||t	          |d         |d                    z             j        | dk     oMt          t          |d         |d         z            t          |d         |d         z            z
            dk     S )zCheck if two guides defined by (position, orientation) and (opos, oor) look
        identical (i.e. the position lies on the other guide AND the guide is
        (anti)parallel to the other guide).

        .. versionadded:: 1.2r   r   gư>)rO   lengthrr   r
   r   perp_distanceabs)guide1guide2rO   oorrJ   oposs         r   rW   zGuide.guides_coincident   s     (6+=+DD 6#5#<<<|(Xk!n{1~o%N%NN T#  X CAQ/003{1~A7N3O3OOPPSWW	
r   )rP   r   rd   )r   r   r   r   r   re   rO   is_horizontalis_verticalrr   classmethodrv   rG   staticmethodrW   __classcell__r{   s   @r   rF   rF      s        HB B B XB HJJ M (JJ K ? ? ? X?     [
   0 
 
 \
 
 
 
 
r   rF   c                      e Zd ZdZdZdS )MetadatazInkscape Metadata elementmetadataNr   r   r   r   r   r      s        ##HHHr   r   c                      e Zd ZdZdZdS )ForeignObjectzSVG foreignObject elementforeignObjectNr   r   r   r   r   r      s        ##HHHr   r   c                      e Zd ZdZdZdS )SwitchzA switch elementswitchNr   r   r   r   r   r     s        HHHr   r   c                      e Zd ZdZdZdS )GridzA namedview grid childzinkscape:gridNr   r   r   r   r   r     s          HHHr   r   c                       e Zd ZdZdZ ed           Z ed           Z ed           Z ed           Z	e
 fd            Zd Z xZS )	ra   z1A namedview page child

    .. versionadded:: 1.2rZ   c                V    |                      |                     d          pd          S )Nr]   r   to_dimensionlessr8   r)   s    r   r9   zPage.<lambda>  s%    $"7"78I8I8NQ"O"O r   c                V    |                      |                     d          pd          S )Nr^   r   r   r)   s    r   r9   zPage.<lambda>  s%    4#8#8(9K9K9Pq#Q#Q r   c                V    |                      |                     d          pd          S )Nr_   r   r   r)   s    r   r9   zPage.<lambda>  #    d33DHHSMM4FQGG r   c                V    |                      |                     d          pd          S )Nr`   r   r   r)   s    r   r9   zPage.<lambda>  r   r   c                    t                                                      }|                    ||           |                    d|           |                    d|           |S )z+Creates a new page element in the namedviewr]   r^   )ru   rv   rG   rH   )rw   r]   r^   r_   r`   pager{   s         r   rv   zPage.new  sW     ww{{}}Q%   6"""r   c                t    |                      dt          |          ddt          |          d           | S )z(Move this page to the given x,y positionrJ   r}   r~   )rH   r   )r#   r_   r`   s      r   rG   zPage.move_to"  s;    a999U1XX999:::r   )r   r   r   r   r   re   r]   r^   r_   r`   r   rv   rG   r   r   s   @r   ra   ra     s          HHOOPPEXQQRRFGGHHAGGHHA    [      r   ra   )r   
__future__r   r   typingr   lxmlr   stylesr   
transformsr   r	   r
   _baser   r   r   r,   r0   r3   r6   rF   r   r   r   r   ra   r   r   r   <module>r      s  *  # " " " " "                    B B B B B B B B B B          ;   = = = = =; = = =. . . . .[ . . .    ;       K   P P P P P P P PfL
 L
 L
 L
 L
K L
 L
 L
^    {       K       [       ;       ;     r   