
    BPc%i                    ^   d Z ddlmZ ddlmZ ddlmZmZmZ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mZ ddlmZ ddlmZmZm Z  ddl!m"Z"m#Z#m$Z$m%Z%m&Z& ddl'm(Z(m)Z) ddl*m+Z+ ddl,m-Z-m.Z.  e
dd          Z/ G d de          Z0e0e-_1         G d de0          Z2d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.
    )annotations)deepcopy)AnyTupleOptionaloverloadTypeVarList)etree   )IBaseElementISVGDocumentElement)SvgOutputMixin)Path)StyleClasses)	TransformBoundingBox)FragmentError)convert_unitrender_unit
parse_unit   )ChildToPropertyNSSaddNSremoveNSsplitNS)BaseStyleValueall_properties)ElementList)NodeBasedLookup
SVG_PARSERTBaseElement)boundc                  v    e Zd ZdZd Zed^d            ZdZe fd	            Z	ed
             Z
 ed           Z	 eZ	 defdefddeffZ	 ed             Zed             Z ed           Z	  ed           Z	  edd          Z	  edd          Z	 d Z fdZd_ fd	Z fdZd Zd_dZed`d#            Z edad&            Z d' Z d( Z!	 	 	 	 dbdcd1Z"	 	 	 	 ddded5Z# ed6           Z$	 dfdgd9Z%dhd:Z&ed;             Z'did<Z(d= Z)djd?Z*d@ Z+dA Z,e-f fdB	Z.e-f fdC	Z/dD Z0dE Z1dF Z2dG Z3dH Z4dI Z5dJ Z6edK             Z7e7j8        dL             Z7edM             Z9e9j8        dN             Z9dO Z:dkdPZ;edQ             Z<e=dldS            Z>e=dT             Z?dldUZ@dV ZAdldWZBdldXZCdY ZDdZ ZEd[ ZFd\ ZGd_d]ZH xZIS )mr%   z)Provide automatic namespaces to all callsc                @    | j         rt          j        |            d S d S N)tag_namer"   register_class)clss    6/usr/share/inkscape/extensions/inkex/elements/_base.py__init_subclass__zBaseElement.__init_subclass__7   s-    < 	0*3/////	0 	0    elemetree.Elementreturnboolc                    dS )zHook to do more restrictive check in addition to (ns,tag) match

        .. versionadded:: 1.2
            The function has been made public.T )r,   r0   s     r-   is_class_elementzBaseElement.is_class_element;   s	     tr/    c                    | j         s&t          t                      j                  d         S t          | j                   d         S )zReturn the tag_name without NS)r*   r   supertag)self	__class__s    r-   TAGzBaseElement.TAGG   s=     } 	-EGGK((,,&&r**r/   c                *     | | } |j         di | |S )z9Create a new element, converting attrs values to strings.r5   )update)r,   childrenattrsobjs       r-   newzBaseElement.newN   s,     c8n
U
r/   c                6    t          | j                  d         S )Nr   )r   r*   r<   s    r-   <lambda>zBaseElement.<lambda>U   s    gdm&<&<Q&? r/   	transformstyleclassesclassc                $    d | j         D             S )z1Map attributes to property name and wrapper classc                <    i | ]}|d          |d         |d         fS )r   r9   r5   .0rows     r-   
<dictcomp>z-BaseElement.wrapped_attrs.<locals>.<dictcomp>h   s+    IIIsB#a&#b'*IIIr/   WRAPPED_ATTRSrF   s    r-   wrapped_attrszBaseElement.wrapped_attrse        JId6HIIIIr/   c                $    d | j         D             S )z2Map properties to attribute name and wrapper classc                <    i | ]}|d          |d         |d         fS )r   rN   r9   r5   rO   s     r-   rR   z-BaseElement.wrapped_props.<locals>.<dictcomp>m   s+    IIIsAR#b'*IIIr/   rS   rF   s    r-   wrapped_propszBaseElement.wrapped_propsj   rV   r/   c                *    t          |           j        S r)   )type__name__rF   s    r-   rG   zBaseElement.<lambda>o   s    T$ZZ%8 r/   c                P    |                                                      |           S r)   )getroottreegetpathrF   s    r-   rG   zBaseElement.<lambda>q   s     T%5%5%7%7%?%?%E%E r/   zsvg:descT)prependz	svg:titlec                    | j         v r\ j         |         \  } fd} | j                            d          |          }|dk    r |_        t	           ||           |S t          d j         d|           )z9Get the attribute, but load it if it is not available yetc                    | r%                     t          |                      d S j                            d            d S r)   )setstrattribpop)new_itemattrr<   s    r-   	_set_attrz*BaseElement.__getattr__.<locals>._set_attr   sG     0HHT3x==11111KOOD$/////r/   N)callbackrI   zCan't find attribute .)rY   re   getelementsetattrAttributeErrortypename)r<   namer,   ri   valuerh   s   `    @r-   __getattr__zBaseElement.__getattr__~   s    4%%%,T2KT30 0 0 0 0 0 Cd33iHHHEw $D$&&&LKT]KKTKKLLLr/   c                $   || j         v rc| j         |         \  }}|r4t          ||          s ||          }t          |          | j        |<   dS | j                            |d           dS t                                          ||           dS )z&Set the attribute, update it if neededN)rY   
isinstancerd   re   rf   r:   __setattr__)r<   rq   rr   rh   r,   r=   s        r-   rv   zBaseElement.__setattr__   s    4%%%,T2KT3 ,!%-- 'CJJE$'JJD!!!d+++++GGe,,,,,r/   Nc                    || j         v r8| j         |         \  }}t          | |d          }|rt          |          n|pd}|S t                                          t          |          |          S )z0Get element attribute named, with addNS support.N)rU   getattrrd   r:   rl   r   )r<   rh   defaultprop_rr   retr=   s          r-   rl   zBaseElement.get   sp    4%%%*40IT1D$--E !&<#e***GOtCJww{{5;;000r/   c                j   || j         v r>| j         |         \  }}t          | | ||                     t          | |          }|sdS |*| j                            t          |          d           dS t          |          }t                                          t          |          |           dS )z/Set element attribute named, with addNS supportN)	rU   rn   rx   re   rf   r   rd   r:   rc   )r<   rh   rr   rz   r,   r=   s        r-   rc   zBaseElement.set   s    4%%%,T2KT3D$E

