processing.core
Class PFont

java.lang.Object
  extended by processing.core.PFont
All Implemented Interfaces:
PConstants

public class PFont
extends java.lang.Object
implements PConstants

Grayscale bitmap font class used by Processing.

Awful (and by that, I mean awesome) ascii (non)art for how this works:

   |
   |                   height is the full used height of the image
   |
   |   ..XX..       }
   |   ..XX..       }
   |   ......       }
   |   XXXX..       }  topExtent (top y is baseline - topExtent)
   |   ..XX..       }
   |   ..XX..       }  dotted areas are where the image data
   |   ..XX..       }  is actually located for the character
   +---XXXXXX----   }  (it extends to the right and down
   |                   for power of two texture sizes)
   ^^^^ leftExtent (amount to move over before drawing the image

   ^^^^^^^^^^^^^^ setWidth (width displaced by char)
 


Field Summary
 int ascent
           
 int charCount
           
static char[] DEFAULT_CHARSET
          The default Processing character set.
 int descent
           
 int[] height
           
 PImage[] images
           
 int[] leftExtent
           
 int mbox2
          next power of 2 over the max image size (usually 64)
 java.lang.String name
          Name of the font as seen by Java when it was created.
 java.lang.String psname
          Postscript name of the font that this bitmap was created from.
 int[] setWidth
           
 int size
          "natural" size of the font (most often 48)
 boolean smooth
          true if smoothing was enabled for this font, used for native impl
 int theight
          texture height, same as mbox2, but reserved for future use
 int[] topExtent
           
 int twidth
          texture width, same as mbox2, but reserved for future use
 int[] value
           
 int[] width
           
 
Fields inherited from interface processing.core.PConstants
A, AB, ADD, AG, ALPHA, ALPHA_MASK, ALT, AMBIENT, AR, ARC, ARGB, ARROW, B, BACKSPACE, BASELINE, BEEN_LIT, BEVEL, BLEND, BLUE_MASK, BLUR, BOTTOM, BOX, BURN, CENTER, CENTER_DIAMETER, CENTER_RADIUS, CHATTER, CLOSE, CMYK, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CUSTOM, DA, DARKEST, DB, DEG_TO_RAD, DELETE, DG, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ACCURATE_TEXTURES, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_OPENGL_2X_SMOOTH, DISABLE_OPENGL_ERROR_REPORT, DODGE, DOWN, DR, DXF, EB, EDGE, EG, ELLIPSE, ENABLE_ACCURATE_TEXTURES, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_2X_SMOOTH, ENABLE_OPENGL_4X_SMOOTH, ENABLE_OPENGL_ERROR_REPORT, ENTER, EPSILON, ER, ERODE, ERROR_BACKGROUND_IMAGE_FORMAT, ERROR_BACKGROUND_IMAGE_SIZE, ERROR_PUSHMATRIX_OVERFLOW, ERROR_PUSHMATRIX_UNDERFLOW, ERROR_TEXTFONT_NULL_PFONT, ESC, EXCLUSION, G, GIF, GRAY, GREEN_MASK, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LEFT, LIGHTEST, LINE, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MOVE, MULTIPLY, NORMAL, NORMALIZED, NX, NY, NZ, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, platformNames, POINT, POINTS, POLYGON, POSTERIZE, PROBLEM, PROJECT, QUAD, QUAD_STRIP, QUADS, QUARTER_PI, R, RAD_TO_DEG, RADIUS, RECT, RED_MASK, REPLACE, RETURN, RGB, RIGHT, ROUND, SA, SB, SCREEN, SG, SHAPE, SHIFT, SHINE, SOFT_LIGHT, SPB, SPG, SPHERE, SPOT, SPR, SQUARE, SR, SUBTRACT, SW, TAB, TARGA, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, TX, TY, TZ, U, UP, V, VERTEX_FIELD_COUNT, VW, VX, VY, VZ, WAIT, WHITESPACE, WINDOWS, X, Y, Z
 
Constructor Summary
PFont()
           
PFont(java.awt.Font font, boolean smooth, char[] charset)
          Create a new image-based font on the fly.
PFont(java.io.InputStream input)
           
 
Method Summary
 float ascent()
          Returns the ascent of this font from the baseline.
 float descent()
          Returns how far this font descends from the baseline.
 java.awt.Font findFont()
          Attempt to find the native version of this font.
static java.awt.Font findFont(java.lang.String name)
          Starting with Java 1.5, Apple broke the ability to specify most fonts.
 java.awt.Font getFont()
          Return the native java.awt.Font associated with this PFont (if any).
 int index(char c)
          Get index for the char (convert from unicode to bagel charset).
 float kern(char a, char b)
          Currently un-implemented for .vlw fonts, but honored for layout in case subclasses use it.
static java.lang.String[] list()
          Get a list of the fonts installed on the system that can be used by Java.
static void loadFonts()
           
 void save(java.io.OutputStream output)
          Write this PFont to an OutputStream.
 void setFont(java.awt.Font font)
          Set the native complement of this font.
 float width(char c)
          Width of this character for a font of size 1.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

charCount

public int charCount

images

public PImage[] images

name

public java.lang.String name
Name of the font as seen by Java when it was created. If the font is available, the native version will be used.


psname

public java.lang.String psname
Postscript name of the font that this bitmap was created from.


size

public int size
"natural" size of the font (most often 48)


smooth

public boolean smooth
true if smoothing was enabled for this font, used for native impl


mbox2

public int mbox2
next power of 2 over the max image size (usually 64)


twidth

public int twidth
texture width, same as mbox2, but reserved for future use


theight

public int theight
texture height, same as mbox2, but reserved for future use


value

public int[] value

height

public int[] height

width

public int[] width

setWidth

public int[] setWidth

topExtent

public int[] topExtent

leftExtent

public int[] leftExtent

ascent

public int ascent

descent

public int descent

DEFAULT_CHARSET

public static char[] DEFAULT_CHARSET
The default Processing character set.

This is the union of the Mac Roman and Windows ANSI (CP1250) character sets. ISO 8859-1 Latin 1 is Unicode characters 0x80 -> 0xFF, and would seem a good standard, but in practice, most P5 users would rather have characters that they expect from their platform's fonts.

This is more of an interim solution until a much better font solution can be determined. (i.e. create fonts on the fly from some sort of vector format).

Not that I expect that to happen.

Constructor Detail

PFont

public PFont()

PFont

public PFont(java.io.InputStream input)
      throws java.io.IOException
Throws:
java.io.IOException

PFont

public PFont(java.awt.Font font,
             boolean smooth,
             char[] charset)
Create a new image-based font on the fly.

Parameters:
font - the font object to create from
charset - array of all unicode chars that should be included
smooth - true to enable smoothing/anti-aliasing
Method Detail

setFont

public void setFont(java.awt.Font font)
Set the native complement of this font.


getFont

public java.awt.Font getFont()
Return the native java.awt.Font associated with this PFont (if any).


findFont

public java.awt.Font findFont()
Attempt to find the native version of this font. (Public so that it can be used by OpenGL or other renderers.)


save

public void save(java.io.OutputStream output)
          throws java.io.IOException
Write this PFont to an OutputStream.

This is used by the Create Font tool, or whatever anyone else dreams up for messing with fonts themselves.

It is assumed that the calling class will handle closing the stream when finished.

Throws:
java.io.IOException

index

public int index(char c)
Get index for the char (convert from unicode to bagel charset).

Returns:
index into arrays or -1 if not found

kern

public float kern(char a,
                  char b)
Currently un-implemented for .vlw fonts, but honored for layout in case subclasses use it.


ascent

public float ascent()
Returns the ascent of this font from the baseline. The value is based on a font of size 1.


descent

public float descent()
Returns how far this font descends from the baseline. The value is based on a font size of 1.


width

public float width(char c)
Width of this character for a font of size 1.


list

public static java.lang.String[] list()
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.


loadFonts

public static void loadFonts()

findFont

public static java.awt.Font findFont(java.lang.String name)
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.