o
    e^  ã                   @   s<   d Z ddlmZ ddlmZ ddlmZ G dd„ deƒZdS )a  Char object based on PDF raw dict extracted with ``PyMuPDF``.

Data structure refer to this `link <https://pymupdf.readthedocs.io/en/latest/textpage.html>`_::

    {
        'bbox'  : (x0, y0, x1, y1), 
        'c'     : str, 
        'origin': (x,y)
    }
é   )ÚINVALID_CHARS)ÚElement)ÚShapec                       sH   e Zd ZdZddef‡ fdd„Zddedefd	d
„Z‡ fdd„Z	‡  Z
S )ÚCharz Object representing a character.NÚrawc                    sH   |d u ri }|  dd¡}|tv rd}|| _|  dd ¡| _tƒ  |¡ d S )NÚcÚ Úorigin)Úgetr   r   r	   ÚsuperÚ__init__)Úselfr   r   ©Ú	__class__© úBD:\Projects\ConvertPro\env\Lib\site-packages\pdf2docx/text/Char.pyr      s   zChar.__init__TÚrectÚ
horizontalc                 C   sD   | j |j v rdS | j |j @ }|r|jd| j j kS |jd| j j kS )a¶  Detect whether it locates in a rect.

        Args:
            rect (Shape): Target rect to check.
            horizontal (bool, optional): Text direction is horizontal if True. Defaults to True.

        Returns:
            bool: Whether a Char locates in target rect.
        
        .. note::
            It's considered as contained in the target rect if the intersection is larger than 
            half of the char bbox.
        Tg      à?)ZbboxÚwidthÚheight)r   r   r   Zintsecr   r   r   Úcontained_in_rect"   s   zChar.contained_in_rectc                    s"   t ƒ  ¡ }| | j| jdœ¡ |S )N)r   r	   )r   ÚstoreÚupdater   r	   )r   Úresr   r   r   r   =   s   
þz
Char.store)N)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Údictr   r   Úboolr   r   Ú__classcell__r   r   r   r   r      s
    r   N)r   Zcommon.constantsr   Zcommon.Elementr   Zshape.Shaper   r   r   r   r   r   Ú<module>   s
   