0N/A/*
2362N/A * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d.pipe;
0N/A
0N/Aimport java.awt.Rectangle;
0N/Aimport java.awt.Shape;
0N/Aimport java.awt.Font;
0N/Aimport java.awt.font.GlyphVector;
0N/Aimport sun.java2d.SunGraphics2D;
0N/Aimport sun.java2d.loops.FontInfo;
0N/Aimport sun.font.GlyphList;
0N/A
0N/A/*
0N/A * This class uses the alpha graybits arrays from a GlyphList object to
0N/A * drive a CompositePipe in much the same way as the antialiasing renderer.
0N/A */
0N/Apublic class TextRenderer extends GlyphListPipe {
0N/A
0N/A CompositePipe outpipe;
0N/A
0N/A public TextRenderer(CompositePipe pipe) {
0N/A outpipe = pipe;
0N/A }
0N/A
0N/A protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {
0N/A int num = gl.getNumGlyphs();
0N/A Region clipRegion = sg2d.getCompClip();
0N/A int cx1 = clipRegion.getLoX();
0N/A int cy1 = clipRegion.getLoY();
0N/A int cx2 = clipRegion.getHiX();
0N/A int cy2 = clipRegion.getHiY();
0N/A Object ctx = null;
0N/A try {
0N/A int[] bounds = gl.getBounds();
0N/A Rectangle r = new Rectangle(bounds[0], bounds[1],
0N/A bounds[2] - bounds[0],
0N/A bounds[3] - bounds[1]);
0N/A Shape s = sg2d.untransformShape(r);
0N/A ctx = outpipe.startSequence(sg2d, s, r, bounds);
0N/A for (int i = 0; i < num; i++) {
0N/A gl.setGlyphIndex(i);
0N/A int metrics[] = gl.getMetrics();
0N/A int gx1 = metrics[0];
0N/A int gy1 = metrics[1];
0N/A int w = metrics[2];
0N/A int gx2 = gx1 + w;
0N/A int gy2 = gy1 + metrics[3];
0N/A int off = 0;
0N/A if (gx1 < cx1) {
0N/A off = cx1 - gx1;
0N/A gx1 = cx1;
0N/A }
0N/A if (gy1 < cy1) {
0N/A off += (cy1 - gy1) * w;
0N/A gy1 = cy1;
0N/A }
0N/A if (gx2 > cx2) gx2 = cx2;
0N/A if (gy2 > cy2) gy2 = cy2;
0N/A if (gx2 > gx1 && gy2 > gy1 &&
0N/A outpipe.needTile(ctx, gx1, gy1, gx2 - gx1, gy2 - gy1))
0N/A {
0N/A byte alpha[] = gl.getGrayBits();
0N/A outpipe.renderPathTile(ctx, alpha, off, w,
0N/A gx1, gy1, gx2 - gx1, gy2 - gy1);
0N/A } else {
0N/A outpipe.skipTile(ctx, gx1, gy1);
0N/A }
0N/A }
0N/A } finally {
0N/A if (ctx != null) {
0N/A outpipe.endSequence(ctx);
0N/A }
0N/A }
0N/A }
0N/A}