0

I have to make a text appear on a custom path, like a curve, and I am using native canvas for that.

Something like

Canvas{
 drawIntoCanvas{
  it.nativeCanvas.drawTextOnPath(
   "Text Goes Here",
   textPath,
   0f,
   0f,
   Paint().apply{
    //Here, I can specify the text size, but don't know how to specify the family

    //PS: it offers a typeface to modify, but it is messed up with the legacy APIs
   }
  )
 }
}

The issue is that the nativeCanvas uses android.graphics.Paint, and so everything inside it is also the legacy android stuff. How do I access the font in Compose, given that I have it located as a .tff file in my res/fonts.

Thanks!

Richard Onslow Roper
  • 5,477
  • 2
  • 11
  • 42
  • 1
    You can only apply the legacy modification to `android.graphics.Paint`. If you are asking how to convert `FontFamily` to a typeface, that is what you should ask, in this case canvas has nothing to do with the question. – Phil Dukhov Sep 08 '21 at 14:58
  • If you only need to apply font from your resources, you should look for non compose solution, like [this one](https://stackoverflow.com/a/56660510/3585796) – Phil Dukhov Sep 08 '21 at 15:23
  • About that, I am storing my font in the res/fonts folder, but the font itself is a `.tff` as mentioned in the question. It is not accessible from the `R.font.` programmatically. Also, you suggested asking a separate question about converting FontFamily to Typeface, right? There are four combinations in this case. Each of these has its own legacy as well as Compose version. – Richard Onslow Roper Sep 08 '21 at 17:31
  • PS: The first part is solved now! I had used capital letters in the name that's why it was not accessible. – Richard Onslow Roper Sep 08 '21 at 17:36
  • I didn't mean that you need to create a separate question, I don't understand what you're asking here, if it's font family conversion to typeface, you should edit this question to this topic. – Phil Dukhov Sep 08 '21 at 17:53

0 Answers0