[F] Fix font

This commit is contained in:
2025-10-26 11:04:32 +08:00
parent acbf4b8998
commit ac2d815228
4 changed files with 22 additions and 1 deletions
@@ -1,7 +1,11 @@
package aza.instant
import android.content.Context
import android.graphics.Picture
import android.graphics.Typeface
import androidx.core.content.res.ResourcesCompat
import com.caverock.androidsvg.SVG
import com.caverock.androidsvg.SVGExternalFileResolver
import qrcode.QRCode
import qrcode.raw.ErrorCorrectionLevel
import java.io.ByteArrayOutputStream
@@ -36,4 +40,21 @@ suspend fun genSvg(template: String, imagePath: String): String {
return svg
}
fun renderSvgAndroid(svg: String): Picture? = SVG.getFromString(svg).renderToPicture(6192 /6, 4128/6)
class FontResolver(private val context: Context) : SVGExternalFileResolver() {
override fun resolveFont(fontFamily: String?, fontWeight: Int, fontStyle: String?): Typeface? {
if (fontFamily.equals("Quicksand", ignoreCase = true)) {
val fontRes = when (fontWeight) {
in 0..400 -> R.raw.quicksand_regular
in 401..600 -> R.raw.quicksand_medium
else -> R.raw.quicksand_bold
}
return ResourcesCompat.getFont(context, fontRes)
}
return super.resolveFont(fontFamily, fontWeight, fontStyle)
}
}
fun renderSvgAndroid(context: Context, svg: String): Picture? {
SVG.registerExternalFileResolver(FontResolver(context))
return SVG.getFromString(svg).renderToPicture(6192 / 6, 4128 / 6)
}
Binary file not shown.
Binary file not shown.
Binary file not shown.