
    kh                     :    d Z ddlmZmZ ddlmZ  G d de      Zy)z(Base class for text/image/table blocks.
   )	BlockTypeTextAlignment)Elementc                        e Zd ZdZddef fdZed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zed        Zd Zd Zd Zd Zd ZdefdZd Z fdZd Z xZS )BlockzBase class for text/image/table blocks.

    Attributes:
        raw (dict): initialize object from raw properties.
        parent (optional): parent object that this block belongs to.
    rawc                    t         j                  | _        |i }| j                  |j	                  dd            | _        |j	                  dd      | _        |j	                  dd      | _        |j	                  dd      | _        |j	                  dg       | _	        |j	                  dd      | _
        |j	                  d	d      | _        |j	                  d
d      | _        |j	                  dd      | _        t        | =  ||       y )N	alignment    
left_spaceg        right_spacefirst_line_space	tab_stopsbefore_spaceafter_space
line_spaceline_space_typer   )r   	UNDEFINED_type_get_alignmentgetr
   r   r   r   r   r   r   r   r   super__init__)selfr   parent	__class__s      Q/var/www/teggl/fontify/venv/lib/python3.12/site-packages/pdf2docx/common/Block.pyr   zBlock.__init__   s    ((
 ;b,,SWW[!-DE'',477=#6 #(:C @ b1  GGNC877=#6'',4"ww'8!<f%    c                 <    | j                   t        j                  k(  S )zWhether test block.)r   r   TEXTr   s    r   is_text_blockzBlock.is_text_block'   s     zz9>>))r   c                 <    | j                   t        j                  k(  S )zWhether inline image block.)r   r   IMAGEr!   s    r   is_inline_image_blockzBlock.is_inline_image_block,   s     zz9??**r   c                 <    | j                   t        j                  k(  S )zWhether float image block.)r   r   FLOAT_IMAGEr!   s    r   is_float_image_blockzBlock.is_float_image_block1   s     zz90000r   c                 6    | j                   xs | j                  S )z$Whether inline or float image block.)r%   r(   r!   s    r   is_image_blockzBlock.is_image_block6   s     ))FT-F-FFr   c                 6    | j                   xs | j                  S )z)Whether text block or inline image block.)r"   r%   r!   s    r   is_text_image_blockzBlock.is_text_image_block;   s     !!?T%?%??r   c                 <    | j                   t        j                  k(  S )z5Whether lattice table (explicit table borders) block.)r   r   LATTICE_TABLEr!   s    r   is_lattice_table_blockzBlock.is_lattice_table_block@   s     zz92222r   c                 <    | j                   t        j                  k(  S )z6Whether stream table (implied by table content) block.)r   r   STREAM_TABLEr!   s    r   is_stream_table_blockzBlock.is_stream_table_blockE   s     zz91111r   c                 6    | j                   xs | j                  S )z(Whether table (lattice or stream) block.)r/   r2   r!   s    r   is_table_blockzBlock.is_table_blockJ   s     **Hd.H.HHr   c                 .    t         j                  | _        yzSet block type.N)r   r    r   r!   s    r   set_text_blockzBlock.set_text_blockO   s    ^^
r   c                 .    t         j                  | _        yr6   )r   r$   r   r!   s    r   set_inline_image_blockzBlock.set_inline_image_blockS   s    __
r   c                 .    t         j                  | _        yr6   )r   r'   r   r!   s    r   set_float_image_blockzBlock.set_float_image_blockW   s    **
r   c                 .    t         j                  | _        yr6   )r   r.   r   r!   s    r   set_lattice_table_blockzBlock.set_lattice_table_block[   s    ,,
r   c                 .    t         j                  | _        yr6   )r   r1   r   r!   s    r   set_stream_table_blockzBlock.set_stream_table_block_   s    ++
r   modec                 ^    t         D ]  }|j                  |k(  s|c S  t         j                  S )N)r   valueLEFT)r   r@   ts      r   r   zBlock._get_alignmentc   s/     	Aww}	 !!!r   c                     | j                   rdnd\  }}t        j                  | _        | j                  |   ||   z
  |z  | _        y)zSet 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)is_horizontal_textr   rC   r
   bboxr   )r   rH   argsidxfs        r   parse_horizontal_spacingzBlock.parse_horizontal_spacingi   sA     "44)Q&++99S>DI5:r   c                 L   t         |          }|j                  | 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   rB   r
   r   r   r   r   r   r   r   r   )r   resr   s     r   rO   zBlock.storex   s    gmo

!%!1!1!%!5!5!%!%!1!1!%!6!6!%!2!2!%!1!1!%!%!5!5!% 	 
r   c                     t         )zYCreate associated docx element.

        Raises:
            NotImplementedError
        )NotImplementedError)r   rI   kwargss      r   	make_docxzBlock.make_docx   s
     "!r   )NN)__name__
__module____qualname____doc__dictr   propertyr"   r%   r(   r*   r,   r/   r2   r4   r7   r9   r;   r=   r?   intr   rL   rO   rU   __classcell__)r   s   @r   r   r   
   s    &4 &, * * + + 1 1 G G @ @ 3 3 2 2 I I$%+-,"# ";$"r   r   N)rY   sharer   r   r   r    r   r   <module>r`      s     , F"G F"r   