mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
make pixelDensity(displayDensity()) work properly, fixes #3436
This commit is contained in:
@@ -1120,6 +1120,7 @@ public class PApplet implements PConstants {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
// If nobody's density is 1 (or != 2, to be exact) then everyone is 2
|
||||
return 2;
|
||||
}
|
||||
return displayDensity(display);
|
||||
@@ -1153,7 +1154,7 @@ public class PApplet implements PConstants {
|
||||
System.err.println("Only one display is currently known, use displayDensity(1).");
|
||||
} else {
|
||||
System.err.format("Your displays are numbered %d through %d, " +
|
||||
"pass one of those numbers to displayDensity()", 1, devices.length);
|
||||
"pass one of those numbers to displayDensity()%n", 1, devices.length);
|
||||
}
|
||||
throw new RuntimeException("Display " + display + " does not exist.");
|
||||
}
|
||||
|
||||
@@ -329,6 +329,11 @@ public class PdePreprocessor {
|
||||
String[] pixelDensityContents = matchMethod("pixelDensity", searchArea);
|
||||
if (pixelDensityContents != null) {
|
||||
extraStatements.append(pixelDensityContents[0]);
|
||||
} else {
|
||||
pixelDensityContents = matchDensityMess(searchArea);
|
||||
if (pixelDensityContents != null) {
|
||||
extraStatements.append(pixelDensityContents[0]);
|
||||
}
|
||||
}
|
||||
|
||||
String[] sizeContents = matchMethod("size", searchArea);
|
||||
@@ -433,6 +438,13 @@ public class PdePreprocessor {
|
||||
}
|
||||
|
||||
|
||||
static protected String[] matchDensityMess(String searchArea) {
|
||||
final String regexp =
|
||||
"(?:^|\\s|;)pixelDensity\\s*\\(\\s*displayDensity\\s*\\([^\\)]*\\)\\s*\\)\\s*\\;";
|
||||
return PApplet.match(searchArea, regexp);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replace all commented portions of a given String as spaces.
|
||||
* Utility function used here and in the preprocessor.
|
||||
|
||||
Reference in New Issue
Block a user