blob: b930e1e1b09c017cc18c0bf6279bb38a191bce65 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.java2d.pipe;
27
28import java.awt.Rectangle;
29import java.awt.Shape;
30import java.awt.Font;
31import java.awt.font.GlyphVector;
32import sun.java2d.SunGraphics2D;
33import sun.java2d.loops.FontInfo;
34import sun.font.GlyphList;
35
36/*
37 * This class uses the alpha graybits arrays from a GlyphList object to
38 * drive a CompositePipe in much the same way as the antialiasing renderer.
39 */
40public class TextRenderer extends GlyphListPipe {
41
42 CompositePipe outpipe;
43
44 public TextRenderer(CompositePipe pipe) {
45 outpipe = pipe;
46 }
47
48 protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {
49 int num = gl.getNumGlyphs();
50 Region clipRegion = sg2d.getCompClip();
51 int cx1 = clipRegion.getLoX();
52 int cy1 = clipRegion.getLoY();
53 int cx2 = clipRegion.getHiX();
54 int cy2 = clipRegion.getHiY();
55 Object ctx = null;
56 try {
57 int[] bounds = gl.getBounds();
58 Rectangle r = new Rectangle(bounds[0], bounds[1],
59 bounds[2] - bounds[0],
60 bounds[3] - bounds[1]);
61 Shape s = sg2d.untransformShape(r);
62 ctx = outpipe.startSequence(sg2d, s, r, bounds);
63 for (int i = 0; i < num; i++) {
64 gl.setGlyphIndex(i);
65 int metrics[] = gl.getMetrics();
66 int gx1 = metrics[0];
67 int gy1 = metrics[1];
68 int w = metrics[2];
69 int gx2 = gx1 + w;
70 int gy2 = gy1 + metrics[3];
71 int off = 0;
72 if (gx1 < cx1) {
73 off = cx1 - gx1;
74 gx1 = cx1;
75 }
76 if (gy1 < cy1) {
77 off += (cy1 - gy1) * w;
78 gy1 = cy1;
79 }
80 if (gx2 > cx2) gx2 = cx2;
81 if (gy2 > cy2) gy2 = cy2;
82 if (gx2 > gx1 && gy2 > gy1 &&
83 outpipe.needTile(ctx, gx1, gy1, gx2 - gx1, gy2 - gy1))
84 {
85 byte alpha[] = gl.getGrayBits();
86 outpipe.renderPathTile(ctx, alpha, off, w,
87 gx1, gy1, gx2 - gx1, gy2 - gy1);
88 } else {
89 outpipe.skipTile(ctx, gx1, gy1);
90 }
91 }
92 } finally {
93 if (ctx != null) {
94 outpipe.endSequence(ctx);
95 }
96 }
97 }
98}