Skip to content

Commit

Permalink
fix: Ensure fontFamily fallback (#446)
Browse files Browse the repository at this point in the history
Closes #275.
  • Loading branch information
shuding authored Apr 14, 2023
1 parent 9bbacbc commit ac1b510
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ export default class FontLoader {
fontSize = 16,
lineHeight = 1.2,
{
fontFamily,
fontFamily = 'sans-serif',
fontWeight = 400,
fontStyle = 'normal',
}: {
fontFamily: string | string[]
fontFamily?: string | string[]
fontWeight?: Weight | WeightName
fontStyle?: Style
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions test/font.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,35 @@ describe('Font', () => {
expect(toImage(svg, 100)).toMatchImageSnapshot()
})
})

it('should handle font-family fallback', async () => {
const fontName = 'MontserratSubrayada'
const fontPath = join(
process.cwd(),
'test',
'assets',
`${fontName}-Regular.ttf`
)
const fontData = await readFile(fontPath)
const montserratFont = {
name: fontName,
data: fontData,
}
const svg = await satori(
<div
style={{
fontSize: '3rem',
}}
>
Hello
</div>,
{
width: 100,
height: 100,
fonts: [montserratFont],
}
)

expect(toImage(svg, 100)).toMatchImageSnapshot()
})
})

1 comment on commit ac1b510

@vercel
Copy link

@vercel vercel bot commented on ac1b510 Apr 14, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.