o
    Õj  ã                   @   s4   d Z ddlmZmZ ddlmZ G dd„ deƒZdS )z(Base class for text/image/table blocks.
é   )Ú	BlockTypeÚTextAlignment)ÚElementc                       sÚ   e Zd ZdZd)def‡ fdd„Zedd„ ƒZedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd efd!d"„Zd#d$„ Z‡ fd%d&„Zd'd(„ Z‡  ZS )*ÚBlockz½Base class for text/image/table blocks.

    Attributes:
        raw (dict): initialize object from raw properties.
        parent (optional): parent object that this block belongs to.
    NÚrawc                    sª   t j| _|d u r
i }|  | dd¡¡| _| dd¡| _| dd¡| _| dd¡| _| dg ¡| _	| dd¡| _
| d	d¡| _| d
d¡| _| dd¡| _tƒ  ||¡ d S )NÚ	alignmenté    Ú
left_spaceg        Úright_spaceÚfirst_line_spaceÚ	tab_stopsÚbefore_spaceÚafter_spaceÚ
line_spaceÚline_space_typer   )r   Z	UNDEFINEDÚ_typeÚ_get_alignmentÚgetr   r	   r
   r   r   r   r   r   r   ÚsuperÚ__init__)Úselfr   Úparent©Ú	__class__© úV/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/pdf2docx/common/Block.pyr      s   zBlock.__init__c                 C   ó   | j tjkS )zWhether test block.)r   r   ÚTEXT©r   r   r   r   Úis_text_block'   ó   zBlock.is_text_blockc                 C   r   )zWhether inline image block.)r   r   ÚIMAGEr   r   r   r   Úis_inline_image_block,   r    zBlock.is_inline_image_blockc                 C   r   )zWhether float image block.)r   r   ÚFLOAT_IMAGEr   r   r   r   Úis_float_image_block1   r    zBlock.is_float_image_blockc                 C   ó   | j p| jS )z$Whether inline or float image block.)r"   r$   r   r   r   r   Úis_image_block6   r    zBlock.is_image_blockc                 C   r%   )z)Whether text block or inline image block.)r   r"   r   r   r   r   Úis_text_image_block;   r    zBlock.is_text_image_blockc                 C   r   )z5Whether lattice table (explicit table borders) block.)r   r   ÚLATTICE_TABLEr   r   r   r   Úis_lattice_table_block@   r    zBlock.is_lattice_table_blockc                 C   r   )z6Whether stream table (implied by table content) block.)r   r   ÚSTREAM_TABLEr   r   r   r   Úis_stream_table_blockE   r    zBlock.is_stream_table_blockc                 C   r%   )z(Whether table (lattice or stream) block.)r)   r+   r   r   r   r   Úis_table_blockJ   r    zBlock.is_table_blockc                 C   ó   t j| _dS ©zSet block type.N)r   r   r   r   r   r   r   Úset_text_blockO   ó   zBlock.set_text_blockc                 C   r-   r.   )r   r!   r   r   r   r   r   Úset_inline_image_blockS   r0   zBlock.set_inline_image_blockc                 C   r-   r.   )r   r#   r   r   r   r   r   Úset_float_image_blockW   r0   zBlock.set_float_image_blockc                 C   r-   r.   )r   r(   r   r   r   r   r   Úset_lattice_table_block[   r0   zBlock.set_lattice_table_blockc                 C   r-   r.   )r   r*   r   r   r   r   r   Úset_stream_table_block_   r0   zBlock.set_stream_table_blockÚmodec                 C   s"   t D ]}|j|kr|  S qt jS )N)r   ÚvalueÚLEFT)r   r5   Útr   r   r   r   c   s
   
ÿzBlock._get_alignmentc                 G   s6   | j rdnd\}}tj| _| j| ||  | | _dS )z½Set left alignment, and calculate left space. 
        
        Override by :obj:`pdf2docx.text.TextBlock`.

        Args:
            bbox (fitz.rect): boundary box of this block.
        )r   g      ð?)é   g      ð¿N)Zis_horizontal_textr   r7   r   Úbboxr	   )r   r:   ÚargsÚidxÚfr   r   r   Úparse_horizontal_spacingi   s   
zBlock.parse_horizontal_spacingc                    sF   t ƒ  ¡ }| | jj| jj| j| j| j| j	| j
| j| j| jdœ
¡ |S )z Store attributes in json format.)
Útyper   r	   r
   r   r   r   r   r   r   )r   ÚstoreÚupdater   r6   r   r	   r
   r   r   r   r   r   r   )r   Úresr   r   r   r@   x   s   
özBlock.storec                 O   s   t ‚)zYCreate associated docx element.

        Raises:
            NotImplementedError
        )ÚNotImplementedError)r   r;   Úkwargsr   r   r   Ú	make_docxŠ   s   zBlock.make_docx)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Údictr   Úpropertyr   r"   r$   r&   r'   r)   r+   r,   r/   r1   r2   r3   r4   Úintr   r>   r@   rE   Ú__classcell__r   r   r   r   r   
   s8    







r   N)rI   Zsharer   r   r   r   r   r   r   r   Ú<module>   s   