101 lines
3.7 KiB
Kotlin
101 lines
3.7 KiB
Kotlin
/*
|
|
*
|
|
* * Copyright © 2022-2024 by Navi Technologies Limited
|
|
* * All rights reserved. Strictly confidential
|
|
*
|
|
*/
|
|
|
|
package com.navi.design.theme
|
|
|
|
import androidx.compose.ui.text.font.Font
|
|
import androidx.compose.ui.text.font.FontFamily
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
import com.navi.design.font.FontWeightEnum
|
|
import com.navi.design.utils.Constants.TT_FONT_FAMILY
|
|
import com.navi.design.utils.getFontStyle
|
|
|
|
val composeFontFamily =
|
|
FontFamily(
|
|
Font(getFontStyle(FontWeightEnum.REGULAR), FontWeight.Normal),
|
|
Font(getFontStyle(FontWeightEnum.SEMI_BOLD), FontWeight.SemiBold),
|
|
Font(getFontStyle(FontWeightEnum.BOLD), FontWeight.Bold),
|
|
Font(getFontStyle(FontWeightEnum.EXTRA_BOLD), FontWeight.ExtraBold),
|
|
Font(getFontStyle(FontWeightEnum.ROBOTO_REGULAR), FontWeight.Normal),
|
|
Font(getFontStyle(FontWeightEnum.ROBOTO_MEDIUM), FontWeight.Medium),
|
|
Font(getFontStyle(FontWeightEnum.ROBOTO_BOLD), FontWeight.Bold),
|
|
)
|
|
|
|
val ttComposeFontFamily =
|
|
FontFamily(
|
|
Font(getFontStyle(FontWeightEnum.TT_MEDIUM), FontWeight.Medium),
|
|
Font(getFontStyle(FontWeightEnum.TT_BOLD), FontWeight.Bold),
|
|
Font(getFontStyle(FontWeightEnum.TT_SEMI_BOLD), FontWeight.SemiBold),
|
|
Font(getFontStyle(FontWeightEnum.TT_REGULAR), FontWeight.Normal)
|
|
)
|
|
|
|
fun getFontWeight(fontWeight: FontWeightEnum): FontWeight {
|
|
return when (fontWeight) {
|
|
FontWeightEnum.ROBOTO_REGULAR,
|
|
FontWeightEnum.REGULAR,
|
|
FontWeightEnum.TT_REGULAR,
|
|
FontWeightEnum.NAVI_BODY_REGULAR -> FontWeight.Normal
|
|
FontWeightEnum.SEMI_BOLD,
|
|
FontWeightEnum.TT_SEMI_BOLD,
|
|
FontWeightEnum.NAVI_BODY_DEMI_BOLD -> FontWeight.SemiBold
|
|
FontWeightEnum.ROBOTO_MEDIUM,
|
|
FontWeightEnum.TT_MEDIUM,
|
|
FontWeightEnum.NAVI_HEADLINE_REGULAR -> FontWeight.Medium
|
|
FontWeightEnum.ROBOTO_BOLD,
|
|
FontWeightEnum.TT_BOLD,
|
|
FontWeightEnum.BOLD,
|
|
FontWeightEnum.NAVI_HEADLINE_BOLD -> FontWeight.Bold
|
|
FontWeightEnum.EXTRA_BOLD -> FontWeight.ExtraBold
|
|
else -> FontWeight.Normal
|
|
}
|
|
}
|
|
|
|
fun getFontFamily(fontFamily: String?): FontFamily {
|
|
return when (fontFamily) {
|
|
TT_FONT_FAMILY -> ttComposeFontFamily
|
|
else -> composeFontFamily
|
|
}
|
|
}
|
|
|
|
fun getFontWeight(fontWeight: String?): FontWeight {
|
|
return when (fontWeight) {
|
|
FontWeightEnum.TT_REGULAR.name,
|
|
FontWeightEnum.ROBOTO_REGULAR.name,
|
|
FontWeightEnum.REGULAR.name,
|
|
FontWeightEnum.NAVI_REGULAR.name -> FontWeight.Normal
|
|
FontWeightEnum.TT_SEMI_BOLD.name,
|
|
FontWeightEnum.SEMI_BOLD.name,
|
|
FontWeightEnum.NAVI_EXTRA_BOLD.name -> FontWeight.SemiBold
|
|
FontWeightEnum.ROBOTO_MEDIUM.name,
|
|
FontWeightEnum.TT_MEDIUM.name,
|
|
FontWeightEnum.NAVI_BOLD.name -> FontWeight.Medium
|
|
FontWeightEnum.ROBOTO_BOLD.name,
|
|
FontWeightEnum.TT_BOLD.name,
|
|
FontWeightEnum.BOLD.name -> FontWeight.Bold
|
|
FontWeightEnum.EXTRA_BOLD.name -> FontWeight.ExtraBold
|
|
else -> FontWeight.Normal
|
|
}
|
|
}
|
|
|
|
fun FontWeight?.toEnum(fontFamily: FontFamily?) =
|
|
if (fontFamily == ttComposeFontFamily) {
|
|
when (this) {
|
|
FontWeight.Medium -> FontWeightEnum.TT_MEDIUM
|
|
FontWeight.Bold -> FontWeightEnum.TT_BOLD
|
|
else -> FontWeightEnum.TT_MEDIUM
|
|
}
|
|
} else {
|
|
when (this) {
|
|
FontWeight.Normal -> FontWeightEnum.ROBOTO_REGULAR
|
|
FontWeight.Medium -> FontWeightEnum.ROBOTO_MEDIUM
|
|
FontWeight.Bold -> FontWeightEnum.ROBOTO_BOLD
|
|
else -> FontWeightEnum.ROBOTO_REGULAR
|
|
}
|
|
}
|
|
|
|
fun FontWeight?.getFont(fontFamily: FontFamily?) = getFontStyle(this.toEnum(fontFamily))
|