B
    |b,                @   s   d Z ddlZddlZddlZddlmZ ddlmZmZ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ZdZdZdZdZ dZ!dZ"dZ#e$de#Z%dZ&dZ'dZ(dZ)dZ*G dd deZ+dd Z,dS )z:mod:`wand.drawing` --- Drawings
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The module provides some vector drawing functions.

.. versionadded:: 0.3.0

    N   )
assertions)AffineMatrix	PointInfolibrary)Color)abcbinarystring_typetext	text_typexrange)WandLibraryVersionError)	BaseImageCOMPOSITE_OPERATORS)SingleImage)Resource)CLIP_PATH_UNITSFILL_RULE_TYPESFONT_METRICS_ATTRIBUTESGRAVITY_TYPESLINE_CAP_TYPESLINE_JOIN_TYPESPAINT_METHOD_TYPESSTRETCH_TYPESSTYLE_TYPESTEXT_ALIGN_TYPESTEXT_DECORATION_TYPESTEXT_DIRECTION_TYPESDrawingFontMetrics)Zundefined_path_unitsZ
user_spaceZuser_space_on_useZobject_bounding_box)	undefinedleftcenterright)r!   no	underlineoverlineZline_through)r!   right_to_leftZleft_to_right)ZforgetZ
north_westZnorthZ
north_eastZwestr#   ZeastZ
south_westZsouthZ
south_eastZstatic)r!   ZevenoddZnonzero)Zcharacter_widthZcharacter_heightZascenderZ	descender
text_widthZtext_heightZmaximum_horizontal_advancex1y1x2y2xyr    )r!   normalZultra_condensedZextra_condensedZ	condensedZsemi_condensedZsemi_expandedexpandedZextra_expandedZultra_expandedany)r!   r0   italicZobliquer2   )r!   ZbuttroundZsquare)r!   Zmiterr4   Zbevel)r!   pointreplaceZ	floodfillZfilltoborderresetc            	   @   sZ  e Zd ZdZejZejZej	Z
ejZdddZedd Zejdd Zedd	 Zejd
d	 Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zedd Zejdd Zed d! Zejd"d! Zed#d$ Zejd%d$ Zed&d' Zejd(d' Zed)d* Zejd+d* Zed,d- Zejd.d- Zed/d0 Zejd1d0 Zed2d3 Zejd4d3 Zed5d6 Z e jd7d6 Z ed8d9 Z!e!jd:d9 Z!ed;d< Z"e"jd=d< Z"ed>d? Z#e#jd@d? Z#edAdB Z$e$jdCdB Z$edDdE Z%e%jdFdE Z%edGdH Z&e&jdIdH Z&edJdK Z'e'jdLdK Z'edMdN Z(e(jdOdN Z(edPdQ Z)e)jdRdQ Z)edSdT Z*e*jdUdT Z*edVdW Z+e+jdXdW Z+edYdZ Z,e,jd[dZ Z,ed\d] Z-e-jd^d] Z-ed_d` Z.e.jdad` Z.edbdc Z/e/jdddc Z/ededf Z0e0jdgdf Z0edhdi Z1e1jdjdi Z1edkdl Z2e2jdmdl Z2dndo Z3ddqdrZ4dsdt Z5ddudvZ6dwdx Z7dydz Z8d{d| Z9dd~dZ:dddZ;dd Z<dd Z=dddZ>dddZ?dd Z@dddZAdd ZBdddZCdddZDdddZEdd ZFdddZGdddZHdddZIdd ZJdddZKdddZLdddZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdddZWdddZXdddZYdd ZZddÄ Z[dddńZ\ddǄ Z]dddɄZ^dd˄ Z_dd̈́ Z`dS )r   a  Drawing object.  It maintains several vector drawing instructions
    and can get drawn into zero or more :class:`~wand.image.Image` objects
    by calling it.

    For example, the following code draws a diagonal line to the ``image``::

        with Drawing() as draw:
            draw.line((0, 0), image.size)
            draw(image)

    :param drawing: an optional drawing object to clone.
                    use :meth:`clone()` method rather than this parameter
    :type drawing: :class:`Drawing`

    .. versionadded:: 0.3.0

    Nc          	   C   sX   |   F |st }n,t|t| s8tdt| nt|j}|| _W d Q R X d S )Nz5drawing must be a wand.drawing.Drawing instance, not )	allocater   ZNewDrawingWand
isinstancetype	TypeErrorreprZCloneDrawingWandresource)selfdrawingwand rA   O/home/ankuromar296_gmail_com/.local/lib/python3.7/site-packages/wand/drawing.py__init__   s    

zDrawing.__init__c             C   s.   t  }t | j| t|}t |}|S )z(:class:`~wand.color.Color`) the current border color. It also can
        be set. This attribute controls the behavior of
        :meth:`~wand.drawing.Drawing.color()` during ``'filltoborder'``
        operation.

        .. versionadded:: 0.4.0
        )r   NewPixelWandZDrawGetBorderColorr=   r   from_pixelwandDestroyPixelWand)r>   Z	pixelwandcolorrA   rA   rB   border_color   s
    	

zDrawing.border_colorc          	   C   sB   t |trt|}tj|d | t| j|j W d Q R X d S )N)rH   )r9   r
   r   r   assert_colorr   ZDrawSetBorderColorr=   )r>   rG   rA   rA   rB   rH      s
    
c             C   s0   d}t | j}|r,tt|}t |}|S )a	  (:class:`basestring`) The current clip path. It also can be set.

        .. versionadded:: 0.4.0

        .. versionchanged: 0.4.1
           Safely release allocated memory with
           :c:func:`MagickRelinquishMemory` instead of :c:func:`libc.free`.

        N)r   ZDrawGetClipPathr=   r   ctypes	string_atMagickRelinquishMemory)r>   Zclip_path_strZclip_path_prA   rA   rB   	clip_path   s    
zDrawing.clip_pathc             C   s"   t j|d t| jt| d S )N)rM   )r   assert_stringr   ZDrawSetClipPathr=   r	   )r>   pathrA   rA   rB   rM      s    c             C   s   t | j}t| S )z(:class:`basestring`) The current clip rule. It also can be set.
        It's a string value from :const:`FILL_RULE_TYPES` list.

        .. versionadded:: 0.4.0
        )r   ZDrawGetClipRuler=   r   )r>   	clip_rulerA   rA   rB   rP      s    zDrawing.clip_rulec             C   s(   t jtd|d t| jt| d S )Nzwand.drawing.FILL_RULE_TYPES)rP   )r   string_in_listr   r   ZDrawSetClipRuler=   index)r>   rP   rA   rA   rB   rP      s
    c             C   s   t | j}t| S )z(:class:`basestring`) The current clip units. It also can be set.
        It's a string value from :const:`CLIP_PATH_UNITS` list.

        .. versionadded:: 0.4.0
        )r   ZDrawGetClipUnitsr=   r   )r>   	clip_unitrA   rA   rB   
clip_units   s    zDrawing.clip_unitsc             C   s(   t jtd|d t| jt| d S )Nzwand.drawing.CLIP_PATH_UNITS)rS   )r   rQ   r   r   ZDrawSetClipUnitsr=   rR   )r>   rS   rA   rA   rB   rT     s
    c             C   s.   t  }t | j| t|}t |}|S )z](:class:`~wand.color.Color`) The current color to fill.
        It also can be set.

        )r   rD   ZDrawGetFillColorr=   r   rE   rF   )r>   pixelrG   rA   rA   rB   
fill_color  s
    

zDrawing.fill_colorc          	   C   sB   t |trt|}tj|d | t| j|j W d Q R X d S )N)rV   )r9   r
   r   r   rI   r   ZDrawSetFillColorr=   )r>   rG   rA   rA   rB   rV     s
    
c             C   s   t | jS )zx(:class:`~numbers.Real`) The current fill opacity.
        It also can be set.

        .. versionadded:: 0.4.0
        )r   ZDrawGetFillOpacityr=   )r>   rA   rA   rB   fill_opacity   s    zDrawing.fill_opacityc             C   s   t j|d t| j| d S )N)rW   )r   assert_realr   ZDrawSetFillOpacityr=   )r>   opacityrA   rA   rB   rW   )  s    c             C   s(   t | j}|tkr|   tt| S )z(:class:`basestring`) The current fill rule. It can also be set.
        It's a string value from :const:`FILL_RULE_TYPES` list.

        .. versionadded:: 0.4.0
        )r   ZDrawGetFillRuler=   r   raise_exceptionr   )r>   Zfill_rule_indexrA   rA   rB   	fill_rule.  s    zDrawing.fill_rulec             C   s(   t jtd|d t| jt| d S )Nzwand.drawing.FILL_RULE_TYPES)r[   )r   rQ   r   r   ZDrawSetFillRuler=   rR   )r>   r[   rA   rA   rB   r[   :  s
    c             C   s0   d}t | j}|r,tt|}t |}|S )z(:class:`basestring`) The current font name.  It also can be set.

        .. versionchanged: 0.4.1
           Safely release allocated memory with
           :c:func:`MagickRelinquishMemory` instead of :c:func:`libc.free`.

        N)r   ZDrawGetFontr=   r   rJ   rK   rL   )r>   Zfont_strZfont_prA   rA   rB   fontB  s    	
zDrawing.fontc             C   s"   t j|d t| jt| d S )N)r\   )r   rN   r   ZDrawSetFontr=   r	   )r>   r\   rA   rA   rB   r\   R  s    c             C   s0   d}t | j}|r,tt|}t |}|S )a  (:class:`basestring`) The current font family. It also can be set.

        .. versionadded:: 0.4.0

        .. versionchanged: 0.4.1
           Safely release allocated memory with
           :c:func:`MagickRelinquishMemory` instead of :c:func:`libc.free`.

        N)r   ZDrawGetFontFamilyr=   r   rJ   rK   rL   )r>   Zfont_family_strZfont_family_prA   rA   rB   font_familyW  s    
zDrawing.font_familyc             C   s"   t j|d t| jt| d S )N)r]   )r   rN   r   ZDrawSetFontFamilyr=   r	   )r>   familyrA   rA   rB   r]   i  s    c             C   s>   t dt d }}t| jt |t | |j|jfS )z(:class:`~collections.abc.Sequence`) The current font resolution. It also
        can be set.

        .. versionadded:: 0.4.0
        g        )rJ   c_doubler   ZDrawGetFontResolutionr=   byrefvalue)r>   r.   r/   rA   rA   rB   font_resolutionn  s
    zDrawing.font_resolutionc             C   s"   t j|d tj| jf|  d S )N)rb   )r   assert_coordinater   ZDrawSetFontResolutionr=   )r>   
resolutionrA   rA   rB   rb   {  s    c             C   s   t | jS )z;(:class:`numbers.Real`) The font size.  It also can be set.)r   ZDrawGetFontSizer=   )r>   rA   rA   rB   	font_size  s    zDrawing.font_sizec             C   s6   t j|d |dk r$tdt| t| j| d S )N)re   g        z!cannot be less than 0.0, but got )r   rX   
ValueErrorr<   r   ZDrawSetFontSizer=   )r>   sizerA   rA   rB   re     s    c             C   s   t | j}tt| S )z(:class:`basestring`) The current font stretch variation.
        It also can be set, but will only apply if the font-family or encoder
        supports the stretch type.

        .. versionadded:: 0.4.0
        )r   ZDrawGetFontStretchr=   r   r   )r>   Zstretch_indexrA   rA   rB   font_stretch  s    zDrawing.font_stretchc             C   s(   t jtd|d t| jt| d S )Nzwand.drawing.STRETCH_TYPES)rh   )r   rQ   r   r   ZDrawSetFontStretchr=   rR   )r>   ZstretchrA   rA   rB   rh     s
    c             C   s   t | j}tt| S )z(:class:`basestring`) The current font style.
        It also can be set, but will only apply if the font-family
        supports the style.

        .. versionadded:: 0.4.0
        )r   ZDrawGetFontStyler=   r   r   )r>   Zstyle_indexrA   rA   rB   
font_style  s    zDrawing.font_stylec             C   s(   t jtd|d t| jt| d S )Nzwand.drawing.STYLE_TYPES)ri   )r   rQ   r   r   ZDrawSetFontStyler=   rR   )r>   stylerA   rA   rB   ri     s
    c             C   s   t | jS )z{(:class:`~numbers.Integral`) The current font weight.
        It also can be set.

        .. versionadded:: 0.4.0
        )r   ZDrawGetFontWeightr=   )r>   rA   rA   rB   font_weight  s    zDrawing.font_weightc             C   s   t j|d t| j| d S )N)rk   )r   assert_integerr   ZDrawSetFontWeightr=   )r>   weightrA   rA   rB   rk     s    c             C   s$   t | j}|s|   tt| S )z(:class:`basestring`) The text placement gravity used when
        annotating with text.  It's a string from :const:`GRAVITY_TYPES`
        list.  It also can be set.

        )r   ZDrawGetGravityr=   rZ   r   r   )r>   Zgravity_indexrA   rA   rB   gravity  s    zDrawing.gravityc             C   s(   t jtd|d t| jt| d S )Nzwand.drawing.GRAVITY_TYPES)rn   )r   rQ   r   r   ZDrawSetGravityr=   rR   )r>   ra   rA   rA   rB   rn     s    c             C   s   t | jS )ai  (:class:`~numbers.Real`) returns the opacity used when drawing with
        the fill or stroke color or texture. Fully opaque is 1.0. This method
        only affects vector graphics, and is experimental. To set the opacity
        of a drawing, use
        :attr:`Drawing.fill_opacity` & :attr:`Drawing.stroke_opacity`

        .. versionadded:: 0.4.0
        )r   ZDrawGetOpacityr=   )r>   rA   rA   rB   rY     s    
zDrawing.opacityc             C   s   t j|d t| j| d S )N)rY   )r   rX   r   ZDrawSetOpacityr=   )r>   opaquerA   rA   rB   rY     s    c             C   s   t | j}t|S )aX  (:class:`bool`) Controls whether stroked outlines are antialiased.
        Stroked outlines are antialiased by default. When antialiasing is
        disabled stroked pixels are thresholded to determine if the stroke
        color or underlying canvas color should be used.

        It also can be set.

        .. versionadded:: 0.4.0

        )r   ZDrawGetStrokeAntialiasr=   bool)r>   stroke_antialiasrA   rA   rB   rq     s    zDrawing.stroke_antialiasc             C   s   t j|d t| j| d S )N)rq   )r   assert_boolr   ZDrawSetStrokeAntialiasr=   )r>   rq   rA   rA   rB   rq     s    c             C   s.   t  }t | j| t|}t |}|S )z(:class:`~wand.color.Color`) The current color of stroke.
        It also can be set.

        .. versionadded:: 0.3.3

        )r   rD   ZDrawGetStrokeColorr=   r   rE   rF   )r>   rU   rG   rA   rA   rB   stroke_color  s
    

zDrawing.stroke_colorc          	   C   sB   t |trt|}tj|d | t| j|j W d Q R X d S )N)rs   )r9   r
   r   r   rI   r   ZDrawSetStrokeColorr=   )r>   rG   rA   rA   rB   rs     s
    
c                sL   t d}t| jt | g } rH fddt|jD }t  |S )at  (:class:`~collections.abc.Sequence`) - (:class:`numbers.Real`) An
        array representing the pattern of dashes & gaps used to stroke paths.
        It also can be set.

        .. versionadded:: 0.4.0

        .. versionchanged: 0.4.1
           Safely release allocated memory with
           :c:func:`MagickRelinquishMemory` instead of :c:func:`libc.free`.

        r   c                s   g | ]}t  | qS rA   )float).0i)dash_array_prA   rB   
<listcomp>!  s   z-Drawing.stroke_dash_array.<locals>.<listcomp>)	rJ   c_size_tr   ZDrawGetStrokeDashArrayr=   r`   r   ra   rL   )r>   Znumber_elements
dash_arrayrA   )rw   rB   stroke_dash_array  s    


zDrawing.stroke_dash_arrayc             C   s*   t |}tj| | }t| j|| d S )N)lenrJ   r_   r   ZDrawSetStrokeDashArrayr=   )r>   rz   Zdash_array_lrw   rA   rA   rB   r{   &  s
    c             C   s   t | jS )zm(:class:`numbers.Real`) The stroke dash offset. It also can be set.

        .. versionadded:: 0.4.0
        )r   ZDrawGetStrokeDashOffsetr=   )r>   rA   rA   rB   stroke_dash_offset.  s    zDrawing.stroke_dash_offsetc             C   s   t j|d t| j| d S )N)r}   )r   rX   r   ZDrawSetStrokeDashOffsetr=   )r>   offsetrA   rA   rB   r}   6  s    c             C   s(   t | j}|tkr|   tt| S )zh(:class:`basestring`) The stroke line cap. It also can be set.

        .. versionadded:: 0.4.0
        )r   ZDrawGetStrokeLineCapr=   r   rZ   r   )r>   Zline_cap_indexrA   rA   rB   stroke_line_cap;  s    zDrawing.stroke_line_capc             C   s(   t jtd|d t| jt| d S )Nzwand.drawing.LINE_CAP_TYPES)r   )r   rQ   r   r   ZDrawSetStrokeLineCapr=   rR   )r>   Zline_caprA   rA   rB   r   F  s
    c             C   s(   t | j}|tkr|   tt| S )zi(:class:`basestring`) The stroke line join. It also can be set.

        .. versionadded:: 0.4.0
        )r   ZDrawGetStrokeLineJoinr=   r   rZ   r   )r>   Zline_join_indexrA   rA   rB   stroke_line_joinN  s    zDrawing.stroke_line_joinc             C   s(   t jtd|d t| jt| d S )Nzwand.drawing.LINE_JOIN_TYPES)r   )r   rQ   r   r   ZDrawSetStrokeLineJoinr=   rR   )r>   Z	line_joinrA   rA   rB   r   Y  s
    c             C   s   t | jS )z{(:class:`~numbers.Integral`) The current miter limit.
        It also can be set.

        .. versionadded:: 0.4.0
        )r   ZDrawGetStrokeMiterLimitr=   )r>   rA   rA   rB   stroke_miter_limita  s    zDrawing.stroke_miter_limitc             C   s   t j|d t| j| d S )N)r   )r   rl   r   ZDrawSetStrokeMiterLimitr=   )r>   Zmiter_limitrA   rA   rB   r   j  s    c             C   s   t | jS )zz(:class:`~numbers.Real`) The current stroke opacity.
        It also can be set.

        .. versionadded:: 0.4.0
        )r   ZDrawGetStrokeOpacityr=   )r>   rA   rA   rB   stroke_opacityo  s    zDrawing.stroke_opacityc             C   s   t j|d t| j| d S )N)r   )r   rX   r   ZDrawSetStrokeOpacityr=   )r>   rY   rA   rA   rB   r   x  s    c             C   s   t | jS )zi(:class:`numbers.Real`) The stroke width.  It also can be set.

        .. versionadded:: 0.3.3

        )r   ZDrawGetStrokeWidthr=   )r>   rA   rA   rB   stroke_width}  s    zDrawing.stroke_widthc             C   s6   t j|d |dk r$tdt| t| j| d S )N)r   g        z!cannot be less than 0.0, but got )r   rX   rf   r<   r   ZDrawSetStrokeWidthr=   )r>   widthrA   rA   rB   r     s    c             C   s$   t | j}|s|   tt| S )z(:class:`basestring`) The current text alignment setting.
        It's a string value from :const:`TEXT_ALIGN_TYPES` list.
        It also can be set.

        )r   ZDrawGetTextAlignmentr=   rZ   r   r   )r>   Ztext_alignment_indexrA   rA   rB   text_alignment  s    zDrawing.text_alignmentc             C   s(   t jtd|d t| jt| d S )Nzwand.drawing.TEXT_ALIGN_TYPES)r   )r   rQ   r   r   ZDrawSetTextAlignmentr=   rR   )r>   alignrA   rA   rB   r     s
    c             C   s   t | j}t|S )z(:class:`bool`) The boolean value which represents whether
        antialiasing is used for text rendering.  It also can be set to
        ``True`` or ``False`` to switch the setting.

        )r   ZDrawGetTextAntialiasr=   rp   )r>   resultrA   rA   rB   text_antialias  s    zDrawing.text_antialiasc             C   s   t j|d t| j| d S )N)r   )r   rr   r   ZDrawSetTextAntialiasr=   )r>   ra   rA   rA   rB   r     s    c             C   s$   t | j}|s|   tt| S )z(:class:`basestring`) The text decoration setting, a string
        from :const:`TEXT_DECORATION_TYPES` list.  It also can be set.

        )r   ZDrawGetTextDecorationr=   rZ   r   r   )r>   Ztext_decoration_indexrA   rA   rB   text_decoration  s    zDrawing.text_decorationc             C   s(   t jtd|d t| jt| d S )Nz"wand.drawing.TEXT_DECORATION_TYPES)r   )r   rQ   r   r   ZDrawSetTextDecorationr=   rR   )r>   Z
decorationrA   rA   rB   r     s
    c             C   s6   t jdkrtdt | j}|s*|   tt| S )z(:class:`basestring`) The text direction setting. a string
        from :const:`TEXT_DIRECTION_TYPES` list. It also can be set.NzBthe installed version of ImageMagick does not support this feature)r   DrawGetTextDirectionr   r=   rZ   r   r   )r>   Ztext_direction_indexrA   rA   rB   text_direction  s    
zDrawing.text_directionc             C   s:   t jd krtdtjtd|d t | jt| d S )NzBThe installed version of ImageMagick does not support this featurez!wand.drawing.TEXT_DIRECTION_TYPES)r   )	r   r   r   r   rQ   r   ZDrawSetTextDirectionr=   rR   )r>   	directionrA   rA   rB   r     s    
c             C   s0   d}t | j}|r,tt|}t |}|S )a&  (:class:`basestring`) The internally used text encoding setting.
        Although it also can be set, but it's not encouraged.

        .. versionchanged: 0.4.1
           Safely release allocated memory with
           :c:func:`MagickRelinquishMemory` instead of :c:func:`libc.free`.

        N)r   ZDrawGetTextEncodingr=   r   rJ   rK   rL   )r>   Ztext_encoding_strZtext_encoding_prA   rA   rB   text_encoding  s    

zDrawing.text_encodingc             C   s4   |d krd}nt j|d t|}t| j| d S )N    )r   )r   rN   r	   r   ZDrawSetTextEncodingr=   )r>   encodingrA   rA   rB   r     s
    c             C   s   t jdkrtdt | jS )zc(:class:`numbers.Real`) The setting of the text line spacing.
        It also can be set.

        NzBThe installed version of ImageMagick does not support this feature)r   ZDrawGetTextInterlineSpacingr   r=   )r>   rA   rA   rB   text_interline_spacing  s    
zDrawing.text_interline_spacingc             C   s0   t jd krtdtj|d t | j| d S )NzBThe installed version of ImageMagick does not support this feature)r   )r   ZDrawSetTextInterlineSpacingr   r   rX   r=   )r>   spacingrA   rA   rB   r     s    
c             C   s   t | jS )z^(:class:`numbers.Real`) The setting of the word spacing.
        It also can be set.

        )r   ZDrawGetTextInterwordSpacingr=   )r>   rA   rA   rB   text_interword_spacing  s    zDrawing.text_interword_spacingc             C   s   t j|d t| j| d S )N)r   )r   rX   r   ZDrawSetTextInterwordSpacingr=   )r>   r   rA   rA   rB   r     s    c             C   s   t | jS )z^(:class:`numbers.Real`) The setting of the text kerning.
        It also can be set.

        )r   ZDrawGetTextKerningr=   )r>   rA   rA   rB   text_kerning  s    zDrawing.text_kerningc             C   s   t j|d t| j| d S )N)r   )r   rX   r   ZDrawSetTextKerningr=   )r>   ZkerningrA   rA   rB   r   $  s    c             C   s.   t  }t | j| t|}t |}|S )z(:class:`~wand.color.Color`) The color of a background rectangle
        to place under text annotations.  It also can be set.

        )r   rD   ZDrawGetTextUnderColorr=   r   rE   rF   )r>   rU   rG   rA   rA   rB   text_under_color)  s
    

zDrawing.text_under_colorc          	   C   sB   t |trt|}tj|d | t| j|j W d Q R X d S )N)r   )r9   r
   r   r   rI   r   ZDrawSetTextUnderColorr=   )r>   rG   rA   rA   rB   r   5  s
    
c             C   s:   t | j}|r&t|}t |}nd}dt| d S )a  (:class:`basestring`) The XML text of the Vector Graphics.
        It also can be set.  The drawing-wand XML is experimental,
        and subject to change.

        Setting this property to None will reset all vector graphic properties
        to the default state.

        .. versionadded:: 0.4.0

        .. versionchanged: 0.4.1
           Safely release allocated memory with
           :c:func:`MagickRelinquishMemory` instead of :c:func:`libc.free`.

        r   z<wand>z</wand>)r   ZDrawGetVectorGraphicsr=   rJ   rK   rL   r   )r>   Zvg_pZvg_strrA   rA   rB   vector_graphics=  s    
zDrawing.vector_graphicsc             C   sd   |d k	r$t |ts$tdt| n<|d kr:t| j n&t|}t| j|}|dkr`t	dd S )Nzexpected a string, not r   zVector graphic not understood.)
r9   r
   r;   r<   r   ZDrawResetVectorGraphicsr=   r	   ZDrawSetVectorGraphicsrf   )r>   r   okayrA   rA   rB   r   U  s    c             C   s   t |tjrt|dkr tdx0t|D ]$\}}t |tjs*tdt	| q*W t
