picrate 0.7.0-java → 0.8.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/.gitignore +1 -1
- data/.mvn/wrapper/MavenWrapperDownloader.java +117 -0
- data/.mvn/wrapper/maven-wrapper.properties +2 -1
- data/.travis.yml +2 -5
- data/CHANGELOG.md +4 -0
- data/README.md +3 -3
- data/Rakefile +15 -27
- data/docs/_config.yml +1 -1
- data/docs/_posts/2018-05-11-arch-linux-arm.md +1 -1
- data/docs/_posts/2018-11-18-building-gem.md +1 -1
- data/lib/picrate/app.rb +1 -1
- data/lib/picrate/native_folder.rb +1 -1
- data/lib/picrate/version.rb +1 -1
- data/mvnw +127 -51
- data/mvnw.cmd +182 -0
- data/pom.rb +39 -30
- data/pom.xml +50 -37
- data/src/main/java/monkstone/ColorUtil.java +1 -1
- data/src/main/java/monkstone/core/LibraryProxy.java +0 -1
- data/src/main/java/monkstone/noise/SimplexNoise.java +1 -1
- data/src/main/java/monkstone/vecmath/GfxRender.java +87 -0
- data/src/main/java/monkstone/vecmath/ShapeRender.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +48 -50
- data/src/main/java/processing/awt/PShapeJava2D.java +10 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +315 -371
- data/src/main/java/processing/core/PApplet.java +15424 -15495
- data/src/main/java/processing/core/PConstants.java +4 -4
- data/src/main/java/processing/core/PFont.java +394 -369
- data/src/main/java/processing/core/PGraphics.java +11 -10
- data/src/main/java/processing/core/PImage.java +1389 -1435
- data/src/main/java/processing/core/PMatrix2D.java +297 -294
- data/src/main/java/processing/core/PMatrix3D.java +641 -594
- data/src/main/java/processing/core/PShape.java +1755 -1784
- data/src/main/java/processing/core/PShapeOBJ.java +145 -133
- data/src/main/java/processing/core/PShapeSVG.java +808 -801
- data/src/main/java/processing/core/PStyle.java +141 -149
- data/src/main/java/processing/core/PSurface.java +111 -117
- data/src/main/java/processing/core/PSurfaceNone.java +178 -187
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +349 -346
- data/src/main/java/processing/opengl/FontTexture.java +40 -59
- data/src/main/java/processing/opengl/FrameBuffer.java +28 -18
- data/src/main/java/processing/opengl/LinePath.java +7 -7
- data/src/main/java/processing/opengl/LineStroker.java +6 -10
- data/src/main/java/processing/opengl/PGL.java +56 -44
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +909 -2338
- data/src/main/java/processing/opengl/PJOGL.java +1722 -1763
- data/src/main/java/processing/opengl/PShader.java +1308 -1192
- data/src/main/java/processing/opengl/PShapeOpenGL.java +487 -1811
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +482 -497
- data/src/main/java/processing/opengl/Texture.java +99 -76
- data/src/main/java/processing/opengl/VertexBuffer.java +41 -43
- data/vendors/Rakefile +1 -1
- metadata +7 -4
@@ -134,7 +134,7 @@ public interface PConstants {
|
|
134
134
|
/**
|
135
135
|
*
|
136
136
|
*/
|
137
|
-
static final String[]
|
137
|
+
static final String[] PLATFORM_NAMES = {
|
138
138
|
"other", "windows", "macosx", "linux"
|
139
139
|
};
|
140
140
|
|
@@ -711,7 +711,7 @@ public interface PConstants {
|
|
711
711
|
/**
|
712
712
|
* textMode(MODEL) is the default, meaning that characters will be affected
|
713
713
|
* by transformations like any other shapes.
|
714
|
-
*
|
714
|
+
*
|
715
715
|
* Changed value in 0093 to not interfere with LEFT, CENTER, and RIGHT.
|
716
716
|
*/
|
717
717
|
static final int MODEL = 4;
|
@@ -722,7 +722,7 @@ public interface PConstants {
|
|
722
722
|
* then textMode(SHAPE) will be ignored and textMode(MODEL) will be used
|
723
723
|
* instead. For this reason, be sure to call textMode()
|
724
724
|
* <EM>after</EM> calling textFont().
|
725
|
-
*
|
725
|
+
*
|
726
726
|
* Currently, textMode(SHAPE) is only supported by OPENGL mode. It also
|
727
727
|
* requires Java 1.2 or higher (OPENGL requires 1.4 anyway)
|
728
728
|
*/
|
@@ -734,7 +734,7 @@ public interface PConstants {
|
|
734
734
|
/**
|
735
735
|
*
|
736
736
|
*/
|
737
|
-
static final int SQUARE = 1
|
737
|
+
static final int SQUARE = 1; // called 'butt' in the svg spec
|
738
738
|
|
739
739
|
/**
|
740
740
|
*
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
2
2
|
|
3
|
-
/*
|
3
|
+
/*
|
4
4
|
Part of the Processing project - http://processing.org
|
5
5
|
|
6
6
|
Copyright (c) 2012-15 The Processing Foundation
|
@@ -20,8 +20,7 @@
|
|
20
20
|
Public License along with this library; if not, write to the
|
21
21
|
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
22
22
|
Boston, MA 02111-1307 USA
|
23
|
-
*/
|
24
|
-
|
23
|
+
*/
|
25
24
|
package processing.core;
|
26
25
|
|
27
26
|
import java.awt.*;
|
@@ -33,7 +32,6 @@ import java.io.*;
|
|
33
32
|
import java.util.Arrays;
|
34
33
|
import java.util.HashMap;
|
35
34
|
|
36
|
-
|
37
35
|
/**
|
38
36
|
* Grayscale bitmap font class used by Processing.
|
39
37
|
* <P>
|
@@ -55,6 +53,7 @@ import java.util.HashMap;
|
|
55
53
|
*
|
56
54
|
* ^^^^^^^^^^^^^^ setWidth (width displaced by char)
|
57
55
|
* </PRE>
|
56
|
+
*
|
58
57
|
* @webref typography
|
59
58
|
* @see PApplet#loadFont(String)
|
60
59
|
* @see PApplet#createFont(String, float, boolean, char[])
|
@@ -62,18 +61,20 @@ import java.util.HashMap;
|
|
62
61
|
*/
|
63
62
|
public class PFont implements PConstants {
|
64
63
|
|
65
|
-
/**
|
64
|
+
/**
|
65
|
+
* Number of character glyphs in this font.
|
66
|
+
*/
|
66
67
|
protected int glyphCount;
|
67
68
|
|
68
69
|
/**
|
69
|
-
* Actual glyph data. The length of this array won't necessarily be the
|
70
|
-
*
|
70
|
+
* Actual glyph data. The length of this array won't necessarily be the same
|
71
|
+
* size as glyphCount, in cases where lazy font loading is in use.
|
71
72
|
*/
|
72
73
|
protected Glyph[] glyphs;
|
73
74
|
|
74
75
|
/**
|
75
|
-
* Name of the font as seen by Java when it was created.
|
76
|
-
*
|
76
|
+
* Name of the font as seen by Java when it was created. If the font is
|
77
|
+
* available, the native version will be used.
|
77
78
|
*/
|
78
79
|
protected String name;
|
79
80
|
|
@@ -87,16 +88,20 @@ public class PFont implements PConstants {
|
|
87
88
|
*/
|
88
89
|
protected int size;
|
89
90
|
|
90
|
-
/**
|
91
|
+
/**
|
92
|
+
* Default density set to 1 for backwards compatibility with loadFont().
|
93
|
+
*/
|
91
94
|
protected int density = 1;
|
92
95
|
|
93
|
-
/**
|
96
|
+
/**
|
97
|
+
* true if smoothing was enabled for this font, used for native impl
|
98
|
+
*/
|
94
99
|
protected boolean smooth;
|
95
100
|
|
96
101
|
/**
|
97
|
-
* The ascent of the font. If the 'd' character is present in this PFont,
|
98
|
-
*
|
99
|
-
*
|
102
|
+
* The ascent of the font. If the 'd' character is present in this PFont, this
|
103
|
+
* value is replaced with its pixel height, because the values returned by
|
104
|
+
* FontMetrics.getAscent() seem to be terrible.
|
100
105
|
*/
|
101
106
|
protected int ascent;
|
102
107
|
|
@@ -121,17 +126,17 @@ public class PFont implements PConstants {
|
|
121
126
|
protected boolean lazy;
|
122
127
|
|
123
128
|
/**
|
124
|
-
* Native Java version of the font. If possible, this allows the
|
125
|
-
*
|
126
|
-
*
|
129
|
+
* Native Java version of the font. If possible, this allows the PGraphics
|
130
|
+
* subclass to just use Java's font rendering stuff in situations where that's
|
131
|
+
* faster.
|
127
132
|
*/
|
128
133
|
protected Font font;
|
129
134
|
|
130
135
|
/**
|
131
|
-
* True if this font was loaded from an InputStream, rather than by name
|
132
|
-
*
|
133
|
-
*
|
134
|
-
*
|
136
|
+
* True if this font was loaded from an InputStream, rather than by name from
|
137
|
+
* the OS. It's best to use the native version of a font loaded from a TTF
|
138
|
+
* file, since that will ensure that the font is available when the sketch is
|
139
|
+
* exported.
|
135
140
|
*/
|
136
141
|
protected boolean stream;
|
137
142
|
|
@@ -142,20 +147,22 @@ public class PFont implements PConstants {
|
|
142
147
|
*/
|
143
148
|
protected boolean subsetting;
|
144
149
|
|
145
|
-
/**
|
150
|
+
/**
|
151
|
+
* True if already tried to find the native AWT version of this font.
|
152
|
+
*/
|
146
153
|
protected boolean fontSearched;
|
147
154
|
|
148
155
|
/**
|
149
156
|
* Array of the native system fonts. Used to lookup native fonts by their
|
150
|
-
* PostScript name. This is a workaround for a several year old Apple Java
|
151
|
-
*
|
157
|
+
* PostScript name. This is a workaround for a several year old Apple Java bug
|
158
|
+
* that they can't be bothered to fix.
|
152
159
|
*/
|
153
160
|
static protected Font[] fonts;
|
154
161
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
162
|
+
/**
|
163
|
+
*
|
164
|
+
*/
|
165
|
+
static protected HashMap<String, Font> fontDifferent;
|
159
166
|
|
160
167
|
// /**
|
161
168
|
// * If not null, this font is set to load dynamically. This is the default
|
@@ -163,51 +170,50 @@ public class PFont implements PConstants {
|
|
163
170
|
// * versions of characters are only created when prompted by an index() call.
|
164
171
|
// */
|
165
172
|
// protected Font lazyFont;
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
*/
|
173
|
+
/**
|
174
|
+
*
|
175
|
+
*/
|
170
176
|
protected BufferedImage lazyImage;
|
171
177
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
/**
|
178
|
-
*
|
179
|
-
*/
|
180
|
-
protected FontMetrics lazyMetrics;
|
178
|
+
/**
|
179
|
+
*
|
180
|
+
*/
|
181
|
+
protected Graphics2D lazyGraphics;
|
181
182
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
183
|
+
/**
|
184
|
+
*
|
185
|
+
*/
|
186
|
+
protected FontMetrics lazyMetrics;
|
186
187
|
|
188
|
+
/**
|
189
|
+
*
|
190
|
+
*/
|
191
|
+
protected int[] lazySamples;
|
187
192
|
|
188
|
-
/**
|
193
|
+
/**
|
194
|
+
* for subclasses that need to store metadata about the font
|
195
|
+
*/
|
189
196
|
// protected HashMap<PGraphics, Object> cacheMap;
|
190
|
-
|
191
197
|
/**
|
192
198
|
* @nowebref
|
193
199
|
*/
|
194
|
-
public PFont() {
|
195
|
-
|
200
|
+
public PFont() {
|
201
|
+
} // for subclasses
|
196
202
|
|
197
203
|
/**
|
198
204
|
* ( begin auto-generated from PFont.xml )
|
199
205
|
*
|
200
206
|
* PFont is the font class for Processing. To create a font to use with
|
201
|
-
* Processing, select "Create Font..." from the Tools menu. This will
|
202
|
-
*
|
203
|
-
*
|
204
|
-
*
|
205
|
-
*
|
206
|
-
*
|
207
|
-
* <b>list()</b> method creates a list of the fonts installed on the
|
208
|
-
*
|
209
|
-
* <b>createFont()</b> function for dynamically converting fonts into a
|
210
|
-
*
|
207
|
+
* Processing, select "Create Font..." from the Tools menu. This will create a
|
208
|
+
* font in the format Processing requires and also adds it to the current
|
209
|
+
* sketch's data directory. Processing displays fonts using the .vlw font
|
210
|
+
* format, which uses images for each letter, rather than defining them
|
211
|
+
* through vector data. The <b>loadFont()</b> function constructs a new font
|
212
|
+
* and <b>textFont()</b> makes a font active. The
|
213
|
+
* <b>list()</b> method creates a list of the fonts installed on the computer,
|
214
|
+
* which is useful information to use with the
|
215
|
+
* <b>createFont()</b> function for dynamically converting fonts into a format
|
216
|
+
* to use with Processing.
|
211
217
|
*
|
212
218
|
* ( end auto-generated )
|
213
219
|
*
|
@@ -219,13 +225,12 @@ public class PFont implements PConstants {
|
|
219
225
|
this(font, smooth, null);
|
220
226
|
}
|
221
227
|
|
222
|
-
|
223
228
|
/**
|
224
|
-
* Create a new image-based font on the fly. If charset is set to null,
|
225
|
-
*
|
229
|
+
* Create a new image-based font on the fly. If charset is set to null, the
|
230
|
+
* characters will only be created as bitmaps when they're drawn.
|
226
231
|
*
|
227
|
-
|
228
|
-
|
232
|
+
* @param font
|
233
|
+
* @param smooth
|
229
234
|
* @nowebref
|
230
235
|
* @param charset array of all unicode chars that should be included
|
231
236
|
*/
|
@@ -242,7 +247,6 @@ public class PFont implements PConstants {
|
|
242
247
|
//lazy = true;
|
243
248
|
// not sure what else to do here
|
244
249
|
//mbox2 = 0;
|
245
|
-
|
246
250
|
int initialCount = 10;
|
247
251
|
glyphs = new Glyph[initialCount];
|
248
252
|
|
@@ -254,14 +258,14 @@ public class PFont implements PConstants {
|
|
254
258
|
lazyImage = new BufferedImage(mbox3, mbox3, BufferedImage.TYPE_INT_RGB);
|
255
259
|
lazyGraphics = (Graphics2D) lazyImage.getGraphics();
|
256
260
|
lazyGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
257
|
-
|
258
|
-
|
259
|
-
|
261
|
+
smooth
|
262
|
+
? RenderingHints.VALUE_ANTIALIAS_ON
|
263
|
+
: RenderingHints.VALUE_ANTIALIAS_OFF);
|
260
264
|
// adding this for post-1.0.9
|
261
265
|
lazyGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
262
|
-
|
263
|
-
|
264
|
-
|
266
|
+
smooth
|
267
|
+
? RenderingHints.VALUE_TEXT_ANTIALIAS_ON
|
268
|
+
: RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
265
269
|
|
266
270
|
lazyGraphics.setFont(font);
|
267
271
|
lazyMetrics = lazyGraphics.getFontMetrics();
|
@@ -272,7 +276,6 @@ public class PFont implements PConstants {
|
|
272
276
|
// calculate-by-hand method of measuring pixels in characters.
|
273
277
|
//ascent = lazyMetrics.getAscent();
|
274
278
|
//descent = lazyMetrics.getDescent();
|
275
|
-
|
276
279
|
if (charset == null) {
|
277
280
|
lazy = true;
|
278
281
|
// lazyFont = font;
|
@@ -347,27 +350,26 @@ public class PFont implements PConstants {
|
|
347
350
|
}
|
348
351
|
}
|
349
352
|
|
350
|
-
|
351
353
|
/**
|
352
|
-
* Adds an additional parameter that indicates the font came from a file,
|
353
|
-
*
|
354
|
+
* Adds an additional parameter that indicates the font came from a file, not
|
355
|
+
* a built-in OS font.
|
354
356
|
*
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
357
|
+
* @param font
|
358
|
+
* @param smooth
|
359
|
+
* @param charset
|
360
|
+
* @param stream
|
361
|
+
* @param density
|
360
362
|
* @nowebref
|
361
363
|
*/
|
362
364
|
public PFont(Font font, boolean smooth, char charset[],
|
363
|
-
|
365
|
+
boolean stream, int density) {
|
364
366
|
this(font, smooth, charset);
|
365
367
|
this.stream = stream;
|
366
368
|
this.density = density;
|
367
369
|
}
|
368
370
|
|
369
371
|
/**
|
370
|
-
|
372
|
+
* @throws java.io.IOException
|
371
373
|
* @nowebref
|
372
374
|
* @param input InputStream
|
373
375
|
*/
|
@@ -390,7 +392,7 @@ public class PFont implements PConstants {
|
|
390
392
|
// this will make new fonts downward compatible
|
391
393
|
is.readInt(); // ignore the other mbox attribute
|
392
394
|
|
393
|
-
ascent
|
395
|
+
ascent = is.readInt(); // formerly baseHt (zero/ignored)
|
394
396
|
descent = is.readInt(); // formerly ignored struct padding
|
395
397
|
|
396
398
|
// allocate enough space for the character info
|
@@ -413,8 +415,8 @@ public class PFont implements PConstants {
|
|
413
415
|
// not a roman font, so throw an error and ask to re-build.
|
414
416
|
// that way can avoid a bunch of error checking hacks in here.
|
415
417
|
if ((ascent == 0) && (descent == 0)) {
|
416
|
-
throw new RuntimeException("Please use \"Create Font\" to "
|
417
|
-
|
418
|
+
throw new RuntimeException("Please use \"Create Font\" to "
|
419
|
+
+ "re-create this font.");
|
418
420
|
}
|
419
421
|
|
420
422
|
for (Glyph glyph : glyphs) {
|
@@ -433,17 +435,17 @@ public class PFont implements PConstants {
|
|
433
435
|
// findNative();
|
434
436
|
}
|
435
437
|
|
436
|
-
|
437
438
|
/**
|
438
439
|
* Write this PFont to an OutputStream.
|
439
440
|
* <p>
|
440
|
-
* This is used by the Create Font tool, or whatever anyone else dreams
|
441
|
-
*
|
441
|
+
* This is used by the Create Font tool, or whatever anyone else dreams up for
|
442
|
+
* messing with fonts themselves.
|
442
443
|
* <p>
|
443
|
-
* It is assumed that the calling class will handle closing
|
444
|
-
*
|
445
|
-
|
446
|
-
|
444
|
+
* It is assumed that the calling class will handle closing the stream when
|
445
|
+
* finished.
|
446
|
+
*
|
447
|
+
* @param output
|
448
|
+
* @throws java.io.IOException
|
447
449
|
*/
|
448
450
|
public void save(OutputStream output) throws IOException {
|
449
451
|
DataOutputStream os = new DataOutputStream(output);
|
@@ -477,9 +479,9 @@ public class PFont implements PConstants {
|
|
477
479
|
os.flush();
|
478
480
|
}
|
479
481
|
|
480
|
-
|
481
482
|
/**
|
482
483
|
* Create a new glyph, and add the character to the current font.
|
484
|
+
*
|
483
485
|
* @param c character to create an image for.
|
484
486
|
*/
|
485
487
|
protected void addGlyph(char c) {
|
@@ -495,7 +497,7 @@ public class PFont implements PConstants {
|
|
495
497
|
ascii[glyph.value] = 0;
|
496
498
|
}
|
497
499
|
|
498
|
-
} else if (glyphs[glyphCount-1].value < glyph.value) {
|
500
|
+
} else if (glyphs[glyphCount - 1].value < glyph.value) {
|
499
501
|
glyphs[glyphCount] = glyph;
|
500
502
|
if (glyph.value < 128) {
|
501
503
|
ascii[glyph.value] = glyphCount;
|
@@ -505,7 +507,7 @@ public class PFont implements PConstants {
|
|
505
507
|
for (int i = 0; i < glyphCount; i++) {
|
506
508
|
if (glyphs[i].value > c) {
|
507
509
|
for (int j = glyphCount; j > i; --j) {
|
508
|
-
glyphs[j] = glyphs[j-1];
|
510
|
+
glyphs[j] = glyphs[j - 1];
|
509
511
|
if (glyphs[j].value < 128) {
|
510
512
|
ascii[glyphs[j].value] = j;
|
511
513
|
}
|
@@ -513,7 +515,9 @@ public class PFont implements PConstants {
|
|
513
515
|
glyph.index = i;
|
514
516
|
glyphs[i] = glyph;
|
515
517
|
// cache locations of the ascii charset
|
516
|
-
if (c < 128)
|
518
|
+
if (c < 128) {
|
519
|
+
ascii[c] = i;
|
520
|
+
}
|
517
521
|
break;
|
518
522
|
}
|
519
523
|
}
|
@@ -521,48 +525,48 @@ public class PFont implements PConstants {
|
|
521
525
|
glyphCount++;
|
522
526
|
}
|
523
527
|
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
528
|
+
/**
|
529
|
+
*
|
530
|
+
* @return
|
531
|
+
*/
|
532
|
+
public String getName() {
|
529
533
|
return name;
|
530
534
|
}
|
531
535
|
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
536
|
+
/**
|
537
|
+
*
|
538
|
+
* @return
|
539
|
+
*/
|
540
|
+
public String getPostScriptName() {
|
537
541
|
return psname;
|
538
542
|
}
|
539
543
|
|
540
|
-
|
541
544
|
/**
|
542
545
|
* Set the native complement of this font. Might be set internally via the
|
543
|
-
* findFont() function, or externally by a deriveFont() call if the font
|
544
|
-
*
|
545
|
-
|
546
|
+
* findFont() function, or externally by a deriveFont() call if the font is
|
547
|
+
* resized by PGraphicsJava2D.
|
548
|
+
*
|
549
|
+
* @param font
|
546
550
|
*/
|
547
551
|
public void setNative(Object font) {
|
548
552
|
this.font = (Font) font;
|
549
553
|
}
|
550
554
|
|
551
|
-
|
552
555
|
/**
|
553
556
|
* Use the getNative() method instead, which allows library interfaces to be
|
554
557
|
* written in a cross-platform fashion for desktop, Android, and others.
|
555
|
-
|
558
|
+
*
|
559
|
+
* @return
|
556
560
|
*/
|
557
561
|
@Deprecated
|
558
562
|
public Font getFont() {
|
559
563
|
return font;
|
560
564
|
}
|
561
565
|
|
562
|
-
|
563
566
|
/**
|
564
567
|
* Return the native java.awt.Font associated with this PFont (if any).
|
565
|
-
|
568
|
+
*
|
569
|
+
* @return
|
566
570
|
*/
|
567
571
|
public Object getNative() {
|
568
572
|
if (subsetting) {
|
@@ -571,62 +575,60 @@ public class PFont implements PConstants {
|
|
571
575
|
return font;
|
572
576
|
}
|
573
577
|
|
574
|
-
|
575
578
|
/**
|
576
579
|
* Return size of this font.
|
577
|
-
|
580
|
+
*
|
581
|
+
* @return
|
578
582
|
*/
|
579
583
|
public int getSize() {
|
580
584
|
return size;
|
581
585
|
}
|
582
586
|
|
583
|
-
|
584
587
|
// public void setDefaultSize(int size) {
|
585
588
|
// defaultSize = size;
|
586
589
|
// }
|
587
|
-
|
588
|
-
|
589
590
|
/**
|
590
|
-
* Returns the size that will be used when textFont(font) is called.
|
591
|
-
*
|
592
|
-
*
|
593
|
-
*
|
594
|
-
*
|
595
|
-
|
591
|
+
* Returns the size that will be used when textFont(font) is called. When
|
592
|
+
* drawing with 2x pixel density, bitmap fonts in OpenGL need to be created
|
593
|
+
* (behind the scenes) at double the requested size. This ensures that they're
|
594
|
+
* shown at half on displays (so folks don't have to change their sketch
|
595
|
+
* code).
|
596
|
+
*
|
597
|
+
* @return
|
596
598
|
*/
|
597
599
|
public int getDefaultSize() {
|
598
600
|
//return defaultSize;
|
599
601
|
return size / density;
|
600
602
|
}
|
601
603
|
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
604
|
+
/**
|
605
|
+
*
|
606
|
+
* @return
|
607
|
+
*/
|
608
|
+
public boolean isSmooth() {
|
607
609
|
return smooth;
|
608
610
|
}
|
609
611
|
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
612
|
+
/**
|
613
|
+
*
|
614
|
+
* @return
|
615
|
+
*/
|
616
|
+
public boolean isStream() {
|
615
617
|
return stream;
|
616
618
|
}
|
617
619
|
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
620
|
+
/**
|
621
|
+
*
|
622
|
+
*/
|
623
|
+
public void setSubsetting() {
|
622
624
|
subsetting = true;
|
623
625
|
}
|
624
626
|
|
625
|
-
|
626
627
|
/**
|
627
|
-
* Attempt to find the native version of this font.
|
628
|
-
*
|
629
|
-
|
628
|
+
* Attempt to find the native version of this font. (Public so that it can be
|
629
|
+
* used by OpenGL or other renderers.)
|
630
|
+
*
|
631
|
+
* @return
|
630
632
|
*/
|
631
633
|
public Object findNative() {
|
632
634
|
if (font == null) {
|
@@ -651,20 +653,20 @@ public class PFont implements PConstants {
|
|
651
653
|
return font;
|
652
654
|
}
|
653
655
|
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
656
|
+
/**
|
657
|
+
*
|
658
|
+
* @param c
|
659
|
+
* @return
|
660
|
+
*/
|
661
|
+
public Glyph getGlyph(char c) {
|
660
662
|
int index = index(c);
|
661
663
|
return (index == -1) ? null : glyphs[index];
|
662
664
|
}
|
663
665
|
|
664
|
-
|
665
666
|
/**
|
666
667
|
* Get index for the character.
|
667
|
-
|
668
|
+
*
|
669
|
+
* @param c
|
668
670
|
* @return index into arrays or -1 if not found
|
669
671
|
*/
|
670
672
|
protected int index(char c) {
|
@@ -688,134 +690,144 @@ public class PFont implements PConstants {
|
|
688
690
|
}
|
689
691
|
}
|
690
692
|
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
693
|
+
/**
|
694
|
+
*
|
695
|
+
* @param c
|
696
|
+
* @return
|
697
|
+
*/
|
698
|
+
protected int indexActual(char c) {
|
697
699
|
// degenerate case, but the find function will have trouble
|
698
700
|
// if there are somehow zero chars in the lookup
|
699
701
|
//if (value.length == 0) return -1;
|
700
|
-
if (glyphCount == 0)
|
702
|
+
if (glyphCount == 0) {
|
703
|
+
return -1;
|
704
|
+
}
|
701
705
|
|
702
706
|
// quicker lookup for the ascii fellers
|
703
|
-
if (c < 128)
|
707
|
+
if (c < 128) {
|
708
|
+
return ascii[c];
|
709
|
+
}
|
704
710
|
|
705
711
|
// some other unicode char, hunt it out
|
706
712
|
//return index_hunt(c, 0, value.length-1);
|
707
|
-
return indexHunt(c, 0, glyphCount-1);
|
713
|
+
return indexHunt(c, 0, glyphCount - 1);
|
708
714
|
}
|
709
715
|
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
716
|
+
/**
|
717
|
+
*
|
718
|
+
* @param c
|
719
|
+
* @param start
|
720
|
+
* @param stop
|
721
|
+
* @return
|
722
|
+
*/
|
723
|
+
protected int indexHunt(int c, int start, int stop) {
|
718
724
|
int pivot = (start + stop) / 2;
|
719
725
|
|
720
726
|
// if this is the char, then return it
|
721
|
-
if (c == glyphs[pivot].value)
|
727
|
+
if (c == glyphs[pivot].value) {
|
728
|
+
return pivot;
|
729
|
+
}
|
722
730
|
|
723
731
|
// char doesn't exist, otherwise would have been the pivot
|
724
732
|
//if (start == stop) return -1;
|
725
|
-
if (start >= stop)
|
733
|
+
if (start >= stop) {
|
734
|
+
return -1;
|
735
|
+
}
|
726
736
|
|
727
737
|
// if it's in the lower half, continue searching that
|
728
|
-
if (c < glyphs[pivot].value)
|
738
|
+
if (c < glyphs[pivot].value) {
|
739
|
+
return indexHunt(c, start, pivot - 1);
|
740
|
+
}
|
729
741
|
|
730
742
|
// if it's in the upper half, continue there
|
731
|
-
return indexHunt(c, pivot+1, stop);
|
743
|
+
return indexHunt(c, pivot + 1, stop);
|
732
744
|
}
|
733
745
|
|
734
|
-
|
735
746
|
/**
|
736
|
-
* Currently un-implemented for .vlw fonts,
|
737
|
-
*
|
738
|
-
|
739
|
-
|
740
|
-
|
747
|
+
* Currently un-implemented for .vlw fonts, but honored for layout in case
|
748
|
+
* subclasses use it.
|
749
|
+
*
|
750
|
+
* @param a
|
751
|
+
* @param b
|
752
|
+
* @return
|
741
753
|
*/
|
742
754
|
public float kern(char a, char b) {
|
743
755
|
return 0;
|
744
756
|
}
|
745
757
|
|
746
|
-
|
747
758
|
/**
|
748
|
-
* Returns the ascent of this font from the baseline.
|
749
|
-
*
|
750
|
-
|
759
|
+
* Returns the ascent of this font from the baseline. The value is based on a
|
760
|
+
* font of size 1.
|
761
|
+
*
|
762
|
+
* @return
|
751
763
|
*/
|
752
764
|
public float ascent() {
|
753
765
|
return ((float) ascent / (float) size);
|
754
766
|
}
|
755
767
|
|
756
|
-
|
757
768
|
/**
|
758
|
-
* Returns how far this font descends from the baseline.
|
759
|
-
*
|
760
|
-
|
769
|
+
* Returns how far this font descends from the baseline. The value is based on
|
770
|
+
* a font size of 1.
|
771
|
+
*
|
772
|
+
* @return
|
761
773
|
*/
|
762
774
|
public float descent() {
|
763
775
|
return ((float) descent / (float) size);
|
764
776
|
}
|
765
777
|
|
766
|
-
|
767
778
|
/**
|
768
779
|
* Width of this character for a font of size 1.
|
769
|
-
|
770
|
-
|
780
|
+
*
|
781
|
+
* @param c
|
782
|
+
* @return
|
771
783
|
*/
|
772
784
|
public float width(char c) {
|
773
|
-
if (c == 32)
|
785
|
+
if (c == 32) {
|
786
|
+
return width('i');
|
787
|
+
}
|
774
788
|
|
775
789
|
int cc = index(c);
|
776
|
-
if (cc == -1)
|
790
|
+
if (cc == -1) {
|
791
|
+
return 0;
|
792
|
+
}
|
777
793
|
|
778
794
|
return ((float) glyphs[cc].setWidth / (float) size);
|
779
795
|
}
|
780
796
|
|
781
|
-
|
782
797
|
//////////////////////////////////////////////////////////////
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
public int getGlyphCount() {
|
798
|
+
/**
|
799
|
+
*
|
800
|
+
* @return
|
801
|
+
*/
|
802
|
+
public int getGlyphCount() {
|
791
803
|
return glyphCount;
|
792
804
|
}
|
793
805
|
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
806
|
+
/**
|
807
|
+
*
|
808
|
+
* @param i
|
809
|
+
* @return
|
810
|
+
*/
|
811
|
+
public Glyph getGlyph(int i) {
|
800
812
|
return glyphs[i];
|
801
813
|
}
|
802
814
|
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
815
|
+
/**
|
816
|
+
*
|
817
|
+
* @param ch
|
818
|
+
* @return
|
819
|
+
*/
|
820
|
+
public PShape getShape(char ch) {
|
809
821
|
return getShape(ch, 0);
|
810
822
|
}
|
811
823
|
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
824
|
+
/**
|
825
|
+
*
|
826
|
+
* @param ch
|
827
|
+
* @param detail
|
828
|
+
* @return
|
829
|
+
*/
|
830
|
+
public PShape getShape(char ch, float detail) {
|
819
831
|
Font font = (Font) getNative();
|
820
832
|
if (font == null) {
|
821
833
|
throw new IllegalArgumentException("getShape() only works on fonts loaded with createFont()");
|
@@ -826,18 +838,19 @@ public class PFont implements PConstants {
|
|
826
838
|
// six element array received from the Java2D path iterator
|
827
839
|
float[] iterPoints = new float[6];
|
828
840
|
// array passed to createGylphVector
|
829
|
-
char[] textArray = new char[]
|
841
|
+
char[] textArray = new char[]{ch};
|
830
842
|
|
831
843
|
//Graphics2D graphics = (Graphics2D) this.getGraphics();
|
832
844
|
//FontRenderContext frc = graphics.getFontRenderContext();
|
833
845
|
@SuppressWarnings("deprecation")
|
834
|
-
FontRenderContext frc
|
835
|
-
Toolkit.getDefaultToolkit().getFontMetrics(font).getFontRenderContext();
|
846
|
+
FontRenderContext frc
|
847
|
+
= Toolkit.getDefaultToolkit().getFontMetrics(font).getFontRenderContext();
|
836
848
|
GlyphVector gv = font.createGlyphVector(frc, textArray);
|
837
849
|
Shape shp = gv.getOutline();
|
838
850
|
// make everything into moveto and lineto
|
839
|
-
PathIterator iter = (detail == 0)
|
840
|
-
shp.getPathIterator(null)
|
851
|
+
PathIterator iter = (detail == 0)
|
852
|
+
? shp.getPathIterator(null)
|
853
|
+
: // maintain curves
|
841
854
|
shp.getPathIterator(null, detail); // convert to line segments
|
842
855
|
|
843
856
|
int contours = 0;
|
@@ -846,50 +859,50 @@ public class PFont implements PConstants {
|
|
846
859
|
while (!iter.isDone()) {
|
847
860
|
int type = iter.currentSegment(iterPoints);
|
848
861
|
switch (type) {
|
849
|
-
|
862
|
+
case PathIterator.SEG_MOVETO: // 1 point (2 vars) in textPoints
|
850
863
|
// System.out.println("moveto");
|
851
864
|
// if (!contour) {
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
865
|
+
if (contours == 0) {
|
866
|
+
s.beginShape();
|
867
|
+
} else {
|
868
|
+
s.beginContour();
|
856
869
|
// contour = true;
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
870
|
+
}
|
871
|
+
contours++;
|
872
|
+
s.vertex(iterPoints[0], iterPoints[1]);
|
873
|
+
break;
|
861
874
|
|
862
|
-
|
875
|
+
case PathIterator.SEG_LINETO: // 1 point
|
863
876
|
// System.out.println("lineto");
|
864
877
|
// PApplet.println(PApplet.subset(iterPoints, 0, 2));
|
865
|
-
|
866
|
-
|
878
|
+
s.vertex(iterPoints[0], iterPoints[1]);
|
879
|
+
break;
|
867
880
|
|
868
|
-
|
881
|
+
case PathIterator.SEG_QUADTO: // 2 points
|
869
882
|
// System.out.println("quadto");
|
870
883
|
// PApplet.println(PApplet.subset(iterPoints, 0, 4));
|
871
|
-
|
872
|
-
|
873
|
-
|
884
|
+
s.quadraticVertex(iterPoints[0], iterPoints[1],
|
885
|
+
iterPoints[2], iterPoints[3]);
|
886
|
+
break;
|
874
887
|
|
875
|
-
|
888
|
+
case PathIterator.SEG_CUBICTO: // 3 points
|
876
889
|
// System.out.println("cubicto");
|
877
890
|
// PApplet.println(iterPoints);
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
891
|
+
s.quadraticVertex(iterPoints[0], iterPoints[1],
|
892
|
+
iterPoints[2], iterPoints[3],
|
893
|
+
iterPoints[4], iterPoints[5]);
|
894
|
+
break;
|
882
895
|
|
883
|
-
|
896
|
+
case PathIterator.SEG_CLOSE:
|
884
897
|
// System.out.println("close");
|
885
|
-
|
898
|
+
if (contours > 1) {
|
886
899
|
// contours--;
|
887
900
|
// if (contours == 0) {
|
888
901
|
//// s.endShape();
|
889
902
|
// } else {
|
890
|
-
|
891
|
-
|
892
|
-
|
903
|
+
s.endContour();
|
904
|
+
}
|
905
|
+
break;
|
893
906
|
}
|
894
907
|
// PApplet.println(iterPoints);
|
895
908
|
iter.next();
|
@@ -898,10 +911,7 @@ public class PFont implements PConstants {
|
|
898
911
|
return s;
|
899
912
|
}
|
900
913
|
|
901
|
-
|
902
914
|
//////////////////////////////////////////////////////////////
|
903
|
-
|
904
|
-
|
905
915
|
static final char[] EXTRA_CHARS = {
|
906
916
|
0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
|
907
917
|
0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
|
@@ -933,32 +943,34 @@ public class PFont implements PConstants {
|
|
933
943
|
0xFB01, 0xFB02
|
934
944
|
};
|
935
945
|
|
936
|
-
|
937
946
|
/**
|
938
947
|
* The default Processing character set.
|
939
948
|
* <P>
|
940
|
-
* This is the union of the Mac Roman and Windows ANSI (CP1250)
|
941
|
-
*
|
942
|
-
*
|
943
|
-
*
|
949
|
+
* This is the union of the Mac Roman and Windows ANSI (CP1250) character
|
950
|
+
* sets. ISO 8859-1 Latin 1 is Unicode characters 0x80 -> 0xFF, and would seem
|
951
|
+
* a good standard, but in practice, most P5 users would rather have
|
952
|
+
* characters that they expect from their platform's fonts.
|
944
953
|
* <P>
|
945
|
-
* This is more of an interim solution until a much better
|
946
|
-
*
|
947
|
-
*
|
954
|
+
* This is more of an interim solution until a much better font solution can
|
955
|
+
* be determined. (i.e. create fonts on the fly from some sort of vector
|
956
|
+
* format).
|
948
957
|
* <P>
|
949
958
|
* Not that I expect that to happen.
|
950
959
|
*/
|
951
960
|
static public char[] CHARSET;
|
961
|
+
|
952
962
|
static {
|
953
|
-
CHARSET = new char[126-33+1 + EXTRA_CHARS.length];
|
963
|
+
CHARSET = new char[126 - 33 + 1 + EXTRA_CHARS.length];
|
954
964
|
int index = 0;
|
955
965
|
for (int i = 33; i <= 126; i++) {
|
956
|
-
CHARSET[index++] = (char)i;
|
966
|
+
CHARSET[index++] = (char) i;
|
957
967
|
}
|
958
968
|
for (int i = 0; i < EXTRA_CHARS.length; i++) {
|
959
969
|
CHARSET[index++] = EXTRA_CHARS[i];
|
960
970
|
}
|
961
|
-
}
|
971
|
+
}
|
972
|
+
|
973
|
+
;
|
962
974
|
|
963
975
|
|
964
976
|
/**
|
@@ -986,16 +998,16 @@ public class PFont implements PConstants {
|
|
986
998
|
return list;
|
987
999
|
}
|
988
1000
|
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
1001
|
+
/**
|
1002
|
+
*
|
1003
|
+
*/
|
1004
|
+
static public void loadFonts() {
|
993
1005
|
if (fonts == null) {
|
994
|
-
GraphicsEnvironment ge
|
995
|
-
GraphicsEnvironment.getLocalGraphicsEnvironment();
|
1006
|
+
GraphicsEnvironment ge
|
1007
|
+
= GraphicsEnvironment.getLocalGraphicsEnvironment();
|
996
1008
|
fonts = ge.getAllFonts();
|
997
1009
|
if (PApplet.platform == PConstants.MACOSX) {
|
998
|
-
fontDifferent = new HashMap
|
1010
|
+
fontDifferent = new HashMap<>();
|
999
1011
|
for (Font font : fonts) {
|
1000
1012
|
// getName() returns the PostScript name on OS X 10.6 w/ Java 6.
|
1001
1013
|
fontDifferent.put(font.getName(), font);
|
@@ -1005,13 +1017,13 @@ public class PFont implements PConstants {
|
|
1005
1017
|
}
|
1006
1018
|
}
|
1007
1019
|
|
1008
|
-
|
1009
1020
|
/**
|
1010
|
-
* Starting with Java 1.5, Apple broke the ability to specify most fonts.
|
1011
|
-
*
|
1021
|
+
* Starting with Java 1.5, Apple broke the ability to specify most fonts. This
|
1022
|
+
* bug was filed years ago as #4769141 at bugreporter.apple.com. More:
|
1012
1023
|
* <a href="http://dev.processing.org/bugs/show_bug.cgi?id=407">Bug 407</a>.
|
1013
|
-
|
1014
|
-
|
1024
|
+
*
|
1025
|
+
* @param name
|
1026
|
+
* @return
|
1015
1027
|
*/
|
1016
1028
|
static public Font findFont(String name) {
|
1017
1029
|
loadFonts();
|
@@ -1029,79 +1041,76 @@ public class PFont implements PConstants {
|
|
1029
1041
|
return new Font(name, Font.PLAIN, 1);
|
1030
1042
|
}
|
1031
1043
|
|
1032
|
-
|
1033
1044
|
//////////////////////////////////////////////////////////////
|
1034
|
-
|
1035
|
-
|
1036
1045
|
/**
|
1037
1046
|
* A single character, and its visage.
|
1038
1047
|
*/
|
1039
1048
|
public class Glyph {
|
1040
1049
|
|
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
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1050
|
+
/**
|
1051
|
+
*
|
1052
|
+
*/
|
1053
|
+
public PImage image;
|
1054
|
+
|
1055
|
+
/**
|
1056
|
+
*
|
1057
|
+
*/
|
1058
|
+
public int value;
|
1059
|
+
|
1060
|
+
/**
|
1061
|
+
*
|
1062
|
+
*/
|
1063
|
+
public int height;
|
1064
|
+
|
1065
|
+
/**
|
1066
|
+
*
|
1067
|
+
*/
|
1068
|
+
public int width;
|
1069
|
+
|
1070
|
+
/**
|
1071
|
+
*
|
1072
|
+
*/
|
1073
|
+
public int index;
|
1074
|
+
|
1075
|
+
/**
|
1076
|
+
*
|
1077
|
+
*/
|
1078
|
+
public int setWidth;
|
1079
|
+
|
1080
|
+
/**
|
1081
|
+
*
|
1082
|
+
*/
|
1083
|
+
public int topExtent;
|
1084
|
+
|
1085
|
+
/**
|
1086
|
+
*
|
1087
|
+
*/
|
1088
|
+
public int leftExtent;
|
1089
|
+
|
1090
|
+
/**
|
1091
|
+
*
|
1092
|
+
*/
|
1093
|
+
public Glyph() {
|
1085
1094
|
index = -1;
|
1086
1095
|
// used when reading from a stream or for subclasses
|
1087
1096
|
}
|
1088
1097
|
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1098
|
+
/**
|
1099
|
+
*
|
1100
|
+
* @param is
|
1101
|
+
* @throws IOException
|
1102
|
+
*/
|
1103
|
+
public Glyph(DataInputStream is) throws IOException {
|
1095
1104
|
index = -1;
|
1096
1105
|
readHeader(is);
|
1097
1106
|
}
|
1098
1107
|
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1108
|
+
/**
|
1109
|
+
*
|
1110
|
+
* @param is
|
1111
|
+
* @throws IOException
|
1112
|
+
*/
|
1113
|
+
protected final void readHeader(DataInputStream is) throws IOException {
|
1105
1114
|
value = is.readInt();
|
1106
1115
|
height = is.readInt();
|
1107
1116
|
width = is.readInt();
|
@@ -1116,19 +1125,23 @@ public class PFont implements PConstants {
|
|
1116
1125
|
// seem to be way too large.. perhaps they're the max?
|
1117
1126
|
// as such, use a more traditional marker for ascent/descent
|
1118
1127
|
if (value == 'd') {
|
1119
|
-
if (ascent == 0)
|
1128
|
+
if (ascent == 0) {
|
1129
|
+
ascent = topExtent;
|
1130
|
+
}
|
1120
1131
|
}
|
1121
1132
|
if (value == 'p') {
|
1122
|
-
if (descent == 0)
|
1133
|
+
if (descent == 0) {
|
1134
|
+
descent = -topExtent + height;
|
1135
|
+
}
|
1123
1136
|
}
|
1124
1137
|
}
|
1125
1138
|
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1139
|
+
/**
|
1140
|
+
*
|
1141
|
+
* @param os
|
1142
|
+
* @throws IOException
|
1143
|
+
*/
|
1144
|
+
protected void writeHeader(DataOutputStream os) throws IOException {
|
1132
1145
|
os.writeInt(value);
|
1133
1146
|
os.writeInt(height);
|
1134
1147
|
os.writeInt(width);
|
@@ -1138,12 +1151,12 @@ public class PFont implements PConstants {
|
|
1138
1151
|
os.writeInt(0); // padding
|
1139
1152
|
}
|
1140
1153
|
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1154
|
+
/**
|
1155
|
+
*
|
1156
|
+
* @param is
|
1157
|
+
* @throws IOException
|
1158
|
+
*/
|
1159
|
+
protected void readBitmap(DataInputStream is) throws IOException {
|
1147
1160
|
image = new PImage(width, height, ALPHA);
|
1148
1161
|
int bitmapSize = width * height;
|
1149
1162
|
|
@@ -1156,7 +1169,7 @@ public class PFont implements PConstants {
|
|
1156
1169
|
int[] pixels = image.pixels;
|
1157
1170
|
for (int y = 0; y < h; y++) {
|
1158
1171
|
for (int x = 0; x < w; x++) {
|
1159
|
-
pixels[y * width + x] = temp[y*w + x] & 0xff;
|
1172
|
+
pixels[y * width + x] = temp[y * w + x] & 0xff;
|
1160
1173
|
// System.out.print((image.pixels[y*64+x] > 128) ? "*" : ".");
|
1161
1174
|
}
|
1162
1175
|
// System.out.println();
|
@@ -1164,13 +1177,13 @@ public class PFont implements PConstants {
|
|
1164
1177
|
// System.out.println();
|
1165
1178
|
}
|
1166
1179
|
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
int[] pixels
|
1180
|
+
/**
|
1181
|
+
*
|
1182
|
+
* @param os
|
1183
|
+
* @throws IOException
|
1184
|
+
*/
|
1185
|
+
protected void writeBitmap(DataOutputStream os) throws IOException {
|
1186
|
+
int[] pixels = image.pixels;
|
1174
1187
|
for (int y = 0; y < height; y++) {
|
1175
1188
|
for (int x = 0; x < width; x++) {
|
1176
1189
|
os.write(pixels[y * width + x] & 0xff);
|
@@ -1178,11 +1191,11 @@ public class PFont implements PConstants {
|
|
1178
1191
|
}
|
1179
1192
|
}
|
1180
1193
|
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1194
|
+
/**
|
1195
|
+
*
|
1196
|
+
* @param c
|
1197
|
+
*/
|
1198
|
+
protected Glyph(char c) {
|
1186
1199
|
int mbox3 = size * 3;
|
1187
1200
|
lazyGraphics.setColor(Color.white);
|
1188
1201
|
lazyGraphics.fillRect(0, 0, mbox3, mbox3);
|
@@ -1200,10 +1213,18 @@ public class PFont implements PConstants {
|
|
1200
1213
|
for (int x = 0; x < mbox3; x++) {
|
1201
1214
|
int sample = lazySamples[y * mbox3 + x] & 0xff;
|
1202
1215
|
if (sample != 255) {
|
1203
|
-
if (x < minX)
|
1204
|
-
|
1205
|
-
|
1206
|
-
if (y
|
1216
|
+
if (x < minX) {
|
1217
|
+
minX = x;
|
1218
|
+
}
|
1219
|
+
if (y < minY) {
|
1220
|
+
minY = y;
|
1221
|
+
}
|
1222
|
+
if (x > maxX) {
|
1223
|
+
maxX = x;
|
1224
|
+
}
|
1225
|
+
if (y > maxY) {
|
1226
|
+
maxY = y;
|
1227
|
+
}
|
1207
1228
|
pixelFound = true;
|
1208
1229
|
}
|
1209
1230
|
}
|
@@ -1223,7 +1244,7 @@ public class PFont implements PConstants {
|
|
1223
1244
|
|
1224
1245
|
// offset from vertical location of baseline
|
1225
1246
|
// of where the char was drawn (size*2)
|
1226
|
-
topExtent = size*2 - minY;
|
1247
|
+
topExtent = size * 2 - minY;
|
1227
1248
|
|
1228
1249
|
// offset from left of where coord was drawn
|
1229
1250
|
leftExtent = minX - size;
|
@@ -1240,10 +1261,14 @@ public class PFont implements PConstants {
|
|
1240
1261
|
|
1241
1262
|
// replace the ascent/descent values with something.. err, decent.
|
1242
1263
|
if (value == 'd') {
|
1243
|
-
if (ascent == 0)
|
1264
|
+
if (ascent == 0) {
|
1265
|
+
ascent = topExtent;
|
1266
|
+
}
|
1244
1267
|
}
|
1245
1268
|
if (value == 'p') {
|
1246
|
-
if (descent == 0)
|
1269
|
+
if (descent == 0) {
|
1270
|
+
descent = -topExtent + height;
|
1271
|
+
}
|
1247
1272
|
}
|
1248
1273
|
}
|
1249
1274
|
}
|