Showing the changes to java/pkg/sun/font/TextLabelFactory.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,181 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 2003, 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 | * | ||
| 27 | * (C) Copyright IBM Corp. 1998-2003 All Rights Reserved | ||
| 28 | */ | ||
| 29 | |||
| 30 | package sun.font; | ||
| 31 | |||
| 32 | import java.awt.Font; | ||
| 33 | |||
| 34 | import java.awt.font.FontRenderContext; | ||
| 35 | import java.awt.font.LineMetrics; | ||
| 36 | import java.text.Bidi; | ||
| 37 | |||
| 38 | /** | ||
| 39 | * A factory for text labels. Basically this just holds onto the stuff that | ||
| 40 | * doesn't change-- the render context, context, and bidi info for the context-- and gets | ||
| 41 | * called for each subrange you want to create. | ||
| 42 | * | ||
| 43 | * @see Font | ||
| 44 | * @see FontRenderContext | ||
| 45 | * @see GlyphVector | ||
| 46 | * @see TextLabel | ||
| 47 | * @see ExtendedTextLabel | ||
| 48 | * @see Bidi | ||
| 49 | * @see TextLayout | ||
| 50 | */ | ||
| 51 | |||
| 52 | public class TextLabelFactory { | ||
| 53 | private FontRenderContext frc; | ||
| 54 | private char[] text; | ||
| 55 | private Bidi bidi; | ||
| 56 | private Bidi lineBidi; | ||
| 57 | private int flags; | ||
| 58 | private int lineStart; | ||
| 59 | private int lineLimit; | ||
| 60 | |||
| 61 | /** | ||
| 62 | * Initialize a factory to produce glyph arrays. | ||
| 63 | * @param frc the FontRenderContext to use for the arrays to be produced. | ||
| 64 | * @param text the text of the paragraph. | ||
| 65 | * @param bidi the bidi information for the paragraph text, or null if the | ||
| 66 | * entire text is left-to-right text. | ||
| 67 | */ | ||
| 68 | public TextLabelFactory(FontRenderContext frc, | ||
| 69 | char[] text, | ||
| 70 | Bidi bidi, | ||
| 71 | int flags) { | ||
| 72 | this.frc = frc; | ||
| 73 | this.text = text; | ||
| 74 | this.bidi = bidi; | ||
| 75 | this.flags = flags; | ||
| 76 | this.lineBidi = bidi; | ||
| 77 | this.lineStart = 0; | ||
| 78 | this.lineLimit = text.length; | ||
| 79 | } | ||
| 80 | |||
| 81 | public FontRenderContext getFontRenderContext() { | ||
| 82 | return frc; | ||
| 83 | } | ||
| 84 | |||
| 85 | public char[] getText() { | ||
| 86 | return text; | ||
| 87 | } | ||
| 88 | |||
| 89 | public Bidi getParagraphBidi() { | ||
| 90 | return bidi; | ||
| 91 | } | ||
| 92 | |||
| 93 | public Bidi getLineBidi() { | ||
| 94 | return lineBidi; | ||
| 95 | } | ||
| 96 | |||
| 97 | public int getLayoutFlags() { | ||
| 98 | return flags; | ||
| 99 | } | ||
| 100 | |||
| 101 | public int getLineStart() { | ||
| 102 | return lineStart; | ||
| 103 | } | ||
| 104 | |||
| 105 | public int getLineLimit() { | ||
| 106 | return lineLimit; | ||
| 107 | } | ||
| 108 | |||
| 109 | /** | ||
| 110 | * Set a line context for the factory. Shaping only occurs on this line. | ||
| 111 | * Characters are ordered as they would appear on this line. | ||
| 112 | * @param lineStart the index within the text of the start of the line. | ||
| 113 | * @param lineLimit the index within the text of the limit of the line. | ||
| 114 | */ | ||
| 115 | public void setLineContext(int lineStart, int lineLimit) { | ||
| 116 | this.lineStart = lineStart; | ||
| 117 | this.lineLimit = lineLimit; | ||
| 118 | if (bidi != null) { | ||
| 119 | lineBidi = bidi.createLineBidi(lineStart, lineLimit); | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | /** | ||
| 124 | * Create an extended glyph array for the text between start and limit. | ||
| 125 | * | ||
| 126 | * @param font the font to use to generate glyphs and character positions. | ||
| 127 | * @param start the start of the subrange for which to create the glyph array | ||
| 128 | * @param limit the limit of the subrange for which to create glyph array | ||
| 129 | * | ||
| 130 | * Start and limit must be within the bounds of the current line. If no | ||
| 131 | * line context has been set, the entire text is used as the current line. | ||
| 132 | * The text between start and limit will be treated as though it all has | ||
| 133 | * the same bidi level (and thus the same directionality) as the character | ||
| 134 | * at start. Clients should ensure that all text between start and limit | ||
| 135 | * has the same bidi level for the current line. | ||
| 136 | */ | ||
| 137 | public ExtendedTextLabel createExtended(Font font, | ||
| 138 | CoreMetrics lm, | ||
| 139 | Decoration decorator, | ||
| 140 | int start, | ||
| 141 | int limit) { | ||
| 142 | |||
| 143 | if (start >= limit || start < lineStart || limit > lineLimit) { | ||
| 144 | throw new IllegalArgumentException("bad start: " + start + " or limit: " + limit); | ||
| 145 | } | ||
| 146 | |||
| 147 | int level = lineBidi == null ? 0 : lineBidi.getLevelAt(start - lineStart); | ||
| 148 | int linedir = (lineBidi == null || lineBidi.baseIsLeftToRight()) ? 0 : 1; | ||
| 149 | int layoutFlags = flags & ~0x9; // remove bidi, line direction flags | ||
| 150 | if ((level & 0x1) != 0) layoutFlags |= 1; // rtl | ||
| 151 | if ((linedir & 0x1) != 0) layoutFlags |= 8; // line rtl | ||
| 152 | |||
| 153 | TextSource source = new StandardTextSource(text, start, limit - start, lineStart, lineLimit - lineStart, level, layoutFlags, font, frc, lm); | ||
| 154 | return new ExtendedTextSourceLabel(source, decorator); | ||
| 155 | } | ||
| 156 | |||
| 157 | /** | ||
| 158 | * Create a simple glyph array for the text between start and limit. | ||
| 159 | * | ||
| 160 | * @param font the font to use to generate glyphs and character positions. | ||
| 161 | * @param start the start of the subrange for which to create the glyph array | ||
| 162 | * @param limit the limit of the subrange for which to create glyph array | ||
| 163 | */ | ||
| 164 | public TextLabel createSimple(Font font, | ||
| 165 | CoreMetrics lm, | ||
| 166 | int start, | ||
| 167 | int limit) { | ||
| 168 | |||
| 169 | if (start >= limit || start < lineStart || limit > lineLimit) { | ||
| 170 | throw new IllegalArgumentException("bad start: " + start + " or limit: " + limit); | ||
| 171 | } | ||
| 172 | |||
| 173 | int level = lineBidi == null ? 0 : lineBidi.getLevelAt(start - lineStart); | ||
| 174 | int linedir = (lineBidi == null || lineBidi.baseIsLeftToRight()) ? 0 : 1; | ||
| 175 | int layoutFlags = flags & ~0x9; // remove bidi, line direction flags | ||
| 176 | if ((level & 0x1) != 0) layoutFlags |= 1; // rtl | ||
| 177 | if ((linedir & 0x1) != 0) layoutFlags |= 8; // line rtl | ||
| 178 | TextSource source = new StandardTextSource(text, start, limit - start, lineStart, lineLimit - lineStart, level, layoutFlags, font, frc, lm); | ||
| 179 | return new TextSourceLabel(source); | ||
| 180 | } | ||
| 181 | } | ||