Skip to content

Commit 46c9078

Browse files
committed
use Map in appropriate places, use Dict classes in others
1 parent e435956 commit 46c9078

1 file changed

Lines changed: 61 additions & 34 deletions

File tree

core/src/processing/core/PShapeSVG.java

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.awt.image.ColorModel;
3636
import java.awt.image.Raster;
3737
import java.awt.image.WritableRaster;
38+
import java.util.Map;
3839
import java.util.HashMap;
3940

4041

@@ -1351,7 +1352,8 @@ void setColor(String colorText, boolean isFill) {
13511352
*/
13521353
static protected int parseSimpleColor(String colorText) {
13531354
colorText = colorText.toLowerCase().trim();
1354-
if (colorNames.containsKey(colorText)) {
1355+
//if (colorNames.containsKey(colorText)) {
1356+
if (colorNames.hasKey(colorText)) {
13551357
return colorNames.get(colorText);
13561358
} else if (colorText.startsWith("#")) {
13571359
if (colorText.length() == 4) {
@@ -1373,29 +1375,49 @@ static protected int parseSimpleColor(String colorText) {
13731375
* Deliberately conforms to HTML 4.01 color spec + en-gb grey,
13741376
* not SVG's 147-color system.
13751377
*/
1376-
static protected HashMap<String, Integer> colorNames;
1377-
1378+
static protected IntDict colorNames = new IntDict(new Object[][] {
1379+
{ "aqua", 0x00ffff },
1380+
{ "black", 0x000000 },
1381+
{ "blue", 0x0000ff },
1382+
{ "fuchsia", 0xff00ff },
1383+
{ "gray", 0x808080 },
1384+
{ "grey", 0x808080 },
1385+
{ "green", 0x008000 },
1386+
{ "lime", 0x00ff00 },
1387+
{ "maroon", 0x800000 },
1388+
{ "navy", 0x000080 },
1389+
{ "olive", 0x808000 },
1390+
{ "purple", 0x800080 },
1391+
{ "red", 0xff0000 },
1392+
{ "silver", 0xc0c0c0 },
1393+
{ "teal", 0x008080 },
1394+
{ "white", 0xffffff },
1395+
{ "yellow", 0xffff00 }
1396+
});
1397+
1398+
/*
1399+
static protected Map<String, Integer> colorNames;
13781400
static {
13791401
colorNames = new HashMap<String, Integer>();
1380-
colorNames.put("aqua", 0x00ffff);
1381-
colorNames.put("black", 0x000000);
1382-
colorNames.put("blue", 0x0000ff);
1383-
colorNames.put("fuchsia", 0xff00ff);
1384-
colorNames.put("gray", 0x808080);
1385-
colorNames.put("grey", 0x808080);
1386-
colorNames.put("green", 0x008000);
1387-
colorNames.put("lime", 0x00ff00);
1388-
colorNames.put("maroon", 0x800000);
1389-
colorNames.put("navy", 0x000080);
1390-
colorNames.put("olive", 0x808000);
1391-
colorNames.put("purple", 0x800080);
1392-
colorNames.put("red", 0xff0000);
1393-
colorNames.put("silver", 0xc0c0c0);
1394-
colorNames.put("teal", 0x008080);
1395-
colorNames.put("white", 0xffffff);
1396-
colorNames.put("yellow", 0xffff00);
1402+
colorNames.put("aqua", 0x00ffff);
1403+
colorNames.put("black", 0x000000);
1404+
colorNames.put("blue", 0x0000ff);
1405+
colorNames.put("fuchsia", 0xff00ff);
1406+
colorNames.put("gray", 0x808080);
1407+
colorNames.put("grey", 0x808080);
1408+
colorNames.put("green", 0x008000);
1409+
colorNames.put("lime", 0x00ff00);
1410+
colorNames.put("maroon", 0x800000);
1411+
colorNames.put("navy", 0x000080);
1412+
colorNames.put("olive", 0x808000);
1413+
colorNames.put("purple", 0x800080);
1414+
colorNames.put("red", 0xff0000);
1415+
colorNames.put("silver", 0xc0c0c0);
1416+
colorNames.put("teal", 0x008080);
1417+
colorNames.put("white", 0xffffff);
1418+
colorNames.put("yellow", 0xffff00);
13971419
}
1398-
1420+
*/
13991421

14001422
static protected int parseRGB(String what) {
14011423
int leftParen = what.indexOf('(') + 1;
@@ -1419,14 +1441,18 @@ static protected int parseRGB(String what) {
14191441
}
14201442

14211443

1422-
static protected HashMap<String, String> parseStyleAttributes(String style) {
1423-
HashMap<String, String> table = new HashMap<String, String>();
1424-
if (style == null) return table;
1425-
1426-
String[] pieces = style.split(";");
1427-
for (int i = 0; i < pieces.length; i++) {
1428-
String[] parts = pieces[i].split(":");
1429-
table.put(parts[0], parts[1]);
1444+
//static protected Map<String, String> parseStyleAttributes(String style) {
1445+
static protected StringDict parseStyleAttributes(String style) {
1446+
//Map<String, String> table = new HashMap<String, String>();
1447+
StringDict table = new StringDict();
1448+
// if (style == null) return table;
1449+
if (style != null) {
1450+
String[] pieces = style.split(";");
1451+
for (int i = 0; i < pieces.length; i++) {
1452+
String[] parts = pieces[i].split(":");
1453+
//table.put(parts[0], parts[1]);
1454+
table.set(parts[0], parts[1]);
1455+
}
14301456
}
14311457
return table;
14321458
}
@@ -1522,7 +1548,8 @@ public Gradient(PShapeSVG parent, XML properties) {
15221548
offset[count] = parseFloatOrPercent(offsetAttr);
15231549

15241550
String style = elem.getString("style");
1525-
HashMap<String, String> styles = parseStyleAttributes(style);
1551+
//Map<String, String> styles = parseStyleAttributes(style);
1552+
StringDict styles = parseStyleAttributes(style);
15261553

15271554
String colorStr = styles.get("stop-color");
15281555
if (colorStr == null) {
@@ -1891,8 +1918,8 @@ protected void styles(PGraphics g) {
18911918
public static class Font extends PShapeSVG {
18921919
public FontFace face;
18931920

1894-
public HashMap<String,FontGlyph> namedGlyphs;
1895-
public HashMap<Character,FontGlyph> unicodeGlyphs;
1921+
public Map<String, FontGlyph> namedGlyphs;
1922+
public Map<Character, FontGlyph> unicodeGlyphs;
18961923

18971924
public int glyphCount;
18981925
public FontGlyph[] glyphs;
@@ -1909,8 +1936,8 @@ public Font(PShapeSVG parent, XML properties) {
19091936

19101937
horizAdvX = properties.getInt("horiz-adv-x", 0);
19111938

1912-
namedGlyphs = new HashMap<String,FontGlyph>();
1913-
unicodeGlyphs = new HashMap<Character,FontGlyph>();
1939+
namedGlyphs = new HashMap<String, FontGlyph>();
1940+
unicodeGlyphs = new HashMap<Character, FontGlyph>();
19141941
glyphCount = 0;
19151942
glyphs = new FontGlyph[elements.length];
19161943

0 commit comments

Comments
 (0)