propane 3.3.1-java → 3.4.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -1076,41 +1076,39 @@ public class PShapeSVG extends PShape {
1076
1076
  return null;
1077
1077
  }
1078
1078
  float[] m = PApplet.parseFloat(PApplet.splitTokens(pieces[2], ", "));
1079
- if (pieces[1].equals("matrix")) {
1080
- return new PMatrix2D(m[0], m[2], m[4], m[1], m[3], m[5]);
1081
-
1082
- } else if (pieces[1].equals("translate")) {
1083
- float tx = m[0];
1084
- float ty = (m.length == 2) ? m[1] : m[0];
1085
- return new PMatrix2D(1, 0, tx, 0, 1, ty);
1086
-
1087
- } else if (pieces[1].equals("scale")) {
1088
- float sx = m[0];
1089
- float sy = (m.length == 2) ? m[1] : m[0];
1090
- return new PMatrix2D(sx, 0, 0, 0, sy, 0);
1091
-
1092
- } else if (pieces[1].equals("rotate")) {
1093
- float angle = m[0];
1094
-
1095
- if (m.length == 1) {
1096
- float c = PApplet.cos(angle);
1097
- float s = PApplet.sin(angle);
1098
- // SVG version is cos(a) sin(a) -sin(a) cos(a) 0 0
1099
- return new PMatrix2D(c, -s, 0, s, c, 0);
1100
-
1101
- } else if (m.length == 3) {
1102
- PMatrix2D mat = new PMatrix2D(0, 1, m[1], 1, 0, m[2]);
1103
- mat.rotate(m[0]);
1104
- mat.translate(-m[1], -m[2]);
1105
- return mat;
1106
- }
1107
-
1108
- } else if (pieces[1].equals("skewX")) {
1109
- return new PMatrix2D(1, 0, 1, PApplet.tan(m[0]), 0, 0);
1110
-
1111
- } else if (pieces[1].equals("skewY")) {
1112
- return new PMatrix2D(1, 0, 1, 0, PApplet.tan(m[0]), 0);
1113
- }
1079
+ switch (pieces[1]) {
1080
+ case "matrix":
1081
+ return new PMatrix2D(m[0], m[2], m[4], m[1], m[3], m[5]);
1082
+ case "translate":
1083
+ float tx = m[0];
1084
+ float ty = (m.length == 2) ? m[1] : m[0];
1085
+ return new PMatrix2D(1, 0, tx, 0, 1, ty);
1086
+ case "scale":
1087
+ float sx = m[0];
1088
+ float sy = (m.length == 2) ? m[1] : m[0];
1089
+ return new PMatrix2D(sx, 0, 0, 0, sy, 0);
1090
+ case "rotate":
1091
+ float angle = m[0];
1092
+ if (m.length == 1) {
1093
+ float c = PApplet.cos(angle);
1094
+ float s = PApplet.sin(angle);
1095
+ // SVG version is cos(a) sin(a) -sin(a) cos(a) 0 0
1096
+ return new PMatrix2D(c, -s, 0, s, c, 0);
1097
+
1098
+ } else if (m.length == 3) {
1099
+ PMatrix2D mat = new PMatrix2D(0, 1, m[1], 1, 0, m[2]);
1100
+ mat.rotate(m[0]);
1101
+ mat.translate(-m[1], -m[2]);
1102
+ return mat;
1103
+ }
1104
+ break;
1105
+ case "skewX":
1106
+ return new PMatrix2D(1, 0, 1, PApplet.tan(m[0]), 0, 0);
1107
+ case "skewY":
1108
+ return new PMatrix2D(1, 0, 1, 0, PApplet.tan(m[0]), 0);
1109
+ default:
1110
+ break;
1111
+ }
1114
1112
  return null;
1115
1113
  }
1116
1114
 
@@ -1162,41 +1160,41 @@ public class PShapeSVG extends PShape {
1162
1160
  String styleText = properties.getString("style");
1163
1161
  String[] styleTokens = PApplet.splitTokens(styleText, ";");
1164
1162
 
1165
- //PApplet.println(styleTokens);
1166
- for (int i = 0; i < styleTokens.length; i++) {
1167
- String[] tokens = PApplet.splitTokens(styleTokens[i], ":");
1168
- //PApplet.println(tokens);
1169
-
1170
- tokens[0] = PApplet.trim(tokens[0]);
1171
-
1172
- if (tokens[0].equals("fill")) {
1173
- setColor(tokens[1], true);
1174
-
1175
- } else if (tokens[0].equals("fill-opacity")) {
1176
- setFillOpacity(tokens[1]);
1177
-
1178
- } else if (tokens[0].equals("stroke")) {
1179
- setColor(tokens[1], false);
1180
-
1181
- } else if (tokens[0].equals("stroke-width")) {
1182
- setStrokeWeight(tokens[1]);
1183
-
1184
- } else if (tokens[0].equals("stroke-linecap")) {
1185
- setStrokeCap(tokens[1]);
1186
-
1187
- } else if (tokens[0].equals("stroke-linejoin")) {
1188
- setStrokeJoin(tokens[1]);
1189
-
1190
- } else if (tokens[0].equals("stroke-opacity")) {
1191
- setStrokeOpacity(tokens[1]);
1192
-
1193
- } else if (tokens[0].equals("opacity")) {
1194
- setOpacity(tokens[1]);
1195
-
1196
- } else {
1197
- // Other attributes are not yet implemented
1198
- }
1199
- }
1163
+ //PApplet.println(styleTokens);
1164
+ for (var styleToken : styleTokens) {
1165
+ String[] tokens = PApplet.splitTokens(styleToken, ":");
1166
+ //PApplet.println(tokens);
1167
+ tokens[0] = PApplet.trim(tokens[0]);
1168
+ switch (tokens[0]) {
1169
+ case "fill":
1170
+ setColor(tokens[1], true);
1171
+ break;
1172
+ case "fill-opacity":
1173
+ setFillOpacity(tokens[1]);
1174
+ break;
1175
+ case "stroke":
1176
+ setColor(tokens[1], false);
1177
+ break;
1178
+ case "stroke-width":
1179
+ setStrokeWeight(tokens[1]);
1180
+ break;
1181
+ case "stroke-linecap":
1182
+ setStrokeCap(tokens[1]);
1183
+ break;
1184
+ case "stroke-linejoin":
1185
+ setStrokeJoin(tokens[1]);
1186
+ break;
1187
+ case "stroke-opacity":
1188
+ setStrokeOpacity(tokens[1]);
1189
+ break;
1190
+ case "opacity":
1191
+ setOpacity(tokens[1]);
1192
+ break;
1193
+ // Other attributes are not yet implemented
1194
+ default:
1195
+ break;
1196
+ }
1197
+ }
1200
1198
  }
1201
1199
  }
1202
1200
 
@@ -1216,33 +1214,41 @@ public class PShapeSVG extends PShape {
1216
1214
  }
1217
1215
 
1218
1216
  void setStrokeJoin(String linejoin) {
1219
- if (linejoin.equals("inherit")) {
1220
- // do nothing, will inherit automatically
1221
-
1222
- } else if (linejoin.equals("miter")) {
1223
- strokeJoin = PConstants.MITER;
1224
-
1225
- } else if (linejoin.equals("round")) {
1226
- strokeJoin = PConstants.ROUND;
1227
-
1228
- } else if (linejoin.equals("bevel")) {
1229
- strokeJoin = PConstants.BEVEL;
1230
- }
1217
+ switch (linejoin) {
1218
+ // do nothing, will inherit automatically
1219
+ case "inherit":
1220
+ break;
1221
+ case "miter":
1222
+ strokeJoin = PConstants.MITER;
1223
+ break;
1224
+ case "round":
1225
+ strokeJoin = PConstants.ROUND;
1226
+ break;
1227
+ case "bevel":
1228
+ strokeJoin = PConstants.BEVEL;
1229
+ break;
1230
+ default:
1231
+ break;
1232
+ }
1231
1233
  }
1232
1234
 
1233
1235
  void setStrokeCap(String linecap) {
1234
- if (linecap.equals("inherit")) {
1235
- // do nothing, will inherit automatically
1236
-
1237
- } else if (linecap.equals("butt")) {
1238
- strokeCap = PConstants.SQUARE;
1239
-
1240
- } else if (linecap.equals("round")) {
1241
- strokeCap = PConstants.ROUND;
1242
-
1243
- } else if (linecap.equals("square")) {
1244
- strokeCap = PConstants.PROJECT;
1245
- }
1236
+ switch (linecap) {
1237
+ // do nothing, will inherit automatically
1238
+ case "inherit":
1239
+ break;
1240
+ case "butt":
1241
+ strokeCap = PConstants.SQUARE;
1242
+ break;
1243
+ case "round":
1244
+ strokeCap = PConstants.ROUND;
1245
+ break;
1246
+ case "square":
1247
+ strokeCap = PConstants.PROJECT;
1248
+ break;
1249
+ default:
1250
+ break;
1251
+ }
1246
1252
  }
1247
1253
 
1248
1254
  void setFillOpacity(String opacityText) {
@@ -1394,11 +1400,11 @@ public class PShapeSVG extends PShape {
1394
1400
  // if (style == null) return table;
1395
1401
  if (style != null) {
1396
1402
  String[] pieces = style.split(";");
1397
- for (int i = 0; i < pieces.length; i++) {
1398
- String[] parts = pieces[i].split(":");
1399
- //table.put(parts[0], parts[1]);
1400
- table.set(parts[0], parts[1]);
1401
- }
1403
+ for (String piece : pieces) {
1404
+ String[] parts = piece.split(":");
1405
+ //table.put(parts[0], parts[1]);
1406
+ table.set(parts[0], parts[1]);
1407
+ }
1402
1408
  }
1403
1409
  return table;
1404
1410
  }
@@ -1482,38 +1488,37 @@ public class PShapeSVG extends PShape {
1482
1488
  offset = new float[elements.length];
1483
1489
  color = new int[elements.length];
1484
1490
 
1485
- // <stop offset="0" style="stop-color:#967348"/>
1486
- for (int i = 0; i < elements.length; i++) {
1487
- XML elem = elements[i];
1488
- String name = elem.getName();
1489
- if (name.equals("stop")) {
1490
- String offsetAttr = elem.getString("offset");
1491
- offset[count] = parseFloatOrPercent(offsetAttr);
1492
-
1493
- String style = elem.getString("style");
1494
- //Map<String, String> styles = parseStyleAttributes(style);
1495
- StringDict styles = parseStyleAttributes(style);
1496
-
1497
- String colorStr = styles.get("stop-color");
1498
- if (colorStr == null) {
1499
- colorStr = elem.getString("stop-color");
1500
- if (colorStr == null) {
1501
- colorStr = "#000000";
1502
- }
1503
- }
1504
- String opacityStr = styles.get("stop-opacity");
1505
- if (opacityStr == null) {
1506
- opacityStr = elem.getString("stop-opacity");
1507
- if (opacityStr == null) {
1508
- opacityStr = "1";
1509
- }
1510
- }
1511
- int tupacity = PApplet.constrain(
1512
- (int) (PApplet.parseFloat(opacityStr) * 255), 0, 255);
1513
- color[count] = (tupacity << 24) | parseSimpleColor(colorStr);
1514
- count++;
1491
+ // <stop offset="0" style="stop-color:#967348"/>
1492
+ for (XML elem : elements) {
1493
+ String name = elem.getName();
1494
+ if (name.equals("stop")) {
1495
+ String offsetAttr = elem.getString("offset");
1496
+ offset[count] = parseFloatOrPercent(offsetAttr);
1497
+
1498
+ String style = elem.getString("style");
1499
+ //Map<String, String> styles = parseStyleAttributes(style);
1500
+ StringDict styles = parseStyleAttributes(style);
1501
+
1502
+ String colorStr = styles.get("stop-color");
1503
+ if (colorStr == null) {
1504
+ colorStr = elem.getString("stop-color");
1505
+ if (colorStr == null) {
1506
+ colorStr = "#000000";
1507
+ }
1508
+ }
1509
+ String opacityStr = styles.get("stop-opacity");
1510
+ if (opacityStr == null) {
1511
+ opacityStr = elem.getString("stop-opacity");
1512
+ if (opacityStr == null) {
1513
+ opacityStr = "1";
1515
1514
  }
1515
+ }
1516
+ int tupacity = PApplet.constrain(
1517
+ (int) (PApplet.parseFloat(opacityStr) * 255), 0, 255);
1518
+ color[count] = (tupacity << 24) | parseSimpleColor(colorStr);
1519
+ count++;
1516
1520
  }
1521
+ }
1517
1522
  offset = PApplet.subset(offset, 0, count);
1518
1523
  color = PApplet.subset(color, 0, count);
1519
1524
  }
@@ -1599,37 +1604,40 @@ public class PShapeSVG extends PShape {
1599
1604
 
1600
1605
  horizAdvX = properties.getInt("horiz-adv-x", 0);
1601
1606
 
1602
- namedGlyphs = new HashMap<String, FontGlyph>();
1603
- unicodeGlyphs = new HashMap<Character, FontGlyph>();
1607
+ namedGlyphs = new HashMap<>();
1608
+ unicodeGlyphs = new HashMap<>();
1604
1609
  glyphCount = 0;
1605
1610
  glyphs = new FontGlyph[elements.length];
1606
1611
 
1607
- for (int i = 0; i < elements.length; i++) {
1608
- String name = elements[i].getName();
1609
- XML elem = elements[i];
1610
- if (name == null) {
1611
- // skip it
1612
- } else if (name.equals("glyph")) {
1613
- FontGlyph fg = new FontGlyph(this, elem, this);
1614
- if (fg.isLegit()) {
1615
- if (fg.name != null) {
1616
- namedGlyphs.put(fg.name, fg);
1617
- }
1618
- if (fg.unicode != 0) {
1619
- unicodeGlyphs.put(Character.valueOf(fg.unicode), fg);
1620
- }
1612
+ for (XML element1 : elements) {
1613
+ String name = element1.getName();
1614
+ XML elem = element1;
1615
+ if (null == name) {
1616
+ // skip it
1617
+ } else switch (name) {
1618
+ case "glyph":
1619
+ FontGlyph fg = new FontGlyph(this, elem, this);
1620
+ if (fg.isLegit()) {
1621
+ if (fg.name != null) {
1622
+ namedGlyphs.put(fg.name, fg);
1621
1623
  }
1622
- glyphs[glyphCount++] = fg;
1623
-
1624
- } else if (name.equals("missing-glyph")) {
1625
- // System.out.println("got missing glyph inside <font>");
1626
- missingGlyph = new FontGlyph(this, elem, this);
1627
- } else if (name.equals("font-face")) {
1628
- face = new FontFace(this, elem);
1629
- } else {
1630
- System.err.println("Ignoring " + name + " inside <font>");
1631
- }
1632
- }
1624
+ if (fg.unicode != 0) {
1625
+ unicodeGlyphs.put(fg.unicode, fg);
1626
+ }
1627
+ } glyphs[glyphCount++] = fg;
1628
+ break;
1629
+ case "missing-glyph":
1630
+ // System.out.println("got missing glyph inside <font>");
1631
+ missingGlyph = new FontGlyph(this, elem, this);
1632
+ break;
1633
+ case "font-face":
1634
+ face = new FontFace(this, elem);
1635
+ break;
1636
+ default:
1637
+ System.err.println("Ignoring " + name + " inside <font>");
1638
+ break;
1639
+ }
1640
+ }
1633
1641
  }
1634
1642
 
1635
1643
  protected void drawShape() {
@@ -1648,7 +1656,7 @@ public class PShapeSVG extends PShape {
1648
1656
  char[] c = str.toCharArray();
1649
1657
  for (int i = 0; i < c.length; i++) {
1650
1658
  // call draw on each char (pulling it w/ the unicode table)
1651
- FontGlyph fg = unicodeGlyphs.get(Character.valueOf(c[i]));
1659
+ FontGlyph fg = unicodeGlyphs.get(c[i]);
1652
1660
  if (fg != null) {
1653
1661
  fg.draw(g);
1654
1662
  // add horizAdvX/unitsPerEm to the x coordinate along the way
@@ -1665,7 +1673,7 @@ public class PShapeSVG extends PShape {
1665
1673
  float s = size / face.unitsPerEm;
1666
1674
  g.translate(x, y);
1667
1675
  g.scale(s, -s);
1668
- FontGlyph fg = unicodeGlyphs.get(Character.valueOf(c));
1676
+ FontGlyph fg = unicodeGlyphs.get(c);
1669
1677
  if (fg != null) {
1670
1678
  g.shape(fg);
1671
1679
  }
@@ -1677,7 +1685,7 @@ public class PShapeSVG extends PShape {
1677
1685
  char[] c = str.toCharArray();
1678
1686
  for (int i = 0; i < c.length; i++) {
1679
1687
  // call draw on each char (pulling it w/ the unicode table)
1680
- FontGlyph fg = unicodeGlyphs.get(Character.valueOf(c[i]));
1688
+ FontGlyph fg = unicodeGlyphs.get(c[i]);
1681
1689
  if (fg != null) {
1682
1690
  w += (float) fg.horizAdvX / face.unitsPerEm;
1683
1691
  }
@@ -55,6 +55,7 @@ public class PSurfaceNone implements PSurface {
55
55
  + getClass().getSimpleName());
56
56
  }
57
57
 
58
+ @Override
58
59
  public Object getNative() {
59
60
  return null;
60
61
  }
@@ -148,15 +149,19 @@ public class PSurfaceNone implements PSurface {
148
149
  // public void blit() {
149
150
  // // TODO Auto-generated method stub
150
151
  // }
152
+ @Override
151
153
  public void setCursor(int kind) {
152
154
  }
153
155
 
156
+ @Override
154
157
  public void setCursor(PImage image, int hotspotX, int hotspotY) {
155
158
  }
156
159
 
160
+ @Override
157
161
  public void showCursor() {
158
162
  }
159
163
 
164
+ @Override
160
165
  public void hideCursor() {
161
166
  }
162
167
 
@@ -165,6 +170,7 @@ public class PSurfaceNone implements PSurface {
165
170
  return new AnimationThread();
166
171
  }
167
172
 
173
+ @Override
168
174
  public void startThread() {
169
175
  if (thread == null) {
170
176
  thread = createThread();
@@ -175,6 +181,7 @@ public class PSurfaceNone implements PSurface {
175
181
  }
176
182
  }
177
183
 
184
+ @Override
178
185
  public boolean stopThread() {
179
186
  if (thread == null) {
180
187
  return false;
@@ -183,11 +190,13 @@ public class PSurfaceNone implements PSurface {
183
190
  return true;
184
191
  }
185
192
 
193
+ @Override
186
194
  public boolean isStopped() {
187
195
  return thread == null || !thread.isAlive();
188
196
  }
189
197
 
190
198
  // sets a flag to pause the thread when ready
199
+ @Override
191
200
  public void pauseThread() {
192
201
  PApplet.debug("PApplet.run() paused, calling object wait...");
193
202
  paused = true;
@@ -208,6 +217,7 @@ public class PSurfaceNone implements PSurface {
208
217
  // PApplet.debug("done with pause");
209
218
  }
210
219
 
220
+ @Override
211
221
  public void resumeThread() {
212
222
  paused = false;
213
223
  synchronized (pauseObject) {