Skip to content

Commit ab6cd9f

Browse files
committed
additional cleanup to SVG code after incorporating #4168
1 parent f82e703 commit ab6cd9f

4 files changed

Lines changed: 96 additions & 97 deletions

File tree

core/src/processing/core/PShape.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,13 @@
2525
import java.awt.Image;
2626
import java.awt.color.ColorSpace;
2727
import java.awt.image.BufferedImage;
28-
import java.io.IOException;
29-
import java.nio.charset.Charset;
30-
import java.nio.file.Files;
31-
import java.nio.file.Paths;
3228
import java.util.HashMap;
3329
import java.util.Map;
34-
import java.util.Base64.Decoder;
35-
import java.util.logging.Level;
36-
import java.util.logging.Logger;
37-
import java.nio.charset.StandardCharsets;
30+
3831
import javax.swing.ImageIcon;
3932
import javax.xml.bind.DatatypeConverter;
4033

4134

42-
43-
import processing.core.PApplet;
44-
45-
4635
/**
4736
* ( begin auto-generated from PShape.xml )
4837
*
@@ -1910,7 +1899,7 @@ private void loadImage(PGraphics g){
19101899
}
19111900
this.imagePath = null;
19121901
}
1913-
1902+
19141903
private void loadFileSystemImage(PGraphics g){
19151904
imagePath = imagePath.substring(7);
19161905
PImage loadedImage = g.parent.loadImage(imagePath);
@@ -1932,7 +1921,7 @@ private void loadBase64Image(){
19321921
System.err.println("Decode Error on image: " + imagePath.substring(0, 20));
19331922
return;
19341923
}
1935-
1924+
19361925
Image awtImage = new ImageIcon(decodedBytes).getImage();
19371926

19381927
if (awtImage instanceof BufferedImage) {
@@ -1953,7 +1942,7 @@ private void loadBase64Image(){
19531942
extension.equals("unknown")) {
19541943
loadedImage.checkAlpha();
19551944
}
1956-
1945+
19571946
setTexture(loadedImage);
19581947
}
19591948

core/src/processing/core/PShapeSVG.java

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ protected PShape parseChild(XML elem) {
334334
} else if (name.equals("rect")) {
335335
shape = createShape(this, elem, true);
336336
shape.parseRect();
337-
337+
338338
} else if (name.equals("image")) {
339339
shape = createShape(this, elem, true);
340340
shape.parseImage();
@@ -368,8 +368,8 @@ protected PShape parseChild(XML elem) {
368368

369369
} else if (name.equals("text")) { // || name.equals("font")) {
370370
return new Text(this, elem);
371-
372-
} else if (name.equals("tspan")) {
371+
372+
} else if (name.equals("tspan")) {
373373
return new LineOfText(this, elem);
374374

375375
} else if (name.equals("filter")) {
@@ -450,8 +450,8 @@ protected void parseRect() {
450450
getFloatWithUnit(element, "height", svgHeight)
451451
};
452452
}
453-
454-
453+
454+
455455
protected void parseImage() {
456456
kind = RECT;
457457
textureMode = NORMAL;
@@ -466,7 +466,7 @@ protected void parseImage() {
466466

467467
this.imagePath = element.getString("xlink:href");
468468
}
469-
469+
470470
/**
471471
* Parse a polyline or polygon from an SVG file.
472472
* Syntax defined at http://www.w3.org/TR/SVG/shapes.html#PointsBNF
@@ -1537,7 +1537,10 @@ public Gradient(PShapeSVG parent, XML properties) {
15371537
}
15381538

15391539

1540-
public class LinearGradient extends Gradient {
1540+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1541+
1542+
1543+
static public class LinearGradient extends Gradient {
15411544
public float x1, y1, x2, y2;
15421545

15431546
public LinearGradient(PShapeSVG parent, XML properties) {
@@ -1567,7 +1570,10 @@ public LinearGradient(PShapeSVG parent, XML properties) {
15671570
}
15681571

15691572

1570-
public class RadialGradient extends Gradient {
1573+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1574+
1575+
1576+
static public class RadialGradient extends Gradient {
15711577
public float cx, cy, r;
15721578

15731579
public RadialGradient(PShapeSVG parent, XML properties) {
@@ -1596,23 +1602,22 @@ public RadialGradient(PShapeSVG parent, XML properties) {
15961602

15971603

15981604
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1599-
1600-
public static float TEXT_QUALITY = 1;
1601-
protected PFont parseFont(XML properties) {
16021605

1603-
// FontFace fontFace = new FontFace(this, properties);
1606+
1607+
// static private float TEXT_QUALITY = 1;
1608+
1609+
static private PFont parseFont(XML properties) {
16041610
String fontFamily = null;
16051611
float size = 10;
16061612
int weight = PLAIN; // 0
16071613
int italic = 0;
1608-
1614+
16091615
if (properties.hasAttribute("style")) {
16101616
String styleText = properties.getString("style");
16111617
String[] styleTokens = PApplet.splitTokens(styleText, ";");
16121618

16131619
//PApplet.println(styleTokens);
16141620
for (int i = 0; i < styleTokens.length; i++) {
1615-
16161621
String[] tokens = PApplet.splitTokens(styleTokens[i], ":");
16171622
//PApplet.println(tokens);
16181623

@@ -1628,13 +1633,13 @@ protected PFont parseFont(XML properties) {
16281633
// setFillOpacity(tokens[1]);
16291634

16301635
} else if (tokens[0].equals("font-weight")) {
1631-
// PApplet.println("font-weight: " + tokens[1]);
1632-
1633-
if (tokens[1].contains("bold")) {
1634-
weight = BOLD;
1635-
// PApplet.println("Bold weight ! ");
1636-
}
1637-
1636+
// PApplet.println("font-weight: " + tokens[1]);
1637+
1638+
if (tokens[1].contains("bold")) {
1639+
weight = BOLD;
1640+
// PApplet.println("Bold weight ! ");
1641+
}
1642+
16381643

16391644
} else if (tokens[0].equals("font-stretch")) {
16401645
// not supported.
@@ -1673,25 +1678,26 @@ protected PFont parseFont(XML properties) {
16731678
if (fontFamily == null) {
16741679
return null;
16751680
}
1676-
size = size * TEXT_QUALITY;
1681+
// size = size * TEXT_QUALITY;
16771682

16781683
return createFont(fontFamily, weight | italic, size, true);
16791684
}
16801685

1681-
protected PFont createFont(String name, int weight, float size, boolean smooth) {
1682-
1683-
// System.out.println("Try to create a font of " + name + " family, " + weight);
1684-
java.awt.Font baseFont = new java.awt.Font(name, weight, (int) size); // PFont.findFont(name);ç
16851686

1686-
// System.out.println("Resulting family : " + baseFont.getFamily() + " " + baseFont.getStyle());
1687-
PFont outputPFont = new PFont(baseFont.deriveFont(size), smooth, null);
1687+
static protected PFont createFont(String name, int weight,
1688+
float size, boolean smooth) {
1689+
//System.out.println("Try to create a font of " + name + " family, " + weight);
1690+
java.awt.Font baseFont = new java.awt.Font(name, weight, (int) size);
16881691

1689-
// System.out.println("Resulting PFont family : " + outputPFont.getName());
1690-
return outputPFont;
1692+
//System.out.println("Resulting family : " + baseFont.getFamily() + " " + baseFont.getStyle());
1693+
return new PFont(baseFont.deriveFont(size), smooth, null);
16911694
}
16921695

1693-
public static class Text extends PShapeSVG {
16941696

1697+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1698+
1699+
1700+
static public class Text extends PShapeSVG {
16951701
protected PFont font;
16961702

16971703
public Text(PShapeSVG parent, XML properties) {
@@ -1709,43 +1715,40 @@ public Text(PShapeSVG parent, XML properties) {
17091715
family = GROUP;
17101716

17111717
font = parseFont(properties);
1712-
17131718
}
1714-
1715-
// @Override
1716-
// public void drawImpl(PGraphics g){
1717-
// }
17181719
}
17191720

1720-
public static class LineOfText extends PShapeSVG {
17211721

1722+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1723+
1724+
1725+
static public class LineOfText extends PShapeSVG {
17221726
String textToDisplay;
17231727
PFont font;
17241728

17251729
public LineOfText(PShapeSVG parent, XML properties) {
1726-
1727-
// TODO: child should ideally be parsed too...
1728-
// for inline content.
1730+
// TODO: child should ideally be parsed too for inline content.
17291731
super(parent, properties, false);
17301732

1731-
// // get location
1733+
//get location
17321734
float x = Float.parseFloat(properties.getString("x"));
17331735
float y = Float.parseFloat(properties.getString("y"));
17341736

17351737
float parentX = Float.parseFloat(parent.element.getString("x"));
17361738
float parentY = Float.parseFloat(parent.element.getString("y"));
1737-
1739+
17381740
if (matrix == null) matrix = new PMatrix2D();
17391741
matrix.translate(x - parentX, (y - parentY) / 2f);
1740-
1741-
// get the first properties
1742-
parseColors(properties);
1742+
1743+
// get the first properties
1744+
parseColors(properties);
17431745
font = parseFont(properties);
17441746

1745-
// It is a line..
1746-
boolean isALine = properties.getString("role") == "line";
1747-
// NO inline content yet.
1747+
// cleaned up syntax but removing b/c unused [fry 190118]
1748+
//boolean isLine = properties.getString("role").equals("line");
1749+
17481750
if (this.childCount > 0) {
1751+
// no inline content yet.
17491752
}
17501753

17511754
String text = properties.getContent();
@@ -1762,14 +1765,18 @@ public void drawImpl(PGraphics g) {
17621765
}
17631766

17641767
pre(g);
1765-
g.textFont(font, font.size / TEXT_QUALITY);
1768+
// g.textFont(font, font.size / TEXT_QUALITY);
1769+
g.textFont(font, font.size);
17661770
g.text(textToDisplay, 0, 0);
17671771
post(g);
17681772
}
1769-
17701773
}
1771-
1772-
public static class Font extends PShapeSVG {
1774+
1775+
1776+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1777+
1778+
1779+
static public class Font extends PShapeSVG {
17731780
public FontFace face;
17741781

17751782
public Map<String, FontGlyph> namedGlyphs;
@@ -1790,8 +1797,8 @@ public Font(PShapeSVG parent, XML properties) {
17901797

17911798
horizAdvX = properties.getInt("horiz-adv-x", 0);
17921799

1793-
namedGlyphs = new HashMap<String, FontGlyph>();
1794-
unicodeGlyphs = new HashMap<Character, FontGlyph>();
1800+
namedGlyphs = new HashMap<>();
1801+
unicodeGlyphs = new HashMap<>();
17951802
glyphCount = 0;
17961803
glyphs = new FontGlyph[elements.length];
17971804

@@ -1920,7 +1927,7 @@ protected void drawShape() {
19201927
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19211928

19221929

1923-
public static class FontGlyph extends PShapeSVG { // extends Path
1930+
static public class FontGlyph extends PShapeSVG { // extends Path
19241931
public String name;
19251932
char unicode;
19261933
int horizAdvX;

core/todo.txt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ X had to back this fix out again
1111
X Fixes blend mode not being set correctly, fixing #5645
1212
X https://github.com/processing/processing/issues/5645
1313
X https://github.com/processing/processing/pull/5647
14-
_ NullPointerException in Contribution Manager
15-
_ https://github.com/processing/processing/issues/5524
16-
_ https://github.com/processing/processing/pull/5742
14+
X extended SVG support
15+
X https://github.com/processing/processing/pull/4168
1716

1817
gohai
1918
X Profile GL3bc is not available on X11GraphicsDevice
@@ -47,6 +46,11 @@ X https://github.com/processing/processing/pull/5698
4746
X Recreate FBOs when offscreen PGraphicsOpenGL is resized
4847
X https://github.com/processing/processing/pull/5699
4948

49+
cleaning
50+
o WARNING: GL pipe is running in software mode (Renderer ID=0x1020400)
51+
o is this coming from us? if so, need to provide actions
52+
X haven't seen for a while, maybe fixed
53+
5054

5155
_ NullPointerException at java.awt.Window.init(Window.java:497) when using Airplay
5256
_ https://github.com/processing/processing/issues/5620
@@ -72,8 +76,6 @@ _ create icon.png or have an 'icons' folder with multiple sizes
7276

7377

7478
contribs
75-
_ extended SVG support
76-
_ https://github.com/processing/processing/pull/4168
7779
_ show a warning when a font isn't what the user expected
7880
_ https://github.com/processing/processing/issues/5481
7981
_ https://github.com/processing/processing/pull/5605
@@ -89,20 +91,12 @@ _ Switch to getModifiersEx() and fix the AWT modifiers used in PSurfaceAWT
8991
_ this is an easy fix, but need to check impact elsewhere
9092
_ does anything else rely on these modifiers?
9193

92-
_ Fix Java 9 incompatibilities inside PSurfaceFX
93-
_ https://github.com/processing/processing/issues/5286
94-
95-
_ Hitting ESC in FX2D app on macOS throws IllegalStateException
96-
_ https://github.com/processing/processing/issues/5249
9794

9895
_ when doing createFont, can we add it to the os fonts available?
9996

10097
_ add separator option to loadTable()
10198
_ https://github.com/processing/processing/issues/5068
10299

103-
_ WARNING: GL pipe is running in software mode (Renderer ID=0x1020400)
104-
_ is this coming from us? if so, need to provide actions
105-
106100
_ implement sketch scaling into PApplet
107101
_ https://github.com/processing/processing/issues/4897
108102
_ Sketches on Windows don't take UI sizing into account
@@ -165,6 +159,10 @@ _ https://github.com/processing/processing/issues/3753
165159

166160

167161
javafx
162+
_ Fix Java 11 incompatibilities inside PSurfaceFX
163+
_ https://github.com/processing/processing/issues/5286
164+
_ Hitting ESC in FX2D app on macOS throws IllegalStateException
165+
_ https://github.com/processing/processing/issues/5249
168166
_ wrong window size with fullScreen()
169167
_ https://github.com/processing/processing/issues/4737
170168
_ menu bar not hiding properly in exported applications with FX2D

0 commit comments

Comments
 (0)