Fonts not being loaded on WeasyPrint 53.4

See original GitHub issue

[This is rather question/help request rather than current project issue, but if you can help -> thanks!]

Hey, So I wanted to update WeasyPrint from 52.5 to 53.4 on my project, and now for some reason is not loading fonts into pdf correctly (I think). I wanted to know what changed from the version to version and why it can behave like this.

WeasyPrint 53.4: image

WeasyPrint 52.5: image

Fonts are loaded using FontConfig, from template style.css file, and also by using font-faces like this:

@font-face {
      font-family: 'Roboto';
      src: local('Roboto'), url('{% static 'reports/avantage/fonts/Roboto-Regular.ttf' %}') format('truetype');
      unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
PSzczepanski1996commented, Mar 1, 2022

It works! I was only loading normal weight 400 fonts, when I added next types (italic/bold) it started working. Thanks!

1reaction
grewn0uillecommented, Feb 28, 2022

With the CSS you shared, the Roboto font is never really called. If you want to define fonts and use them on elements, you have to do something like this (please see the example below).

Here, we define two font-face, one with Regular Roboto and one with Italic Roboto, and we say that the whole body uses Roboto. So, Roboto is used everywhere and, as we gave information about Roboto Italic, WeasyPrint is able to apply Roboto Italic on i tags.

@font-face {
  font-family: Roboto;
  src: url("Roboto-regular.ttf");
}
@font-face {
  font-family: Roboto;
  src: url("Roboto-italic.ttf");
  font-style: italic;
}

body {
  font-family: Roboto;
}

With 52.5, a false italic was generated by cairo. As we don’t rely on cairo anymore, you have to define all the font-face you need.

Read more comments on GitHub >

github_iconTop Results From Across the Web

In PDF, font-face appears to be loading from URL, but is not ...
I am using WeasyPrint 52.4 and Django 3.2. I have been using system fonts, which has been working great. Now I'm trying to...
Read more >
API Reference — WeasyPrint 53.4 documentation - CourtBouillon
The font-variant-caps property is supported but needs the small-caps variant of the font to be installed. WeasyPrint does not simulate missing small-caps ...
Read more >
weasyprint 43rc2 - PyPI
WeasyPrint is free software made available under a BSD license. It is based on various libraries but *not* on a full rendering engine...
Read more >
weasyprint(1) - Debian Manpages
If no character is drawn in the generated PDF, or if you get squares instead of letters, you have to install fonts and...
Read more >
Django-weasyprint uses correct font on local but not on PAW.
I've also loaded the font in the html template: ... Yeah I tried that with Segoe UI as that was the default bootstrap...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found