picrate 2.3.0-java → 2.4.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,7 +39,6 @@ import java.util.zip.*;
39
39
 
40
40
  // loadXML() error handling
41
41
  import javax.xml.parsers.ParserConfigurationException;
42
- import monkstone.noise.NoiseGenerator;
43
42
  import org.xml.sax.SAXException;
44
43
 
45
44
  // TODO have this removed by 4.0 final
@@ -48,8 +47,6 @@ import processing.awt.ShimAWT;
48
47
  import processing.data.*;
49
48
  import processing.event.*;
50
49
  import processing.opengl.*;
51
- import monkstone.noise.Noise;
52
- import monkstone.noise.NoiseMode;
53
50
 
54
51
  /**
55
52
  * Base class for all sketches that use processing.core.
@@ -106,7 +103,6 @@ public class PApplet implements PConstants {
106
103
  }
107
104
  }
108
105
 
109
- Noise noiseGenerator = new NoiseGenerator();
110
106
  /**
111
107
  * Whether to use native (AWT) dialogs for selectInput and selectOutput. The
112
108
  * native dialogs on some platforms can be ugly, buggy, or missing features.
@@ -4887,9 +4883,6 @@ public class PApplet implements PConstants {
4887
4883
  internalRandom.setSeed(seed);
4888
4884
  }
4889
4885
 
4890
- public void noiseMode(NoiseMode mode) {
4891
- noiseGenerator.noiseMode(mode);
4892
- }
4893
4886
  /**
4894
4887
  *
4895
4888
  * @param lod
@@ -4913,91 +4906,7 @@ public class PApplet implements PConstants {
4913
4906
 
4914
4907
  }
4915
4908
 
4916
- /**
4917
- * @param x
4918
- * @return
4919
- */
4920
- public float noise(float x) {
4921
- return noiseGenerator.noise(x);
4922
- }
4923
-
4924
- /**
4925
- * @param x
4926
- * @param y
4927
- * @return
4928
- */
4929
- public float noise(float x, float y) {
4930
- return noiseGenerator.noise(x, y);
4931
- }
4932
-
4933
- /**
4934
- * ( begin auto-generated from noise.xml )
4935
- *
4936
- * Returns the Perlin noise value at specified coordinates.Perlin noise is a
4937
- * random sequence generator producing a more natural ordered, harmonic
4938
- * succession of numbers compared to the standard <b>random()</b> function.
4939
- * It was invented by Ken Perlin in the 1980s and been used since in
4940
- * graphical applications to produce procedural textures, natural motion,
4941
- * shapes, terrains etc. The main difference to the
4942
- * <b>random()</b> function is that Perlin noise is defined in an infinite
4943
- * n-dimensional space where each pair of coordinates corresponds to a fixed
4944
- * semi-random value (fixed only for the lifespan of the program). The
4945
- * resulting value will always be between 0.0 and 1.0. Processing can
4946
- * compute 1D, 2D and 3D noise, depending on the number of coordinates
4947
- * given. The noise value can be animated by moving through the noise space
4948
- * as demonstrated in the example above. The 2nd and 3rd dimension can also
4949
- * be interpreted as time.The actual noise is structured similar to an audio
4950
- * signal, in respect to the function's use of frequencies. Similar to the
4951
- * concept of harmonics in physics, perlin noise is computed over several
4952
- * octaves which are added together for the final result. Another way to
4953
- * adjust the character of the resulting sequence is the scale of the input
4954
- * coordinates. As the function works within an infinite space the value of
4955
- * the coordinates doesn't matter as such, only the distance between
4956
- * successive coordinates does (eg. when using <b>noise()</b> within a
4957
- * loop). As a general rule the smaller the difference between coordinates,
4958
- * the smoother the resulting noise sequence will be. Steps of 0.005-0.03
4959
- * work best for most applications, but this will differ depending on use.
4960
- *
4961
- *
4962
- *
4963
- * @return
4964
- * @webref math:random
4965
- * @param x x-coordinate in noise space
4966
- * @param y y-coordinate in noise space
4967
- * @param z z-coordinate in noise space
4968
- * @see PApplet#noiseSeed(long)
4969
- * @see PApplet#noiseDetail(int, float)
4970
- * @see PApplet#random(float,float)
4971
- */
4972
- public float noise(float x, float y, float z) {
4973
- return noiseGenerator.noise(x, y, z);
4974
- }
4975
-
4976
- public float noise(float x, float y, float z, float w) {
4977
- return noiseGenerator.noise(x, y, z, w);
4978
- }
4979
-
4980
- /**
4981
- *
4982
- *
4983
- * Sets the seed value for <b>noise()</b>. By default, <b>noise()</b>
4984
- * produces different results each time the program is run. Set the
4985
- * <b>value</b> parameter to a constant to return the same pseudo-random
4986
- * numbers each time the software is run.
4987
- *
4988
- *
4989
- * @webref math:random
4990
- * @param seed seed value
4991
- * @see PApplet#noise(float, float, float)
4992
- * @see PApplet#noiseDetail(int, float)
4993
- * @see PApplet#random(float,float)
4994
- * @see PApplet#randomSeed(long)
4995
- */
4996
- public void noiseSeed(long seed) {
4997
- noiseGenerator.noiseSeed(seed);
4998
- }
4999
-
5000
- // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4909
+ // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5001
4910
  /**
5002
4911
  * ( begin auto-generated from loadImage.xml )
5003
4912
  *
@@ -21,37 +21,39 @@
21
21
  package processing.pdf;
22
22
 
23
23
  import com.itextpdf.awt.DefaultFontMapper;
24
- import com.itextpdf.text.Rectangle;
24
+ import com.itextpdf.awt.PdfGraphics2D;
25
25
  import com.itextpdf.text.Document;
26
26
  import com.itextpdf.text.DocumentException;
27
+ import com.itextpdf.text.Rectangle;
27
28
  import com.itextpdf.text.pdf.ByteBuffer;
28
29
  import com.itextpdf.text.pdf.PdfContentByte;
29
30
  import com.itextpdf.text.pdf.PdfWriter;
30
31
  import java.awt.Font;
31
32
  import java.awt.Graphics2D;
32
33
  import java.awt.Image;
33
- import java.io.*;
34
- import java.util.*;
34
+ import java.io.BufferedOutputStream;
35
+ import java.io.File;
36
+ import java.io.FileNotFoundException;
37
+ import java.io.FileOutputStream;
38
+ import java.io.OutputStream;
39
+ import java.util.Arrays;
40
+ import java.util.HashMap;
35
41
  import java.util.logging.Level;
36
42
  import java.util.logging.Logger;
37
-
38
- //import com.lowagie.text.*;
39
- //import com.lowagie.text.pdf.*;
40
- //import com.lowagie.text.pdf.ByteBuffer;
41
-
42
43
  import processing.awt.PGraphicsJava2D;
43
- import processing.core.*;
44
+ import processing.core.PApplet;
45
+ import processing.core.PConstants;
46
+ import processing.core.PFont;
47
+ import processing.core.PImage;
48
+ import processing.core.PStyle;
49
+ import processing.core.PSurface;
50
+ import processing.core.PSurfaceNone;
44
51
 
45
52
  /**
46
53
  * Thin wrapper for the iText PDF library that handles writing PDF files. The
47
54
  * majority of the work in this library is done by
48
- * <a href="http://www.lowagie.com/iText/">iText</a>.
49
- * This is currently using iText 2.1.7.
50
- * The issue is that versions from the 5.x series were slow to handle lots of
51
- * fonts with the DefaultFontMapper. 2.x seemed a little slower than 1.x, but
52
- * 5.x took up to 10 times the time to load, meaning a lag of several seconds
53
- * when starting sketches on a machine that had a good handful of fonts
54
- * installed. (Like, say, anyone in our target audience. Or me.)
55
+ * <a href="https://github.com/itext/itextpdf">itextpdf</a>. This is currently using
56
+ * itextpdf-5.5.13.2.
55
57
  */
