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.ExperimentalMaterial3ExpressiveApi
20 import androidx.compose.material3.Typography
21 import androidx.compose.runtime.Composable
22 import androidx.compose.runtime.remember
23 import androidx.compose.ui.text.TextStyle
24 import androidx.compose.ui.text.font.FontWeight
25 import androidx.compose.ui.text.style.Hyphens
26 import androidx.compose.ui.unit.em
27 import androidx.compose.ui.unit.sp
28
29 private class SettingsTypography(settingsFontFamily: SettingsFontFamily) {
30 private val brand = settingsFontFamily.brand
31 private val plain = settingsFontFamily.plain
32
33 val typography =
34 Typography(
35 displayLarge =
36 TextStyle(
37 fontFamily = brand,
38 fontWeight = FontWeight.Normal,
39 fontSize = 57.sp,
40 lineHeight = 64.sp,
41 letterSpacing = (-0.2).sp,
42 hyphens = Hyphens.Auto,
43 ),
44 displayMedium =
45 TextStyle(
46 fontFamily = brand,
47 fontWeight = FontWeight.Normal,
48 fontSize = 45.sp,
49 lineHeight = 52.sp,
50 letterSpacing = 0.0.sp,
51 hyphens = Hyphens.Auto,
52 ),
53 displaySmall =
54 TextStyle(
55 fontFamily = brand,
56 fontWeight = FontWeight.Normal,
57 fontSize = 36.sp,
58 lineHeight = 44.sp,
59 letterSpacing = 0.0.sp,
60 hyphens = Hyphens.Auto,
61 ),
62 headlineLarge =
63 TextStyle(
64 fontFamily = brand,
65 fontWeight = FontWeight.Normal,
66 fontSize = 32.sp,
67 lineHeight = 40.sp,
68 letterSpacing = 0.0.sp,
69 hyphens = Hyphens.Auto,
70 ),
71 headlineMedium =
72 TextStyle(
73 fontFamily = brand,
74 fontWeight = FontWeight.Normal,
75 fontSize = 28.sp,
76 lineHeight = 36.sp,
77 letterSpacing = 0.0.sp,
78 hyphens = Hyphens.Auto,
79 ),
80 headlineSmall =
81 TextStyle(
82 fontFamily = brand,
83 fontWeight = FontWeight.Normal,
84 fontSize = 24.sp,
85 lineHeight = 32.sp,
86 letterSpacing = 0.0.sp,
87 hyphens = Hyphens.Auto,
88 ),
89 titleLarge =
90 TextStyle(
91 fontFamily = brand,
92 fontWeight = FontWeight.Normal,
93 fontSize = 22.sp,
94 lineHeight = 28.sp,
95 letterSpacing = 0.02.em,
96 hyphens = Hyphens.Auto,
97 ),
98 titleMedium =
99 TextStyle(
100 fontFamily = brand,
101 fontWeight = FontWeight.Normal,
102 fontSize = 20.sp,
103 lineHeight = 24.sp,
104 letterSpacing = 0.02.em,
105 hyphens = Hyphens.Auto,
106 ),
107 titleSmall =
108 TextStyle(
109 fontFamily = brand,
110 fontWeight = FontWeight.Normal,
111 fontSize = 18.sp,
112 lineHeight = 20.sp,
113 letterSpacing = 0.02.em,
114 hyphens = Hyphens.Auto,
115 ),
116 bodyLarge =
117 TextStyle(
118 fontFamily = plain,
119 fontWeight = FontWeight.Normal,
120 fontSize = 16.sp,
121 lineHeight = 24.sp,
122 letterSpacing = 0.01.em,
123 hyphens = Hyphens.Auto,
124 ),
125 bodyMedium =
126 TextStyle(
127 fontFamily = plain,
128 fontWeight = FontWeight.Normal,
129 fontSize = 14.sp,
130 lineHeight = 20.sp,
131 letterSpacing = 0.01.em,
132 hyphens = Hyphens.Auto,
133 ),
134 bodySmall =
135 TextStyle(
136 fontFamily = plain,
137 fontWeight = FontWeight.Normal,
138 fontSize = 12.sp,
139 lineHeight = 16.sp,
140 letterSpacing = 0.01.em,
141 hyphens = Hyphens.Auto,
142 ),
143 labelLarge =
144 TextStyle(
145 fontFamily = plain,
146 fontWeight = FontWeight.Medium,
147 fontSize = 16.sp,
148 lineHeight = 24.sp,
149 letterSpacing = 0.01.em,
150 hyphens = Hyphens.Auto,
151 ),
152 labelMedium =
153 TextStyle(
154 fontFamily = plain,
155 fontWeight = FontWeight.Medium,
156 fontSize = 14.sp,
157 lineHeight = 20.sp,
158 letterSpacing = 0.01.em,
159 hyphens = Hyphens.Auto,
160 ),
161 labelSmall =
162 TextStyle(
163 fontFamily = plain,
164 fontWeight = FontWeight.Medium,
165 fontSize = 12.sp,
166 lineHeight = 16.sp,
167 letterSpacing = 0.01.em,
168 hyphens = Hyphens.Auto,
169 ),
170 )
171
172 @OptIn(ExperimentalMaterial3ExpressiveApi::class)
173 val expressiveTypography =
174 Typography(
175 displayLarge =
176 TextStyle(
177 fontFamily = brand,
178 fontWeight = FontWeight.Normal,
179 fontSize = 57.sp,
180 lineHeight = 64.sp,
181 letterSpacing = (-0.2).sp,
182 hyphens = Hyphens.Auto,
183 ),
184 displayLargeEmphasized =
185 TextStyle(
186 fontFamily = brand,
187 fontWeight = FontWeight.Medium,
188 fontSize = 57.sp,
189 lineHeight = 64.sp,
190 letterSpacing = (-0.2).sp,
191 hyphens = Hyphens.Auto,
192 ),
193 displayMedium =
194 TextStyle(
195 fontFamily = brand,
196 fontWeight = FontWeight.Normal,
197 fontSize = 45.sp,
198 lineHeight = 52.sp,
199 letterSpacing = 0.0.sp,
200 hyphens = Hyphens.Auto,
201 ),
202 displayMediumEmphasized =
203 TextStyle(
204 fontFamily = brand,
205 fontWeight = FontWeight.Medium,
206 fontSize = 45.sp,
207 lineHeight = 52.sp,
208 letterSpacing = 0.0.sp,
209 hyphens = Hyphens.Auto,
210 ),
211 displaySmall =
212 TextStyle(
213 fontFamily = brand,
214 fontWeight = FontWeight.Normal,
215 fontSize = 36.sp,
216 lineHeight = 44.sp,
217 letterSpacing = 0.0.sp,
218 hyphens = Hyphens.Auto,
219 ),
220 displaySmallEmphasized =
221 TextStyle(
222 fontFamily = brand,
223 fontWeight = FontWeight.Medium,
224 fontSize = 36.sp,
225 lineHeight = 44.sp,
226 letterSpacing = 0.0.sp,
227 hyphens = Hyphens.Auto,
228 ),
229 headlineLarge =
230 TextStyle(
231 fontFamily = brand,
232 fontWeight = FontWeight.Normal,
233 fontSize = 32.sp,
234 lineHeight = 40.sp,
235 letterSpacing = 0.0.sp,
236 hyphens = Hyphens.Auto,
237 ),
238 headlineLargeEmphasized =
239 TextStyle(
240 fontFamily = brand,
241 fontWeight = FontWeight.Medium,
242 fontSize = 32.sp,
243 lineHeight = 40.sp,
244 letterSpacing = 0.0.sp,
245 hyphens = Hyphens.Auto,
246 ),
247 headlineMedium =
248 TextStyle(
249 fontFamily = brand,
250 fontWeight = FontWeight.Normal,
251 fontSize = 28.sp,
252 lineHeight = 36.sp,
253 letterSpacing = 0.0.sp,
254 hyphens = Hyphens.Auto,
255 ),
256 headlineMediumEmphasized =
257 TextStyle(
258 fontFamily = brand,
259 fontWeight = FontWeight.Medium,
260 fontSize = 28.sp,
261 lineHeight = 36.sp,
262 letterSpacing = 0.0.sp,
263 hyphens = Hyphens.Auto,
264 ),
265 headlineSmall =
266 TextStyle(
267 fontFamily = brand,
268 fontWeight = FontWeight.Normal,
269 fontSize = 24.sp,
270 lineHeight = 32.sp,
271 letterSpacing = 0.0.sp,
272 hyphens = Hyphens.Auto,
273 ),
274 headlineSmallEmphasized =
275 TextStyle(
276 fontFamily = brand,
277 fontWeight = FontWeight.Medium,
278 fontSize = 24.sp,
279 lineHeight = 32.sp,
280 letterSpacing = 0.0.sp,
281 hyphens = Hyphens.Auto,
282 ),
283 titleLarge =
284 TextStyle(
285 fontFamily = brand,
286 fontWeight = FontWeight.Normal,
287 fontSize = 22.sp,
288 lineHeight = 28.sp,
289 letterSpacing = 0.02.em,
290 hyphens = Hyphens.Auto,
291 ),
292 titleLargeEmphasized =
293 TextStyle(
294 fontFamily = brand,
295 fontWeight = FontWeight.Medium,
296 fontSize = 22.sp,
297 lineHeight = 28.sp,
298 letterSpacing = 0.02.em,
299 hyphens = Hyphens.Auto,
300 ),
301 titleMedium =
302 TextStyle(
303 fontFamily = brand,
304 fontWeight = FontWeight.Medium,
305 fontSize = 16.sp,
306 lineHeight = 24.sp,
307 letterSpacing = 0.02.em,
308 hyphens = Hyphens.Auto,
309 ),
310 titleMediumEmphasized =
311 TextStyle(
312 fontFamily = brand,
313 fontWeight = FontWeight.SemiBold,
314 fontSize = 16.sp,
315 lineHeight = 24.sp,
316 letterSpacing = 0.02.em,
317 hyphens = Hyphens.Auto,
318 ),
319 titleSmall =
320 TextStyle(
321 fontFamily = brand,
322 fontWeight = FontWeight.Medium,
323 fontSize = 14.sp,
324 lineHeight = 20.sp,
325 letterSpacing = 0.02.em,
326 hyphens = Hyphens.Auto,
327 ),
328 titleSmallEmphasized =
329 TextStyle(
330 fontFamily = brand,
331 fontWeight = FontWeight.SemiBold,
332 fontSize = 14.sp,
333 lineHeight = 20.sp,
334 letterSpacing = 0.02.em,
335 hyphens = Hyphens.Auto,
336 ),
337 bodyLarge =
338 TextStyle(
339 fontFamily = plain,
340 fontWeight = FontWeight.Normal,
341 fontSize = 16.sp,
342 lineHeight = 24.sp,
343 letterSpacing = 0.01.em,
344 hyphens = Hyphens.Auto,
345 ),
346 bodyLargeEmphasized =
347 TextStyle(
348 fontFamily = plain,
349 fontWeight = FontWeight.Medium,
350 fontSize = 16.sp,
351 lineHeight = 24.sp,
352 letterSpacing = 0.01.em,
353 hyphens = Hyphens.Auto,
354 ),
355 bodyMedium =
356 TextStyle(
357 fontFamily = plain,
358 fontWeight = FontWeight.Normal,
359 fontSize = 14.sp,
360 lineHeight = 20.sp,
361 letterSpacing = 0.01.em,
362 hyphens = Hyphens.Auto,
363 ),
364 bodyMediumEmphasized =
365 TextStyle(
366 fontFamily = plain,
367 fontWeight = FontWeight.Medium,
368 fontSize = 14.sp,
369 lineHeight = 20.sp,
370 letterSpacing = 0.01.em,
371 hyphens = Hyphens.Auto,
372 ),
373 bodySmall =
374 TextStyle(
375 fontFamily = plain,
376 fontWeight = FontWeight.Normal,
377 fontSize = 12.sp,
378 lineHeight = 16.sp,
379 letterSpacing = 0.01.em,
380 hyphens = Hyphens.Auto,
381 ),
382 bodySmallEmphasized =
383 TextStyle(
384 fontFamily = plain,
385 fontWeight = FontWeight.Medium,
386 fontSize = 12.sp,
387 lineHeight = 16.sp,
388 letterSpacing = 0.01.em,
389 hyphens = Hyphens.Auto,
390 ),
391 labelLarge =
392 TextStyle(
393 fontFamily = plain,
394 fontWeight = FontWeight.Medium,
395 fontSize = 14.sp,
396 lineHeight = 20.sp,
397 letterSpacing = 0.01.em,
398 hyphens = Hyphens.Auto,
399 ),
400 labelLargeEmphasized =
401 TextStyle(
402 fontFamily = plain,
403 fontWeight = FontWeight.SemiBold,
404 fontSize = 14.sp,
405 lineHeight = 20.sp,
406 letterSpacing = 0.01.em,
407 hyphens = Hyphens.Auto,
408 ),
409 labelMedium =
410 TextStyle(
411 fontFamily = plain,
412 fontWeight = FontWeight.Medium,
413 fontSize = 12.sp,
414 lineHeight = 16.sp,
415 letterSpacing = 0.01.em,
416 hyphens = Hyphens.Auto,
417 ),
418 labelMediumEmphasized =
419 TextStyle(
420 fontFamily = plain,
421 fontWeight = FontWeight.SemiBold,
422 fontSize = 12.sp,
423 lineHeight = 16.sp,
424 letterSpacing = 0.01.em,
425 hyphens = Hyphens.Auto,
426 ),
427 labelSmall =
428 TextStyle(
429 fontFamily = plain,
430 fontWeight = FontWeight.Medium,
431 fontSize = 11.sp,
432 lineHeight = 16.sp,
433 letterSpacing = 0.01.em,
434 hyphens = Hyphens.Auto,
435 ),
436 labelSmallEmphasized =
437 TextStyle(
438 fontFamily = plain,
439 fontWeight = FontWeight.SemiBold,
440 fontSize = 11.sp,
441 lineHeight = 16.sp,
442 letterSpacing = 0.01.em,
443 hyphens = Hyphens.Auto,
444 ),
445 )
446 }
447
448 @Composable
rememberSettingsTypographynull449 internal fun rememberSettingsTypography(): Typography {
450 val settingsFontFamily = rememberSettingsFontFamily()
451 return remember {
452 if (isSpaExpressiveEnabled) SettingsTypography(settingsFontFamily).expressiveTypography
453 else SettingsTypography(settingsFontFamily).typography
454 }
455 }
456
457 /** Creates a new [TextStyle] which font weight set to medium. */
toMediumWeightnull458 internal fun TextStyle.toMediumWeight() =
459 copy(fontWeight = FontWeight.Medium, letterSpacing = 0.01.em)
460
461 internal fun TextStyle.toSemiBoldWeight() =
462 copy(fontWeight = FontWeight.SemiBold, letterSpacing = 0.01.em)
463