Add 'rem' support #295

Closed
wants to merge 12 commits into
from

Conversation

3 participants
@fdemmer

fdemmer commented Feb 10, 2016

I am using Foundation, that uses the 'rem' unit a lot.

I am not sure about what i am doing here is correctly implementing the spec and the implementation follows "weasyprint conventions". Is there documentation on how weasy works? sequence of operations, what happens where etc?

I read through #264 to maybe figure this out, but I don't need all the viewport related relative units, so I attempted to just solve 'rem' for now.

It's based on the 'font-size' of the root element, so I am passing on the computed style of the 'body' element to compute() and use it in length().

My pdf output now works as I'd expect it.

weasyprint/css/__init__.py
-
+ parent_style = computed_styles[parent, None] \
+ if parent is not None else None
+ root_style = computed_styles.get((root, None), {})

This comment has been minimized.

@SimonSapin

SimonSapin Feb 10, 2016

Member

.get() here should be [] indexing. We want this to fail early if the root element’s style can’t be found. This should be fine since get_all_computed_styles deals with the root element first.

But this brings the question: what about computing styles for the root element itself? Let’s look at the spec:

https://drafts.csswg.org/css-values/#rem

Equal to the computed value of font-size on the root element. When specified on the font-size property of the root element, the rem units refer to the property’s initial value.

All in all, please replace this line with:

root_style = computed_styles[root, None] if root is not element else properties.INITIAL_VALUES
@SimonSapin

SimonSapin Feb 10, 2016

Member

.get() here should be [] indexing. We want this to fail early if the root element’s style can’t be found. This should be fine since get_all_computed_styles deals with the root element first.

But this brings the question: what about computing styles for the root element itself? Let’s look at the spec:

https://drafts.csswg.org/css-values/#rem

Equal to the computed value of font-size on the root element. When specified on the font-size property of the root element, the rem units refer to the property’s initial value.

All in all, please replace this line with:

root_style = computed_styles[root, None] if root is not element else properties.INITIAL_VALUES

This comment has been minimized.

@SimonSapin

SimonSapin Feb 10, 2016

Member

Ah, sorry, it’s more subtle than I first thought. rem refers to the initial value for font-size on the root element, but it still has its usual definition for other properties of the root element.

I’ll leave it to you to figure out how to do this exactly. Unless you’d rather I do it, let me know.

@SimonSapin

SimonSapin Feb 10, 2016

Member

Ah, sorry, it’s more subtle than I first thought. rem refers to the initial value for font-size on the root element, but it still has its usual definition for other properties of the root element.

I’ll leave it to you to figure out how to do this exactly. Unless you’d rather I do it, let me know.

@SimonSapin

This comment has been minimized.

Show comment
Hide comment
@SimonSapin

SimonSapin Feb 10, 2016

Member

Thanks for your contribution! This looks good overall, there are just some minor issues noted inline.

It’d be good to add tests for this as well: change weasyprint/tests/resources/doc1.html to use rem (both in font-size and other properties, both on the root element and other elements) and test_annotate_document() in weasyprint/tests/test_css.py to check computed values.

Let me know if you want to do these fixes and add tests or if you’d rather I do it.

Member

SimonSapin commented Feb 10, 2016

Thanks for your contribution! This looks good overall, there are just some minor issues noted inline.

It’d be good to add tests for this as well: change weasyprint/tests/resources/doc1.html to use rem (both in font-size and other properties, both on the root element and other elements) and test_annotate_document() in weasyprint/tests/test_css.py to check computed values.

Let me know if you want to do these fixes and add tests or if you’d rather I do it.

@fdemmer

This comment has been minimized.

Show comment
Hide comment
@fdemmer

fdemmer Feb 11, 2016

updated the branch:

  • using set()
  • use actual root element, not body
  • take the initial font-size as input into the style computation for the root element

in my dev environment i get a lot of failing tests, would be great and probably save me a lot of time if you could complete that. thanks!

ah and i thought you could do a merge --squash or do you want me to squash the branch...?

fdemmer commented Feb 11, 2016

updated the branch:

  • using set()
  • use actual root element, not body
  • take the initial font-size as input into the style computation for the root element

in my dev environment i get a lot of failing tests, would be great and probably save me a lot of time if you could complete that. thanks!

ah and i thought you could do a merge --squash or do you want me to squash the branch...?

@SimonSapin

This comment has been minimized.

Show comment
Hide comment
@SimonSapin

SimonSapin Feb 11, 2016

Member

I didn’t know about merge --squash, thanks! (I’ve been using rebase -i.)

I’ll look into tests later if @liZe doesn’t get to it first ;)

Member

SimonSapin commented Feb 11, 2016

I didn’t know about merge --squash, thanks! (I’ve been using rebase -i.)

I’ll look into tests later if @liZe doesn’t get to it first ;)

@liZe

This comment has been minimized.

Show comment
Hide comment
@liZe

liZe Feb 11, 2016

Member

Everything is OK on Travis, even with Python 2.6, good news. I've updated the tests and it works very well, but I can't push as it's not my branch.

@SimonSapin if everything is OK for you, I can merge and commit the test after.
@fdemmer I can squash the branch and add you in the AUTHORS :).

Member

liZe commented Feb 11, 2016

Everything is OK on Travis, even with Python 2.6, good news. I've updated the tests and it works very well, but I can't push as it's not my branch.

