diff --git a/core/src/processing/awt/PGraphicsJava2D.java b/core/src/processing/awt/PGraphicsJava2D.java index 6de795b0b..35f73d025 100644 --- a/core/src/processing/awt/PGraphicsJava2D.java +++ b/core/src/processing/awt/PGraphicsJava2D.java @@ -2055,8 +2055,20 @@ public class PGraphicsJava2D extends PGraphics { protected void textLineImpl(char[] buffer, int start, int stop, float x, float y) { Font font = (Font) textFont.getNative(); -// if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) { if (font != null) { + // If using the default font, warn the user when their code calls + // text() called with unavailable characters. Not done with all + // fonts because it would be too slow, but useful/acceptable for + // the default case because it will hit beginners/casual use. + if (textFont.getName().equals(defaultFontName)) { + if (font.canDisplayUpTo(buffer, start, stop) != -1) { + final String msg = + "Some characters not available in the current font, " + + "use createFont() to specify a typeface the includes them."; + showWarning(msg); + } + } + /* // save the current setting for text smoothing. note that this is // different from the smooth() function, because the font smoothing @@ -2109,7 +2121,7 @@ public class PGraphicsJava2D extends PGraphics { //g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, textAntialias); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialias); - } else { // otherwise just do the default + } else { // otherwise, just do the default super.textLineImpl(buffer, start, stop, x, y); } } diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index ae1fec148..f3117916f 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -460,6 +460,9 @@ public class PGraphics extends PImage implements PConstants { /** The current text leading (read-only) */ public float textLeading; + /** Used internally to check whether still using the default font */ + protected String defaultFontName; + static final protected String ERROR_TEXTFONT_NULL_PFONT = "A null PFont was passed to textFont()"; @@ -4243,6 +4246,7 @@ public class PGraphics extends PImage implements PConstants { InputStream input = getClass().getResourceAsStream("/font/ProcessingSansPro-Regular.ttf"); if (input != null) { baseFont = Font.createFont(Font.TRUETYPE_FONT, input); + defaultFontName = baseFont.getName(); } } catch (Exception e) { e.printStackTrace(); // dammit