propane 3.10.0-java → 3.11.0-java

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