Add string export

This commit is contained in:
Alexander Nozik 2022-10-09 13:48:19 +03:00
parent 28663a010d
commit 77e27c7eb6
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357

View File

@ -26,13 +26,12 @@ fun SchemeFeaturesState.snapshot(): FeatureStateSnapshot =
features(), features(),
features().values.filterIsInstance<PainterFeature>().associateWith { it.painter() }) features().values.filterIsInstance<PainterFeature>().associateWith { it.painter() })
fun FeatureStateSnapshot.generateSvg(
fun FeatureStateSnapshot.exportToSvg(
viewPoint: SchemeViewPoint, viewPoint: SchemeViewPoint,
width: Double, width: Double,
height: Double, height: Double,
path: java.nio.file.Path, id: String? = null
) { ): String{
fun SchemeCoordinates.toOffset(): Offset = Offset( fun SchemeCoordinates.toOffset(): Offset = Offset(
(width / 2 + (x - viewPoint.focus.x) * viewPoint.scale).toFloat(), (width / 2 + (x - viewPoint.focus.x) * viewPoint.scale).toFloat(),
@ -132,6 +131,17 @@ fun FeatureStateSnapshot.exportToSvg(
drawFeature(viewPoint.scale, feature) drawFeature(viewPoint.scale, feature)
} }
} }
return svgGraphics2D.getSVGElement(id)
SVGUtils.writeToSVG(path.toFile(), svgGraphics2D.svgElement) }
fun FeatureStateSnapshot.exportToSvg(
viewPoint: SchemeViewPoint,
width: Double,
height: Double,
path: java.nio.file.Path,
) {
val svgString = generateSvg(viewPoint, width, height)
SVGUtils.writeToSVG(path.toFile(), svgString)
} }