propane 3.8.0-java → 3.9.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 +2 -0
- data/README.md +2 -2
- data/Rakefile +1 -0
- data/lib/propane/app.rb +3 -2
- data/lib/propane/version.rb +1 -1
- data/library/pdf/pdf.rb +7 -0
- data/library/svg/svg.rb +7 -0
- data/pom.rb +24 -2
- data/pom.xml +40 -1
- data/propane.gemspec +3 -1
- data/src/main/java/monkstone/noise/FastTerrain.java +874 -0
- data/src/main/java/monkstone/noise/Noise.java +0 -26
- data/src/main/java/monkstone/noise/NoiseGenerator.java +35 -23
- data/src/main/java/monkstone/noise/NoiseMode.java +15 -2
- data/src/main/java/monkstone/noise/OpenSimplex2F.java +881 -0
- data/src/main/java/monkstone/noise/OpenSimplex2S.java +1106 -0
- data/src/main/java/monkstone/noise/SmoothTerrain.java +1099 -0
- data/src/main/java/processing/core/PApplet.java +106 -127
- data/src/main/java/processing/core/PGraphics.java +116 -109
- data/src/main/java/processing/pdf/PGraphicsPDF.java +581 -0
- data/src/main/java/processing/svg/PGraphicsSVG.java +378 -0
- data/vendors/Rakefile +1 -1
- metadata +14 -6
- data/src/main/java/monkstone/noise/SimplexNoise.java +0 -470
- data/src/main/java/monkstone/noise/ValueNoise.java +0 -170
@@ -30,9 +30,11 @@ import java.awt.Color;
|
|
30
30
|
|
31
31
|
// Used for the 'image' object that's been here forever
|
32
32
|
import java.awt.Font;
|
33
|
+
import java.awt.FontFormatException;
|
33
34
|
import java.awt.Image;
|
34
35
|
|
35
36
|
import java.io.File;
|
37
|
+
import java.io.IOException;
|
36
38
|
import java.io.InputStream;
|
37
39
|
import java.util.Map;
|
38
40
|
import java.util.HashMap;
|
@@ -1984,35 +1986,32 @@ public class PGraphics extends PImage implements PConstants {
|
|
1984
1986
|
* @param d height of the rectangle, by default
|
1985
1987
|
*/
|
1986
1988
|
public void clip(float a, float b, float c, float d) {
|
1987
|
-
|
1988
|
-
|
1989
|
-
|
1989
|
+
switch (imageMode) {
|
1990
|
+
case CORNER:
|
1991
|
+
if (c < 0) { // reset a negative width
|
1992
|
+
a += c; c = -c;
|
1993
|
+
} if (d < 0) { // reset a negative height
|
1994
|
+
b += d; d = -d;
|
1995
|
+
} clipImpl(a, b, a + c, b + d);
|
1996
|
+
break;
|
1997
|
+
case CORNERS:
|
1998
|
+
if (c < a) { // reverse because x2 < x1
|
1999
|
+
float temp = a; a = c; c = temp;
|
2000
|
+
} if (d < b) { // reverse because y2 < y1
|
2001
|
+
float temp = b; b = d; d = temp;
|
2002
|
+
} clipImpl(a, b, c, d);
|
2003
|
+
break;
|
2004
|
+
case CENTER:
|
2005
|
+
// c and d are width/height
|
2006
|
+
if (c < 0) c = -c;
|
2007
|
+
if (d < 0) d = -d;
|
2008
|
+
float x1 = a - c/2;
|
2009
|
+
float y1 = b - d/2;
|
2010
|
+
clipImpl(x1, y1, x1 + c, y1 + d);
|
2011
|
+
break;
|
2012
|
+
default:
|
2013
|
+
break;
|
1990
2014
|
}
|
1991
|
-
if (d < 0) { // reset a negative height
|
1992
|
-
b += d; d = -d;
|
1993
|
-
}
|
1994
|
-
|
1995
|
-
clipImpl(a, b, a + c, b + d);
|
1996
|
-
|
1997
|
-
} else if (imageMode == CORNERS) {
|
1998
|
-
if (c < a) { // reverse because x2 < x1
|
1999
|
-
float temp = a; a = c; c = temp;
|
2000
|
-
}
|
2001
|
-
if (d < b) { // reverse because y2 < y1
|
2002
|
-
float temp = b; b = d; d = temp;
|
2003
|
-
}
|
2004
|
-
|
2005
|
-
clipImpl(a, b, c, d);
|
2006
|
-
|
2007
|
-
} else if (imageMode == CENTER) {
|
2008
|
-
// c and d are width/height
|
2009
|
-
if (c < 0) c = -c;
|
2010
|
-
if (d < 0) d = -d;
|
2011
|
-
float x1 = a - c/2;
|
2012
|
-
float y1 = b - d/2;
|
2013
|
-
|
2014
|
-
clipImpl(x1, y1, x1 + c, y1 + d);
|
2015
|
-
}
|
2016
2015
|
}
|
2017
2016
|
|
2018
2017
|
|
@@ -2811,20 +2810,24 @@ public class PGraphics extends PImage implements PConstants {
|
|
2811
2810
|
float w = c;
|
2812
2811
|
float h = d;
|
2813
2812
|
|
2814
|
-
|
2815
|
-
|
2816
|
-
|
2817
|
-
|
2818
|
-
|
2819
|
-
|
2820
|
-
|
2821
|
-
|
2822
|
-
|
2823
|
-
|
2824
|
-
|
2825
|
-
|
2826
|
-
|
2827
|
-
|
2813
|
+
switch (ellipseMode) {
|
2814
|
+
case CORNERS:
|
2815
|
+
w = c - a;
|
2816
|
+
h = d - b;
|
2817
|
+
break;
|
2818
|
+
case RADIUS:
|
2819
|
+
x = a - c;
|
2820
|
+
y = b - d;
|
2821
|
+
w = c * 2;
|
2822
|
+
h = d * 2;
|
2823
|
+
break;
|
2824
|
+
case DIAMETER:
|
2825
|
+
x = a - c/2f;
|
2826
|
+
y = b - d/2f;
|
2827
|
+
break;
|
2828
|
+
default:
|
2829
|
+
break;
|
2830
|
+
}
|
2828
2831
|
|
2829
2832
|
if (w < 0) { // undo negative width
|
2830
2833
|
x += w;
|
@@ -2881,20 +2884,24 @@ public class PGraphics extends PImage implements PConstants {
|
|
2881
2884
|
float w = c;
|
2882
2885
|
float h = d;
|
2883
2886
|
|
2884
|
-
|
2885
|
-
|
2886
|
-
|
2887
|
-
|
2888
|
-
|
2889
|
-
|
2890
|
-
|
2891
|
-
|
2892
|
-
|
2893
|
-
|
2894
|
-
|
2895
|
-
|
2896
|
-
|
2897
|
-
|
2887
|
+
switch (ellipseMode) {
|
2888
|
+
case CORNERS:
|
2889
|
+
w = c - a;
|
2890
|
+
h = d - b;
|
2891
|
+
break;
|
2892
|
+
case RADIUS:
|
2893
|
+
x = a - c;
|
2894
|
+
y = b - d;
|
2895
|
+
w = c * 2;
|
2896
|
+
h = d * 2;
|
2897
|
+
break;
|
2898
|
+
case CENTER:
|
2899
|
+
x = a - c/2f;
|
2900
|
+
y = b - d/2f;
|
2901
|
+
break;
|
2902
|
+
default:
|
2903
|
+
break;
|
2904
|
+
}
|
2898
2905
|
|
2899
2906
|
// make sure the loop will exit before starting while
|
2900
2907
|
if (!Float.isInfinite(start) && !Float.isInfinite(stop)) {
|
@@ -3854,41 +3861,38 @@ public class PGraphics extends PImage implements PConstants {
|
|
3854
3861
|
// loadImageAsync() sets width and height to -1 when loading fails.
|
3855
3862
|
if (img.width == -1 || img.height == -1) return;
|
3856
3863
|
|
3857
|
-
|
3858
|
-
|
3859
|
-
|
3860
|
-
|
3861
|
-
|
3862
|
-
|
3864
|
+
switch (imageMode) {
|
3865
|
+
case CORNER:
|
3866
|
+
if (c < 0) { // reset a negative width
|
3867
|
+
a += c; c = -c;
|
3868
|
+
} if (d < 0) { // reset a negative height
|
3869
|
+
b += d; d = -d;
|
3870
|
+
} imageImpl(img,
|
3871
|
+
a, b, a + c, b + d,
|
3872
|
+
u1, v1, u2, v2);
|
3873
|
+
break;
|
3874
|
+
case CORNERS:
|
3875
|
+
if (c < a) { // reverse because x2 < x1
|
3876
|
+
float temp = a; a = c; c = temp;
|
3877
|
+
} if (d < b) { // reverse because y2 < y1
|
3878
|
+
float temp = b; b = d; d = temp;
|
3879
|
+
} imageImpl(img,
|
3880
|
+
a, b, c, d,
|
3881
|
+
u1, v1, u2, v2);
|
3882
|
+
break;
|
3883
|
+
case CENTER:
|
3884
|
+
// c and d are width/height
|
3885
|
+
if (c < 0) c = -c;
|
3886
|
+
if (d < 0) d = -d;
|
3887
|
+
float x1 = a - c/2;
|
3888
|
+
float y1 = b - d/2;
|
3889
|
+
imageImpl(img,
|
3890
|
+
x1, y1, x1 + c, y1 + d,
|
3891
|
+
u1, v1, u2, v2);
|
3892
|
+
break;
|
3893
|
+
default:
|
3894
|
+
break;
|
3863
3895
|
}
|
3864
|
-
|
3865
|
-
imageImpl(img,
|
3866
|
-
a, b, a + c, b + d,
|
3867
|
-
u1, v1, u2, v2);
|
3868
|
-
|
3869
|
-
} else if (imageMode == CORNERS) {
|
3870
|
-
if (c < a) { // reverse because x2 < x1
|
3871
|
-
float temp = a; a = c; c = temp;
|
3872
|
-
}
|
3873
|
-
if (d < b) { // reverse because y2 < y1
|
3874
|
-
float temp = b; b = d; d = temp;
|
3875
|
-
}
|
3876
|
-
|
3877
|
-
imageImpl(img,
|
3878
|
-
a, b, c, d,
|
3879
|
-
u1, v1, u2, v2);
|
3880
|
-
|
3881
|
-
} else if (imageMode == CENTER) {
|
3882
|
-
// c and d are width/height
|
3883
|
-
if (c < 0) c = -c;
|
3884
|
-
if (d < 0) d = -d;
|
3885
|
-
float x1 = a - c/2;
|
3886
|
-
float y1 = b - d/2;
|
3887
|
-
|
3888
|
-
imageImpl(img,
|
3889
|
-
x1, y1, x1 + c, y1 + d,
|
3890
|
-
u1, v1, u2, v2);
|
3891
|
-
}
|
3892
3896
|
}
|
3893
3897
|
|
3894
3898
|
|
@@ -4062,6 +4066,7 @@ public class PGraphics extends PImage implements PConstants {
|
|
4062
4066
|
|
4063
4067
|
|
4064
4068
|
/**
|
4069
|
+
* @param shape
|
4065
4070
|
* @param a x-coordinate of the shape
|
4066
4071
|
* @param b y-coordinate of the shape
|
4067
4072
|
* @param c width to display the shape
|
@@ -4073,23 +4078,26 @@ public class PGraphics extends PImage implements PConstants {
|
|
4073
4078
|
|
4074
4079
|
pushMatrix();
|
4075
4080
|
|
4076
|
-
|
4077
|
-
|
4078
|
-
|
4079
|
-
|
4080
|
-
|
4081
|
-
|
4082
|
-
|
4083
|
-
|
4084
|
-
|
4085
|
-
|
4086
|
-
|
4087
|
-
|
4088
|
-
|
4089
|
-
|
4090
|
-
|
4091
|
-
|
4092
|
-
|
4081
|
+
switch (shapeMode) {
|
4082
|
+
case CENTER:
|
4083
|
+
// x and y are center, c and d refer to a diameter
|
4084
|
+
translate(a - c/2f, b - d/2f);
|
4085
|
+
scale(c / shape.getWidth(), d / shape.getHeight());
|
4086
|
+
break;
|
4087
|
+
case CORNER:
|
4088
|
+
translate(a, b);
|
4089
|
+
scale(c / shape.getWidth(), d / shape.getHeight());
|
4090
|
+
break;
|
4091
|
+
case CORNERS:
|
4092
|
+
// c and d are x2/y2, make them into width/height
|
4093
|
+
c -= a; d -= b;
|
4094
|
+
// then same as above
|
4095
|
+
translate(a, b);
|
4096
|
+
scale(c / shape.getWidth(), d / shape.getHeight());
|
4097
|
+
break;
|
4098
|
+
default:
|
4099
|
+
break;
|
4100
|
+
}
|
4093
4101
|
shape.draw(this);
|
4094
4102
|
|
4095
4103
|
popMatrix();
|
@@ -4141,9 +4149,8 @@ public class PGraphics extends PImage implements PConstants {
|
|
4141
4149
|
}
|
4142
4150
|
return createFont(baseFont, size, smooth, charset, stream != null);
|
4143
4151
|
|
4144
|
-
} catch (
|
4152
|
+
} catch (FontFormatException | IOException e) {
|
4145
4153
|
System.err.println("Problem with createFont(\"" + name + "\")");
|
4146
|
-
e.printStackTrace();
|
4147
4154
|
return null;
|
4148
4155
|
}
|
4149
4156
|
}
|
@@ -0,0 +1,581 @@
|
|
1
|
+
/*
|
2
|
+
Part of the Processing project - http://processing.org
|
3
|
+
|
4
|
+
Copyright (c) 2005-12 Ben Fry and Casey Reas
|
5
|
+
Copyright (c) 2012-18 The Processing Foundation
|
6
|
+
|
7
|
+
This library is free software; you can redistribute it and/or
|
8
|
+
modify it under the terms of the GNU Lesser General Public
|
9
|
+
License version 2.1 as published by the Free Software Foundation.
|
10
|
+
|
11
|
+
This library is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General
|
17
|
+
Public License along with this library; if not, write to the
|
18
|
+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
19
|
+
Boston, MA 02111-1307 USA
|
20
|
+
*/
|
21
|
+
package processing.pdf;
|
22
|
+
|
23
|
+
import com.itextpdf.awt.DefaultFontMapper;
|
24
|
+
import com.itextpdf.awt.PdfGraphics2D;
|
25
|
+
import com.itextpdf.text.Document;
|
26
|
+
import com.itextpdf.text.DocumentException;
|
27
|
+
import com.itextpdf.text.Rectangle;
|
28
|
+
import com.itextpdf.text.pdf.ByteBuffer;
|
29
|
+
import com.itextpdf.text.pdf.PdfContentByte;
|
30
|
+
import com.itextpdf.text.pdf.PdfWriter;
|
31
|
+
import java.awt.Font;
|
32
|
+
import java.awt.Graphics2D;
|
33
|
+
import java.awt.Image;
|
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;
|
41
|
+
import java.util.logging.Level;
|
42
|
+
import java.util.logging.Logger;
|
43
|
+
import processing.awt.PGraphicsJava2D;
|
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;
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Thin wrapper for the iText PDF library that handles writing PDF files. The
|
54
|
+
* majority of the work in this library is done by
|
55
|
+
* <a href="https://github.com/itext/itextpdf">itextpdf</a>. This is currently using
|
56
|
+
* itextpdf-5.5.13.2.
|
57
|
+
*/
|
58
|
+
public class PGraphicsPDF extends PGraphicsJava2D {
|
59
|
+
|
60
|
+
/**
|
61
|
+
* File being written, if it's a file.
|
62
|
+
*/
|
63
|
+
protected File file;
|
64
|
+
/**
|
65
|
+
* OutputStream being written to, if using an OutputStream.
|
66
|
+
*/
|
67
|
+
protected OutputStream output;
|
68
|
+
|
69
|
+
protected Document document;
|
70
|
+
protected PdfWriter writer;
|
71
|
+
protected PdfContentByte content;
|
72
|
+
protected PdfGraphics2D graphicContent;
|
73
|
+
/**
|
74
|
+
* Shared across instances because it's incredibly time-consuming to create.
|
75
|
+
*/
|
76
|
+
static protected DefaultFontMapper mapper;
|
77
|
+
static protected String[] fontList;
|
78
|
+
|
79
|
+
@Override
|
80
|
+
public void setPath(String path) {
|
81
|
+
this.path = path;
|
82
|
+
if (path != null) {
|
83
|
+
file = new File(path);
|
84
|
+
if (!file.isAbsolute()) {
|
85
|
+
file = null;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
if (file == null) {
|
89
|
+
throw new RuntimeException("PGraphicsPDF requires an absolute path "
|
90
|
+
+ "for the location of the output file.");
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Set the library to write to an output stream instead of a file.
|
96
|
+
* @param output
|
97
|
+
*/
|
98
|
+
public void setOutput(OutputStream output) {
|
99
|
+
this.output = output;
|
100
|
+
}
|
101
|
+
|
102
|
+
@Override
|
103
|
+
public PSurface createSurface() {
|
104
|
+
return surface = new PSurfaceNone(this);
|
105
|
+
}
|
106
|
+
|
107
|
+
@Override
|
108
|
+
protected void defaultSettings() { // ignore
|
109
|
+
super.defaultSettings();
|
110
|
+
textMode = SHAPE;
|
111
|
+
}
|
112
|
+
|
113
|
+
@Override
|
114
|
+
public void beginDraw() {
|
115
|
+
if (document == null) {
|
116
|
+
ByteBuffer.HIGH_PRECISION = true;
|
117
|
+
document = new Document(new Rectangle(width, height));
|
118
|
+
boolean missingPath = false;
|
119
|
+
try {
|
120
|
+
if (file != null) {
|
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
|
+
}
|
126
|
+
} else if (output == null) {
|
127
|
+
missingPath = true;
|
128
|
+
throw new RuntimeException("PGraphicsPDF requires a path "
|
129
|
+
+ "for the location of the output file.");
|
130
|
+
}
|
131
|
+
try {
|
132
|
+
writer = PdfWriter.getInstance(document, output);
|
133
|
+
} catch (DocumentException ex) {
|
134
|
+
Logger.getLogger(PGraphicsPDF.class.getName()).log(Level.SEVERE, null, ex);
|
135
|
+
}
|
136
|
+
document.open();
|
137
|
+
content = writer.getDirectContent();
|
138
|
+
// template = content.createTemplate(width, height);
|
139
|
+
|
140
|
+
} catch (RuntimeException re) {
|
141
|
+
if (missingPath) {
|
142
|
+
throw re; // don't re-package our own error
|
143
|
+
} else {
|
144
|
+
throw new RuntimeException("Problem saving the PDF file.", re);
|
145
|
+
}
|
146
|
+
}
|
147
|
+
g2 = new PdfGraphics2D(content, width, height);
|
148
|
+
}
|
149
|
+
|
150
|
+
// super in Java2D now creates an image buffer, don't do that
|
151
|
+
//super.beginDraw();
|
152
|
+
checkSettings();
|
153
|
+
resetMatrix(); // reset model matrix
|
154
|
+
vertexCount = 0;
|
155
|
+
pushMatrix();
|
156
|
+
}
|
157
|
+
|
158
|
+
static protected DefaultFontMapper getMapper() {
|
159
|
+
if (mapper == null) {
|
160
|
+
mapper = new DefaultFontMapper();
|
161
|
+
switch (PApplet.platform) {
|
162
|
+
case PConstants.MACOS:
|
163
|
+
try {
|
164
|
+
String homeLibraryFonts
|
165
|
+
= System.getProperty("user.home") + "/Library/Fonts";
|
166
|
+
mapper.insertDirectory(homeLibraryFonts);
|
167
|
+
} catch (Exception e) {
|
168
|
+
// might be a security issue with getProperty() and user.home
|
169
|
+
// if this sketch is running from the web
|
170
|
+
} // add the system font paths
|
171
|
+
mapper.insertDirectory("/System/Library/Fonts");
|
172
|
+
mapper.insertDirectory("/Library/Fonts");
|
173
|
+
break;
|
174
|
+
|
175
|
+
case PConstants.WINDOWS:
|
176
|
+
// how to get the windows fonts directory?
|
177
|
+
// could be c:\winnt\fonts or c:\windows\fonts or not even c:
|
178
|
+
// maybe do a Runtime.exec() on echo %WINDIR% ?
|
179
|
+
// Runtime.exec solution might be a mess on systems where the
|
180
|
+
// the backslash/colon characters not really used (i.e. JP)
|
181
|
+
|
182
|
+
// find the windows fonts folder
|
183
|
+
File roots[] = File.listRoots();
|
184
|
+
for (File root : roots) {
|
185
|
+
if (root.toString().startsWith("A:")) {
|
186
|
+
// Seems to be a problem with some machines that the A:
|
187
|
+
// drive is returned as an actual root, even if not available.
|
188
|
+
// This won't fix the issue if the same thing happens with
|
189
|
+
// other removable drive devices, but should fix the
|
190
|
+
// initial/problem as cited by the bug report:
|
191
|
+
// http://dev.processing.org/bugs/show_bug.cgi?id=478
|
192
|
+
// If not, will need to use the other fileExists() code below.
|
193
|
+
continue;
|
194
|
+
}
|
195
|
+
File folder = new File(root, "WINDOWS/Fonts");
|
196
|
+
if (folder.exists()) {
|
197
|
+
mapper.insertDirectory(folder.getAbsolutePath());
|
198
|
+
break;
|
199
|
+
}
|
200
|
+
folder = new File(root, "WINNT/Fonts");
|
201
|
+
if (folder.exists()) {
|
202
|
+
mapper.insertDirectory(folder.getAbsolutePath());
|
203
|
+
break;
|
204
|
+
}
|
205
|
+
}
|
206
|
+
break;
|
207
|
+
|
208
|
+
case PConstants.LINUX:
|
209
|
+
checkDir("/usr/share/fonts/", mapper);
|
210
|
+
checkDir("/usr/local/share/fonts/", mapper);
|
211
|
+
checkDir(System.getProperty("user.home") + "/.fonts", mapper);
|
212
|
+
break;
|
213
|
+
default:
|
214
|
+
break;
|
215
|
+
}
|
216
|
+
}
|
217
|
+
return mapper;
|
218
|
+
}
|
219
|
+
|
220
|
+
static protected void checkDir(String path, DefaultFontMapper mapper) {
|
221
|
+
File folder = new File(path);
|
222
|
+
if (folder.exists()) {
|
223
|
+
mapper.insertDirectory(path);
|
224
|
+
traverseDir(folder, mapper);
|
225
|
+
}
|
226
|
+
}
|
227
|
+
|
228
|
+
/**
|
229
|
+
* Recursive walk to get all subdirectories for font fun.Patch submitted by
|
230
|
+
* Matthias
|
231
|
+
* Breuer.(<a href="http://dev.processing.org/bugs/show_bug.cgi?id=1566">Bug
|
232
|
+
* 1566</a>)
|
233
|
+
*
|
234
|
+
* @param folder
|
235
|
+
* @param mapper
|
236
|
+
*/
|
237
|
+
static protected void traverseDir(File folder, DefaultFontMapper mapper) {
|
238
|
+
File[] files = folder.listFiles();
|
239
|
+
for (File file1 : files) {
|
240
|
+
if (file1.isDirectory()) {
|
241
|
+
mapper.insertDirectory(file1.getPath());
|
242
|
+
traverseDir(new File(file1.getPath()), mapper);
|
243
|
+
}
|
244
|
+
}
|
245
|
+
}
|
246
|
+
|
247
|
+
// endDraw() needs to be overridden so that the endDraw() from
|
248
|
+
// PGraphicsJava2D is not inherited (it calls loadPixels).
|
249
|
+
// http://dev.processing.org/bugs/show_bug.cgi?id=1169
|
250
|
+
@Override
|
251
|
+
public void endDraw() {
|
252
|
+
// Also need to pop the matrix since the matrix doesn't reset on each run
|
253
|
+
// http://dev.processing.org/bugs/show_bug.cgi?id=1227
|
254
|
+
popMatrix();
|
255
|
+
}
|
256
|
+
|
257
|
+
/**
|
258
|
+
* Call to explicitly go to the next page from within a single draw().
|
259
|
+
*/
|
260
|
+
public void nextPage() {
|
261
|
+
PStyle savedStyle = getStyle();
|
262
|
+
endDraw();
|
263
|
+
g2.dispose();
|
264
|
+
|
265
|
+
try {
|
266
|
+
// writer.setPageEmpty(false); // maybe useful later
|
267
|
+
document.newPage(); // is this bad if no addl pages are made?
|
268
|
+
} catch (Exception e) {
|
269
|
+
}
|
270
|
+
g2 = createGraphics();
|
271
|
+
beginDraw();
|
272
|
+
style(savedStyle);
|
273
|
+
}
|
274
|
+
|
275
|
+
protected Graphics2D createGraphics() {
|
276
|
+
if (textMode == SHAPE) {
|
277
|
+
return new PdfGraphics2D(content, width, height);
|
278
|
+
} else if (textMode == MODEL) {
|
279
|
+
return new PdfGraphics2D(content, width, height, getMapper());
|
280
|
+
}
|
281
|
+
// Should not be reachable...
|
282
|
+
throw new RuntimeException("Invalid textMode() selected for PDF.");
|
283
|
+
}
|
284
|
+
|
285
|
+
@Override
|
286
|
+
public void dispose() {
|
287
|
+
if (document != null) {
|
288
|
+
g2.dispose();
|
289
|
+
document.close(); // can't be done in finalize, not always called
|
290
|
+
document = null;
|
291
|
+
}
|
292
|
+
//new Exception().printStackTrace(System.out);
|
293
|
+
}
|
294
|
+
|
295
|
+
/**
|
296
|
+
* Don't open a window for this renderer, it won't be used.
|
297
|
+
* @return
|
298
|
+
*/
|
299
|
+
@Override
|
300
|
+
public boolean displayable() {
|
301
|
+
return false;
|
302
|
+
}
|
303
|
+
|
304
|
+
@Override
|
305
|
+
protected void imageImpl(PImage image,
|
306
|
+
float x1, float y1, float x2, float y2,
|
307
|
+
int u1, int v1, int u2, int v2) {
|
308
|
+
pushMatrix();
|
309
|
+
translate(x1, y1);
|
310
|
+
int imageWidth = image.width;
|
311
|
+
int imageHeight = image.height;
|
312
|
+
scale((x2 - x1) / imageWidth,
|
313
|
+
(y2 - y1) / imageHeight);
|
314
|
+
if (u2 - u1 == imageWidth && v2 - v1 == imageHeight) {
|
315
|
+
g2.drawImage((Image) image.getNative(), 0, 0, null);
|
316
|
+
} else {
|
317
|
+
PImage tmp = image.get(u1, v1, u2 - u1, v2 - v1);
|
318
|
+
g2.drawImage((Image) tmp.getNative(), 0, 0, null);
|
319
|
+
}
|
320
|
+
popMatrix();
|
321
|
+
}
|
322
|
+
|
323
|
+
//////////////////////////////////////////////////////////////
|
324
|
+
@Override
|
325
|
+
public void textFont(PFont which) {
|
326
|
+
super.textFont(which);
|
327
|
+
checkFont();
|
328
|
+
}
|
329
|
+
|
330
|
+
/**
|
331
|
+
* Change the textMode() to either SHAPE or MODEL. This resets all renderer
|
332
|
+
* settings, and therefore must be called
|
333
|
+
* <EM>before</EM> any other commands that set the fill() or the textFont()
|
334
|
+
* or anything. Unlike other renderers, use textMode() directly after the
|
335
|
+
* size() command.
|
336
|
+
*/
|
337
|
+
@Override
|
338
|
+
public void textMode(int mode) {
|
339
|
+
if (textMode != mode) {
|
340
|
+
switch (mode) {
|
341
|
+
case SHAPE:
|
342
|
+
textMode = SHAPE;
|
343
|
+
g2.dispose();
|
344
|
+
g2 = createGraphics();
|
345
|
+
break;
|
346
|
+
case MODEL:
|
347
|
+
textMode = MODEL;
|
348
|
+
g2.dispose();
|
349
|
+
g2 = createGraphics();
|
350
|
+
break;
|
351
|
+
case SCREEN:
|
352
|
+
throw new RuntimeException("textMode(SCREEN) not supported with PDF");
|
353
|
+
default:
|
354
|
+
throw new RuntimeException("That textMode() does not exist");
|
355
|
+
}
|
356
|
+
}
|
357
|
+
}
|
358
|
+
|
359
|
+
@Override
|
360
|
+
protected void textLineImpl(char buffer[], int start, int stop,
|
361
|
+
float x, float y) {
|
362
|
+
checkFont();
|
363
|
+
super.textLineImpl(buffer, start, stop, x, y);
|
364
|
+
}
|
365
|
+
|
366
|
+
//////////////////////////////////////////////////////////////
|
367
|
+
@Override
|
368
|
+
public void loadPixels() {
|
369
|
+
nope("loadPixels");
|
370
|
+
}
|
371
|
+
|
372
|
+
@Override
|
373
|
+
public void updatePixels() {
|
374
|
+
nope("updatePixels");
|
375
|
+
}
|
376
|
+
|
377
|
+
@Override
|
378
|
+
public void updatePixels(int x, int y, int c, int d) {
|
379
|
+
nope("updatePixels");
|
380
|
+
}
|
381
|
+
|
382
|
+
//
|
383
|
+
@Override
|
384
|
+
public int get(int x, int y) {
|
385
|
+
nope("get");
|
386
|
+
return 0; // not reached
|
387
|
+
}
|
388
|
+
|
389
|
+
@Override
|
390
|
+
public PImage get(int x, int y, int c, int d) {
|
391
|
+
nope("get");
|
392
|
+
return null; // not reached
|
393
|
+
}
|
394
|
+
|
395
|
+
@Override
|
396
|
+
public PImage get() {
|
397
|
+
nope("get");
|
398
|
+
return null; // not reached
|
399
|
+
}
|
400
|
+
|
401
|
+
@Override
|
402
|
+
public void set(int x, int y, int argb) {
|
403
|
+
nope("set");
|
404
|
+
}
|
405
|
+
|
406
|
+
@Override
|
407
|
+
public void set(int x, int y, PImage image) {
|
408
|
+
nope("set");
|
409
|
+
}
|
410
|
+
|
411
|
+
//
|
412
|
+
/**
|
413
|
+
*
|
414
|
+
* @param alpha
|
415
|
+
*/
|
416
|
+
@Override
|
417
|
+
public void mask(int alpha[]) {
|
418
|
+
nope("mask");
|
419
|
+
}
|
420
|
+
|
421
|
+
@Override
|
422
|
+
public void mask(PImage alpha) {
|
423
|
+
nope("mask");
|
424
|
+
}
|
425
|
+
|
426
|
+
/**
|
427
|
+
*
|
428
|
+
* @param kind
|
429
|
+
*/
|
430
|
+
@Override
|
431
|
+
public void filter(int kind) {
|
432
|
+
nope("filter");
|
433
|
+
}
|
434
|
+
|
435
|
+
@Override
|
436
|
+
public void filter(int kind, float param) {
|
437
|
+
nope("filter");
|
438
|
+
}
|
439
|
+
|
440
|
+
//
|
441
|
+
@Override
|
442
|
+
protected void blendModeImpl() {
|
443
|
+
if (blendMode != REPLACE && blendMode != BLEND) {
|
444
|
+
showMissingWarning("blendMode");
|
445
|
+
}
|
446
|
+
}
|
447
|
+
|
448
|
+
//
|
449
|
+
@Override
|
450
|
+
public void copy(int sx1, int sy1, int sx2, int sy2,
|
451
|
+
int dx1, int dy1, int dx2, int dy2) {
|
452
|
+
nope("copy");
|
453
|
+
}
|
454
|
+
|
455
|
+
/**
|
456
|
+
*
|
457
|
+
* @param src
|
458
|
+
* @param sx1
|
459
|
+
* @param sy1
|
460
|
+
* @param sx2
|
461
|
+
* @param sy2
|
462
|
+
* @param dx1
|
463
|
+
* @param dy1
|
464
|
+
* @param dx2
|
465
|
+
* @param dy2
|
466
|
+
*/
|
467
|
+
@Override
|
468
|
+
public void copy(PImage src,
|
469
|
+
int sx1, int sy1, int sx2, int sy2,
|
470
|
+
int dx1, int dy1, int dx2, int dy2) {
|
471
|
+
nope("copy");
|
472
|
+
}
|
473
|
+
|
474
|
+
//
|
475
|
+
public void blend(int sx, int sy, int dx, int dy, int mode) {
|
476
|
+
nope("blend");
|
477
|
+
}
|
478
|
+
|
479
|
+
public void blend(PImage src,
|
480
|
+
int sx, int sy, int dx, int dy, int mode) {
|
481
|
+
nope("blend");
|
482
|
+
}
|
483
|
+
|
484
|
+
@Override
|
485
|
+
public void blend(int sx1, int sy1, int sx2, int sy2,
|
486
|
+
int dx1, int dy1, int dx2, int dy2, int mode) {
|
487
|
+
nope("blend");
|
488
|
+
}
|
489
|
+
|
490
|
+
@Override
|
491
|
+
public void blend(PImage src,
|
492
|
+
int sx1, int sy1, int sx2, int sy2,
|
493
|
+
int dx1, int dy1, int dx2, int dy2, int mode) {
|
494
|
+
nope("blend");
|
495
|
+
}
|
496
|
+
|
497
|
+
//
|
498
|
+
@Override
|
499
|
+
public boolean save(String filename) {
|
500
|
+
nope("save");
|
501
|
+
return false;
|
502
|
+
}
|
503
|
+
|
504
|
+
//////////////////////////////////////////////////////////////
|
505
|
+
/**
|
506
|
+
* On Linux or any other platform, you'll need to add the directories by
|
507
|
+
* hand. (If there are actual standards here that we can use as a starting
|
508
|
+
* point, please file a bug to make a note of it)
|
509
|
+
*
|
510
|
+
* @param directory
|
511
|
+
*/
|
512
|
+
public void addFonts(String directory) {
|
513
|
+
mapper.insertDirectory(directory);
|
514
|
+
}
|
515
|
+
|
516
|
+
/**
|
517
|
+
* Check whether the specified font can be used with the PDF library.
|
518
|
+
*
|
519
|
+
*/
|
520
|
+
protected void checkFont() {
|
521
|
+
Font awtFont = (Font) textFont.getNative();
|
522
|
+
if (awtFont == null) { // always need a native font or reference to it
|
523
|
+
throw new RuntimeException("Use createFont() instead of loadFont() "
|
524
|
+
+ "when drawing text using the PDF library.");
|
525
|
+
} else if (textMode != SHAPE) {
|
526
|
+
if (textFont.isStream()) {
|
527
|
+
throw new RuntimeException("Use textMode(SHAPE) with PDF when loading "
|
528
|
+
+ ".ttf and .otf files with createFont().");
|
529
|
+
} else if (mapper.getAliases().get(textFont.getName()) == null) {
|
530
|
+
//System.out.println("alias for " + name + " = " + mapper.getAliases().get(name));
|
531
|
+
// System.err.println("Use PGraphicsPDF.listFonts() to get a list of " +
|
532
|
+
// "fonts that can be used with PDF.");
|
533
|
+
// throw new RuntimeException("The font “" + textFont.getName() + "” " +
|
534
|
+
// "cannot be used with PDF Export.");
|
535
|
+
if (textFont.getName().equals("Lucida Sans")) {
|
536
|
+
throw new RuntimeException("Use textMode(SHAPE) with the default "
|
537
|
+
+ "font when exporting to PDF.");
|
538
|
+
} else {
|
539
|
+
throw new RuntimeException("Use textMode(SHAPE) with "
|
540
|
+
+ "“" + textFont.getName() + "” "
|
541
|
+
+ "when exporting to PDF.");
|
542
|
+
}
|
543
|
+
}
|
544
|
+
}
|
545
|
+
}
|
546
|
+
|
547
|
+
/**
|
548
|
+
* List the fonts known to the PDF renderer.This is like PFont.list(),
|
549
|
+
* however not all those fonts are available by default.
|
550
|
+
*
|
551
|
+
* @return
|
552
|
+
*/
|
553
|
+
static public String[] listFonts() {
|
554
|
+
if (fontList == null) {
|
555
|
+
HashMap<?, ?> map = getMapper().getAliases();
|
556
|
+
// Set entries = map.entrySet();
|
557
|
+
// fontList = new String[entries.size()];
|
558
|
+
fontList = new String[map.size()];
|
559
|
+
int count = 0;
|
560
|
+
for (Object key : map.keySet()) {
|
561
|
+
// for (Object entry : map.entrySet()) {
|
562
|
+
// fontList[count++] = (String) ((Map.Entry) entry).getKey();
|
563
|
+
fontList[count++] = (String) key;
|
564
|
+
}
|
565
|
+
// Iterator it = entries.iterator();
|
566
|
+
// int count = 0;
|
567
|
+
// while (it.hasNext()) {
|
568
|
+
// Map.Entry entry = (Map.Entry) it.next();
|
569
|
+
// //System.out.println(entry.getKey() + "-->" + entry.getValue());
|
570
|
+
// fontList[count++] = (String) entry.getKey();
|
571
|
+
// }
|
572
|
+
Arrays.sort(fontList);
|
573
|
+
}
|
574
|
+
return fontList;
|
575
|
+
}
|
576
|
+
|
577
|
+
//////////////////////////////////////////////////////////////
|
578
|
+
protected void nope(String function) {
|
579
|
+
throw new RuntimeException("No " + function + "() for " + getClass().getSimpleName());
|
580
|
+
}
|
581
|
+
}
|