|d |d |d |d |d |d	 d
}t| jt| dS )au  Adjusts the current affine transformation matrix with the specified
        affine transformation matrix. Note that the current affine transform is
        adjusted rather than replaced.

        .. sourcecode:: text

                                              | sx  rx  0 |
            | x', y', 1 |  =  | x, y, 1 |  *  | ry  sy  0 |
                                              | tx  ty  1 |

        :param matrix: a list of :class:`~numbers.Real` to define affine
                       matrix ``[sx, rx, ry, sy, tx, ty]``
        :type matrix: :class:`collections.abc.Sequence`

        .. versionadded:: 0.4.0

           z*matrix must be a list of size Real numbersz$expecting numbers.Real in position #r   r               )sxrxryZsyZtxtyN)r9   r   Sequencer|   rf   	enumeratenumbersRealr;   r<   r   r   Z
DrawAffiner=   rJ   r`   )r>   ZmatrixidxvalZamxrA   rA   rB   affined  s    zDrawing.affiner!   c             C   sP   t jdkrtdtj||d tjtd|d t|}t | j||| dS )aJ  Paints on the image's opacity channel in order to set effected pixels
        to transparent.

         To influence the opacity of pixels. The available methods are:

        - ``'undefined'``
        - ``'point'``
        - ``'replace'``
        - ``'floodfill'``
        - ``'filltoborder'``
        - ``'reset'``

        .. note::

            This method replaces :meth:`matte()` in ImageMagick version 7.
            An :class:`AttributeError` will be raised if attempting
            to call on a library without ``DrawAlpha`` support.

        .. versionadded:: 0.5.0

        Nz[Method added with ImageMagick version 7. Please use `wand.drawing.Drawing.matte()' instead.)r.   r/   zwand.drawing.PAINT_METHOD_TYPES)paint_method)	r   Z	DrawAlphaAttributeErrorr   rX   rQ   r   rR   r=   )r>   r.   r/   r   oprA   rA   rB   alpha  s    

zDrawing.alphac       
   
   C   s\   t j|||d |\}}|\}}|\}}	t| jt|t|t|t|t|t|	 dS )a  Draws a arc using the current :attr:`stroke_color`,
        :attr:`stroke_width`, and :attr:`fill_color`.

        :param start: (:class:`~numbers.Real`, :class:`numbers.Real`)
                      pair which represents starting x and y of the arc
        :type start: :class:`~collections.abc.Sequence`
        :param end: (:class:`~numbers.Real`, :class:`numbers.Real`)
                      pair which represents ending x and y of the arc
        :type end: :class:`~collections.abc.Sequence`
        :param degree: (:class:`~numbers.Real`, :class:`numbers.Real`)
                      pair which represents starting degree, and ending degree
        :type degree: :class:`~collections.abc.Sequence`

        .. versionadded:: 0.4.0

        )startenddegreeN)r   rc   r   ZDrawArcr=   rt   )
r>   r   r   r   start_xstart_yend_xend_yZdegree_startZ
degree_endrA   rA   rB   arc  s    zDrawing.arcc          
   C   s.   t |\}}t| j|t|tt dS )ao  Draws a bezier curve through a set of points on the image, using
        the specified array of coordinates.

        At least four points should be given to complete a bezier path.
        The first & forth point being the start & end point, and the second
        & third point controlling the direction & curve.

        Example bezier on ``image`` ::

            with Drawing() as draw:
                points = [(40,10), # Start point
                          (20,50), # First control
                          (90,10), # Second control
                          (70,40)] # End point
                draw.stroke_color = Color('#000')
                draw.fill_color = Color('#fff')
                draw.bezier(points)
                draw.draw(image)

        :param points: list of x,y tuples
        :type points: :class:`list`

        .. versionadded:: 0.4.0

        N)_list_to_point_infor   Z
DrawBezierr=   rJ   castPOINTERr   )r>   pointspoints_lpoints_prA   rA   rB   bezier  s    
zDrawing.bezierc             C   s6   t j||d |\}}|\}}t| j|||| dS )a  Draws a circle from ``origin`` to ``perimeter``

        :param origin: (:class:`~numbers.Real`, :class:`numbers.Real`)
                       pair which represents origin x and y of circle
        :type origin: :class:`collections.abc.Sequence`
        :param perimeter: (:class:`~numbers.Real`, :class:`numbers.Real`)
                       pair which represents perimeter x and y of circle
        :type perimeter: :class:`collections.abc.Sequence`

        .. versionadded:: 0.4.0

        )origin	perimeterN)r   rc   r   Z
DrawCircler=   )r>   r   r   origin_xorigin_yZperimeter_xZperimeter_yrA   rA   rB   circle  s
    zDrawing.circlec             C   s   t | j d S )N)r   ZClearDrawingWandr=   )r>   rA   rA   rB   clear  s    zDrawing.clearc             C   s   t | | dS )zdCopies a drawing object.

        :returns: a duplication
        :rtype: :class:`Drawing`

        )r?   )r:   )r>   rA   rA   rB   clone  s    zDrawing.clone        c             C   s>   t j||d t jtd|d t|}t| j||| dS )an  Draws a color on the image using current fill color, starting
        at specified position & method.

        Available methods in :class:`wand.drawing.PAINT_METHOD_TYPES`:

        - ``'undefined'``
        - ``'point'``
        - ``'replace'``
        - ``'floodfill'``
        - ``'filltoborder'``
        - ``'reset'``

        .. versionadded:: 0.4.0

        )r.   r/   zwand.drawing.PAINT_METHOD_TYPES)r   N)r   rX   rQ   r   rR   r   Z	DrawColorr=   )r>   r.   r/   r   r   rA   rA   rB   rG     s    
