From 618d565edb83270d9b829edc430788032e6f2bc6 Mon Sep 17 00:00:00 2001 From: Lynnnnnnxx Date: Sun, 6 Oct 2024 22:01:40 +0800 Subject: [PATCH] fix: textDecoration should compatible with transform (#640) --- src/builder/text-decoration.ts | 28 ++++++++------ src/text/index.ts | 1 + ...h-text-decoration-and-transform-1-snap.png | Bin 0 -> 1190 bytes test/text-decoration.test.tsx | 35 ++++++++++++++++++ 4 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 test/__image_snapshots__/text-decoration-test-tsx-test-text-decoration-test-tsx-text-decoration-should-work-correctly-with-text-decoration-and-transform-1-snap.png diff --git a/src/builder/text-decoration.ts b/src/builder/text-decoration.ts index e53e98c7..ea441ac3 100644 --- a/src/builder/text-decoration.ts +++ b/src/builder/text-decoration.ts @@ -7,12 +7,14 @@ export default function buildDecoration( top, ascender, clipPathId, + matrix, }: { width: number left: number top: number ascender: number clipPathId?: string + matrix?: string }, style: Record ) { @@ -43,15 +45,19 @@ export default function buildDecoration( ? `0 ${height * 2}` : undefined - return buildXMLString('line', { - x1: left, - y1: y, - x2: left + width, - y2: y, - stroke: textDecorationColor || color, - 'stroke-width': height, - 'stroke-dasharray': dasharray, - 'stroke-linecap': textDecorationStyle === 'dotted' ? 'round' : 'square', - 'clip-path': clipPathId ? `url(#${clipPathId})` : undefined, - }) + return ( + (clipPathId ? `` : '') + + buildXMLString('line', { + x1: left, + y1: y, + x2: left + width, + y2: y, + stroke: textDecorationColor || color, + 'stroke-width': height, + 'stroke-dasharray': dasharray, + 'stroke-linecap': textDecorationStyle === 'dotted' ? 'round' : 'square', + transform: matrix, + }) + + (clipPathId ? '' : '') + ) } diff --git a/src/text/index.ts b/src/text/index.ts index 9eb199c8..7149a84b 100644 --- a/src/text/index.ts +++ b/src/text/index.ts @@ -681,6 +681,7 @@ export default async function* buildTextNodes( width: deco[3], ascender: deco[2], clipPathId, + matrix, }, parentStyle ) diff --git a/test/__image_snapshots__/text-decoration-test-tsx-test-text-decoration-test-tsx-text-decoration-should-work-correctly-with-text-decoration-and-transform-1-snap.png b/test/__image_snapshots__/text-decoration-test-tsx-test-text-decoration-test-tsx-text-decoration-should-work-correctly-with-text-decoration-and-transform-1-snap.png new file mode 100644 index 0000000000000000000000000000000000000000..c7fc3bcab3bbff9ac242abb41593cf0f423acdc2 GIT binary patch literal 1190 zcmeAS@N?(olHy`uVBq!ia0vp^DImTdopJ-LaEQ_4??enLjWrCt&iU)_JkW*XB1V_auA3t8acmKZatbHBItU{cVgGv}kHE%jwOdFS4}Z!he%{A)OF-ny0L79O4< zed6feN2PHA9E=$uQx>(ix8IxBE>~Yu^XB3Y4=zPUFZq4v|Lt^p`>C(5Z`LK|ATM8| z+abD&2k+gRCt7zO7y?t@GfymBFX7o*Z?B)xq7W%AE-u%rZhfMr{!7$_sn^7sHnj$_ zpUk~*yU^!P&1GBnrzi8cckbD<<<99a@j2FRChJ0f7JhDW<9Nn;hF@W+$+hZ_7^WFqwL^n zNvU2pxtU9+%sRrZ5v~zEV@=?_T^=WRMD88%aGNjCU?j?)9=I*wbh6OfX)_(1(iVJR zb2DmdnPOYa%5sE@XR+GSlvtG%Hm>{xm1GZ&Q$nYNJv2?3+!jx~8h5Vkl<0&Bk{Wv& zC-x{RGVsTJWN1%slrZclo`2^zOv2OYRM^c!hh^P(D{5R+gOH!k}VT zH;>_SRe*NX_Y1yNs){ptCst>6J?Ar68N3=Pec$v6mdc7L0o*J9KJUA=eZFFtc`hFx zUru@X^~Le*Ygm@+hN*pA>SX72vo*r4*OyyJpM#YO0>D;hg>FtAC4I#}5Z; fW?7v1|A%zRoF2gx%{`BR { ) expect(toImage(svg, 200)).toMatchImageSnapshot() }) + + it('Should work correctly with `text-decoration` and `transform`', async () => { + const svg = await satori( +
+
+ lynn +
+
, + { + width: 100, + height: 100, + fonts, + loadAdditionalAsset: (languageCode: string, segment: string) => { + return loadDynamicAsset(languageCode, segment) as any + }, + } + ) + expect(toImage(svg, 100)).toMatchImageSnapshot() + }) })