Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'InlineBox' object has no attribute 'position_x' #811

Closed
TheElderMindseeker opened this issue Feb 20, 2019 · 3 comments

Comments

3 participants
@TheElderMindseeker
Copy link

commented Feb 20, 2019

I've run into this issue when trying to compile HTML document with the following content:

<html>
<head>
    <meta charset="utf-8">
    <link herf="style.css" rel="stylesheet">
    <title>My PDF Report</title>
    <meta name="description" content="Report trial">
</head>
<body>
    <article id="lorem">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempor, neque luctus vestibulum sagittis, massa justo facilisis leo, vitae tempor tortor urna ut ligula. Nulla eget lectus facilisis, malesuada tortor ut, eleifend nisl. Mauris ante libero, vulputate eu diam sit amet, luctus laoreet sem. Proin sodales ligula nec porttitor fermentum. Maecenas vitae feugiat ex. Phasellus sodales scelerisque dictum. Aliquam sed eleifend dolor. Aliquam quis convallis lectus. Cras euismod vel leo at pretium. Aliquam erat volutpat. Praesent vehicula turpis non sem convallis, convallis finibus nisi congue. Donec rhoncus dapibus euismod. Fusce eget commodo nunc, sit amet tincidunt nisi. Proin cursus accumsan magna, non vestibulum metus finibus ut.

        <img src="Abatur.png">

        <p>
            <a href="https://google.com">Just a link to Google</a>
        </p>
    </article>
</body>
</html>

with this CSS stylesheet provided:

@page {
    margin: 1in;
    @top-center {
        background: black;
        content: '';
        display: block;
        height: 0.05cm;
        opacity: 0.75;
        width: 100%;
    }
    @top-right {
        content: counter(page);
        height: 1cm;
        width: 1cm;
        text-align: center;
    }
}

html body article#lorem {
    align-content: space-between;
    display: flex;
    flex-wrap: wrap;
    height: 9in;
}

Specifically, the issue rises when wrapping anchor to Google into <p> tags, though I think this is a valid HTML construct, the WeasyPrint crashes with the following traceback:

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    stylesheets=[weasyprint.CSS('style.css')]
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/__init__.py", line 199, in write_pdf
    font_config=font_config).write_pdf(
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/__init__.py", line 160, in render
    font_config)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/document.py", line 361, in _render
    [Page(p, enable_hinting) for p in page_boxes],
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/document.py", line 361, in <listcomp>
    [Page(p, enable_hinting) for p in page_boxes],
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/__init__.py", line 126, in layout_document
    context, root_box, html, cascaded_styles, computed_styles, pages))
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/pages.py", line 788, in make_all_pages
    i, context, root_box, html, cascaded_styles, computed_styles)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/pages.py", line 726, in remake_page
    page_number, page_state)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/pages.py", line 554, in make_page
    positioned_boxes, positioned_boxes, adjoining_margins)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 55, in block_level_layout
    adjoining_margins)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 71, in block_level_layout_switch
    adjoining_margins)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 125, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 495, in block_container_layout
    adjoining_margins)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 55, in block_level_layout
    adjoining_margins)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 71, in block_level_layout_switch
    adjoining_margins)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 125, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 495, in block_container_layout
    adjoining_margins)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 55, in block_level_layout
    adjoining_margins)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/blocks.py", line 86, in block_level_layout_switch
    device_size, page_is_empty, absolute_boxes, fixed_boxes)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/layout/flex.py", line 777, in flex_layout
    child.translate(**{direction: cross_translate})
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/formatting_structure/boxes.py", line 128, in translate
    child.translate(dx, dy, ignore_floats)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/formatting_structure/boxes.py", line 128, in translate
    child.translate(dx, dy, ignore_floats)
  File "/home/daniil/Documents/Projects/Learning/Jinja2/venv/lib/python3.7/site-packages/weasyprint/formatting_structure/boxes.py", line 124, in translate
    self.position_x += dx
AttributeError: 'InlineBox' object has no attribute 'position_x'

Some research: removing "lorem ipsum" text or removing <p> tags brings things back to normal. Cutting down "lorem ipsum" to one-two sentences' length also solves the problem, allowing to compile the document.

@liZe liZe added the crash label Feb 20, 2019

@erickjx

This comment has been minimized.

Copy link

commented Apr 27, 2019

Hi, i used 2 work around:

in formatting_structure/boxes.py modify code to:

122         if dx == 0 and dy == 0:
123              return
124         try:
125              self.position_x += dx
126              self.position_y += dy
127         except Exception:
128              print("Error XXX")

And in layout/inlines.py add lines 206-207:

 204        if index == 0 and not box.children:
 205              return None
 206        if index >= len(box.children):
 207              return None
 208        result = skip_first_whitespace(box.children[index], next_skip_stack)
@liZe

This comment has been minimized.

Copy link
Member

commented May 16, 2019

Minimal document:

<style>
  article {
    align-content: space-between;
    display: flex;
    flex-wrap: wrap;
    height: 1in;
  }
</style>
<article>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  <p><span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></p>
</article>

@liZe liZe closed this in 99f85be May 16, 2019

@liZe liZe added this to the 48 milestone May 16, 2019

@liZe

This comment has been minimized.

Copy link
Member

commented May 16, 2019

It's fixed, thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.