<commit_before># coding: utf8
"""
    weasyprint.absolute
    -------------------

    :copyright: Copyright 2011-2012 <NAME> and contributors, see AUTHORS.
    :license: BSD, see LICENSE for details.

"""

from __future__ import division, unicode_literals

from .percentages import resolve_percentages, resolve_position_percentages
from .preferred import shrink_to_fit
from .markers import list_marker_layout
from .tables import table_wrapper_width
from ..formatting_structure import boxes


class AbsolutePlaceholder(object):
    """Left where an absolutely-positioned box was taken out of the flow."""
    def __init__(self, box):
        # Work around the overloaded __setattr__
        object.__setattr__(self, '_box', box)
        object.__setattr__(self, '_layout_done', False)

    def set_laid_out_box(self, new_box):
        object.__setattr__(self, '_box', new_box)
        object.__setattr__(self, '_layout_done', True)

    def translate(self, dx=0, dy=0):
        if self._layout_done:
            self._box.translate(dx, dy)
        else:
            # Descendants do not have a position yet.
            self._box.position_x += dx
            self._box.position_y += dy

    def copy(self):
        new_placeholder = AbsolutePlaceholder(self._box.copy())
        object.__setattr__(new_placeholder, '_layout_done', self._layout_done)
        return new_placeholder

    # Pretend to be the box itself
    def __getattr__(self, name):
        return getattr(self._box, name)

    def __setattr__(self, name, value):
        setattr(self._box, name, value)


def absolute_layout(document, placeholder, containing_block):
    """Set the width of absolute positioned ``box``."""
    box = placeholder._box

    cb = containing_block
    # TODO: handle inline boxes (point 10.1.4.1)
    # http://www.w3.org/TR/CSS2/visudet.html#containing-block-details
    if isinstance(box, boxes.PageBox):
        cb_x = cb.content_box_x()
        cb_y = cb.content_box_y()
        cb_width = cb.padding_width()
        cb_height = cb.padding_height()
    else:
        cb_x = cb.padding_box_x()
        cb_y = cb.padding_box_y()
        cb_width = cb.padding_width()
        cb_height = cb.padding_height()
    containing_block = cb_x, cb_y, cb_width, cb_height

    resolve_percentages(box, (cb_width, cb_height))
    resolve_position_percentages(box, (cb_width, cb_height))

    # TODO: handle absolute tables
    if isinstance(box, boxes.BlockBox):
        new_box = absolute_block(document, box, containing_block)<commit_msg>Fix the initial containing block<commit_after># coding: utf8
"""
    weasyprint.absolute
    -------------------

    :copyright: Copyright 2011-2012 <NAME> and contributors, see AUTHORS.
    :license: BSD, see LICENSE for details.

"""

from __future__ import division, unicode_literals

from .percentages import resolve_percentages, resolve_position_percentages
from .preferred import shrink_to_fit
from .markers import list_marker_layout
from .tables import table_wrapper_width
from ..formatting_structure import boxes


class AbsolutePlaceholder(object):
    """Left where an absolutely-positioned box was taken out of the flow."""
    def __init__(self, box):
        # Work around the overloaded __setattr__
        object.__setattr__(self, '_box', box)
        object.__setattr__(self, '_layout_done', False)

    def set_laid_out_box(self, new_box):
        object.__setattr__(self, '_box', new_box)
        object.__setattr__(self, '_layout_done', True)

    def translate(self, dx=0, dy=0):
        if self._layout_done:
            self._box.translate(dx, dy)
        else:
            # Descendants do not have a position yet.
            self._box.position_x += dx
            self._box.position_y += dy

    def copy(self):
        new_placeholder = AbsolutePlaceholder(self._box.copy())
        object.__setattr__(new_placeholder, '_layout_done', self._layout_done)
        return new_placeholder

    # Pretend to be the box itself
    def __getattr__(self, name):
        return getattr(self._box, name)

    def __setattr__(self, name, value):
        setattr(self._box, name, value)


def absolute_layout(document, placeholder, containing_block):
    """Set the width of absolute positioned ``box``."""
    box = placeholder._box

    cb = containing_block
    # TODO: handle inline boxes (point 10.1.4.1)
    # http://www.w3.org/TR/CSS2/visudet.html#containing-block-details
    if isinstance(containing_block, boxes.PageBox):
        cb_x = cb.content_box_x()
        cb_y = cb.content_box_y()
        cb_width = cb.width
        cb_height = cb.height
    else:
        cb_x = cb.padding_box_x()
        cb_y = cb.padding_box_y()
        cb_width = cb.padding_width()
        cb_height = cb.padding_height()
    containing_block = cb_x, cb_y, cb_width, cb_height

    resolve_percentages(box, (cb_width, cb_height))
    resolve_position_percentages(box, (cb_width, cb_height))

    # TODO: handle absolute tables
    if isinstance(box, boxes.BlockBox):
        new_box = absolute_block(document, box, containing_block)
{'fraction_non_alphanumeric': 0.10382945124358468, 'fraction_numerical': 0.007106198183971575, 'mean_word_length': 3.0895883777239708, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2988089', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1497, 'n_words': 387}