You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package org.jetbrains.codeviewer.platform
|
|
|
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.ui.text.font.Font
|
|
|
|
import androidx.compose.ui.text.font.FontStyle
|
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
|
import kotlinx.coroutines.runBlocking
|
|
|
|
import org.jetbrains.compose.resources.ExperimentalResourceApi
|
|
|
|
import org.jetbrains.compose.resources.resource
|
|
|
|
|
|
|
|
private val cache: MutableMap<String, Font> = mutableMapOf()
|
|
|
|
|
|
|
|
@OptIn(ExperimentalResourceApi::class)
|
|
|
|
@Composable
|
|
|
|
actual fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font {
|
|
|
|
return cache.getOrPut(res) {
|
|
|
|
val byteArray = runBlocking {
|
|
|
|
resource("font/$res.ttf").readBytes()
|
|
|
|
}
|
|
|
|
androidx.compose.ui.text.platform.Font(res, byteArray, weight, style)
|
|
|
|
}
|
|
|
|
}
|