[F] Fix font
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
package aza.instant
|
package aza.instant
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.graphics.Picture
|
import android.graphics.Picture
|
||||||
|
import android.graphics.Typeface
|
||||||
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import com.caverock.androidsvg.SVG
|
import com.caverock.androidsvg.SVG
|
||||||
|
import com.caverock.androidsvg.SVGExternalFileResolver
|
||||||
import qrcode.QRCode
|
import qrcode.QRCode
|
||||||
import qrcode.raw.ErrorCorrectionLevel
|
import qrcode.raw.ErrorCorrectionLevel
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
@@ -36,4 +40,21 @@ suspend fun genSvg(template: String, imagePath: String): String {
|
|||||||
return svg
|
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.
Reference in New Issue
Block a user