picrate 0.8.0-java → 0.9.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/CHANGELOG.md +4 -0
- data/docs/_libraries/net.md +11 -0
- data/docs/_libraries/picrate.md +0 -2
- data/docs/_magic/processing.md +0 -3
- data/docs/_methods/data_path.md +0 -2
- data/docs/_methods/library_loader.md +1 -1
- data/docs/_methods/settings.md +1 -1
- data/docs/assets/net.png +0 -0
- data/lib/picrate.rb +2 -2
- data/lib/picrate/app.rb +1 -1
- data/lib/picrate/version.rb +1 -1
- data/library/dxf/dxf.rb +4 -0
- data/library/net/net.rb +5 -0
- data/pom.rb +1 -1
- data/pom.xml +1 -1
- data/src/main/java/processing/awt/PSurfaceAWT.java +4 -31
- data/src/main/java/processing/core/PApplet.java +15397 -15455
- data/src/main/java/processing/core/PFont.java +117 -303
- data/src/main/java/processing/dxf/RawDXF.java +388 -0
- data/src/main/java/processing/net/Client.java +756 -0
- data/src/main/java/processing/net/Server.java +385 -0
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1192 -1221
- data/vendors/Rakefile +1 -1
- metadata +11 -4
@@ -1,25 +1,27 @@
|
|
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
|
-
|
7
|
-
|
8
|
-
|
6
|
+
Copyright (c) 2012-19 The Processing Foundation
|
7
|
+
Copyright (c) 2004-12 Ben Fry & Casey Reas
|
8
|
+
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
This library is free software; you can redistribute it and/or
|
11
|
+
modify it under the terms of version 2.01 of the GNU Lesser General
|
12
|
+
Public License as published by the Free Software Foundation.
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
This library is distributed in the hope that it will be useful,
|
15
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
17
|
+
Lesser General Public License for more details.
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
You should have received a copy of the GNU Lesser General
|
20
|
+
Public License along with this library; if not, write to the
|
21
|
+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
22
|
+
Boston, MA 02111-1307 USA
|
23
|
+
|
24
|
+
Hacked by Martin Prout to remove Apple shit, not needed on linux
|
23
25
|
*/
|
24
26
|
package processing.core;
|
25
27
|
|
@@ -30,7 +32,7 @@ import java.awt.geom.PathIterator;
|
|
30
32
|
import java.awt.image.*;
|
31
33
|
import java.io.*;
|
32
34
|
import java.util.Arrays;
|
33
|
-
import java.util.HashMap;
|
35
|
+
//import java.util.HashMap;
|
34
36
|
|
35
37
|
/**
|
36
38
|
* Grayscale bitmap font class used by Processing.
|
@@ -153,47 +155,16 @@ public class PFont implements PConstants {
|
|
153
155
|
protected boolean fontSearched;
|
154
156
|
|
155
157
|
/**
|
156
|
-
*
|
157
|
-
*
|
158
|
-
* that they can't be bothered to fix.
|
159
|
-
*/
|
160
|
-
static protected Font[] fonts;
|
161
|
-
|
162
|
-
/**
|
163
|
-
*
|
164
|
-
*/
|
165
|
-
static protected HashMap<String, Font> fontDifferent;
|
166
|
-
|
167
|
-
// /**
|
168
|
-
// * If not null, this font is set to load dynamically. This is the default
|
169
|
-
// * when createFont() method is called without a character set. Bitmap
|
170
|
-
// * versions of characters are only created when prompted by an index() call.
|
171
|
-
// */
|
172
|
-
// protected Font lazyFont;
|
173
|
-
/**
|
174
|
-
*
|
158
|
+
* The name of the font that Java uses when a font isn't found. See
|
159
|
+
* {@link #findFont(String)} and {@link #loadFonts()} for more info.
|
175
160
|
*/
|
161
|
+
static protected String systemFontName;
|
162
|
+
static protected String[] fonts;
|
176
163
|
protected BufferedImage lazyImage;
|
177
|
-
|
178
|
-
/**
|
179
|
-
*
|
180
|
-
*/
|
181
164
|
protected Graphics2D lazyGraphics;
|
182
|
-
|
183
|
-
/**
|
184
|
-
*
|
185
|
-
*/
|
186
165
|
protected FontMetrics lazyMetrics;
|
187
|
-
|
188
|
-
/**
|
189
|
-
*
|
190
|
-
*/
|
191
166
|
protected int[] lazySamples;
|
192
167
|
|
193
|
-
/**
|
194
|
-
* for subclasses that need to store metadata about the font
|
195
|
-
*/
|
196
|
-
// protected HashMap<PGraphics, Object> cacheMap;
|
197
168
|
/**
|
198
169
|
* @nowebref
|
199
170
|
*/
|
@@ -226,9 +197,8 @@ public class PFont implements PConstants {
|
|
226
197
|
}
|
227
198
|
|
228
199
|
/**
|
229
|
-
* Create a new image-based font on the fly.
|
230
|
-
* characters will only be created as bitmaps when they're drawn.
|
231
|
-
*
|
200
|
+
* Create a new image-based font on the fly.If charset is set to null, the
|
201
|
+
* characters will only be created as bitmaps when they're drawn. *
|
232
202
|
* @param font
|
233
203
|
* @param smooth
|
234
204
|
* @nowebref
|
@@ -278,7 +248,7 @@ public class PFont implements PConstants {
|
|
278
248
|
//descent = lazyMetrics.getDescent();
|
279
249
|
if (charset == null) {
|
280
250
|
lazy = true;
|
281
|
-
// lazyFont = font;
|
251
|
+
// lazyFont = font;
|
282
252
|
|
283
253
|
} else {
|
284
254
|
// charset needs to be sorted to make index lookup run more quickly
|
@@ -307,24 +277,24 @@ public class PFont implements PConstants {
|
|
307
277
|
// foreign font, so just make ascent the max topExtent
|
308
278
|
// for > 1.0.9, not doing this anymore.
|
309
279
|
// instead using getAscent() and getDescent() values for these cases.
|
310
|
-
// if ((ascent == 0) && (descent == 0)) {
|
311
|
-
// //for (int i = 0; i < charCount; i++) {
|
312
|
-
// for (Glyph glyph : glyphs) {
|
313
|
-
// char cc = (char) glyph.value;
|
314
|
-
// //char cc = (char) glyphs[i].value;
|
315
|
-
// if (Character.isWhitespace(cc) ||
|
316
|
-
// (cc == '\u00A0') || (cc == '\u2007') || (cc == '\u202F')) {
|
317
|
-
// continue;
|
318
|
-
// }
|
319
|
-
// if (glyph.topExtent > ascent) {
|
320
|
-
// ascent = glyph.topExtent;
|
321
|
-
// }
|
322
|
-
// int d = -glyph.topExtent + glyph.height;
|
323
|
-
// if (d > descent) {
|
324
|
-
// descent = d;
|
325
|
-
// }
|
326
|
-
// }
|
327
|
-
// }
|
280
|
+
// if ((ascent == 0) && (descent == 0)) {
|
281
|
+
// //for (int i = 0; i < charCount; i++) {
|
282
|
+
// for (Glyph glyph : glyphs) {
|
283
|
+
// char cc = (char) glyph.value;
|
284
|
+
// //char cc = (char) glyphs[i].value;
|
285
|
+
// if (Character.isWhitespace(cc) ||
|
286
|
+
// (cc == '\u00A0') || (cc == '\u2007') || (cc == '\u202F')) {
|
287
|
+
// continue;
|
288
|
+
// }
|
289
|
+
// if (glyph.topExtent > ascent) {
|
290
|
+
// ascent = glyph.topExtent;
|
291
|
+
// }
|
292
|
+
// int d = -glyph.topExtent + glyph.height;
|
293
|
+
// if (d > descent) {
|
294
|
+
// descent = d;
|
295
|
+
// }
|
296
|
+
// }
|
297
|
+
// }
|
328
298
|
}
|
329
299
|
|
330
300
|
// If not already created, just create these two characters to calculate
|
@@ -370,8 +340,7 @@ public class PFont implements PConstants {
|
|
370
340
|
|
371
341
|
/**
|
372
342
|
* @throws java.io.IOException
|
373
|
-
* @nowebref
|
374
|
-
* @param input InputStream
|
343
|
+
* @nowebref @param input InputStream
|
375
344
|
*/
|
376
345
|
public PFont(InputStream input) throws IOException {
|
377
346
|
DataInputStream is = new DataInputStream(input);
|
@@ -432,7 +401,7 @@ public class PFont implements PConstants {
|
|
432
401
|
}
|
433
402
|
// See if there's a native version of this font that can be used,
|
434
403
|
// in case that's of interest later.
|
435
|
-
// findNative();
|
404
|
+
// findNative();
|
436
405
|
}
|
437
406
|
|
438
407
|
/**
|
@@ -443,7 +412,6 @@ public class PFont implements PConstants {
|
|
443
412
|
* <p>
|
444
413
|
* It is assumed that the calling class will handle closing the stream when
|
445
414
|
* finished.
|
446
|
-
*
|
447
415
|
* @param output
|
448
416
|
* @throws java.io.IOException
|
449
417
|
*/
|
@@ -525,27 +493,18 @@ public class PFont implements PConstants {
|
|
525
493
|
glyphCount++;
|
526
494
|
}
|
527
495
|
|
528
|
-
/**
|
529
|
-
*
|
530
|
-
* @return
|
531
|
-
*/
|
532
496
|
public String getName() {
|
533
497
|
return name;
|
534
498
|
}
|
535
499
|
|
536
|
-
/**
|
537
|
-
*
|
538
|
-
* @return
|
539
|
-
*/
|
540
500
|
public String getPostScriptName() {
|
541
501
|
return psname;
|
542
502
|
}
|
543
503
|
|
544
504
|
/**
|
545
|
-
* Set the native complement of this font.
|
546
|
-
|
547
|
-
|
548
|
-
*
|
505
|
+
* Set the native complement of this font.Might be set internally via the
|
506
|
+
findFont() function, or externally by a deriveFont() call if the font is
|
507
|
+
resized by PGraphicsJava2D.
|
549
508
|
* @param font
|
550
509
|
*/
|
551
510
|
public void setNative(Object font) {
|
@@ -555,8 +514,7 @@ public class PFont implements PConstants {
|
|
555
514
|
/**
|
556
515
|
* Use the getNative() method instead, which allows library interfaces to be
|
557
516
|
* written in a cross-platform fashion for desktop, Android, and others.
|
558
|
-
*
|
559
|
-
* @return
|
517
|
+
* @return
|
560
518
|
*/
|
561
519
|
@Deprecated
|
562
520
|
public Font getFont() {
|
@@ -565,8 +523,7 @@ public class PFont implements PConstants {
|
|
565
523
|
|
566
524
|
/**
|
567
525
|
* Return the native java.awt.Font associated with this PFont (if any).
|
568
|
-
*
|
569
|
-
* @return
|
526
|
+
* @return
|
570
527
|
*/
|
571
528
|
public Object getNative() {
|
572
529
|
if (subsetting) {
|
@@ -577,58 +534,43 @@ public class PFont implements PConstants {
|
|
577
534
|
|
578
535
|
/**
|
579
536
|
* Return size of this font.
|
580
|
-
*
|
581
|
-
* @return
|
537
|
+
* @return
|
582
538
|
*/
|
583
539
|
public int getSize() {
|
584
540
|
return size;
|
585
541
|
}
|
586
542
|
|
587
|
-
// public void setDefaultSize(int size) {
|
588
|
-
// defaultSize = size;
|
589
|
-
// }
|
543
|
+
// public void setDefaultSize(int size) {
|
544
|
+
// defaultSize = size;
|
545
|
+
// }
|
590
546
|
/**
|
591
|
-
* Returns the size that will be used when textFont(font) is called.
|
547
|
+
* Returns the size that will be used when textFont(font) is called.When
|
592
548
|
* drawing with 2x pixel density, bitmap fonts in OpenGL need to be created
|
593
549
|
* (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
|
-
*
|
596
|
-
*
|
597
|
-
* @return
|
550
|
+
* shown at half on displays (so folks don't have to change their sketch code).
|
551
|
+
* @return
|
598
552
|
*/
|
599
553
|
public int getDefaultSize() {
|
600
554
|
//return defaultSize;
|
601
555
|
return size / density;
|
602
556
|
}
|
603
557
|
|
604
|
-
/**
|
605
|
-
*
|
606
|
-
* @return
|
607
|
-
*/
|
608
558
|
public boolean isSmooth() {
|
609
559
|
return smooth;
|
610
560
|
}
|
611
561
|
|
612
|
-
/**
|
613
|
-
*
|
614
|
-
* @return
|
615
|
-
*/
|
616
562
|
public boolean isStream() {
|
617
563
|
return stream;
|
618
564
|
}
|
619
565
|
|
620
|
-
/**
|
621
|
-
*
|
622
|
-
*/
|
623
566
|
public void setSubsetting() {
|
624
567
|
subsetting = true;
|
625
568
|
}
|
626
569
|
|
627
570
|
/**
|
628
|
-
* Attempt to find the native version of this font.
|
571
|
+
* Attempt to find the native version of this font.(Public so that it can be
|
629
572
|
* used by OpenGL or other renderers.)
|
630
|
-
*
|
631
|
-
* @return
|
573
|
+
* @return
|
632
574
|
*/
|
633
575
|
public Object findNative() {
|
634
576
|
if (font == null) {
|
@@ -653,11 +595,6 @@ public class PFont implements PConstants {
|
|
653
595
|
return font;
|
654
596
|
}
|
655
597
|
|
656
|
-
/**
|
657
|
-
*
|
658
|
-
* @param c
|
659
|
-
* @return
|
660
|
-
*/
|
661
598
|
public Glyph getGlyph(char c) {
|
662
599
|
int index = index(c);
|
663
600
|
return (index == -1) ? null : glyphs[index];
|
@@ -690,11 +627,6 @@ public class PFont implements PConstants {
|
|
690
627
|
}
|
691
628
|
}
|
692
629
|
|
693
|
-
/**
|
694
|
-
*
|
695
|
-
* @param c
|
696
|
-
* @return
|
697
|
-
*/
|
698
630
|
protected int indexActual(char c) {
|
699
631
|
// degenerate case, but the find function will have trouble
|
700
632
|
// if there are somehow zero chars in the lookup
|
@@ -713,13 +645,6 @@ public class PFont implements PConstants {
|
|
713
645
|
return indexHunt(c, 0, glyphCount - 1);
|
714
646
|
}
|
715
647
|
|
716
|
-
/**
|
717
|
-
*
|
718
|
-
* @param c
|
719
|
-
* @param start
|
720
|
-
* @param stop
|
721
|
-
* @return
|
722
|
-
*/
|
723
648
|
protected int indexHunt(int c, int start, int stop) {
|
724
649
|
int pivot = (start + stop) / 2;
|
725
650
|
|
@@ -746,30 +671,27 @@ public class PFont implements PConstants {
|
|
746
671
|
/**
|
747
672
|
* Currently un-implemented for .vlw fonts, but honored for layout in case
|
748
673
|
* subclasses use it.
|
749
|
-
*
|
750
674
|
* @param a
|
751
675
|
* @param b
|
752
|
-
* @return
|
676
|
+
* @return
|
753
677
|
*/
|
754
678
|
public float kern(char a, char b) {
|
755
679
|
return 0;
|
756
680
|
}
|
757
681
|
|
758
682
|
/**
|
759
|
-
* Returns the ascent of this font from the baseline.
|
683
|
+
* Returns the ascent of this font from the baseline.The value is based on a
|
760
684
|
* font of size 1.
|
761
|
-
*
|
762
|
-
* @return
|
685
|
+
* @return
|
763
686
|
*/
|
764
687
|
public float ascent() {
|
765
688
|
return ((float) ascent / (float) size);
|
766
689
|
}
|
767
690
|
|
768
691
|
/**
|
769
|
-
* Returns how far this font descends from the baseline.
|
770
|
-
|
771
|
-
*
|
772
|
-
* @return
|
692
|
+
* Returns how far this font descends from the baseline.The value is based on
|
693
|
+
a font size of 1.
|
694
|
+
* @return
|
773
695
|
*/
|
774
696
|
public float descent() {
|
775
697
|
return ((float) descent / (float) size);
|
@@ -777,9 +699,8 @@ public class PFont implements PConstants {
|
|
777
699
|
|
778
700
|
/**
|
779
701
|
* Width of this character for a font of size 1.
|
780
|
-
*
|
781
702
|
* @param c
|
782
|
-
* @return
|
703
|
+
* @return
|
783
704
|
*/
|
784
705
|
public float width(char c) {
|
785
706
|
if (c == 32) {
|
@@ -795,41 +716,21 @@ public class PFont implements PConstants {
|
|
795
716
|
}
|
796
717
|
|
797
718
|
//////////////////////////////////////////////////////////////
|
798
|
-
/**
|
799
|
-
*
|
800
|
-
* @return
|
801
|
-
*/
|
802
719
|
public int getGlyphCount() {
|
803
720
|
return glyphCount;
|
804
721
|
}
|
805
722
|
|
806
|
-
/**
|
807
|
-
*
|
808
|
-
* @param i
|
809
|
-
* @return
|
810
|
-
*/
|
811
723
|
public Glyph getGlyph(int i) {
|
812
724
|
return glyphs[i];
|
813
725
|
}
|
814
726
|
|
815
|
-
/**
|
816
|
-
*
|
817
|
-
* @param ch
|
818
|
-
* @return
|
819
|
-
*/
|
820
727
|
public PShape getShape(char ch) {
|
821
728
|
return getShape(ch, 0);
|
822
729
|
}
|
823
730
|
|
824
|
-
/**
|
825
|
-
*
|
826
|
-
* @param ch
|
827
|
-
* @param detail
|
828
|
-
* @return
|
829
|
-
*/
|
830
731
|
public PShape getShape(char ch, float detail) {
|
831
|
-
Font
|
832
|
-
if (
|
732
|
+
Font lfont = (Font) getNative();
|
733
|
+
if (lfont == null) {
|
833
734
|
throw new IllegalArgumentException("getShape() only works on fonts loaded with createFont()");
|
834
735
|
}
|
835
736
|
|
@@ -844,8 +745,8 @@ public class PFont implements PConstants {
|
|
844
745
|
//FontRenderContext frc = graphics.getFontRenderContext();
|
845
746
|
@SuppressWarnings("deprecation")
|
846
747
|
FontRenderContext frc
|
847
|
-
= Toolkit.getDefaultToolkit().getFontMetrics(
|
848
|
-
GlyphVector gv =
|
748
|
+
= Toolkit.getDefaultToolkit().getFontMetrics(lfont).getFontRenderContext();
|
749
|
+
GlyphVector gv = lfont.createGlyphVector(frc, textArray);
|
849
750
|
Shape shp = gv.getOutline();
|
850
751
|
// make everything into moveto and lineto
|
851
752
|
PathIterator iter = (detail == 0)
|
@@ -855,56 +756,56 @@ public class PFont implements PConstants {
|
|
855
756
|
|
856
757
|
int contours = 0;
|
857
758
|
//boolean outer = true;
|
858
|
-
// boolean contour = false;
|
759
|
+
// boolean contour = false;
|
859
760
|
while (!iter.isDone()) {
|
860
761
|
int type = iter.currentSegment(iterPoints);
|
861
762
|
switch (type) {
|
862
763
|
case PathIterator.SEG_MOVETO: // 1 point (2 vars) in textPoints
|
863
|
-
// System.out.println("moveto");
|
864
|
-
// if (!contour) {
|
764
|
+
// System.out.println("moveto");
|
765
|
+
// if (!contour) {
|
865
766
|
if (contours == 0) {
|
866
767
|
s.beginShape();
|
867
768
|
} else {
|
868
769
|
s.beginContour();
|
869
|
-
// contour = true;
|
770
|
+
// contour = true;
|
870
771
|
}
|
871
772
|
contours++;
|
872
773
|
s.vertex(iterPoints[0], iterPoints[1]);
|
873
774
|
break;
|
874
775
|
|
875
776
|
case PathIterator.SEG_LINETO: // 1 point
|
876
|
-
// System.out.println("lineto");
|
877
|
-
// PApplet.println(PApplet.subset(iterPoints, 0, 2));
|
777
|
+
// System.out.println("lineto");
|
778
|
+
// PApplet.println(PApplet.subset(iterPoints, 0, 2));
|
878
779
|
s.vertex(iterPoints[0], iterPoints[1]);
|
879
780
|
break;
|
880
781
|
|
881
782
|
case PathIterator.SEG_QUADTO: // 2 points
|
882
|
-
// System.out.println("quadto");
|
883
|
-
// PApplet.println(PApplet.subset(iterPoints, 0, 4));
|
783
|
+
// System.out.println("quadto");
|
784
|
+
// PApplet.println(PApplet.subset(iterPoints, 0, 4));
|
884
785
|
s.quadraticVertex(iterPoints[0], iterPoints[1],
|
885
786
|
iterPoints[2], iterPoints[3]);
|
886
787
|
break;
|
887
788
|
|
888
789
|
case PathIterator.SEG_CUBICTO: // 3 points
|
889
|
-
// System.out.println("cubicto");
|
890
|
-
// PApplet.println(iterPoints);
|
790
|
+
// System.out.println("cubicto");
|
791
|
+
// PApplet.println(iterPoints);
|
891
792
|
s.quadraticVertex(iterPoints[0], iterPoints[1],
|
892
793
|
iterPoints[2], iterPoints[3],
|
893
794
|
iterPoints[4], iterPoints[5]);
|
894
795
|
break;
|
895
796
|
|
896
797
|
case PathIterator.SEG_CLOSE:
|
897
|
-
// System.out.println("close");
|
798
|
+
// System.out.println("close");
|
898
799
|
if (contours > 1) {
|
899
|
-
// contours--;
|
900
|
-
// if (contours == 0) {
|
901
|
-
//// s.endShape();
|
902
|
-
// } else {
|
800
|
+
// contours--;
|
801
|
+
// if (contours == 0) {
|
802
|
+
//// s.endShape();
|
803
|
+
// } else {
|
903
804
|
s.endContour();
|
904
805
|
}
|
905
806
|
break;
|
906
807
|
}
|
907
|
-
// PApplet.println(iterPoints);
|
808
|
+
// PApplet.println(iterPoints);
|
908
809
|
iter.next();
|
909
810
|
}
|
910
811
|
s.endShape(CLOSE);
|
@@ -968,77 +869,53 @@ public class PFont implements PConstants {
|
|
968
869
|
for (int i = 0; i < EXTRA_CHARS.length; i++) {
|
969
870
|
CHARSET[index++] = EXTRA_CHARS[i];
|
970
871
|
}
|
971
|
-
}
|
972
|
-
|
973
|
-
;
|
974
|
-
|
872
|
+
};
|
975
873
|
|
976
874
|
/**
|
977
|
-
*
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
* fonts. This function is meant as a tool for programming local
|
983
|
-
* applications and is not recommended for use in applets.
|
984
|
-
*
|
985
|
-
* ( end auto-generated )
|
986
|
-
*
|
987
|
-
* @return
|
988
|
-
* @webref pfont
|
989
|
-
* @usage application
|
990
|
-
* @brief Gets a list of the fonts installed on the system
|
991
|
-
*/
|
875
|
+
* @return
|
876
|
+
* @webref pfont
|
877
|
+
* @usage application
|
878
|
+
* @brief Gets a list of the fonts installed on the system
|
879
|
+
*/
|
992
880
|
static public String[] list() {
|
993
881
|
loadFonts();
|
994
|
-
|
995
|
-
for (int i = 0; i < list.length; i++) {
|
996
|
-
list[i] = fonts[i].getName();
|
997
|
-
}
|
998
|
-
return list;
|
882
|
+
return fonts;
|
999
883
|
}
|
1000
884
|
|
1001
885
|
/**
|
1002
|
-
*
|
886
|
+
* Make an internal list of available fonts.
|
1003
887
|
*/
|
1004
888
|
static public void loadFonts() {
|
1005
889
|
if (fonts == null) {
|
1006
890
|
GraphicsEnvironment ge
|
1007
891
|
= GraphicsEnvironment.getLocalGraphicsEnvironment();
|
1008
|
-
fonts = ge.
|
1009
|
-
if (PApplet.platform == PConstants.MACOSX) {
|
1010
|
-
fontDifferent = new HashMap<>();
|
1011
|
-
for (Font font : fonts) {
|
1012
|
-
// getName() returns the PostScript name on OS X 10.6 w/ Java 6.
|
1013
|
-
fontDifferent.put(font.getName(), font);
|
1014
|
-
//fontDifferent.put(font.getPSName(), font);
|
1015
|
-
}
|
1016
|
-
}
|
892
|
+
fonts = ge.getAvailableFontFamilyNames();
|
1017
893
|
}
|
1018
894
|
}
|
1019
895
|
|
1020
896
|
/**
|
1021
|
-
*
|
1022
|
-
*
|
1023
|
-
* <a href="
|
1024
|
-
*
|
897
|
+
* This function displays a warning when the font is not found and Java's
|
898
|
+
* system font is used. See:
|
899
|
+
* <a href="https://github.com/processing/processing/issues/5481">issue
|
900
|
+
* #5481</a>
|
1025
901
|
* @param name
|
1026
|
-
* @return
|
902
|
+
* @return
|
1027
903
|
*/
|
1028
904
|
static public Font findFont(String name) {
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
}
|
1035
|
-
// for (int i = 0; i < fonts.length; i++) {
|
1036
|
-
// if (name.equals(fonts[i].getName())) {
|
1037
|
-
// return fonts[i];
|
1038
|
-
// }
|
1039
|
-
// }
|
905
|
+
Font font = new Font(name, Font.PLAIN, 1);
|
906
|
+
// make sure we have the name of the system fallback font
|
907
|
+
if (systemFontName == null) {
|
908
|
+
// Figure out what the font is named when things fail
|
909
|
+
systemFontName = new Font("", Font.PLAIN, 1).getFontName();
|
1040
910
|
}
|
1041
|
-
|
911
|
+
// warn the user if they didn't get the font they want
|
912
|
+
if (!name.equals(systemFontName)
|
913
|
+
&& font.getFontName().equals(systemFontName)) {
|
914
|
+
PGraphics.showWarning("\"" + name + "\" is not available, "
|
915
|
+
+ "so another font will be used. "
|
916
|
+
+ "Use PFont.list() to show available fonts.");
|
917
|
+
}
|
918
|
+
return font;
|
1042
919
|
}
|
1043
920
|
|
1044
921
|
//////////////////////////////////////////////////////////////
|
@@ -1047,70 +924,26 @@ public class PFont implements PConstants {
|
|
1047
924
|
*/
|
1048
925
|
public class Glyph {
|
1049
926
|
|
1050
|
-
/**
|
1051
|
-
*
|
1052
|
-
*/
|
1053
927
|
public PImage image;
|
1054
|
-
|
1055
|
-
/**
|
1056
|
-
*
|
1057
|
-
*/
|
1058
928
|
public int value;
|
1059
|
-
|
1060
|
-
/**
|
1061
|
-
*
|
1062
|
-
*/
|
1063
929
|
public int height;
|
1064
|
-
|
1065
|
-
/**
|
1066
|
-
*
|
1067
|
-
*/
|
1068
930
|
public int width;
|
1069
|
-
|
1070
|
-
/**
|
1071
|
-
*
|
1072
|
-
*/
|
1073
931
|
public int index;
|
1074
|
-
|
1075
|
-
/**
|
1076
|
-
*
|
1077
|
-
*/
|
1078
932
|
public int setWidth;
|
1079
|
-
|
1080
|
-
/**
|
1081
|
-
*
|
1082
|
-
*/
|
1083
933
|
public int topExtent;
|
1084
|
-
|
1085
|
-
/**
|
1086
|
-
*
|
1087
|
-
*/
|
1088
934
|
public int leftExtent;
|
1089
935
|
|
1090
|
-
/**
|
1091
|
-
*
|
1092
|
-
*/
|
1093
936
|
public Glyph() {
|
1094
937
|
index = -1;
|
1095
938
|
// used when reading from a stream or for subclasses
|
1096
939
|
}
|
1097
940
|
|
1098
|
-
/**
|
1099
|
-
*
|
1100
|
-
* @param is
|
1101
|
-
* @throws IOException
|
1102
|
-
*/
|
1103
941
|
public Glyph(DataInputStream is) throws IOException {
|
1104
942
|
index = -1;
|
1105
943
|
readHeader(is);
|
1106
944
|
}
|
1107
945
|
|
1108
|
-
|
1109
|
-
*
|
1110
|
-
* @param is
|
1111
|
-
* @throws IOException
|
1112
|
-
*/
|
1113
|
-
protected final void readHeader(DataInputStream is) throws IOException {
|
946
|
+
protected void readHeader(DataInputStream is) throws IOException {
|
1114
947
|
value = is.readInt();
|
1115
948
|
height = is.readInt();
|
1116
949
|
width = is.readInt();
|
@@ -1136,11 +969,6 @@ public class PFont implements PConstants {
|
|
1136
969
|
}
|
1137
970
|
}
|
1138
971
|
|
1139
|
-
/**
|
1140
|
-
*
|
1141
|
-
* @param os
|
1142
|
-
* @throws IOException
|
1143
|
-
*/
|
1144
972
|
protected void writeHeader(DataOutputStream os) throws IOException {
|
1145
973
|
os.writeInt(value);
|
1146
974
|
os.writeInt(height);
|
@@ -1151,11 +979,6 @@ public class PFont implements PConstants {
|
|
1151
979
|
os.writeInt(0); // padding
|
1152
980
|
}
|
1153
981
|
|
1154
|
-
/**
|
1155
|
-
*
|
1156
|
-
* @param is
|
1157
|
-
* @throws IOException
|
1158
|
-
*/
|
1159
982
|
protected void readBitmap(DataInputStream is) throws IOException {
|
1160
983
|
image = new PImage(width, height, ALPHA);
|
1161
984
|
int bitmapSize = width * height;
|
@@ -1170,18 +993,13 @@ public class PFont implements PConstants {
|
|
1170
993
|
for (int y = 0; y < h; y++) {
|
1171
994
|
for (int x = 0; x < w; x++) {
|
1172
995
|
pixels[y * width + x] = temp[y * w + x] & 0xff;
|
1173
|
-
// System.out.print((image.pixels[y*64+x] > 128) ? "*" : ".");
|
996
|
+
// System.out.print((image.pixels[y*64+x] > 128) ? "*" : ".");
|
1174
997
|
}
|
1175
|
-
// System.out.println();
|
998
|
+
// System.out.println();
|
1176
999
|
}
|
1177
|
-
// System.out.println();
|
1000
|
+
// System.out.println();
|
1178
1001
|
}
|
1179
1002
|
|
1180
|
-
/**
|
1181
|
-
*
|
1182
|
-
* @param os
|
1183
|
-
* @throws IOException
|
1184
|
-
*/
|
1185
1003
|
protected void writeBitmap(DataOutputStream os) throws IOException {
|
1186
1004
|
int[] pixels = image.pixels;
|
1187
1005
|
for (int y = 0; y < height; y++) {
|
@@ -1191,10 +1009,6 @@ public class PFont implements PConstants {
|
|
1191
1009
|
}
|
1192
1010
|
}
|
1193
1011
|
|
1194
|
-
/**
|
1195
|
-
*
|
1196
|
-
* @param c
|
1197
|
-
*/
|
1198
1012
|
protected Glyph(char c) {
|
1199
1013
|
int mbox3 = size * 3;
|
1200
1014
|
lazyGraphics.setColor(Color.white);
|