New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More options for drawing stroked text and paths #137064
Comments
The last few paragraphs focus on the specific use case of painting text with an outline and a fill. We could implement that directly in It would be good to have a concrete use case to drive this. |
Hey all! This was spurred by a request of mine so I can provide at least one good use case: Text overlays on maps. It's important for accessibility that text be legible against all kind of different backgrounds on vector or satellite based maps. Google maps has a stroke around points of interest names for that exact purpose. In general, it's a valuable tool in a designer's pocket for aesthetic or functional purposes. A
|
This issue is a bit vague about specifically what it is about. We should probably close this in favour of more specific use cases. It could be:
...or any number of other things, or maybe several of these. |
Design programs support a number of options for configuring stroke on text and paths. For example, Adobe Illustrator defaults stroked text to "outside".
(Generalizing this a bit, "Inside" to "outside" could be represented as floats between -1.0 and 1.0 with 0.0 mapping to "center".)
Skia does not support this concept natively for text or paths. The concept exists in the SVG standard, however Chrome (and
package:flutter_svg
which attempts to emulate Chrome) can have undesirable behavior depending on the specific paths that appear in the font:To accomplish this today in Flutter, there are a couple of options. First you can use a
Stack
of twoText
widgets. The top one gets the text fill color. The one behind gets a stroke and you set the one behind to be twice the size of the stroke you need (so that ½ of it is revealed from the edges of the top-fill-colored text). This is problematic because there are twoText
widgets when there technically should only be one, for example you'd need to use anExcludeSemantics
widget to wrap one of theText
widgets, and potentially other pitfalls.Alternatively, you could get down to the render objects and write the code to do this stacked painting without separate widgets. However, then one would need to reimplement all the rest of the functionality of the
Text
widget, which is a heavy burden.There are strategies for implementing this natively in Impeller (and possibly also as a feature request for the Skia team). However, for consistency across platforms, implementing this using the render object approach in the framework as part of the existing
Text
widget seems like it would be the most convenient. Later, if needed for performance for example, we could then explore adding features to Impeller and/or Skia to implement this. Tagging this as 'team-framework'.The text was updated successfully, but these errors were encountered: