Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/text/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,10 @@ export default async function* buildTextNodes(
currentLineHeight = engine.height(word)
}

const allowedToPutAtBeginning = ',.!?:-@)>]}%#'.indexOf(word[0]) < 0
const allowedToJustify = textAlign === 'justify'

const willWrap =
i &&
allowedToPutAtBeginning &&
// When determining whether a line break is necessary, the width of the
// trailing spaces is not included in the calculation, as the end boundary
// can be closely adjacent to the last non-space character.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions test/typesetting.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { it, describe, expect } from 'vitest'

import { initFonts, toImage } from './utils.js'
import satori from '../src/index.js'

describe('typesetting', () => {
let fonts
initFonts((f) => (fonts = f))

it('should wrap normally', async () => {
const svg = await satori(
<div
style={{
width: '100%',
height: '100%',
fontSize: 18,
color: 'black',
wordBreak: 'break-word',
}}
>
A quick brown fox jumps over the lazy dog.
</div>,
{
width: 100,
height: 100,
fonts,
}
)

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

it('should wrap normally for special characters', async () => {
const svg = await satori(
<div
style={{
width: '100%',
height: '100%',
fontSize: 18,
color: 'black',
wordBreak: 'break-word',
}}
>
{`@A #quick ?brown :fox !jumps -over ~the %lazy ^dog.`}
</div>,
{
width: 100,
height: 100,
fonts,
}
)

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