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

TypeError: unsupported operand type(s) for -: 'Dimension' and 'float' #225

Closed
amarsahinovic opened this issue Nov 2, 2014 · 8 comments
Closed
Assignees
Labels
bug Existing features not working as expected crash Problems preventing documents from being rendered

Comments

@amarsahinovic
Copy link

I can reproduce this error by running: weasyprint http://foundation.zurb.com/docs/ out.pdf
It also crashes on my other website (which also uses foundation) with the same error. There is also a bunch of parse errors before the exception is raised.

Traceback (most recent call last):
  File "/home/amar/.virtualenvs/weasyprinttest/bin/weasyprint", line 9, in <module>
    load_entry_point('WeasyPrint==0.23', 'console_scripts', 'weasyprint')()
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/__main__.py", line 156, in main
    getattr(html, 'write_' + format_)(output, **kwargs)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/__init__.py", line 164, in write_pdf
    return self.render(stylesheets).write_pdf(target, zoom, attachments)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/__init__.py", line 132, in render
    return Document._render(self, stylesheets, enable_hinting)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/document.py", line 319, in _render
    return cls([Page(p, enable_hinting) for p in page_boxes],
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/document.py", line 319, in <listcomp>
    return cls([Page(p, enable_hinting) for p in page_boxes],
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/__init__.py", line 50, in layout_document
    pages = list(make_all_pages(context, root_box))
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/pages.py", line 541, in make_all_pages
    context, root_box, page_type, resume_at, content_empty)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/pages.py", line 503, in make_page
    positioned_boxes, positioned_boxes, adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 60, in block_level_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 88, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 435, in block_container_layout
    adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 60, in block_level_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 88, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 435, in block_container_layout
    adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 60, in block_level_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 88, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 435, in block_container_layout
    adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 60, in block_level_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 88, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 435, in block_container_layout
    adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 60, in block_level_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 88, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 435, in block_container_layout
    adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 60, in block_level_layout
    absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 88, in block_box_layout
    page_is_empty, absolute_boxes, fixed_boxes, adjoining_margins)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/blocks.py", line 321, in block_container_layout
    for line, resume_at in lines_iterator:
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/inlines.py", line 48, in iter_line_boxes
    device_size, absolute_boxes, fixed_boxes)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/layout/inlines.py", line 78, in get_next_linebox
    linebox.height, _ = strut_layout(linebox.style, context.enable_hinting)
  File "/home/amar/.virtualenvs/weasyprinttest/lib/python3.4/site-packages/weasyprint/css/computed_values.py", line 536, in strut_layout
    return value, baseline + (value - pango_height) / 2
TypeError: unsupported operand type(s) for -: 'Dimension' and 'float'
@liZe liZe added bug Existing features not working as expected crash Problems preventing documents from being rendered labels Nov 3, 2014
@liZe liZe self-assigned this Apr 28, 2015
@liZe
Copy link
Member

liZe commented Apr 28, 2015

Simple example:

<style>body{line-height: 1rem;}</style>
<body>1

Looks like the unknown units break the computed values.

@SimonSapin
Copy link
Member

This is wrong, unknow units should be rejected at parse time. See the get_length() function.

if (token.type in ('NUMBER', 'INTEGER', 'DIMENSION', 'PERCENTAGE') and
token.value >= 0):
return Dimension(token.value, token.unit)

@SimonSapin
Copy link
Member

And note that in "validator" functions, returning None means that the declaration’s value is invalid for this property. (And so the declaration should be ignored.)

@liZe liZe closed this as completed in 01a5ce7 Apr 28, 2015
@liZe
Copy link
Member

liZe commented Apr 28, 2015

Oh, maybe the solution was to implement the rem unit?

@SimonSapin
Copy link
Member

Implementing rem would be good, but that doesn’t change that line-height: 1bazinga should be rejected too.

@liZe
Copy link
Member

liZe commented Apr 29, 2015

(That was both a joke AND a hint if you don't know how to spend you next 15 minutes :p)

@halfnibble
Copy link

I'm confused. This error still occurs, and weasyprint crashes when using zurb foundation. Are you saying weasyprint will not support rem units at all?

@liZe
Copy link
Member

liZe commented Jul 6, 2015

This error still occurs, and weasyprint crashes when using zurb foundation.

It looks like it's another error, I've opened a new ticket (#260).

Are you saying weasyprint will not support rem units at all?

We are just saying that we didn't find the time to read the spec, write the code and make tests pass ;).

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

No branches or pull requests

4 participants