diff --git a/android/core/.classpath b/android/core/.classpath
index 7f9716b17..829ee9b98 100644
--- a/android/core/.classpath
+++ b/android/core/.classpath
@@ -1,6 +1,6 @@
-
+
diff --git a/android/core/src/processing/core/GLFont.java b/android/core/src/processing/core/GLFont.java
index 788e8e4a1..b2d3d20e1 100644
--- a/android/core/src/processing/core/GLFont.java
+++ b/android/core/src/processing/core/GLFont.java
@@ -169,7 +169,7 @@ public class GLFont extends PFont {
*/
public GLFont(PApplet parent, Typeface font, int size, boolean smooth, char charset[]) {
// save this so that we can use the native version
- this.font = font;
+ this.typeface = font;
this.smooth = smooth;
// name = font.getName();
diff --git a/android/core/src/processing/core/PApplet.java b/android/core/src/processing/core/PApplet.java
index 3e6ba58a6..3bf5fa318 100644
--- a/android/core/src/processing/core/PApplet.java
+++ b/android/core/src/processing/core/PApplet.java
@@ -2966,12 +2966,12 @@ public class PApplet extends Activity implements PConstants, Runnable {
public PFont createFont(String name, float size) {
- return createFont(name, size, true, PFont.DEFAULT_CHARSET);
+ return createFont(name, size, true, null);
}
public PFont createFont(String name, float size, boolean smooth) {
- return createFont(name, size, smooth, PFont.DEFAULT_CHARSET);
+ return createFont(name, size, smooth, null);
}
@@ -2980,12 +2980,11 @@ public class PApplet extends Activity implements PConstants, Runnable {
* installed on the system, or from a .ttf or .otf that's inside
* the data folder of this sketch.
*
typefaceMap;
+ static String[] fontList;
+
+
/**
- * Get a list of the fonts installed on the system that can be used
- * by Java. Not all fonts can be used in Java, in fact it's mostly
- * only TrueType fonts. OpenType fonts with CFF data such as Adobe's
- * OpenType fonts seem to have trouble (even though they're sort of
- * TrueType fonts as well, or may have a .ttf extension). Regular
- * PostScript fonts seem to work OK, however.
- *
- * Not recommended for use in applets, but this is implemented
- * in PFont because the Java methods to access this information
- * have changed between 1.1 and 1.4, and the 1.4 method is
- * typical of the sort of undergraduate-level over-abstraction
- * that the seems to have made its way into the Java API after 1.1.
+ * Get a list of the built-in fonts.
*/
static public String[] list() {
- loadFonts();
- String list[] = new String[fonts.length];
- for (int i = 0; i < list.length; i++) {
- list[i] = fonts[i].getName();
- }
- return list;
+ loadTypefaces();
+ return fontList;
}
- static public void loadFonts() {
- if (fonts == null) {
- GraphicsEnvironment ge =
- GraphicsEnvironment.getLocalGraphicsEnvironment();
- fonts = ge.getAllFonts();
- }
- }
+ static public void loadTypefaces() {
+ if (typefaceMap == null) {
+ typefaceMap = new HashMap();
+
+ typefaceMap.put("Serif",
+ Typeface.create(Typeface.SERIF, Typeface.NORMAL));
+ typefaceMap.put("Serif-Bold",
+ Typeface.create(Typeface.SERIF, Typeface.BOLD));
+ typefaceMap.put("Serif-Italic",
+ Typeface.create(Typeface.SERIF, Typeface.ITALIC));
+ typefaceMap.put("Serif-BoldItalic",
+ Typeface.create(Typeface.SERIF, Typeface.BOLD_ITALIC));
+ typefaceMap.put("SansSerif",
+ Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL));
+ typefaceMap.put("SansSerif-Bold",
+ Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
+ typefaceMap.put("SansSerif-Italic",
+ Typeface.create(Typeface.SANS_SERIF, Typeface.ITALIC));
+ typefaceMap.put("SansSerif-BoldItalic",
+ Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD_ITALIC));
- /**
- * 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
- * Bug 407.
- */
- 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];
- }
- }
+ typefaceMap.put("Monospaced",
+ Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL));
+ typefaceMap.put("Monospaced-Bold",
+ Typeface.create(Typeface.MONOSPACE, Typeface.BOLD));
+ typefaceMap.put("Monospaced-Italic",
+ Typeface.create(Typeface.MONOSPACE, Typeface.ITALIC));
+ typefaceMap.put("Monospaced-BoldItalic",
+ Typeface.create(Typeface.MONOSPACE, Typeface.BOLD_ITALIC));
+
+ fontList = new String[typefaceMap.size()];
+ typefaceMap.keySet().toArray(fontList);
}
- return new Font(name, Font.PLAIN, 1);
}
@@ -754,13 +724,17 @@ public class PFont implements PConstants {
protected Glyph(char c) {
int mbox3 = size * 3;
- lazyGraphics.setColor(Color.white);
- lazyGraphics.fillRect(0, 0, mbox3, mbox3);
- lazyGraphics.setColor(Color.black);
- lazyGraphics.drawString(String.valueOf(c), size, size * 2);
-
- WritableRaster raster = lazyImage.getRaster();
- raster.getDataElements(0, 0, mbox3, mbox3, lazySamples);
+// lazyGraphics.setColor(Color.white);
+// lazyGraphics.fillRect(0, 0, mbox3, mbox3);
+ lazyCanvas.drawColor(Color.WHITE); // fill canvas with white
+// lazyGraphics.setColor(Color.black);
+ lazyPaint.setColor(Color.BLACK);
+// lazyGraphics.drawString(String.valueOf(c), size, size * 2);
+ lazyCanvas.drawText(String.valueOf(c), size, size * 2, lazyPaint);
+
+// WritableRaster raster = lazyImage.getRaster();
+// raster.getDataElements(0, 0, mbox3, mbox3, lazySamples);
+ lazyBitmap.getPixels(lazySamples, 0, mbox3, 0, 0, mbox3, mbox3);
int minX = 1000, maxX = 0;
int minY = 1000, maxY = 0;
@@ -789,7 +763,8 @@ public class PFont implements PConstants {
value = c;
height = (maxY - minY) + 1;
width = (maxX - minX) + 1;
- setWidth = lazyMetrics.charWidth(c);
+// setWidth = lazyMetrics.charWidth(c);
+ setWidth = (int) lazyPaint.measureText(String.valueOf(c));
// offset from vertical location of baseline
// of where the char was drawn (size*2)
diff --git a/android/core/src/processing/core/PGraphics.java b/android/core/src/processing/core/PGraphics.java
index 146483dd3..c442fa724 100644
--- a/android/core/src/processing/core/PGraphics.java
+++ b/android/core/src/processing/core/PGraphics.java
@@ -2420,11 +2420,9 @@ public class PGraphics extends PImage implements PConstants {
public void textFont(PFont which) {
if (which != null) {
textFont = which;
- if (hints[ENABLE_NATIVE_FONTS]) {
- //if (which.font == null) {
- which.findFont();
- //}
- }
+// if (hints[ENABLE_NATIVE_FONTS]) {
+// which.findTypeface(name);
+// }
/*
textFontNative = which.font;
@@ -3039,36 +3037,33 @@ public class PGraphics extends PImage implements PConstants {
}
- protected void textCharImpl(char ch, float x, float y) { //, float z) {
- int index = textFont.index(ch);
- if (index == -1) return;
+ protected void textCharImpl(char ch, float x, float y) {
+ PFont.Glyph glyph = textFont.getGlyph(ch);
+ if (glyph != null) {
+ if (textMode == MODEL) {
+ float high = glyph.height / (float) textFont.size;
+ float bwidth = glyph.width / (float) textFont.size;
+ float lextent = glyph.leftExtent / (float) textFont.size;
+ float textent = glyph.topExtent / (float) textFont.size;
- PImage glyph = textFont.images[index];
+ float x1 = x + lextent * textSize;
+ float y1 = y - textent * textSize;
+ float x2 = x1 + bwidth * textSize;
+ float y2 = y1 + high * textSize;
- if (textMode == MODEL) {
- float high = (float) textFont.height[index] / textFont.fheight;
- float bwidth = (float) textFont.width[index] / textFont.fwidth;
- float lextent = (float) textFont.leftExtent[index] / textFont.fwidth;
- float textent = (float) textFont.topExtent[index] / textFont.fheight;
+ textCharModelImpl(glyph.image,
+ x1, y1, x2, y2,
+ glyph.width, glyph.height);
- float x1 = x + lextent * textSize;
- float y1 = y - textent * textSize;
- float x2 = x1 + bwidth * textSize;
- float y2 = y1 + high * textSize;
+ } else if (textMode == SCREEN) {
+ int xx = (int) x + glyph.leftExtent;
+ int yy = (int) y - glyph.topExtent;
- textCharModelImpl(glyph,
- x1, y1, x2, y2,
- //x1, y1, z, x2, y2, z,
- textFont.width[index], textFont.height[index]);
+ int w0 = glyph.width;
+ int h0 = glyph.height;
- } else if (textMode == SCREEN) {
- int xx = (int) x + textFont.leftExtent[index];;
- int yy = (int) y - textFont.topExtent[index];
-
- int w0 = textFont.width[index];
- int h0 = textFont.height[index];
-
- textCharScreenImpl(glyph, xx, yy, w0, h0);
+ textCharScreenImpl(glyph.image, xx, yy, w0, h0);
+ }
}
}
@@ -3141,7 +3136,7 @@ public class PGraphics extends PImage implements PConstants {
// TODO this can be optimized a bit
for (int row = y0; row < y0 + h0; row++) {
for (int col = x0; col < x0 + w0; col++) {
- int a1 = (fa * pixels1[row * textFont.twidth + col]) >> 8;
+ int a1 = (fa * pixels1[row * glyph.width + col]) >> 8;
int a2 = a1 ^ 0xff;
//int p1 = pixels1[row * glyph.width + col];
int p2 = pixels[(yy + row-y0)*width + (xx+col-x0)];
diff --git a/android/core/src/processing/core/PGraphicsAndroid2D.java b/android/core/src/processing/core/PGraphicsAndroid2D.java
index 1acc0bb14..9372d0911 100644
--- a/android/core/src/processing/core/PGraphicsAndroid2D.java
+++ b/android/core/src/processing/core/PGraphicsAndroid2D.java
@@ -1061,7 +1061,7 @@ public class PGraphicsAndroid2D extends PGraphics {
public float textAscent() {
// Font font = textFont.getFont();
- Typeface font = textFont.getFont();
+ Typeface font = textFont.getTypeface();
if (font == null) {
return super.textAscent();
}
@@ -1073,7 +1073,7 @@ public class PGraphicsAndroid2D extends PGraphics {
public float textDescent() {
// Font font = textFont.getFont();
- Typeface font = textFont.getFont();
+ Typeface font = textFont.getTypeface();
if (font == null) {
return super.textDescent();
}
@@ -1085,7 +1085,7 @@ public class PGraphicsAndroid2D extends PGraphics {
public void textFont(PFont which) {
super.textFont(which);
- fillPaint.setTypeface(which.getFont());
+ fillPaint.setTypeface(which.getTypeface());
}
@@ -1111,7 +1111,7 @@ public class PGraphicsAndroid2D extends PGraphics {
*/
public void textSize(float size) {
// Font font = textFont.getFont();
- Typeface font = textFont.getFont();
+ Typeface font = textFont.getTypeface();
if (font != null) {
// Font dfont = font.deriveFont(size);
// canvas.setFont(dfont);
@@ -1134,7 +1134,7 @@ public class PGraphicsAndroid2D extends PGraphics {
protected float textWidthImpl(char buffer[], int start, int stop) {
// Font font = textFont.getFont();
- Typeface font = textFont.getFont();
+ Typeface font = textFont.getTypeface();
if (font == null) {
return super.textWidthImpl(buffer, start, stop);
}
@@ -1166,7 +1166,7 @@ public class PGraphicsAndroid2D extends PGraphics {
protected void textLineImpl(char buffer[], int start, int stop,
float x, float y) {
- Typeface font = textFont.getFont();
+ Typeface font = textFont.getTypeface();
if (font == null) {
super.textLineImpl(buffer, start, stop, x, y);
return;