0N/A/*
6321N/A * Copyright (c) 1998, 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/A *
0N/A * (C) Copyright IBM Corp. 1998-2003 All Rights Reserved
0N/A */
0N/A
0N/Apackage sun.font;
0N/A
0N/Aimport java.awt.Font;
0N/A
0N/Aimport java.awt.font.FontRenderContext;
0N/Aimport java.awt.font.LineMetrics;
0N/Aimport java.text.Bidi;
0N/A
0N/A /**
0N/A * A factory for text labels. Basically this just holds onto the stuff that
0N/A * doesn't change-- the render context, context, and bidi info for the context-- and gets
0N/A * called for each subrange you want to create.
0N/A *
0N/A * @see Font
0N/A * @see FontRenderContext
0N/A * @see GlyphVector
0N/A * @see TextLabel
0N/A * @see ExtendedTextLabel
0N/A * @see Bidi
0N/A * @see TextLayout
0N/A */
0N/A
0N/Apublic class TextLabelFactory {
0N/A private FontRenderContext frc;
0N/A private char[] text;
0N/A private Bidi bidi;
0N/A private Bidi lineBidi;
0N/A private int flags;
0N/A private int lineStart;
5893N/A private int lineLimit;
0N/A
0N/A /**
0N/A * Initialize a factory to produce glyph arrays.
6321N/A * @param frc the FontRenderContext to use for the arrays to be produced.
0N/A * @param text the text of the paragraph.
0N/A * @param bidi the bidi information for the paragraph text, or null if the
0N/A * entire text is left-to-right text.
0N/A */
6321N/A public TextLabelFactory(FontRenderContext frc,
0N/A char[] text,
0N/A Bidi bidi,
0N/A int flags) {
0N/A this.frc = frc;
0N/A this.text = text;
0N/A this.bidi = bidi;
0N/A this.flags = flags;
0N/A this.lineBidi = bidi;
0N/A this.lineStart = 0;
0N/A this.lineLimit = text.length;
0N/A }
0N/A
0N/A public FontRenderContext getFontRenderContext() {
0N/A return frc;
0N/A }
0N/A
0N/A public char[] getText() {
0N/A return text;
0N/A }
0N/A
0N/A public Bidi getParagraphBidi() {
0N/A return bidi;
0N/A }
0N/A
0N/A public Bidi getLineBidi() {
0N/A return lineBidi;
0N/A }
0N/A
0N/A public int getLayoutFlags() {
0N/A return flags;
0N/A }
0N/A
0N/A public int getLineStart() {
0N/A return lineStart;
0N/A }
0N/A
6321N/A public int getLineLimit() {
0N/A return lineLimit;
0N/A }
0N/A
0N/A /**
0N/A * Set a line context for the factory. Shaping only occurs on this line.
0N/A * Characters are ordered as they would appear on this line.
0N/A * @param lineStart the index within the text of the start of the line.
0N/A * @param lineLimit the index within the text of the limit of the line.
6321N/A */
0N/A public void setLineContext(int lineStart, int lineLimit) {
0N/A this.lineStart = lineStart;
0N/A this.lineLimit = lineLimit;
0N/A if (bidi != null) {
0N/A lineBidi = bidi.createLineBidi(lineStart, lineLimit);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Create an extended glyph array for the text between start and limit.
0N/A *
0N/A * @param font the font to use to generate glyphs and character positions.
0N/A * @param start the start of the subrange for which to create the glyph array
0N/A * @param limit the limit of the subrange for which to create glyph array
0N/A *
0N/A * Start and limit must be within the bounds of the current line. If no
0N/A * line context has been set, the entire text is used as the current line.
0N/A * The text between start and limit will be treated as though it all has
0N/A * the same bidi level (and thus the same directionality) as the character
0N/A * at start. Clients should ensure that all text between start and limit
0N/A * has the same bidi level for the current line.
0N/A */
0N/A public ExtendedTextLabel createExtended(Font font,
0N/A CoreMetrics lm,
0N/A Decoration decorator,
0N/A int start,
0N/A int limit) {
0N/A
0N/A if (start >= limit || start < lineStart || limit > lineLimit) {
0N/A throw new IllegalArgumentException("bad start: " + start + " or limit: " + limit);
0N/A }
0N/A
0N/A int level = lineBidi == null ? 0 : lineBidi.getLevelAt(start - lineStart);
0N/A int linedir = (lineBidi == null || lineBidi.baseIsLeftToRight()) ? 0 : 1;
0N/A int layoutFlags = flags & ~0x9; // remove bidi, line direction flags
0N/A if ((level & 0x1) != 0) layoutFlags |= 1; // rtl
0N/A if ((linedir & 0x1) != 0) layoutFlags |= 8; // line rtl
0N/A
0N/A TextSource source = new StandardTextSource(text, start, limit - start, lineStart, lineLimit - lineStart, level, layoutFlags, font, frc, lm);
0N/A return new ExtendedTextSourceLabel(source, decorator);
0N/A }
0N/A
0N/A /**
0N/A * Create a simple glyph array for the text between start and limit.
0N/A *
0N/A * @param font the font to use to generate glyphs and character positions.
0N/A * @param start the start of the subrange for which to create the glyph array
6321N/A * @param limit the limit of the subrange for which to create glyph array
0N/A */
0N/A public TextLabel createSimple(Font font,
0N/A CoreMetrics lm,
0N/A int start,
0N/A int limit) {
0N/A
0N/A if (start >= limit || start < lineStart || limit > lineLimit) {
0N/A throw new IllegalArgumentException("bad start: " + start + " or limit: " + limit);
0N/A }
0N/A
0N/A int level = lineBidi == null ? 0 : lineBidi.getLevelAt(start - lineStart);
0N/A int linedir = (lineBidi == null || lineBidi.baseIsLeftToRight()) ? 0 : 1;
0N/A int layoutFlags = flags & ~0x9; // remove bidi, line direction flags
0N/A if ((level & 0x1) != 0) layoutFlags |= 1; // rtl
0N/A if ((linedir & 0x1) != 0) layoutFlags |= 8; // line rtl
0N/A TextSource source = new StandardTextSource(text, start, limit - start, lineStart, lineLimit - lineStart, level, layoutFlags, font, frc, lm);
0N/A return new TextSourceLabel(source);
0N/A }
0N/A}
0N/A