MCPcopy Index your code
hub / github.com/benfry/processing4 / parseUnitSize

Method parseUnitSize

core/src/processing/core/PShapeSVG.java:1463–1483  ·  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

1461 * svgXYSize for anything else.
1462 */
1463 static protected float parseUnitSize(String text, float relativeTo) {
1464 int len = text.length() - 2;
1465
1466 if (text.endsWith("pt")) {
1467 return PApplet.parseFloat(text.substring(0, len)) * 1.25f;
1468 } else if (text.endsWith("pc")) {
1469 return PApplet.parseFloat(text.substring(0, len)) * 15;
1470 } else if (text.endsWith("mm")) {
1471 return PApplet.parseFloat(text.substring(0, len)) * 3.543307f;
1472 } else if (text.endsWith("cm")) {
1473 return PApplet.parseFloat(text.substring(0, len)) * 35.43307f;
1474 } else if (text.endsWith("in")) {
1475 return PApplet.parseFloat(text.substring(0, len)) * 90;
1476 } else if (text.endsWith("px")) {
1477 return PApplet.parseFloat(text.substring(0, len));
1478 } else if (text.endsWith("%")) {
1479 return relativeTo * parseFloatOrPercent(text);
1480 } else {
1481 return PApplet.parseFloat(text);
1482 }
1483 }
1484
1485
1486 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