3
VÓmW÷  ã               @   sx   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZ dd	lmZ d
d„ Zdd„ ZG dd„ deƒZdS )a8  
    weasyprint.layout
    -----------------

    Transform a "before layout" box tree into an "after layout" tree.
    (Surprising, hu?)

    Break boxes across lines and pages; determine the size and dimension
    of each box fragement.

    Boxes in the new tree have *used values* in their ``position_x``,
    ``position_y``, ``width`` and ``height`` attributes, amongst others.

    See http://www.w3.org/TR/CSS21/cascade.html#used-value

    :copyright: Copyright 2011-2014 Simon Sapin and contributors, see AUTHORS.
    :license: BSD, see LICENSE for details.

é    )ÚdivisionÚunicode_literals)Údefaultdicté   )Úxrangeé   )Úabsolute_box_layout)Úmake_all_pagesÚmake_margin_boxes)Úlayout_backgroundsc             c   s2   x,|D ]$}x|j D ]}t| ||g ƒV  qW qW dS )z/Lay out and yield the fixed boxes of ``pages``.N)Zfixed_boxesr   )ÚcontextÚpagesÚpageZbox© r   úZ/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/weasyprint/layout/__init__.pyÚlayout_fixed_boxes   s    
r   c             c   sâ   t | ||ƒ}tt||ƒƒ}dg}|t|ƒgdœ}x¬t|ƒD ] \}}	g }
|	j\}|
jt||d|… ƒƒ |
j|jƒ |
jt|||d d… ƒƒ |j|
ƒ}|d |_	|ft
t||	|ƒƒ |	_t|	|ƒ |	V  |d  d7  < q:W dS )zØLay out the whole document.

    This includes line breaks, page breaks, absolute size and position for all
    boxes.

    :param context: a LayoutContext object.
    :returns: a list of laid out Page objects.

    r   )r   r   Nr   )ÚLayoutContextÚlistr	   ÚlenÚ	enumerateÚchildrenÚextendr   Zcopy_with_childrenÚcurrent_pageÚtupler
   r   )Úenable_hintingÚ	style_forÚget_image_from_uriÚroot_boxr   r   Zpage_counterZcounter_valuesÚir   Zroot_childrenÚrootr   r   r   Úlayout_document(   s"    



r    c               @   s.   e Zd Zdd„ Zdd„ Zdd„ Zd
dd	„ZdS )r   c             C   s6   || _ || _|| _g | _d | _tdd„ ƒ| _d | _d S )Nc               S   s   t dd„ ƒS )Nc               S   s   t ƒ S )N)r   r   r   r   r   Ú<lambda>L   s    z:LayoutContext.__init__.<locals>.<lambda>.<locals>.<lambda>)r   r   r   r   r   r!   L   s    z(LayoutContext.__init__.<locals>.<lambda>)r   r   r   Ú_excluded_shapes_listsÚexcluded_shapesr   Ú
string_setr   )Úselfr   r   r   r   r   r   Ú__init__F   s    zLayoutContext.__init__c             C   s   g | _ | jj| j ƒ d S )N)r#   r"   Úappend)r%   r   r   r   Úcreate_block_formatting_contextO   s    z-LayoutContext.create_block_formatting_contextc             C   sz   |j jdkrR|jƒ |j }x6| jD ],}|j|jƒ  }||kr"| j|| 7  _q"W | jjƒ  | jrp| jd | _nd | _d S )NÚautor   éÿÿÿÿ)ÚstyleÚheightZcontent_box_yr#   Z
position_yZmargin_heightr"   Úpop)r%   r   Z
box_bottomÚshapeZshape_bottomr   r   r   Úfinish_block_formatting_contextS   s    
z-LayoutContext.finish_block_formatting_contextNc             C   sŒ   |dk}| j | j| krP|dkr$dS |r<| j| | j  d S | j| | j  d S x6t| j ddƒD ]$}|| j| kr`| j| | d S q`W dS )	a’  Resolve value of string function (as set by string set).

        We'll have something like this that represents all assignments on a
        given page:

        {1: [u'First Header'], 3: [u'Second Header'],
         4: [u'Third Header', u'3.5th Header']}

        Value depends on current page.
        http://dev.w3.org/csswg/css-gcpm/#funcdef-string

        :param name: the name of the named string.
        :param keyword: indicates which value of the named string to use.
                        Default is the first assignment on the current page
                        else the most recent assignment (entry value)
        :returns: text

        Úlastzfirst-exceptÚ r   r   r*   r*   r*   )r   r$   r   )r%   ÚnameÚkeywordr0   Zprevious_pager   r   r   Úget_string_set_fora   s    z LayoutContext.get_string_set_for)N)Ú__name__Ú
__module__Ú__qualname__r&   r(   r/   r4   r   r   r   r   r   E   s   	r   N)Ú__doc__Ú
__future__r   r   Úcollectionsr   Úcompatr   Zabsoluter   r   r	   r
   Zbackgroundsr   r   r    Úobjectr   r   r   r   r   Ú<module>   s   
