Skip to content

Commit 9e08b98

Browse files
committed
make pixelDensity(displayDensity()) work properly, fixes processing#3436
1 parent 741b0de commit 9e08b98

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

core/src/processing/core/PApplet.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,7 @@ public int displayDensity() {
11201120
return 1;
11211121
}
11221122
}
1123+
// If nobody's density is 1 (or != 2, to be exact) then everyone is 2
11231124
return 2;
11241125
}
11251126
return displayDensity(display);
@@ -1153,7 +1154,7 @@ static public int displayDensity(int display) {
11531154
System.err.println("Only one display is currently known, use displayDensity(1).");
11541155
} else {
11551156
System.err.format("Your displays are numbered %d through %d, " +
1156-
"pass one of those numbers to displayDensity()", 1, devices.length);
1157+
"pass one of those numbers to displayDensity()%n", 1, devices.length);
11571158
}
11581159
throw new RuntimeException("Display " + display + " does not exist.");
11591160
}

java/src/processing/mode/java/preproc/PdePreprocessor.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ make sure that it uses numbers (or displayWidth/Height), copy into settings
329329
String[] pixelDensityContents = matchMethod("pixelDensity", searchArea);
330330
if (pixelDensityContents != null) {
331331
extraStatements.append(pixelDensityContents[0]);
332+
} else {
333+
pixelDensityContents = matchDensityMess(searchArea);
334+
if (pixelDensityContents != null) {
335+
extraStatements.append(pixelDensityContents[0]);
336+
}
332337
}
333338

334339
String[] sizeContents = matchMethod("size", searchArea);
@@ -433,6 +438,13 @@ static protected String[] matchMethod(String methodName, String searchArea) {
433438
}
434439

435440

441+
static protected String[] matchDensityMess(String searchArea) {
442+
final String regexp =
443+
"(?:^|\\s|;)pixelDensity\\s*\\(\\s*displayDensity\\s*\\([^\\)]*\\)\\s*\\)\\s*\\;";
444+
return PApplet.match(searchArea, regexp);
445+
}
446+
447+
436448
/**
437449
* Replace all commented portions of a given String as spaces.
438450
* Utility function used here and in the preprocessor.

0 commit comments

Comments
 (0)