Could not calculate distance when resolving text path
Description
We are using Skia to build an instrument panel for boats, which needs to be updated at 5Hz. At the top left corner of the attached screenshot, you can see an instrument that contains several curved texts made using the TextPath component.
At the moment we are using version 0.1.137 and it works fine (with known issues for that version, but with no crashes). I'm trying to upgrade the version, as I see many new features and improvements, but after 10-15min of activity the app crashes in both iOS and Android with this error Could not calculate distance when resolving text path coming from com.shopify.reactnative.skia.PlatformContext$2 in run at line 73.
Before the crash, everything works as expected. Any clue of what can be the cause?
Version
0.176
Steps to reproduce
Not able to intentionally reproduce it, but what we have are four TextPath with string values that update every 200ms.
Snack, code example, screenshot, or link to a repository

Thanks for reporting this, the project looks very impressive. I would like to reproduce the issue. Which font are you using? Is the error reproducible with any font? (e.g SF Pro) Could you log the paths and texts parameters everytime they are updating (before drawing/crashing) and we send it to us? this will allow to add a test for it and fix the issue.
Is the path you draw the text to a full circle? (that would mean it's not an issue where we try to draw text outside the bounds of the path)
I hope that we can get to the bottom of this ASAP.
Thanks for your quick reply!
We're using an edited version of Uber Move, which uses monospace for numbers. If you need the exact one, you can download it here. I'll try to use SF Pro now, and see if it also crashes or not.
Yes, it is a full-circle path. This is the full component I use:
const font = overrideFont || UberMove;
const textFont = useFont(font, fontSize);
const textColor = color || WidgetsColorTheme[theme].TEXT;
const isFlippedPath = angle < 90 || angle > 270;
const path = useComputedValue(() => {
const circlePath = Skia.Path.Make().addCircle(center.x, center.y, rad)!;
const reversedPath = reverse(circlePath.toSVGString());
if (isFlippedPath) return circlePath;
return Skia.Path.MakeFromSVGString(reversedPath)!;
}, [center, rad, angle]);
const rotate = useMemo(() => toRad(angle - 90), [angle]);
const labelOffset = useMemo(() => {
if (!textFont || label === '') return 0;
const labelWidth = textFont.getTextWidth(`${label} `);
return Math.asin(labelWidth / rad);
}, [label, rad, textFont]);
const stringValue = useComputedValue(() => {
const val = isNumber(value) ? value : value.current;
return `${val.toFixed()} ${unit}`;
}, [value]);
if (!textFont || !path.current) return null;
return (
<>
<Group
transform={[
{
rotate: rotate - (isFlippedPath ? labelOffset : -labelOffset),
},
]}
origin={vec(172.11, 172.11)}
>
<TextPath
font={textFont}
path={path}
text={label}
color={textColor}
/>
</Group>
<Group transform={[{rotate}]} origin={vec(172.11, 172.11)}>
<TextPath
font={textFont}
path={path}
text={stringValue}
color={textColor}
/>
</Group>
</>
);
},
Tried to log what you requested, but everything looks normal. Also, JS continued logging after the crash (in debug). Please, find attached an example of the logs (path, label, value):
M332 172Q332 175.928 331.807 179.851Q331.615 183.774 331.23 187.683Q330.845 191.592 330.268 195.477Q329.692 199.362 328.926 203.214Q328.159 207.067 327.205 210.877Q326.251 214.687 325.11 218.446Q323.97 222.204 322.647 225.902Q321.324 229.601 319.821 233.229Q318.318 236.858 316.638 240.409Q314.959 243.959 313.107 247.423Q311.256 250.887 309.237 254.256Q307.217 257.625 305.035 260.891Q302.853 264.157 300.513 267.312Q298.173 270.467 295.682 273.503Q293.19 276.539 290.552 279.449Q287.914 282.36 285.137 285.137Q282.36 287.914 279.449 290.552Q276.539 293.19 273.503 295.682Q270.467 298.173 267.312 300.513Q264.157 302.853 260.891 305.035Q257.625 307.217 254.256 309.237Q250.887 311.256 247.423 313.107Q243.959 314.959 240.409 316.638Q236.858 318.318 233.229 319.821Q229.601 321.324 225.902 322.647Q222.204 323.97 218.446 325.11Q214.687 326.251 210.877 327.205Q207.067 328.159 203.214 328.926Q199.362 329.692 195.477 330.268Q191.592 330.845 187.683 331.23Q183.774 331.615 179.851 331.807Q175.928 332 172 332Q168.072 332 164.149 331.807Q160.226 331.615 156.317 331.23Q152.408 330.845 148.523 330.268Q144.638 329.692 140.786 328.926Q136.933 328.159 133.123 327.205Q129.313 326.251 125.554 325.11Q121.796 323.97 118.098 322.647Q114.399 321.324 110.771 319.821Q107.142 318.318 103.591 316.638Q100.041 314.959 96.5765 313.107Q93.1125 311.256 89.7435 309.237Q86.3746 307.217 83.1087 305.035Q79.8429 302.853 76.6881 300.513Q73.5333 298.173 70.4971 295.682Q67.4609 293.19 64.5506 290.552Q61.6403 287.914 58.8629 285.137Q56.0855 282.36 53.4478 279.449Q50.8101 276.539 48.3183 273.503Q45.8266 270.467 43.4868 267.312Q41.147 264.157 38.9649 260.891Q36.7827 257.625 34.7634 254.256Q32.7441 250.887 30.8926 247.423Q29.0411 243.959 27.3617 240.409Q25.6824 236.858 24.1793 233.229Q22.6762 229.601 21.3529 225.902Q20.0297 222.204 18.8895 218.446Q17.7494 214.687 16.795 210.877Q15.8406 207.067 15.0744 203.214Q14.3081 199.362 13.7318 195.477Q13.1554 191.592 12.7704 187.683Q12.3855 183.774 12.1927 179.851Q12 175.928 12 172Q12 168.072 12.1927 164.149Q12.3855 160.226 12.7704 156.317Q13.1554 152.408 13.7318 148.523Q14.3081 144.638 15.0744 140.786Q15.8406 136.933 16.795 133.123Q17.7494 129.313 18.8895 125.554Q20.0297 121.796 21.3529 118.098Q22.6762 114.399 24.1793 110.771Q25.6824 107.142 27.3617 103.591Q29.0411 100.041 30.8926 96.5765Q32.7441 93.1125 34.7634 89.7435Q36.7827 86.3746 38.9649 83.1087Q41.147 79.8429 43.4868 76.6881Q45.8266 73.5333 48.3183 70.4971Q50.8101 67.4609 53.4478 64.5506Q56.0855 61.6403 58.8629 58.8629Q61.6403 56.0855 64.5506 53.4478Q67.4609 50.8101 70.4971 48.3183Q73.5333 45.8266 76.6881 43.4868Q79.8429 41.147 83.1087 38.9649Q86.3746 36.7827 89.7435 34.7634Q93.1125 32.7441 96.5765 30.8926Q100.041 29.0411 103.591 27.3617Q107.142 25.6824 110.771 24.1793Q114.399 22.6762 118.098 21.3529Q121.796 20.0297 125.554 18.8895Q129.313 17.7494 133.123 16.795Q136.933 15.8406 140.786 15.0744Q144.638 14.3081 148.523 13.7318Q152.408 13.1554 156.317 12.7704Q160.226 12.3855 164.149 12.1927Q168.072 12 172 12Q175.928 12 179.851 12.1927Q183.774 12.3855 187.683 12.7704Q191.592 13.1554 195.477 13.7318Q199.362 14.3081 203.214 15.0744Q207.067 15.8406 210.877 16.795Q214.687 17.7494 218.446 18.8895Q222.204 20.0297 225.902 21.3529Q229.601 22.6762 233.229 24.1793Q236.858 25.6824 240.409 27.3617Q243.959 29.0411 247.423 30.8926Q250.887 32.7441 254.256 34.7634Q257.625 36.7827 260.891 38.9649Q264.157 41.147 267.312 43.4868Q270.467 45.8266 273.503 48.3183Q276.539 50.8101 279.449 53.4478Q282.36 56.0855 285.137 58.8629Q287.914 61.6403 290.552 64.5506Q293.19 67.4609 295.682 70.4971Q298.173 73.5333 300.513 76.6881Q302.853 79.8429 305.035 83.1087Q307.217 86.3746 309.237 89.7435Q311.256 93.1125 313.107 96.5765Q314.959 100.041 316.638 103.591Q318.318 107.142 319.821 110.771Q321.324 114.399 322.647 118.098Q323.97 121.796 325.11 125.554Q326.251 129.313 327.205 133.123Q328.159 136.933 328.926 140.786Q329.692 144.638 330.268 148.523Q330.845 152.408 331.23 156.317Q331.615 160.226 331.807 164.149Q332 168.072 332 172Z AWA 31 °
M332 172Q332 175.928 331.807 179.851Q331.615 183.774 331.23 187.683Q330.845 191.592 330.268 195.477Q329.692 199.362 328.926 203.214Q328.159 207.067 327.205 210.877Q326.251 214.687 325.11 218.446Q323.97 222.204 322.647 225.902Q321.324 229.601 319.821 233.229Q318.318 236.858 316.638 240.409Q314.959 243.959 313.107 247.423Q311.256 250.887 309.237 254.256Q307.217 257.625 305.035 260.891Q302.853 264.157 300.513 267.312Q298.173 270.467 295.682 273.503Q293.19 276.539 290.552 279.449Q287.914 282.36 285.137 285.137Q282.36 287.914 279.449 290.552Q276.539 293.19 273.503 295.682Q270.467 298.173 267.312 300.513Q264.157 302.853 260.891 305.035Q257.625 307.217 254.256 309.237Q250.887 311.256 247.423 313.107Q243.959 314.959 240.409 316.638Q236.858 318.318 233.229 319.821Q229.601 321.324 225.902 322.647Q222.204 323.97 218.446 325.11Q214.687 326.251 210.877 327.205Q207.067 328.159 203.214 328.926Q199.362 329.692 195.477 330.268Q191.592 330.845 187.683 331.23Q183.774 331.615 179.851 331.807Q175.928 332 172 332Q168.072 332 164.149 331.807Q160.226 331.615 156.317 331.23Q152.408 330.845 148.523 330.268Q144.638 329.692 140.786 328.926Q136.933 328.159 133.123 327.205Q129.313 326.251 125.554 325.11Q121.796 323.97 118.098 322.647Q114.399 321.324 110.771 319.821Q107.142 318.318 103.591 316.638Q100.041 314.959 96.5765 313.107Q93.1125 311.256 89.7435 309.237Q86.3746 307.217 83.1087 305.035Q79.8429 302.853 76.6881 300.513Q73.5333 298.173 70.4971 295.682Q67.4609 293.19 64.5506 290.552Q61.6403 287.914 58.8629 285.137Q56.0855 282.36 53.4478 279.449Q50.8101 276.539 48.3183 273.503Q45.8266 270.467 43.4868 267.312Q41.147 264.157 38.9649 260.891Q36.7827 257.625 34.7634 254.256Q32.7441 250.887 30.8926 247.423Q29.0411 243.959 27.3617 240.409Q25.6824 236.858 24.1793 233.229Q22.6762 229.601 21.3529 225.902Q20.0297 222.204 18.8895 218.446Q17.7494 214.687 16.795 210.877Q15.8406 207.067 15.0744 203.214Q14.3081 199.362 13.7318 195.477Q13.1554 191.592 12.7704 187.683Q12.3855 183.774 12.1927 179.851Q12 175.928 12 172Q12 168.072 12.1927 164.149Q12.3855 160.226 12.7704 156.317Q13.1554 152.408 13.7318 148.523Q14.3081 144.638 15.0744 140.786Q15.8406 136.933 16.795 133.123Q17.7494 129.313 18.8895 125.554Q20.0297 121.796 21.3529 118.098Q22.6762 114.399 24.1793 110.771Q25.6824 107.142 27.3617 103.591Q29.0411 100.041 30.8926 96.5765Q32.7441 93.1125 34.7634 89.7435Q36.7827 86.3746 38.9649 83.1087Q41.147 79.8429 43.4868 76.6881Q45.8266 73.5333 48.3183 70.4971Q50.8101 67.4609 53.4478 64.5506Q56.0855 61.6403 58.8629 58.8629Q61.6403 56.0855 64.5506 53.4478Q67.4609 50.8101 70.4971 48.3183Q73.5333 45.8266 76.6881 43.4868Q79.8429 41.147 83.1087 38.9649Q86.3746 36.7827 89.7435 34.7634Q93.1125 32.7441 96.5765 30.8926Q100.041 29.0411 103.591 27.3617Q107.142 25.6824 110.771 24.1793Q114.399 22.6762 118.098 21.3529Q121.796 20.0297 125.554 18.8895Q129.313 17.7494 133.123 16.795Q136.933 15.8406 140.786 15.0744Q144.638 14.3081 148.523 13.7318Q152.408 13.1554 156.317 12.7704Q160.226 12.3855 164.149 12.1927Q168.072 12 172 12Q175.928 12 179.851 12.1927Q183.774 12.3855 187.683 12.7704Q191.592 13.1554 195.477 13.7318Q199.362 14.3081 203.214 15.0744Q207.067 15.8406 210.877 16.795Q214.687 17.7494 218.446 18.8895Q222.204 20.0297 225.902 21.3529Q229.601 22.6762 233.229 24.1793Q236.858 25.6824 240.409 27.3617Q243.959 29.0411 247.423 30.8926Q250.887 32.7441 254.256 34.7634Q257.625 36.7827 260.891 38.9649Q264.157 41.147 267.312 43.4868Q270.467 45.8266 273.503 48.3183Q276.539 50.8101 279.449 53.4478Q282.36 56.0855 285.137 58.8629Q287.914 61.6403 290.552 64.5506Q293.19 67.4609 295.682 70.4971Q298.173 73.5333 300.513 76.6881Q302.853 79.8429 305.035 83.1087Q307.217 86.3746 309.237 89.7435Q311.256 93.1125 313.107 96.5765Q314.959 100.041 316.638 103.591Q318.318 107.142 319.821 110.771Q321.324 114.399 322.647 118.098Q323.97 121.796 325.11 125.554Q326.251 129.313 327.205 133.123Q328.159 136.933 328.926 140.786Q329.692 144.638 330.268 148.523Q330.845 152.408 331.23 156.317Q331.615 160.226 331.807 164.149Q332 168.072 332 172Z HDG 137 °
M332 172Q332 175.928 331.807 179.851Q331.615 183.774 331.23 187.683Q330.845 191.592 330.268 195.477Q329.692 199.362 328.926 203.214Q328.159 207.067 327.205 210.877Q326.251 214.687 325.11 218.446Q323.97 222.204 322.647 225.902Q321.324 229.601 319.821 233.229Q318.318 236.858 316.638 240.409Q314.959 243.959 313.107 247.423Q311.256 250.887 309.237 254.256Q307.217 257.625 305.035 260.891Q302.853 264.157 300.513 267.312Q298.173 270.467 295.682 273.503Q293.19 276.539 290.552 279.449Q287.914 282.36 285.137 285.137Q282.36 287.914 279.449 290.552Q276.539 293.19 273.503 295.682Q270.467 298.173 267.312 300.513Q264.157 302.853 260.891 305.035Q257.625 307.217 254.256 309.237Q250.887 311.256 247.423 313.107Q243.959 314.959 240.409 316.638Q236.858 318.318 233.229 319.821Q229.601 321.324 225.902 322.647Q222.204 323.97 218.446 325.11Q214.687 326.251 210.877 327.205Q207.067 328.159 203.214 328.926Q199.362 329.692 195.477 330.268Q191.592 330.845 187.683 331.23Q183.774 331.615 179.851 331.807Q175.928 332 172 332Q168.072 332 164.149 331.807Q160.226 331.615 156.317 331.23Q152.408 330.845 148.523 330.268Q144.638 329.692 140.786 328.926Q136.933 328.159 133.123 327.205Q129.313 326.251 125.554 325.11Q121.796 323.97 118.098 322.647Q114.399 321.324 110.771 319.821Q107.142 318.318 103.591 316.638Q100.041 314.959 96.5765 313.107Q93.1125 311.256 89.7435 309.237Q86.3746 307.217 83.1087 305.035Q79.8429 302.853 76.6881 300.513Q73.5333 298.173 70.4971 295.682Q67.4609 293.19 64.5506 290.552Q61.6403 287.914 58.8629 285.137Q56.0855 282.36 53.4478 279.449Q50.8101 276.539 48.3183 273.503Q45.8266 270.467 43.4868 267.312Q41.147 264.157 38.9649 260.891Q36.7827 257.625 34.7634 254.256Q32.7441 250.887 30.8926 247.423Q29.0411 243.959 27.3617 240.409Q25.6824 236.858 24.1793 233.229Q22.6762 229.601 21.3529 225.902Q20.0297 222.204 18.8895 218.446Q17.7494 214.687 16.795 210.877Q15.8406 207.067 15.0744 203.214Q14.3081 199.362 13.7318 195.477Q13.1554 191.592 12.7704 187.683Q12.3855 183.774 12.1927 179.851Q12 175.928 12 172Q12 168.072 12.1927 164.149Q12.3855 160.226 12.7704 156.317Q13.1554 152.408 13.7318 148.523Q14.3081 144.638 15.0744 140.786Q15.8406 136.933 16.795 133.123Q17.7494 129.313 18.8895 125.554Q20.0297 121.796 21.3529 118.098Q22.6762 114.399 24.1793 110.771Q25.6824 107.142 27.3617 103.591Q29.0411 100.041 30.8926 96.5765Q32.7441 93.1125 34.7634 89.7435Q36.7827 86.3746 38.9649 83.1087Q41.147 79.8429 43.4868 76.6881Q45.8266 73.5333 48.3183 70.4971Q50.8101 67.4609 53.4478 64.5506Q56.0855 61.6403 58.8629 58.8629Q61.6403 56.0855 64.5506 53.4478Q67.4609 50.8101 70.4971 48.3183Q73.5333 45.8266 76.6881 43.4868Q79.8429 41.147 83.1087 38.9649Q86.3746 36.7827 89.7435 34.7634Q93.1125 32.7441 96.5765 30.8926Q100.041 29.0411 103.591 27.3617Q107.142 25.6824 110.771 24.1793Q114.399 22.6762 118.098 21.3529Q121.796 20.0297 125.554 18.8895Q129.313 17.7494 133.123 16.795Q136.933 15.8406 140.786 15.0744Q144.638 14.3081 148.523 13.7318Q152.408 13.1554 156.317 12.7704Q160.226 12.3855 164.149 12.1927Q168.072 12 172 12Q175.928 12 179.851 12.1927Q183.774 12.3855 187.683 12.7704Q191.592 13.1554 195.477 13.7318Q199.362 14.3081 203.214 15.0744Q207.067 15.8406 210.877 16.795Q214.687 17.7494 218.446 18.8895Q222.204 20.0297 225.902 21.3529Q229.601 22.6762 233.229 24.1793Q236.858 25.6824 240.409 27.3617Q243.959 29.0411 247.423 30.8926Q250.887 32.7441 254.256 34.7634Q257.625 36.7827 260.891 38.9649Q264.157 41.147 267.312 43.4868Q270.467 45.8266 273.503 48.3183Q276.539 50.8101 279.449 53.4478Q282.36 56.0855 285.137 58.8629Q287.914 61.6403 290.552 64.5506Q293.19 67.4609 295.682 70.4971Q298.173 73.5333 300.513 76.6881Q302.853 79.8429 305.035 83.1087Q307.217 86.3746 309.237 89.7435Q311.256 93.1125 313.107 96.5765Q314.959 100.041 316.638 103.591Q318.318 107.142 319.821 110.771Q321.324 114.399 322.647 118.098Q323.97 121.796 325.11 125.554Q326.251 129.313 327.205 133.123Q328.159 136.933 328.926 140.786Q329.692 144.638 330.268 148.523Q330.845 152.408 331.23 156.317Q331.615 160.226 331.807 164.149Q332 168.072 332 172Z AWA 28 °
I will try to add more tests (see #1414), it sounds like you're not able to pin down an exact font/text/path input that can make the component throw the error in a deterministic way?
Exactly, I need to leave the app working for at least 10-15min and it then it crashes, but it's never the same value or the same amount of time elapsed. I'm running it now with SF Pro as you suggested. Will let you know if it has the same behaviour or not. Thanks a lot!
it could be many input that cause the error but I'm wondering if we can capture an input that always causes the issue.
On Thu, Mar 9, 2023 at 1:53 PM Adrià M. Cassorla @.***> wrote:
Exactly, I need to leave the app working for at least 10-15min and it then it crashes, but it's never the same value or the same amount of time elapsed. I'm running it now with SF Pro as you suggested. Will let you know if it has the same behaviour or not. Thanks a lot!
— Reply to this email directly, view it on GitHub https://github.com/Shopify/react-native-skia/issues/1410#issuecomment-1462011599, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACKXVSZXLV7E55TEGS64ITW3HHDLANCNFSM6AAAAAAVUBWO6A . You are receiving this because you commented.Message ID: @.***>
Hi @wcandillon , Tested it for a few hours with TF Pro font, and there are no crashes. So, to reproduce the error you will need to use this font.
Thank you for sending the font. Unfortunately, updating the test with this font was not enough to reproduce the crash. I still believe that the issue is deterministic and that there is an exact triplet font/path/text that can enable us to reproduce the issue every single time and subsequently fix it. Do you think you could manage to capture that triplet?
The path is always a circle made using Skia.Path.Make().addCircle. The size is dynamic and it doesn't seem to have a relationship to the crashes.
Related to the text, I added a log in TextBlobProp.h (where the error is thrown) with the text that caused that error. The result was '29 °'. Next test was to hard code this value in my TextPath component, which didn't make the app crash. However, I noticed that there was another rendering issue. In the video, the only action I'm doing is cmd-S in my keyboard, so refreshing the component. Notice that the value is randomly rendered.
Please, let me know if I can log more things in TextBlobProp.h that can help to find the issue.
https://user-images.githubusercontent.com/105632810/224945691-246a215f-5917-4808-84d1-42bf85f3635c.mp4
The log should be on the JS side (the properties of TextPath). In the TextBlob, the TextPath computation that failed should be done already, so if you log in TextBlob I'm afraid you're missing the input that make our text path calculation crash.
I'm am still operating under the assumption that there is a deterministic input that make the Text Path calculation crash. This assumption might be wrong but we haven't ruled it out yet.
Is the text in the compass, an image? it doesn't seem to be affected by the refresh? Are these updating text path values a Skia animation value?
Is there any chance you could share with us (it can be done privately) a small repository that would help us reproduce the issue?
Hey @wcandillon , yes, I will prepare a small repo for you. But I'd need some time. I'll let you know when I have it. Thanks again for your help.
The compass (including its inner numbers) is an SVG image, but all the other numbers are Skia text
@orca-adria I would like to follow up on this and I was wondering if you could email me privately as well as I have some questions about this example.
Hey @wcandillon. Sorry for the late response. Can you write me an email at [email protected] ?? We can chat there. I hope I'll have some spare time to prepare an example project to replicate the crash in a couple of weeks, but happy to discuss it with you before that.
@orca-adria I added a test case at #1623. It's using the same path and font. Now we need an input to reproduce the issue. In the example you provided, the issue is indeed easy to reproduce but we need something that would happen without animated. An input that we know for sure our text path algorithm will fail on.
In the meantime, you can use the javascript implementation directly: https://github.com/Shopify/react-native-skia/blob/main/package/src/dom/nodes/drawings/Text.ts#L40 If you extract this function, you can create a text blob which you can draw using: https://shopify.github.io/react-native-skia/docs/text/blob
I would like to keep open the possibility that the crash may be related to the animation but right now it is way more likely that it is an issue in the C++ implementation of the text along path implementation that we took from the C++ code.
Just tested the JS approach and it works fine now.
I've been trying to find the input values that make the C++ implementation crash, but I've not find them yet. In fact, in the example I provided, there is a progress loop that changes the values, and it never crashes at the same place. Sometimes it makes a couple or more loops, and other times crashes immediately, so I'm not sure if the problem is the input... Will continue investigating that and keep you updated.
Thanks for your help!
this has been fixed offline I believe.
Hi @orca-adria I'm getting this issue as well with version 1.3.10 for both Android and iOS. Do you have any workaround?
Hi @r0b0t3d, the workaround was to use the TextBlob and the js implementation suggested by @wcandillon.
In my case it looks something like this (very simplified):
import {
Skia,
SkTextBlob,
TextBlob,
useFont,
} from '@shopify/react-native-skia';
export default () => {
const textFont = useFont(font, fontSize);
const path = Skia.Path.Make().addCircle(center.x, center.y, rad);
// We call processValueChange in different scenarios and it's a bit more complex,
// but the important part would be this:
const blobValue = useSharedValue<SkTextBlob | undefined>(undefined);
const processValueChange = (text: string) => {
'worklet';
const blob = makeTextPathBlob(text, path, textFont);
blobValue.value = blob;
};
// Among other groups and inside a canvas:
return (
<TextBlob
blob={blobValue as SharedValue<SkTextBlob>}
color={textColor}
/>
);
}
Then for the makeTextPathBlob you'd need this:
export const makeTextPathBlob = (
inputText = '',
path: SkPath,
font: SkFont | null,
initialOffset = 0,
) => {
'worklet';
if (!font) return undefined;
let text = inputText;
const ids = font.getGlyphIDs(text);
const widths = font.getGlyphWidths(ids);
const rsx: SkRSXform[] = [];
const meas = Skia.ContourMeasureIter(path, false, 1);
let cont = meas.next();
let dist = initialOffset;
for (let i = 0; i < text.length && cont; i++) {
const width = widths[i];
dist += width / 2;
if (dist > cont.length()) {
// jump to next contour
cont = meas.next();
if (!cont) {
// We have come to the end of the path - terminate the string
// right here.
text = text.substring(0, i);
break;
}
dist = width / 2;
}
// Gives us the (x, y) coordinates as well as the cos/sin of the tangent
// line at that position.
const [p, t] = cont.getPosTan(dist);
const adjustedX = p.x - (width / 2) * t.x;
const adjustedY = p.y - (width / 2) * t.y;
rsx.push(Skia.RSXform(t.x, t.y, adjustedX, adjustedY));
dist += width / 2;
}
return Skia.TextBlob.MakeFromRSXform(text, rsx, font);
};