o
    e{
  ã                   @   sH   d Z ddlmZ ddlmZ ddlmZ ddlmZ G dd	„ d	eƒZd
S )am  Section of Page.

In most cases, one section per page. But in case multi-columns page, sections are used 
to distinguish these different layouts.

.. note::
    Currently, support at most two columns.

::

    {
        'bbox': (x0,y0,x1,y1)
        'num_cols': 1,
        'space': 0,
        'columns': [{
            ... # column properties
        }, ...]
    }
é    )Ú
WD_SECTIONé   )Úset_columns)ÚBaseCollectioné   )ÚColumnc                       s^   e Zd Zddedef‡ fdd„Zedd„ ƒZ‡ fd	d
„Zde	fdd„Z
dd„ Zdd„ Z‡  ZS )ÚSectionr   NÚspaceÚcolumnsc                    s   || _ d| _tƒ  ||¡ dS )a%  Initialize Section instance.

        Args:
            space (int, optional): Space between adjacent columns. Defaults to 0.
            columns (list, optional): A list of Column instances. Defaults to None.
            parent (Sections, optional): Parent element. Defaults to None.
        g        N)r	   Úbefore_spaceÚsuperÚ__init__)Úselfr	   r
   Úparent©Ú	__class__© úGD:\Projects\ConvertPro\env\Lib\site-packages\pdf2docx/layout/Section.pyr      s   zSection.__init__c                 C   s   t | ƒS )N)Úlen©r   r   r   r   Únum_cols,   s   zSection.num_colsc                    s,   t dd„ | jD ƒƒ| j| j| jtƒ  ¡ dœS )z+Store parsed section layout in dict format.c                 S   s   g | ]}|‘qS r   r   )Ú.0Úxr   r   r   Ú
<listcomp>3   s    z!Section.store.<locals>.<listcomp>)Úbboxr   r	   r   r
   )Útupler   r   r	   r   r   Ústorer   r   r   r   r   0   s   ûzSection.storeÚrawc                 C   sH   |  dd¡| _|  dd¡| _|  dg ¡D ]}tƒ  |¡}|  |¡ q| S )z!Restore section from source dict.r	   r   r   r
   )Úgetr	   r   r   ÚrestoreÚappend)r   r   Zraw_colÚcolumnr   r   r   r   ;   s   zSection.restorec                 K   s   | D ]
}|j di |¤Ž q| S )zParse section layout.Nr   )Úparse)r   Úsettingsr!   r   r   r   r"   I   s   zSection.parsec                 C   sV   |j d }dd„ | D ƒ}t||| jƒ | D ]}|| d kr#| tj¡ | |¡ qdS )zlCreate section in docx. 

        Args:
            doc (Document): ``python-docx`` document object
        éÿÿÿÿc                 S   s    g | ]}|j d  |j d  ‘qS )r   r   )r   )r   Úcr   r   r   r   W   s     z%Section.make_docx.<locals>.<listcomp>r   N)Úsectionsr   r	   Úadd_sectionr   Z
NEW_COLUMNÚ	make_docx)r   ÚdocÚsectionZ
width_listr!   r   r   r   r(   O   s   
úzSection.make_docx)r   NN)Ú__name__Ú
__module__Ú__qualname__ÚintÚlistr   Úpropertyr   r   Údictr   r"   r(   Ú__classcell__r   r   r   r   r      s    
r   N)	Ú__doc__Zdocx.enum.sectionr   Zcommon.docxr   Zcommon.Collectionr   r   r   r   r   r   r   Ú<module>   s   