WeasyPrint icon indicating copy to clipboard operation
WeasyPrint copied to clipboard

Reduction of "display, float, position" calculation

Open ssjkamei opened this issue 1 year ago • 5 comments

I tried to reduce the process of judging every __missing__ with ComputedStyle in css.

ssjkamei avatar Jan 09 '24 11:01 ssjkamei

Hi!

Thanks for the proposal. This solution is appealing, as it’s simple and removes a quite dirty workaround! But I think that it’s actually broken in some corner cases. For example:

<div style="float: none">
  <div style="float: inherit; display: inline">
    test 1
  </div>
  <div style="float: inherit; display: inline">
    test 2
  </div>
</div>

doesn’t give the same result before and after your PR (yes, that should be a test!) That’s because the current code resolves many values ('inherit', 'initial', and CSS variables for example) before storing them in the specified dictionary. But your code only uses the raw cascaded value as the specified value. In this example, with this PR, the specified float value is inherit when it should actually be none.

But you’re right, it should be possible to remove this specified dictionary somehow. It’s just not that easy, because the computed values of the three properties depend on the specified value for each other (see CSS2), and that this specified value is somewhere between the cascaded value and the computed value.

liZe avatar Jan 09 '24 21:01 liZe

Thank you!

Is the test written correctly? What I was wondering is that the original code didn't seem to come through either.

ssjkamei avatar Jan 10 '24 02:01 ssjkamei

Is the test written correctly?

Yes, that’s great. Thanks a lot, my comment was more a reminder for me than an advice for you! 🙏️

What I was wondering is that the original code didn't seem to come through either.

The current specified values go through the whole __missing__ code before being stored.

liZe avatar Jan 11 '24 07:01 liZe

Sorry, I guess I didn't communicate that well.

When I checked, I wanted to say that the previous code was also what was causing the error. (but wasn't sure if that was correct)

I understood from what you said before that you need to check the inherited value and if there is no float but a display is specified in a higher level node, you need to take that default value. Thanks very much for your help.

ssjkamei avatar Jan 11 '24 07:01 ssjkamei

When I checked, I wanted to say that the previous code was also what was causing the error. (but wasn't sure if that was correct)

I don’t get the same result.

Here’s what I get from current main branch: Capture d’écran du 2024-01-14 14-08-52

and from your branch: Capture d’écran du 2024-01-14 14-08-32

The first image is correct, as float should be seen as none, so the used value of display is inline as specified. The second image is incorrect, because float is set to inherit (not resolved to none, that’s the bug), and when float is set to something different from none then display is ignored.

liZe avatar Jan 14 '24 13:01 liZe

Closing for now, please add a comment if you want to share new commits on this topic.

liZe avatar Mar 17 '24 16:03 liZe