[F] Scaling
This commit is contained in:
@@ -44,6 +44,7 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.withTranslation
|
||||
import androidx.work.OneTimeWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
import androidx.work.workDataOf
|
||||
@@ -165,7 +166,19 @@ fun FileListerScreen(modifier: Modifier = Modifier, sharedImageUri: Uri?, onShar
|
||||
Column(modifier = Modifier.weight(1f), horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
picture?.let { p ->
|
||||
Canvas(modifier = Modifier.fillMaxWidth().weight(1f).drawWithCache {
|
||||
onDrawWithContent{ drawIntoCanvas { it.nativeCanvas.drawPicture(p) } }
|
||||
onDrawWithContent {
|
||||
drawIntoCanvas { canvas ->
|
||||
if (!(p.width > 0 && p.height > 0)) return@onDrawWithContent
|
||||
val scale = minOf(size.width / p.width, size.height / p.height)
|
||||
val dx = (size.width - p.width * scale) / 2
|
||||
val dy = (size.height - p.height * scale) / 2
|
||||
|
||||
canvas.nativeCanvas.withTranslation(dx, dy) {
|
||||
scale(scale, scale)
|
||||
drawPicture(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class FontResolver(private val context: Context) : SVGExternalFileResolver() {
|
||||
|
||||
fun renderSvgAndroid(context: Context, svg: String): Picture? {
|
||||
SVG.registerExternalFileResolver(FontResolver(context))
|
||||
return SVG.getFromString(svg).renderToPicture(7133 / 2, 4904 / 2)
|
||||
return SVG.getFromString(svg).renderToPicture(7133, 4904)
|
||||
}
|
||||
|
||||
fun renderSvgBytes(context: Context, svg: String, exif: ExifResult) = renderSvgAndroid(context, svg)?.run {
|
||||
|
||||
Reference in New Issue
Block a user