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 )	z+A group of TextSpan and ImageSpan objects.
é   )ÚElementCollectioné   )ÚTextSpan)Ú	ImageSpanc                   @   s>   e Zd ZdZdefdd„Zedd„ ƒZedd„ ƒZd	d
„ Z	dS )ÚSpansz/Collection of TextSpan and ImageSpan instances.Úrawsc                 C   sF   |D ]}d|v rt |ƒ}nt|ƒ}|j ¡ s|jsd}|  |¡ q| S )z5Recreate TextSpan or ImageSpan from source dict list.ÚimageN)r   r   ÚtextÚstripÚstyleÚappend)Úselfr   Zraw_spanÚspan© r   úCD:\Projects\ConvertPro\env\Lib\site-packages\pdf2docx/text/Spans.pyÚrestore   s   
zSpans.restorec                 C   ó   t tdd„ | jƒƒ}t|ƒS )zGet TextSpan instances.c                 S   ó
   t | tƒS ©N)Ú
isinstancer   ©r   r   r   r   Ú<lambda>   ó   
 z"Spans.text_spans.<locals>.<lambda>©ÚlistÚfilterÚ
_instancesr   ©r   Úspansr   r   r   Ú
text_spans   ó   
ÿzSpans.text_spansc                 C   r   )zGet ImageSpan instances.c                 S   r   r   )r   r   r   r   r   r   r   &   r   z#Spans.image_spans.<locals>.<lambda>r   r   r   r   r   Úimage_spans"   r    zSpans.image_spansc                 C   sd   d}| j s|S | j d }t|tƒr|p| ¡ }| j d }t|tƒr'|p&| ¡ }|r0| j | j¡ |S )z.Remove redundant blanks at the begin/end span.Fé    éÿÿÿÿ)r   r   r   ÚlstripÚrstripÚ_parentZupdate_bboxZbbox)r   ÚstrippedZ	left_spanZ
right_spanr   r   r   r
   +   s   


zSpans.stripN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úpropertyr   r!   r
   r   r   r   r   r   
   s    

r   N)r+   Zcommon.Collectionr   r   Zimage.ImageSpanr   r   r   r   r   r   Ú<module>   s
   