3
$ßL]¨  ã               @   s4   d dl Zd dlmZ d dlmZ G dd„ deƒZdS )é    N)ÚRendererAgg)Úprocess_figure_for_rasterizingc               @   s2   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZdS )ÚMixedModeRenderera&  
    A helper class to implement a renderer that switches between
    vector and raster drawing.  An example may be a PDF writer, where
    most things are drawn with PDF vector commands, but some very
    complex objects, such as quad meshes, are rasterised and then
    output as images.
    Nc             C   sV   |dkrt }|| _|| _|| _|| _|| _d| _d| _|| _|j	ƒ | _
|| _|| _dS )a+  
        Parameters
        ----------
        figure : `matplotlib.figure.Figure`
            The figure instance.

        width : scalar
            The width of the canvas in logical units

        height : scalar
            The height of the canvas in logical units

        dpi : scalar
            The dpi of the canvas

        vector_renderer : `matplotlib.backend_bases.RendererBase`
            An instance of a subclass of
            `~matplotlib.backend_bases.RendererBase` that will be used for the
            vector drawing.

        raster_renderer_class : `matplotlib.backend_bases.RendererBase`
            The renderer class to use for the raster drawing.  If not provided,
            this will use the Agg backend (which is currently the only viable
            option anyway.)

        Nr   )r   Ú_raster_renderer_classÚ_widthÚ_heightÚdpiÚ_vector_rendererÚ_raster_rendererÚ_rasterizingÚfigureZget_dpiÚ_figdpiÚ_bbox_inches_restoreÚ	_renderer)Úselfr   ÚwidthÚheightr   Zvector_rendererZraster_renderer_classZbbox_inches_restore© r   úI/tmp/pip-install-edjban26/matplotlib/matplotlib/backends/backend_mixed.pyÚ__init__   s    
zMixedModeRenderer.__init__c             C   s   t | j|ƒS )N)Úgetattrr   )r   Úattrr   r   r   Ú__getattr__C   s    zMixedModeRenderer.__getattr__c             C   sn   | j j| jƒ | jr(t| j | jƒ}|| _| jdkr\| j| j| j | j| j | jƒ| _	| j	| _
|  jd7  _dS )a  
        Enter "raster" mode.  All subsequent drawing commands (until
        stop_rasterizing is called) will be drawn with the raster
        backend.

        If start_rasterizing is called multiple times before
        stop_rasterizing is called, this method has no effect.
        r   é   N)r   Úset_dpir   r   r   r   r   r   r   r
   r   )r   Úrr   r   r   Ústart_rasterizingL   s    
z#MixedModeRenderer.start_rasterizingc             C   sü   |  j d8  _ | j dkrÚ| j| _| j| j }| jjƒ \}}|\}}}}|dkrÀ|dkrÀtj|tj	d�}|j
||dfƒ}|ddd… }| jjƒ }	| jj|	|| j | j || | | j | j |ƒ d| _d| _ | jj| jƒ | jrøt| j| j| jƒ}
|
| _dS )a9  
        Exit "raster" mode.  All of the drawing that was done since
        the last start_rasterizing command will be copied to the
        vector backend by calling draw_image.

        If stop_rasterizing is called multiple times before
        start_rasterizing is called, this method has no effect.
        r   r   )Zdtypeé   NFéÿÿÿÿ)r   r	   r   r   r   r
   Ztostring_rgba_minimizedÚnpZ
frombufferZuint8ZreshapeZnew_gcZ
draw_imager   r   r   r   r   )r   r   ÚbufferZboundsÚlÚbÚwÚhÚimageÚgcr   r   r   r   Ústop_rasterizingd   s0    	

z"MixedModeRenderer.stop_rasterizing)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r'   r   r   r   r   r      s    
2	r   )Znumpyr   Zmatplotlib.backends.backend_aggr   Zmatplotlib.tight_bboxr   Úobjectr   r   r   r   r   Ú<module>   s   