propane 3.1.0.pre-java → 3.2.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/CHANGELOG.md +1 -5
- data/README.md +23 -12
- data/Rakefile +23 -12
- data/lib/propane/helpers/version_error.rb +6 -0
- data/lib/propane/runner.rb +12 -0
- data/lib/propane/version.rb +1 -1
- data/library/slider/slider.rb +1 -1
- data/mvnw +234 -0
- data/mvnw.cmd +145 -0
- data/pom.xml +28 -27
- data/propane.gemspec +2 -2
- data/src/main/java/japplemenubar/JAppleMenuBar.java +41 -47
- data/src/main/java/monkstone/ColorUtil.java +1 -1
- data/src/main/java/monkstone/MathToolModule.java +12 -11
- data/src/main/java/monkstone/PropaneLibrary.java +9 -10
- data/src/main/java/monkstone/core/LibraryProxy.java +124 -113
- data/src/main/java/monkstone/fastmath/Deglut.java +86 -89
- data/src/main/java/monkstone/filechooser/Chooser.java +7 -13
- data/src/main/java/monkstone/noise/SimplexNoise.java +0 -1
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +4 -4
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +9 -9
- data/src/main/java/monkstone/slider/SimpleSlider.java +0 -9
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +11 -13
- data/src/main/java/monkstone/slider/Slider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +8 -9
- data/src/main/java/monkstone/vecmath/AppRender.java +2 -2
- data/src/main/java/monkstone/vecmath/ShapeRender.java +2 -2
- data/src/main/java/monkstone/vecmath/package-info.java +2 -2
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
- data/src/main/java/monkstone/videoevent/VideoInterface.java +11 -5
- data/src/main/java/monkstone/videoevent/package-info.java +2 -2
- data/src/main/java/processing/awt/PGraphicsJava2D.java +1742 -2243
- data/src/main/java/processing/awt/PShapeJava2D.java +268 -270
- data/src/main/java/processing/awt/PSurfaceAWT.java +821 -920
- data/src/main/java/processing/core/DesktopHandler.java +94 -0
- data/src/main/java/processing/core/PApplet.java +14170 -14082
- data/src/main/java/processing/core/PConstants.java +447 -473
- data/src/main/java/processing/core/PFont.java +867 -873
- data/src/main/java/processing/core/PGraphics.java +7193 -7428
- data/src/main/java/processing/core/PImage.java +3051 -3117
- data/src/main/java/processing/core/PMatrix.java +159 -172
- data/src/main/java/processing/core/PMatrix2D.java +403 -444
- data/src/main/java/processing/core/PMatrix3D.java +735 -749
- data/src/main/java/processing/core/PShape.java +2651 -2793
- data/src/main/java/processing/core/PShapeOBJ.java +415 -422
- data/src/main/java/processing/core/PShapeSVG.java +1466 -1475
- data/src/main/java/processing/core/PStyle.java +37 -40
- data/src/main/java/processing/core/PSurface.java +98 -103
- data/src/main/java/processing/core/PSurfaceNone.java +208 -236
- data/src/main/java/processing/core/PVector.java +961 -990
- data/src/main/java/processing/data/DoubleDict.java +709 -753
- data/src/main/java/processing/data/DoubleList.java +695 -748
- data/src/main/java/processing/data/FloatDict.java +702 -746
- data/src/main/java/processing/data/FloatList.java +697 -751
- data/src/main/java/processing/data/IntDict.java +673 -718
- data/src/main/java/processing/data/IntList.java +633 -699
- data/src/main/java/processing/data/JSONArray.java +873 -931
- data/src/main/java/processing/data/JSONObject.java +1165 -1262
- data/src/main/java/processing/data/JSONTokener.java +341 -351
- data/src/main/java/processing/data/LongDict.java +662 -707
- data/src/main/java/processing/data/LongList.java +634 -700
- data/src/main/java/processing/data/Sort.java +41 -37
- data/src/main/java/processing/data/StringDict.java +486 -522
- data/src/main/java/processing/data/StringList.java +580 -624
- data/src/main/java/processing/data/Table.java +3508 -3686
- data/src/main/java/processing/data/TableRow.java +183 -182
- data/src/main/java/processing/data/XML.java +883 -957
- data/src/main/java/processing/event/Event.java +66 -87
- data/src/main/java/processing/event/KeyEvent.java +41 -48
- data/src/main/java/processing/event/MouseEvent.java +93 -103
- data/src/main/java/processing/event/TouchEvent.java +6 -10
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +5 -69
- data/src/main/java/processing/javafx/PSurfaceFX.java +2 -7
- data/src/main/java/processing/opengl/FontTexture.java +270 -290
- data/src/main/java/processing/opengl/FrameBuffer.java +363 -375
- data/src/main/java/processing/opengl/LinePath.java +500 -543
- data/src/main/java/processing/opengl/LineStroker.java +582 -593
- data/src/main/java/processing/opengl/PGL.java +2881 -2904
- data/src/main/java/processing/opengl/PGraphics2D.java +315 -408
- data/src/main/java/processing/opengl/PGraphics3D.java +72 -107
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12043 -12230
- data/src/main/java/processing/opengl/PJOGL.java +1681 -1745
- data/src/main/java/processing/opengl/PShader.java +1257 -1260
- data/src/main/java/processing/opengl/PShapeOpenGL.java +4599 -4662
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1030 -1047
- data/src/main/java/processing/opengl/Texture.java +1397 -1462
- data/src/main/java/processing/opengl/VertexBuffer.java +55 -57
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/vendors/Rakefile +1 -1
- metadata +12 -8
- data/src/main/java/processing/core/ThinkDifferent.java +0 -70
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
|
2
|
-
|
|
3
1
|
/*
|
|
4
2
|
Part of the Processing project - http://processing.org
|
|
5
3
|
|
|
@@ -20,8 +18,7 @@
|
|
|
20
18
|
Public License along with this library; if not, write to the
|
|
21
19
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
22
20
|
Boston, MA 02111-1307 USA
|
|
23
|
-
*/
|
|
24
|
-
|
|
21
|
+
*/
|
|
25
22
|
package processing.core;
|
|
26
23
|
|
|
27
24
|
import java.awt.*;
|
|
@@ -33,7 +30,6 @@ import java.io.*;
|
|
|
33
30
|
import java.util.Arrays;
|
|
34
31
|
import java.util.HashMap;
|
|
35
32
|
|
|
36
|
-
|
|
37
33
|
/**
|
|
38
34
|
* Grayscale bitmap font class used by Processing.
|
|
39
35
|
* <P>
|
|
@@ -55,6 +51,7 @@ import java.util.HashMap;
|
|
|
55
51
|
*
|
|
56
52
|
* ^^^^^^^^^^^^^^ setWidth (width displaced by char)
|
|
57
53
|
* </PRE>
|
|
54
|
+
*
|
|
58
55
|
* @webref typography
|
|
59
56
|
* @see PApplet#loadFont(String)
|
|
60
57
|
* @see PApplet#createFont(String, float, boolean, char[])
|
|
@@ -62,96 +59,104 @@ import java.util.HashMap;
|
|
|
62
59
|
*/
|
|
63
60
|
public class PFont implements PConstants {
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Number of character glyphs in this font.
|
|
64
|
+
*/
|
|
65
|
+
protected int glyphCount;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Actual glyph data. The length of this array won't necessarily be the same
|
|
69
|
+
* size as glyphCount, in cases where lazy font loading is in use.
|
|
70
|
+
*/
|
|
71
|
+
protected Glyph[] glyphs;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Name of the font as seen by Java when it was created. If the font is
|
|
75
|
+
* available, the native version will be used.
|
|
76
|
+
*/
|
|
77
|
+
protected String name;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Postscript name of the font that this bitmap was created from.
|
|
81
|
+
*/
|
|
82
|
+
protected String psname;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The original size of the font when it was first created
|
|
86
|
+
*/
|
|
87
|
+
protected int size;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Default density set to 1 for backwards compatibility with loadFont().
|
|
91
|
+
*/
|
|
92
|
+
protected int density = 1;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* true if smoothing was enabled for this font, used for native impl
|
|
96
|
+
*/
|
|
97
|
+
protected boolean smooth;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The ascent of the font. If the 'd' character is present in this PFont,
|
|
101
|
+
* this value is replaced with its pixel height, because the values returned
|
|
102
|
+
* by FontMetrics.getAscent() seem to be terrible.
|
|
103
|
+
*/
|
|
104
|
+
protected int ascent;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The descent of the font. If the 'p' character is present in this PFont,
|
|
108
|
+
* this value is replaced with its lowest pixel height, because the values
|
|
109
|
+
* returned by FontMetrics.getDescent() are gross.
|
|
110
|
+
*/
|
|
111
|
+
protected int descent;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* A more efficient array lookup for straight ASCII characters. For Unicode
|
|
115
|
+
* characters, a QuickSort-style search is used.
|
|
116
|
+
*/
|
|
117
|
+
protected int[] ascii;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* True if this font is set to load dynamically. This is the default when
|
|
121
|
+
* createFont() method is called without a character set. Bitmap versions of
|
|
122
|
+
* characters are only created when prompted by an index() call.
|
|
123
|
+
*/
|
|
124
|
+
protected boolean lazy;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Native Java version of the font. If possible, this allows the PGraphics
|
|
128
|
+
* subclass to just use Java's font rendering stuff in situations where
|
|
129
|
+
* that's faster.
|
|
130
|
+
*/
|
|
131
|
+
protected Font font;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* True if this font was loaded from an InputStream, rather than by name
|
|
135
|
+
* from the OS. It's best to use the native version of a font loaded from a
|
|
136
|
+
* TTF file, since that will ensure that the font is available when the
|
|
137
|
+
* sketch is exported.
|
|
138
|
+
*/
|
|
139
|
+
protected boolean stream;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* True if this font should return 'null' for getFont(), so that the native
|
|
143
|
+
* font will be used to create a subset, but the native version of the font
|
|
144
|
+
* will not be used.
|
|
145
|
+
*/
|
|
146
|
+
protected boolean subsetting;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* True if already tried to find the native AWT version of this font.
|
|
150
|
+
*/
|
|
151
|
+
protected boolean fontSearched;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Array of the native system fonts. Used to lookup native fonts by their
|
|
155
|
+
* PostScript name. This is a workaround for a several year old Apple Java
|
|
156
|
+
* bug that they can't be bothered to fix.
|
|
157
|
+
*/
|
|
158
|
+
static protected Font[] fonts;
|
|
159
|
+
static protected HashMap<String, Font> fontDifferent;
|
|
155
160
|
|
|
156
161
|
// /**
|
|
157
162
|
// * If not null, this font is set to load dynamically. This is the default
|
|
@@ -159,129 +164,126 @@ public class PFont implements PConstants {
|
|
|
159
164
|
// * versions of characters are only created when prompted by an index() call.
|
|
160
165
|
// */
|
|
161
166
|
// protected Font lazyFont;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
protected BufferedImage lazyImage;
|
|
168
|
+
protected Graphics2D lazyGraphics;
|
|
169
|
+
protected FontMetrics lazyMetrics;
|
|
170
|
+
protected int[] lazySamples;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* for subclasses that need to store metadata about the font
|
|
174
|
+
*/
|
|
169
175
|
// protected HashMap<PGraphics, Object> cacheMap;
|
|
176
|
+
/**
|
|
177
|
+
* @nowebref
|
|
178
|
+
*/
|
|
179
|
+
public PFont() {
|
|
180
|
+
} // for subclasses
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* ( begin auto-generated from PFont.xml )
|
|
184
|
+
*
|
|
185
|
+
* PFont is the font class for Processing. To create a font to use with
|
|
186
|
+
* Processing, select "Create Font..." from the Tools menu. This will create
|
|
187
|
+
* a font in the format Processing requires and also adds it to the current
|
|
188
|
+
* sketch's data directory. Processing displays fonts using the .vlw font
|
|
189
|
+
* format, which uses images for each letter, rather than defining them
|
|
190
|
+
* through vector data. The <b>loadFont()</b> function constructs a new font
|
|
191
|
+
* and <b>textFont()</b> makes a font active. The
|
|
192
|
+
* <b>list()</b> method creates a list of the fonts installed on the
|
|
193
|
+
* computer, which is useful information to use with the
|
|
194
|
+
* <b>createFont()</b> function for dynamically converting fonts into a
|
|
195
|
+
* format to use with Processing.
|
|
196
|
+
*
|
|
197
|
+
* ( end auto-generated )
|
|
198
|
+
*
|
|
199
|
+
* @nowebref
|
|
200
|
+
* @param font font the font object to create from
|
|
201
|
+
* @param smooth smooth true to enable smoothing/anti-aliasing
|
|
202
|
+
*/
|
|
203
|
+
public PFont(Font font, boolean smooth) {
|
|
204
|
+
this(font, smooth, null);
|
|
205
|
+
}
|
|
170
206
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
//mbox2 = 0;
|
|
223
|
-
|
|
224
|
-
int initialCount = 10;
|
|
225
|
-
glyphs = new Glyph[initialCount];
|
|
226
|
-
|
|
227
|
-
ascii = new int[128];
|
|
228
|
-
Arrays.fill(ascii, -1);
|
|
229
|
-
|
|
230
|
-
int mbox3 = size * 3;
|
|
231
|
-
|
|
232
|
-
lazyImage = new BufferedImage(mbox3, mbox3, BufferedImage.TYPE_INT_RGB);
|
|
233
|
-
lazyGraphics = (Graphics2D) lazyImage.getGraphics();
|
|
234
|
-
lazyGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
|
235
|
-
smooth ?
|
|
236
|
-
RenderingHints.VALUE_ANTIALIAS_ON :
|
|
237
|
-
RenderingHints.VALUE_ANTIALIAS_OFF);
|
|
238
|
-
// adding this for post-1.0.9
|
|
239
|
-
lazyGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
|
240
|
-
smooth ?
|
|
241
|
-
RenderingHints.VALUE_TEXT_ANTIALIAS_ON :
|
|
242
|
-
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
|
243
|
-
|
|
244
|
-
lazyGraphics.setFont(font);
|
|
245
|
-
lazyMetrics = lazyGraphics.getFontMetrics();
|
|
246
|
-
lazySamples = new int[mbox3 * mbox3];
|
|
247
|
-
|
|
248
|
-
// These values are terrible/unusable. Verified again for Processing 1.1.
|
|
249
|
-
// They vary widely per-platform and per-font, so instead we'll use the
|
|
250
|
-
// calculate-by-hand method of measuring pixels in characters.
|
|
251
|
-
//ascent = lazyMetrics.getAscent();
|
|
252
|
-
//descent = lazyMetrics.getDescent();
|
|
253
|
-
|
|
254
|
-
if (charset == null) {
|
|
255
|
-
lazy = true;
|
|
207
|
+
/**
|
|
208
|
+
* Create a new image-based font on the fly. If charset is set to null, the
|
|
209
|
+
* characters will only be created as bitmaps when they're drawn.
|
|
210
|
+
*
|
|
211
|
+
* @nowebref
|
|
212
|
+
* @param charset array of all unicode chars that should be included
|
|
213
|
+
*/
|
|
214
|
+
public PFont(Font font, boolean smooth, char charset[]) {
|
|
215
|
+
// save this so that we can use the native version
|
|
216
|
+
this.font = font;
|
|
217
|
+
this.smooth = smooth;
|
|
218
|
+
|
|
219
|
+
name = font.getName();
|
|
220
|
+
psname = font.getPSName();
|
|
221
|
+
size = font.getSize();
|
|
222
|
+
|
|
223
|
+
// no, i'm not interested in getting off the couch
|
|
224
|
+
//lazy = true;
|
|
225
|
+
// not sure what else to do here
|
|
226
|
+
//mbox2 = 0;
|
|
227
|
+
int initialCount = 10;
|
|
228
|
+
glyphs = new Glyph[initialCount];
|
|
229
|
+
|
|
230
|
+
ascii = new int[128];
|
|
231
|
+
Arrays.fill(ascii, -1);
|
|
232
|
+
|
|
233
|
+
int mbox3 = size * 3;
|
|
234
|
+
|
|
235
|
+
lazyImage = new BufferedImage(mbox3, mbox3, BufferedImage.TYPE_INT_RGB);
|
|
236
|
+
lazyGraphics = (Graphics2D) lazyImage.getGraphics();
|
|
237
|
+
lazyGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
|
238
|
+
smooth
|
|
239
|
+
? RenderingHints.VALUE_ANTIALIAS_ON
|
|
240
|
+
: RenderingHints.VALUE_ANTIALIAS_OFF);
|
|
241
|
+
// adding this for post-1.0.9
|
|
242
|
+
lazyGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
|
243
|
+
smooth
|
|
244
|
+
? RenderingHints.VALUE_TEXT_ANTIALIAS_ON
|
|
245
|
+
: RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
|
246
|
+
|
|
247
|
+
lazyGraphics.setFont(font);
|
|
248
|
+
lazyMetrics = lazyGraphics.getFontMetrics();
|
|
249
|
+
lazySamples = new int[mbox3 * mbox3];
|
|
250
|
+
|
|
251
|
+
// These values are terrible/unusable. Verified again for Processing 1.1.
|
|
252
|
+
// They vary widely per-platform and per-font, so instead we'll use the
|
|
253
|
+
// calculate-by-hand method of measuring pixels in characters.
|
|
254
|
+
//ascent = lazyMetrics.getAscent();
|
|
255
|
+
//descent = lazyMetrics.getDescent();
|
|
256
|
+
if (charset == null) {
|
|
257
|
+
lazy = true;
|
|
256
258
|
// lazyFont = font;
|
|
257
259
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
260
|
+
} else {
|
|
261
|
+
// charset needs to be sorted to make index lookup run more quickly
|
|
262
|
+
// http://dev.processing.org/bugs/show_bug.cgi?id=494
|
|
263
|
+
Arrays.sort(charset);
|
|
264
|
+
|
|
265
|
+
glyphs = new Glyph[charset.length];
|
|
266
|
+
|
|
267
|
+
glyphCount = 0;
|
|
268
|
+
for (char c : charset) {
|
|
269
|
+
if (font.canDisplay(c)) {
|
|
270
|
+
Glyph glyf = new Glyph(c);
|
|
271
|
+
if (glyf.value < 128) {
|
|
272
|
+
ascii[glyf.value] = glyphCount;
|
|
273
|
+
}
|
|
274
|
+
glyf.index = glyphCount;
|
|
275
|
+
glyphs[glyphCount++] = glyf;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
276
278
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
// shorten the array if necessary
|
|
280
|
+
if (glyphCount != charset.length) {
|
|
281
|
+
glyphs = (Glyph[]) PApplet.subset(glyphs, 0, glyphCount);
|
|
282
|
+
}
|
|
281
283
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
284
|
+
// foreign font, so just make ascent the max topExtent
|
|
285
|
+
// for > 1.0.9, not doing this anymore.
|
|
286
|
+
// instead using getAscent() and getDescent() values for these cases.
|
|
285
287
|
// if ((ascent == 0) && (descent == 0)) {
|
|
286
288
|
// //for (int i = 0; i < charCount; i++) {
|
|
287
289
|
// for (Glyph glyph : glyphs) {
|
|
@@ -300,575 +302,562 @@ public class PFont implements PConstants {
|
|
|
300
302
|
// }
|
|
301
303
|
// }
|
|
302
304
|
// }
|
|
303
|
-
|
|
305
|
+
}
|
|
304
306
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
307
|
+
// If not already created, just create these two characters to calculate
|
|
308
|
+
// the ascent and descent values for the font. This was tested to only
|
|
309
|
+
// require 5-10 ms on a 2.4 GHz MacBook Pro.
|
|
310
|
+
// In versions 1.0.9 and earlier, fonts that could not display d or p
|
|
311
|
+
// used the max up/down values as calculated by looking through the font.
|
|
312
|
+
// That's no longer valid with the auto-generating fonts, so we'll just
|
|
313
|
+
// use getAscent() and getDescent() in such (minor) cases.
|
|
314
|
+
if (ascent == 0) {
|
|
315
|
+
if (font.canDisplay('d')) {
|
|
316
|
+
new Glyph('d');
|
|
317
|
+
} else {
|
|
318
|
+
ascent = lazyMetrics.getAscent();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (descent == 0) {
|
|
322
|
+
if (font.canDisplay('p')) {
|
|
323
|
+
new Glyph('p');
|
|
324
|
+
} else {
|
|
325
|
+
descent = lazyMetrics.getDescent();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
325
328
|
}
|
|
326
|
-
}
|
|
327
329
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
this.density = density;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* @nowebref
|
|
344
|
-
* @param input InputStream
|
|
345
|
-
*/
|
|
346
|
-
public PFont(InputStream input) throws IOException {
|
|
347
|
-
DataInputStream is = new DataInputStream(input);
|
|
348
|
-
|
|
349
|
-
// number of character images stored in this font
|
|
350
|
-
glyphCount = is.readInt();
|
|
351
|
-
|
|
352
|
-
// used to be the bitCount, but now used for version number.
|
|
353
|
-
// version 8 is any font before 69, so 9 is anything from 83+
|
|
354
|
-
// 9 was buggy so gonna increment to 10.
|
|
355
|
-
int version = is.readInt();
|
|
356
|
-
|
|
357
|
-
// this was formerly ignored, now it's the actual font size
|
|
358
|
-
//mbox = is.readInt();
|
|
359
|
-
size = is.readInt();
|
|
360
|
-
|
|
361
|
-
// this was formerly mboxY, the one that was used
|
|
362
|
-
// this will make new fonts downward compatible
|
|
363
|
-
is.readInt(); // ignore the other mbox attribute
|
|
364
|
-
|
|
365
|
-
ascent = is.readInt(); // formerly baseHt (zero/ignored)
|
|
366
|
-
descent = is.readInt(); // formerly ignored struct padding
|
|
367
|
-
|
|
368
|
-
// allocate enough space for the character info
|
|
369
|
-
glyphs = new Glyph[glyphCount];
|
|
370
|
-
|
|
371
|
-
ascii = new int[128];
|
|
372
|
-
Arrays.fill(ascii, -1);
|
|
373
|
-
|
|
374
|
-
// read the information about the individual characters
|
|
375
|
-
for (int i = 0; i < glyphCount; i++) {
|
|
376
|
-
Glyph glyph = new Glyph(is);
|
|
377
|
-
// cache locations of the ascii charset
|
|
378
|
-
if (glyph.value < 128) {
|
|
379
|
-
ascii[glyph.value] = i;
|
|
380
|
-
}
|
|
381
|
-
glyph.index = i;
|
|
382
|
-
glyphs[i] = glyph;
|
|
330
|
+
/**
|
|
331
|
+
* Adds an additional parameter that indicates the font came from a file,
|
|
332
|
+
* not a built-in OS font.
|
|
333
|
+
*
|
|
334
|
+
* @nowebref
|
|
335
|
+
*/
|
|
336
|
+
public PFont(Font font, boolean smooth, char charset[],
|
|
337
|
+
boolean stream, int density) {
|
|
338
|
+
this(font, smooth, charset);
|
|
339
|
+
this.stream = stream;
|
|
340
|
+
this.density = density;
|
|
383
341
|
}
|
|
384
342
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
343
|
+
/**
|
|
344
|
+
* @nowebref @param input InputStream
|
|
345
|
+
*/
|
|
346
|
+
public PFont(InputStream input) throws IOException {
|
|
347
|
+
DataInputStream is = new DataInputStream(input);
|
|
391
348
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
349
|
+
// number of character images stored in this font
|
|
350
|
+
glyphCount = is.readInt();
|
|
395
351
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
if (version == 11) {
|
|
401
|
-
smooth = is.readBoolean();
|
|
402
|
-
}
|
|
403
|
-
// See if there's a native version of this font that can be used,
|
|
404
|
-
// in case that's of interest later.
|
|
405
|
-
// findNative();
|
|
406
|
-
}
|
|
352
|
+
// used to be the bitCount, but now used for version number.
|
|
353
|
+
// version 8 is any font before 69, so 9 is anything from 83+
|
|
354
|
+
// 9 was buggy so gonna increment to 10.
|
|
355
|
+
int version = is.readInt();
|
|
407
356
|
|
|
357
|
+
// this was formerly ignored, now it's the actual font size
|
|
358
|
+
//mbox = is.readInt();
|
|
359
|
+
size = is.readInt();
|
|
408
360
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
* This is used by the Create Font tool, or whatever anyone else dreams
|
|
413
|
-
* up for messing with fonts themselves.
|
|
414
|
-
* <p>
|
|
415
|
-
* It is assumed that the calling class will handle closing
|
|
416
|
-
* the stream when finished.
|
|
417
|
-
*/
|
|
418
|
-
public void save(OutputStream output) throws IOException {
|
|
419
|
-
DataOutputStream os = new DataOutputStream(output);
|
|
361
|
+
// this was formerly mboxY, the one that was used
|
|
362
|
+
// this will make new fonts downward compatible
|
|
363
|
+
is.readInt(); // ignore the other mbox attribute
|
|
420
364
|
|
|
421
|
-
|
|
365
|
+
ascent = is.readInt(); // formerly baseHt (zero/ignored)
|
|
366
|
+
descent = is.readInt(); // formerly ignored struct padding
|
|
422
367
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
psname = "";
|
|
426
|
-
}
|
|
368
|
+
// allocate enough space for the character info
|
|
369
|
+
glyphs = new Glyph[glyphCount];
|
|
427
370
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
os.writeInt(0); // formerly mboxY, now ignored
|
|
431
|
-
os.writeInt(ascent); // formerly baseHt (was ignored)
|
|
432
|
-
os.writeInt(descent); // formerly struct padding for c version
|
|
371
|
+
ascii = new int[128];
|
|
372
|
+
Arrays.fill(ascii, -1);
|
|
433
373
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
374
|
+
// read the information about the individual characters
|
|
375
|
+
for (int i = 0; i < glyphCount; i++) {
|
|
376
|
+
Glyph glyph = new Glyph(is);
|
|
377
|
+
// cache locations of the ascii charset
|
|
378
|
+
if (glyph.value < 128) {
|
|
379
|
+
ascii[glyph.value] = i;
|
|
380
|
+
}
|
|
381
|
+
glyph.index = i;
|
|
382
|
+
glyphs[i] = glyph;
|
|
383
|
+
}
|
|
437
384
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
385
|
+
// not a roman font, so throw an error and ask to re-build.
|
|
386
|
+
// that way can avoid a bunch of error checking hacks in here.
|
|
387
|
+
if ((ascent == 0) && (descent == 0)) {
|
|
388
|
+
throw new RuntimeException("Please use \"Create Font\" to "
|
|
389
|
+
+ "re-create this font.");
|
|
390
|
+
}
|
|
441
391
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
os.writeBoolean(smooth);
|
|
392
|
+
for (Glyph glyph : glyphs) {
|
|
393
|
+
glyph.readBitmap(is);
|
|
394
|
+
}
|
|
446
395
|
|
|
447
|
-
|
|
448
|
-
|
|
396
|
+
if (version >= 10) { // includes the font name at the end of the file
|
|
397
|
+
name = is.readUTF();
|
|
398
|
+
psname = is.readUTF();
|
|
399
|
+
}
|
|
400
|
+
if (version == 11) {
|
|
401
|
+
smooth = is.readBoolean();
|
|
402
|
+
}
|
|
403
|
+
// See if there's a native version of this font that can be used,
|
|
404
|
+
// in case that's of interest later.
|
|
405
|
+
// findNative();
|
|
406
|
+
}
|
|
449
407
|
|
|
408
|
+
/**
|
|
409
|
+
* Write this PFont to an OutputStream.
|
|
410
|
+
* <p>
|
|
411
|
+
* This is used by the Create Font tool, or whatever anyone else dreams up
|
|
412
|
+
* for messing with fonts themselves.
|
|
413
|
+
* <p>
|
|
414
|
+
* It is assumed that the calling class will handle closing the stream when
|
|
415
|
+
* finished.
|
|
416
|
+
*/
|
|
417
|
+
public void save(OutputStream output) throws IOException {
|
|
418
|
+
DataOutputStream os = new DataOutputStream(output);
|
|
419
|
+
|
|
420
|
+
os.writeInt(glyphCount);
|
|
421
|
+
|
|
422
|
+
if ((name == null) || (psname == null)) {
|
|
423
|
+
name = "";
|
|
424
|
+
psname = "";
|
|
425
|
+
}
|
|
450
426
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
Glyph glyph = new Glyph(c);
|
|
427
|
+
os.writeInt(11); // formerly numBits, now used for version number
|
|
428
|
+
os.writeInt(size); // formerly mboxX (was 64, now 48)
|
|
429
|
+
os.writeInt(0); // formerly mboxY, now ignored
|
|
430
|
+
os.writeInt(ascent); // formerly baseHt (was ignored)
|
|
431
|
+
os.writeInt(descent); // formerly struct padding for c version
|
|
457
432
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
if (glyphCount == 0) {
|
|
462
|
-
glyph.index = 0;
|
|
463
|
-
glyphs[glyphCount] = glyph;
|
|
464
|
-
if (glyph.value < 128) {
|
|
465
|
-
ascii[glyph.value] = 0;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
} else if (glyphs[glyphCount-1].value < glyph.value) {
|
|
469
|
-
glyphs[glyphCount] = glyph;
|
|
470
|
-
if (glyph.value < 128) {
|
|
471
|
-
ascii[glyph.value] = glyphCount;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
} else {
|
|
475
|
-
for (int i = 0; i < glyphCount; i++) {
|
|
476
|
-
if (glyphs[i].value > c) {
|
|
477
|
-
for (int j = glyphCount; j > i; --j) {
|
|
478
|
-
glyphs[j] = glyphs[j-1];
|
|
479
|
-
if (glyphs[j].value < 128) {
|
|
480
|
-
ascii[glyphs[j].value] = j;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
glyph.index = i;
|
|
484
|
-
glyphs[i] = glyph;
|
|
485
|
-
// cache locations of the ascii charset
|
|
486
|
-
if (c < 128) ascii[c] = i;
|
|
487
|
-
break;
|
|
433
|
+
for (int i = 0; i < glyphCount; i++) {
|
|
434
|
+
glyphs[i].writeHeader(os);
|
|
488
435
|
}
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
glyphCount++;
|
|
492
|
-
}
|
|
493
436
|
|
|
437
|
+
for (int i = 0; i < glyphCount; i++) {
|
|
438
|
+
glyphs[i].writeBitmap(os);
|
|
439
|
+
}
|
|
494
440
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
441
|
+
// version 11
|
|
442
|
+
os.writeUTF(name);
|
|
443
|
+
os.writeUTF(psname);
|
|
444
|
+
os.writeBoolean(smooth);
|
|
498
445
|
|
|
446
|
+
os.flush();
|
|
447
|
+
}
|
|
499
448
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
449
|
+
/**
|
|
450
|
+
* Create a new glyph, and add the character to the current font.
|
|
451
|
+
*
|
|
452
|
+
* @param c character to create an image for.
|
|
453
|
+
*/
|
|
454
|
+
protected void addGlyph(char c) {
|
|
455
|
+
Glyph glyph = new Glyph(c);
|
|
503
456
|
|
|
457
|
+
if (glyphCount == glyphs.length) {
|
|
458
|
+
glyphs = (Glyph[]) PApplet.expand(glyphs);
|
|
459
|
+
}
|
|
460
|
+
if (glyphCount == 0) {
|
|
461
|
+
glyph.index = 0;
|
|
462
|
+
glyphs[glyphCount] = glyph;
|
|
463
|
+
if (glyph.value < 128) {
|
|
464
|
+
ascii[glyph.value] = 0;
|
|
465
|
+
}
|
|
504
466
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
public void setNative(Object font) {
|
|
511
|
-
this.font = (Font) font;
|
|
512
|
-
}
|
|
467
|
+
} else if (glyphs[glyphCount - 1].value < glyph.value) {
|
|
468
|
+
glyphs[glyphCount] = glyph;
|
|
469
|
+
if (glyph.value < 128) {
|
|
470
|
+
ascii[glyph.value] = glyphCount;
|
|
471
|
+
}
|
|
513
472
|
|
|
473
|
+
} else {
|
|
474
|
+
for (int i = 0; i < glyphCount; i++) {
|
|
475
|
+
if (glyphs[i].value > c) {
|
|
476
|
+
for (int j = glyphCount; j > i; --j) {
|
|
477
|
+
glyphs[j] = glyphs[j - 1];
|
|
478
|
+
if (glyphs[j].value < 128) {
|
|
479
|
+
ascii[glyphs[j].value] = j;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
glyph.index = i;
|
|
483
|
+
glyphs[i] = glyph;
|
|
484
|
+
// cache locations of the ascii charset
|
|
485
|
+
if (c < 128) {
|
|
486
|
+
ascii[c] = i;
|
|
487
|
+
}
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
glyphCount++;
|
|
493
|
+
}
|
|
514
494
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
*/
|
|
519
|
-
@Deprecated
|
|
520
|
-
public Font getFont() {
|
|
521
|
-
return font;
|
|
522
|
-
}
|
|
495
|
+
public String getName() {
|
|
496
|
+
return name;
|
|
497
|
+
}
|
|
523
498
|
|
|
499
|
+
public String getPostScriptName() {
|
|
500
|
+
return psname;
|
|
501
|
+
}
|
|
524
502
|
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
503
|
+
/**
|
|
504
|
+
* Set the native complement of this font. Might be set internally via the
|
|
505
|
+
* findFont() function, or externally by a deriveFont() call if the font is
|
|
506
|
+
* resized by PGraphicsJava2D.
|
|
507
|
+
*/
|
|
508
|
+
public void setNative(Object font) {
|
|
509
|
+
this.font = (Font) font;
|
|
531
510
|
}
|
|
532
|
-
return font;
|
|
533
|
-
}
|
|
534
511
|
|
|
512
|
+
/**
|
|
513
|
+
* Use the getNative() method instead, which allows library interfaces to be
|
|
514
|
+
* written in a cross-platform fashion for desktop, Android, and others.
|
|
515
|
+
*/
|
|
516
|
+
@Deprecated
|
|
517
|
+
public Font getFont() {
|
|
518
|
+
return font;
|
|
519
|
+
}
|
|
535
520
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
521
|
+
/**
|
|
522
|
+
* Return the native java.awt.Font associated with this PFont (if any).
|
|
523
|
+
*/
|
|
524
|
+
public Object getNative() {
|
|
525
|
+
if (subsetting) {
|
|
526
|
+
return null; // don't return the font for use
|
|
527
|
+
}
|
|
528
|
+
return font;
|
|
529
|
+
}
|
|
542
530
|
|
|
531
|
+
/**
|
|
532
|
+
* Return size of this font.
|
|
533
|
+
*/
|
|
534
|
+
public int getSize() {
|
|
535
|
+
return size;
|
|
536
|
+
}
|
|
543
537
|
|
|
544
538
|
// public void setDefaultSize(int size) {
|
|
545
539
|
// defaultSize = size;
|
|
546
540
|
// }
|
|
541
|
+
/**
|
|
542
|
+
* Returns the size that will be used when textFont(font) is called. When
|
|
543
|
+
* drawing with 2x pixel density, bitmap fonts in OpenGL need to be created
|
|
544
|
+
* (behind the scenes) at double the requested size. This ensures that
|
|
545
|
+
* they're shown at half on displays (so folks don't have to change their
|
|
546
|
+
* sketch code).
|
|
547
|
+
*/
|
|
548
|
+
public int getDefaultSize() {
|
|
549
|
+
//return defaultSize;
|
|
550
|
+
return size / density;
|
|
551
|
+
}
|
|
547
552
|
|
|
553
|
+
public boolean isSmooth() {
|
|
554
|
+
return smooth;
|
|
555
|
+
}
|
|
548
556
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
* created (behind the scenes) at double the requested size. This ensures
|
|
553
|
-
* that they're shown at half on displays (so folks don't have to change
|
|
554
|
-
* their sketch code).
|
|
555
|
-
*/
|
|
556
|
-
public int getDefaultSize() {
|
|
557
|
-
//return defaultSize;
|
|
558
|
-
return size / density;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
public boolean isSmooth() {
|
|
563
|
-
return smooth;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
public boolean isStream() {
|
|
568
|
-
return stream;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
public void setSubsetting() {
|
|
573
|
-
subsetting = true;
|
|
574
|
-
}
|
|
557
|
+
public boolean isStream() {
|
|
558
|
+
return stream;
|
|
559
|
+
}
|
|
575
560
|
|
|
561
|
+
public void setSubsetting() {
|
|
562
|
+
subsetting = true;
|
|
563
|
+
}
|
|
576
564
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
565
|
+
/**
|
|
566
|
+
* Attempt to find the native version of this font. (Public so that it can
|
|
567
|
+
* be used by OpenGL or other renderers.)
|
|
568
|
+
*/
|
|
569
|
+
public Object findNative() {
|
|
570
|
+
if (font == null) {
|
|
571
|
+
if (!fontSearched) {
|
|
572
|
+
// this font may or may not be installed
|
|
573
|
+
font = new Font(name, Font.PLAIN, size);
|
|
574
|
+
// if the ps name matches, then we're in fine shape
|
|
575
|
+
if (!font.getPSName().equals(psname)) {
|
|
576
|
+
// on osx java 1.4 (not 1.3.. ugh), you can specify the ps name
|
|
577
|
+
// of the font, so try that in case this .vlw font was created on pc
|
|
578
|
+
// and the name is different, but the ps name is found on the
|
|
579
|
+
// java 1.4 mac that's currently running this sketch.
|
|
580
|
+
font = new Font(psname, Font.PLAIN, size);
|
|
581
|
+
}
|
|
582
|
+
// check again, and if still bad, screw em
|
|
583
|
+
if (!font.getPSName().equals(psname)) {
|
|
584
|
+
font = null;
|
|
585
|
+
}
|
|
586
|
+
fontSearched = true;
|
|
587
|
+
}
|
|
597
588
|
}
|
|
598
|
-
|
|
599
|
-
}
|
|
589
|
+
return font;
|
|
600
590
|
}
|
|
601
|
-
return font;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
public Glyph getGlyph(char c) {
|
|
606
|
-
int index = index(c);
|
|
607
|
-
return (index == -1) ? null : glyphs[index];
|
|
608
|
-
}
|
|
609
|
-
|
|
610
591
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
*/
|
|
615
|
-
protected int index(char c) {
|
|
616
|
-
if (lazy) {
|
|
617
|
-
int index = indexActual(c);
|
|
618
|
-
if (index != -1) {
|
|
619
|
-
return index;
|
|
620
|
-
}
|
|
621
|
-
if (font != null && font.canDisplay(c)) {
|
|
622
|
-
// create the glyph
|
|
623
|
-
addGlyph(c);
|
|
624
|
-
// now where did i put that?
|
|
625
|
-
return indexActual(c);
|
|
626
|
-
|
|
627
|
-
} else {
|
|
628
|
-
return -1;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
} else {
|
|
632
|
-
return indexActual(c);
|
|
592
|
+
public Glyph getGlyph(char c) {
|
|
593
|
+
int index = index(c);
|
|
594
|
+
return (index == -1) ? null : glyphs[index];
|
|
633
595
|
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
protected int indexActual(char c) {
|
|
638
|
-
// degenerate case, but the find function will have trouble
|
|
639
|
-
// if there are somehow zero chars in the lookup
|
|
640
|
-
//if (value.length == 0) return -1;
|
|
641
|
-
if (glyphCount == 0) return -1;
|
|
642
|
-
|
|
643
|
-
// quicker lookup for the ascii fellers
|
|
644
|
-
if (c < 128) return ascii[c];
|
|
645
|
-
|
|
646
|
-
// some other unicode char, hunt it out
|
|
647
|
-
//return index_hunt(c, 0, value.length-1);
|
|
648
|
-
return indexHunt(c, 0, glyphCount-1);
|
|
649
|
-
}
|
|
650
|
-
|
|
651
596
|
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
* but honored for layout in case subclasses use it.
|
|
673
|
-
*/
|
|
674
|
-
public float kern(char a, char b) {
|
|
675
|
-
return 0;
|
|
676
|
-
}
|
|
597
|
+
/**
|
|
598
|
+
* Get index for the character.
|
|
599
|
+
*
|
|
600
|
+
* @return index into arrays or -1 if not found
|
|
601
|
+
*/
|
|
602
|
+
protected int index(char c) {
|
|
603
|
+
if (lazy) {
|
|
604
|
+
int index = indexActual(c);
|
|
605
|
+
if (index != -1) {
|
|
606
|
+
return index;
|
|
607
|
+
}
|
|
608
|
+
if (font != null && font.canDisplay(c)) {
|
|
609
|
+
// create the glyph
|
|
610
|
+
addGlyph(c);
|
|
611
|
+
// now where did i put that?
|
|
612
|
+
return indexActual(c);
|
|
613
|
+
|
|
614
|
+
} else {
|
|
615
|
+
return -1;
|
|
616
|
+
}
|
|
677
617
|
|
|
618
|
+
} else {
|
|
619
|
+
return indexActual(c);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
678
622
|
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
623
|
+
protected int indexActual(char c) {
|
|
624
|
+
// degenerate case, but the find function will have trouble
|
|
625
|
+
// if there are somehow zero chars in the lookup
|
|
626
|
+
//if (value.length == 0) return -1;
|
|
627
|
+
if (glyphCount == 0) {
|
|
628
|
+
return -1;
|
|
629
|
+
}
|
|
686
630
|
|
|
631
|
+
// quicker lookup for the ascii fellers
|
|
632
|
+
if (c < 128) {
|
|
633
|
+
return ascii[c];
|
|
634
|
+
}
|
|
687
635
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
public float descent() {
|
|
693
|
-
return ((float) descent / (float) size);
|
|
694
|
-
}
|
|
636
|
+
// some other unicode char, hunt it out
|
|
637
|
+
//return index_hunt(c, 0, value.length-1);
|
|
638
|
+
return indexHunt(c, 0, glyphCount - 1);
|
|
639
|
+
}
|
|
695
640
|
|
|
641
|
+
protected int indexHunt(int c, int start, int stop) {
|
|
642
|
+
int pivot = (start + stop) / 2;
|
|
696
643
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
if (c == 32) return width('i');
|
|
644
|
+
// if this is the char, then return it
|
|
645
|
+
if (c == glyphs[pivot].value) {
|
|
646
|
+
return pivot;
|
|
647
|
+
}
|
|
702
648
|
|
|
703
|
-
|
|
704
|
-
|
|
649
|
+
// char doesn't exist, otherwise would have been the pivot
|
|
650
|
+
//if (start == stop) return -1;
|
|
651
|
+
if (start >= stop) {
|
|
652
|
+
return -1;
|
|
653
|
+
}
|
|
705
654
|
|
|
706
|
-
|
|
707
|
-
|
|
655
|
+
// if it's in the lower half, continue searching that
|
|
656
|
+
if (c < glyphs[pivot].value) {
|
|
657
|
+
return indexHunt(c, start, pivot - 1);
|
|
658
|
+
}
|
|
708
659
|
|
|
660
|
+
// if it's in the upper half, continue there
|
|
661
|
+
return indexHunt(c, pivot + 1, stop);
|
|
662
|
+
}
|
|
709
663
|
|
|
710
|
-
|
|
664
|
+
/**
|
|
665
|
+
* Currently un-implemented for .vlw fonts, but honored for layout in case
|
|
666
|
+
* subclasses use it.
|
|
667
|
+
*/
|
|
668
|
+
public float kern(char a, char b) {
|
|
669
|
+
return 0;
|
|
670
|
+
}
|
|
711
671
|
|
|
672
|
+
/**
|
|
673
|
+
* Returns the ascent of this font from the baseline. The value is based on
|
|
674
|
+
* a font of size 1.
|
|
675
|
+
*/
|
|
676
|
+
public float ascent() {
|
|
677
|
+
return ((float) ascent / (float) size);
|
|
678
|
+
}
|
|
712
679
|
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
680
|
+
/**
|
|
681
|
+
* Returns how far this font descends from the baseline. The value is based
|
|
682
|
+
* on a font size of 1.
|
|
683
|
+
*/
|
|
684
|
+
public float descent() {
|
|
685
|
+
return ((float) descent / (float) size);
|
|
686
|
+
}
|
|
716
687
|
|
|
688
|
+
/**
|
|
689
|
+
* Width of this character for a font of size 1.
|
|
690
|
+
*/
|
|
691
|
+
public float width(char c) {
|
|
692
|
+
if (c == 32) {
|
|
693
|
+
return width('i');
|
|
694
|
+
}
|
|
717
695
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
696
|
+
int cc = index(c);
|
|
697
|
+
if (cc == -1) {
|
|
698
|
+
return 0;
|
|
699
|
+
}
|
|
721
700
|
|
|
701
|
+
return ((float) glyphs[cc].setWidth / (float) size);
|
|
702
|
+
}
|
|
722
703
|
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
704
|
+
//////////////////////////////////////////////////////////////
|
|
705
|
+
public int getGlyphCount() {
|
|
706
|
+
return glyphCount;
|
|
707
|
+
}
|
|
726
708
|
|
|
709
|
+
public Glyph getGlyph(int i) {
|
|
710
|
+
return glyphs[i];
|
|
711
|
+
}
|
|
727
712
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
if (font == null) {
|
|
731
|
-
throw new IllegalArgumentException("getShape() only works on fonts loaded with createFont()");
|
|
713
|
+
public PShape getShape(char ch) {
|
|
714
|
+
return getShape(ch, 0);
|
|
732
715
|
}
|
|
733
716
|
|
|
734
|
-
PShape
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
717
|
+
public PShape getShape(char ch, float detail) {
|
|
718
|
+
Font font = (Font) getNative();
|
|
719
|
+
if (font == null) {
|
|
720
|
+
throw new IllegalArgumentException("getShape() only works on fonts loaded with createFont()");
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
PShape s = new PShape(PShape.PATH);
|
|
724
|
+
|
|
725
|
+
// six element array received from the Java2D path iterator
|
|
726
|
+
float[] iterPoints = new float[6];
|
|
727
|
+
// array passed to createGylphVector
|
|
728
|
+
char[] textArray = new char[]{ch};
|
|
729
|
+
|
|
730
|
+
//Graphics2D graphics = (Graphics2D) this.getGraphics();
|
|
731
|
+
//FontRenderContext frc = graphics.getFontRenderContext();
|
|
732
|
+
@SuppressWarnings("deprecation")
|
|
733
|
+
FontRenderContext frc
|
|
734
|
+
= Toolkit.getDefaultToolkit().getFontMetrics(font).getFontRenderContext();
|
|
735
|
+
GlyphVector gv = font.createGlyphVector(frc, textArray);
|
|
736
|
+
Shape shp = gv.getOutline();
|
|
737
|
+
// make everything into moveto and lineto
|
|
738
|
+
PathIterator iter = (detail == 0)
|
|
739
|
+
? shp.getPathIterator(null)
|
|
740
|
+
: // maintain curves
|
|
741
|
+
shp.getPathIterator(null, detail); // convert to line segments
|
|
742
|
+
|
|
743
|
+
int contours = 0;
|
|
744
|
+
//boolean outer = true;
|
|
755
745
|
// boolean contour = false;
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
746
|
+
while (!iter.isDone()) {
|
|
747
|
+
int type = iter.currentSegment(iterPoints);
|
|
748
|
+
switch (type) {
|
|
749
|
+
case PathIterator.SEG_MOVETO: // 1 point (2 vars) in textPoints
|
|
760
750
|
// System.out.println("moveto");
|
|
761
751
|
// if (!contour) {
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
752
|
+
if (contours == 0) {
|
|
753
|
+
s.beginShape();
|
|
754
|
+
} else {
|
|
755
|
+
s.beginContour();
|
|
766
756
|
// contour = true;
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
757
|
+
}
|
|
758
|
+
contours++;
|
|
759
|
+
s.vertex(iterPoints[0], iterPoints[1]);
|
|
760
|
+
break;
|
|
771
761
|
|
|
772
|
-
|
|
762
|
+
case PathIterator.SEG_LINETO: // 1 point
|
|
773
763
|
// System.out.println("lineto");
|
|
774
764
|
// PApplet.println(PApplet.subset(iterPoints, 0, 2));
|
|
775
|
-
|
|
776
|
-
|
|
765
|
+
s.vertex(iterPoints[0], iterPoints[1]);
|
|
766
|
+
break;
|
|
777
767
|
|
|
778
|
-
|
|
768
|
+
case PathIterator.SEG_QUADTO: // 2 points
|
|
779
769
|
// System.out.println("quadto");
|
|
780
770
|
// PApplet.println(PApplet.subset(iterPoints, 0, 4));
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
771
|
+
s.quadraticVertex(iterPoints[0], iterPoints[1],
|
|
772
|
+
iterPoints[2], iterPoints[3]);
|
|
773
|
+
break;
|
|
784
774
|
|
|
785
|
-
|
|
775
|
+
case PathIterator.SEG_CUBICTO: // 3 points
|
|
786
776
|
// System.out.println("cubicto");
|
|
787
777
|
// PApplet.println(iterPoints);
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
778
|
+
s.quadraticVertex(iterPoints[0], iterPoints[1],
|
|
779
|
+
iterPoints[2], iterPoints[3],
|
|
780
|
+
iterPoints[4], iterPoints[5]);
|
|
781
|
+
break;
|
|
792
782
|
|
|
793
|
-
|
|
783
|
+
case PathIterator.SEG_CLOSE:
|
|
794
784
|
// System.out.println("close");
|
|
795
|
-
|
|
785
|
+
if (contours > 1) {
|
|
796
786
|
// contours--;
|
|
797
787
|
// if (contours == 0) {
|
|
798
788
|
//// s.endShape();
|
|
799
789
|
// } else {
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
790
|
+
s.endContour();
|
|
791
|
+
}
|
|
792
|
+
break;
|
|
793
|
+
}
|
|
804
794
|
// PApplet.println(iterPoints);
|
|
805
|
-
|
|
795
|
+
iter.next();
|
|
796
|
+
}
|
|
797
|
+
s.endShape(CLOSE);
|
|
798
|
+
return s;
|
|
806
799
|
}
|
|
807
|
-
s.endShape(CLOSE);
|
|
808
|
-
return s;
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
//////////////////////////////////////////////////////////////
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
static final char[] EXTRA_CHARS = {
|
|
816
|
-
0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
|
|
817
|
-
0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
|
|
818
|
-
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
|
|
819
|
-
0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
|
|
820
|
-
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
|
821
|
-
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
|
822
|
-
0x00B0, 0x00B1, 0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00BA,
|
|
823
|
-
0x00BB, 0x00BF, 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5,
|
|
824
|
-
0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD,
|
|
825
|
-
0x00CE, 0x00CF, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6,
|
|
826
|
-
0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DF,
|
|
827
|
-
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
|
|
828
|
-
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
|
829
|
-
0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8,
|
|
830
|
-
0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FF, 0x0102, 0x0103,
|
|
831
|
-
0x0104, 0x0105, 0x0106, 0x0107, 0x010C, 0x010D, 0x010E, 0x010F,
|
|
832
|
-
0x0110, 0x0111, 0x0118, 0x0119, 0x011A, 0x011B, 0x0131, 0x0139,
|
|
833
|
-
0x013A, 0x013D, 0x013E, 0x0141, 0x0142, 0x0143, 0x0144, 0x0147,
|
|
834
|
-
0x0148, 0x0150, 0x0151, 0x0152, 0x0153, 0x0154, 0x0155, 0x0158,
|
|
835
|
-
0x0159, 0x015A, 0x015B, 0x015E, 0x015F, 0x0160, 0x0161, 0x0162,
|
|
836
|
-
0x0163, 0x0164, 0x0165, 0x016E, 0x016F, 0x0170, 0x0171, 0x0178,
|
|
837
|
-
0x0179, 0x017A, 0x017B, 0x017C, 0x017D, 0x017E, 0x0192, 0x02C6,
|
|
838
|
-
0x02C7, 0x02D8, 0x02D9, 0x02DA, 0x02DB, 0x02DC, 0x02DD, 0x03A9,
|
|
839
|
-
0x03C0, 0x2013, 0x2014, 0x2018, 0x2019, 0x201A, 0x201C, 0x201D,
|
|
840
|
-
0x201E, 0x2020, 0x2021, 0x2022, 0x2026, 0x2030, 0x2039, 0x203A,
|
|
841
|
-
0x2044, 0x20AC, 0x2122, 0x2202, 0x2206, 0x220F, 0x2211, 0x221A,
|
|
842
|
-
0x221E, 0x222B, 0x2248, 0x2260, 0x2264, 0x2265, 0x25CA, 0xF8FF,
|
|
843
|
-
0xFB01, 0xFB02
|
|
844
|
-
};
|
|
845
|
-
|
|
846
800
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
801
|
+
//////////////////////////////////////////////////////////////
|
|
802
|
+
static final char[] EXTRA_CHARS = {
|
|
803
|
+
0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
|
|
804
|
+
0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
|
|
805
|
+
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
|
|
806
|
+
0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
|
|
807
|
+
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
|
808
|
+
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
|
809
|
+
0x00B0, 0x00B1, 0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00BA,
|
|
810
|
+
0x00BB, 0x00BF, 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5,
|
|
811
|
+
0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD,
|
|
812
|
+
0x00CE, 0x00CF, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6,
|
|
813
|
+
0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DF,
|
|
814
|
+
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
|
|
815
|
+
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
|
816
|
+
0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8,
|
|
817
|
+
0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FF, 0x0102, 0x0103,
|
|
818
|
+
0x0104, 0x0105, 0x0106, 0x0107, 0x010C, 0x010D, 0x010E, 0x010F,
|
|
819
|
+
0x0110, 0x0111, 0x0118, 0x0119, 0x011A, 0x011B, 0x0131, 0x0139,
|
|
820
|
+
0x013A, 0x013D, 0x013E, 0x0141, 0x0142, 0x0143, 0x0144, 0x0147,
|
|
821
|
+
0x0148, 0x0150, 0x0151, 0x0152, 0x0153, 0x0154, 0x0155, 0x0158,
|
|
822
|
+
0x0159, 0x015A, 0x015B, 0x015E, 0x015F, 0x0160, 0x0161, 0x0162,
|
|
823
|
+
0x0163, 0x0164, 0x0165, 0x016E, 0x016F, 0x0170, 0x0171, 0x0178,
|
|
824
|
+
0x0179, 0x017A, 0x017B, 0x017C, 0x017D, 0x017E, 0x0192, 0x02C6,
|
|
825
|
+
0x02C7, 0x02D8, 0x02D9, 0x02DA, 0x02DB, 0x02DC, 0x02DD, 0x03A9,
|
|
826
|
+
0x03C0, 0x2013, 0x2014, 0x2018, 0x2019, 0x201A, 0x201C, 0x201D,
|
|
827
|
+
0x201E, 0x2020, 0x2021, 0x2022, 0x2026, 0x2030, 0x2039, 0x203A,
|
|
828
|
+
0x2044, 0x20AC, 0x2122, 0x2202, 0x2206, 0x220F, 0x2211, 0x221A,
|
|
829
|
+
0x221E, 0x222B, 0x2248, 0x2260, 0x2264, 0x2265, 0x25CA, 0xF8FF,
|
|
830
|
+
0xFB01, 0xFB02
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* The default Processing character set.
|
|
835
|
+
* <P>
|
|
836
|
+
* This is the union of the Mac Roman and Windows ANSI (CP1250) character
|
|
837
|
+
* sets. ISO 8859-1 Latin 1 is Unicode characters 0x80 -> 0xFF, and would
|
|
838
|
+
* seem a good standard, but in practice, most P5 users would rather have
|
|
839
|
+
* characters that they expect from their platform's fonts.
|
|
840
|
+
* <P>
|
|
841
|
+
* This is more of an interim solution until a much better font solution can
|
|
842
|
+
* be determined. (i.e. create fonts on the fly from some sort of vector
|
|
843
|
+
* format).
|
|
844
|
+
* <P>
|
|
845
|
+
* Not that I expect that to happen.
|
|
846
|
+
*/
|
|
847
|
+
static public char[] CHARSET;
|
|
848
|
+
|
|
849
|
+
static {
|
|
850
|
+
CHARSET = new char[126 - 33 + 1 + EXTRA_CHARS.length];
|
|
851
|
+
int index = 0;
|
|
852
|
+
for (int i = 33; i <= 126; i++) {
|
|
853
|
+
CHARSET[index++] = (char) i;
|
|
854
|
+
}
|
|
855
|
+
for (int i = 0; i < EXTRA_CHARS.length; i++) {
|
|
856
|
+
CHARSET[index++] = EXTRA_CHARS[i];
|
|
857
|
+
}
|
|
870
858
|
}
|
|
871
|
-
|
|
859
|
+
|
|
860
|
+
;
|
|
872
861
|
|
|
873
862
|
|
|
874
863
|
/**
|
|
@@ -887,212 +876,217 @@ public class PFont implements PConstants {
|
|
|
887
876
|
* @brief Gets a list of the fonts installed on the system
|
|
888
877
|
*/
|
|
889
878
|
static public String[] list() {
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
}
|
|
895
|
-
return list;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
static public void loadFonts() {
|
|
900
|
-
if (fonts == null) {
|
|
901
|
-
GraphicsEnvironment ge =
|
|
902
|
-
GraphicsEnvironment.getLocalGraphicsEnvironment();
|
|
903
|
-
fonts = ge.getAllFonts();
|
|
904
|
-
if (PApplet.platform == PConstants.MACOSX) {
|
|
905
|
-
fontDifferent = new HashMap<String,Font>();
|
|
906
|
-
for (Font font : fonts) {
|
|
907
|
-
// getName() returns the PostScript name on OS X 10.6 w/ Java 6.
|
|
908
|
-
fontDifferent.put(font.getName(), font);
|
|
909
|
-
//fontDifferent.put(font.getPSName(), font);
|
|
879
|
+
loadFonts();
|
|
880
|
+
String list[] = new String[fonts.length];
|
|
881
|
+
for (int i = 0; i < list.length; i++) {
|
|
882
|
+
list[i] = fonts[i].getName();
|
|
910
883
|
}
|
|
911
|
-
|
|
884
|
+
return list;
|
|
912
885
|
}
|
|
913
|
-
}
|
|
914
886
|
|
|
887
|
+
static public void loadFonts() {
|
|
888
|
+
if (fonts == null) {
|
|
889
|
+
GraphicsEnvironment ge
|
|
890
|
+
= GraphicsEnvironment.getLocalGraphicsEnvironment();
|
|
891
|
+
fonts = ge.getAllFonts();
|
|
892
|
+
if (PApplet.platform == PConstants.MACOSX) {
|
|
893
|
+
fontDifferent = new HashMap<String, Font>();
|
|
894
|
+
for (Font font : fonts) {
|
|
895
|
+
// getName() returns the PostScript name on OS X 10.6 w/ Java 6.
|
|
896
|
+
fontDifferent.put(font.getName(), font);
|
|
897
|
+
//fontDifferent.put(font.getPSName(), font);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
915
902
|
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
903
|
+
/**
|
|
904
|
+
* Starting with Java 1.5, Apple broke the ability to specify most fonts.
|
|
905
|
+
* This bug was filed years ago as #4769141 at bugreporter.apple.com. More:
|
|
906
|
+
* <a href="http://dev.processing.org/bugs/show_bug.cgi?id=407">Bug 407</a>.
|
|
907
|
+
*/
|
|
908
|
+
static public Font findFont(String name) {
|
|
909
|
+
loadFonts();
|
|
910
|
+
if (PApplet.platform == PConstants.MACOSX) {
|
|
911
|
+
Font maybe = fontDifferent.get(name);
|
|
912
|
+
if (maybe != null) {
|
|
913
|
+
return maybe;
|
|
914
|
+
}
|
|
928
915
|
// for (int i = 0; i < fonts.length; i++) {
|
|
929
916
|
// if (name.equals(fonts[i].getName())) {
|
|
930
917
|
// return fonts[i];
|
|
931
918
|
// }
|
|
932
919
|
// }
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
//////////////////////////////////////////////////////////////
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
/**
|
|
942
|
-
* A single character, and its visage.
|
|
943
|
-
*/
|
|
944
|
-
public class Glyph {
|
|
945
|
-
public PImage image;
|
|
946
|
-
public int value;
|
|
947
|
-
public int height;
|
|
948
|
-
public int width;
|
|
949
|
-
public int index;
|
|
950
|
-
public int setWidth;
|
|
951
|
-
public int topExtent;
|
|
952
|
-
public int leftExtent;
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
public Glyph() {
|
|
956
|
-
index = -1;
|
|
957
|
-
// used when reading from a stream or for subclasses
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
public Glyph(DataInputStream is) throws IOException {
|
|
962
|
-
index = -1;
|
|
963
|
-
readHeader(is);
|
|
920
|
+
}
|
|
921
|
+
return new Font(name, Font.PLAIN, 1);
|
|
964
922
|
}
|
|
965
923
|
|
|
924
|
+
//////////////////////////////////////////////////////////////
|
|
925
|
+
/**
|
|
926
|
+
* A single character, and its visage.
|
|
927
|
+
*/
|
|
928
|
+
public class Glyph {
|
|
929
|
+
|
|
930
|
+
public PImage image;
|
|
931
|
+
public int value;
|
|
932
|
+
public int height;
|
|
933
|
+
public int width;
|
|
934
|
+
public int index;
|
|
935
|
+
public int setWidth;
|
|
936
|
+
public int topExtent;
|
|
937
|
+
public int leftExtent;
|
|
938
|
+
|
|
939
|
+
public Glyph() {
|
|
940
|
+
index = -1;
|
|
941
|
+
// used when reading from a stream or for subclasses
|
|
942
|
+
}
|
|
966
943
|
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
setWidth = is.readInt();
|
|
972
|
-
topExtent = is.readInt();
|
|
973
|
-
leftExtent = is.readInt();
|
|
974
|
-
|
|
975
|
-
// pointer from a struct in the c version, ignored
|
|
976
|
-
is.readInt();
|
|
977
|
-
|
|
978
|
-
// the values for getAscent() and getDescent() from FontMetrics
|
|
979
|
-
// seem to be way too large.. perhaps they're the max?
|
|
980
|
-
// as such, use a more traditional marker for ascent/descent
|
|
981
|
-
if (value == 'd') {
|
|
982
|
-
if (ascent == 0) ascent = topExtent;
|
|
983
|
-
}
|
|
984
|
-
if (value == 'p') {
|
|
985
|
-
if (descent == 0) descent = -topExtent + height;
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
|
|
944
|
+
public Glyph(DataInputStream is) throws IOException {
|
|
945
|
+
index = -1;
|
|
946
|
+
readHeader(is);
|
|
947
|
+
}
|
|
989
948
|
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
949
|
+
protected void readHeader(DataInputStream is) throws IOException {
|
|
950
|
+
value = is.readInt();
|
|
951
|
+
height = is.readInt();
|
|
952
|
+
width = is.readInt();
|
|
953
|
+
setWidth = is.readInt();
|
|
954
|
+
topExtent = is.readInt();
|
|
955
|
+
leftExtent = is.readInt();
|
|
956
|
+
|
|
957
|
+
// pointer from a struct in the c version, ignored
|
|
958
|
+
is.readInt();
|
|
959
|
+
|
|
960
|
+
// the values for getAscent() and getDescent() from FontMetrics
|
|
961
|
+
// seem to be way too large.. perhaps they're the max?
|
|
962
|
+
// as such, use a more traditional marker for ascent/descent
|
|
963
|
+
if (value == 'd') {
|
|
964
|
+
if (ascent == 0) {
|
|
965
|
+
ascent = topExtent;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
if (value == 'p') {
|
|
969
|
+
if (descent == 0) {
|
|
970
|
+
descent = -topExtent + height;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
999
974
|
|
|
975
|
+
protected void writeHeader(DataOutputStream os) throws IOException {
|
|
976
|
+
os.writeInt(value);
|
|
977
|
+
os.writeInt(height);
|
|
978
|
+
os.writeInt(width);
|
|
979
|
+
os.writeInt(setWidth);
|
|
980
|
+
os.writeInt(topExtent);
|
|
981
|
+
os.writeInt(leftExtent);
|
|
982
|
+
os.writeInt(0); // padding
|
|
983
|
+
}
|
|
1000
984
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
985
|
+
protected void readBitmap(DataInputStream is) throws IOException {
|
|
986
|
+
image = new PImage(width, height, ALPHA);
|
|
987
|
+
int bitmapSize = width * height;
|
|
1004
988
|
|
|
1005
|
-
|
|
1006
|
-
|
|
989
|
+
byte[] temp = new byte[bitmapSize];
|
|
990
|
+
is.readFully(temp);
|
|
1007
991
|
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
992
|
+
// convert the bitmap to an alpha channel
|
|
993
|
+
int w = width;
|
|
994
|
+
int h = height;
|
|
995
|
+
int[] pixels = image.pixels;
|
|
996
|
+
for (int y = 0; y < h; y++) {
|
|
997
|
+
for (int x = 0; x < w; x++) {
|
|
998
|
+
pixels[y * width + x] = temp[y * w + x] & 0xff;
|
|
1015
999
|
// System.out.print((image.pixels[y*64+x] > 128) ? "*" : ".");
|
|
1016
|
-
|
|
1000
|
+
}
|
|
1017
1001
|
// System.out.println();
|
|
1018
|
-
|
|
1002
|
+
}
|
|
1019
1003
|
// System.out.println();
|
|
1020
|
-
|
|
1021
|
-
|
|
1004
|
+
}
|
|
1022
1005
|
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1006
|
+
protected void writeBitmap(DataOutputStream os) throws IOException {
|
|
1007
|
+
int[] pixels = image.pixels;
|
|
1008
|
+
for (int y = 0; y < height; y++) {
|
|
1009
|
+
for (int x = 0; x < width; x++) {
|
|
1010
|
+
os.write(pixels[y * width + x] & 0xff);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1028
1013
|
}
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
1014
|
|
|
1015
|
+
protected Glyph(char c) {
|
|
1016
|
+
int mbox3 = size * 3;
|
|
1017
|
+
lazyGraphics.setColor(Color.white);
|
|
1018
|
+
lazyGraphics.fillRect(0, 0, mbox3, mbox3);
|
|
1019
|
+
lazyGraphics.setColor(Color.black);
|
|
1020
|
+
lazyGraphics.drawString(String.valueOf(c), size, size * 2);
|
|
1021
|
+
|
|
1022
|
+
WritableRaster raster = lazyImage.getRaster();
|
|
1023
|
+
raster.getDataElements(0, 0, mbox3, mbox3, lazySamples);
|
|
1024
|
+
|
|
1025
|
+
int minX = 1000, maxX = 0;
|
|
1026
|
+
int minY = 1000, maxY = 0;
|
|
1027
|
+
boolean pixelFound = false;
|
|
1028
|
+
|
|
1029
|
+
for (int y = 0; y < mbox3; y++) {
|
|
1030
|
+
for (int x = 0; x < mbox3; x++) {
|
|
1031
|
+
int sample = lazySamples[y * mbox3 + x] & 0xff;
|
|
1032
|
+
if (sample != 255) {
|
|
1033
|
+
if (x < minX) {
|
|
1034
|
+
minX = x;
|
|
1035
|
+
}
|
|
1036
|
+
if (y < minY) {
|
|
1037
|
+
minY = y;
|
|
1038
|
+
}
|
|
1039
|
+
if (x > maxX) {
|
|
1040
|
+
maxX = x;
|
|
1041
|
+
}
|
|
1042
|
+
if (y > maxY) {
|
|
1043
|
+
maxY = y;
|
|
1044
|
+
}
|
|
1045
|
+
pixelFound = true;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1032
1049
|
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
// of where the char was drawn (size*2)
|
|
1074
|
-
topExtent = size*2 - minY;
|
|
1075
|
-
|
|
1076
|
-
// offset from left of where coord was drawn
|
|
1077
|
-
leftExtent = minX - size;
|
|
1078
|
-
|
|
1079
|
-
image = new PImage(width, height, ALPHA);
|
|
1080
|
-
int[] pixels = image.pixels;
|
|
1081
|
-
for (int y = minY; y <= maxY; y++) {
|
|
1082
|
-
for (int x = minX; x <= maxX; x++) {
|
|
1083
|
-
int val = 255 - (lazySamples[y * mbox3 + x] & 0xff);
|
|
1084
|
-
int pindex = (y - minY) * width + (x - minX);
|
|
1085
|
-
pixels[pindex] = val;
|
|
1050
|
+
if (!pixelFound) {
|
|
1051
|
+
minX = minY = 0;
|
|
1052
|
+
maxX = maxY = 0;
|
|
1053
|
+
// this will create a 1 pixel white (clear) character..
|
|
1054
|
+
// maybe better to set one to -1 so nothing is added?
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
value = c;
|
|
1058
|
+
height = (maxY - minY) + 1;
|
|
1059
|
+
width = (maxX - minX) + 1;
|
|
1060
|
+
setWidth = lazyMetrics.charWidth(c);
|
|
1061
|
+
|
|
1062
|
+
// offset from vertical location of baseline
|
|
1063
|
+
// of where the char was drawn (size*2)
|
|
1064
|
+
topExtent = size * 2 - minY;
|
|
1065
|
+
|
|
1066
|
+
// offset from left of where coord was drawn
|
|
1067
|
+
leftExtent = minX - size;
|
|
1068
|
+
|
|
1069
|
+
image = new PImage(width, height, ALPHA);
|
|
1070
|
+
int[] pixels = image.pixels;
|
|
1071
|
+
for (int y = minY; y <= maxY; y++) {
|
|
1072
|
+
for (int x = minX; x <= maxX; x++) {
|
|
1073
|
+
int val = 255 - (lazySamples[y * mbox3 + x] & 0xff);
|
|
1074
|
+
int pindex = (y - minY) * width + (x - minX);
|
|
1075
|
+
pixels[pindex] = val;
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// replace the ascent/descent values with something.. err, decent.
|
|
1080
|
+
if (value == 'd') {
|
|
1081
|
+
if (ascent == 0) {
|
|
1082
|
+
ascent = topExtent;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
if (value == 'p') {
|
|
1086
|
+
if (descent == 0) {
|
|
1087
|
+
descent = -topExtent + height;
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1086
1090
|
}
|
|
1087
|
-
}
|
|
1088
|
-
|
|
1089
|
-
// replace the ascent/descent values with something.. err, decent.
|
|
1090
|
-
if (value == 'd') {
|
|
1091
|
-
if (ascent == 0) ascent = topExtent;
|
|
1092
|
-
}
|
|
1093
|
-
if (value == 'p') {
|
|
1094
|
-
if (descent == 0) descent = -topExtent + height;
|
|
1095
|
-
}
|
|
1096
1091
|
}
|
|
1097
|
-
}
|
|
1098
1092
|
}
|