Add settings for variable font axes in typography scheme
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
package de.mm20.launcher2.themes.typography
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.graphics.fonts.SystemFonts
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.core.graphics.TypefaceCompat
|
||||
|
||||
data class FontList(
|
||||
val builtIn: List<FontFamily>,
|
||||
@@ -14,6 +9,14 @@ data class FontList(
|
||||
val system: List<FontFamily>,
|
||||
)
|
||||
|
||||
data class VariableFontAxis(
|
||||
val name: String,
|
||||
val label: String,
|
||||
val range: ClosedFloatingPointRange<Float>,
|
||||
val step: Float,
|
||||
val defaultValue: Float,
|
||||
)
|
||||
|
||||
class FontManager(
|
||||
private val context: Context
|
||||
) {
|
||||
@@ -24,12 +27,12 @@ class FontManager(
|
||||
.getIdentifier("config_bodyFontFamily", "string", "android")
|
||||
|
||||
val deviceHeadlineExists = deviceHeadlineResId != 0 &&
|
||||
context.resources.getString(deviceHeadlineResId).isNotBlank()
|
||||
context.resources.getString(deviceHeadlineResId).isNotBlank()
|
||||
|
||||
val deviceBodyExists = deviceBodyResId != 0 &&
|
||||
context.resources.getString(deviceBodyResId).isNotBlank()
|
||||
context.resources.getString(deviceBodyResId).isNotBlank()
|
||||
return FontList(
|
||||
builtIn = listOf(FontFamily.LauncherDefault, FontFamily.LauncherDefaultRound),
|
||||
builtIn = listOf(FontFamily.LauncherDefault()),
|
||||
generic = listOf(
|
||||
FontFamily.SansSerif,
|
||||
FontFamily.Serif,
|
||||
@@ -42,4 +45,16 @@ class FontManager(
|
||||
system = emptyList(),
|
||||
)
|
||||
}
|
||||
|
||||
fun getFontSettings(font: FontFamily.VariableFontFamily): List<VariableFontAxis> {
|
||||
if (font is FontFamily.LauncherDefault) {
|
||||
return listOf(
|
||||
VariableFontAxis("wdth", "Width", 25f..151f, 1f, 100f),
|
||||
VariableFontAxis("ROND", "Roundness", 0f..100f, 1f, 0f),
|
||||
VariableFontAxis("GRAD", "Grade", 0f..100f, 1f, 0f),
|
||||
)
|
||||
}
|
||||
|
||||
return emptyList()
|
||||
}
|
||||
}
|
||||
@@ -181,13 +181,18 @@ data class TextStyle<out W : FontWeight?>(
|
||||
|
||||
@Serializable
|
||||
sealed interface FontFamily {
|
||||
@Serializable
|
||||
@SerialName("launcher_default")
|
||||
data object LauncherDefault : FontFamily
|
||||
|
||||
sealed interface VariableFontFamily {
|
||||
val settings: Map<String, Float>
|
||||
get() = emptyMap()
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@SerialName("launcher_default_round")
|
||||
data object LauncherDefaultRound : FontFamily
|
||||
@SerialName("launcher_default")
|
||||
data class LauncherDefault(
|
||||
override val settings: Map<String, Float> = emptyMap()
|
||||
) : FontFamily, VariableFontFamily
|
||||
|
||||
|
||||
@Serializable
|
||||
@SerialName("device_headline")
|
||||
|
||||
@@ -78,8 +78,8 @@ class TypographyRepository(
|
||||
builtIn = true,
|
||||
name = "Google Sans",
|
||||
fonts = mapOf(
|
||||
"brand" to FontFamily.LauncherDefault,
|
||||
"plain" to FontFamily.LauncherDefault,
|
||||
"brand" to FontFamily.LauncherDefault(),
|
||||
"plain" to FontFamily.LauncherDefault(),
|
||||
),
|
||||
styles = DefaultTextStyles,
|
||||
emphasizedStyles = DefaultEmphasizedTextStyles,
|
||||
@@ -91,8 +91,8 @@ class TypographyRepository(
|
||||
builtIn = true,
|
||||
name = "Google Sans (Rounded)",
|
||||
fonts = mapOf(
|
||||
"brand" to FontFamily.LauncherDefaultRound,
|
||||
"plain" to FontFamily.LauncherDefaultRound,
|
||||
"brand" to FontFamily.LauncherDefault(mapOf("ROND" to 100f)),
|
||||
"plain" to FontFamily.LauncherDefault(mapOf("ROND" to 100f)),
|
||||
),
|
||||
styles = DefaultTextStyles,
|
||||
emphasizedStyles = DefaultEmphasizedTextStyles,
|
||||
|
||||
Reference in New Issue
Block a user