zDrawing.colorc             C   s4   |dkrd}nt j|d t|}t| j| dS )zAdds a comment to the vector stream.

        :param message: the comment to set.
        :type message: :class:`basestring`

        .. versionadded:: 0.4.0
        Nr   )message)r   rN   r	   r   ZDrawCommentr=   )r>   r   rA   rA   rB   comment  s
    zDrawing.commentc          	   C   s^   t j|d t j||||d t jtd|d t|}t| j||||||j	 | 
  dS )a  Composites an image onto the current image, using the specified
        composition operator, specified position, and at the specified size.

        :param operator: the operator that affects how the composite
                         is applied to the image.  available values
                         can be found in the :const:`COMPOSITE_OPERATORS`
                         list
        :param type: :const:`COMPOSITE_OPERATORS`
        :param left: the column offset of the composited drawing source
        :type left: :class:`numbers.Real`
        :param top: the row offset of the composited drawing source
        :type top: :class:`numbers.Real`
        :param width: the total columns to include in the composited source
        :type width: :class:`numbers.Real`
        :param height: the total rows to include in the composited source
        :type height: :class:`numbers.Real`

        .. versionadded:: 0.4.0

        )operator)r"   topr   heightz wand.drawing.COMPOSITE_OPERATORSN)r   rN   rX   rQ   r   rR   r   ZDrawCompositer=   r@   rZ   )r>   r   r"   r   r   r   imager   rA   rA   rB   	composite!  s    

zDrawing.compositec             C   s   t |tstdt| t |trht|jj}t	|jj|j
 t|jj| j}t	|jj| nt|j| j}|s|   dS )a  Renders the current drawing into the ``image``.  You can simply
        call :class:`Drawing` instance rather than calling this method.
        That means the following code which calls :class:`Drawing` object
        itself::

            drawing(image)

        is equivalent to the following code which calls :meth:`draw()` method::

            drawing.draw(image)

        :param image: the image to be drawn
        :type image: :class:`~wand.image.BaseImage`

        z3image must be a wand.image.BaseImage instance, not N)r9   r   r;   r<   r   r   ZMagickGetIteratorIndex	containerr@   ZMagickSetIteratorIndexrR   ZMagickDrawImager=   rZ   )r>   r   previousresrA   rA   rB   draw@  s    

zDrawing.drawc       
   	   C   sP   |dkrd}t j|||d |\}}|\}}|\}}	t| j||||||	 dS )a6  Draws a ellipse at ``origin`` with independent x & y ``radius``.
        Ellipse can be partial by setting start & end ``rotation``.

        :param origin: (:class:`~numbers.Real`, :class:`numbers.Real`)
                       pair which represents origin x and y of circle
        :type origin: :class:`collections.abc.Sequence`
        :param radius: (:class:`~numbers.Real`, :class:`numbers.Real`)
                       pair which represents radius x and radius y of circle
        :type radius: :class:`collections.abc.Sequence`
        :param rotation: (:class:`~numbers.Real`, :class:`numbers.Real`)
                         pair which represents start and end of ellipse.
                         Default (0,360)
        :type rotation: :class:`collections.abc.Sequence`

        .. versionadded:: 0.4.0

        N)r   ih  )r   radiusrotation)r   rc   r   ZDrawEllipser=   )
