001: /*
002: * Copyright 2000-2004 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.loops;
027:
028: import sun.java2d.loops.GraphicsPrimitive;
029: import sun.java2d.pipe.Region;
030: import sun.java2d.SunGraphics2D;
031: import sun.java2d.SurfaceData;
032: import sun.font.GlyphList;
033:
034: /**
035: * DrawGlyphListAA - loops for AATextRenderer pipe
036: * 1) draw anti-aliased text onto destination surface
037: * 2) must accept output area [x, y, dx, dy]
038: * from within the surface description data for clip rect
039: */
040: public class DrawGlyphListAA extends GraphicsPrimitive {
041:
042: public final static String methodSignature = "DrawGlyphListAA(...)"
043: .toString();
044:
045: public final static int primTypeID = makePrimTypeID();
046:
047: public static DrawGlyphListAA locate(SurfaceType srctype,
048: CompositeType comptype, SurfaceType dsttype) {
049: return (DrawGlyphListAA) GraphicsPrimitiveMgr.locate(
050: primTypeID, srctype, comptype, dsttype);
051: }
052:
053: protected DrawGlyphListAA(SurfaceType srctype,
054: CompositeType comptype, SurfaceType dsttype) {
055: super (methodSignature, primTypeID, srctype, comptype, dsttype);
056: }
057:
058: public DrawGlyphListAA(long pNativePrim, SurfaceType srctype,
059: CompositeType comptype, SurfaceType dsttype) {
060: super (pNativePrim, methodSignature, primTypeID, srctype,
061: comptype, dsttype);
062: }
063:
064: public native void DrawGlyphListAA(SunGraphics2D sg2d,
065: SurfaceData dest, GlyphList srcData);
066:
067: static {
068: GraphicsPrimitiveMgr.registerGeneral(new DrawGlyphListAA(null,
069: null, null));
070: }
071:
072: public GraphicsPrimitive makePrimitive(SurfaceType srctype,
073: CompositeType comptype, SurfaceType dsttype) {
074: return new General(srctype, comptype, dsttype);
075: }
076:
077: public static class General extends DrawGlyphListAA {
078: MaskFill maskop;
079:
080: public General(SurfaceType srctype, CompositeType comptype,
081: SurfaceType dsttype) {
082: super (srctype, comptype, dsttype);
083: maskop = MaskFill.locate(srctype, comptype, dsttype);
084: }
085:
086: public void DrawGlyphListAA(SunGraphics2D sg2d,
087: SurfaceData dest, GlyphList gl) {
088: gl.getBounds(); // Don't delete, bug 4895493
089: int num = gl.getNumGlyphs();
090: Region clip = sg2d.getCompClip();
091: int cx1 = clip.getLoX();
092: int cy1 = clip.getLoY();
093: int cx2 = clip.getHiX();
094: int cy2 = clip.getHiY();
095: for (int i = 0; i < num; i++) {
096: gl.setGlyphIndex(i);
097: int metrics[] = gl.getMetrics();
098: int gx1 = metrics[0];
099: int gy1 = metrics[1];
100: int w = metrics[2];
101: int gx2 = gx1 + w;
102: int gy2 = gy1 + metrics[3];
103: int off = 0;
104: if (gx1 < cx1) {
105: off = cx1 - gx1;
106: gx1 = cx1;
107: }
108: if (gy1 < cy1) {
109: off += (cy1 - gy1) * w;
110: gy1 = cy1;
111: }
112: if (gx2 > cx2)
113: gx2 = cx2;
114: if (gy2 > cy2)
115: gy2 = cy2;
116: if (gx2 > gx1 && gy2 > gy1) {
117: byte alpha[] = gl.getGrayBits();
118: maskop.MaskFill(sg2d, dest, sg2d.composite, gx1,
119: gy1, gx2 - gx1, gy2 - gy1, alpha, off, w);
120: }
121: }
122: }
123: }
124:
125: public GraphicsPrimitive traceWrap() {
126: return new TraceDrawGlyphListAA(this );
127: }
128:
129: private static class TraceDrawGlyphListAA extends DrawGlyphListAA {
130: DrawGlyphListAA target;
131:
132: public TraceDrawGlyphListAA(DrawGlyphListAA target) {
133: super (target.getSourceType(), target.getCompositeType(),
134: target.getDestType());
135: this .target = target;
136: }
137:
138: public GraphicsPrimitive traceWrap() {
139: return this ;
140: }
141:
142: public void DrawGlyphListAA(SunGraphics2D sg2d,
143: SurfaceData dest, GlyphList glyphs) {
144: tracePrimitive(target);
145: target.DrawGlyphListAA(sg2d, dest, glyphs);
146: }
147: }
148: }
|