/* * PCFFontAA.java * Parse and display a PCF font using Anti-Aliasing * * Ken Shirriff ken.shirriff@eng.sun.com * * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved. * * Some of this code is based on the X Consortium's pcfread.c. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. * * Please refer to the file "license.txt" * for further important copyright and licensing information. */ package pcffont; import java.awt.*; import java.awt.image.*; import java.io.*; /** * PCFFontAA provides antialiased use of a font in X11 .PCF format. * * For example: *
 *   g = getGraphics();
 *   InputStream is = stream to the font file
 *   PCFFont bf = new PCFFontAA(is);
 *   bf.drawString(g, "This is a test string", 10, 10);
 * 
* * @see PCFFont * @author Ken Shirriff, shirriff@eng.sun.com */ public class PCFFontAA extends PCFFont { PCFMetrics origMetrics[]; int fgFracs[]; public void setFgColor(Color c) { super.setFgColor(c); recomputeFracs(); } public void setBgColor(Color c) { super.setBgColor(c); recomputeFracs(); } void recomputeFracs() { if (fgFracs == null) { fgFracs = new int[5]; } int af = (fgColor>>>24)&0xff; int rf = (fgColor>>>16)&0xff; int gf = (fgColor>>>8)&0xff; int bf = (fgColor)&0xff; int ab = (bgColor>>>24)&0xff; int rb = (bgColor>>>16)&0xff; int gb = (bgColor>>>8)&0xff; int bb = (bgColor)&0xff; for (int i=0;i<=4;i++) { int a,r,g,b; if (ab==0) { a = (af*i+ab*(4-i))/4; r = rf; g = gf; b = bf; } else { a = (af*i+ab*(4-i))/4; r = (rf*i+rb*(4-i))/4; g = (gf*i+gb*(4-i))/4; b = (bf*i+bb*(4-i))/4; } fgFracs[i] = (a<<24)|(r<<16)|(g<<8)|(b<<0); } } /** * Creates a new PCFFontAA. * A stream to the PCF font file is passed in. * @param data A input stream supplying the font data * @exception IOException If a problem occurs. */ public PCFFontAA(InputStream data) throws IOException { this(data, null); } /** * Create a new PCFFont, reporting back as the file is loaded. * A stream to the PCF font file is passed in. * The caller is informed through the callback of progress in loading the font. * @param data A input stream supplying the font data * @param callback A callback to report of the status of the load. * @exception IOException If a problem occurs. */ public PCFFontAA(InputStream data, CompletionCallback callback) throws IOException { super(data, callback); setBgColor(Color.white); // Divide dimensions by two ascent = divide2(ascent); descent = divide2(descent); maxAscent = divide2(maxAscent); maxDescent = divide2(maxDescent); maxbounds = divide2(maxbounds); origMetrics = new PCFMetrics[nbitmaps]; for (int i=0; i>3); int w2 = divide2(width); int h2 = divide2(height); int tmpbuf[] = new int[w2*h2]; stride = (stride+glyphpad-1)&~(glyphpad-1); for (int i=0;i>3; if ((bits[offset+ ((byte_pos+i*stride)^byteflip)]& (1<0) { buf[bufoffset+i*span+j] = fgFracs[pixel]; } } } } }