Skip to content

Commit

Permalink
update: remove close() & dispose()
Browse files Browse the repository at this point in the history
  • Loading branch information
muedsa committed Jan 12, 2024
1 parent e4d98a2 commit 707fc4a
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 49 deletions.
1 change: 0 additions & 1 deletion src/main/kotlin/com/muedsa/snapshot/Snapshot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class Snapshot(
surface.flush()
image = surface.makeImageSnapshot()
surface.close()
rootWidget.dispose()
isDrawed = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,4 @@ internal class InternalDecorationImagePainter(
canvas.restore()
}
}


override fun dispose() {
if (!details.image.isClosed) {
details.image.close()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)"
}
Expand Down Expand Up @@ -244,7 +239,7 @@ class SimpleTextPainter(
).apply {
layout(minWidth = minWidth, maxWidth = maxWidth)
}
return painter.use { painter.width }
return painter.width
}

@JvmStatic
Expand Down Expand Up @@ -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 =
Expand Down
7 changes: 0 additions & 7 deletions src/main/kotlin/com/muedsa/snapshot/widget/LocalImage.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -36,10 +35,4 @@ open class LocalImage(
colorBlendMode = colorBlendMode
)
}

@MustCallSuper
override fun dispose() {
image.close()
super.dispose()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.muedsa.snapshot.widget

import com.muedsa.snapshot.annotation.MustCallSuper

abstract class MultiChildWidget(
val children: Array<out Widget>?
) : Widget() {
Expand All @@ -12,10 +10,4 @@ abstract class MultiChildWidget(
it.parent = this
}
}

@MustCallSuper
override fun dispose() {
children?.forEach { it.dispose() }
super.dispose()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.muedsa.snapshot.widget

import com.muedsa.snapshot.annotation.MustCallSuper

abstract class SingleChildWidget(
val child: Widget?
) : Widget() {
Expand All @@ -13,10 +11,4 @@ abstract class SingleChildWidget(
it.parent = this
}
}

@MustCallSuper
override fun dispose() {
child?.dispose()
super.dispose()
}
}
4 changes: 0 additions & 4 deletions src/main/kotlin/com/muedsa/snapshot/widget/Widget.kt
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -16,7 +15,4 @@ abstract class Widget {
}

abstract fun createRenderTree(): RenderBox

@MustCallSuper
open fun dispose() { }
}
16 changes: 16 additions & 0 deletions src/test/kotlin/com/muedsa/snapshot/paint/SimpleTextPainterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 707fc4a

Please sign in to comment.