picrate 2.3.0-java → 2.5.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/Gemfile +1 -1
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/docs/.gitignore +1 -0
- data/docs/_classes/{app_render → gfx_render}/app_render.md +5 -5
- data/docs/_methods/{noise_mode.md → noise_modes.md} +9 -21
- data/docs/_posts/2018-05-06-install_jruby.md +5 -5
- data/docs/_posts/2019-11-11-getting_started_buster.md +1 -1
- data/lib/picrate/app.rb +3 -7
- data/lib/picrate/native_folder.rb +1 -1
- data/lib/picrate/version.rb +1 -1
- data/lib/{picrate-2.3.0.jar → picrate-2.5.0.jar} +0 -0
- data/{lib → library/pdf}/itextpdf-5.5.13.2.jar +0 -0
- data/library/pdf/pdf.rb +1 -0
- data/library/svg/batik-all-1.14.jar +0 -0
- data/library/svg/svg.rb +7 -0
- data/picrate.gemspec +4 -3
- data/pom.rb +19 -10
- data/pom.xml +19 -6
- data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
- data/src/main/java/monkstone/PicrateLibrary.java +2 -0
- data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
- data/src/main/java/monkstone/noise/OpenSimplex2F.java +62 -29
- data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -1106
- data/src/main/java/monkstone/vecmath/GfxRender.java +10 -11
- data/src/main/java/monkstone/vecmath/JRender.java +7 -7
- data/src/main/java/monkstone/vecmath/ShapeRender.java +3 -4
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +28 -40
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +30 -45
- data/src/main/java/processing/awt/PImageAWT.java +1 -1
- data/src/main/java/processing/awt/ShimAWT.java +1 -1
- data/src/main/java/processing/core/PApplet.java +1 -92
- data/src/main/java/processing/core/PImage.java +14 -14
- data/src/main/java/processing/opengl/PShader.java +0 -6
- data/src/main/java/processing/pdf/PGraphicsPDF.java +61 -139
- data/src/main/java/processing/svg/PGraphicsSVG.java +378 -0
- data/test/noise_test.rb +17 -0
- data/test/respond_to_test.rb +0 -1
- data/test/test_helper.rb +1 -1
- data/vendors/Rakefile +1 -1
- metadata +21 -32
- data/src/main/java/japplemenubar/JAppleMenuBar.java +0 -96
- data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/src/main/java/monkstone/complex/JComplex.java +0 -252
- data/src/main/java/monkstone/noise/FastTerrain.java +0 -874
- data/src/main/java/monkstone/noise/Noise.java +0 -90
- data/src/main/java/monkstone/noise/NoiseGenerator.java +0 -75
- data/src/main/java/monkstone/noise/NoiseMode.java +0 -28
- data/src/main/java/monkstone/noise/SmoothTerrain.java +0 -1099
- data/src/main/java/monkstone/vecmath/AppRender.java +0 -88
- data/src/main/java/monkstone/vecmath/package-info.java +0 -20
- data/src/main/java/monkstone/vecmath/vec2/package-info.java +0 -6
- data/src/main/java/monkstone/vecmath/vec3/package-info.java +0 -6
@@ -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
|
*
|
@@ -1523,24 +1523,24 @@ public class PImage implements PConstants, Cloneable {
|
|
1523
1523
|
* Sometimes called "Normal" or "Copy" in other software.
|
1524
1524
|
*
|
1525
1525
|
* <LI>BLEND - linear interpolation of colours:
|
1526
|
-
* <
|
1526
|
+
* <code>C = A*factor + B</code>
|
1527
1527
|
*
|
1528
1528
|
* <LI>ADD - additive blending with white clip:
|
1529
|
-
* <
|
1529
|
+
* <code>C = min(A*factor + B, 255)</code>.
|
1530
1530
|
* Clipped to 0..255, Photoshop calls this "Linear Burn",
|
1531
1531
|
* and Director calls it "Add Pin".
|
1532
1532
|
*
|
1533
1533
|
* <LI>SUBTRACT - subtractive blend with black clip:
|
1534
|
-
* <
|
1534
|
+
* <code>C = max(B - A*factor, 0)</code>.
|
1535
1535
|
* Clipped to 0..255, Photoshop calls this "Linear Dodge",
|
1536
1536
|
* and Director calls it "Subtract Pin".
|
1537
1537
|
*
|
1538
1538
|
* <LI>DARKEST - only the darkest colour succeeds:
|
1539
|
-
* <
|
1539
|
+
* <code>C = min(A*factor, B)</code>.
|
1540
1540
|
* Illustrator calls this "Darken".
|
1541
1541
|
*
|
1542
1542
|
* <LI>LIGHTEST - only the lightest colour succeeds:
|
1543
|
-
* <
|
1543
|
+
* <code>C = max(A*factor, B)</code>.
|
1544
1544
|
* Illustrator calls this "Lighten".
|
1545
1545
|
*
|
1546
1546
|
* <LI>DIFFERENCE - subtract colors from underlying image.
|
@@ -1571,12 +1571,12 @@ public class PImage implements PConstants, Cloneable {
|
|
1571
1571
|
* <P>It is important to note that Processing uses "fast" code, not
|
1572
1572
|
* necessarily "correct" code. No biggie, most software does. A nitpicker
|
1573
1573
|
* can find numerous "off by 1 division" problems in the blend code where
|
1574
|
-
* <
|
1575
|
-
* <
|
1574
|
+
* <code>>>8</code> or <code>>>7</code> is used when strictly speaking
|
1575
|
+
* <code>/255.0</T> or <code>/127.0</code> should have been used.</P>
|
1576
1576
|
* <P>For instance, exclusion (not intended for real-time use) reads
|
1577
|
-
* <
|
1578
|
-
* not <
|
1579
|
-
* the same as <
|
1577
|
+
* <code>r1 + r2 - ((2 * r1 * r2) / 255)</code> because <code>255 == 1.0</code>
|
1578
|
+
* not <code>256 == 1.0</code>. In other words, <code>(255*255)>>8</code> is not
|
1579
|
+
* the same as <code>(255*255)/255</code>. But for real-time use the shifts
|
1580
1580
|
* are preferable, and the difference is insignificant for applications
|
1581
1581
|
* built with Processing.</P>
|
1582
1582
|
*
|
@@ -3104,9 +3104,9 @@ int testFunction(int dst, int src) {
|
|
3104
3104
|
* </p>
|
3105
3105
|
* Starting with revision 0092, the format setting is taken into account:
|
3106
3106
|
* <UL>
|
3107
|
-
* <LI><
|
3108
|
-
* <LI><
|
3109
|
-
* <LI><
|
3107
|
+
* <LI><code>ALPHA</code> images written as 8bit grayscale (uses lowest byte)
|
3108
|
+
* <LI><code>RGB</code> → 24 bits
|
3109
|
+
* <LI><code>ARGB</code> → 32 bits
|
3110
3110
|
* </UL>
|
3111
3111
|
* All versions are RLE compressed.
|
3112
3112
|
* </p>
|
@@ -3278,7 +3278,7 @@ int testFunction(int dst, int src) {
|
|
3278
3278
|
* and the extension used is supported (usually png, jpg, jpeg, bmp,
|
3279
3279
|
* and tiff), then those methods will be used to write the image.
|
3280
3280
|
* To get a list of the supported formats for writing, use: <BR>
|
3281
|
-
* <
|
3281
|
+
* <code>println(javax.imageio.ImageIO.getReaderFormatNames())</code>
|
3282
3282
|
* <p>
|
3283
3283
|
* To use the original built-in image writers, use .tga or .tif as the
|
3284
3284
|
* extension, or don't include an extension. When no extension is used,
|
@@ -1757,16 +1757,10 @@ public class PShader implements PConstants {
|
|
1757
1757
|
colorLoc = getAttributeLoc("color");
|
1758
1758
|
texCoordLoc = getAttributeLoc("texCoord");
|
1759
1759
|
normalLoc = getAttributeLoc("normal");
|
1760
|
-
|
1761
1760
|
ambientLoc = getAttributeLoc("ambient");
|
1762
1761
|
specularLoc = getAttributeLoc("specular");
|
1763
1762
|
emissiveLoc = getAttributeLoc("emissive");
|
1764
1763
|
shininessLoc = getAttributeLoc("shininess");
|
1765
|
-
|
1766
|
-
directionLoc = getAttributeLoc("direction");
|
1767
|
-
|
1768
|
-
offsetLoc = getAttributeLoc("offset");
|
1769
|
-
|
1770
1764
|
directionLoc = getAttributeLoc("direction");
|
1771
1765
|
offsetLoc = getAttributeLoc("offset");
|
1772
1766
|
|
@@ -21,37 +21,39 @@
|
|
21
21
|
package processing.pdf;
|
22
22
|
|
23
23
|
import com.itextpdf.awt.DefaultFontMapper;
|
24
|
-
import com.itextpdf.
|
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.
|
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="
|
49
|
-
*
|
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
|
-
|
140
|
-
|
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
|
-
|
188
|
-
|
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
|
208
|
-
1566
|
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
|
225
|
+
return new PdfGraphics2D(content, width, height);
|
253
226
|
} else if (textMode == MODEL) {
|
254
|
-
return content
|
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
|
-
*
|
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
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
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
|
-
|
520
|
+
Arrays.sort(fontList);
|
599
521
|
}
|
600
522
|
return fontList;
|
601
523
|
}
|