Font

class Font @JvmOverloads constructor(val resourcePath: String, val letterSpacing: Float = 0.0f, val lineSpacing: Float = 1.2f, val family: FontFamily? = null, val italic: Boolean = resourcePath.contains("italic", ignoreCase = true), val weight: Font.Weight = Weight.entries.getByName(resourcePath.findLastAnyOf(Weight.entries.names(), ignoreCase = true)?.second) ?: Weight.Regular) : Resource

Font

A font used by the rendering implementation. As with other PolyUI resources, the actual loading, management, etc. of the font is NOT managed in this class in any way. This class just contains metadata for usage with PolyUI.

Parameters

resourcePath

The resource of the font, can be a URL (see here, you should use this or an equivalent method)

letterSpacing

The letter spacing of the font, in pixels (e.g. 1 pixel = 1 empty pixel between each letter).

lineSpacing

The line spacing of the font, in proportion to the font size (e.g. 2 means 1 empty line between each line, 1.5 = half a line between...)

family

a reference to the family that encloses this font. Only set if this font was retrieved from a method like FontFamily.get or similar.

Constructors

Link copied to clipboard
constructor(resourcePath: String, letterSpacing: Float = 0.0f, lineSpacing: Float = 1.2f, family: FontFamily? = null, italic: Boolean = resourcePath.contains("italic", ignoreCase = true), weight: Font.Weight = Weight.entries.getByName(resourcePath.findLastAnyOf(Weight.entries.names(), ignoreCase = true)?.second) ?: Weight.Regular)

Types

Link copied to clipboard
object Companion
Link copied to clipboard

Enum representing weights available to a font in PolyUI.

Properties

Link copied to clipboard
val family: FontFamily? = null
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
@get:JvmName(name = "shouldLoadSync")
val loadSync: Boolean

true if this resource should be loaded synchronously, false otherwise. (optional operation)

Link copied to clipboard
val name: <Error class: unknown class>
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open fun bytes(): ByteArray

Return this resource's contents as an array of bytes.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
fun getAtStyle(weight: Font.Weight, italic: Boolean): Font
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
inline fun load(errorHandler: (Throwable) -> ByteArray = { throw it }): ByteArray

load the given resource synchronously into a new byte array. you may then perform any operations on the result.

inline fun <T> load(errorHandler: (Throwable) -> T & Any = { throw it }, mapper: (ByteArray) -> T & Any): T

load the given resource synchronously, mapping to definitely non-nullable type T. you may then perform any operations on the result.

Link copied to clipboard
fun loadAsync(errorHandler: (Throwable) -> Unit = { throw it }, consumer: (ByteArray) -> Unit)

load the given resource asynchronously into a new byte array, calling the consumer with the result on the worker thread.

fun <T> loadAsync(errorHandler: (Throwable) -> Unit = { throw it }, mapper: (ByteArray) -> T & Any, consumer: (T & Any) -> Unit)

load the given resource asynchronously, mapping to definitely non-nullable type T, calling the consumer with the result on the worker thread.

Link copied to clipboard
fun onInit(func: () -> Unit)

Add a callback that will be executed once this resource is about to be initialized by a rendering implementation.

Link copied to clipboard
@ApiStatus.Internal
fun reportInit()

Use this method to execute any callbacks that were added before the resource was initialized.

Link copied to clipboard
fun setLoadingClass(loadingClass: Class<*>)

Set the class that will be used to load this resource. This is useful if you want to load resources from a different classloader or package. Note that you can only set this once, and all subsequent calls will be ignored.

Link copied to clipboard
open fun stream(): InputStream

return the stream of this resource. it is the caller's responsibility to close the stream.

Link copied to clipboard
open override fun toString(): String