Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Noto flag emojis exceed bounds #2

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import org.jetbrains.skia.Rect
import org.jetbrains.skia.skottie.Animation
import org.jetbrains.skia.sksg.InvalidationController
import org.jetbrains.skia.svg.SVGDOM
import org.jetbrains.skia.svg.SVGLengthContext
import org.jetbrains.skia.svg.SVGLengthUnit
import kotlin.math.min
import kotlin.math.roundToInt


Expand All @@ -41,9 +42,24 @@ internal actual fun SVGImage(image: SVGImage, contentDescription: String, modifi
this.role = Role.Image
}
) {
image.dom.setContainerSize(size.width, size.height)
val svgWidth = image.dom.root?.width
val svgHeight = image.dom.root?.height
// If the SVG has width+height specs instead of viewBox, Skia will not honor the container size
val scaleManually =
svgWidth?.unit == SVGLengthUnit.NUMBER && svgHeight?.unit == SVGLengthUnit.NUMBER
if (!scaleManually) {
image.dom.setContainerSize(size.width, size.height)
}
drawIntoCanvas { canvas ->
image.dom.render(canvas.nativeCanvas)
if (svgWidth != null && svgHeight != null && scaleManually) {
val scaleFactor = min(size.width / svgWidth.value, size.height / svgHeight.value)
canvas.save()
canvas.scale(scaleFactor, scaleFactor)
image.dom.render(canvas.nativeCanvas)
canvas.restore()
} else {
image.dom.render(canvas.nativeCanvas)
}
}
}
}
Expand Down
Loading