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

added font config support (this allows custom fonts such as google fonts) #80

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Zac-hills
Copy link

@Zac-hills Zac-hills commented Oct 17, 2024

Added FontConfiguration object from weasyprint

  • Allows for custom font-faces for example:

@font-face { font-family: "Figtree"; font-style: normal; font-weight: 600; font-display: swap; src: url(https://fonts.gstatic.com/s/figtree/v6/_Xms-HUzqDCFdgfMm4S9DQ.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

This will now download and embed the above custom font that is defined in the css passed in.

Copy link
Owner

@jmaupetit jmaupetit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's huge, thanks!

Can you also apply the following path to test gfonts integration?

commit 2aa0398342b92016982d2f54ba51f19eedb359de
Author: Julien Maupetit <[email protected]>
Date:   Tue Oct 29 18:17:56 2024 +0100

    Fix & test @font-face integration

diff --git a/tests/assets/input.css b/tests/assets/input.css
index 5dbf8f0..5f1c479 100644
--- a/tests/assets/input.css
+++ b/tests/assets/input.css
@@ -3,6 +3,17 @@
   src: url("https://mdn.github.io/css-examples/web-fonts/VeraSeBd.ttf");
 }
 
+@font-face {
+  font-family: "Figtree";
+  font-style: normal;
+  font-weight: 600;
+  font-display: swap;
+  src: url(https://fonts.gstatic.com/s/figtree/v6/_Xms-HUzqDCFdgfMm4S9DQ.woff2) format("woff2");
+  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
+    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
+    U+2212, U+2215, U+FEFF, U+FFFD;
+}
+
 body {
   margin: 0 auto;
   background-color: white;
@@ -26,6 +37,7 @@ h2,
 h3,
 h4 {
   font-weight: 400;
+  font-family: "Figtree";
 }
 
 h2,

if css:
styles.append(CSS(filename=css))
styles.append(CSS(filename=css), font_config=font_config)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
styles.append(CSS(filename=css), font_config=font_config)
styles.append(CSS(filename=css, font_config=font_config))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants