Path: blob/master/src/java.desktop/share/classes/sun/java2d/pipe/TextRenderer.java
41159 views
/*1* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.pipe;2627import java.awt.Rectangle;28import java.awt.Shape;29import sun.java2d.SunGraphics2D;30import sun.font.GlyphList;3132/*33* This class uses the alpha graybits arrays from a GlyphList object to34* drive a CompositePipe in much the same way as the antialiasing renderer.35*/36public class TextRenderer extends GlyphListPipe {3738CompositePipe outpipe;3940public TextRenderer(CompositePipe pipe) {41outpipe = pipe;42}4344protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {45int num = gl.getNumGlyphs();46Region clipRegion = sg2d.getCompClip();47int cx1 = clipRegion.getLoX();48int cy1 = clipRegion.getLoY();49int cx2 = clipRegion.getHiX();50int cy2 = clipRegion.getHiY();51Object ctx = null;52try {53gl.startGlyphIteration();54int[] bounds = gl.getBounds(num);55Rectangle r = new Rectangle(bounds[0], bounds[1],56bounds[2] - bounds[0],57bounds[3] - bounds[1]);58Shape s = sg2d.untransformShape(r);59ctx = outpipe.startSequence(sg2d, s, r, bounds);60for (int i = 0; i < num; i++) {61gl.setGlyphIndex(i);62int[] metrics = gl.getMetrics();63int gx1 = metrics[0];64int gy1 = metrics[1];65int w = metrics[2];66int gx2 = gx1 + w;67int gy2 = gy1 + metrics[3];68int off = 0;69if (gx1 < cx1) {70off = cx1 - gx1;71gx1 = cx1;72}73if (gy1 < cy1) {74off += (cy1 - gy1) * w;75gy1 = cy1;76}77if (gx2 > cx2) gx2 = cx2;78if (gy2 > cy2) gy2 = cy2;79if (gx2 > gx1 && gy2 > gy1 && !gl.isColorGlyph(i) &&80outpipe.needTile(ctx, gx1, gy1, gx2 - gx1, gy2 - gy1))81{82byte[] alpha = gl.getGrayBits();83outpipe.renderPathTile(ctx, alpha, off, w,84gx1, gy1, gx2 - gx1, gy2 - gy1);85} else {86outpipe.skipTile(ctx, gx1, gy1);87}88}89} finally {90if (ctx != null) {91outpipe.endSequence(ctx);92}93}94}95}969798