Status Update
Comments
so...@google.com <so...@google.com>
nj...@google.com <nj...@google.com> #2
Hi,
I also see my text cut off when I set maxLines = 2
. Is it the same issue?
Box(
modifier =
Modifier.size(
width = 108dp,
height = 34dp,
),
contentAlignment = Alignment.Center,
) {
BasicText(
text = "text text text",
maxLines = 2,
autoSize = AutoSize.StepBased(minFontSize = 1.sp, maxFontSize = 13.sp, stepSize = 0.2.sp),
)
}
ma...@gmail.com <ma...@gmail.com> #3
Project: platform/frameworks/support
Branch: androidx-main
Author: Jossi Wolf <
Link:
Fix TextAutoSize bug with maxLines = 1
Expand for full commit details
Fix TextAutoSize bug with maxLines = 1
We were overcaching the paragraphIntrinsics in MultiParagraphLayoutCache when mutating the style. For `AutoSizeStepBased` instances with biased windows (more values smaller/bigger than the optimal), this could result in performing layout with outdated intrinsics, and thus an outdated style and font size, without surfacing this in the TextLayoutResult.
Test: New MultiParagraphLayoutCacheTests and manual testing
Relnote: Fixed a bug in BasicText with TextAutoSize and maxLines set to 1.
Fixes: 376834366
Change-Id: Ic0450c763c5d764492995b44ee1fe570246a9689
Files:
- M
compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/text/modifiers/MultiParagraphLayoutCacheTest.kt
- M
compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/modifiers/MultiParagraphLayoutCache.kt
Hash: e1b712d78cc60384ed67a56c006148291ba146a6
Date: Tue Jan 07 18:52:26 2025
nj...@google.com <nj...@google.com> #4
#2, yeah, that's the same issue.
ma...@gmail.com <ma...@gmail.com> #5
Thanks @jo...@google.com for fixing this! Do you know when the fix would be available for g3 apps?
nj...@google.com <nj...@google.com> #6
Moving the internal discussion offline. The bug is fixed and the fix available in snapshot builds. We will comment on this issue when the bug fix is included in a release.
ma...@gmail.com <ma...@gmail.com> #7
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.compose.foundation:foundation:1.8.0-beta01
androidx.compose.foundation:foundation-android:1.8.0-beta01
androidx.compose.foundation:foundation-jvmstubs:1.8.0-beta01
androidx.compose.foundation:foundation-linuxx64stubs:1.8.0-beta01
ma...@gmail.com <ma...@gmail.com> #8
I cannot share a code snippet now but I've used the same approach exposed in that answer on Stack overflow
nj...@google.com <nj...@google.com> #9
Thanks for the screenshots.
I think you can do the following as a workaround to draw the pixel art image directly with anti-aliasing disabled:
val imageBitmap = BitmapFactory.decodeResource(
LocalContext.current.resources,
R.drawable.my_pixel_art
).asImageBitmap()
val paint = remember {
Paint().apply {
isAntiAlias = false
}
}
Canvas(modifier = Modifier.fillMaxSize()) { // DrawScope
drawIntoCanvas { canvas ->
canvas.drawImage(imageBitmap, Offset.Zero, paint)
}
}
ro...@google.com <ro...@google.com> #10
It's filtering you want to disable for pixel art, not anti-aliasing (although you may want that too when the image is rotated or uses subpixel positioning).
ma...@gmail.com <ma...@gmail.com> #11
I ended up using a custom Painter. The painter is almost identical to BitmapPainter
, I have overwritten only DrawScope.onDraw
private val customPaint = Paint().apply {
asFrameworkPaint().apply {
this.isDither = false
this.isFilterBitmap = false
this.isAntiAlias = false
}
}
override fun DrawScope.onDraw() {
drawIntoCanvas {
it.drawImageRect(
image = image,
srcSize = srcSize,
srcOffset = srcOffset,
dstSize = IntSize(
this@onDraw.size.width.roundToInt(),
this@onDraw.size.height.roundToInt()
),
paint = customPaint
)
}
}
ap...@google.com <ap...@google.com> #12
Branch: androidx-main
commit 5df92271b6eac729464aea71f9691acd21983777
Author: Nader Jawad <njawad@google.com>
Date: Tue Jul 13 12:35:20 2021
Add support for FilterQuality in DrawScope
Relnote: "Updated DrawScope#drawImage method that
consumes source and destination rects
to consume an optional FilterQuality
parameter. This is useful for pixel
art that is intended to be pixelated
when scaled up for pixel based art.
Updated BitmapPainter + Image composable
to also consume an optional FilterQuality
parameter"
Fixes: 180311607
Test: Added various tests to DrawScopeTest,
BitmapPainterTest and ImageTest
Change-Id: Ie4fb04013701add0fba1c5c6bb9da2812d6436e7
M compose/foundation/foundation/api/current.ignore
M compose/foundation/foundation/api/current.txt
M compose/foundation/foundation/api/public_plus_experimental_current.txt
M compose/foundation/foundation/api/restricted_current.ignore
M compose/foundation/foundation/api/restricted_current.txt
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ImageTest.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Image.kt
D compose/material/material/api/current.ignore
D compose/material/material/api/restricted_current.ignore
D compose/ui/ui-graphics/api/current.ignore
M compose/ui/ui-graphics/api/current.txt
M compose/ui/ui-graphics/api/public_plus_experimental_current.txt
D compose/ui/ui-graphics/api/restricted_current.ignore
M compose/ui/ui-graphics/api/restricted_current.txt
M compose/ui/ui-graphics/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/drawscope/DrawScopeTest.kt
M compose/ui/ui-graphics/src/androidAndroidTest/kotlin/androidx/compose/ui/graphics/painter/BitmapPainterTest.kt
M compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/Paint.kt
M compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/drawscope/CanvasDrawScope.kt
M compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.kt
M compose/ui/ui-graphics/src/commonMain/kotlin/androidx/compose/ui/graphics/painter/BitmapPainter.kt
D compose/ui/ui-text/api/current.ignore
D compose/ui/ui-text/api/restricted_current.ignore
Description
Jetpack Compose release version: 1.0.0-alpha12
I would like to ask to allow to disable the antialiasing when using the
Image
composable. Paint has an antialiasing property but it's not exposed by the painter object used to draw the image.There is currently no easy way to disable the antialiasing without creating a custom painter and using a Paint object that is not the one passed to the DrawScope of the painter.
With SwiftUi I can simply use
func antialiased(Bool) -> Image
that is an extension ofImage