jeran
10/07/2022, 7:27 PMagrosner
10/07/2022, 10:43 PMagrosner
10/07/2022, 10:43 PMDavid Herman
10/11/2022, 3:34 AMjeran
10/13/2022, 6:09 PMjeran
10/13/2022, 6:10 PMDavid Herman
10/13/2022, 7:02 PMagrosner
10/14/2022, 1:54 PMagrosner
10/14/2022, 1:54 PMagrosner
10/14/2022, 1:55 PMrequire
.agrosner
10/14/2022, 1:56 PMdata class FontResourceImpl(private val font: AsyncFont, private val fileName: String) : FontResource {
override val realFont: Font
@Composable
get() = fontOrHelp(fileName, font)
}
agrosner
10/14/2022, 1:56 PMinterface FontResource {
@get:Composable
val realFont: Font
}
expect fun findFontResource(font: AsyncFont): FontResource?
data class AsyncFont(
val identity: String,
override val style: FontStyle,
override val weight: FontWeight,
val fontName: String
) : Font {
override val loadingStrategy: FontLoadingStrategy = FontLoadingStrategy.Async
}
agrosner
10/14/2022, 1:58 PM@Composable
fun FontStyleLocal.resolveFontFamily(): FontFamily {
val fonts = **.fonts
val font = when (this) {
FontStyleLocal.BaseBold -> fonts.bold
FontStyleLocal.BaseItalics -> fonts.italics
FontStyleLocal.BaseRegular -> fonts.regular
FontStyleLocal.Primary -> fonts.primary
}
val found = findFontResource(font)?.realFont ?: Font(
identity = "",
data = ByteArray(0),
)
return FontFamily(
found
)
}
composable to load font, we have our own design system so this just maps a token to the font and resource (probably dont need first portion of function)agrosner
10/14/2022, 1:59 PMwebpack.config.d
next to source a file I call it `01-resources.js`:
config.module.rules.push({
test: /\.(woff|woff2|eot|ttf|otf)$/i,
loader: "file-loader"
})
agrosner
10/14/2022, 1:59 PMagrosner
10/14/2022, 2:00 PMimplementation(npm("copy-webpack-plugin", "9.0.0"))
implementation(npm("file-loader", "6.2.0"))
agrosner
10/14/2022, 2:00 PMagrosner
10/14/2022, 2:01 PMjeran
10/18/2022, 2:55 PMagrosner
10/18/2022, 3:44 PMJeff T
12/01/2022, 4:44 PMwindow.fetch
solution working? trying to decide best path forward so I was curious if there are alternate options to implement thisjeran
12/01/2022, 4:50 PMwindow.fetch(
Request(url),
).then { response ->
response.arrayBuffer()
}.then { arrayBuffer ->
val byteLength = arrayBuffer.byteLength
val byteArray = ByteArray(byteLength)
val uInt8Array = Uint8Array(arrayBuffer)
for (i in 0 until byteLength) {
byteArray[i] = uInt8Array[i]
}
return@then androidx.compose.ui.text.platform.Font(
identity = url,
data = byteArray,
weight = weight,
style = style,
)
}.await()
where url is a url to a ttf, weight and style are corresponding FontWeight
and FontStyle
and you can use it something like this:
@Composable
fun rememberFont(
url: String,
weight: FontWeight,
style: FontStyle,
): Font? {
var font by remember { mutableStateOf<Font?>(null) }
LaunchedEffect(path, weight, style) {
font = loadFont(url, weight, style)
}
return font
}
Jeff T
12/01/2022, 4:54 PMjeran
12/05/2022, 10:34 PMjeran
12/05/2022, 10:34 PMjeran
12/05/2022, 10:38 PMJeff T
12/06/2022, 3:28 AM