Skip to content
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

FontFamily.Monospace doesn't seem to work for Web? #293

Closed
Zomis opened this issue Jun 12, 2024 · 4 comments
Closed

FontFamily.Monospace doesn't seem to work for Web? #293

Zomis opened this issue Jun 12, 2024 · 4 comments

Comments

@Zomis
Copy link

Zomis commented Jun 12, 2024

It might be me who is doing something wrong, or it might be something with Compose and/or Wasm, but I can't get the monospace font to work when building for Web.

Add to Kotlin Multiplatform project (I used the https://kmp.jetbrains.com generator)

val state = rememberRichTextState()
LaunchedEffect(Unit) {
    state.addSpanStyle(SpanStyle(fontFamily = FontFamily.Monospace))
    state.setText("Hello World.,!?")
}
RichTextEditor(state, modifier = Modifier.fillMaxSize())

Run ./gradlew :composeApp:wasmJsBrowserDevelopmentRun

Expected result: Monospace font

Actual result: No monospace font

Any help on how to make Monospace font appear in browser appreciated.

On Desktop it works as expected.

@MohamedRejeb
Copy link
Owner

If you try a normal Text composable or a TextField with this font family, it works fine?

@Zomis
Copy link
Author

Zomis commented Aug 8, 2024

@MohamedRejeb Nope, it seems like Text("Hello world", fontFamily = FontFamily.Monospace) also does not work as expected. 😞

Any idea where I can report that issue, or how to make it work?

@Zomis
Copy link
Author

Zomis commented Aug 8, 2024

I added composeApp/src/commonMain/composeResources/font/Monospace.ttf (which I got from https://www.1001fonts.com/monospace-font.html) and did this:

var font: FontFamily? by remember {
    mutableStateOf(null)
}
LaunchedEffect(Unit) {
    font = FontFamily(
        Font(identity = "Monospace", data = Res.readBytes("font/Monospace.ttf"), weight = FontWeight.Normal),
    )
}

And then I could use the monospace font just fine.

Thanks.

@Zomis Zomis closed this as completed Aug 8, 2024
@MohamedRejeb
Copy link
Owner

Ok good,
you can improve this more by changing Res.readBytes with FontFamily(Font(Res.font.Monospace))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants