Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support chained decimals during SVG Parsing #659

Merged
merged 1 commit into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/src/processing/core/PShapeSVG.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ protected void parsePath() {

StringBuilder pathBuffer = new StringBuilder();
boolean lastSeparate = false;
boolean isOnDecimal = false;

for (int i = 0; i < pathDataChars.length; i++) {
char c = pathDataChars[i];
Expand All @@ -539,6 +540,13 @@ protected void parsePath() {
if (c == 'Z' || c == 'z') {
separate = false;
}
if (c == '.' && !isOnDecimal) {
isOnDecimal = true;
}
else if (isOnDecimal && (c < '0' || c > '9')) {
pathBuffer.append("|");
isOnDecimal = c == '.';
}
if (c == '-' && !lastSeparate) {
// allow for 'e' notation in numbers, e.g. 2.10e-9
// https://download.processing.org/bugzilla/1408.html
Expand Down
32 changes: 32 additions & 0 deletions core/test/processing/core/PShapeSVGTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package processing.core;

import org.junit.Assert;
import org.junit.Test;
import processing.data.XML;
import processing.core.PImage;

import java.awt.*;


public class PShapeSVGTest {

private static final String TEST_CONTENT = "<svg><g><path d=\"L 0,3.1.4.1\"/></g></svg>";

@Test
public void testDecimals() {
try {
XML xml = XML.parse(TEST_CONTENT);
PShapeSVG shape = new PShapeSVG(xml);
PShape[] children = shape.getChildren();
Assert.assertEquals(1, children.length);
PShape[] grandchildren = children[0].getChildren();
Assert.assertEquals(1, grandchildren.length);
Assert.assertEquals(0, grandchildren[0].getChildCount());
Assert.assertEquals(2, grandchildren[0].getVertexCount());
}
catch (Exception e) {
Assert.fail("Encountered exception " + e);
}
}

}