Skip to content

Commit 186b358

Browse files
committed
fix for createFont bug #197, now createFont does not sort the original charset array
1 parent cbdf55c commit 186b358

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

core/src/processing/core/PFont.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,17 @@ public PFont(Font font, boolean smooth, char[] charset) {
272272
} else {
273273
// charset needs to be sorted to make index lookup run more quickly
274274
// http://dev.processing.org/bugs/show_bug.cgi?id=494
275-
Arrays.sort(charset);
276275

277-
glyphs = new Glyph[charset.length];
276+
// make copy of charset for sorting to not effect original array
277+
// fix for bug: https://github.com/processing/processing4/issues/197
278+
char[] sortedCharset = Arrays.copyOf(charset, charset.length );
279+
280+
Arrays.sort(sortedCharset);
281+
282+
glyphs = new Glyph[sortedCharset.length];
278283

279284
glyphCount = 0;
280-
for (char c : charset) {
285+
for (char c : sortedCharset) {
281286
if (font.canDisplay(c)) {
282287
Glyph glyf = new Glyph(c);
283288
if (glyf.value < 128) {
@@ -289,7 +294,7 @@ public PFont(Font font, boolean smooth, char[] charset) {
289294
}
290295

291296
// shorten the array if necessary
292-
if (glyphCount != charset.length) {
297+
if (glyphCount != sortedCharset.length) {
293298
glyphs = (Glyph[]) PApplet.subset(glyphs, 0, glyphCount);
294299
}
295300

0 commit comments

Comments
 (0)