1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.settingslib.spa.framework.theme
18
19 import androidx.compose.material3.Typography
20 import androidx.compose.runtime.Composable
21 import androidx.compose.runtime.remember
22 import androidx.compose.ui.text.TextStyle
23 import androidx.compose.ui.text.font.FontWeight
24 import androidx.compose.ui.text.style.Hyphens
25 import androidx.compose.ui.unit.em
26 import androidx.compose.ui.unit.sp
27
28 private class SettingsTypography(settingsFontFamily: SettingsFontFamily) {
29 private val brand = settingsFontFamily.brand
30 private val plain = settingsFontFamily.plain
31
32 val typography = Typography(
33 displayLarge = TextStyle(
34 fontFamily = brand,
35 fontWeight = FontWeight.Normal,
36 fontSize = 57.sp,
37 lineHeight = 64.sp,
38 letterSpacing = (-0.2).sp,
39 hyphens = Hyphens.Auto,
40 ),
41 displayMedium = TextStyle(
42 fontFamily = brand,
43 fontWeight = FontWeight.Normal,
44 fontSize = 45.sp,
45 lineHeight = 52.sp,
46 letterSpacing = 0.0.sp,
47 hyphens = Hyphens.Auto,
48 ),
49 displaySmall = TextStyle(
50 fontFamily = brand,
51 fontWeight = FontWeight.Normal,
52 fontSize = 36.sp,
53 lineHeight = 44.sp,
54 letterSpacing = 0.0.sp,
55 hyphens = Hyphens.Auto,
56 ),
57 headlineLarge = TextStyle(
58 fontFamily = brand,
59 fontWeight = FontWeight.Normal,
60 fontSize = 32.sp,
61 lineHeight = 40.sp,
62 letterSpacing = 0.0.sp,
63 hyphens = Hyphens.Auto,
64 ),
65 headlineMedium = TextStyle(
66 fontFamily = brand,
67 fontWeight = FontWeight.Normal,
68 fontSize = 28.sp,
69 lineHeight = 36.sp,
70 letterSpacing = 0.0.sp,
71 hyphens = Hyphens.Auto,
72 ),
73 headlineSmall = TextStyle(
74 fontFamily = brand,
75 fontWeight = FontWeight.Normal,
76 fontSize = 24.sp,
77 lineHeight = 32.sp,
78 letterSpacing = 0.0.sp,
79 hyphens = Hyphens.Auto,
80 ),
81 titleLarge = TextStyle(
82 fontFamily = brand,
83 fontWeight = FontWeight.Normal,
84 fontSize = 22.sp,
85 lineHeight = 28.sp,
86 letterSpacing = 0.02.em,
87 hyphens = Hyphens.Auto,
88 ),
89 titleMedium = TextStyle(
90 fontFamily = brand,
91 fontWeight = FontWeight.Normal,
92 fontSize = 20.sp,
93 lineHeight = 24.sp,
94 letterSpacing = 0.02.em,
95 hyphens = Hyphens.Auto,
96 ),
97 titleSmall = TextStyle(
98 fontFamily = brand,
99 fontWeight = FontWeight.Normal,
100 fontSize = 18.sp,
101 lineHeight = 20.sp,
102 letterSpacing = 0.02.em,
103 hyphens = Hyphens.Auto,
104 ),
105 bodyLarge = TextStyle(
106 fontFamily = plain,
107 fontWeight = FontWeight.Normal,
108 fontSize = 16.sp,
109 lineHeight = 24.sp,
110 letterSpacing = 0.01.em,
111 hyphens = Hyphens.Auto,
112 ),
113 bodyMedium = TextStyle(
114 fontFamily = plain,
115 fontWeight = FontWeight.Normal,
116 fontSize = 14.sp,
117 lineHeight = 20.sp,
118 letterSpacing = 0.01.em,
119 hyphens = Hyphens.Auto,
120 ),
121 bodySmall = TextStyle(
122 fontFamily = plain,
123 fontWeight = FontWeight.Normal,
124 fontSize = 12.sp,
125 lineHeight = 16.sp,
126 letterSpacing = 0.01.em,
127 hyphens = Hyphens.Auto,
128 ),
129 labelLarge = TextStyle(
130 fontFamily = plain,
131 fontWeight = FontWeight.Medium,
132 fontSize = 16.sp,
133 lineHeight = 24.sp,
134 letterSpacing = 0.01.em,
135 hyphens = Hyphens.Auto,
136 ),
137 labelMedium = TextStyle(
138 fontFamily = plain,
139 fontWeight = FontWeight.Medium,
140 fontSize = 14.sp,
141 lineHeight = 20.sp,
142 letterSpacing = 0.01.em,
143 hyphens = Hyphens.Auto,
144 ),
145 labelSmall = TextStyle(
146 fontFamily = plain,
147 fontWeight = FontWeight.Medium,
148 fontSize = 12.sp,
149 lineHeight = 16.sp,
150 letterSpacing = 0.01.em,
151 hyphens = Hyphens.Auto,
152 ),
153 )
154 }
155
156 @Composable
rememberSettingsTypographynull157 internal fun rememberSettingsTypography(): Typography {
158 val settingsFontFamily = rememberSettingsFontFamily()
159 return remember { SettingsTypography(settingsFontFamily).typography }
160 }
161
162 /** Creates a new [TextStyle] which font weight set to medium. */
toMediumWeightnull163 internal fun TextStyle.toMediumWeight() =
164 copy(fontWeight = FontWeight.Medium, letterSpacing = 0.01.em)
165