Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
Force minimum line width of 0.1, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
maltaisn committed Dec 18, 2020
1 parent 0684ddb commit 6b983f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ Here's an example usage of options:
-p 3 -e parametric --transform="translate(10 10) rotate(30) skewX(10)" --latex --lenient
```

If using the style script, the stroke width will most likely have to be tuned manually.
This is because Desmos doesn't have an absolute stroke width, but rather the width is kept the same for
all zoom levels. Therefore, the width must be adjusted for whatever zoom level will be used to view.
Also note that the script can only set widths ranging from 0.1 to 25.5.

#### Current limitations
- The only supported tag is `path`, and the only supported attributes are `d`, `transform`, `opacity`,
`stroke-opacity`, `stroke` and `stroke-width`. Make sure to manually check your SVG file content before
Expand Down
15 changes: 10 additions & 5 deletions app/src/main/kotlin/com/maltaisn/svgequations/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ fun main(args: Array<String>) {
val tokens = pathTokenizer.tokenize(it.path)
val curves = pathParser.parse(tokens)
val color = colorParser.parse(it.color, it.opacity)
val width = if (it.width != null) {
(it.width.toDoubleOrNull() ?: parseError("Invalid stroke width")) * params.lineWidthMult
} else {
2.5 // default width
}
val width = parsePathWidth(it.width, params.lineWidthMult)
val transform = if (it.transform != null) {
transformParser.parse(it.transform)
} else {
Expand Down Expand Up @@ -132,3 +128,12 @@ fun main(args: Array<String>) {
}

}

private fun parsePathWidth(width: String?, mult: Double) =
if (width != null) {
// Parse line width. Force a minimum of 0.1 to avoid making lines invisible.
((width.toDoubleOrNull() ?: parseError("Invalid stroke width")) * mult)
.coerceAtLeast(0.1)
} else {
2.5 // default width
}

0 comments on commit 6b983f5

Please sign in to comment.