-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FontVariation.Settings support to the resources library (#5183)
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 <[email protected]>
- Loading branch information
Showing
12 changed files
with
249 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+1.61 MB
...ts/resources/demo/shared/src/commonMain/composeResources/font/RobotoFlex-VariableFont.ttf
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...es/library/src/skikoTest/kotlin/org/jetbrains/compose/resources/VariationFontCacheTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters