fun strokePaint()

in platf-skia/src/commonMain/kotlin/org/jetbrains/letsPlot/skia/shape/Util.kt [155:179]


fun strokePaint(
    stroke: Color4f? = null,
    strokeWidth: Float = 1f,
    strokeOpacity: Float = 1f,
    strokeDashArray: List<Float>? = null,
    strokeDashOffset: Float = 0f, // not mandatory, default works fine
    strokeMiter: Float? = null
) : Paint? {
    if (stroke == null) return null
    if (strokeOpacity == 0f) return null

    if (strokeWidth == 0f) {
        // Handle zero width manually, because Skia threatens 0 as "hairline" width, i.e. 1 pixel.
        // Source: https://api.skia.org/classSkPaint.html#af08c5bc138e981a4e39ad1f9b165c32c
        return null
    }

    val paint = Paint()
    paint.setStroke(true)
    paint.color4f = stroke.withA(strokeOpacity)
    paint.strokeWidth = strokeWidth
    strokeMiter?.let { paint.strokeMiter = it }
    strokeDashArray?.let { paint.pathEffect = makeDash(it.toFloatArray(), strokeDashOffset) }
    return paint
}