override fun setAttribute()

in platf-skia/src/commonMain/kotlin/org/jetbrains/letsPlot/skia/mapping/svg/attr/SvgTSpanElementAttrMapping.kt [18:61]


    override fun setAttribute(target: TSpan, name: String, value: Any?) {
        when (name) {
            SvgShape.FILL.name -> target.fill = toColor(value)
            //SvgShape.FILL_OPACITY.name -> target.fillOpacity = value!!.asFloat
            SvgShape.STROKE.name -> target.stroke = toColor(value)
            //SvgShape.STROKE_OPACITY.name -> target.strokeOpacity = value!!.asFloat
            SvgShape.STROKE_WIDTH.name -> target.strokeWidth = value!!.asFloat
            "font-size" -> {
                require(value is String) { "font-size: only string value is supported" }
                target.fontScale = when {
                    "em" in value -> value.removeSuffix("em").toFloat()
                    "%" in value -> value.removeSuffix("%").toFloat() / 100.0f
                    else -> 1f
                }
            }
            "font-family" -> target.fontFamily = value?.asFontFamily ?: DEFAULT_FONT_FAMILY

            "baseline-shift" -> target.baselineShift = when (value) {
                "sub" -> BaselineShift.SUB
                "super" -> BaselineShift.SUPER
                else -> error("Unexpected baseline-shift value: $value")
            }

            "font-style" -> target.fontSlant = when(value) {
                "italic" -> FontSlant.ITALIC
                else -> FontSlant.UPRIGHT // normal and others
            }

            "font-weight" -> target.fontWeight = when(value) {
                "bold" -> FontWeight.BOLD
                else -> FontWeight.NORMAL // normal and others
            }

            "dy" -> {
                require(value is String) { "dy: only string value is supported" }
                target.dy = when {
                    "em" in value -> value.removeSuffix("em").toFloat()
                    "%" in value -> value.removeSuffix("%").toFloat() / 100.0f
                    else -> 0f
                }
            }
            else -> super.setAttribute(target, name, value)
        }
    }