diff --git a/core/designsystem/src/androidMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/FontResource.kt b/core/designsystem/src/androidMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/FontResource.kt deleted file mode 100644 index a6d30d4eb..000000000 --- a/core/designsystem/src/androidMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/FontResource.kt +++ /dev/null @@ -1,48 +0,0 @@ -package io.github.droidkaigi.confsched.designsystem.theme - -import android.content.Context -import android.content.res.Resources.NotFoundException -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.text.font.FontFamily -import androidx.core.content.res.ResourcesCompat -import co.touchlab.kermit.Logger -import io.github.droidkaigi.confsched.core.designsystem.R -import io.github.droidkaigi.confsched.designsystem.theme.FontResource.Montserrat -import org.jetbrains.compose.resources.ExperimentalResourceApi - -val fontMap: HashMap = HashMap() - -// https://ishroid.medium.com/custom-font-loading-in-kmp-compose-multiplatform-2eb19865f61b -@ExperimentalResourceApi -@Composable -actual fun fontFamilyResource(fontResource: FontResource): FontFamily? { - val context: Context = LocalContext.current - - var fontFamily: FontFamily? by - remember(fontResource.resName) { mutableStateOf(fontMap[fontResource.resName]) } - if (fontFamily == null) { - LaunchedEffect(fontResource) { - fontFamily = try { - FontFamily( - ResourcesCompat.getFont( - context, - when (fontResource) { - Montserrat -> R.font.montserrat_medium - }, - )!!, - ) - } catch (e: Exception) { - Logger.e(e.message ?: "Please check if the font file specification is correct.") - throw NotFoundException() - } - fontMap[fontResource.resName] = fontFamily - } - } - return fontFamily -} diff --git a/core/designsystem/src/commonMain/composeResources/font/dot_gothic16_regular.ttf b/core/designsystem/src/commonMain/composeResources/font/dot_gothic16_regular.ttf new file mode 100644 index 000000000..18b0c1e73 Binary files /dev/null and b/core/designsystem/src/commonMain/composeResources/font/dot_gothic16_regular.ttf differ diff --git a/core/designsystem/src/commonMain/composeResources/values-ja/designsystem_strings.xml b/core/designsystem/src/commonMain/composeResources/values-ja/designsystem_strings.xml new file mode 100644 index 000000000..8f3723939 --- /dev/null +++ b/core/designsystem/src/commonMain/composeResources/values-ja/designsystem_strings.xml @@ -0,0 +1,4 @@ + + + !!Please remove this resource when you add string resource!! + diff --git a/core/designsystem/src/commonMain/composeResources/values/designsystem_strings.xml b/core/designsystem/src/commonMain/composeResources/values/designsystem_strings.xml new file mode 100644 index 000000000..8f3723939 --- /dev/null +++ b/core/designsystem/src/commonMain/composeResources/values/designsystem_strings.xml @@ -0,0 +1,4 @@ + + + !!Please remove this resource when you add string resource!! + diff --git a/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/DesignSystemRes.kt b/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/DesignSystemRes.kt new file mode 100644 index 000000000..1169c7ccd --- /dev/null +++ b/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/DesignSystemRes.kt @@ -0,0 +1,9 @@ +package io.github.droidkaigi.confsched.designsystem + +import conference_app_2024.core.designsystem.generated.resources.Res + +object DesignSystemRes { + val drawable = Res.drawable + val string = Res.string + val font = Res.font +} diff --git a/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/FontPreview.kt b/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/FontPreview.kt index 0e556bebf..94250f1a3 100644 --- a/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/FontPreview.kt +++ b/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/FontPreview.kt @@ -14,20 +14,20 @@ internal fun FontPreview() { Column( Modifier.background(color = Color.White), ) { - Text("Display Large", style = AppTypography.displayLarge) - Text("Display Medium", style = AppTypography.displayMedium) - Text("Display Small", style = AppTypography.displaySmall) - Text("Headline Large", style = AppTypography.headlineLarge) - Text("Headline Medium", style = AppTypography.headlineMedium) - Text("Headline Small", style = AppTypography.headlineSmall) - Text("Title Large", style = AppTypography.titleLarge) - Text("Title Medium", style = AppTypography.titleMedium) - Text("Title Small", style = AppTypography.titleSmall) - Text("Label Large", style = AppTypography.labelLarge) - Text("Label Medium", style = AppTypography.labelMedium) - Text("Label Small", style = AppTypography.labelSmall) - Text("Body Large", style = AppTypography.bodyLarge) - Text("Body Medium", style = AppTypography.bodyMedium) - Text("Body Small", style = AppTypography.bodySmall) + Text("Display Large", style = appTypography().displayLarge) + Text("Display Medium", style = appTypography().displayMedium) + Text("Display Small", style = appTypography().displaySmall) + Text("Headline Large", style = appTypography().headlineLarge) + Text("Headline Medium", style = appTypography().headlineMedium) + Text("Headline Small", style = appTypography().headlineSmall) + Text("Title Large", style = appTypography().titleLarge) + Text("Title Medium", style = appTypography().titleMedium) + Text("Title Small", style = appTypography().titleSmall) + Text("Label Large", style = appTypography().labelLarge) + Text("Label Medium", style = appTypography().labelMedium) + Text("Label Small", style = appTypography().labelSmall) + Text("Body Large", style = appTypography().bodyLarge) + Text("Body Medium", style = appTypography().bodyMedium) + Text("Body Small", style = appTypography().bodySmall) } } diff --git a/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/FontResource.kt b/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/FontResource.kt deleted file mode 100644 index 098b5c07d..000000000 --- a/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/FontResource.kt +++ /dev/null @@ -1,14 +0,0 @@ -package io.github.droidkaigi.confsched.designsystem.theme - -import androidx.compose.runtime.Composable -import androidx.compose.ui.text.font.FontFamily -import org.jetbrains.compose.resources.ExperimentalResourceApi - -enum class FontResource(val resName: String) { - Montserrat("montserrat_medium.ttf"), -} - -// https://ishroid.medium.com/custom-font-loading-in-kmp-compose-multiplatform-2eb19865f61b -@ExperimentalResourceApi -@Composable -public expect fun fontFamilyResource(fontResource: FontResource): FontFamily? diff --git a/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/Theme.kt b/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/Theme.kt index 52abbd8d6..f035ad5fd 100644 --- a/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/Theme.kt +++ b/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/Theme.kt @@ -252,7 +252,7 @@ fun KaigiTheme( MaterialTheme( colorScheme = colorScheme, - typography = AppTypography, + typography = appTypography(), content = content, ) } diff --git a/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/Type.kt b/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/Type.kt index 912ba0ff9..5bbd49223 100644 --- a/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/Type.kt +++ b/core/designsystem/src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/Type.kt @@ -1,5 +1,114 @@ package io.github.droidkaigi.confsched.designsystem.theme import androidx.compose.material3.Typography +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp +import conference_app_2024.core.designsystem.generated.resources.dot_gothic16_regular +import io.github.droidkaigi.confsched.designsystem.DesignSystemRes +import org.jetbrains.compose.resources.Font -val AppTypography = Typography() +@Composable +fun appTypography(): Typography { + val dotGothic16 = FontFamily( + Font(DesignSystemRes.font.dot_gothic16_regular), + ) + return remember(dotGothic16) { + Typography( + displayLarge = TextStyle( + fontFamily = dotGothic16, + fontSize = 57.sp, + lineHeight = 64.sp, + letterSpacing = (-0.25).sp, + ), + displayMedium = TextStyle( + fontFamily = dotGothic16, + fontSize = 45.sp, + lineHeight = 52.sp, + letterSpacing = 0.sp, + ), + displaySmall = TextStyle( + fontFamily = dotGothic16, + fontSize = 36.sp, + lineHeight = 44.sp, + letterSpacing = 0.sp, + ), + headlineLarge = TextStyle( + fontFamily = dotGothic16, + fontSize = 32.sp, + lineHeight = 40.sp, + letterSpacing = 0.sp, + ), + headlineMedium = TextStyle( + fontFamily = dotGothic16, + fontSize = 28.sp, + lineHeight = 36.sp, + letterSpacing = 0.sp, + ), + headlineSmall = TextStyle( + fontFamily = dotGothic16, + fontSize = 24.sp, + lineHeight = 32.sp, + letterSpacing = 0.sp, + ), + titleLarge = TextStyle( + fontFamily = dotGothic16, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp, + ), + titleMedium = TextStyle( + fontFamily = dotGothic16, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.15.sp, + ), + titleSmall = TextStyle( + fontFamily = dotGothic16, + fontSize = 14.sp, + lineHeight = 20.sp, + letterSpacing = 0.1.sp, + ), + labelLarge = TextStyle( + fontFamily = dotGothic16, + fontWeight = FontWeight.Medium, + fontSize = 14.sp, + lineHeight = 20.sp, + letterSpacing = 0.1.sp, + ), + labelMedium = TextStyle( + fontFamily = dotGothic16, + fontWeight = FontWeight.Medium, + fontSize = 12.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp, + ), + labelSmall = TextStyle( + fontFamily = dotGothic16, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp, + ), + bodyLarge = TextStyle( + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp, + ), + bodyMedium = TextStyle( + fontSize = 14.sp, + lineHeight = 20.sp, + letterSpacing = 0.25.sp, + ), + bodySmall = TextStyle( + fontSize = 12.sp, + lineHeight = 16.sp, + letterSpacing = 0.4.sp, + ), + + ) + } +} diff --git a/core/designsystem/src/commonMain/resources/font/montserrat_medium.ttf b/core/designsystem/src/commonMain/resources/font/montserrat_medium.ttf deleted file mode 100644 index dfc7e2fc5..000000000 Binary files a/core/designsystem/src/commonMain/resources/font/montserrat_medium.ttf and /dev/null differ diff --git a/core/designsystem/src/iosMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/FontResource.kt b/core/designsystem/src/iosMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/FontResource.kt deleted file mode 100644 index 5253a4b95..000000000 --- a/core/designsystem/src/iosMain/kotlin/io/github/droidkaigi/confsched/designsystem/theme/FontResource.kt +++ /dev/null @@ -1,33 +0,0 @@ -package io.github.droidkaigi.confsched.designsystem.theme - -import androidx.compose.runtime.Composable -import androidx.compose.ui.text.font.FontFamily - -val fontMap: HashMap = HashMap() - -// https://ishroid.medium.com/custom-font-loading-in-kmp-compose-multiplatform-2eb19865f61b -// FIXME We initially planned to use this implementation on the iOS side. -// However, when shared.swift is output by XCFramework, methods with Compose annotations are not output. -// Therefore, this implementation cannot be referenced from the iOS side. -@Composable -actual fun fontFamilyResource(fontResource: FontResource): FontFamily? { - // FIXME: Load the custom font in resources directory - return FontFamily.Default -// var fontFamily: FontFamily? by -// remember(fontResource.resName) { mutableStateOf(fontMap[fontResource.resName]) } -// if (fontFamily == null) { -// LaunchedEffect(fontResource.resName) { -// fontFamily = try { -// val font = Font( -// fontResource.resName, -// resource("font/${fontResource.resName}").readBytes(), -// ) -// fontMap[fontResource.resName] = FontFamily(font) -// fontMap[fontResource.resName] -// } catch (e: Exception) { -// throw IllegalArgumentException(e) -// } -// } -// } -// return fontFamily -}