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.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: * DrawGlyphList - loops for SolidTextRenderer pipe.
036: * 1) draw solid color 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 DrawGlyphList extends GraphicsPrimitive {
041:
042: public final static String methodSignature = "DrawGlyphList(...)"
043: .toString();
044:
045: public final static int primTypeID = makePrimTypeID();
046:
047: public static DrawGlyphList locate(SurfaceType srctype,
048: CompositeType comptype, SurfaceType dsttype) {
049: return (DrawGlyphList) GraphicsPrimitiveMgr.locate(primTypeID,
050: srctype, comptype, dsttype);
051: }
052:
053: protected DrawGlyphList(SurfaceType srctype,
054: CompositeType comptype, SurfaceType dsttype) {
055: super (methodSignature, primTypeID, srctype, comptype, dsttype);
056: }
057:
058: public DrawGlyphList(long pNativePrim, SurfaceType srctype,
059: CompositeType comptype, SurfaceType dsttype) {
060: super (pNativePrim, methodSignature, primTypeID, srctype,
061: comptype, dsttype);
062: }
063:
064: public native void DrawGlyphList(SunGraphics2D sg2d,
065: SurfaceData dest, GlyphList srcData);
066:
067: // This instance is used only for lookup.
068: static {
069: GraphicsPrimitiveMgr.registerGeneral(new DrawGlyphList(null,
070: null, null));
071: }
072:
073: public GraphicsPrimitive makePrimitive(SurfaceType srctype,
074: CompositeType comptype, SurfaceType dsttype) {
075: return new General(srctype, comptype, dsttype);
076: }
077:
078: private static class General extends DrawGlyphList {
079: MaskFill maskop;
080:
081: public General(SurfaceType srctype, CompositeType comptype,
082: SurfaceType dsttype) {
083: super (srctype, comptype, dsttype);
084: maskop = MaskFill.locate(srctype, comptype, dsttype);
085: }
086:
087: public void DrawGlyphList(SunGraphics2D sg2d, SurfaceData dest,
088: GlyphList gl) {
089:
090: int strbounds[] = gl.getBounds(); // Don't delete, bug 4895493
091: int num = gl.getNumGlyphs();
092: Region clip = sg2d.getCompClip();
093: int cx1 = clip.getLoX();
094: int cy1 = clip.getLoY();
095: int cx2 = clip.getHiX();
096: int cy2 = clip.getHiY();
097: for (int i = 0; i < num; i++) {
098: gl.setGlyphIndex(i);
099: int metrics[] = gl.getMetrics();
100: int gx1 = metrics[0];
101: int gy1 = metrics[1];
102: int w = metrics[2];
103: int gx2 = gx1 + w;
104: int gy2 = gy1 + metrics[3];
105: int off = 0;
106: if (gx1 < cx1) {
107: off = cx1 - gx1;
108: gx1 = cx1;
109: }
110: if (gy1 < cy1) {
111: off += (cy1 - gy1) * w;
112: gy1 = cy1;
113: }
114: if (gx2 > cx2)
115: gx2 = cx2;
116: if (gy2 > cy2)
117: gy2 = cy2;
118: if (gx2 > gx1 && gy2 > gy1) {
119: byte alpha[] = gl.getGrayBits();
120: maskop.MaskFill(sg2d, dest, sg2d.composite, gx1,
121: gy1, gx2 - gx1, gy2 - gy1, alpha, off, w);
122: }
123: }
124: }
125: }
126:
127: public GraphicsPrimitive traceWrap() {
128: return new TraceDrawGlyphList(this );
129: }
130:
131: private static class TraceDrawGlyphList extends DrawGlyphList {
132: DrawGlyphList target;
133:
134: public TraceDrawGlyphList(DrawGlyphList target) {
135: super (target.getSourceType(), target.getCompositeType(),
136: target.getDestType());
137: this .target = target;
138: }
139:
140: public GraphicsPrimitive traceWrap() {
141: return this ;
142: }
143:
144: public void DrawGlyphList(SunGraphics2D sg2d, SurfaceData dest,
145: GlyphList glyphs) {
146: tracePrimitive(target);
147: target.DrawGlyphList(sg2d, dest, glyphs);
148: }
149: }
150: }
|