| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -257,6 +257,7 @@ public String preprocess(File srcFolder, | |||
| 257 | 257 | } | |
| 258 | 258 | //System.out.format("size() is '%s'%n", info[0]); | |
| 259 | 259 | ||
| 260 | + /* | ||
| 260 | 261 | // Remove the size() statement (will be added back by writeFooter()) | |
| 261 | 262 | if (sizeInfo != null) { | |
| 262 | 263 | String sizeStatement = sizeInfo.getStatement(); | |
@@ -265,7 +266,7 @@ public String preprocess(File srcFolder, | |||
| 265 | 266 | bigCode.delete(index, index + sizeStatement.length()); | |
| 266 | 267 | } | |
| 267 | 268 | } | |
| 268 | - | ||
| 269 | + */ | ||
| 269 | 270 | ||
| 270 | 271 | PreprocessorResult result; | |
| 271 | 272 | try { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -163,10 +163,10 @@ public static enum Mode { | |||
| 163 | 163 | */ | |
| 164 | 164 | // public static final String SIZE_REGEX = | |
| 165 | 165 | // "(?:^|\\s|;)size\\s*\\(\\s*([^\\s,]+)\\s*,\\s*([^\\s,\\)]+)\\s*,?\\s*([^\\)]*)\\s*\\)\\s*\\;"; | |
| 166 | - static private final String SIZE_CONTENTS_REGEX = | ||
| 167 | - "(?:^|\\s|;)size\\s*\\(([^\\)]+)\\)\\s*\\;"; | ||
| 168 | - static private final String FULL_SCREEN_CONTENTS_REGEX = | ||
| 169 | - "(?:^|\\s|;)fullScreen\\s*\\(([^\\)]+)\\)\\s*\\;"; | ||
| 166 | + // static private final String SIZE_CONTENTS_REGEX = | ||
| 167 | + // "(?:^|\\s|;)size\\s*\\(([^\\)]+)\\)\\s*\\;"; | ||
| 168 | + // static private final String FULL_SCREEN_CONTENTS_REGEX = | ||
| 169 | + // "(?:^|\\s|;)fullScreen\\s*\\(([^\\)]+)\\)\\s*\\;"; | ||
| 170 | 170 | // /** Test whether there's a void somewhere (the program has functions). */ | |
| 171 | 171 | // static private final String VOID_REGEX = | |
| 172 | 172 | // "(?:^|\\s|;)void\\s"; | |
@@ -208,9 +208,11 @@ public SurfaceInfo initSketchSize(String code, | |||
| 208 | 208 | } | |
| 209 | 209 | ||
| 210 | 210 | ||
| 211 | - // break on commas, except those inside quotes, e.g.: | ||
| 212 | - // size(300, 200, PDF, "output,weirdname.pdf"); | ||
| 213 | - // no handling for escaped (\") quotes | ||
| 211 | + /** | ||
| 212 | + * Break on commas, except those inside quotes, | ||
| 213 | + * e.g.: size(300, 200, PDF, "output,weirdname.pdf"); | ||
| 214 | + * No special handling implemented for escaped (\") quotes. | ||
| 215 | + */ | ||
| 214 | 216 | static private StringList breakCommas(String contents) { | |
| 215 | 217 | StringList outgoing = new StringList(); | |
| 216 | 218 | ||
@@ -248,7 +250,8 @@ static private StringList breakCommas(String contents) { | |||
| 248 | 250 | ||
| 249 | 251 | /** | |
| 250 | 252 | * Parse a chunk of code and extract the size() command and its contents. | |
| 251 | - * @param code Usually the code from the main tab in the sketch | ||
| 253 | + * Also goes after fullScreen(), smooth(), and noSmooth(). | ||
| 254 | + * @param code The code from the main tab in the sketch | ||
| 252 | 255 | * @param fussy true if it should show an error message if bad size() | |
| 253 | 256 | * @return null if there was an error, otherwise an array (might contain some/all nulls) | |
| 254 | 257 | */ | |
@@ -306,14 +309,28 @@ make sure that it uses numbers (or displayWidth/Height), copy into settings | |||
| 306 | 309 | searchArea = sb.toString(); | |
| 307 | 310 | } | |
| 308 | 311 | ||
| 309 | - // Get everything inside the parens for the size() method | ||
| 310 | - String[] contents = PApplet.match(searchArea, SIZE_CONTENTS_REGEX); | ||
| 311 | - if (contents != null) { | ||
| 312 | - //String[] matches = split on commas, but not commas inside quotes | ||
| 312 | + // First look for noSmooth() or smooth(N) so we can hoist it into settings. | ||
| 313 | + String smoothStatement = null; | ||
| 314 | + String[] smoothContents = matchMethod("smooth", searchArea); | ||
| 315 | + if (smoothContents != null) { | ||
| 316 | + smoothStatement = smoothContents[0]; | ||
| 317 | + } | ||
| 318 | + String[] noContents = matchMethod("noSmooth", searchArea); | ||
| 319 | + if (noContents != null) { | ||
| 320 | + if (smoothStatement != null) { | ||
| 321 | + throw new SketchException("smooth() and noSmooth() cannot be used in the same sketch"); | ||
| 322 | + } else { | ||
| 323 | + smoothStatement = noContents[0]; | ||
| 324 | + } | ||
| 325 | + } | ||
| 313 | 326 | ||
| 314 | - StringList args = breakCommas(contents[1]); | ||
| 327 | + // Get everything inside the parens for the size() method | ||
| 328 | + //String[] contents = PApplet.match(searchArea, SIZE_CONTENTS_REGEX); | ||
| 329 | + String[] sizeContents = matchMethod("size", searchArea); | ||
| 330 | + if (sizeContents != null) { | ||
| 331 | + StringList args = breakCommas(sizeContents[1]); | ||
| 315 | 332 | SurfaceInfo info = new SurfaceInfo(); | |
| 316 | - info.statement = contents[0]; | ||
| 333 | + info.statement = sizeContents[0]; | ||
| 317 | 334 | info.width = args.get(0).trim(); | |
| 318 | 335 | info.height = args.get(1).trim(); | |
| 319 | 336 | info.renderer = (args.size() >= 3) ? args.get(2).trim() : null; | |
@@ -340,30 +357,69 @@ make sure that it uses numbers (or displayWidth/Height), copy into settings | |||
| 340 | 357 | throw new SketchException("Please fix the size() line to continue.", false); | |
| 341 | 358 | } | |
| 342 | 359 | ||
| 360 | + if (smoothStatement != null) { | ||
| 361 | + info.statement += smoothStatement; | ||
| 362 | + } | ||
| 343 | 363 | info.checkEmpty(); | |
| 344 | 364 | return info; | |
| 345 | 365 | //return new String[] { contents[0], width, height, renderer, path }; | |
| 346 | 366 | } | |
| 347 | 367 | // if no size() found, check for fullScreen() | |
| 348 | - contents = PApplet.match(searchArea, FULL_SCREEN_CONTENTS_REGEX); | ||
| 349 | - if (contents != null) { | ||
| 368 | + //contents = PApplet.match(searchArea, FULL_SCREEN_CONTENTS_REGEX); | ||
| 369 | + String[] fullContents = matchMethod("fullScreen", searchArea); | ||
| 370 | + if (fullContents != null) { | ||
| 350 | 371 | SurfaceInfo info = new SurfaceInfo(); | |
| 351 | - info.statement = contents[0]; | ||
| 352 | - StringList args = breakCommas(contents[1]); | ||
| 353 | - info.renderer = args.get(0).trim(); | ||
| 354 | - info.display = args.size() > 1 ? args.get(1).trim() : null; | ||
| 372 | + info.statement = fullContents[0]; | ||
| 373 | + StringList args = breakCommas(fullContents[1]); | ||
| 374 | + if (args.size() > 0) { // might have no args | ||
| 375 | + String args0 = args.get(0).trim(); | ||
| 376 | + if (args.size() == 1) { | ||
| 377 | + // could be either fullScreen(1) or fullScreen(P2D), figure out which | ||
| 378 | + if (args0.equals("SPAN") || PApplet.parseInt(args0, -1) != -1) { | ||
| 379 | + // it's the display parameter, not the renderer | ||
| 380 | + info.display = args0; | ||
| 381 | + } else { | ||
| 382 | + info.renderer = args0; | ||
| 383 | + } | ||
| 384 | + } else if (args.size() == 2) { | ||
| 385 | + info.renderer = args0; | ||
| 386 | + info.display = args.get(1).trim(); | ||
| 387 | + } else { | ||
| 388 | + throw new SketchException("That's too many parameters for fullScreen()"); | ||
| 389 | + } | ||
| 390 | + } | ||
| 355 | 391 | info.width = "displayWidth"; | |
| 356 | 392 | info.height = "displayHeight"; | |
| 393 | + if (smoothStatement != null) { | ||
| 394 | + info.statement += smoothStatement; | ||
| 395 | + } | ||
| 357 | 396 | info.checkEmpty(); | |
| 358 | 397 | return info; | |
| 359 | 398 | } | |
| 360 | 399 | ||
| 400 | + // Made it this far, but no size() or fullScreen(), and still | ||
| 401 | + // need to pull out the noSmooth() and smooth(N) methods. | ||
| 402 | + if (smoothStatement != null) { | ||
| 403 | + SurfaceInfo info = new SurfaceInfo(); | ||
| 404 | + info.statement = smoothStatement; | ||
| 405 | + return info; | ||
| 406 | + } | ||
| 407 | + | ||
| 361 | 408 | // not an error, just no size() specified | |
| 362 | 409 | //return new String[] { null, null, null, null, null }; | |
| 363 | 410 | return new SurfaceInfo(); | |
| 364 | 411 | } | |
| 365 | 412 | ||
| 366 | 413 | ||
| 414 | + static protected String[] matchMethod(String methodName, String searchArea) { | ||
| 415 | + final String left = "(?:^|\\s|;)"; | ||
| 416 | + // doesn't match empty pairs of parens | ||
| 417 | + //final String right = "\\s*\\(([^\\)]+)\\)\\s*\\;"; | ||
| 418 | + final String right = "\\s*\\(([^\\)]*)\\)\\s*\\;"; | ||
| 419 | + return PApplet.match(searchArea, left + methodName + right); | ||
| 420 | + } | ||
| 421 | + | ||
| 422 | + | ||
| 367 | 423 | /** | |
| 368 | 424 | * Replace all commented portions of a given String as spaces. | |
| 369 | 425 | * Utility function used here and in the preprocessor. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,7 @@ | |||
| 4 | 4 | SizeInfo - parsed elements of a size() or fullScreen() call | |
| 5 | 5 | Part of the Processing project - http://processing.org | |
| 6 | 6 | ||
| 7 | - Copyright (c) 2015 Ben Fry and Casey Reas | ||
| 7 | + Copyright (c) 2015 The Processing Foundation | ||
| 8 | 8 | ||
| 9 | 9 | This program is free software; you can redistribute it and/or modify | |
| 10 | 10 | it under the terms of the GNU General Public License as published by | |
@@ -36,7 +36,8 @@ public class SurfaceInfo { | |||
| 36 | 36 | ||
| 37 | 37 | String display; | |
| 38 | 38 | /** null for nothing in setup(), 0 for noSmooth(), N for smooth(N) */ | |
| 39 | - Integer quality; | ||
| 39 | + //Integer quality; | ||
| 40 | + // String smooth; | ||
| 40 | 41 | ||
| 41 | 42 | ||
| 42 | 43 | boolean hasOldSyntax() { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments