jvmMain.dev.icerock.moko.resources.FontResource.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resources-jvm Show documentation
Show all versions of resources-jvm Show documentation
Resources access for Kotlin Multiplatform development (mobile first)
The newest version!
/*
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/
package dev.icerock.moko.resources
import java.awt.Font
import java.awt.GraphicsEnvironment
import java.io.File
import java.io.FileNotFoundException
import java.io.InputStream
actual class FontResource(
val resourcesClassLoader: ClassLoader,
val filePath: String
) {
val file: File by lazy {
val resourceStream: InputStream = resourcesClassLoader.getResourceAsStream(filePath)
?: throw FileNotFoundException("Couldn't find font resource at: $filePath")
resourceStream.use { inputStream ->
val file = File.createTempFile("moko-resources-font-cache", null)
file.deleteOnExit()
file.outputStream().use { outputStream ->
inputStream.copyTo(outputStream)
}
file
}
}
val font: Font by lazy {
Font.createFont(Font.TRUETYPE_FONT, file)
}
init {
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy