Kirill Grouchnikov
02/08/2022, 1:49 PMTextStyle such as fontFamily, fontStyle, fontWeight, fontSize) to Skiko's Typeface or Font. Is there any public function or class that provides that bridge? There's some code in here for example that looks interesting, but it's all either internal or works with local font resources.Igor Demin
02/08/2022, 2:28 PMFontFamily to Skia Typeface. If you need to know how it is converted internally, you are looking at the right place (the code in there is not trivial though)Kirill Grouchnikov
02/08/2022, 2:33 PMCanvas doesn't have any APIs to draw text directly?Igor Demin
02/08/2022, 3:19 PMAny plans to make such a bridgeThere are no specific plans.
convert from ComposeThere is a way to convertto SkiaFontFamilyTypeface
Font to SkTypeface though:
val loader = LocalFontLoader.current
val typeface = remember { loader.load(Font("NotoSans-Italic.ttf")) }
Converting FontFamily is more difficult, because the are some `FontFamily`'s that are not converting to SkTypeface (GenericFontFamily, for example), they just passed as a String to SkiaParagraph.
draw text directly?You can draw Paragraph on Canvas:
val loader = LocalFontLoader.current
val density = LocalDensity.current
val par = remember {
Paragraph("text", TextStyle.Default, width = 200f, density = density, resourceLoader = loader)
}
Canvas(Modifier.fillMaxSize()) {
drawIntoCanvas {
par.paint(it, Color.Black)
}
}Kirill Grouchnikov
02/08/2022, 3:28 PMCanvas.drawTextOnPath. Eventually it goes down to Skia's Canvas.drawTextBlob where the blob is created by TextBlobBuilder configured with appendRunRSXform . Every glyph along the Path has its own RSXform to properly position and rotate it to follow the path's curvature. This is where I'd like to have the option to convert Compose's TextStyle to Skia's Font to pass it to TextBlobBuilder.appendRunRSXform, and even before that to call Font.getStringGlyphs and other similar methods. Using higher level APIs like Paragraph is not good here, as it doesn't provide the lower-level glyph-based metrics that are needed.Kirill Grouchnikov
02/08/2022, 3:29 PM