Cicero
05/11/2021, 9:26 AMCicero
05/11/2021, 9:26 AMprivate fun create(
fontStyle: FontStyle = FontStyle.Normal,
fontWeight: FontWeight = FontWeight.Normal,
fontFamily: FontListFontFamily,
fontSynthesis: FontSynthesis = FontSynthesis.All
): Typeface {
val font = fontMatcher.matchFont(fontFamily, fontWeight, fontStyle)
val typeface = try {
when (font) {
is ResourceFont -> resourceLoader.load(font) as Typeface
is AndroidFont -> font.typeface
else -> throw IllegalStateException("Unknown font type: $font")
}
} catch (e: Exception) {
throw IllegalStateException("Cannot create Typeface from $font")
}
val loadedFontIsSameAsRequest = fontWeight == font.weight && fontStyle == font.style
// if synthesis is not requested or there is an exact match we don't need synthesis
if (fontSynthesis == FontSynthesis.None || loadedFontIsSameAsRequest) {
return typeface
}
return synthesize(typeface, font, fontWeight, fontStyle, fontSynthesis)
}
Cicero
05/11/2021, 9:26 AMthrow IllegalStateException("Cannot create Typeface from $font")
Cicero
05/11/2021, 9:28 AMCicero
05/11/2021, 9:29 AMCicero
05/11/2021, 9:31 AMCicero
05/11/2021, 9:31 AMCicero
05/11/2021, 9:43 AMCicero
05/11/2021, 9:44 AMCicero
05/11/2021, 9:44 AMCicero
05/11/2021, 9:47 AMRahul Sainani
05/12/2021, 9:20 AMCicero
05/12/2021, 10:00 AM