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

Fixes PolylineShape built from a buildShape { } and/or graphics { } not displaying line dashes #1782

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions korim/src/commonMain/kotlin/korlibs/image/vector/Shape.kt
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,19 @@ data class PolylineShape constructor(
return bounds?.immutable ?: Rectangle.ZERO
}

override fun drawInternal(c: Context2d) {
c.lineScaleMode = strokeInfo.scaleMode
c.lineWidth = strokeInfo.thickness
c.lineCap = strokeInfo.endCap
fun setState(c: Context2d) {
c.lineScaleMode = strokeInfo.scaleMode
c.lineWidth = strokeInfo.thickness
c.startLineCap = strokeInfo.startCap
c.endLineCap = strokeInfo.endCap
c.lineJoin = strokeInfo.join
c.miterLimit = strokeInfo.miterLimit
c.lineDash = strokeInfo.dash
c.lineDashOffset = strokeInfo.dashOffset
}

override fun drawInternal(c: Context2d) {
setState(c)
c.stroke(paint)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import korlibs.io.async.*
import korlibs.math.geom.*
import korlibs.math.geom.vector.*
import korlibs.crypto.encoding.*
import korlibs.image.vector.*
import kotlin.test.*

class Bitmap32Context2dTest {
Expand Down Expand Up @@ -123,6 +124,24 @@ class Bitmap32Context2dTest {
assertEquals(color, bmp.toBMP32()[100, 10])
}
}

@Test
fun testLineDash() = suspendTest {
val shape: Shape = buildShape {
stroke(Colors.WHITE, 4f, lineDash = floatArrayListOf(20f, 10f)) {
line(Point(0, 0), Point(100, 100))
}
}
Bitmap32(100, 100).context2d {
assertEquals(null, this.lineDash)
//this.draw(shape)
(shape as PolylineShape).setState(this)
assertEquals(4f, this.lineWidth)
assertEquals(floatArrayListOf(20f, 10f), this.lineDash)

}
//.showImageAndWait()
}
}


Expand Down