56
58
  public class PGraphicsPDF extends PGraphicsJava2D {
57
59
 
@@ -67,20 +69,13 @@ public class PGraphicsPDF extends PGraphicsJava2D {
67
69
  protected Document document;
68
70
  protected PdfWriter writer;
69
71
  protected PdfContentByte content;
70
-
72
+ protected PdfGraphics2D graphicContent;
71
73
  /**
72
74
  * Shared across instances because it's incredibly time-consuming to create.
73
75
  */
74
76
  static protected DefaultFontMapper mapper;
75
77
  static protected String[] fontList;
76
78
 
77
-
78
- /*
79
- public PGraphicsPDF() {
80
- // PDF always likes native fonts. Always.
81
- hint(ENABLE_NATIVE_FONTS);
82
- }
83
- */
84
79
  @Override
85
80
  public void setPath(String path) {
86
81
  this.path = path;
@@ -104,15 +99,6 @@ public class PGraphicsPDF extends PGraphicsJava2D {
104
99
  this.output = output;
105
100
  }
106
101
 
107
- // /**
108
- // * all the init stuff happens in here, in case someone calls size()
109
- // * along the way and wants to hork things up.
110
- // */
111
- // protected void allocate() {
112
- // // can't do anything here, because this will be called by the
113
- // // superclass PGraphics, and the file/path object won't be set yet
114
- // // (since super() called right at the beginning of the constructor)
115
- // }
116
102
  @Override
117
103
  public PSurface createSurface() {
118
104
  return surface = new PSurfaceNone(this);
@@ -126,19 +112,17 @@ public class PGraphicsPDF extends PGraphicsJava2D {
126
112
 
127
113
  @Override
128
114
  public void beginDraw() {
129
- // long t0 = System.currentTimeMillis();
130
-
131
115
  if (document == null) {
132
- // https://github.com/processing/processing/issues/5801#issuecomment-466632459
133
116
  ByteBuffer.HIGH_PRECISION = true;
134
-
135
117
  document = new Document(new Rectangle(width, height));
136
118
  boolean missingPath = false;
137
119
  try {
138
120
  if (file != null) {
139
- //BufferedOutputStream output = new BufferedOutputStream(stream, 16384);
140
- output = new BufferedOutputStream(new FileOutputStream(file), 16384);
141
-
121
+ try {
122
+ output = new BufferedOutputStream(new FileOutputStream(file), 16384);
123
+ } catch (FileNotFoundException ex) {
124
+ Logger.getLogger(PGraphicsPDF.class.getName()).log(Level.SEVERE, null, ex);
125
+ }
142
126
  } else if (output == null) {
143
127
  missingPath = true;
144
128
  throw new RuntimeException("PGraphicsPDF requires a path "
@@ -159,13 +143,8 @@ public class PGraphicsPDF extends PGraphicsJava2D {
159
143
  } else {
160
144
  throw new RuntimeException("Problem saving the PDF file.", re);
161
145
  }
162
-
163
- } catch (FileNotFoundException fnfe) {
164
- throw new RuntimeException("Can't save the PDF file to " + path, fnfe);
165
-
166
146
  }
167
-
168
- g2 = content.createGraphicsShapes(width, height);
147
+ g2 = new PdfGraphics2D(content, width, height);
169
148
  }
170
149
 
171
150
  // super in Java2D now creates an image buffer, don't do that
@@ -173,24 +152,16 @@ public class PGraphicsPDF extends PGraphicsJava2D {
173
152
  checkSettings();
174
153
  resetMatrix(); // reset model matrix
175
154
  vertexCount = 0;
176
-
177
- // Also need to push the matrix since the matrix doesn't reset on each run
178
- // http://dev.processing.org/bugs/show_bug.cgi?id=1227
179
155
  pushMatrix();
180
156
  }
181
157
 
182
158
  static protected DefaultFontMapper getMapper() {
183
159
  if (mapper == null) {
184
- // long t = System.currentTimeMillis();
185
160
  mapper = new DefaultFontMapper();
186
-
187
- if (PApplet.platform == PConstants.LINUX) {
188
- checkDir("/usr/share/fonts/", mapper);
189
- checkDir("/usr/local/share/fonts/", mapper);
190
- checkDir(System.getProperty("user.home") + "/.fonts", mapper);
161
+ checkDir("/usr/share/fonts/", mapper);
162
+ checkDir("/usr/local/share/fonts/", mapper);
163
+ checkDir(System.getProperty("user.home") + "/.fonts", mapper);
191
164
  }
192
- // System.out.println("mapping " + (System.currentTimeMillis() - t));
193
- }
194
165
  return mapper;
195
166
  }
196
167
 
@@ -204,8 +175,10 @@ public class PGraphicsPDF extends PGraphicsJava2D {
204
175
 
205
176
  /**
206
177
  * Recursive walk to get all subdirectories for font fun.Patch submitted by
207
- Matthias Breuer.(<a href="http://dev.processing.org/bugs/show_bug.cgi?id=1566">Bug
208
- 1566</a>)
178
+ * Matthias
179
+ * Breuer.(<a href="http://dev.processing.org/bugs/show_bug.cgi?id=1566">Bug
180
+ * 1566</a>)
181
+ *
209
182
  * @param folder
210
183
  * @param mapper
211
184
  */
@@ -249,9 +222,9 @@ public class PGraphicsPDF extends PGraphicsJava2D {
249
222
 
250
223
  protected Graphics2D createGraphics() {
251
224
  if (textMode == SHAPE) {
252
- return content.createGraphics(width, height);
225
+ return new PdfGraphics2D(content, width, height);
253
226
  } else if (textMode == MODEL) {
254
- return content.createGraphics(width, height, getMapper());
227
+ return new PdfGraphics2D(content, width, height, getMapper());
255
228
  }
256
229
  // Should not be reachable...
257
230
  throw new RuntimeException("Invalid textMode() selected for PDF.");
@@ -276,45 +249,6 @@ public class PGraphicsPDF extends PGraphicsJava2D {
276
249
  return false;
277
250
  }
278
251
 
279
- /*
280
- protected void finalize() throws Throwable {
281
- System.out.println("calling finalize");
282
- //document.close(); // do this in dispose instead?
283
- }
284
- */
285
- //////////////////////////////////////////////////////////////
286
- /*
287
- public void endRecord() {
288
- super.endRecord();
289
- dispose();
290
- }
291
-
292
-
293
- public void endRaw() {
294
- System.out.println("ending raw");
295
- super.endRaw();
296
- System.out.println("disposing");
297
- dispose();
298
- System.out.println("done");
299
- }
300
- */
301
- //////////////////////////////////////////////////////////////
302
- /*
303
- protected void rectImpl(float x1, float y1, float x2, float y2) {
304
- //rect.setFrame(x1, y1, x2-x1, y2-y1);
305
- //draw_shape(rect);
306
- System.out.println("rect implements");
307
- g2.fillRect((int)x1, (int)y1, (int) (x2-x1), (int) (y2-y1));
308
- }
309
- *
310
-
311
- /*
312
- public void clear() {
313
- g2.setColor(Color.red);
314
- g2.fillRect(0, 0, width, height);
315
- }
316
- */
317
- //////////////////////////////////////////////////////////////
318
252
  @Override
319
253
  protected void imageImpl(PImage image,
320
254
  float x1, float y1, float x2, float y2,
@@ -339,49 +273,36 @@ public class PGraphicsPDF extends PGraphicsJava2D {
339
273
  public void textFont(PFont which) {
340
274
  super.textFont(which);
341
275
  checkFont();
342
- // Make sure a native version of the font is available.
343
- // if (textFont.getFont() == null) {
344
- // throw new RuntimeException("Use createFont() instead of loadFont() " +
345
- // "when drawing text using the PDF library.");
346
- // }
347
- // Make sure that this is a font that the PDF library can deal with.
348
- // if ((textMode != SHAPE) && !checkFont(which.getName())) {
349
- // System.err.println("Use PGraphicsPDF.listFonts() to get a list of available fonts.");
350
- // throw new RuntimeException("The font “" + which.getName() + "” cannot be used with PDF Export.");
351
- // }
352
276
  }
353
277
 
354
278
  /**
355
- * Change the textMode() to either SHAPE or MODEL.
356
- * This resets all renderer settings, and therefore must be called
279
+ * Change the textMode() to either SHAPE or MODEL. This resets all renderer
280
+ * settings, and therefore must be called
357
281
  * <EM>before</EM> any other commands that set the fill() or the textFont()
358
282
  * or anything. Unlike other renderers, use textMode() directly after the
359
283
  * size() command.
360
284
  */
361
- @Override
362
- public void textMode(int mode) {
363
- if (textMode != mode) {
364
- switch (mode) {
365
- case SHAPE:
366
- textMode = SHAPE;
367
- g2.dispose();
368
- // g2 = content.createGraphicsShapes(width, height);
369
- g2 = createGraphics();
370
- break;
371
- case MODEL:
372
- textMode = MODEL;
373
- g2.dispose();
374
- // g2 = content.createGraphics(width, height, mapper);
375
- g2 = createGraphics();
376
- // g2 = template.createGraphics(width, height, mapper);
377
- break;
378
- case SCREEN:
379
- throw new RuntimeException("textMode(SCREEN) not supported with PDF");
380
- default:
381
- throw new RuntimeException("That textMode() does not exist");
382
- }
383
- }
384
- }
285
+ @Override
286
+ public void textMode(int mode) {
287
+ if (textMode != mode) {
288
+ switch (mode) {
289
+ case SHAPE:
290
+ textMode = SHAPE;
291
+ g2.dispose();
292
+ g2 = createGraphics();
293
+ break;
294
+ case MODEL:
295
+ textMode = MODEL;
296
+ g2.dispose();
297
+ g2 = createGraphics();
298
+ break;
299
+ case SCREEN:
300
+ throw new RuntimeException("textMode(SCREEN) not supported with PDF");
301
+ default:
302
+ throw new RuntimeException("That textMode() does not exist");
303
+ }
304
+ }
305
+ }
385
306
 
386
307
  @Override
387
308
  protected void textLineImpl(char buffer[], int start, int stop,
@@ -436,7 +357,6 @@ public class PGraphicsPDF extends PGraphicsJava2D {
436
357
  }
437
358
 
438
359
  //
439
-
440
360
  /**
441
361
  *
442
362
  * @param alpha
@@ -534,6 +454,7 @@ public class PGraphicsPDF extends PGraphicsJava2D {
534
454
  * On Linux or any other platform, you'll need to add the directories by
535
455
  * hand. (If there are actual standards here that we can use as a starting
536
456
  * point, please file a bug to make a note of it)
457
+ *
537
458
  * @param directory
538
459
  */
539
460
  public void addFonts(String directory) {
@@ -573,7 +494,8 @@ public class PGraphicsPDF extends PGraphicsJava2D {
573
494
 
574
495
  /**
575
496
  * List the fonts known to the PDF renderer.This is like PFont.list(),
576
- however not all those fonts are available by default.
497
+ * however not all those fonts are available by default.
498
+ *
577
499
  * @return
578
500
  */
579
501
  static public String[] listFonts() {
@@ -595,7 +517,7 @@ public class PGraphicsPDF extends PGraphicsJava2D {
595
517
  // //System.out.println(entry.getKey() + "-->" + entry.getValue());
596
518
  // fontList[count++] = (String) entry.getKey();
597
519
  // }
598
- fontList = PApplet.sort(fontList);
520
+ Arrays.sort(fontList);
599
521
  }
600
522
  return fontList;
601
523
  }