
    kh                     t    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ee
      Zy)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                   J     e Zd ZdZddef fdZd Zd Z fdZ fdZ	 xZ
S )	
ImageBlockzImage block.rawc                 D    t         |   |       | j                          y N)super__init__set_inline_image_block)selfr   	__class__s     U/var/www/teggl/fontify/venv/lib/python3.12/site-packages/pdf2docx/image/ImageBlock.pyr   zImageBlock.__init__   s     	##%    c                     t               j                  |       }t               }|j                  |       t	               }|j                  |       |j                          |S )zConvert image block to a span under text block.

        Returns:
            TextBlock: New TextBlock instance containing this image.
        )r	   
from_imager   addr   r   )r   span
image_lineblocks       r   to_text_blockzImageBlock.to_text_block   sS     {%%d+ V
t 		* 	$$&r   c                 x    t        j                  |       }|j                  t        j                  |              |S )z&Store ImageBlock instance in raw dict.)r
   storeupdater   )r   ress     r   r    zImageBlock.store1   s/    kk$

KK	
 
r   c                 (    t         |   |d       y)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   s     r   r%   zImageBlock.plot:   s     	T)r   c                     | j                   r9| j                  \  }}}}t        |t        | j                        ||z
  ||       |S t
        |   |       |S )zCreate floating image behind text. 
        
        Args:
            p (Paragraph): ``python-docx`` paragraph instance.
        
        .. note::
            Inline image is created within TextBlock.
        )widthpos_xpos_y)is_float_image_blockbboxr   r   imager   	make_docx)r   px0y0x1y1r   s         r   r.   zImageBlock.make_docxC   sX     $$!YYNBBAwtzz2"R%rQST  Ga r   r   )__name__
__module____qualname____doc__dictr   r   r    r%   r.   __classcell__)r   s   @r   r   r      s+    &4 &.* r   r   N)r7   ior   	text.Liner   text.TextBlockr   r   r	   common.Blockr
   common.docxr   r    r   r   <module>r@      s1   
   &      )@ @r   