mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
warn the user if drawing unavailable chars with default font
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user