diff --git a/src/main/kotlin/com/muedsa/snapshot/Snapshot.kt b/src/main/kotlin/com/muedsa/snapshot/Snapshot.kt index 35a6d04..19bd73f 100644 --- a/src/main/kotlin/com/muedsa/snapshot/Snapshot.kt +++ b/src/main/kotlin/com/muedsa/snapshot/Snapshot.kt @@ -38,7 +38,6 @@ class Snapshot( surface.flush() image = surface.makeImageSnapshot() surface.close() - rootWidget.dispose() isDrawed = true } diff --git a/src/main/kotlin/com/muedsa/snapshot/paint/decoration/BoxPainter.kt b/src/main/kotlin/com/muedsa/snapshot/paint/decoration/BoxPainter.kt index af96405..4a058d8 100644 --- a/src/main/kotlin/com/muedsa/snapshot/paint/decoration/BoxPainter.kt +++ b/src/main/kotlin/com/muedsa/snapshot/paint/decoration/BoxPainter.kt @@ -2,12 +2,8 @@ package com.muedsa.snapshot.paint.decoration import com.muedsa.geometry.Offset import com.muedsa.geometry.Size -import com.muedsa.snapshot.annotation.MustCallSuper import org.jetbrains.skia.Canvas abstract class BoxPainter { abstract fun paint(canvas: Canvas, offset: Offset, size: Size) - - @MustCallSuper - fun dispose() { } } \ No newline at end of file diff --git a/src/main/kotlin/com/muedsa/snapshot/paint/decoration/DecorationImagePainter.kt b/src/main/kotlin/com/muedsa/snapshot/paint/decoration/DecorationImagePainter.kt index f677d21..f43eb4c 100644 --- a/src/main/kotlin/com/muedsa/snapshot/paint/decoration/DecorationImagePainter.kt +++ b/src/main/kotlin/com/muedsa/snapshot/paint/decoration/DecorationImagePainter.kt @@ -7,5 +7,4 @@ import org.jetbrains.skia.Rect interface DecorationImagePainter { fun paint(canvas: Canvas, rect: Rect, clipPath : Path?, blend: Float = 1f, blendMode: BlendMode = BlendMode.SRC_OVER) - fun dispose() } \ No newline at end of file diff --git a/src/main/kotlin/com/muedsa/snapshot/paint/decoration/InternalDecorationImagePainter.kt b/src/main/kotlin/com/muedsa/snapshot/paint/decoration/InternalDecorationImagePainter.kt index 79916f1..32c2a73 100644 --- a/src/main/kotlin/com/muedsa/snapshot/paint/decoration/InternalDecorationImagePainter.kt +++ b/src/main/kotlin/com/muedsa/snapshot/paint/decoration/InternalDecorationImagePainter.kt @@ -36,11 +36,4 @@ internal class InternalDecorationImagePainter( canvas.restore() } } - - - override fun dispose() { - if (!details.image.isClosed) { - details.image.close() - } - } } \ No newline at end of file diff --git a/src/main/kotlin/com/muedsa/snapshot/paint/text/SimpleTextPainter.kt b/src/main/kotlin/com/muedsa/snapshot/paint/text/SimpleTextPainter.kt index 95c146e..8dbf02b 100644 --- a/src/main/kotlin/com/muedsa/snapshot/paint/text/SimpleTextPainter.kt +++ b/src/main/kotlin/com/muedsa/snapshot/paint/text/SimpleTextPainter.kt @@ -17,8 +17,8 @@ class SimpleTextPainter( val maxLines: Int? = null, val ellipsis: String? = null, val textWidthBasis: TextWidthBasis = TextWidthBasis.PARENT, - val textHeightMode: HeightMode? = null, -): AutoCloseable { + val textHeightMode: HeightMode? = null +) { init { fontFamilyName?.let { @@ -202,11 +202,6 @@ class SimpleTextPainter( } } - override fun close() { - layoutCache?.paragraph?.close() - layoutCache = null - } - override fun toString(): String { return "SimpleTextPainter(text='$text', color=$color, fontSize=$fontSize, fontFamilyName=${fontFamilyName?.contentToString()}, fontStyle=$fontStyle, textAlign=$textAlign, textDirection=$textDirection, maxLines=$maxLines, ellipsis=$ellipsis, textWidthBasis=$textWidthBasis, textHeightMode=$textHeightMode)" } @@ -244,7 +239,7 @@ class SimpleTextPainter( ).apply { layout(minWidth = minWidth, maxWidth = maxWidth) } - return painter.use { painter.width } + return painter.width } @JvmStatic @@ -278,7 +273,7 @@ class SimpleTextPainter( ).apply { layout(minWidth = minWidth, maxWidth = maxWidth) } - return painter.use { painter.maxIntrinsicWidth } + return painter.maxIntrinsicWidth } private fun computePaintOffsetFraction(textAlign: Alignment, textDirection: Direction) :Float = diff --git a/src/main/kotlin/com/muedsa/snapshot/widget/LocalImage.kt b/src/main/kotlin/com/muedsa/snapshot/widget/LocalImage.kt index d47b766..e50704f 100644 --- a/src/main/kotlin/com/muedsa/snapshot/widget/LocalImage.kt +++ b/src/main/kotlin/com/muedsa/snapshot/widget/LocalImage.kt @@ -1,7 +1,6 @@ package com.muedsa.snapshot.widget import com.muedsa.geometry.BoxAlignment -import com.muedsa.snapshot.annotation.MustCallSuper import com.muedsa.snapshot.paint.BoxFit import com.muedsa.snapshot.paint.ImageRepeat import com.muedsa.snapshot.rendering.box.RenderBox @@ -36,10 +35,4 @@ open class LocalImage( colorBlendMode = colorBlendMode ) } - - @MustCallSuper - override fun dispose() { - image.close() - super.dispose() - } } \ No newline at end of file diff --git a/src/main/kotlin/com/muedsa/snapshot/widget/MultiChildWidget.kt b/src/main/kotlin/com/muedsa/snapshot/widget/MultiChildWidget.kt index 0e09f7d..f9281c1 100644 --- a/src/main/kotlin/com/muedsa/snapshot/widget/MultiChildWidget.kt +++ b/src/main/kotlin/com/muedsa/snapshot/widget/MultiChildWidget.kt @@ -1,7 +1,5 @@ package com.muedsa.snapshot.widget -import com.muedsa.snapshot.annotation.MustCallSuper - abstract class MultiChildWidget( val children: Array? ) : Widget() { @@ -12,10 +10,4 @@ abstract class MultiChildWidget( it.parent = this } } - - @MustCallSuper - override fun dispose() { - children?.forEach { it.dispose() } - super.dispose() - } } \ No newline at end of file diff --git a/src/main/kotlin/com/muedsa/snapshot/widget/SingleChildWidget.kt b/src/main/kotlin/com/muedsa/snapshot/widget/SingleChildWidget.kt index c45251c..4b8f212 100644 --- a/src/main/kotlin/com/muedsa/snapshot/widget/SingleChildWidget.kt +++ b/src/main/kotlin/com/muedsa/snapshot/widget/SingleChildWidget.kt @@ -1,7 +1,5 @@ package com.muedsa.snapshot.widget -import com.muedsa.snapshot.annotation.MustCallSuper - abstract class SingleChildWidget( val child: Widget? ) : Widget() { @@ -13,10 +11,4 @@ abstract class SingleChildWidget( it.parent = this } } - - @MustCallSuper - override fun dispose() { - child?.dispose() - super.dispose() - } } \ No newline at end of file diff --git a/src/main/kotlin/com/muedsa/snapshot/widget/Widget.kt b/src/main/kotlin/com/muedsa/snapshot/widget/Widget.kt index 0dc2094..81abf93 100644 --- a/src/main/kotlin/com/muedsa/snapshot/widget/Widget.kt +++ b/src/main/kotlin/com/muedsa/snapshot/widget/Widget.kt @@ -1,6 +1,5 @@ package com.muedsa.snapshot.widget -import com.muedsa.snapshot.annotation.MustCallSuper import com.muedsa.snapshot.rendering.box.RenderBox abstract class Widget { @@ -16,7 +15,4 @@ abstract class Widget { } abstract fun createRenderTree(): RenderBox - - @MustCallSuper - open fun dispose() { } } \ No newline at end of file diff --git a/src/test/kotlin/com/muedsa/snapshot/paint/SimpleTextPainterTest.kt b/src/test/kotlin/com/muedsa/snapshot/paint/SimpleTextPainterTest.kt index 07222c3..4c02d30 100644 --- a/src/test/kotlin/com/muedsa/snapshot/paint/SimpleTextPainterTest.kt +++ b/src/test/kotlin/com/muedsa/snapshot/paint/SimpleTextPainterTest.kt @@ -155,10 +155,26 @@ class SimpleTextPainterTest { } + @OptIn(ExperimentalStdlibApi::class) + @Test + fun emoji_test() { + println("\n\n\nSimpleTextPainterTest.emoji_test()") + val textPainter = SimpleTextPainter( + text = SAMPLE_EMOJI, + fontSize = 30f + ).apply { + layout(0f, 600f) + } + drawPainter("text/emoji", textPainter.size) { canvas -> + textPainter.paint(canvas, offset = Offset.ZERO) + textPainter.debugPaint(canvas, offset = Offset.ZERO) + } + } companion object { const val SAMPLE_TEXT_EN = "Hello Word!" const val SAMPLE_TEXT_CN = "你好,世界!" const val SAMPLE_TEXT = "$SAMPLE_TEXT_EN $SAMPLE_TEXT_CN" + const val SAMPLE_EMOJI = "\uD83E\uDD70\uD83D\uDC80✌\uFE0F\uD83C\uDF34\uD83D\uDC22\uD83D\uDC10\uD83C\uDF44⚽\uD83C\uDF7B\uD83D\uDC51\uD83D\uDCF8\uD83D\uDE2C\uD83D\uDC40\uD83D\uDEA8\uD83C\uDFE1\uD83D\uDD4A\uFE0F\uD83C\uDFC6\uD83D\uDE3B\uD83C\uDF1F\uD83E\uDDFF\uD83C\uDF40\uD83C\uDFA8\uD83C\uDF5C" } } \ No newline at end of file