JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.28k stars 1.11k forks source link

Add support for variable fonts on iOS/desktop #3127

Open MikolajKakol opened 1 year ago

MikolajKakol commented 1 year ago

Currently, we cannot pass FontVariation arguments like we can on Android. We should be able to write code like this:

    Font( 
        R.font.roboto_slab, 
        weight = it, 
        variationSettings = FontVariation.Settings(FontVariation.weight(it.weight)) 
    ) 

Right now we cannot add those settings to modify custom axis. Like in https://speednet.pl/blog/fun-with-fonts2/

pjBooms commented 1 year ago

.. and the first part of the task is to provide common API for font loading from resources.

RageshAntony commented 1 year ago

@pjBooms

So we can't use Fonts like this, we using in Android, in compose mutliplatform ?

val nunitoLight = FontFamily(Font(R.font.nunito_light)
val nunitoRegular = FontFamily(Font(R.font.nunito_regular))
val nunitoMedium = FontFamily(Font(R.font.nunito_medium))
val nunitoBold = FontFamily(Font(R.font.nunito_bold))
MikolajKakol commented 1 year ago

It is possible to do it like that(almost, it's bit different resources API). The request is for variable fonts

RageshAntony commented 1 year ago

@MikolajKakol

The problem is, I put the font file in resources folder in commonMain, put couldn't access it like accessing in painterResource("res_file_name")

MikolajKakol commented 1 year ago

https://link.medium.com/AqBqFC0UDzb this is nice article about using fonts, I have almost identical implementation that worked for me

Skaldebane commented 9 months ago

Hi! Are there any plans to support this anytime soon?

The lack of this feature forces me to use static font files for Desktop/iOS, while using only one variable font file on Android. This makes some variable font weight/slant animations impossible to show anywhere other than Android.

I'd love to be able to use only the variable font files in the Shared module and define the variationAxis just as we do it in Android.

What would it take to implement this? I can take on the Desktop side at least and implement support for it there!

vdcast commented 4 months ago

Hi! Are there any plans to support this anytime soon?

The lack of this feature forces me to use static font files for Desktop/iOS, while using only one variable font file on Android. This makes some variable font weight/slant animations impossible to show anywhere other than Android.

I'd love to be able to use only the variable font files in the Shared module and define the variationAxis just as we do it in Android.

What would it take to implement this? I can take on the Desktop side at least and implement support for it there!

Hi there! Which approach do you use to setup custom fonts in Compose Multiplatform, especially IOS?