o
    e                     @   sn   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	l	m
Z
 dd
lmZ G dd dee
ZdS )zjDefinition of Image block objects. 

**The raw image block will be merged into TextBlock > Line > Span.**
    )BytesIO   )Line)	TextBlock   )Image)	ImageSpan)Block)add_float_imagec                       sP   e Zd ZdZddef fddZdd Zdd	 Z fd
dZ fddZ	  Z
S )
ImageBlockzImage block.Nrawc                    s   t  | |   d S N)super__init__set_inline_image_block)selfr   	__class__ ID:\Projects\ConvertPro\env\Lib\site-packages\pdf2docx/image/ImageBlock.pyr      s   zImageBlock.__init__c                 C   s8   t  | }t }|| t }|| |  |S )zConvert image block to a span under text block.

        Returns:
            TextBlock: New TextBlock instance containing this image.
        )r   Z
from_imager   addr   r   )r   spanZ
image_lineblockr   r   r   to_text_block   s   

zImageBlock.to_text_blockc                 C   s   t | }|t|  |S )z&Store ImageBlock instance in raw dict.)r	   storeupdater   )r   resr   r   r   r   1   s
   
zImageBlock.storec                    s   t  j|dd dS )zPlot image bbox with diagonal lines (for debug purpose).
        
        Args: 
            page (fitz.Page): pdf page to plot.
        )r   r   r   )colorN)r   plot)r   pager   r   r   r   :   s   zImageBlock.plotc                    sD   | j r| j\}}}}t|t| j|| ||d |S t | |S )zCreate floating image behind text. 
        
        Args:
            p (Paragraph): ``python-docx`` paragraph instance.
        
        .. note::
            Inline image is created within TextBlock.
        )widthZpos_xZpos_y)Zis_float_image_blockZbboxr
   r   imager   	make_docx)r   pZx0Zy0x1y1r   r   r   r"   C   s   	zImageBlock.make_docxr   )__name__
__module____qualname____doc__dictr   r   r   r   r"   __classcell__r   r   r   r   r      s    		r   N)r)   ior   Z	text.Liner   Ztext.TextBlockr   r   r   Zcommon.Blockr	   Zcommon.docxr
   r   r   r   r   r   <module>   s   