Skip to content

Commit 87affba

Browse files
committed
Fix Google Fonts missing font hinting info
Google fonts returns files that have the font hinting instructions removed when the user agent is set as OSX. This is almost certainly due to the fact that OSX disabled sub-pixel antialiasing by default back with the release of Mojave. Switching out the user agent for an equivalent windows one will ensure that the font hinting is included, dramatically improving the rendering of most fonts on 1x resolution screens where font hinting is enabled. This seems to result in a roughly 20% increase in the size of the fetched fonts.
1 parent 0e973f7 commit 87affba

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

crates/next-core/src/next_font/google/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub const GOOGLE_FONTS_STYLESHEET_URL: &str = "https://fonts.googleapis.com/css2
6565
// Always sending this user agent ensures consistent results from Google Fonts.
6666
// Google Fonts will vary responses based on user agent, e.g. only returning
6767
// references to certain font types for certain browsers.
68-
pub const USER_AGENT_FOR_GOOGLE_FONTS: &str = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) \
68+
pub const USER_AGENT_FOR_GOOGLE_FONTS: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) \
6969
AppleWebKit/537.36 (KHTML, like Gecko) \
7070
Chrome/104.0.0.0 Safari/537.36";
7171

packages/font/src/google/fetch-resource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function fetchResource(
2424
headers: {
2525
// The file format is based off of the user agent, make sure woff2 files are fetched
2626
'User-Agent':
27-
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ' +
27+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' +
2828
'AppleWebKit/537.36 (KHTML, like Gecko) ' +
2929
'Chrome/104.0.0.0 Safari/537.36',
3030
},

0 commit comments

Comments
 (0)