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

Error: 'Node' object has no attribute 'text_bounding_box' (since version 61.0) #2070

Closed
danwos opened this issue Feb 13, 2024 · 5 comments
Closed
Labels
crash Problems preventing documents from being rendered

Comments

@danwos
Copy link

danwos commented Feb 13, 2024

With the newest version 61.0 I get the following error:
AttributeError: 'Node' object has no attribute 'text_bounding_box'. Did you mean: 'bounding_box'?

Version 60.2 works fine.

Can't really tell how to reproduce this, as weasyprint is indirectly used by Sphinx-SimplePDF.

Sphinx-SimplePDF creates a SingleHTML-Page of a Sphinx documentation and then let weasyprint "translate" this page to PDF.

Complete traceback:

Traceback (most recent call last):
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/bin/weasyprint", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/__main__.py", line 183, in main
    html.write_pdf(output, **options)
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/__init__.py", line 259, in write_pdf
    self.render(font_config, counter_style, **options)
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/document.py", line 390, in write_pdf
    pdf = generate_pdf(self, target, zoom, **options)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/pdf/__init__.py", line 192, in generate_pdf
    page.paint(stream, scale)
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/document.py", line 99, in paint
    draw_page(self._page_box, stream)
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/draw.py", line 65, in draw_page
    draw_stacking_context(stream, stacking_context)
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/draw.py", line 174, in draw_stacking_context
    draw_stacking_context(stream, child_context)
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/draw.py", line 167, in draw_stacking_context
    draw_inline_level(
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/draw.py", line 1031, in draw_inline_level
    draw_inline_level(
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/draw.py", line 1037, in draw_inline_level
    draw_replacedbox(stream, box)
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/draw.py", line 994, in draw_replacedbox
    box.replacement.draw(
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/images.py", line 276, in draw
    self._svg.draw(
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/svg/__init__.py", line 392, in draw
    self.draw_node(self.tree, size('12pt'))
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/svg/__init__.py", line 466, in draw_node
    self.draw_node(child, font_size, fill_stroke)
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/svg/__init__.py", line 466, in draw_node
    self.draw_node(child, font_size, fill_stroke)
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/svg/__init__.py", line 466, in draw_node
    self.draw_node(child, font_size, fill_stroke)
  File "/home/daniel/workspace/sphinx/sphinx-needs-demo/.venv/lib/python3.11/site-packages/weasyprint/svg/__init__.py", line 468, in draw_node
    if not is_valid_bounding_box(child.text_bounding_box):
                                 ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Node' object has no attribute 'text_bounding_box'. Did you mean: 'bounding_box'?
@danwos danwos changed the title Error: 'Node' object has no attribute 'text_bounding_box' Error: 'Node' object has no attribute 'text_bounding_box' (since version 61.0) Feb 13, 2024
@liZe
Copy link
Member

liZe commented Feb 13, 2024

Hi!

Thanks for the report. The problem is in an SVG file (with text), do you have such an image in your document?

@liZe liZe added the crash Problems preventing documents from being rendered label Feb 13, 2024
@danwos
Copy link
Author

danwos commented Feb 13, 2024

Thanks for the fast response.

And yes, I have a lot of SVG files with text.
The source of this is the used Sphinx-Needs extension, and there the needflow directive. This feature often creates dozens of such SVG files: https://sphinx-needs.readthedocs.io/en/latest/directives/needflow.html.
The images there are also all SVG files with text, so if test-data is needed... :)

The problem is in an SVG file (with text)

Do you mean the SVG itself is the problem, so maybe not following the standard?
Or has weasyprint a problem dealing with such (valid) files?

@liZe
Copy link
Member

liZe commented Feb 13, 2024

Do you mean the SVG itself is the problem, so maybe not following the standard?
Or has weasyprint a problem dealing with such (valid) files?

I mean WeasyPrint has a problem 😄. Even if the SVG was not valid, it shouldn’t crash!

The source of this is the used Sphinx-Needs extension, and there the needflow directive. This feature often creates dozens of such SVG files: https://sphinx-needs.readthedocs.io/en/latest/directives/needflow.html.

Thanks, I can reproduce with this page, I’ll find what’s wrong.

liZe added a commit that referenced this issue Feb 13, 2024
@liZe liZe closed this as completed in 812e194 Feb 13, 2024
@liZe
Copy link
Member

liZe commented Feb 13, 2024

It should be fixed, feedback is welcome!

The images there are also all SVG files with text, so if test-data is needed... :)

We definitely need more tests for SVG rendering.

I’ve added a specific check to log an error instead of crashing when a problem happens while drawing SVG files. It’s not glorious but it’s better than a crash, and all browsers do that.

@danwos
Copy link
Author

danwos commented Feb 15, 2024

Thanks for the fix.

Tested it with the current main branch, and it works.
SVGs are also part of the PDF and are good-looking.

Kudos for the really quick response and fix 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Problems preventing documents from being rendered
Projects
None yet
Development

No branches or pull requests

2 participants