openhtmltopdf icon indicating copy to clipboard operation
openhtmltopdf copied to clipboard

Gradient stops are positioned incorrectly

Open jochenberger opened this issue 2 years ago • 4 comments

Consider the following HTML

<html>
<head>
<style>
div {
  border: 1mm dashed black;
  background-image: linear-gradient(to top, red 0, red 5mm, white 5mm, white);
  margin: 5mm;
}
.h1 { height: 1cm; }
.h3 { height: 3cm; }
.w1 { width: 1cm; }
.w3 { width: 3cm; }
</style>
</head>
<body>
<div class="h1 w1"/>
<div class="h1 w3"/>
<div class="h3 w1"/>
<div class="h3 w3"/>
</body>
</html>

All the divs should have a 5mm red bar at the bottom. But the result looks like this: grafik

I think we can ignore the blur, that's probably https://github.com/mozilla/pdf.js/issues/10572. But at least the red bars should all have the same height since it's given in mm.

Btw, if you change the gradient to to right, all the bars have the same width: grafik

So it's probably got something to do with the y coordinates.

jochenberger avatar Nov 15 '22 07:11 jochenberger

I assume that there's something wrong with the com.openhtmltopdf.css.style.derived.FSLinearGradient.endPointsFromAngle(float, int, int) method.

jochenberger avatar Nov 15 '22 07:11 jochenberger

After some debugging, I think that the problem is that the wrong distance is passed to com.openhtmltopdf.pdfboxout.GradientHelper.buildType3Function(List<StopPoint>, float). But I haven't yet figured out all of the math that's done there.

jochenberger avatar Nov 15 '22 08:11 jochenberger

@siegelzc, do you think this is something we could address in the fork?

jochenberger avatar May 22 '24 12:05 jochenberger

@siegelzc, do you think this is something we could address in the fork?

Of course. I'm not going to personally commit to implementing it though.

siegelzc avatar May 22 '24 13:05 siegelzc