@SimonSapin if everything is OK for you, I can merge and commit the test after.
@fdemmer I can squash the branch and add you in the AUTHORS :).

@fdemmer

This comment has been minimized.

Show comment
Hide comment
@fdemmer

fdemmer Feb 11, 2016

👍 and thanks for weasyprint!

fdemmer commented Feb 11, 2016

👍 and thanks for weasyprint!

@liZe

This comment has been minimized.

Show comment
Hide comment
@liZe

liZe Feb 11, 2016

Member

Thank you for your contribution!

Member

liZe commented Feb 11, 2016

Thank you for your contribution!

@liZe liZe closed this Feb 11, 2016

@SimonSapin

This comment has been minimized.

Show comment
Hide comment
Member

SimonSapin commented Feb 17, 2016

@liZe

This comment has been minimized.

Show comment
Hide comment
@liZe

liZe Feb 20, 2016

Member

Will be done in #297.

Member

liZe commented Feb 20, 2016

Will be done in #297.

jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Jan 15, 2017

kleink
Update py-weasyprint to 0.34.
Version 0.34
------------

Released on 2016-12-21.

Bug fixes:

* `#398 <Kozea/WeasyPrint#398>`_:
  Honor the presentational_hints option for PDFs.
* `#399 <Kozea/WeasyPrint#399>`_:
  Avoid CairoSVG-2.0.0rc* on Python 2.
* `#396 <Kozea/WeasyPrint#396>`_:
  Correctly close files open by mkstemp.
* `#403 <Kozea/WeasyPrint#403>`_:
  Cast the number of columns into int.
* Fix multi-page multi-columns and add related tests.


Version 0.33
------------

Released on 2016-11-28.

New features:

* `#393 <Kozea/WeasyPrint#393:
  Add tests on MacOS.
* `#370 <Kozea/WeasyPrint#370>`_:
  Enable @font-face on MacOS.

Bug fixes:

* `#389 <Kozea/WeasyPrint#389>`_:
  Always update resume_at when splitting lines.
* `#394 <Kozea/WeasyPrint#394>`_:
  Don't build universal wheels.
* `#388 <Kozea/WeasyPrint#388>`_:
  Fix logic when finishing block formatting context.


Version 0.32
------------

Released on 2016-11-17.

New features:

* `#28 <Kozea/WeasyPrint#28>`_:
  Support @font-face on Linux.
* Support CSS fonts level 3 almost entirely, including OpenType features.
* `#253 <Kozea/WeasyPrint#253>`_:
  Support presentational hints (optional).
* Support break-after, break-before and break-inside for pages and columns.
* `#384 <Kozea/WeasyPrint#384:
  Major performance boost.

Bux fixes:

* `#368 <Kozea/WeasyPrint#368>`_:
  Respect white-space for shrink-to-fit.
* `#382 <Kozea/WeasyPrint#382>`_:
  Fix the preferred width for column groups.
* Handle relative boxes in column-layout boxes.

Documentation:

* Add more and more documentation about Windows installation.
* `#355 <Kozea/WeasyPrint#355:
  Add fonts requirements for tests.


Version 0.31
------------

Released on 2016-08-28.

New features:

* `#124 <Kozea/WeasyPrint#124>`_:
  Add MIME sniffing for images.
* `#60 <Kozea/WeasyPrint#60>`_:
  CSS Multi-column Layout.
* `#197 <Kozea/WeasyPrint#197>`_:
  Add hyphens at line breaks activated by a soft hyphen.

Bux fixes:

* `#132 <Kozea/WeasyPrint#132>`_:
  Fix Python 3 compatibility on Windows.

Documentation:

* `#329 <Kozea/WeasyPrint#329>`_:
  Add documentation about installation on Windows.


Version 0.30
------------

Released on 2016-07-18.

WeasyPrint now depends on html5lib-0.999999999.

Bux fixes:

* Fix Acid2
* `#325 <Kozea/WeasyPrint#325>`_:
  Cutting lines is broken in page margin boxes.
* `#334 <Kozea/WeasyPrint#334>`_:
  Newest html5lib 0.999999999 breaks rendering.


Version 0.29
------------

Released on 2016-06-17.

Bug fixes:

* `#263 <Kozea/WeasyPrint#263:
  Don't crash with floats with percents in positions.
* `#323 <Kozea/WeasyPrint#323>`_:
  Fix CairoSVG 2.0 pre-release dependency in Python 2.x.


Version 0.28
------------

Released on 2016-05-16.

Bug fixes:

* `#189 <Kozea/WeasyPrint#189>`_:
  ``white-space: nowrap`` still wraps on hyphens
* `#305 <Kozea/WeasyPrint#305>`_:
  Fix crashes on some tables
* Don't crash when transform matrix isn't invertible
* Don't crash when rendering ratio-only SVG images
* Fix margins and borders on some tables


Version 0.27
------------

Released on 2016-04-08.

New features:

* `#295 <Kozea/WeasyPrint#295>`_:
  Support the 'rem' unit.
* `#299 <Kozea/WeasyPrint#299>`_:
  Enhance the support of SVG images.

Bug fixes:

* `#307 <Kozea/WeasyPrint#307>`_:
  Fix the layout of cells larger than their tables.

Documentation:

* The website is now on GitHub Pages, the documentation is on Read the Docs.
* `#297 <Kozea/WeasyPrint#297>`_:
  Rewrite the CSS chapter of the documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment