2 * (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
\r
4 * The program is provided "as is" without any warranty express or
\r
5 * implied, including the warranty of non-infringement and the implied
\r
6 * warranties of merchantibility and fitness for a particular purpose.
\r
7 * IBM will not be liable for any damages suffered by you as a result
\r
8 * of using the Program. In no event will IBM be liable for any
\r
9 * special, indirect or consequential damages or lost profits even if
\r
10 * IBM has been advised of the possibility of their occurrence. IBM
\r
11 * will not be liable for any third party claims against you.
\r
14 package com.ibm.richtext.textlayout.attributes;
\r
16 import java.util.Hashtable;
\r
17 import java.text.AttributedCharacterIterator.Attribute;
\r
18 import java.io.InvalidObjectException;
\r
21 * This class contains a number of keys (or attributes) for specifying text styles
\r
22 * in a Map. A text style is a collection of key-value pairs, where
\r
23 * the key represents a certain characteristic (such as size) and
\r
24 * the value tells how that characteristic is realized (ie what the
\r
27 * All of the attributes in TextAttribute specify a class for their value.
\r
28 * Map does not enforce these class specifications; however, text rendering code
\r
29 * will tend to fail with a ClassCastException if a key's value
\r
30 * has an unexpected class.
\r
32 * Some attributes are meaningful for entire paragraphs, not individual
\r
33 * characters. These attributes are documented as applying to paragraphs.
\r
34 * All other attributes apply to characters.
\r
36 * Many of the field names and values in this class
\r
37 * are taken from the JDK 1.2
\r
38 * <code>java.awt.font.TextAttribute class</code>.
\r
41 public class TextAttribute extends Attribute {
\r
46 private static final long serialVersionUID = 1831947517687597324L;
\r
48 private static final Hashtable instanceMap = new Hashtable(9);
\r
50 protected TextAttribute(String name) {
\r
52 if (this.getClass() == TextAttribute.class) {
\r
53 instanceMap.put(name, this);
\r
57 protected Object readResolve() throws InvalidObjectException {
\r
58 if (this.getClass() != TextAttribute.class) {
\r
59 throw new InvalidObjectException("subclass didn't correctly implement readResolve");
\r
62 TextAttribute instance = (TextAttribute) instanceMap.get(getName());
\r
63 if (instance != null) {
\r
66 throw new InvalidObjectException("unknown attribute name");
\r
70 public static final Object FONT = java.awt.font.TextAttribute.FONT;
\r
72 public static final Object FAMILY = java.awt.font.TextAttribute.FAMILY;
\r
74 public static final Object WEIGHT = java.awt.font.TextAttribute.WEIGHT;
\r
75 public static final Float WEIGHT_BOLD = java.awt.font.TextAttribute.WEIGHT_BOLD;
\r
77 public static final Object POSTURE = java.awt.font.TextAttribute.POSTURE;
\r
78 public static final Float POSTURE_OBLIQUE = java.awt.font.TextAttribute.POSTURE_OBLIQUE;
\r
80 public static final Object SIZE = java.awt.font.TextAttribute.SIZE;
\r
82 public static final Object SUPERSCRIPT = java.awt.font.TextAttribute.SUPERSCRIPT;
\r
83 public static final Integer SUPERSCRIPT_SUPER = java.awt.font.TextAttribute.SUPERSCRIPT_SUPER;
\r
84 public static final Integer SUPERSCRIPT_SUB = java.awt.font.TextAttribute.SUPERSCRIPT_SUB;
\r
87 * Attribute key for the foreground and background color adornment.
\r
89 public static final Object FOREGROUND = java.awt.font.TextAttribute.FOREGROUND;
\r
90 public static final Object BACKGROUND = java.awt.font.TextAttribute.BACKGROUND;
\r
92 public static final Object UNDERLINE = java.awt.font.TextAttribute.UNDERLINE;
\r
93 public static final Integer UNDERLINE_ON = java.awt.font.TextAttribute.UNDERLINE_ON;
\r
95 public static final Object STRIKETHROUGH = java.awt.font.TextAttribute.STRIKETHROUGH;
\r
96 public static final Boolean STRIKETHROUGH_ON = java.awt.font.TextAttribute.STRIKETHROUGH_ON;
\r
98 public static final Object OFFSET = new TextAttribute("offset");
\r
100 public static final Object CHAR_REPLACEMENT = java.awt.font.TextAttribute.CHAR_REPLACEMENT;
\r
101 // Paragraph Styles
\r
103 // values are Floats:
\r
104 public static final Object EXTRA_LINE_SPACING = new TextAttribute("extra_line_spacing");
\r
105 public static final Object EXTRA_FIRST_LINE_SPACING = new TextAttribute("extra_first_line_spacing");
\r
108 * Amount beyond leading margin to indent the first line of a paragraph.
\r
110 public static final Object FIRST_LINE_INDENT = new TextAttribute("first_line_indent");
\r
112 public static final Object MIN_LINE_SPACING = new TextAttribute("min_line_spacing");
\r
113 public static final Object MIN_FIRST_LINE_SPACING = new TextAttribute("min_first_line_spacing");
\r
116 * Flush lines left, right, or center.
\r
118 public static final Object LINE_FLUSH = new TextAttribute("line_flush");
\r
120 public static final Integer FLUSH_LEADING = new Integer(0);
\r
121 public static final Integer FLUSH_CENTER = new Integer(1);
\r
122 public static final Integer FLUSH_TRAILING = new Integer(2);
\r
124 * Value of <code>LINE_FLUSH</code> for full justification.
\r
126 public static final Integer FULLY_JUSTIFIED = new Integer(3);
\r
129 * Leading and trailing margin in paragraph.
\r
131 public static final Object LEADING_MARGIN = new TextAttribute("leading_margin");
\r
132 public static final Object TRAILING_MARGIN = new TextAttribute("trailing_margin");
\r
135 * Tab ruler. Values are MTabRuler instances.
\r
137 public static final Object TAB_RULER = new TextAttribute("tab_ruler");
\r
140 * Attribute key for the run direction of the line.
\r
142 * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
\r
144 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
\r
145 * <TD VALIGN="TOP">RUN_DIRECTION</TD></TR>
\r
147 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
\r
148 * <TD VALIGN="TOP">Boolean</TD></TR>
\r
150 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
\r
151 * <TD VALIGN="TOP">RUN_DIRECTION_LTR = true, RUN_DIRECTION_RTL = false
\r
154 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
\r
155 * <TD VALIGN="TOP">Use the default Unicode base direction from the BIDI
\r
156 * algorithm.</TD></TR>
\r
158 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
\r
159 * <TD VALIGN="TOP"><P>Specifies which base run direction to use when
\r
160 * positioning mixed directional runs within a paragraph. If this value is
\r
161 * RUN_DIRECTION_DEFAULT, <code>TextLayout</code> uses the default Unicode
\r
162 * base direction from the BIDI algorithm.</P>
\r
163 * <P><I>This attribute should have the same value over the whole
\r
164 * paragraph.</I></TD></TR>
\r
167 public static final Object RUN_DIRECTION = java.awt.font.TextAttribute.RUN_DIRECTION;
\r
170 * Left-to-right run direction.
\r
171 * @see #RUN_DIRECTION
\r
173 public static final Boolean RUN_DIRECTION_LTR = java.awt.font.TextAttribute.RUN_DIRECTION_LTR;
\r
176 * Right-to-left run direction.
\r
177 * @see #RUN_DIRECTION
\r
179 public static final Boolean RUN_DIRECTION_RTL = java.awt.font.TextAttribute.RUN_DIRECTION_RTL;
\r
182 * Attribute key for the embedding level for nested bidirectional runs.
\r
184 * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
\r
186 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
\r
187 * <TD VALIGN="TOP">BIDI_EMBEDDING</TD></TR>
\r
189 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
\r
190 * <TD VALIGN="TOP">Integer</TD></TR>
\r
192 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>
\r
193 * <TD VALIGN="TOP">Positive values 1 through 15 are <I>embedding</I>
\r
194 * levels, negative values<BR> through -15 are <I>override</I> levels
\r
197 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
\r
198 * <TD VALIGN="TOP">Use standard BIDI to compute levels from formatting
\r
199 * characters in the text.</TD></TR>
\r
201 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
\r
202 * <TD VALIGN="TOP">Specifies the bidi embedding level of the character.
\r
203 * When this attribute is present anywhere in a paragraph, then the
\r
204 * Unicode characters RLO, LRO, RLE, LRE, PDF are disregarded in the BIDI
\r
205 * analysis of that paragraph.
\r
206 * See the Unicode Standard v. 2.0, section 3-11.
\r
210 public static final Object BIDI_EMBEDDING = java.awt.font.TextAttribute.BIDI_EMBEDDING;
\r
213 * Attribute key for the justification of a paragraph.
\r
215 * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
\r
217 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
\r
218 * <TD VALIGN="TOP">JUSTIFICATION</TD></TR>
\r
220 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
\r
221 * <TD VALIGN="TOP">Float</TD></TR>
\r
223 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>
\r
224 * <TD VALIGN="TOP">0.0 through1.0</TD></TR>
\r
226 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
\r
227 * <TD VALIGN="TOP">1.0</TD></TR>
\r
229 * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
\r
230 * <TD VALIGN="TOP"><P>Specifies which fraction of the extra space to use
\r
231 * when justification is requested. For example, if the line is 50 points
\r
232 * wide and the margins are 70 points apart, a value of 0.5 means that the
\r
233 * line is padded to reach a width of 60 points.</P>
\r
234 * <P><I>This attribute should have the same value over the whole
\r
235 * paragraph.</I></TD></TR>
\r
238 public static final Object JUSTIFICATION = java.awt.font.TextAttribute.JUSTIFICATION;
\r
241 * Justify the line to the full requested width.
\r
242 * @see #JUSTIFICATION
\r
244 public static final Float JUSTIFICATION_FULL = java.awt.font.TextAttribute.JUSTIFICATION_FULL;
\r
247 * Do not allow the line to be justified.
\r
248 * @see #JUSTIFICATION
\r
250 public static final Float JUSTIFICATION_NONE = java.awt.font.TextAttribute.JUSTIFICATION_NONE;
\r