2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.java2d.pipe;
|
|
27 |
|
|
28 |
import java.awt.Rectangle;
|
|
29 |
import java.awt.Shape;
|
|
30 |
import java.awt.Font;
|
|
31 |
import java.awt.font.GlyphVector;
|
|
32 |
import sun.java2d.SunGraphics2D;
|
|
33 |
import sun.java2d.loops.FontInfo;
|
|
34 |
import 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 |
*/
|
|
40 |
public 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 |
}
|