001: /*
002: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
003: *
004: * The program is provided "as is" without any warranty express or
005: * implied, including the warranty of non-infringement and the implied
006: * warranties of merchantibility and fitness for a particular purpose.
007: * IBM will not be liable for any damages suffered by you as a result
008: * of using the Program. In no event will IBM be liable for any
009: * special, indirect or consequential damages or lost profits even if
010: * IBM has been advised of the possibility of their occurrence. IBM
011: * will not be liable for any third party claims against you.
012: */
013: // Requires Java2
014: package com.ibm.richtext.textlayout.attributes;
015:
016: import java.util.Hashtable;
017: import java.text.AttributedCharacterIterator.Attribute;
018: import java.io.InvalidObjectException;
019:
020: /**
021: * This class contains a number of keys (or attributes) for specifying text styles
022: * in a Map. A text style is a collection of key-value pairs, where
023: * the key represents a certain characteristic (such as size) and
024: * the value tells how that characteristic is realized (ie what the
025: * size is).
026: * <p>
027: * All of the attributes in TextAttribute specify a class for their value.
028: * Map does not enforce these class specifications; however, text rendering code
029: * will tend to fail with a ClassCastException if a key's value
030: * has an unexpected class.
031: * <p>
032: * Some attributes are meaningful for entire paragraphs, not individual
033: * characters. These attributes are documented as applying to paragraphs.
034: * All other attributes apply to characters.
035: * <p>
036: * Many of the field names and values in this class
037: * are taken from the JDK 1.2
038: * <code>java.awt.font.TextAttribute class</code>.
039: * @see Map
040: */
041: public class TextAttribute extends Attribute {
042:
043: private static final Hashtable instanceMap = new Hashtable(9);
044:
045: protected TextAttribute(String name) {
046: super (name);
047: if (this .getClass() == TextAttribute.class) {
048: instanceMap.put(name, this );
049: }
050: }
051:
052: protected Object readResolve() throws InvalidObjectException {
053: if (this .getClass() != TextAttribute.class) {
054: throw new InvalidObjectException(
055: "subclass didn't correctly implement readResolve");
056: }
057:
058: TextAttribute instance = (TextAttribute) instanceMap
059: .get(getName());
060: if (instance != null) {
061: return instance;
062: } else {
063: throw new InvalidObjectException("unknown attribute name");
064: }
065: }
066:
067: public static final Object FONT = java.awt.font.TextAttribute.FONT;
068:
069: public static final Object FAMILY = java.awt.font.TextAttribute.FAMILY;
070:
071: public static final Object WEIGHT = java.awt.font.TextAttribute.WEIGHT;
072: public static final Float WEIGHT_BOLD = java.awt.font.TextAttribute.WEIGHT_BOLD;
073:
074: public static final Object POSTURE = java.awt.font.TextAttribute.POSTURE;
075: public static final Float POSTURE_OBLIQUE = java.awt.font.TextAttribute.POSTURE_OBLIQUE;
076:
077: public static final Object SIZE = java.awt.font.TextAttribute.SIZE;
078:
079: public static final Object SUPERSCRIPT = java.awt.font.TextAttribute.SUPERSCRIPT;
080: public static final Integer SUPERSCRIPT_SUPER = java.awt.font.TextAttribute.SUPERSCRIPT_SUPER;
081: public static final Integer SUPERSCRIPT_SUB = java.awt.font.TextAttribute.SUPERSCRIPT_SUB;
082:
083: /**
084: * Attribute key for the foreground and background color adornment.
085: */
086: public static final Object FOREGROUND = java.awt.font.TextAttribute.FOREGROUND;
087: public static final Object BACKGROUND = java.awt.font.TextAttribute.BACKGROUND;
088:
089: public static final Object UNDERLINE = java.awt.font.TextAttribute.UNDERLINE;
090: public static final Integer UNDERLINE_ON = java.awt.font.TextAttribute.UNDERLINE_ON;
091:
092: public static final Object STRIKETHROUGH = java.awt.font.TextAttribute.STRIKETHROUGH;
093: public static final Boolean STRIKETHROUGH_ON = java.awt.font.TextAttribute.STRIKETHROUGH_ON;
094:
095: public static final Object OFFSET = new TextAttribute("offset");
096:
097: public static final Object CHAR_REPLACEMENT = java.awt.font.TextAttribute.CHAR_REPLACEMENT;
098: // Paragraph Styles
099:
100: // values are Floats:
101: public static final Object EXTRA_LINE_SPACING = new TextAttribute(
102: "extra_line_spacing");
103: public static final Object EXTRA_FIRST_LINE_SPACING = new TextAttribute(
104: "extra_first_line_spacing");
105:
106: /**
107: * Amount beyond leading margin to indent the first line of a paragraph.
108: */
109: public static final Object FIRST_LINE_INDENT = new TextAttribute(
110: "first_line_indent");
111:
112: public static final Object MIN_LINE_SPACING = new TextAttribute(
113: "min_line_spacing");
114: public static final Object MIN_FIRST_LINE_SPACING = new TextAttribute(
115: "min_first_line_spacing");
116:
117: /**
118: * Flush lines left, right, or center.
119: */
120: public static final Object LINE_FLUSH = new TextAttribute(
121: "line_flush");
122:
123: public static final Integer FLUSH_LEADING = new Integer(0);
124: public static final Integer FLUSH_CENTER = new Integer(1);
125: public static final Integer FLUSH_TRAILING = new Integer(2);
126: /**
127: * Value of <code>LINE_FLUSH</code> for full justification.
128: */
129: public static final Integer FULLY_JUSTIFIED = new Integer(3);
130:
131: /**
132: * Leading and trailing margin in paragraph.
133: */
134: public static final Object LEADING_MARGIN = new TextAttribute(
135: "leading_margin");
136: public static final Object TRAILING_MARGIN = new TextAttribute(
137: "trailing_margin");
138:
139: /**
140: * Tab ruler. Values are MTabRuler instances.
141: */
142: public static final Object TAB_RULER = new TextAttribute(
143: "tab_ruler");
144:
145: /**
146: * Attribute key for the run direction of the line.
147: *
148: * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
149: * <TR>
150: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
151: * <TD VALIGN="TOP">RUN_DIRECTION</TD></TR>
152: * <TR>
153: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
154: * <TD VALIGN="TOP">Boolean</TD></TR>
155: * <TR>
156: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
157: * <TD VALIGN="TOP">RUN_DIRECTION_LTR = true, RUN_DIRECTION_RTL = false
158: * </TD></TR>
159: * <TR>
160: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
161: * <TD VALIGN="TOP">Use the default Unicode base direction from the BIDI
162: * algorithm.</TD></TR>
163: * <TR>
164: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
165: * <TD VALIGN="TOP"><P>Specifies which base run direction to use when
166: * positioning mixed directional runs within a paragraph. If this value is
167: * RUN_DIRECTION_DEFAULT, <code>TextLayout</code> uses the default Unicode
168: * base direction from the BIDI algorithm.</P>
169: * <P><I>This attribute should have the same value over the whole
170: * paragraph.</I></TD></TR>
171: * </TABLE>
172: */
173: public static final Object RUN_DIRECTION = java.awt.font.TextAttribute.RUN_DIRECTION;
174:
175: /**
176: * Left-to-right run direction.
177: * @see #RUN_DIRECTION
178: */
179: public static final Boolean RUN_DIRECTION_LTR = java.awt.font.TextAttribute.RUN_DIRECTION_LTR;
180:
181: /**
182: * Right-to-left run direction.
183: * @see #RUN_DIRECTION
184: */
185: public static final Boolean RUN_DIRECTION_RTL = java.awt.font.TextAttribute.RUN_DIRECTION_RTL;
186:
187: /**
188: * Attribute key for the embedding level for nested bidirectional runs.
189: *
190: * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
191: * <TR>
192: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
193: * <TD VALIGN="TOP">BIDI_EMBEDDING</TD></TR>
194: * <TR>
195: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
196: * <TD VALIGN="TOP">Integer</TD></TR>
197: * <TR>
198: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>
199: * <TD VALIGN="TOP">Positive values 1 through 15 are <I>embedding</I>
200: * levels, negative values<BR> through -15 are <I>override</I> levels
201: * </TD></TR>
202: * <TR>
203: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
204: * <TD VALIGN="TOP">Use standard BIDI to compute levels from formatting
205: * characters in the text.</TD></TR>
206: * <TR>
207: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
208: * <TD VALIGN="TOP">Specifies the bidi embedding level of the character.
209: * When this attribute is present anywhere in a paragraph, then the
210: * Unicode characters RLO, LRO, RLE, LRE, PDF are disregarded in the BIDI
211: * analysis of that paragraph.
212: * See the Unicode Standard v. 2.0, section 3-11.
213: * </TD></TR>
214: * </TABLE>
215: */
216: public static final Object BIDI_EMBEDDING = java.awt.font.TextAttribute.BIDI_EMBEDDING;
217:
218: /**
219: * Attribute key for the justification of a paragraph.
220: *
221: * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
222: * <TR>
223: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
224: * <TD VALIGN="TOP">JUSTIFICATION</TD></TR>
225: * <TR>
226: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
227: * <TD VALIGN="TOP">Float</TD></TR>
228: * <TR>
229: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>
230: * <TD VALIGN="TOP">0.0 through1.0</TD></TR>
231: * <TR>
232: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
233: * <TD VALIGN="TOP">1.0</TD></TR>
234: * <TR>
235: * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
236: * <TD VALIGN="TOP"><P>Specifies which fraction of the extra space to use
237: * when justification is requested. For example, if the line is 50 points
238: * wide and the margins are 70 points apart, a value of 0.5 means that the
239: * line is padded to reach a width of 60 points.</P>
240: * <P><I>This attribute should have the same value over the whole
241: * paragraph.</I></TD></TR>
242: * </TABLE>
243: */
244: public static final Object JUSTIFICATION = java.awt.font.TextAttribute.JUSTIFICATION;
245:
246: /**
247: * Justify the line to the full requested width.
248: * @see #JUSTIFICATION
249: */
250: public static final Float JUSTIFICATION_FULL = java.awt.font.TextAttribute.JUSTIFICATION_FULL;
251:
252: /**
253: * Do not allow the line to be justified.
254: * @see #JUSTIFICATION
255: */
256: public static final Float JUSTIFICATION_NONE = java.awt.font.TextAttribute.JUSTIFICATION_NONE;
257: }
|