Browse Source
Sample: ```kotlin Text( modifier = Modifier.padding(16.dp), fontFamily = FontFamily( Font( Res.font.RobotoFlex_VariableFont, variationSettings = FontVariation.Settings(FontVariation.weight(400)) ), ), text = "The quick brown fox jumps over the lazy dog" ) ``` Fixes https://youtrack.jetbrains.com/issue/CMP-7088 ## Testing Demo app: `./gradlew :resources:demo:desktopApp:run` <img width="600" alt="image" src="https://github.com/user-attachments/assets/7fc0403b-6732-42bb-97dc-211136a82d44" /> ## Release Notes ### Highlights - Resources - Add FontVariation.Settings support to the resources library Co-authored-by: adamglin <wwalkingg@gmail.com>pull/4132/merge v1.8.0+dev1976
Konstantin
5 days ago
committed by
GitHub
12 changed files with 249 additions and 7 deletions
Binary file not shown.
@ -0,0 +1,49 @@
|
||||
package org.jetbrains.compose.resources |
||||
|
||||
import androidx.compose.ui.text.font.FontVariation |
||||
import kotlin.test.Test |
||||
import kotlin.test.assertEquals |
||||
import kotlin.test.assertFailsWith |
||||
|
||||
class VariationFontCacheTest { |
||||
|
||||
@Test |
||||
fun `getCacheKey should return an empty string for an empty settings list`() { |
||||
val settings = FontVariation.Settings() |
||||
val cacheKey = settings.getCacheKey() |
||||
assertEquals("", cacheKey, "Cache key for empty settings list should be an empty string") |
||||
} |
||||
|
||||
@Test |
||||
fun `getCacheKey should return a correct key for a single setting`() { |
||||
val setting = FontVariation.Setting("wght", 700f) |
||||
val settings = FontVariation.Settings(setting) |
||||
val cacheKey = settings.getCacheKey() |
||||
assertEquals("SettingFloat(wght,700.0)", cacheKey, "Cache key for a single setting is incorrect") |
||||
} |
||||
|
||||
@Test |
||||
fun `getCacheKey should correctly sort settings by class name and axis name`() { |
||||
val setting1 = FontVariation.Setting("wght", 400f) |
||||
val setting2 = FontVariation.Setting("ital", 1f) |
||||
val settings = FontVariation.Settings(setting1, setting2) |
||||
val cacheKey = settings.getCacheKey() |
||||
assertEquals( |
||||
"SettingFloat(ital,1.0),SettingFloat(wght,400.0)", |
||||
cacheKey, |
||||
"Cache key should sort settings by class name and axis name" |
||||
) |
||||
} |
||||
|
||||
@Test |
||||
fun `getCacheKey should throw an exception when there are duplicate settings`() { |
||||
val setting1 = FontVariation.Setting("wght", 400f) |
||||
val setting2 = FontVariation.Setting("wght", 700f) |
||||
|
||||
assertFailsWith<IllegalArgumentException>( |
||||
"'axis' must be unique" |
||||
) { |
||||
FontVariation.Settings(setting1, setting2) |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue