Skip to content

Commit 57c35d0

Browse files
committed
Migrate to woff2 fonts with woff2ttf decoder
1 parent 6b8a4e6 commit 57c35d0

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

tools/idea-plugin/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [Gutter] Add support for multiple icons in kt file
1515
- [Web Import] Add `Remix` icons provider
1616
- [Web Import] Add `Box` icons provider
17+
- [Web Import] Force `Material Symbols` and `Lucide` icon providers to use woff2 font
1718

1819
### Fixed
1920

tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/material/data/font/MaterialFontRepository.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.composegears.valkyrie.ui.screen.webimport.material.data.font
22

33
import io.github.composegears.valkyrie.ui.screen.webimport.material.domain.model.font.MaterialFontSettings
4+
import io.github.composegears.valkyrie.util.font.Woff2Decoder
45
import io.ktor.client.HttpClient
56
import io.ktor.client.request.get
67
import io.ktor.client.statement.bodyAsChannel
@@ -14,7 +15,9 @@ class MaterialFontRepository(
1415
private val httpClient: HttpClient,
1516
) {
1617
suspend fun downloadFont(url: String): ByteArray = withContext(Dispatchers.IO) {
17-
httpClient.get(url).bodyAsChannel().toByteArray()
18+
val woff2Bytes = httpClient.get(url).bodyAsChannel().toByteArray()
19+
20+
Woff2Decoder.decodeBytes(woff2Bytes) ?: error("Failed to decode WOFF2 font")
1821
}
1922

2023
suspend fun downloadSvg(

tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/material/domain/model/font/MaterialIconFontFamily.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ enum class MaterialIconFontFamily(
66
val fontFamily: String,
77
) {
88
Outlined(
9-
cdnUrl = "https://cdn.jsdelivr.net/gh/google/material-design-icons@master/variablefont/MaterialSymbolsOutlined%5BFILL%2CGRAD%2Copsz%2Cwght%5D.ttf",
9+
cdnUrl = "https://cdn.jsdelivr.net/gh/google/material-design-icons@master/variablefont/MaterialSymbolsOutlined%5BFILL%2CGRAD%2Copsz%2Cwght%5D.woff2",
1010
displayName = "Outlined",
1111
fontFamily = "materialsymbolsoutlined",
1212
),
1313
Rounded(
14-
cdnUrl = "https://cdn.jsdelivr.net/gh/google/material-design-icons@master/variablefont/MaterialSymbolsRounded%5BFILL%2CGRAD%2Copsz%2Cwght%5D.ttf",
14+
cdnUrl = "https://cdn.jsdelivr.net/gh/google/material-design-icons@master/variablefont/MaterialSymbolsRounded%5BFILL%2CGRAD%2Copsz%2Cwght%5D.woff2",
1515
displayName = "Rounded",
1616
fontFamily = "materialsymbolsrounded",
1717
),
1818
Sharp(
19-
cdnUrl = "https://cdn.jsdelivr.net/gh/google/material-design-icons@master/variablefont/MaterialSymbolsSharp%5BFILL%2CGRAD%2Copsz%2Cwght%5D.ttf",
19+
cdnUrl = "https://cdn.jsdelivr.net/gh/google/material-design-icons@master/variablefont/MaterialSymbolsSharp%5BFILL%2CGRAD%2Copsz%2Cwght%5D.woff2",
2020
displayName = "Sharp",
2121
fontFamily = "materialsymbolssharp",
2222
),

tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/standard/lucide/data/LucideRepository.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.composegears.valkyrie.ui.screen.webimport.standard.lucide.data
22

3+
import io.github.composegears.valkyrie.util.font.Woff2Decoder
34
import io.ktor.client.HttpClient
45
import io.ktor.client.request.get
56
import io.ktor.client.statement.bodyAsChannel
@@ -20,7 +21,7 @@ class LucideRepository(
2021
) {
2122
companion object {
2223
private const val UNPKG_BASE = "https://unpkg.com/lucide-static@latest"
23-
private const val FONT_URL = "$UNPKG_BASE/font/lucide.ttf"
24+
private const val FONT_URL = "$UNPKG_BASE/font/lucide.woff2"
2425
private const val CSS_URL = "https://cdn.jsdelivr.net/npm/lucide-static@latest/font/lucide.css"
2526
}
2627

@@ -45,9 +46,10 @@ class LucideRepository(
4546
suspend fun loadFontBytes(): ByteArray = withContext(Dispatchers.IO) {
4647
fontMutex.withLock {
4748
fontBytesCache ?: run {
48-
val bytes = httpClient.get(FONT_URL).bodyAsChannel().toByteArray()
49-
fontBytesCache = bytes
50-
bytes
49+
val woff2Bytes = httpClient.get(FONT_URL).bodyAsChannel().toByteArray()
50+
val ttfBytes = Woff2Decoder.decodeBytes(woff2Bytes) ?: error("Failed to decode WOFF2 font")
51+
fontBytesCache = ttfBytes
52+
ttfBytes
5153
}
5254
}
5355
}

0 commit comments

Comments
 (0)