Skip to content

Commit

Permalink
fix(fontshare): correctly handle weight values
Browse files Browse the repository at this point in the history
resolves #37
  • Loading branch information
danielroe committed Oct 23, 2024
1 parent a83296d commit ca100a5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/providers/fontshare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export default defineFontProvider('fontshare', async (_options, ctx) => {
if (style.is_italic && !options.styles.includes('italic')) {
continue
}
if (!options.weights.includes(String(style.weight.number))) {
if (!style.is_italic && !options.styles.includes('normal')) {
continue
}
if (!options.weights.includes(String(style.weight.weight))) {
continue
}
numbers.push(style.weight.number)
Expand Down
30 changes: 30 additions & 0 deletions test/providers/fontshare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,34 @@ describe('fontshare', () => {
]
`)
})

it('handles italic styles', async () => {
const unifont = await createUnifont([providers.fontshare()])
const { fonts } = await unifont.resolveFont('Ranade', {
styles: ['italic'],
})
expect(sanitizeFontSource(fonts)).toMatchInlineSnapshot(`
[
{
"display": "swap",
"src": [
{
"format": "woff2",
"url": "//cdn.fontshare.com/font",
},
{
"format": "woff",
"url": "//cdn.fontshare.com/font",
},
{
"format": "truetype",
"url": "//cdn.fontshare.com/font",
},
],
"style": "italic",
"weight": 400,
},
]
`)
})
})

0 comments on commit ca100a5

Please sign in to comment.