Showing the changes to java/pkg/sun/java2d/pipe/GlyphListPipe.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,147 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package sun.java2d.pipe; | ||
| 27 | |||
| 28 | import java.awt.Font; | ||
| 29 | import java.awt.Rectangle; | ||
| 30 | import java.awt.Shape; | ||
| 31 | import java.awt.font.FontRenderContext; | ||
| 32 | import java.awt.font.GlyphVector; | ||
| 33 | import java.awt.font.TextLayout; | ||
| 34 | |||
| 35 | import sun.awt.SunHints; | ||
| 36 | import sun.java2d.SunGraphics2D; | ||
| 37 | import sun.java2d.SurfaceData; | ||
| 38 | import sun.font.GlyphList; | ||
| 39 | import sun.java2d.loops.FontInfo; | ||
| 40 | |||
| 41 | /** | ||
| 42 | * A delegate pipe of SG2D for drawing text. | ||
| 43 | */ | ||
| 44 | |||
| 45 | public abstract class GlyphListPipe implements TextPipe { | ||
| 46 | |||
| 47 | public void drawString(SunGraphics2D sg2d, String s, | ||
| 48 | double x, double y) | ||
| 49 | { | ||
| 50 | FontInfo info = sg2d.getFontInfo(); | ||
| 51 | if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) { | ||
| 52 | SurfaceData.outlineTextRenderer.drawString(sg2d, s, x, y); | ||
| 53 | return; | ||
| 54 | } | ||
| 55 | |||
| 56 | float devx, devy; | ||
| 57 | if (sg2d.transformState >= sg2d.TRANSFORM_TRANSLATESCALE) { | ||
| 58 | double origin[] = {x + info.originX, y + info.originY}; | ||
| 59 | sg2d.transform.transform(origin, 0, origin, 0, 1); | ||
| 60 | devx = (float)origin[0]; | ||
| 61 | devy = (float)origin[1]; | ||
| 62 | } else { | ||
| 63 | devx = (float)(x + info.originX + sg2d.transX); | ||
| 64 | devy = (float)(y + info.originY + sg2d.transY); | ||
| 65 | } | ||
| 66 | /* setFromString returns false if shaping is needed, and we then back | ||
| 67 | * off to a TextLayout. Such text may benefit slightly from a lower | ||
| 68 | * overhead in this approach over the approach in previous releases. | ||
| 69 | */ | ||
| 70 | GlyphList gl = GlyphList.getInstance(); | ||
| 71 | if (gl.setFromString(info, s, devx, devy)) { | ||
| 72 | drawGlyphList(sg2d, gl); | ||
| 73 | gl.dispose(); | ||
| 74 | } else { | ||
| 75 | gl.dispose(); // release this asap. | ||
| 76 | TextLayout tl = new TextLayout(s, sg2d.getFont(), | ||
| 77 | sg2d.getFontRenderContext()); | ||
| 78 | tl.draw(sg2d, (float)x, (float)y); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | public void drawChars(SunGraphics2D sg2d, | ||
| 83 | char data[], int offset, int length, | ||
| 84 | int ix, int iy) | ||
| 85 | { | ||
| 86 | FontInfo info = sg2d.getFontInfo(); | ||
| 87 | float x, y; | ||
| 88 | if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) { | ||
| 89 | SurfaceData.outlineTextRenderer.drawChars( | ||
| 90 | sg2d, data, offset, length, ix, iy); | ||
| 91 | return; | ||
| 92 | } | ||
| 93 | if (sg2d.transformState >= sg2d.TRANSFORM_TRANSLATESCALE) { | ||
| 94 | double origin[] = {ix + info.originX, iy + info.originY}; | ||
| 95 | sg2d.transform.transform(origin, 0, origin, 0, 1); | ||
| 96 | x = (float) origin[0]; | ||
| 97 | y = (float) origin[1]; | ||
| 98 | } else { | ||
| 99 | x = ix + info.originX + sg2d.transX; | ||
| 100 | y = iy + info.originY + sg2d.transY; | ||
| 101 | } | ||
| 102 | GlyphList gl = GlyphList.getInstance(); | ||
| 103 | if (gl.setFromChars(info, data, offset, length, x, y)) { | ||
| 104 | drawGlyphList(sg2d, gl); | ||
| 105 | gl.dispose(); | ||
| 106 | } else { | ||
| 107 | gl.dispose(); // release this asap. | ||
| 108 | TextLayout tl = new TextLayout(new String(data, offset, length), | ||
| 109 | sg2d.getFont(), | ||
| 110 | sg2d.getFontRenderContext()); | ||
| 111 | tl.draw(sg2d, ix, iy); | ||
| 112 | |||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | public void drawGlyphVector(SunGraphics2D sg2d, GlyphVector gv, | ||
| 117 | float x, float y) | ||
| 118 | { | ||
| 119 | FontRenderContext frc = gv.getFontRenderContext(); | ||
| 120 | FontInfo info = sg2d.getGVFontInfo(gv.getFont(), frc); | ||
| 121 | if (info.pixelHeight > OutlineTextRenderer.THRESHHOLD) { | ||
| 122 | SurfaceData.outlineTextRenderer.drawGlyphVector(sg2d, gv, x, y); | ||
| 123 | return; | ||
| 124 | } | ||
| 125 | if (sg2d.transformState >= sg2d.TRANSFORM_TRANSLATESCALE) { | ||
| 126 | double origin[] = {x, y}; | ||
| 127 | sg2d.transform.transform(origin, 0, origin, 0, 1); | ||
| 128 | x = (float) origin[0]; | ||
| 129 | y = (float) origin[1]; | ||
| 130 | } else { | ||
| 131 | x += sg2d.transX; // don't use the glyph info origin, already in gv. | ||
| 132 | y += sg2d.transY; | ||
| 133 | } | ||
| 134 | |||
| 135 | GlyphList gl = GlyphList.getInstance(); | ||
| 136 | gl.setFromGlyphVector(info, gv, x, y); | ||
| 137 | drawGlyphList(sg2d, gl, info.aaHint); | ||
| 138 | gl.dispose(); | ||
| 139 | } | ||
| 140 | |||
| 141 | protected abstract void drawGlyphList(SunGraphics2D sg2d, GlyphList gl); | ||
| 142 | |||
| 143 | protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl, | ||
| 144 | int aaHint) { | ||
| 145 | drawGlyphList(sg2d, gl); | ||
| 146 | } | ||
| 147 | } | ||