r>   r   r   r   r   r   Zradius_xZradius_yZrotation_startZrotation_endrA   rA   rB   ellipse]  s    zDrawing.ellipseFc                s   t |tstdt| tj|d |r2tj}ntj}t |t	r^| j
rV|| j
}nt|}||j| j|  s|   |  td fddtdD }t  t| S )aQ  Queries font metrics from the given ``text``.

        :param image: the image to be drawn
        :type image: :class:`~wand.image.BaseImage`
        :param text: the text string for get font metrics.
        :type text: :class:`basestring`
        :param multiline: text is multiline or not
        :type multiline: `boolean`

        z3image must be a wand.image.BaseImage instance, not )r   z(Unable to render text with current font.c                s   g | ]} | qS rA   rA   )ru   rv   )r   rA   rB   rx     s    z,Drawing.get_font_metrics.<locals>.<listcomp>   )r9   r   r;   r<   r   rN   r   ZMagickQueryMultilineFontMetricsZMagickQueryFontMetricsr   r   encoder	   r@   r=   rZ   rf   r   rL   r    )r>   r   r   	multilineZfont_metrics_fargsrA   )r   rB   get_font_metrics{  s&    


zDrawing.get_font_metricsc             C   s8   |\}}|\}}t | jt|t|t|t| dS )a  Draws a line ``start`` to ``end``.

        :param start: (:class:`~numbers.Integral`, :class:`numbers.Integral`)
                      pair which represents starting x and y of the line
        :type start: :class:`collections.abc.Sequence`
        :param end: (:class:`~numbers.Integral`, :class:`numbers.Integral`)
                    pair which represents ending x and y of the line
        :type end: :class:`collections.abc.Sequence`

        N)r   ZDrawLiner=   int)r>   r   r   r   r   r   r   rA   rA   rB   line  s
    zDrawing.linec             C   sP   t jdkrtdtj||d tjtd|d t|}t | j||| dS )aU  Paints on the image's opacity channel in order to set effected pixels
        to transparent.

         To influence the opacity of pixels. The available methods are:

        - ``'undefined'``
        - ``'point'``
        - ``'replace'``
        - ``'floodfill'``
        - ``'filltoborder'``
        - ``'reset'``

        .. note::

            This method has been replace by :meth:`alpha()` in ImageMagick
            version 7. An :class:`AttributeError` will be raised if attempting
            to call on a library without ``DrawMatte`` support.

        .. versionadded:: 0.4.0

        Nz[Method removed from ImageMagick version. Please use `wand.drawing.Drawing.alpha()' instead.)r.   r/   zwand.drawing.PAINT_METHOD_TYPES)r   )	r   Z	DrawMatter   r   rX   rQ   r   rR   r=   )r>   r.   r/   r   r   rA   rA   rB   matte  s    

zDrawing.mattec             C   s   t | j | S )zAdds a path element to the current path which closes
        the current subpath by drawing a straight line from the current point
        to the current subpath's most recent starting point.

        .. versionadded:: 0.4.0

        )r   ZDrawPathCloser=   )r>   rA   rA   rB   
path_close  s    zDrawing.path_closec          	   C   s   |dkrt d|dkr t d|\}}|r6|\}}n|\\}	}
\}}|rz|rdt| j|||| qt| j|||| n6|rt| j|	|
|||| nt| j|	|
|||| | S )a4  Draws a cubic Bezier curve from the current point to given ``to``
        (x,y) coordinate using ``controls`` points at the beginning and
        the end of the curve.
        If ``smooth`` is set to True, only one ``controls`` is expected
        and the previous control is used, else two pair of coordinates are
        expected to define the control points. The ``to`` coordinate then
        becomes the new current point.

        :param to: (:class:`~numbers.Real`, :class:`numbers.Real`)
                   pair which represents coordinates to draw to
        :type to: :class:`collections.abc.Sequence`
        :param controls: (:class:`~numbers.Real`, :class:`numbers.Real`)
                         coordinate to used to influence curve
        :type controls: :class:`collections.abc.Sequence`
        :param smooth: :class:`bool` assume last defined control coordinate
        :type smooth: :class:`bool`
        :param relative: treat given coordinates as relative to current point
        :type relative: :class:`bool`

        .. versionadded:: 0.4.0

        Nzto is missingzcontrols is missing)r;   r   ZDrawPathCurveToSmoothRelativer=   ZDrawPathCurveToSmoothAbsoluteZDrawPathCurveToRelativeZDrawPathCurveToAbsolute)r>   tocontrolssmoothrelativer.   r/   r,   r-   r*   r+   rA   rA   rB   
path_curve  s(    
zDrawing.path_curvec       	      C   s   |dkrt d|\}}|rT|r:t| jt|t| qt| jt|t| nf|dkrdt d|\}}|rt| jt|t|t|t| n$t| jt|t|t|t| | S )a  Draws a quadratic Bezier curve from the current point to given
        ``to`` coordinate. The control point is assumed to be the reflection of
        the control point on the previous command if ``smooth`` is True, else a
        pair of ``control`` coordinates must be given. Each coordinates can be
        relative, or absolute, to the current point by setting the ``relative``
        flag. The ``to`` coordinate then becomes the new current point, and the
        ``control`` coordinate will be assumed when called again
        when ``smooth`` is set to true.

        :param to: (:class:`~numbers.Real`, :class:`numbers.Real`)
                   pair which represents coordinates to draw to
        :type to: :class:`collections.abc.Sequence`
        :param control: (:class:`~numbers.Real`, :class:`numbers.Real`)
                        coordinate to used to influence curve
        :type control: :class:`collections.abc.Sequence`
        :param smooth: assume last defined control coordinate
        :type smooth: :class:`bool`
        :param relative: treat given coordinates as relative to current point
        :type relative: :class:`bool`

        .. versionadded:: 0.4.0

        Nzto is missingzcontrol is missing)r;   r   Z,DrawPathCurveToQuadraticBezierSmoothRelativer=   rt   Z,DrawPathCurveToQuadraticBezierSmoothAbsoluteZ&DrawPathCurveToQuadraticBezierRelativeZ&DrawPathCurveToQuadraticBezierAbsolute)	r>   r   controlr   r   r.   r/   r*   r+   rA   rA   rB   path_curve_to_quadratic_bezier  s0    
z&Drawing.path_curve_to_quadratic_bezierc             C   s   |dkrt d|dkr t d|\}}|\}	}
|rlt| jt|	t|
t|t|t|t|t| n6t| jt|	t|
t|t|t|t|t| | S )a  Draws an elliptical arc from the current point to given ``to``
        coordinates. The ``to`` coordinates can be relative, or absolute,
        to the current point by setting the ``relative`` flag.
        The size and orientation of the ellipse are defined by
        two radii (rx, ry) in ``radius`` and an ``rotation`` parameters,
        which indicates how the ellipse as a whole is
        rotated relative to the current coordinate system. The center of the
        ellipse is calculated automagically to satisfy the constraints imposed
        by the other parameters. ``large_arc`` and ``clockwise`` contribute to
        the automatic calculations and help determine how the arc is drawn.
        If ``large_arc`` is True then draw the larger of the available arcs.
        If ``clockwise`` is true, then draw the arc matching a clock-wise
        rotation.

        :param to: (:class:`~numbers.Real`, :class:`numbers.Real`)
                   pair which represents coordinates to draw to
        :type to: :class:`collections.abc.Sequence`
        :param radius: (:class:`~numbers.Real`, :class:`numbers.Real`)
                       pair which represents the radii of the ellipse to draw
        :type radius: :class:`collections.abc.Sequence`
        :param rotate: degree to rotate ellipse on x-axis
        :type rotate: :class:`~numbers.Real`
        :param large_arc: draw largest available arc
        :type large_arc: :class:`bool`
        :param clockwise: draw arc path clockwise from start to target
        :type clockwise: :class:`bool`
        :param relative: treat given coordinates as relative to current point
        :type relative: :class:`bool`

        .. versionadded:: 0.4.0

        Nzto is missingzradius is missing)r;   r   ZDrawPathEllipticArcRelativer=   rt   rp   ZDrawPathEllipticArcAbsolute)r>   r   r   r   Z	large_arcZ	clockwiser   r.   r/   r   r   rA   rA   rB   path_elliptic_arcF  s(    "zDrawing.path_elliptic_arcc             C   s   t | j | S )zGTerminates the current path.

        .. versionadded:: 0.4.0

        )r   ZDrawPathFinishr=   )r>   rA   rA   rB   path_finish~  s    zDrawing.path_finishc             C   s2   t j|d |r t| j| nt| j| | S )a<  Draws a horizontal line path from the current point to the target
        point. Given ``x`` parameter can be relative, or absolute, to the
        current point by setting the ``relative`` flag. The target point then
        becomes the new current point.

        :param x: :class:`~numbers.Real`
                      x-axis point to draw to.
        :type x: :class:`~numbers.Real`
        :param relative: :class:`bool`
                    treat given point as relative to current point
        :type relative: :class:`bool`

        .. versionadded:: 0.4.0

        )r.   )r   rX   r   Z DrawPathLineToHorizontalRelativer=   Z DrawPathLineToHorizontalAbsolute)r>   r.   r   rA   rA   rB   path_horizontal_line  s
    zDrawing.path_horizontal_linec             C   s>   t j|d |\}}|r*t| j|| nt| j|| | S )a|  Draws a line path from the current point to the given ``to``
        coordinate. The ``to`` coordinates can be relative, or absolute, to the
        current point by setting the ``relative`` flag. The coordinate then
        becomes the new current point.

        :param to: (:class:`~numbers.Real`, :class:`numbers.Real`)
                      pair which represents coordinates to draw to.
        :type to: :class:`collections.abc.Sequence`
        :param relative: :class:`bool`
                    treat given coordinates as relative to current point
        :type relative: :class:`bool`

        .. versionadded:: 0.4.0

        )r   )r   rc   r   ZDrawPathLineToRelativer=   ZDrawPathLineToAbsolute)r>   r   r   r.   r/   rA   rA   rB   	path_line  s    zDrawing.path_linec             C   s>   t j|d |\}}|r*t| j|| nt| j|| | S )a  Starts a new sub-path at the given coordinates. Given ``to``
        parameter can be relative, or absolute, by setting the ``relative``
        flag.

        :param to: (:class:`~numbers.Real`, :class:`numbers.Real`)
                      pair which represents coordinates to draw to.
        :type to: :class:`collections.abc.Sequence`
        :param relative: :class:`bool`
                    treat given coordinates as relative to current point
        :type relative: :class:`bool`

        .. versionadded:: 0.4.0

        )r   )r   rc   r   ZDrawPathMoveToRelativer=   ZDrawPathMoveToAbsolute)r>   r   r   r.   r/   rA   rA   rB   	path_move  s    zDrawing.path_movec             C   s   t | j | S )a  Declares the start of a path drawing list which is terminated by a
        matching :meth:`path_finish()` command. All other `path_*` commands
        must be enclosed between a :meth:`path_start()` and a
        :meth:`path_finish()` command. This is because path drawing commands
        are subordinate commands and they do not function by themselves.

        .. versionadded:: 0.4.0

        )r   ZDrawPathStartr=   )r>   rA   rA   rB   
path_start  s    
zDrawing.path_startc             C   s2   t j|d |r t| j| nt| j| | S )a:  Draws a vertical line path from the current point to the target
        point. Given ``y`` parameter can be relative, or absolute, to the
        current point by setting the ``relative`` flag. The target point then
        becomes the new current point.

        :param y: :class:`~numbers.Real`
                      y-axis point to draw to.
        :type y: :class:`~numbers.Real`
        :param relative: :class:`bool`
                    treat given point as relative to current point
        :type relative: :class:`bool`

        .. versionadded:: 0.4.0

        )r/   )r   rX   r   ZDrawPathLineToVerticalRelativer=   ZDrawPathLineToVerticalAbsolute)r>   r/   r   rA   rA   rB   path_vertical_line  s
    zDrawing.path_vertical_linec          
   C   s.   t |\}}t| j|t|tt dS )a  Draws a polygon using the current :attr:`stroke_color`,
        :attr:`stroke_width`, and :attr:`fill_color`, using the specified
        array of coordinates.

        Example polygon on ``image`` ::

            with Drawing() as draw:
                points = [(40,10), (20,50), (90,10), (70,40)]
                draw.polygon(points)
                draw.draw(image)

        :param points: list of x,y tuples
        :type points: :class:`list`

        .. versionadded:: 0.4.0

        N)r   r   ZDrawPolygonr=   rJ   r   r   r   )r>   r   r   r   rA   rA   rB   polygon  s    
zDrawing.polygonc          
   C   s.   t |\}}t| j|t|tt dS )a  Draws a polyline using the current :attr:`stroke_color`,
        :attr:`stroke_width`, and :attr:`fill_color`, using the specified
        array of coordinates.

        Identical to :class:`~wand.drawing.Drawing.polygon`, but without closed
        stroke line.

        :param points: list of x,y tuples
        :type points: :class:`list`

        .. versionadded:: 0.4.0

        N)r   r   ZDrawPolyliner=   rJ   r   r   r   )r>   r   r   r   rA   rA   rB   polyline  s    
zDrawing.polylinec             C   s"   t j||d t| j|| dS )a
  Draws a point at given ``x`` and ``y``

        :param x: :class:`~numbers.Real` x of point
        :type x: :class:`~numbers.Real`
        :param y: :class:`~numbers.Real` y of point
        :type y: :class:`~numbers.Real`

        .. versionadded:: 0.4.0

        )r.   r/   N)r   rX   r   Z	DrawPointr=   )r>   r.   r/   rA   rA   rB   r5     s    zDrawing.pointc             C   s    t t| j}|s|   |S )a  Pop destroys the current tip of the drawing context stack,
        and restores the parent style context.
        See :meth:`push()` method for an example.

        .. note::

            Popping the graphical context stack will not erase,
            or alter, any previously executed drawing commands.

        :returns: success of pop operation.
        :rtype: :class:`bool`

        .. versionadded:: 0.4.0

        )rp   r   ZPopDrawingWandr=   rZ   )r>   okrA   rA   rB   pop)  s    zDrawing.popc             C   s   t | j dS )zMTerminates a clip path definition.

        .. versionadded:: 0.4.0

        N)r   ZDrawPopClipPathr=   )r>   rA   rA   rB   pop_clip_path>  s    zDrawing.pop_clip_pathc             C   s   t | j dS )zHTerminates a definition list.

        .. versionadded:: 0.4.0

        N)r   ZDrawPopDefsr=   )r>   rA   rA   rB   pop_defsF  s    zDrawing.pop_defsc             C   s   t | j dS )zKTerminates a pattern definition.

        .. versionadded:: 0.4.0

        N)r   ZDrawPopPatternr=   )r>   rA   rA   rB   pop_patternN  s    zDrawing.pop_patternc             C   s    t t| j}|s|   |S )a#  Grows the current drawing context stack by one, and inherits
        the previous style attributes. Use :class:`Drawing.pop` to return
        to restore previous style attributes.

        This is useful for drawing shapes with diffrent styles
        without repeatedly setting the similar
        :meth:`fill_color <wand.drawing.Drawing.fill_color>` &
        :meth:`stroke_color <wand.drawing.Drawing.stroke_color>` properties.

        For example::

            with Drawing() as ctx:
                ctx.fill_color = Color('GREEN')
                ctx.stroke_color = Color('ORANGE')
                ctx.push()
                ctx.fill_color = Color('RED')
                ctx.text(x1, y1, 'this is RED with ORANGE outline')
                ctx.push()
                ctx.stroke_color = Color('BLACK')
                ctx.text(x2, y2, 'this is RED with BLACK outline')
                ctx.pop()
                ctx.pop()
                ctx.text(x3, y3, 'this is GREEN with ORANGE outline')

        Which translate to the following MVG::

            push graphic-context
                fill "GREEN"
                stroke "ORANGE"
                push graphic-context
                    fill "RED"
                    text x1,y1 "this is RED with ORANGE outline"
                    push graphic-context
                        stroke "BLACK"
                        text x2,y2 "this is RED with BLACK outline"
                    pop graphic-context
                pop graphic-context
                text x3,y3 "this is GREEN with ORANGE outline"
            pop graphic-context

        .. note::

            Pushing graphical context does not reset any previously
            drawn artifacts.

        :returns: success of push operation.
        :rtype: :class:`bool`

        .. versionadded:: 0.4.0

        )rp   r   ZPushDrawingWandr=   rZ   )r>   r   rA   rA   rB   pushV  s    4zDrawing.pushc             C   s   t | jt| dS )aJ  Starts a clip path definition which is comprised of any number of
        drawing commands and terminated by a :class:`Drawing.pop_clip_path`
        command.

        :param clip_mask_id: string identifier to associate with the clip path.
        :type clip_mask_id: :class:`basestring`

        .. versionadded:: 0.4.0

        N)r   ZDrawPushClipPathr=   r	   )r>   Zclip_mask_idrA   rA   rB   push_clip_path  s    zDrawing.push_clip_pathc             C   s   t | j dS )a  Indicates that commands up to a terminating :class:`Drawing.pop_defs`
        command create named elements (e.g. clip-paths, textures, etc.) which
        may safely be processed earlier for the sake of efficiency.

        .. versionadded:: 0.4.0

        N)r   ZDrawPushDefsr=   )r>   rA   rA   rB   	push_defs  s    zDrawing.push_defsc             C   sL   t j|d t j||||d t| jt|||||}|sD|   t|S )a  Indicates that subsequent commands up to a
        :class:`Drawing.pop_pattern` command comprise the definition of a named
        pattern. The pattern space is assigned top left corner coordinates, a
        width and height, and becomes its own drawing space. Anything which can
        be drawn may be used in a pattern definition.
        Named patterns may be used as stroke or brush definitions.

        :param pattern_id: a unique identifier for the pattern.
        :type pattern_id: :class:`basestring`
        :param left: x ordinate of top left corner.
        :type left: :class:`numbers.Real`
        :param top: y ordinate of top left corner.
        :type top: :class:`numbers.Real`
        :param width: width of pattern space.
        :type width: :class:`numbers.Real`
        :param height: height of pattern space.
        :type height: :class:`numbers.Real`
        :returns: success of push operation
        :rtype: :class:`bool`

        .. versionadded:: 0.4.0

        )
pattern_id)r"   r   r   r   )	r   rN   rX   r   ZDrawPushPatternr=   r	   rZ   rp   )r>   r   r"   r   r   r   r   rA   rA   rB   push_pattern  s    zDrawing.push_patternc
       
   	   C   s  |dkrt dn^|dkr(t dnJ|dkrD|dkrDt dn.|dkr`|dkr`t dn|dksz|dkszt dn|dks|dkst dnt|tjst dt| nt|tjst d	t| n|dkst|tjst d
t| n||dks t|tjs t dt| nR|dksJt|tjsJt dt| n(|dksrt|tjsrt dt| |dkr|dk rtdt| || }n||k rtd|||dkr|dk rtdt| || }n||k rtd|||dk	r| }}	|dk	s(|	dk	rl|dkr6d}|	dkrDd}	tj||	d t	
| j||||||	 nt	| j|||| |   dS )a
  Draws a rectangle using the current :attr:`stroke_color`,
        :attr:`stroke_width`, and :attr:`fill_color`.

        .. sourcecode:: text

           +--------------------------------------------------+
           |              ^                         ^         |
           |              |                         |         |
           |             top                        |         |
           |              |                         |         |
           |              v                         |         |
           | <-- left --> +-------------------+  bottom       |
           |              |             ^     |     |         |
           |              | <-- width --|---> |     |         |
           |              |           height  |     |         |
           |              |             |     |     |         |
           |              |             v     |     |         |
           |              +-------------------+     v         |
           | <--------------- right ---------->               |
           +--------------------------------------------------+

        :param left: x-offset of the rectangle to draw
        :type left: :class:`numbers.Real`
        :param top: y-offset of the rectangle to draw
        :type top: :class:`numbers.Real`
        :param right: second x-offset of the rectangle to draw.
                      this parameter and ``width`` parameter are exclusive
                      each other
        :type right: :class:`numbers.Real`
        :param bottom: second y-offset of the rectangle to draw.
                       this parameter and ``height`` parameter are exclusive
                       each other
        :type bottom: :class:`numbers.Real`
        :param width: the :attr:`width` of the rectangle to draw.
                      this parameter and ``right`` parameter are exclusive
                      each other
        :type width: :class:`numbers.Real`
        :param height: the :attr:`height` of the rectangle to draw.
                       this parameter and ``bottom`` parameter are exclusive
                       each other
        :type height: :class:`numbers.Real`
        :param radius: the corner rounding. this is a short-cut for setting
                       both :attr:`xradius`, and :attr:`yradius`
        :type radius: :class:`numbers.Real`
        :param xradius: the :attr:`xradius` corner in horizontal direction.
        :type xradius: :class:`numbers.Real`
        :param yradius: the :attr:`yradius` corner in vertical direction.
        :type yradius: :class:`numbers.Real`

        .. versionadded:: 0.3.6

        .. versionchanged:: 0.4.0
           Radius keywords added to create rounded rectangle.

        Nzleft is missingztop is missingzright/width is missingzbottom/height is missingzFparameters right and width are exclusive each other; use one at a timezHparameters bottom and height are exclusive each other; use one at a timezleft must be numbers.Real, not ztop must be numbers.Real, not z right must be numbers.Real, not z!bottom must be numbers.Real, not z width must be numbers.Real, not z!height must be numbers.Real, not r   zwidth must be positive, not z0right must be more than left ({0!r}), not {1!r})zheight must be positive, not z0bottom must be more than top ({0!r}), not {1!r})g        )xradiusyradius)r;   r9   r   r   r<   rf   formatr   rX   r   ZDrawRoundRectangler=   ZDrawRectanglerZ   )
r>   r"   r   r$   bottomr   r   r   r   r   rA   rA   rB   	rectangle  sf    :















zDrawing.rectanglec             C   s   t j|d t| j| dS )zApplies the specified rotation to the current coordinate space.

        :param degree: degree to rotate
        :type degree: :class:`~numbers.Real`

        .. versionadded:: 0.4.0

        )r   N)r   rX   r   Z
DrawRotater=   )r>   r   rA   rA   rB   rotate8  s    	zDrawing.rotate      ?c             C   s"   t j||d t| j|| dS )ak  
        Adjusts the scaling factor to apply in the horizontal and vertical
        directions to the current coordinate space.

        :param x: Horizontal scale factor. Default `1.0`
        :type x: :class:`~numbers.Real`
        :param y: Vertical scale factor. Default `1.0`
        :type y: :class:`~numbers.Real`

        .. versionadded:: 0.4.0

        )r.   r/   N)r   rX   r   Z	DrawScaler=   )r>   r.   r/   rA   rA   rB   scaleD  s    zDrawing.scalec             C   s>   t j|d |d dkr tdt| jt| |   dS )a  Sets the URL to use as a fill pattern for filling objects. Only local
        URLs ("#identifier") are supported at this time. These local URLs are
        normally created by defining a named fill pattern with
        Drawing.push_pattern & Drawing.pop_pattern.

        :param url: URL to use to obtain fill pattern.
        :type url: :class:`basestring`

        .. versionadded:: 0.4.0

        )urlr   #z1value not a relative URL, expecting "#identifier"N)r   rN   rf   r   ZDrawSetFillPatternURLr=   r	   rZ   )r>   r   rA   rA   rB   set_fill_pattern_urlT  s
    zDrawing.set_fill_pattern_urlc             C   s>   t j|d |d dkr tdt| jt| |   dS )a  Sets the pattern used for stroking object outlines. Only local
        URLs ("#identifier") are supported at this time. These local URLs are
        normally created by defining a named stroke pattern with
        Drawing.push_pattern & Drawing.pop_pattern.

        :param url: URL to use to obtain stroke pattern.
        :type url: :class:`basestring`

        .. versionadded:: 0.4.0

        )r   r   r   z1value not a relative URL, expecting "#identifier"N)r   rN   rf   r   ZDrawSetStrokePatternURLr=   r	   rZ   )r>   r   rA   rA   rB   set_stroke_pattern_urlg  s
    zDrawing.set_stroke_pattern_urlc             C   sH   |dk	r"t j|d t| j| |dk	rDt j|d t| j| dS )aV  Skews the current coordinate system in the horizontal direction if
        ``x`` is given, and vertical direction if ``y`` is given.

        :param x: Skew horizontal direction
        :type x: :class:`~numbers.Real`
        :param y: Skew vertical direction
        :type y: :class:`~numbers.Real`

        .. versionadded:: 0.4.0

        N)r.   )r/   )r   rX   r   Z	DrawSkewXr=   Z	DrawSkewY)r>   r.   r/   rA   rA   rB   skewz  s    zDrawing.skewc             C   sx   t j||d t j|d |s&tdt|trH| js<d| _|| j}t	|}t
| j||t|ttj dS )a]  Writes a text ``body`` into (``x``, ``y``).

        :param x: the left offset where to start writing a text
        :type x: :class:`numbers.Integral`
        :param y: the baseline where to start writing text
        :type y: :class:`numbers.Integral`
        :param body: the body string to write
        :type body: :class:`basestring`

        )r.   r/   )bodyzbody string cannot be emptyzUTF-8N)r   Zassert_unsigned_integerrN   rf   r9   r   r   r   rJ   create_string_bufferr   ZDrawAnnotationr=   r   r   c_ubyte)r>   r.   r/   r   Zbody_prA   rA   rB   r     s    

zDrawing.textc             C   s"   t j||d t| j|| dS )aU  Applies a translation to the current coordinate system which moves
        the coordinate system origin to the specified coordinate.

        :param x: Skew horizontal direction
        :type x: :class:`~numbers.Real`
        :param y: Skew vertical direction
        :type y: :class:`~numbers.Real`

        .. versionadded:: 0.4.0
        )r.   r/   N)r   rX   r   ZDrawTranslater=   )r>   r.   r/   rA   rA   rB   	translate  s    zDrawing.translatec             C   s*   t j||||d t| j|||| dS )a)  Viewbox sets the overall canvas size to be recorded with the drawing
        vector data. Usually this will be specified using the same size as the
        canvas image. When the vector data is saved to SVG or MVG formats, the
        viewbox is use to specify the size of the canvas image that a viewer
        will render the vector data on.

        :param left: the left most point of the viewbox.
        :type left: :class:`~numbers.Integral`
        :param top: the top most point of the viewbox.
        :type top: :class:`~numbers.Integral`
        :param right: the right most point of the viewbox.
        :type right: :class:`~numbers.Integral`
        :param bottom: the bottom most point of the viewbox.
        :type bottom: :class:`~numbers.Integral`

        .. versionadded:: 0.4.0

        )r"   r   r$   r   N)r   rl   r   ZDrawSetViewboxr=   )r>   r"   r   r$   r   rA   rA   rB   viewbox  s    
zDrawing.viewboxc             C   s
   |  |S )N)r   )r>   r   rA   rA   rB   __call__  s    zDrawing.__call__)N)NNr!   )N)r   r   r!   )N)N)F)r   r   r!   )NNFF)NNFF)NNr   FFF)NF)NF)NF)NF)N)N)	NNNNNNNNN)r   )r   r   )NN)r   r   )a__name__
__module____qualname____doc__r   ZIsDrawingWandZc_is_resourceZDestroyDrawingWandZc_destroy_resourceZDrawGetExceptionZc_get_exceptionZDrawClearExceptionZc_clear_exceptionrC   propertyrH   setterrM   rP   rT   rV   rW   r[   r\   r]   rb   re   rh   ri   rk   rn   rY   rq   rs   r{   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rG   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r5   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  rA   rA   rA   rB   r      s   


					
	
"
	



$
"
1 
7 
7	





9
!  
o



r   c             C   sz   t | tstdt|  t| }d}|| }tj|  }x6t|D ]*}|| }|| }t| | | ||< qDW ||fS )a  
    Helper method to convert a list of tuples to ``const * PointInfo``

    :param points: a list of tuples
    :type points: `list`
    :returns: tuple of point length and c_double array
    :rtype: `tuple`
    :raises: `TypeError`

    .. versionadded:: 0.4.0

    zpoints must be a list, not r   )r9   listr;   r<   r|   rJ   r_   r   )r   Zpoint_length
tuple_sizeZpoint_info_sizeZ
point_infoZdouble_indexZtuple_indexZtuple_offsetrA   rA   rB   r     s    
r   )-r	  collectionsrJ   r    r   apir   r   r   rG   r   compatr   r	   r
   r   r   r   
exceptionsr   r   r   r   sequencer   r=   r   __all__r   r   r   r   r   r   r   
namedtupler    r   r   r   r   r   r   r   rA   rA   rA   rB   <module>   sR    			              I