+++D$''E =KOOE$KK.....JJEGGKKdU+++++r/   c                f    |                                 D ]\  }}|                     ||           | S )a  
        Update element attributes using keyword arguments

        Note: double underscore is used as namespace separator,
        i.e. "namespace__attr" argument name will be treated as "namespace:attr"

        :param kwargs: dict with name=value pairs
        :return: self
        )itemsrc   )r<   kwargsrq   rr   s       r-   r@   zBaseElement.update   s;     "<<>> 	" 	"KD%HHT5!!!!r/   c                    || j         v r<| j         |         \  }}t          | |          }t          | | |d                     |S | j                            t          |          |          S )z>Delete/remove the element attribute named, with addNS support.N)rU   rx   rn   re   rf   r   )r<   rh   ry   rz   r,   rr   s         r-   rf   zBaseElement.pop   sk    4%%%,T2KT3D$''ED$D		***L{uT{{G444r/   child1child2rA   Tuple[BaseElement]c                    d S r)   r5   )r<   r   r   rA   s       r-   addzBaseElement.add   s	     	r/   childr$   c                    d S r)   r5   )r<   r   s     r-   r   zBaseElement.add   s    r/   c                p    |D ]}|                      |           t          |          dk    r|n|d         S )zk
        Like append, but will do multiple children and will return
        children or only child
        r   r   )appendlen)r<   rA   r   s      r-   r   zBaseElement.add   sF    
  	 	EKKx==A--xx8A;>r/   c                   t          j        dd                                          }|                    |                                            |                                                    dd          d         dd         S )z9Return this element as it would appear in an svg documentr   )widthheights   >
    r   r9   Ni)r   get_templategetrootr   copytostringsplit)r<   svgs     r-   r   zBaseElement.tostring   sk    
 )!<<<DDFF

