diff --git a/android/app/src/main/java/aza/instant/SvgUtil.kt b/android/app/src/main/java/aza/instant/SvgUtil.kt index 3401ffe..3b931ce 100644 --- a/android/app/src/main/java/aza/instant/SvgUtil.kt +++ b/android/app/src/main/java/aza/instant/SvgUtil.kt @@ -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) \ No newline at end of file +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) +} diff --git a/android/app/src/main/res/raw/quicksand_bold.ttf b/android/app/src/main/res/raw/quicksand_bold.ttf new file mode 100644 index 0000000..0106805 Binary files /dev/null and b/android/app/src/main/res/raw/quicksand_bold.ttf differ diff --git a/android/app/src/main/res/raw/quicksand_medium.ttf b/android/app/src/main/res/raw/quicksand_medium.ttf new file mode 100644 index 0000000..afca2d9 Binary files /dev/null and b/android/app/src/main/res/raw/quicksand_medium.ttf differ diff --git a/android/app/src/main/res/raw/quicksand_regular.ttf b/android/app/src/main/res/raw/quicksand_regular.ttf new file mode 100644 index 0000000..c03548a Binary files /dev/null and b/android/app/src/main/res/raw/quicksand_regular.ttf differ