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

Linear gradients bugged with 53.x #1485

Closed
ewuerger opened this issue Nov 3, 2021 · 2 comments
Closed

Linear gradients bugged with 53.x #1485

ewuerger opened this issue Nov 3, 2021 · 2 comments
Labels
bug Existing features not working as expected
Milestone

Comments

@ewuerger
Copy link

ewuerger commented Nov 3, 2021

Hi,

First of all: Thank you very much for this great library!

We are using weasyprint to generate many specification documents in the railway market. Since version 53 our b64 encoded images are looking very weird. It seems like linearGradient elements are not recognized anymore and coordinates are wrong too. I hope the following images help you to debug it.

image
image
(size difference is just b/c of my snipping tool precision)

test.svg

<?xml version="1.0" encoding="utf-8" ?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events"
    xmlns:xlink="http://www.w3.org/1999/xlink" baseProfile="full" height="100" version="1.1" width="100">
    <defs>
        <style>
            .Example {
                fill: url("#.FillGradient");
                stroke: #4A4A97;
            }
        </style>
        <linearGradient id=".FillGradient" x1="0%" x2="0%" y1="0%" y2="100%">
            <stop offset="0" stop-color="#EF2929" />
            <stop offset="1" stop-color="#FFFFFF" />
        </linearGradient>
    </defs>
    <rect class="Example" height="100" width="100" x="0" y="0" />
    <text dominant-baseline="middle" text-anchor="start" x="20" y="15">
        <tspan x="15" xml:space="preserve" y="50">Example</tspan>
    </text>
</svg>

Showcase script

import base64
import jinja2

svg = pathlib.Path("test.svg").read_text()
b64 = base64.standard_b64encode(svg.encode("utf-8"))
b64_svg = "".join(("data:image/svg+xml;base64,", b64.decode("ascii")))
template = """
<!DOCTYPE html>
<html>
<style>
article {
    page: content;
}
@page content {
    size: A4 portrait;
    margin: 2cm 2cm 2cm 2.5cm;
}
figure>img {
    max-width: 100%;
    margin-left: auto;
}
</style>
<body>
<article>
<p>weasyprint 53</p>
<figure><img src="{{b64_svg}}"/></figure>
</article>
</body>
</html>
"""
template = jinja2.Environment().from_string(template).render(b64_svg=b64_svg)
html_template = weasyprint.HTML(string=template, base_url=".")
html_template.write_pdf(target=pathlib.Path("test.pdf"))

For now we need to stick to weasyprint<=53.

liZe added a commit that referenced this issue Nov 4, 2021
liZe added a commit that referenced this issue Nov 4, 2021
It’s hard to get real values, because it would require to access the font
information. But we can at least use values related to the font size, so that
alignment doesn’t get totally wrong.

Related to #1485.
liZe added a commit that referenced this issue Nov 4, 2021
liZe added a commit that referenced this issue Nov 4, 2021
It’s hard to get real values, because it would require to access the font
information. But we can at least use values related to the font size, so that
alignment doesn’t get totally wrong.

Related to #1485.
@liZe liZe added the bug Existing features not working as expected label Nov 4, 2021
@liZe liZe added this to the 53.4 milestone Nov 4, 2021
@liZe
Copy link
Member

liZe commented Nov 4, 2021

Hello, and thanks a lot for this very well documented issue.

First of all: Thank you very much for this great library!

💜

It seems like linearGradient elements are not recognized anymore and coordinates are wrong too.

There were actually two bugs… The linear gradient was missing because of quotes not being handled correctly in url(…) values. The coordinates were wrong because of a dirty values used as font descent and ascent. The new values are still wrong (because they’re not the real values of the font), but at least they take care of the font size and should give suitable results in simple cases.

They’re fixed in the master branch, and will also be included in the next 53.4 version.

We are using weasyprint to generate many specification documents in the railway market.

Glad to hear that WeasyPrint is useful for you! Don’t hesitate to send us a mail if you’d like to share your experience, we’d be really happy to learn more about these mysterious railway specifications 🚆🚆🚆 😃.

@liZe liZe closed this as completed Nov 4, 2021
@liZe
Copy link
Member

liZe commented Nov 4, 2021

(Oh, and we definitely miss tests for SVG, it’s an issue we’re aware of and that’s scheduled for version 55.)

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
Projects
None yet
Development

No branches or pull requests

2 participants