001: /*
002: * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.java2d.pipe;
027:
028: import java.awt.Rectangle;
029: import java.awt.Shape;
030: import java.awt.Font;
031: import java.awt.font.GlyphVector;
032: import sun.java2d.SunGraphics2D;
033: import sun.java2d.loops.FontInfo;
034: import sun.font.GlyphList;
035:
036: /*
037: * This class uses the alpha graybits arrays from a GlyphList object to
038: * drive a CompositePipe in much the same way as the antialiasing renderer.
039: */
040: public class TextRenderer extends GlyphListPipe {
041:
042: CompositePipe outpipe;
043:
044: public TextRenderer(CompositePipe pipe) {
045: outpipe = pipe;
046: }
047:
048: protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {
049: int num = gl.getNumGlyphs();
050: Region clipRegion = sg2d.getCompClip();
051: int cx1 = clipRegion.getLoX();
052: int cy1 = clipRegion.getLoY();
053: int cx2 = clipRegion.getHiX();
054: int cy2 = clipRegion.getHiY();
055: Object ctx = null;
056: try {
057: int[] bounds = gl.getBounds();
058: Rectangle r = new Rectangle(bounds[0], bounds[1], bounds[2]
059: - bounds[0], bounds[3] - bounds[1]);
060: Shape s = sg2d.untransformShape(r);
061: ctx = outpipe.startSequence(sg2d, s, r, bounds);
062: for (int i = 0; i < num; i++) {
063: gl.setGlyphIndex(i);
064: int metrics[] = gl.getMetrics();
065: int gx1 = metrics[0];
066: int gy1 = metrics[1];
067: int w = metrics[2];
068: int gx2 = gx1 + w;
069: int gy2 = gy1 + metrics[3];
070: int off = 0;
071: if (gx1 < cx1) {
072: off = cx1 - gx1;
073: gx1 = cx1;
074: }
075: if (gy1 < cy1) {
076: off += (cy1 - gy1) * w;
077: gy1 = cy1;
078: }
079: if (gx2 > cx2)
080: gx2 = cx2;
081: if (gy2 > cy2)
082: gy2 = cy2;
083: if (gx2 > gx1
084: && gy2 > gy1
085: && outpipe.needTile(ctx, gx1, gy1, gx2 - gx1,
086: gy2 - gy1)) {
087: byte alpha[] = gl.getGrayBits();
088: outpipe.renderPathTile(ctx, alpha, off, w, gx1,
089: gy1, gx2 - gx1, gy2 - gy1);
090: } else {
091: outpipe.skipTile(ctx, gx1, gy1);
092: }
093: }
094: } finally {
095: if (ctx != null) {
096: outpipe.endSequence(ctx);
097: }
098: }
099: }
100: }
|