diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeUtils.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeUtils.kt index 4d1bfdd2e..7f435506e 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeUtils.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/BridgeUtils.kt @@ -6,11 +6,11 @@ import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.graphics.TileMode +import androidx.compose.ui.text.ExperimentalTextApi import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.text.platform.Typeface +import androidx.compose.ui.text.platform.asComposeFontFamily import androidx.compose.ui.unit.Density import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.DpSize @@ -28,13 +28,8 @@ import com.intellij.util.ui.JBDimension import com.intellij.util.ui.JBFont import com.intellij.util.ui.JBInsets import com.intellij.util.ui.JBValue -import kotlinx.coroutines.runBlocking -import org.jetbrains.skia.Typeface import org.jetbrains.skiko.DependsOnJBR -import org.jetbrains.skiko.awt.font.AwtFontManager -import org.jetbrains.skiko.toSkikoTypefaceOrNull import java.awt.Dimension -import java.awt.Font import java.awt.Insets import javax.swing.UIManager @@ -158,17 +153,15 @@ public fun retrieveArcAsCornerSizeWithFallbacks(vararg keys: String): CornerSize keysNotFound(keys.toList(), "Int") } -@OptIn(DependsOnJBR::class) -private val awtFontManager = AwtFontManager() - @DependsOnJBR -public suspend fun retrieveTextStyle(fontKey: String, colorKey: String? = null): TextStyle { +public fun retrieveTextStyle(fontKey: String, colorKey: String? = null): TextStyle { val baseColor = colorKey?.let { retrieveColorOrUnspecified(colorKey) } ?: Color.Unspecified return retrieveTextStyle(fontKey, color = baseColor) } +@OptIn(ExperimentalTextApi::class) @DependsOnJBR -public suspend fun retrieveTextStyle( +public fun retrieveTextStyle( key: String, color: Color = Color.Unspecified, lineHeight: TextUnit = TextUnit.Unspecified, @@ -182,33 +175,17 @@ public suspend fun retrieveTextStyle( val derivedFont = jbFont.let { if (bold) it.asBold() else it.asPlain() } .let { if (fontStyle == FontStyle.Italic) it.asItalic() else it } - val typeface = derivedFont.toSkikoTypefaceOrNull(awtFontManager) - ?: Typeface.makeDefault().also { - logger.warn( - "Unable to convert font ${jbFont.fontName} into a Skiko typeface, " + - "fallback to 'Typeface.makeDefault()'", - ) - } - return TextStyle( color = color, fontSize = size.takeOrElse { derivedFont.size.sp / UISettingsUtils.getInstance().currentIdeScale }, fontWeight = if (bold) FontWeight.Bold else FontWeight.Normal, fontStyle = fontStyle, - fontFamily = FontFamily(Typeface(typeface)), - // todo textDecoration might be defined in the awt theme + fontFamily = derivedFont.asComposeFontFamily(), + // TODO textDecoration might be defined in the AWT theme lineHeight = lineHeight, ) } -@DependsOnJBR -public fun Font.toFontFamily(): FontFamily { - val typeface = runBlocking { toSkikoTypefaceOrNull(awtFontManager) } - ?: error("Can't turn $this into a Typeface") - - return FontFamily(Typeface(typeface)) -} - public val JBValue.dp: Dp get() = unscaled.dp diff --git a/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/releasessample/ReleasesSampleCompose.kt b/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/releasessample/ReleasesSampleCompose.kt index e6b40966e..ed5ce36e0 100644 --- a/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/releasessample/ReleasesSampleCompose.kt +++ b/samples/ide-plugin/src/main/kotlin/org/jetbrains/jewel/samples/ideplugin/releasessample/ReleasesSampleCompose.kt @@ -75,7 +75,6 @@ import kotlinx.datetime.toJavaLocalDate import org.jetbrains.jewel.bridge.retrieveColorOrUnspecified import org.jetbrains.jewel.bridge.retrieveTextStyle import org.jetbrains.jewel.bridge.toComposeColor -import org.jetbrains.jewel.bridge.toFontFamily import org.jetbrains.jewel.foundation.lazy.SelectableLazyColumn import org.jetbrains.jewel.foundation.lazy.SelectionMode import org.jetbrains.jewel.foundation.lazy.items @@ -559,8 +558,7 @@ private fun AndroidStudioReleaseDetails(item: ContentItem.AndroidStudio) { private fun TextWithLabel(labelText: String, valueText: String) { Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) { Text(labelText) - val fontFamily = JBFont.label().asBold().toFontFamily() - Text(valueText, fontFamily = fontFamily, fontWeight = FontWeight.W600) + Text(valueText, fontWeight = FontWeight.W600) } } diff --git a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt index 554d9f725..e911bb658 100644 --- a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt +++ b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt @@ -3,6 +3,9 @@ package org.jetbrains.jewel.samples.standalone import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.res.ResourceLoader import androidx.compose.ui.res.loadSvgPainter +import androidx.compose.ui.text.ExperimentalTextApi +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.unit.Density import androidx.compose.ui.window.application import org.jetbrains.jewel.foundation.theme.JewelTheme @@ -20,14 +23,18 @@ import org.jetbrains.jewel.window.DecoratedWindow import org.jetbrains.jewel.window.styling.TitleBarStyle import java.io.InputStream +@OptIn(ExperimentalTextApi::class) fun main() { val icon = svgResource("icons/jewel-logo.svg") + application { + val textStyle = TextStyle(fontFamily = FontFamily("Inter")) + val themeDefinition = if (MainViewModel.theme.isDark()) { - JewelTheme.darkThemeDefinition() + JewelTheme.darkThemeDefinition(defaultTextStyle = textStyle) } else { - JewelTheme.lightThemeDefinition() + JewelTheme.lightThemeDefinition(defaultTextStyle = textStyle) } IntUiTheme(