mirror of
https://github.com/processing/processing4.git
synced 2026-02-11 01:29:17 +01:00
cleaning up new versions, things now compiling
This commit is contained in:
@@ -23,21 +23,17 @@
|
||||
Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.core;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
#ifdef JDK13
|
||||
// for font builder.. but prolly no need to ifdef
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
#endif
|
||||
|
||||
|
||||
// value[] could be used to build a char to byte mapping table
|
||||
// as the font is loaded..
|
||||
// when generating, use the native char mapping.
|
||||
|
||||
public class BFont implements BConstants {
|
||||
public class PFont implements PConstants {
|
||||
|
||||
/**
|
||||
* This is the union of the Mac Roman and Windows ANSI
|
||||
@@ -98,7 +94,7 @@ public class BFont implements BConstants {
|
||||
|
||||
//int firstChar = 33; // always
|
||||
int charCount;
|
||||
BImage images[];
|
||||
PImage images[];
|
||||
|
||||
// image width, a power of 2
|
||||
// note! these will always be the same
|
||||
@@ -123,11 +119,11 @@ public class BFont implements BConstants {
|
||||
boolean cached;
|
||||
|
||||
|
||||
public BFont() { } // for BFontAI subclass and font builder
|
||||
public PFont() { } // for PFontAI subclass and font builder
|
||||
|
||||
|
||||
// can this throw an exception instead?
|
||||
public BFont(String filename, BGraphics parent) throws IOException {
|
||||
public PFont(String filename, PGraphics parent) throws IOException {
|
||||
//this.parent = parent;
|
||||
//this.valid = false;
|
||||
|
||||
@@ -145,158 +141,9 @@ public class BFont implements BConstants {
|
||||
}
|
||||
cached = false;
|
||||
size();
|
||||
//valid = true;
|
||||
|
||||
//} catch (IOException e) {
|
||||
//parent.message(COMPLAINT, "could not load font " + filename, e);
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
#ifdef JDK13
|
||||
|
||||
public BFont(String name, int size) throws IOException {
|
||||
this(new Font(name, Font.PLAIN, size), true);
|
||||
}
|
||||
|
||||
public BFont(String name, int size, boolean smooth) throws IOException {
|
||||
this(new Font(name, Font.PLAIN, size), smooth);
|
||||
}
|
||||
|
||||
public BFont(Font font, boolean smooth) throws IOException {
|
||||
//int firstChar = 33;
|
||||
//int lastChar = 126;
|
||||
|
||||
//this.charCount = lastChar - firstChar + 1;
|
||||
this.charCount = charset.length;
|
||||
this.mbox = font.getSize();
|
||||
|
||||
// size for image/texture is next power of 2 over font size
|
||||
iwidth = iheight = (int)
|
||||
Math.pow(2, Math.ceil(Math.log(mbox) / Math.log(2)));
|
||||
|
||||
iwidthf = iheightf = (float) iwidth;
|
||||
|
||||
/*
|
||||
iwidth = (int)
|
||||
Math.pow(2, Math.ceil(Math.log(mbox) / Math.log(2)));
|
||||
iheight = (int)
|
||||
Math.pow(2, Math.ceil(Math.log(mbox) / Math.log(2)));
|
||||
|
||||
iwidthf = (float) iwidth;
|
||||
iheightf = (float) iheight;
|
||||
*/
|
||||
|
||||
images = new BImage[charCount];
|
||||
|
||||
// allocate enough space for the character info
|
||||
value = new int[charCount];
|
||||
height = new int[charCount];
|
||||
width = new int[charCount];
|
||||
setWidth = new int[charCount];
|
||||
topExtent = new int[charCount];
|
||||
leftExtent = new int[charCount];
|
||||
|
||||
int mbox3 = mbox * 3;
|
||||
|
||||
BufferedImage playground =
|
||||
new BufferedImage(mbox3, mbox3, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
Graphics2D g = (Graphics2D) playground.getGraphics();
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
smooth ?
|
||||
RenderingHints.VALUE_ANTIALIAS_ON :
|
||||
RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
|
||||
g.setFont(font);
|
||||
FontMetrics metrics = g.getFontMetrics();
|
||||
|
||||
int index = 0;
|
||||
for (int i = 0; i < charCount; i++) {
|
||||
char c = charset[i];
|
||||
if (!font.canDisplay(c)) { // skip chars not in the font
|
||||
continue;
|
||||
}
|
||||
|
||||
g.setColor(Color.white);
|
||||
g.fillRect(0, 0, mbox3, mbox3);
|
||||
g.setColor(Color.black);
|
||||
g.drawString(String.valueOf(c), mbox, mbox * 2);
|
||||
|
||||
// grabs copy of the current data.. so no updates (do each time)
|
||||
Raster raster = playground.getData();
|
||||
|
||||
//int w = metrics.charWidth(c);
|
||||
int minX = 1000, maxX = 0;
|
||||
int minY = 1000, maxY = 0;
|
||||
boolean pixelFound = false;
|
||||
|
||||
for (int y = 0; y < mbox3; y++) {
|
||||
for (int x = 0; x < mbox3; x++) {
|
||||
int sample = raster.getSample(x, y, 0); // maybe?
|
||||
// or int samples[] = raster.getPixel(x, y, null);
|
||||
|
||||
//if (sample == 0) { // or just not white? hmm
|
||||
if (sample != 255) {
|
||||
if (x < minX) minX = x;
|
||||
if (y < minY) minY = y;
|
||||
if (x > maxX) maxX = x;
|
||||
if (y > maxY) maxY = y;
|
||||
pixelFound = true;
|
||||
//System.out.println(x + " " + y + " = " + sample);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!pixelFound) {
|
||||
//System.out.println("no pixels found in char " + ((char)i));
|
||||
// this was dumb that it was set to 20 & 30, because for small
|
||||
// fonts, those guys don't exist
|
||||
minX = minY = 0; //20;
|
||||
maxX = maxY = 0; //30;
|
||||
|
||||
// this will create a 1 pixel white (clear) character..
|
||||
// maybe better to set one to -1 so nothing is added?
|
||||
}
|
||||
|
||||
value[index] = c;
|
||||
height[index] = (maxY - minY) + 1;
|
||||
width[index] = (maxX - minX) + 1;
|
||||
setWidth[index] = metrics.charWidth(c);
|
||||
|
||||
// offset from vertical location of baseline
|
||||
// of where the char was drawn (mbox*2)
|
||||
topExtent[index] = mbox*2 - minY;
|
||||
|
||||
// offset from left of where coord was drawn
|
||||
leftExtent[index] = minX - mbox;
|
||||
|
||||
//System.out.println(height[index] + " " + width[index] + " " +
|
||||
// setWidth[index] + " " +
|
||||
// topExtent[index] + " " + leftExtent[index]);
|
||||
|
||||
images[index] = new BImage(new int[width[index] * height[index]],
|
||||
width[index], height[index], ALPHA);
|
||||
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
//System.out.println("getting pixel " + x + " " + y);
|
||||
int value = 255 - raster.getSample(x, y, 0);
|
||||
int pindex = (y - minY) * width[index] + (x - minX);
|
||||
images[index].pixels[pindex] = value;
|
||||
//System.out.print(BApplet.nf(value, 3) + " ");
|
||||
}
|
||||
//System.out.println();
|
||||
}
|
||||
//System.out.println();
|
||||
index++;
|
||||
}
|
||||
charCount = index;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
public void write(OutputStream output) throws IOException {
|
||||
DataOutputStream os = new DataOutputStream(output);
|
||||
|
||||
@@ -383,12 +230,12 @@ public class BFont implements BConstants {
|
||||
is.readInt();
|
||||
}
|
||||
|
||||
images = new BImage[charCount];
|
||||
images = new PImage[charCount];
|
||||
for (int i = 0; i < charCount; i++) {
|
||||
//int pixels[] = new int[64 * 64];
|
||||
int pixels[] = new int[iwidth * iheight];
|
||||
//images[i] = new BImage(pixels, 64, 64, ALPHA);
|
||||
images[i] = new BImage(pixels, iwidth, iheight, ALPHA);
|
||||
//images[i] = new PImage(pixels, 64, 64, ALPHA);
|
||||
images[i] = new PImage(pixels, iwidth, iheight, ALPHA);
|
||||
int bitmapSize = height[i] * width[i];
|
||||
|
||||
byte temp[] = new byte[bitmapSize];
|
||||
@@ -411,21 +258,13 @@ public class BFont implements BConstants {
|
||||
}
|
||||
//System.out.println();
|
||||
}
|
||||
//kind = VLW;
|
||||
}
|
||||
|
||||
|
||||
//boolean exists(char c) {
|
||||
//return ((c >= firstChar) && (c - firstChar < charCount));
|
||||
//}
|
||||
|
||||
|
||||
/**
|
||||
* Get index for the char (convert from unicode to bagel charset).
|
||||
* @return index into arrays or -1 if not found
|
||||
*/
|
||||
//static private int index(char c) {
|
||||
//static public int index(char c) {
|
||||
public int index(char c) {
|
||||
// these chars required in all fonts
|
||||
if ((c >= 33) && (c <= 126)) {
|
||||
@@ -440,7 +279,6 @@ public class BFont implements BConstants {
|
||||
// whups, this used the p5 charset rather than what was inside the font
|
||||
// meaning that old fonts would crash.. fixed for 0069
|
||||
|
||||
//static private int index_hunt(int c, int start, int stop) {
|
||||
private int index_hunt(int c, int start, int stop) {
|
||||
//System.out.println("checking between " + start + " and " + stop);
|
||||
int pivot = (start + stop) / 2;
|
||||
@@ -526,12 +364,12 @@ public class BFont implements BConstants {
|
||||
}
|
||||
|
||||
|
||||
public void text(char c, float x, float y, BGraphics parent) {
|
||||
public void text(char c, float x, float y, PGraphics parent) {
|
||||
text(c, x, y, 0, parent);
|
||||
}
|
||||
|
||||
|
||||
public void text(char c, float x, float y, float z, BGraphics parent) {
|
||||
public void text(char c, float x, float y, float z, PGraphics parent) {
|
||||
//if (!valid) return;
|
||||
//if (!exists(c)) return;
|
||||
|
||||
@@ -676,11 +514,11 @@ public class BFont implements BConstants {
|
||||
|
||||
private char c[] = new char[8192];
|
||||
|
||||
public void text(String str, float x, float y, BGraphics parent) {
|
||||
public void text(String str, float x, float y, PGraphics parent) {
|
||||
text(str, x, y, 0, parent);
|
||||
}
|
||||
|
||||
public void text(String str, float x, float y, float z, BGraphics parent) {
|
||||
public void text(String str, float x, float y, float z, PGraphics parent) {
|
||||
float startX = x;
|
||||
int index = 0;
|
||||
char previous = 0;
|
||||
|
||||
Reference in New Issue
Block a user