A question for <@U015TKX93PD>. I am trying to find...
# compose-desktop
k
A question for @Igor Demin. I am trying to find the right place in Skiko / Compose-JB that converts Compose's font definition (the relevant parts of
TextStyle
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.
i
There is no public API that allows to convert from Compose
FontFamily
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)
k
Ah, that's a bummer. Any plans to make such a bridge that may be needed since Compose's
Canvas
doesn't have any APIs to draw text directly?
i
Any plans to make such a bridge
There are no specific plans.
convert from Compose 
FontFamily
 to Skia 
Typeface
There is a way to convert
Font
to
SkTypeface
though:
Copy code
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:
Copy code
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)
    }
}
k
I'm working on the desktop equivalent of Android's
Canvas.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.
Here's how the target visuals look like: