Unverified Commit d9ab6e50 authored by Oleksandr Karpovich's avatar Oleksandr Karpovich Committed by GitHub

Fix SVGLength.withUnit: create a new SVGLength with a `_unit` from the input...

Fix SVGLength.withUnit: create a new SVGLength with a `_unit` from the input and not `this.unit` (#804)
parent c932de4c
......@@ -40,6 +40,6 @@ class SVGLength(val value: Float, val unit: SVGLengthUnit) {
}
fun withUnit(_unit: SVGLengthUnit): SVGLength {
return if (this.unit === _unit) this else SVGLength(value, unit)
return if (this.unit === _unit) this else SVGLength(value, _unit)
}
}
\ No newline at end of file
......@@ -38,11 +38,28 @@ class SvgTest {
require(e.tag == SVGTag.SVG)
e.viewBox = Rect(0f, 1f, 100f, 200f)
assertCloseEnough(Rect(0f, 1f, 100f, 200f), e.viewBox!!)
val aspectRatio = SVGPreserveAspectRatio(SVGPreserveAspectRatioAlign.XMIN_YMIN, SVGPreserveAspectRatioScale.MEET)
val aspectRatio =
SVGPreserveAspectRatio(SVGPreserveAspectRatioAlign.XMIN_YMIN, SVGPreserveAspectRatioScale.MEET)
e.preserveAspectRatio = aspectRatio
assertEquals(aspectRatio, e.preserveAspectRatio)
require(e.getIntrinsicSize(SVGLengthContext(100f, 100f)).x == 300f)
e.viewBox = Rect.makeXYWH(0f, 1f, 2f, 3f)
require(e.viewBox == Rect.makeXYWH(0f, 1f, 2f, 3f))
}
@Test
fun SvgLength() {
val l = SVGLength(123f)
assertEquals(123f, l.value)
assertEquals(SVGLengthUnit.NUMBER, l.unit)
val lpx = l.withUnit(SVGLengthUnit.PX)
assertEquals(123f, lpx.value)
assertEquals(SVGLengthUnit.PX, lpx.unit)
val newLpx = lpx.withValue(321f)
assertEquals(321f, newLpx.value)
assertEquals(SVGLengthUnit.PX, newLpx.unit)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment