MCPcopy Index your code
hub / github.com/processing/processing / parseUnitSize

Method parseUnitSize

core/src/processing/core/PShapeSVG.java:1456–1476  ·  view source on GitHub ↗

Parse a size that may have a suffix for its units. This assumes 90dpi, which implies, as given in the units spec: "1pt" equals "1.25px" (and therefore 1.25 user units) "1pc" equals "15px" (and therefore 15 user units) "1mm" wo

(String text, float relativeTo)

Source from the content-addressed store, hash-verified

1454 * svgXYSize for anything else.
1455 */
1456 static protected float parseUnitSize(String text, float relativeTo) {
1457 int len = text.length() - 2;
1458
1459 if (text.endsWith("pt")) {
1460 return PApplet.parseFloat(text.substring(0, len)) * 1.25f;
1461 } else if (text.endsWith("pc")) {
1462 return PApplet.parseFloat(text.substring(0, len)) * 15;
1463 } else if (text.endsWith("mm")) {
1464 return PApplet.parseFloat(text.substring(0, len)) * 3.543307f;
1465 } else if (text.endsWith("cm")) {
1466 return PApplet.parseFloat(text.substring(0, len)) * 35.43307f;
1467 } else if (text.endsWith("in")) {
1468 return PApplet.parseFloat(text.substring(0, len)) * 90;
1469 } else if (text.endsWith("px")) {
1470 return PApplet.parseFloat(text.substring(0, len));
1471 } else if (text.endsWith("%")) {
1472 return relativeTo * parseFloatOrPercent(text);
1473 } else {
1474 return PApplet.parseFloat(text);
1475 }
1476 }
1477
1478
1479 static protected float parseFloatOrPercent(String text) {

Callers 3

PShapeSVGMethod · 0.95
setStrokeWeightMethod · 0.95
getFloatWithUnitMethod · 0.95

Calls 2

parseFloatMethod · 0.95
parseFloatOrPercentMethod · 0.95

Tested by

no test coverage detected