An open API service indexing awesome lists of open source software.

https://github.com/alipsa/gsvg

A Groovy object model for SVG (Scalar Vector Graphics)
https://github.com/alipsa/gsvg

Last synced: 5 months ago
JSON representation

A Groovy object model for SVG (Scalar Vector Graphics)

Awesome Lists containing this project

README

          

![Groovy](https://img.shields.io/badge/groovy-4298B8.svg?style=for-the-badge&logo=apachegroovy&logoColor=white)
[![Maven Central](https://img.shields.io/maven-central/v/se.alipsa.groovy/gsvg.svg?style=for-the-badge)](https://search.maven.org/artifact/se.alipsa.groovy/gsvg)
[![Javadoc](https://javadoc.io/badge2/se.alipsa.groovy/gsvg/javadoc.svg?style=for-the-badge)](https://javadoc.io/doc/se.alipsa.groovy/gsvg)
# Groovy Scalar Vector Graphics (gsvg)

This is an object model to create, parse and manipulate SVG documents for groovy.
If you have groovy in your classpath, you can use it in any JVM language (Java, Scala, etc.).

The goal is to have a simple to use and lightweight library to create SVG documents programmatically or parse existing ones for modification. It supports the SVG 1.1 specification and the SVG 2 draft.

The jvm used should be java 17 or later.

See the test for various ways to create, parse and write SVG

to use it add the following to your Gradle build script
```groovy
implementation("org.apache.groovy:groovy:5.0.3")
implementation("se.alipsa.groovy:gsvg:0.9.0")
```
or if you prefer maven:
```xml


org.apache.groovy
groovy
5.0.3


se.alipsa.groovy
gsvg
0.9.0

```

## Quick start

Create an SVG in code:
```groovy
import se.alipsa.groovy.svg.Svg
import se.alipsa.groovy.svg.io.SvgWriter

def svg = new Svg(200, 120)
svg.addRect(180, 100).x(10).y(10).rx(12).ry(12).fill('#1976d2')
svg.addText('Hello SVG')
.x(30).y(70)
.fill('white')
.fontSize(24)

println SvgWriter.toXmlPretty(svg)
```

Read/parse an existing SVG file and change it:
```groovy
import se.alipsa.groovy.svg.io.SvgReader
import se.alipsa.groovy.svg.io.SvgWriter
import se.alipsa.groovy.svg.Rect

def svg = SvgReader.parse(new File('logo.svg'))
def rects = svg[Rect]
rects.each { it.stroke('red').strokeWidth(2) }

new File('logo-out.svg').text = SvgWriter.toXmlPretty(svg)
```
## Documentation
- [doc](doc/overview.md) for a simple overview of the library structure and usage examples.
- [javadoc](https://javadoc.io/doc/se.alipsa.groovy/gsvg) for full API documentation.
- [benchmarks](doc/benchmarks.md) for performance benchmarks and optimization tips.