Skip to content

Commit 618d565

Browse files
authored
fix: textDecoration should compatible with transform (#640)
1 parent f7b0254 commit 618d565

4 files changed

+53
-11
lines changed

src/builder/text-decoration.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ export default function buildDecoration(
77
top,
88
ascender,
99
clipPathId,
10+
matrix,
1011
}: {
1112
width: number
1213
left: number
1314
top: number
1415
ascender: number
1516
clipPathId?: string
17+
matrix?: string
1618
},
1719
style: Record<string, any>
1820
) {
@@ -43,15 +45,19 @@ export default function buildDecoration(
4345
? `0 ${height * 2}`
4446
: undefined
4547

46-
return buildXMLString('line', {
47-
x1: left,
48-
y1: y,
49-
x2: left + width,
50-
y2: y,
51-
stroke: textDecorationColor || color,
52-
'stroke-width': height,
53-
'stroke-dasharray': dasharray,
54-
'stroke-linecap': textDecorationStyle === 'dotted' ? 'round' : 'square',
55-
'clip-path': clipPathId ? `url(#${clipPathId})` : undefined,
56-
})
48+
return (
49+
(clipPathId ? `<g clip-path="url(#${clipPathId})">` : '') +
50+
buildXMLString('line', {
51+
x1: left,
52+
y1: y,
53+
x2: left + width,
54+
y2: y,
55+
stroke: textDecorationColor || color,
56+
'stroke-width': height,
57+
'stroke-dasharray': dasharray,
58+
'stroke-linecap': textDecorationStyle === 'dotted' ? 'round' : 'square',
59+
transform: matrix,
60+
}) +
61+
(clipPathId ? '</g>' : '')
62+
)
5763
}

src/text/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ export default async function* buildTextNodes(
681681
width: deco[3],
682682
ascender: deco[2],
683683
clipPathId,
684+
matrix,
684685
},
685686
parentStyle
686687
)

test/text-decoration.test.tsx

+35
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,39 @@ describe('Text Decoration', () => {
152152
)
153153
expect(toImage(svg, 200)).toMatchImageSnapshot()
154154
})
155+
156+
it('Should work correctly with `text-decoration` and `transform`', async () => {
157+
const svg = await satori(
158+
<div
159+
style={{
160+
height: '100%',
161+
width: '100%',
162+
display: 'flex',
163+
padding: 10,
164+
backgroundColor: '#fff',
165+
fontSize: 32,
166+
}}
167+
>
168+
<div
169+
style={{
170+
display: 'flex',
171+
transform: 'translate(5px, 5px)',
172+
padding: 10,
173+
textDecoration: 'underline',
174+
}}
175+
>
176+
lynn
177+
</div>
178+
</div>,
179+
{
180+
width: 100,
181+
height: 100,
182+
fonts,
183+
loadAdditionalAsset: (languageCode: string, segment: string) => {
184+
return loadDynamicAsset(languageCode, segment) as any
185+
},
186+
}
187+
)
188+
expect(toImage(svg, 100)).toMatchImageSnapshot()
189+
})
155190
})

0 commit comments

Comments
 (0)