o
    iF                     @   s2   d dl Zd dlmZ d dlmZ G dd dZdS )    N)RendererAgg)process_figure_for_rasterizingc                   @   s6   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u rt }|| _|| _|| _|| _|| _d| _d| _|| _|	 | _
|| _|| _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 : float
            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figureget_dpi_figdpi_bbox_inches_restore	_renderer)selfr   widthheightr   vector_rendererraster_renderer_classbbox_inches_restore r   \/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/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rt| j | j}|| _| jdkr.| | j| j | j| j | j| _	| j	| _
|  jd7  _dS )z
        Enter "raster" mode.  All subsequent drawing commands (until
        `stop_rasterizing` is called) will be drawn with the raster backend.
        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rm| j| _| j| j }| j \}}|\}}}}|dkr`|dkr`tj|tj	d}|
||df}|ddd }| j }	| j|	|| j | j || | | j | j | d| _d| _ | j| j | jr~t| j| j| j}
|
| _dS dS )af  
        Exit "raster" mode.  All of the drawing that was done since
        the last `start_rasterizing` call will be copied to the
        vector backend by calling draw_image.

        If `start_rasterizing` has been called multiple times,
        `stop_rasterizing` must be called the same number of times before
        "raster" mode is exited.
        r   r   )dtype   NF)r   r	   r   r   r   r
   tostring_rgba_minimizednp
frombufferuint8reshapenew_gc
draw_imager   r   r   r   r   )r   r   bufferboundslbwhimagegcr   r   r   r   stop_rasterizing]   s6   



z"MixedModeRenderer.stop_rasterizing)NN)__name__
__module____qualname____doc__r   r   r    r3   r   r   r   r   r      s    
4	r   )numpyr%   matplotlib.backends.backend_aggr   matplotlib.tight_bboxr   r   r   r   r   r   <module>   s    