Hi everyone :wave: I'm looking for a multiplatform...
# compose
m
Hi everyone 👋 I'm looking for a multiplatform equivalent of Android's `Paint.getTextPath()`: Basically, I need to get a vector path from the outline of text. I looked in the
TextMeasurer
,
Paint
and
Canvas
APIs, but couldn't find anything. I thought about making an expect/actual implementation for iOS and Android (the platforms I care about at the moment), but I couldn't find anything in
NativePaint
or
NativeCanvas
that does what I want. Of course, there are Swift APIs that will give me this, but they use the iOS text rendering framework, so there are likely to be subtle differences between the platforms. Before I go down that route, I was just wondering if there was something obvious I was missing.
At a deeper level, there are two reasons what I want this: 1. Short-term: I'm doing off-screen rendering to an ImageBitmap in a non-UI thread, and a bug in how Compose caches SkTextStyle objects is causing concurrent modification exceptions (the WeakKeysCache that is used for the cache appears to not be threadsafe, so when the UI recomposes at the same time, it crashes...). I will file a bug report on this in YouTrack (Android is correctly threadsafe for this, but iOS is not...) 2. Long-term: I will eventually need to do paint-on animations of the stroke of the text. This isn't an immediate need, but eventually even if the bug I mentioned in #1 is solved, I'll still eventually end up needing a solution.
z
Please file a feature request
👍 1
d
@Matthew Feinberg did you find a workaround for this? I think I'm having a similar issue: https://youtrack.jetbrains.com/issue/CMP-8248/Crash-at-toSkTextStyle
m
Hi Daniel! Are you looking at this as a solution to the crash issue, or do you need the outlines for other reasons (like custom rendering or animation)? For the crash issue, I worked around it by just making all the text measurement calls on the UI thread (they are lightweight enough and we can call them in advance of when we actually need them so it doesn't cause performance issues). For the outline issue, our plan is to use native APIs to extract individual character outlines, and use the text measurement result to place those outlines so that there are no subtle differences for things like wrapping, etc. (long-term we may consider using FreeType directly to extract character outlines). Of course, we'll do do this in a modular way so that if this support is added in the future, we can swap it out for the official support in just one place. (All of that work will be part of our Opus video timeline composition library, which we plan to make open-source in the next few months)