Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/java2d/pipe/TextRenderer.java
38918 views
/*1* Copyright (c) 2000, 2003, 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 java.awt.Font;30import java.awt.font.GlyphVector;31import sun.java2d.SunGraphics2D;32import sun.java2d.loops.FontInfo;33import sun.font.GlyphList;3435/*36* This class uses the alpha graybits arrays from a GlyphList object to37* drive a CompositePipe in much the same way as the antialiasing renderer.38*/39public class TextRenderer extends GlyphListPipe {4041CompositePipe outpipe;4243public TextRenderer(CompositePipe pipe) {44outpipe = pipe;45}4647protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {48int num = gl.getNumGlyphs();49Region clipRegion = sg2d.getCompClip();50int cx1 = clipRegion.getLoX();51int cy1 = clipRegion.getLoY();52int cx2 = clipRegion.getHiX();53int cy2 = clipRegion.getHiY();54Object ctx = null;55try {56int[] bounds = gl.getBounds();57Rectangle r = new Rectangle(bounds[0], bounds[1],58bounds[2] - bounds[0],59bounds[3] - bounds[1]);60Shape s = sg2d.untransformShape(r);61ctx = outpipe.startSequence(sg2d, s, r, bounds);62for (int i = 0; i < num; i++) {63gl.setGlyphIndex(i);64int metrics[] = gl.getMetrics();65int gx1 = metrics[0];66int gy1 = metrics[1];67int w = metrics[2];68int gx2 = gx1 + w;69int gy2 = gy1 + metrics[3];70int off = 0;71if (gx1 < cx1) {72off = cx1 - gx1;73gx1 = cx1;74}75if (gy1 < cy1) {76off += (cy1 - gy1) * w;77gy1 = cy1;78}79if (gx2 > cx2) gx2 = cx2;80if (gy2 > cy2) gy2 = cy2;81if (gx2 > gx1 && gy2 > gy1 &&82outpipe.needTile(ctx, gx1, gy1, gx2 - gx1, gy2 - gy1))83{84byte alpha[] = gl.getGrayBits();85outpipe.renderPathTile(ctx, alpha, off, w,86gx1, gy1, gx2 - gx1, gy2 - gy1);87} else {88outpipe.skipTile(ctx, gx1, gy1);89}90}91} finally {92if (ctx != null) {93outpipe.endSequence(ctx);94}95}96}97}9899100