diff --git a/src/text/index.ts b/src/text/index.ts index a5f336c1..59fd85a6 100644 --- a/src/text/index.ts +++ b/src/text/index.ts @@ -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. diff --git a/test/__image_snapshots__/typesetting-test-tsx-test-typesetting-test-tsx-typesetting-should-wrap-normally-1-snap.png b/test/__image_snapshots__/typesetting-test-tsx-test-typesetting-test-tsx-typesetting-should-wrap-normally-1-snap.png new file mode 100644 index 00000000..a3d0593a Binary files /dev/null and b/test/__image_snapshots__/typesetting-test-tsx-test-typesetting-test-tsx-typesetting-should-wrap-normally-1-snap.png differ diff --git a/test/__image_snapshots__/typesetting-test-tsx-test-typesetting-test-tsx-typesetting-should-wrap-normally-for-special-characters-1-snap.png b/test/__image_snapshots__/typesetting-test-tsx-test-typesetting-test-tsx-typesetting-should-wrap-normally-for-special-characters-1-snap.png new file mode 100644 index 00000000..f135cf0c Binary files /dev/null and b/test/__image_snapshots__/typesetting-test-tsx-test-typesetting-test-tsx-typesetting-should-wrap-normally-for-special-characters-1-snap.png differ diff --git a/test/typesetting.test.tsx b/test/typesetting.test.tsx new file mode 100644 index 00000000..8bfd3291 --- /dev/null +++ b/test/typesetting.test.tsx @@ -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( +
+ A quick brown fox jumps over the lazy dog. +
, + { + width: 100, + height: 100, + fonts, + } + ) + + expect(toImage(svg, 100)).toMatchImageSnapshot() + }) + + it('should wrap normally for special characters', async () => { + const svg = await satori( +
+ {`@A #quick ?brown :fox !jumps -over ~the %lazy ^dog.`} +
, + { + width: 100, + height: 100, + fonts, + } + ) + + expect(toImage(svg, 100)).toMatchImageSnapshot() + }) +})