499;;||~~##J2226ss;;r/   FprefixOptional[str]sizeOptional[int]	backlinks	blacklistOptional[List[str]]c                    |t          |           n|}|                     | j                            |||          |           dS )a  Sets the id attribute if it is not already set.

        The id consists of a prefix and an appended random integer of length size.
        Args:
            prefix (str, optional): the prefix of the new ID. Defaults to the tag name.
            size (Optional[int], optional): number of digits of the second part of the
                id. If None, the length is chosen based on the amount of existing
                objects. Defaults to None.

                .. versionchanged:: 1.2
                    The default of this value has been changed from 4 to None.
            backlinks (bool, optional): Whether to update the links in existing objects
                that reference this element. Defaults to False.
            blacklist (List[str], optional): An additional list of ids that are not
                allowed to be used. This is useful when bulk inserting objects.
                Defaults to None.

                .. versionadded:: 1.2
        N)r   r   )r   )rd   set_idrootget_unique_id)r<   r   r   r   r   s        r-   set_random_idzBaseElement.set_random_id   sY    4 %nT&I##F#KK 	 	
 	
 	
 	
 	
r/   r9   levelsintc                    |                      |||           |dk    r0| D ]/}t          |d          r|                    ||dz
  |           .dS dS )a  Same as set_random_id, but will apply also to children

        The id consists of a prefix and an appended random integer of length size.
        Args:
            prefix (str, optional): the prefix of the new ID. Defaults to the tag name.
            levels (int, optional): the depth of the tree traversion, if negative, no
                limit is imposed. Defaults to -1.
            backlinks (bool, optional): Whether to update the links in existing objects
                that reference this element. Defaults to False.
            blacklist (List[str], optional): An additional list of ids that are not
                allowed to be used. This is useful when bulk inserting objects.
                Defaults to None.

                .. versionadded:: 1.2
        )r   r   r   r   set_random_idsr   )r   r   r   N)r   hasattrr   )r<   r   r   r   r   r   s         r-   r   zBaseElement.set_random_ids  s    , 	&ISSSQ;;  5"233 ((%fqjI )    ; r/   c                *    |                                  S r)   )get_idrF   s    r-   rG   zBaseElement.<lambda>-  s     r/   r   rd   c                    d| j         vr|                     | j                   |                     d          }|dk    rd|z   }|dk    rd| d}|S )a  Get the id for the element, will set a new unique id if not set.

        as_url - If set to 1, returns #{id} as a string
                 If set to 2, returns url(#{id}) as a string

        Args:
            as_url (int, optional):
                - If set to 1, returns #{id} as a string
                - If set to 2, returns url(#{id}) as a string.

                Defaults to 0.

                .. versionadded:: 1.1

        Returns:
            str: formatted id
        idr   #r   zurl())re   r   r>   rl   )r<   as_urleids      r-   r   zBaseElement.get_id0  sc    $ t{""tx(((hhtnnA::)CA::---C
r/   c                   |                      dd          }|                     d|           |r|r| j                            |          D ]	}| |_        
dD ]J}| j                            ||          D ]+}|                    ||                     d                     ,K| j                            |          D ]!}|j                            ||           dS dS dS )zASet the id and update backlinks to xlink and style urls if neededr   N)	clip-pathmask)	attributer   )	rl   rc   r   getElementsByHrefhrefr   getElementsByStyleUrlrI   update_urls)r<   new_idr   old_idr0   rh   s         r-   r   zBaseElement.set_idK  s   $%%v 	7 	7	33F;; ! ! 		- 3 3 I77$7OO 3 3DHHT4;;q>>22223	77?? 7 7
&&vv6666	7 	7 	7 	77 7r/   c                    | | }}|||                                 }}|t          |t                    st          d          |S )z9Get the root document element from any element descendentNz/Element fragment does not have a document root!)	getparentru   r   r   )r<   r   parents      r-   r   zBaseElement.rootX  sZ     Tf !6#3#3#5#5&D   $ 344 	S QRRRr/   c                    |                      |          }|N|t          j        |          } |            }|r|                     d|           n|                     |           |S )a  Get or create the given xpath, pre/append new node if not found.

        .. versionchanged:: 1.1
            The ``nodeclass`` attribute is optional; if not given, it is looked up
            using :func:`~inkex.elements._parser.NodeBasedLookup.find_class`Nr   )findoner"   
find_classinsertr   )r<   xpath	nodeclassr`   nodes        r-   get_or_createzBaseElement.get_or_createc  sq     ||E""< +6u==	9;;D "At$$$$D!!!r/   c                d    t          | j        d |                                 D                       S )zWalks the element tree and yields all elements, parent first

        .. versionchanged:: 1.1
            The ``*types`` attribute was removed

        c                J    g | ] }t          |t          t          f          |!S r5   )ru   r%   rd   )rP   rm   s     r-   
<listcomp>z+BaseElement.descendants.<locals>.<listcomp>~  s=       gS'9::  r/   )r!   r   iterrF   s    r-   descendantszBaseElement.descendantst  s?     I #yy{{  
 
 	
r/   r5   c                V    t          | j        |                     ||                    S )a  
        Walk the parents and yield all the ancestor elements, parent first

        Args:
            elem (BaseElement, optional): If provided, it will stop at the last common
                ancestor. Defaults to None.

                .. versionadded:: 1.1

            stop_at (tuple, optional): If provided, it will stop at the first parent
                that is in this list. Defaults to ().

                .. versionadded:: 1.1

        Returns:
            ElementList: list of ancestors
        )r0   stop_at)r!   r   
_ancestors)r<   r0   r   s      r-   	ancestorszBaseElement.ancestors  s&    & 49doo4o&Q&QRRRr/   c              #     K   t          |t                    r!t          |                                          }|                                 D ]}|V  ||v r d S d S r)   )ru   r%   listr   iterancestors)r<   r0   r   r   s       r-   r   zBaseElement._ancestors  st      dK(( 	-4>>++,,G((** 	 	FLLL   !	 	r/   c              '  R  K   |rt          | |          r| V  |                     d          }|ut          | j                            |                    t          | j                            |                    z   }|D ]%}t          |d          r |j        | D ]}|V  $dS dS )zSGet elements which link back to this element, like ancestors but via
        xlinksr   Nr   )ru   rl   r   r   r   r   r   r   )r<   typesmy_idelemsr0   r   s         r-   r   zBaseElement.backlinks  s        	
4// 	JJJ44U;;<<t	//66@ @ E  $ $4-- $!/!7 $ $# $ $r/   c                J    t                                          ||          S )z&Wrap xpath call and add svg namespaces
namespaces)r:   r   r<   patternr   r=   s      r-   r   zBaseElement.xpath  s    ww}}W}<<<r/   c                J    t                                          ||          S )z(Wrap findall call and add svg namespacesr   )r:   findallr   s      r-   r   zBaseElement.findall  s     www:>>>r/   c                D    |                      |          }|r|d         ndS )z:Gets a single element from the given xpath or returns Noner   N)r   )r<   r   el_lists      r-   r   zBaseElement.findone  s&    **U##$.wqzz$.r/   c                    |                                  )|                                                      |            dS dS )z&Delete this node from it's parent nodeN)r   removerF   s    r-   deletezBaseElement.delete  s>    >>'NN##D))))) ('r/   c                    t          d |D                       }| D ])}|rt          ||          r|                     |           *dS )zARemove all children or child types

        .. versionadded:: 1.1c              3  >   K   | ]}t          j        |          V  d S r)   )r"   r   )rP   ts     r-   	<genexpr>z)BaseElement.remove_all.<locals>.<genexpr>  s-      CCo033CCCCCCr/   N)tupleru   r   )r<   r   r   s      r-   
remove_allzBaseElement.remove_all  se     CCUCCCCC 	# 	#E #Jue44 #E"""	# 	#r/   c                2   |                      |           |                    d          s>|                     d          r)|                    d|                     d                     |j        s| j        r| j        |_        |                                  |S )z+Replace this element with the given elementr   )addnextrl   rc   labelr   r<   r0   s     r-   replace_withzBaseElement.replace_with  s    Txx~~ 	+$((4.. 	+HHT488D>>***z 	$dj 	$DJr/   c                P    t          |           }|                    dd           |S )z(Make a copy of the element and return itr   N)r   rc   r   s     r-   r   zBaseElement.copy  s&    ~~tr/   c                    |                                  }|                     |           |                                 |S )zLike copy(), but the copy stays in the tree and sets a random id on the
        duplicate.

        .. versionchanged:: 1.2
            A random id is also set on all the duplicate's descendants)r   r   r   r   s     r-   	duplicatezBaseElement.duplicate  s:     yy{{Tr/   c                `    t          | j                                      dd          d         S )N}r   )maxsplitr9   )rd   r;   r   rF   s    r-   __str__zBaseElement.__str__  s*     48}}""3"33B77r/   c                    |                      d          }|sdS | j                            |                    d                    S )zvReturns the referred-to element if available

        .. versionchanged:: 1.1
            A setter for href was added.
