mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
change ascent/descent for fonts back to the older model
This commit is contained in:
@@ -4083,8 +4083,8 @@ public class PApplet extends Applet
|
||||
* installed on the system, or from a .ttf or .otf that's inside
|
||||
* the data folder of this sketch.
|
||||
* <P/>
|
||||
* Only works with Java 1.3 or later. Many .otf fonts don't seem
|
||||
* to be supported by Java, perhaps because they're CFF based?
|
||||
* Many .otf fonts don't seem to be supported by Java, perhaps because
|
||||
* they're CFF based?
|
||||
* <P/>
|
||||
* Font names are inconsistent across platforms and Java versions.
|
||||
* On Mac OS X, Java 1.3 uses the font menu name of the font,
|
||||
@@ -4103,8 +4103,9 @@ public class PApplet extends Applet
|
||||
Font baseFont = null;
|
||||
|
||||
try {
|
||||
InputStream stream = null;
|
||||
if (lowerName.endsWith(".otf") || lowerName.endsWith(".ttf")) {
|
||||
InputStream stream = createInput(name);
|
||||
stream = createInput(name);
|
||||
if (stream == null) {
|
||||
System.err.println("The font \"" + name + "\" " +
|
||||
"is missing or inaccessible, make sure " +
|
||||
@@ -4115,17 +4116,15 @@ public class PApplet extends Applet
|
||||
baseFont = Font.createFont(Font.TRUETYPE_FONT, createInput(name));
|
||||
|
||||
} else {
|
||||
//baseFont = new Font(name, Font.PLAIN, 1);
|
||||
baseFont = PFont.findFont(name);
|
||||
}
|
||||
return new PFont(baseFont.deriveFont(size), smooth, charset,
|
||||
stream != null);
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Problem using createFont() with " + name);
|
||||
System.err.println("Problem createFont(" + name + ")");
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (charset == null) {
|
||||
return new PFont(baseFont.deriveFont(size), smooth);
|
||||
} else {
|
||||
return new PFont(baseFont.deriveFont(size), smooth, charset);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
/**
|
||||
@@ -115,6 +116,9 @@ public class PFont implements PConstants {
|
||||
*/
|
||||
protected Font font;
|
||||
|
||||
/** True if this font was loaded from a stream, rather than from the OS. */
|
||||
protected boolean stream;
|
||||
|
||||
/**
|
||||
* True if we've already tried to find the native AWT version of this font.
|
||||
*/
|
||||
@@ -126,6 +130,7 @@ public class PFont implements PConstants {
|
||||
* bug that they can't be bothered to fix.
|
||||
*/
|
||||
static protected Font[] fonts;
|
||||
static protected HashMap<String,Font> fontDifferent;
|
||||
|
||||
|
||||
// objects to handle creation of font characters only as they're needed
|
||||
@@ -265,7 +270,17 @@ public class PFont implements PConstants {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds an additional parameter that indicates the font came from a file,
|
||||
* not a built-in OS font.
|
||||
*/
|
||||
public PFont(Font font, boolean smooth, char charset[], boolean stream) {
|
||||
this(font, smooth, charset);
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
|
||||
public PFont(InputStream input) throws IOException {
|
||||
DataInputStream is = new DataInputStream(input);
|
||||
@@ -437,6 +452,11 @@ public class PFont implements PConstants {
|
||||
// }
|
||||
return font;
|
||||
}
|
||||
|
||||
|
||||
public boolean isStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -663,23 +683,35 @@ public class PFont implements PConstants {
|
||||
GraphicsEnvironment ge =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
fonts = ge.getAllFonts();
|
||||
if (PApplet.platform == PConstants.MACOSX) {
|
||||
fontDifferent = new HashMap();
|
||||
for (Font font : fonts) {
|
||||
// getName() returns the PostScript name on OS X 10.6 w/ Java 6.
|
||||
fontDifferent.put(font.getName(), font);
|
||||
//fontDifferent.put(font.getPSName(), font);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Starting with Java 1.5, Apple broke the ability to specify most fonts.
|
||||
* This has been filed as bug #4769141 at bugreporter.apple.com. More info at
|
||||
* This bug was filed years ago as #4769141 at bugreporter.apple.com. More:
|
||||
* <a href="http://dev.processing.org/bugs/show_bug.cgi?id=407">Bug 407</a>.
|
||||
*/
|
||||
*/
|
||||
static public Font findFont(String name) {
|
||||
loadFonts();
|
||||
if (PApplet.platform == PConstants.MACOSX) {
|
||||
for (int i = 0; i < fonts.length; i++) {
|
||||
if (name.equals(fonts[i].getName())) {
|
||||
return fonts[i];
|
||||
}
|
||||
Font maybe = fontDifferent.get(name);
|
||||
if (maybe != null) {
|
||||
return maybe;
|
||||
}
|
||||
// for (int i = 0; i < fonts.length; i++) {
|
||||
// if (name.equals(fonts[i].getName())) {
|
||||
// return fonts[i];
|
||||
// }
|
||||
// }
|
||||
}
|
||||
return new Font(name, Font.PLAIN, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user