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

Fix missing case for loading SystemFont on iOS #1013

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ package androidx.compose.ui.text.platform

import kotlin.native.Platform as NativePlatform
import org.jetbrains.skia.Typeface as SkTypeface
import org.jetbrains.skia.FontStyle as SkFontStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontStyle
import org.jetbrains.skia.Data
import org.jetbrains.skia.FontSlant
import org.jetbrains.skia.FontWidth

internal actual fun loadTypeface(font: Font): SkTypeface {
if (font !is PlatformFont) {
Expand All @@ -27,11 +31,19 @@ internal actual fun loadTypeface(font: Font): SkTypeface {
@Suppress("REDUNDANT_ELSE_IN_WHEN")
return when (font) {
is LoadedFont -> SkTypeface.makeFromData(Data.makeFromBytes(font.getData()))
is SystemFont -> SkTypeface.makeFromName(font.identity, font.skFontStyle)
// TODO: compilation fails without `else` see https://youtrack.jetbrains.com/issue/KT-43875
else -> throw IllegalArgumentException("Unsupported font type: $font")
}
}

private val Font.skFontStyle: SkFontStyle
get() = SkFontStyle(
weight = weight.weight,
width = FontWidth.NORMAL,
slant = if (style == FontStyle.Italic) FontSlant.ITALIC else FontSlant.UPRIGHT
)

internal actual fun currentPlatform(): Platform = when (NativePlatform.osFamily) {
OsFamily.MACOSX -> Platform.MacOS
OsFamily.IOS -> Platform.IOS
Expand Down