xlink:hrefNr   )rl   r   getElementByIdstripr<   refs     r-   r   zBaseElement.href  sB     hh|$$ 	4y''		#777r/   c                    t          |t                    r|                                }|                     dd|z              dS )zSet the href objectr   r   N)ru   r%   r   rc   r   s     r-   r   zBaseElement.href  sA     dK(( 	!;;==DsTz*****r/   c                .    |                      dd          S )zReturns the inkscape labelinkscape:labelNrl   rF   s    r-   r   zBaseElement.label  s     xx($///r/   c                L    |                      dt          |                     dS )zSets the inkscape labelr   N)rc   rd   r<   rr   s     r-   r   zBaseElement.label  s%     	!3u::.....r/   c                6    |                      dd          dk    S )zSReturn true if this element is sensitive in inkscape

        .. versionadded:: 1.1sodipodi:insensitiveNtruer   rF   s    r-   is_sensitivezBaseElement.is_sensitive  s     xx.55??r/   c                B    |                      dddg|                    dS )zGSet the sensitivity of the element/layer

        .. versionadded:: 1.1r   r   N)rc   )r<   	sensitives     r-   set_sensitivezBaseElement.set_sensitive  s(    
 	'&$	)BCCCCCr/   c                >    	 | j         j        S # t          $ r Y dS w xY w)zXReturn the unit being used by the owning document, cached

        .. versionadded:: 1.1px)r   unitr   rF   s    r-   r  zBaseElement.unit  s3    
	9>! 	 	 	44	s    
r  c                "    t          | |          S )z[Convert a value given in user units (px) the given unit type

        .. versionadded:: 1.2r   )rr   to_units     r-   to_dimensionalzBaseElement.to_dimensional"  s    
 E7+++r/   c                "    t          | d          S )zJConvert a length value into user units (px)

        .. versionadded:: 1.2r  r  )rr   s    r-   to_dimensionlesszBaseElement.to_dimensionless)  s    
 E4(((r/   c                0    t          ||| j                  S )a  Convert a unit value to a given unit. If the value does not have a unit,
        "Document" units are assumed. "Document units" are an Inkscape-specific concept.
        For most use-cases, :func:`to_dimensional` is more appropriate.

        .. versionadded:: 1.1)ry   r   r  )r<   rr   r	  s      r-   uutounitzBaseElement.uutounit0  s     E7DI>>>>r/   c                ,    t          || j                  S )ai  Convert a unit value into document units. "Document unit" is an
        Inkscape-specific concept. For most use-cases, :func:`viewport_to_unit` (when
        the size of an object given in viewport units is needed) or
        :func:`to_dimensionless` (when the equivalent value without unit is needed) is
        more appropriate.

        .. versionadded:: 1.1r  r   s     r-   unittouuzBaseElement.unittouu8  s     E49---r/   c                n    |                      |                     |          | j        j        z  |          S )zConverts a length value to viewport units, as defined by the width/height
        element on the root (i.e. applies the equivalent transform of the viewport)

        .. versionadded:: 1.2r
  r  r   equivalent_transform_scaler<   rr   r  s      r-   unit_to_viewportzBaseElement.unit_to_viewportB  :    
 ""!!%((49+OOQU
 
 	
r/   c                n    |                      |                     |          | j        j        z  |          S )zConverts a length given on the viewport to the specified unit in the user
        coordinate system

        .. versionadded:: 1.2r  r  s      r-   viewport_to_unitzBaseElement.viewport_to_unitK  r  r/   c                ,    t          || j                  S )zYAdd document unit when no unit is specified in the string.

        .. versionadded:: 1.1)r   r  r   s     r-   add_unitzBaseElement.add_unitT  s     5$),,,r/   c                *    t          j        |           S )a  Returns the cascaded style of an element (all rules that apply the element
        itself), based on the stylesheets, the presentation attributes and the inline
        style using the respective specificity of the style.

        see https://www.w3.org/TR/CSS22/cascade.html#cascading-order

        .. versionadded:: 1.2

        Returns:
            Style: the cascaded style

        )r   cascaded_stylerF   s    r-   r  zBaseElement.cascaded_styleZ  s     #D)))r/   c                *    t          j        |           S )zReturns the specified style of an element, i.e. the cascaded style +
        inheritance, see https://www.w3.org/TR/CSS22/cascade.html#specified-value.

        Returns:
            Style: the specified style

        .. versionadded:: 1.2
        )r   specified_stylerF   s    r-   r  zBaseElement.specified_stylei  s     $T***r/   c                    t                      }|                                 D ]G}|t          v r<t          |         d         r)t          j        |dz   | j        |         z             ||<   H|S )zTReturn presentation attributes of an element as style

        .. versionadded:: 1.2r   z: )declaration)r   keysr    r   factoryre   )r<   rI   keys      r-   presentation_stylezBaseElement.presentation_stylet  st     99;; 	 	Cn$$)<Q)?$+3 #d
T[-= =  c
 r/   c                    |                                  }|1t          |t                    r|                                | j        z  S | j        S )zCalculate every transform down to the other element
        if none specified the transform is to the root document element
        )r   ru   r%   composed_transformrH   )r<   otherr   s      r-   r'  zBaseElement.composed_transform  sI     !!*V["A"A,,..??~r/   )r0   r1   r2   r3   r)   )r   r%   r   r%   rA   r%   r2   r   )r   r$   r2   r$   )NNFN)r   r   r   r   r   r3   r   r   )Nr9   FN)r   r   r   r   r   r3   r   r   )r   )r2   rd   )F)NF)Nr5   )T)r  )Jr\   
__module____qualname____doc__r.   classmethodr6   r*   propertyr>   rD   	NAMESPACEr#   PARSERr   r   r   rT   rU   rY   rp   xml_pathr   desctitlers   rv   rl   rc   r@   rf   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   setterr   r   r  r  staticmethodr
  r  r  r  r  r  r  r  r  r%  r'  __classcell__)r=   s   @r-   r%   r%   2   s       330 0 0    [ H+ + + + X+   [ ??@@I"FF 
i 	%	GW%	M L
 J J XJ J J XJ x8899H"xEEFFH ?:t444D OK666EM M M*- - - - -	1 	1 	1 	1 	1 	1, , , , ,  5 5 5 5    X
    X? ? ?< < < !%")-
 
 
 
 
D !%)-    < (--
.
.CS    67 7 7 7   X   "
 
 
"S S S S*  $ $ $ ), = = = = = =
 #&? ? ? ? ? ?/ / /
* * *
# # #    	 	 	8 8 8 8 8 X8 
[+ + [+ 0 0 X0 \/ / \/@ @ @D D D D   X , , , \, ) ) \)? ? ? ?. . .
 
 
 

 
 
 
- - -* * *	+ 	+ 	+
 
 
       r/   c                      e Zd ZdZed             Zej        d             Zed             Zej        d             ZddZd	 Z	d
 Z
d ZddZddZd Zd ZdS )ShapeElementz:Elements which have a visible representation on the canvasc                D    t          |                                           S )zJGets the outline or path of the element, this may be a simple bounding box)r   get_pathrF   s    r-   pathzShapeElement.path  s     DMMOO$$$r/   c                0    |                      |           d S r)   )set_pathr<   r:  s     r-   r:  zShapeElement.path  s    dr/   c                h    |                      d          }|sdS | j                            |          S )zBGets the clip path element (if any)

        .. versionadded:: 1.1r   N)rl   r   r   r   s     r-   clipzShapeElement.clip  s8    
 hh{## 	4y'',,,r/   c                Z    |                      d|                    d                     d S )Nr   r   )r   )rc   r   r   s     r-   r?  zShapeElement.clip  s*    dkkk3344444r/   r2   r   c                2    t          d| j         d          )zAGenerate a path for this object which can inform the bounding boxz$Path should be provided by svg elem rk   )NotImplementedErrorrp   rF   s    r-   r9  zShapeElement.get_path  s$    !C4=CCC
 
 	
r/   c                8    t          d| j         d| d          )z*Set the path for this object (if possible)z%Path can not be set on this element: z <- rk   )ro   rp   r=  s     r-   r<  zShapeElement.set_path  s,    NDMNNtNNN
 
 	
r/   c                    ddl m}  |            }| j        |_        |                                 |_        | j        |_        |S )z(Replace this element with a path elementr   )PathElement)	_polygonsrE  r:  effective_stylerI   rH   )r<   rE  r0   s      r-   to_path_elementzShapeElement.to_path_element  sI    ******{}}I	))++
r/   c                    | j         S )z5Without parent styles, what is the effective style is)rI   rF   s    r-   rG  zShapeElement.effective_style  s
    zr/   Nc                    |                      |          }| j        }|||S ||                    t          |          | j        z            z  S )z|BoundingBox of the shape

        .. versionchanged:: 1.1
            result adjusted for element's clip path if applicable.)	shape_boxr?  bounding_boxr   rH   )r<   rH   rK  r?  s       r-   rL  zShapeElement.bounding_box  sT     NN9--	y<9,4,,Yy-A-ADN-RSSSSr/   c                   | j                                         }|du r(|                    |                                           }n1|                    | j                  }|r|                    |          }|                                S )zBoundingBox of the unclipped shape

        .. versionadded:: 1.1
            Previous :func:`bounding_box` function, returning the bounding box
            without computing the effect of a possible clip.T)r:  to_absoluterH   r'  rL  )r<   rH   r:  s      r-   rK  zShapeElement.shape_box  s     y$$&&>>$"9"9";";<<DD>>$.11D 1~~i00  """r/   c                    | j                             dd          dk    rdS t          | j                             dd                    sdS dS )zUReturns false if the css says this object is invisible

        .. versionadded:: 1.1displayr7   noneFopacityg      ?T)rI   rl   floatrF   s    r-   
is_visiblezShapeElement.is_visible  sN     :>>)R((F225TZ^^Is3344 	5tr/   c                    |                                  } |d          } |d          }t          |          }||dz  S |d         dk    r||d         z  dz  S |                     |          S )	zXReturns the specified value of line-height, in user units

        .. versionadded:: 1.1z	font-sizezline-heightNg333333?r   %r   g{Gz?)r  r   r  )r<   rI   	font_sizeline_heightparseds        r-   get_line_height_uuzShapeElement.get_line_height_uu  s     $$&&E+&&	eM**K((>s?"!9vay(4//$$[111r/   )r2   r   r)   )r\   r)  r*  r+  r-  r:  r3  r?  r9  r<  rH  rG  rL  rK  rT  rZ  r5   r/   r-   r7  r7    s       DD% % X% 
[  [ - - X- 
[5 5 [5
 
 
 

 
 
    
T 
T 
T 
T# # # #   2 2 2 2 2r/   r7  N)3r+  
__future__r   r   r   typingr   r   r   r   r	   r
   lxmlr   interfaces.IElementr   r   baser   pathsr   stylesr   r   
transformsr   r   utilsr   unitsr   r   r   _utilsr   r   r   r   r   
propertiesr   r    	_selectedr!   _parserr"   r#   r$   r%   ry   r7  r5   r/   r-   <module>ri     s  ,  # " " " " "       @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @       C C C C C C C C ! ! ! ! ! !       # # # # # # # # / / / / / / / / ! ! ! ! ! ! 9 9 9 9 9 9 9 9 9 9 B B B B B B B B B B B B B B 7 7 7 7 7 7 7 7 " " " " " " 0 0 0 0 0 0 0 0GC}%%%U	 U	 U	 U	 U	, U	 U	 U	p & f2 f2 f2 f2 f2; f2 f2 f2 f2 f2r/   