
    kh{
                     N    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	e      Zy
)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                   \     e Zd Zd
dedef fdZed        Z fdZde	fdZ
d Zd	 Z xZS )Sectionspacecolumnsc                 B    || _         d| _        t        |   ||       y)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__s       S/var/www/teggl/fontify/venv/lib/python3.12/site-packages/pdf2docx/layout/Section.pyr   zSection.__init__   s#     
&)    c                     t        |       S )N)len)r   s    r   num_colszSection.num_cols,   s    "4y(r   c                     t        | j                  D cg c]  }| c}      | j                  | j                  | j                  t
        |          dS c c}w )z+Store parsed section layout in dict format.)bboxr   r   r   r   )tupler   r   r   r   r   store)r   xr   s     r   r   zSection.store0   sI     3Aa34==zz"//w}
 	
3s   	Arawc                     |j                  dd      | _        |j                  dd      | _        |j                  dg       D ],  }t               j	                  |      }| j                  |       . | S )z!Restore section from source dict.r   r   r   r   )getr   r   r   restoreappend)r   r   raw_colcolumns       r   r!   zSection.restore;   sj     WWWa(
GGNA6 wwy"- 	 GX%%g.FKK	  r   c                 8    | D ]  } |j                   di |  | S )zParse section layout. )parse)r   settingsr$   s      r   r'   zSection.parseI   s"    4FLFLL4844r   c                 0   |j                   d   }| D cg c]!  }|j                  d   |j                  d   z
  # }}t        ||| j                         | D ]:  }|| d   k7  r|j	                  t
        j                         |j                  |       < yc c}w )zlCreate section in docx. 

        Args:
            doc (Document): ``python-docx`` document object
        r   r   N)sectionsr   r   r   add_sectionr   
NEW_COLUMN	make_docx)r   docsectionc
width_listr$   s         r   r.   zSection.make_docxO   s     ,,r"378aaffQiq	)8
8GZ4  	"Fa 
 5 56 S!	"	 9s   &B)r   NN)__name__
__module____qualname__intlistr   propertyr   r   dictr!   r'   r.   __classcell__)r   s   @r   r
   r
      sA    
*S 
*D 
* ( (
$ "r   r
   N)	__doc__docx.enum.sectionr   common.docxr   common.Collectionr   r   r
   r&   r   r   <module>r?      s&   ( ) % . D"n D"r   