1 /*
2  * Copyright (c) 1997, 2006, 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 Taligent, Inc. 1996 - 1997, All Rights Reserved
28  * (C) Copyright IBM Corp. 1996 - 1998, All Rights Reserved
29  *
30  * The original version of this source code and documentation is
31  * copyrighted and owned by Taligent, Inc., a wholly-owned subsidiary
32  * of IBM. These materials are provided under terms of a License
33  * Agreement between Taligent and Sun. This technology is protected
34  * by multiple US and International patents.
35  *
36  * This notice and attribution to Taligent may not be removed.
37  * Taligent is a registered trademark of Taligent, Inc.
38  *
39  */
40 
41 package java.awt.font;
42 
43 import java.io.InvalidObjectException;
44 import java.text.AttributedCharacterIterator.Attribute;
45 import java.util.Map;
46 import java.util.HashMap;
47 
48 /**
49  * The <code>TextAttribute</code> class defines attribute keys and
50  * attribute values used for text rendering.
51  * <p>
52  * <code>TextAttribute</code> instances are used as attribute keys to
53  * identify attributes in classes handling text attributes. Other
54  * constants defined in this class can be used as attribute values.
55  * <p>
56  * For each text attribute, the documentation provides:
57  * <UL>
58  *   <LI>the type of its value,
59  *   <LI>the relevant predefined constants, if any
60  *   <LI>the default effect if the attribute is absent
61  *   <LI>the valid values if there are limitations
62  *   <LI>a description of the effect.
63  * </UL>
64  * <p>
65  * <H4>Values</H4>
66  * <UL>
67  *   <LI>The values of attributes must always be immutable.
68  *   <LI>Where value limitations are given, any value outside of that
69  *   set is reserved for future use; the value will be treated as
70  *   the default.
71  *   <LI>The value <code>null</code> is treated the same as the
72  *   default value and results in the default behavior.
73  *   <li>If the value is not of the proper type, the attribute
74  *   will be ignored.
75  *   <li>The identity of the value does not matter, only the actual
76  *   value.  For example, <code>TextAttribute.WEIGHT_BOLD</code> and
77  *   <code>new Float(2.0)</code>
78  *   indicate the same <code>WEIGHT</code>.
79  *   <li>Attribute values of type <code>Number</code> (used for
80  *   <code>WEIGHT</code>, <code>WIDTH</code>, <code>POSTURE</code>,
81  *   <code>SIZE</code>, <code>JUSTIFICATION</code>, and
82  *   <code>TRACKING</code>) can vary along their natural range and are
83  *   not restricted to the predefined constants.
84  *   <code>Number.floatValue()</code> is used to get the actual value
85  *   from the <code>Number</code>.
86  *   <li>The values for <code>WEIGHT</code>, <code>WIDTH</code>, and
87  *   <code>POSTURE</code> are interpolated by the system, which
88  *   can select the 'nearest available' font or use other techniques to
89  *   approximate the user's request.
90  *
91  * </UL>
92  *
93  * @see java.text.AttributedCharacterIterator
94  */
95 
96 // Android-removed: Removed Summary of Attributes.
97 /* <h4>Summary of attributes</h4>
98  * <p>
99  * <font size="-1">
100  * <table align="center" border="0" cellspacing="0" cellpadding="2" width="%95"
101  *     summary="Key, value type, principal constants, and default value
102  *     behavior of all TextAttributes">
103  * <tr bgcolor="#ccccff">
104  * <th valign="TOP" align="CENTER">Key</th>
105  * <th valign="TOP" align="CENTER">Value Type</th>
106  * <th valign="TOP" align="CENTER">Principal Constants</th>
107  * <th valign="TOP" align="CENTER">Default Value</th>
108  * </tr>
109  * <tr>
110  * <td valign="TOP">{@link #FAMILY}</td>
111  * <td valign="TOP">String</td>
112  * <td valign="TOP">See Font {@link java.awt.Font#DIALOG DIALOG},
113 {@link java.awt.Font#DIALOG_INPUT DIALOG_INPUT},<br> {@link java.awt.Font#SERIF SERIF},
114 {@link java.awt.Font#SANS_SERIF SANS_SERIF}, and {@link java.awt.Font#MONOSPACED MONOSPACED}.
115 </td>
116  * <td valign="TOP">"Default" (use platform default)</td>
117  * </tr>
118  * <tr bgcolor="#eeeeff">
119  * <td valign="TOP">{@link #WEIGHT}</td>
120  * <td valign="TOP">Number</td>
121  * <td valign="TOP">WEIGHT_REGULAR, WEIGHT_BOLD</td>
122  * <td valign="TOP">WEIGHT_REGULAR</td>
123  * </tr>
124  * <tr>
125  * <td valign="TOP">{@link #WIDTH}</td>
126  * <td valign="TOP">Number</td>
127  * <td valign="TOP">WIDTH_CONDENSED, WIDTH_REGULAR,<br>WIDTH_EXTENDED</td>
128  * <td valign="TOP">WIDTH_REGULAR</td>
129  * </tr>
130  * <tr bgcolor="#eeeeff">
131  * <td valign="TOP">{@link #POSTURE}</td>
132  * <td valign="TOP">Number</td>
133  * <td valign="TOP">POSTURE_REGULAR, POSTURE_OBLIQUE</td>
134  * <td valign="TOP">POSTURE_REGULAR</td>
135  * </tr>
136  * <tr>
137  * <td valign="TOP">{@link #SIZE}</td>
138  * <td valign="TOP">Number</td>
139  * <td valign="TOP">none</td>
140  * <td valign="TOP">12.0</td>
141  * </tr>
142  * <tr bgcolor="#eeeeff">
143  * <td valign="TOP">{@link #TRANSFORM}</td>
144  * <td valign="TOP">{@link TransformAttribute}</td>
145  * <td valign="TOP">See TransformAttribute {@link TransformAttribute#IDENTITY IDENTITY}</td>
146  * <td valign="TOP">TransformAttribute.IDENTITY</td>
147  * </tr>
148  * <tr>
149  * <td valign="TOP">{@link #SUPERSCRIPT}</td>
150  * <td valign="TOP">Integer</td>
151  * <td valign="TOP">SUPERSCRIPT_SUPER, SUPERSCRIPT_SUB</td>
152  * <td valign="TOP">0 (use the standard glyphs and metrics)</td>
153  * </tr>
154  * <tr bgcolor="#eeeeff">
155  * <td valign="TOP">{@link #FONT}</td>
156  * <td valign="TOP">{@link java.awt.Font}</td>
157  * <td valign="TOP">none</td>
158  * <td valign="TOP">null (do not override font resolution)</td>
159  * </tr>
160  * <tr>
161  * <td valign="TOP">{@link #CHAR_REPLACEMENT}</td>
162  * <td valign="TOP">{@link GraphicAttribute}</td>
163  * <td valign="TOP">none</td>
164  * <td valign="TOP">null (draw text using font glyphs)</td>
165  * </tr>
166  * <tr bgcolor="#eeeeff">
167  * <td valign="TOP">{@link #FOREGROUND}</td>
168  * <td valign="TOP">{@link java.awt.Paint}</td>
169  * <td valign="TOP">none</td>
170  * <td valign="TOP">null (use current graphics paint)</td>
171  * </tr>
172  * <tr>
173  * <td valign="TOP">{@link #BACKGROUND}</td>
174  * <td valign="TOP">{@link java.awt.Paint}</td>
175  * <td valign="TOP">none</td>
176  * <td valign="TOP">null (do not render background)</td>
177  * </tr>
178  * <tr bgcolor="#eeeeff">
179  * <td valign="TOP">{@link #UNDERLINE}</td>
180  * <td valign="TOP">Integer</td>
181  * <td valign="TOP">UNDERLINE_ON</td>
182  * <td valign="TOP">-1 (do not render underline)</td>
183  * </tr>
184  * <tr>
185  * <td valign="TOP">{@link #STRIKETHROUGH}</td>
186  * <td valign="TOP">Boolean</td>
187  * <td valign="TOP">STRIKETHROUGH_ON</td>
188  * <td valign="TOP">false (do not render strikethrough)</td>
189  * </tr>
190  * <tr bgcolor="#eeeeff">
191  * <td valign="TOP">{@link #RUN_DIRECTION}</td>
192  * <td valign="TOP">Boolean</td>
193  * <td valign="TOP">RUN_DIRECTION_LTR<br>RUN_DIRECTION_RTL</td>
194  * <td valign="TOP">null (use {@link java.text.Bidi} standard default)</td>
195  * </tr>
196  * <tr>
197  * <td valign="TOP">{@link #BIDI_EMBEDDING}</td>
198  * <td valign="TOP">Integer</td>
199  * <td valign="TOP">none</td>
200  * <td valign="TOP">0 (use base line direction)</td>
201  * </tr>
202  * <tr bgcolor="#eeeeff">
203  * <td valign="TOP">{@link #JUSTIFICATION}</td>
204  * <td valign="TOP">Number</td>
205  * <td valign="TOP">JUSTIFICATION_FULL</td>
206  * <td valign="TOP">JUSTIFICATION_FULL</td>
207  * </tr>
208  * <tr>
209  * <td valign="TOP">{@link #INPUT_METHOD_HIGHLIGHT}</td>
210  * <td valign="TOP">{@link java.awt.im.InputMethodHighlight},<br>{@link java.text.Annotation}</td>
211  * <td valign="TOP">(see class)</td>
212  * <td valign="TOP">null (do not apply input highlighting)</td>
213  * </tr>
214  * <tr bgcolor="#eeeeff">
215  * <td valign="TOP">{@link #INPUT_METHOD_UNDERLINE}</td>
216  * <td valign="TOP">Integer</td>
217  * <td valign="TOP">UNDERLINE_LOW_ONE_PIXEL,<br>UNDERLINE_LOW_TWO_PIXEL</td>
218  * <td valign="TOP">-1 (do not render underline)</td>
219  * </tr>
220  * <tr>
221  * <td valign="TOP">{@link #SWAP_COLORS}</td>
222  * <td valign="TOP">Boolean</td>
223  * <td valign="TOP">SWAP_COLORS_ON</td>
224  * <td valign="TOP">false (do not swap colors)</td>
225  * </tr>
226  * <tr bgcolor="#eeeeff">
227  * <td valign="TOP">{@link #NUMERIC_SHAPING}</td>
228  * <td valign="TOP">{@link java.awt.font.NumericShaper}</td>
229  * <td valign="TOP">none</td>
230  * <td valign="TOP">null (do not shape digits)</td>
231  * </tr>
232  * <tr>
233  * <td valign="TOP">{@link #KERNING}</td>
234  * <td valign="TOP">Integer</td>
235  * <td valign="TOP">KERNING_ON</td>
236  * <td valign="TOP">0 (do not request kerning)</td>
237  * </tr>
238  * <tr bgcolor="#eeeeff">
239  * <td valign="TOP">{@link #LIGATURES}</td>
240  * <td valign="TOP">Integer</td>
241  * <td valign="TOP">LIGATURES_ON</td>
242  * <td valign="TOP">0 (do not form optional ligatures)</td>
243  * </tr>
244  * <tr>
245  * <td valign="TOP">{@link #TRACKING}</td>
246  * <td valign="TOP">Number</td>
247  * <td valign="TOP">TRACKING_LOOSE, TRACKING_TIGHT</td>
248  * <td valign="TOP">0 (do not add tracking)</td>
249  * </tr>
250  * </table>
251  * </font>
252  *
253  * @see java.awt.Font
254  * @see java.awt.font.TextLayout
255  */
256 // Android-removed
257 //
258 // {@link java.awt.Font Font},
259 // {@link java.awt.font.TextLayout TextLayout},
260 // {@link java.text.AttributedCharacterIterator AttributedCharacterIterator},
261 public final class TextAttribute extends Attribute {
262 
263     // table of all instances in this class, used by readResolve
264     private static final Map instanceMap = new HashMap(29);
265 
266     /**
267      * Constructs a <code>TextAttribute</code> with the specified name.
268      * @param name the attribute name to assign to this
269      * <code>TextAttribute</code>
270      */
TextAttribute(String name)271     protected TextAttribute(String name) {
272         super(name);
273         if (this.getClass() == TextAttribute.class) {
274             instanceMap.put(name, this);
275         }
276     }
277 
278     /**
279      * Resolves instances being deserialized to the predefined constants.
280      */
readResolve()281     protected Object readResolve() throws InvalidObjectException {
282         if (this.getClass() != TextAttribute.class) {
283             throw new InvalidObjectException(
284                 "subclass didn't correctly implement readResolve");
285         }
286 
287         TextAttribute instance = (TextAttribute) instanceMap.get(getName());
288         if (instance != null) {
289             return instance;
290         } else {
291             throw new InvalidObjectException("unknown attribute name");
292         }
293     }
294 
295     // Serialization compatibility with Java 2 platform v1.2.
296     // 1.2 will throw an InvalidObjectException if ever asked to
297     // deserialize INPUT_METHOD_UNDERLINE.
298     // This shouldn't happen in real life.
299     static final long serialVersionUID = 7744112784117861702L;
300 
301     //
302     // For use with Font.
303     //
304 
305     /**
306      * Attribute key for the font name.  Values are instances of
307      * <b><code>String</code></b>.  The default value is
308      * <code>"Default"</code>, which causes the platform default font
309      * family to be used.
310      *
311      * <p> The <code>Font</code> class defines constants for the logical
312      * font names.
313      *
314      * <p>This defines the value passed as <code>name</code> to the
315      * <code>Font</code> constructor.  Both logical and physical
316      * font names are allowed. If a font with the requested name
317      * is not found, the default font is used.
318      *
319      * <p><em>Note:</em> This attribute is unfortunately misnamed, as
320      * it specifies the face name and not just the family.  Thus
321      * values such as "Lucida Sans Bold" will select that face if it
322      * exists.  Note, though, that if the requested face does not
323      * exist, the default will be used with <em>regular</em> weight.
324      * The "Bold" in the name is part of the face name, not a separate
325      * request that the font's weight be bold.</p>
326      */
327     // Android-removed links to font names.
328     //
329     // {@link java.awt.Font#DIALOG DIALOG},
330     // {@link java.awt.Font#DIALOG_INPUT DIALOG_INPUT},
331     // {@link java.awt.Font#SANS_SERIF SANS_SERIF},
332     // {@link java.awt.Font#SERIF SERIF}, and
333     // {@link java.awt.Font#MONOSPACED MONOSPACED}.
334     public static final TextAttribute FAMILY =
335         new TextAttribute("family");
336 
337     /**
338      * Attribute key for the weight of a font.  Values are instances
339      * of <b><code>Number</code></b>.  The default value is
340      * <code>WEIGHT_REGULAR</code>.
341      *
342      * <p>Several constant values are provided, see {@link
343      * #WEIGHT_EXTRA_LIGHT}, {@link #WEIGHT_LIGHT}, {@link
344      * #WEIGHT_DEMILIGHT}, {@link #WEIGHT_REGULAR}, {@link
345      * #WEIGHT_SEMIBOLD}, {@link #WEIGHT_MEDIUM}, {@link
346      * #WEIGHT_DEMIBOLD}, {@link #WEIGHT_BOLD}, {@link #WEIGHT_HEAVY},
347      * {@link #WEIGHT_EXTRABOLD}, and {@link #WEIGHT_ULTRABOLD}.  The
348      * value <code>WEIGHT_BOLD</code> corresponds to the
349      * style value <code>Font.BOLD</code> as passed to the
350      * <code>Font</code> constructor.
351      *
352      * <p>The value is roughly the ratio of the stem width to that of
353      * the regular weight.
354      *
355      * <p>The system can interpolate the provided value.
356      */
357     public static final TextAttribute WEIGHT =
358         new TextAttribute("weight");
359 
360     /**
361      * The lightest predefined weight.
362      * @see #WEIGHT
363      */
364     public static final Float WEIGHT_EXTRA_LIGHT =
365         Float.valueOf(0.5f);
366 
367     /**
368      * The standard light weight.
369      * @see #WEIGHT
370      */
371     public static final Float WEIGHT_LIGHT =
372         Float.valueOf(0.75f);
373 
374     /**
375      * An intermediate weight between <code>WEIGHT_LIGHT</code> and
376      * <code>WEIGHT_STANDARD</code>.
377      * @see #WEIGHT
378      */
379     public static final Float WEIGHT_DEMILIGHT =
380         Float.valueOf(0.875f);
381 
382     /**
383      * The standard weight. This is the default value for <code>WEIGHT</code>.
384      * @see #WEIGHT
385      */
386     public static final Float WEIGHT_REGULAR =
387         Float.valueOf(1.0f);
388 
389     /**
390      * A moderately heavier weight than <code>WEIGHT_REGULAR</code>.
391      * @see #WEIGHT
392      */
393     public static final Float WEIGHT_SEMIBOLD =
394         Float.valueOf(1.25f);
395 
396     /**
397      * An intermediate weight between <code>WEIGHT_REGULAR</code> and
398      * <code>WEIGHT_BOLD</code>.
399      * @see #WEIGHT
400      */
401     public static final Float WEIGHT_MEDIUM =
402         Float.valueOf(1.5f);
403 
404     /**
405      * A moderately lighter weight than <code>WEIGHT_BOLD</code>.
406      * @see #WEIGHT
407      */
408     public static final Float WEIGHT_DEMIBOLD =
409         Float.valueOf(1.75f);
410 
411     /**
412      * The standard bold weight.
413      * @see #WEIGHT
414      */
415     public static final Float WEIGHT_BOLD =
416         Float.valueOf(2.0f);
417 
418     /**
419      * A moderately heavier weight than <code>WEIGHT_BOLD</code>.
420      * @see #WEIGHT
421      */
422     public static final Float WEIGHT_HEAVY =
423         Float.valueOf(2.25f);
424 
425     /**
426      * An extra heavy weight.
427      * @see #WEIGHT
428      */
429     public static final Float WEIGHT_EXTRABOLD =
430         Float.valueOf(2.5f);
431 
432     /**
433      * The heaviest predefined weight.
434      * @see #WEIGHT
435      */
436     public static final Float WEIGHT_ULTRABOLD =
437         Float.valueOf(2.75f);
438 
439     /**
440      * Attribute key for the width of a font.  Values are instances of
441      * <b><code>Number</code></b>.  The default value is
442      * <code>WIDTH_REGULAR</code>.
443      *
444      * <p>Several constant values are provided, see {@link
445      * #WIDTH_CONDENSED}, {@link #WIDTH_SEMI_CONDENSED}, {@link
446      * #WIDTH_REGULAR}, {@link #WIDTH_SEMI_EXTENDED}, {@link
447      * #WIDTH_EXTENDED}.
448      *
449      * <p>The value is roughly the ratio of the advance width to that
450      * of the regular width.
451      *
452      * <p>The system can interpolate the provided value.
453      */
454     public static final TextAttribute WIDTH =
455         new TextAttribute("width");
456 
457     /**
458      * The most condensed predefined width.
459      * @see #WIDTH
460      */
461     public static final Float WIDTH_CONDENSED =
462         Float.valueOf(0.75f);
463 
464     /**
465      * A moderately condensed width.
466      * @see #WIDTH
467      */
468     public static final Float WIDTH_SEMI_CONDENSED =
469         Float.valueOf(0.875f);
470 
471     /**
472      * The standard width. This is the default value for
473      * <code>WIDTH</code>.
474      * @see #WIDTH
475      */
476     public static final Float WIDTH_REGULAR =
477         Float.valueOf(1.0f);
478 
479     /**
480      * A moderately extended width.
481      * @see #WIDTH
482      */
483     public static final Float WIDTH_SEMI_EXTENDED =
484         Float.valueOf(1.25f);
485 
486     /**
487      * The most extended predefined width.
488      * @see #WIDTH
489      */
490     public static final Float WIDTH_EXTENDED =
491         Float.valueOf(1.5f);
492 
493     /**
494      * Attribute key for the posture of a font.  Values are instances
495      * of <b><code>Number</code></b>. The default value is
496      * <code>POSTURE_REGULAR</code>.
497      *
498      * <p>Two constant values are provided, {@link #POSTURE_REGULAR}
499      * and {@link #POSTURE_OBLIQUE}. The value
500      * <code>POSTURE_OBLIQUE</code> corresponds to the style value
501      * <code>Font.ITALIC</code> as passed to the <code>Font</code>
502      * constructor.
503      *
504      * <p>The value is roughly the slope of the stems of the font,
505      * expressed as the run over the rise.  Positive values lean right.
506      *
507      * <p>The system can interpolate the provided value.
508      *
509      * <p>This will affect the font's italic angle as returned by
510      * <code>Font.getItalicAngle</code>.
511      *
512      */
513     // Android-removed.
514     // @see java.awt.Font#getItalicAngle()
515     public static final TextAttribute POSTURE =
516         new TextAttribute("posture");
517 
518     /**
519      * The standard posture, upright.  This is the default value for
520      * <code>POSTURE</code>.
521      * @see #POSTURE
522      */
523     public static final Float POSTURE_REGULAR =
524         Float.valueOf(0.0f);
525 
526     /**
527      * The standard italic posture.
528      * @see #POSTURE
529      */
530     public static final Float POSTURE_OBLIQUE =
531         Float.valueOf(0.20f);
532 
533     /**
534      * Attribute key for the font size.  Values are instances of
535      * <b><code>Number</code></b>.  The default value is 12pt.
536      *
537      * <p>This corresponds to the <code>size</code> parameter to the
538      * <code>Font</code> constructor.
539      *
540      * <p>Very large or small sizes will impact rendering performance,
541      * and the rendering system might not render text at these sizes.
542      * Negative sizes are illegal and result in the default size.
543      *
544      * <p>Note that the appearance and metrics of a 12pt font with a
545      * 2x transform might be different than that of a 24 point font
546      * with no transform.
547      */
548     public static final TextAttribute SIZE =
549         new TextAttribute("size");
550 
551     /**
552      * Attribute key for the transform of a font.  Values are
553      * instances of <b><code>TransformAttribute</code></b>.  The
554      * default value is <code>TransformAttribute.IDENTITY</code>.
555      *
556      * <p>The primary intent is to support scaling and skewing, though
557      * other effects are possible.</p>
558      *
559      * <p>Some transforms will cause the baseline to be rotated and/or
560      * shifted.  The text and the baseline are transformed together so
561      * that the text follows the new baseline.  For example, with text
562      * on a horizontal baseline, the new baseline follows the
563      * direction of the unit x vector passed through the
564      * transform. Text metrics are measured against this new baseline.
565      * So, for example, with other things being equal, text rendered
566      * with a rotated TRANSFORM and an unrotated TRANSFORM will measure as
567      * having the same ascent, descent, and advance.</p>
568      */
569      // Android-removed
570      //
571      // <p>This corresponds to the transform passed to
572      // <code>Font.deriveFont(AffineTransform)</code>.  Since that
573      // transform is mutable and <code>TextAttribute</code> values must
574      // not be, the <code>TransformAttribute</code> wrapper class is
575      // used.
576      //
577      // <p>The <code>TransformAttribute</code> class defines the
578      // constant {@link TransformAttribute#IDENTITY IDENTITY}.
579      // @see TransformAttribute
580      // @see java.awt.geom.AffineTransform
581      //
582      // <p>In styled text, the baselines for each such run are aligned
583      // one after the other to potentially create a non-linear baseline
584      // for the entire run of text. For more information, see {@link
585      // TextLayout#getLayoutPath}.</p>
586      public static final TextAttribute TRANSFORM =
587         new TextAttribute("transform");
588 
589     /**
590      * Attribute key for superscripting and subscripting.  Values are
591      * instances of <b><code>Integer</code></b>.  The default value is
592      * 0, which means that no superscript or subscript is used.
593      *
594      * <p>Two constant values are provided, see {@link
595      * #SUPERSCRIPT_SUPER} and {@link #SUPERSCRIPT_SUB}.  These have
596      * the values 1 and -1 respectively.  Values of
597      * greater magnitude define greater levels of superscript or
598      * subscripting, for example, 2 corresponds to super-superscript,
599      * 3 to super-super-superscript, and similarly for negative values
600      * and subscript, up to a level of 7 (or -7).  Values beyond this
601      * range are reserved; behavior is platform-dependent.
602      *
603      * <p><code>SUPERSCRIPT</code> can
604      * impact the ascent and descent of a font.  The ascent
605      * and descent can never become negative, however.
606      */
607     public static final TextAttribute SUPERSCRIPT =
608         new TextAttribute("superscript");
609 
610     /**
611      * Standard superscript.
612      * @see #SUPERSCRIPT
613      */
614     public static final Integer SUPERSCRIPT_SUPER =
615         Integer.valueOf(1);
616 
617     /**
618      * Standard subscript.
619      * @see #SUPERSCRIPT
620      */
621     public static final Integer SUPERSCRIPT_SUB =
622         Integer.valueOf(-1);
623 
624     /**
625      * Attribute key used to provide the font to use to render text.
626      *
627      * The default
628      * value is null, indicating that normal resolution of a
629      * <code>Font</code> from attributes should be performed.
630      *
631      * <p><code>TextLayout</code> and
632      * <code>AttributedCharacterIterator</code> work in terms of
633      * <code>Maps</code> of <code>TextAttributes</code>.  Normally,
634      * all the attributes are examined and used to select and
635      * configure a <code>Font</code> instance.  If a <code>FONT</code>
636      * attribute is present, though, its associated <code>Font</code>
637      * will be used.  This provides a way for users to override the
638      * resolution of font attributes into a <code>Font</code>, or
639      * force use of a particular <code>Font</code> instance.  This
640      * also allows users to specify subclasses of <code>Font</code> in
641      * cases where a <code>Font</code> can be subclassed.
642      *
643      * <p><code>FONT</code> is used for special situations where
644      * clients already have a <code>Font</code> instance but still
645      * need to use <code>Map</code>-based APIs.  Typically, there will
646      * be no other attributes in the <code>Map</code> except the
647      * <code>FONT</code> attribute.  With <code>Map</code>-based APIs
648      * the common case is to specify all attributes individually, so
649      * <code>FONT</code> is not needed or desireable.
650      *
651      * <p>However, if both <code>FONT</code> and other attributes are
652      * present in the <code>Map</code>, the rendering system will
653      * merge the attributes defined in the <code>Font</code> with the
654      * additional attributes.  This merging process classifies
655      * <code>TextAttributes</code> into two groups.  One group, the
656      * 'primary' group, is considered fundamental to the selection and
657      * metric behavior of a font.  These attributes are
658      * <code>FAMILY</code>, <code>WEIGHT</code>, <code>WIDTH</code>,
659      * <code>POSTURE</code>, <code>SIZE</code>,
660      * <code>TRANSFORM</code>, <code>SUPERSCRIPT</code>, and
661      * <code>TRACKING</code>. The other group, the 'secondary' group,
662      * consists of all other defined attributes, with the exception of
663      * <code>FONT</code> itself.
664      *
665      * <p>To generate the new <code>Map</code>, first the
666      * <code>Font</code> is obtained from the <code>FONT</code>
667      * attribute, and <em>all</em> of its attributes extracted into a
668      * new <code>Map</code>.  Then only the <em>secondary</em>
669      * attributes from the original <code>Map</code> are added to
670      * those in the new <code>Map</code>.  Thus the values of primary
671      * attributes come solely from the <code>Font</code>, and the
672      * values of secondary attributes originate with the
673      * <code>Font</code> but can be overridden by other values in the
674      * <code>Map</code>.
675      */
676     // Android-removed
677     // Values are instances of {@link java.awt.Font}.
678     //
679     // <p><em>Note:</em><code>Font's</code> <code>Map</code>-based
680     // constructor and <code>deriveFont</code> methods do not process
681     // the <code>FONT</code> attribute, as these are used to create
682     // new <code>Font</code> objects.  Instead, {@link
683     // java.awt.Font#getFont(Map) Font.getFont(Map)} should be used to
684     // handle the <code>FONT</code> attribute.
685     //
686     // @see java.awt.Font
687     public static final TextAttribute FONT =
688         new TextAttribute("font");
689 
690     /**
691      * Attribute key for a user-defined glyph to display in lieu
692      * of the font's standard glyph for a character.  Values are
693      * intances of GraphicAttribute.  The default value is null,
694      * indicating that the standard glyphs provided by the font
695      * should be used.
696      *
697      * <p>This attribute is used to reserve space for a graphic or
698      * other component embedded in a line of text.  It is required for
699      * correct positioning of 'inline' components within a line when
700      * bidirectional reordering (see {@link java.text.Bidi}) is
701      * performed.  Each character (Unicode code point) will be
702      * rendered using the provided GraphicAttribute. Typically, the
703      * characters to which this attribute is applied should be
704      * <code>&#92;uFFFC</code>.
705      *
706      * <p>The GraphicAttribute determines the logical and visual
707      * bounds of the text; the actual Font values are ignored.
708      *
709      * @see GraphicAttribute
710      */
711     public static final TextAttribute CHAR_REPLACEMENT =
712         new TextAttribute("char_replacement");
713 
714     //
715     // Adornments added to text.
716     //
717 
718     /**
719      * Attribute key for the paint used to render the text.  Values are
720      * instances of <b><code>Paint</code></b>.  The default value is
721      * null, indicating that the <code>Paint</code> set on the
722      * <code>Graphics2D</code> at the time of rendering is used.
723      *
724      * <p>Glyphs will be rendered using this
725      * <code>Paint</code> regardless of the <code>Paint</code> value
726      * set on the <code>Graphics</code> (but see {@link #SWAP_COLORS}).
727      *
728      * @see java.awt.Paint
729      * @see #SWAP_COLORS
730      */
731     public static final TextAttribute FOREGROUND =
732         new TextAttribute("foreground");
733 
734     /**
735      * Attribute key for the paint used to render the background of
736      * the text.  Values are instances of <b><code>Paint</code></b>.
737      * The default value is null, indicating that the background
738      * should not be rendered.
739      *
740      * <p>The logical bounds of the text will be filled using this
741      * <code>Paint</code>, and then the text will be rendered on top
742      * of it (but see {@link #SWAP_COLORS}).
743      *
744      * <p>The visual bounds of the text is extended to include the
745      * logical bounds, if necessary.  The outline is not affected.
746      *
747      * @see java.awt.Paint
748      * @see #SWAP_COLORS
749      */
750     public static final TextAttribute BACKGROUND =
751         new TextAttribute("background");
752 
753     /**
754      * Attribute key for underline.  Values are instances of
755      * <b><code>Integer</code></b>.  The default value is -1, which
756      * means no underline.
757      *
758      * <p>The constant value {@link #UNDERLINE_ON} is provided.
759      *
760      * <p>The underline affects both the visual bounds and the outline
761      * of the text.
762      */
763     public static final TextAttribute UNDERLINE =
764         new TextAttribute("underline");
765 
766     /**
767      * Standard underline.
768      *
769      * @see #UNDERLINE
770      */
771     public static final Integer UNDERLINE_ON =
772         Integer.valueOf(0);
773 
774     /**
775      * Attribute key for strikethrough.  Values are instances of
776      * <b><code>Boolean</code></b>.  The default value is
777      * <code>false</code>, which means no strikethrough.
778      *
779      * <p>The constant value {@link #STRIKETHROUGH_ON} is provided.
780      *
781      * <p>The strikethrough affects both the visual bounds and the
782      * outline of the text.
783      */
784     public static final TextAttribute STRIKETHROUGH =
785         new TextAttribute("strikethrough");
786 
787     /**
788      * A single strikethrough.
789      *
790      * @see #STRIKETHROUGH
791      */
792     public static final Boolean STRIKETHROUGH_ON =
793         Boolean.TRUE;
794 
795     //
796     // Attributes use to control layout of text on a line.
797     //
798 
799     /**
800      * Attribute key for the run direction of the line.  Values are
801      * instances of <b><code>Boolean</code></b>.  The default value is
802      * null, which indicates that the standard Bidi algorithm for
803      * determining run direction should be used with the value {@link
804      * java.text.Bidi#DIRECTION_DEFAULT_LEFT_TO_RIGHT}.
805      *
806      * <p>The constants {@link #RUN_DIRECTION_RTL} and {@link
807      * #RUN_DIRECTION_LTR} are provided.
808      *
809      * <p>This determines the value passed to the {@link
810      * java.text.Bidi} constructor to select the primary direction of
811      * the text in the paragraph.
812      *
813      * <p><em>Note:</em> This attribute should have the same value for
814      * all the text in a paragraph, otherwise the behavior is
815      * undetermined.
816      *
817      * @see java.text.Bidi
818      */
819     public static final TextAttribute RUN_DIRECTION =
820         new TextAttribute("run_direction");
821 
822     /**
823      * Left-to-right run direction.
824      * @see #RUN_DIRECTION
825      */
826     public static final Boolean RUN_DIRECTION_LTR =
827         Boolean.FALSE;
828 
829     /**
830      * Right-to-left run direction.
831      * @see #RUN_DIRECTION
832      */
833     public static final Boolean RUN_DIRECTION_RTL =
834         Boolean.TRUE;
835 
836     /**
837      * Attribute key for the embedding level of the text.  Values are
838      * instances of <b><code>Integer</code></b>.  The default value is
839      * <code>null</code>, indicating that the the Bidirectional
840      * algorithm should run without explicit embeddings.
841      *
842      * <p>Positive values 1 through 61 are <em>embedding</em> levels,
843      * negative values -1 through -61 are <em>override</em> levels.
844      * The value 0 means that the base line direction is used.  These
845      * levels are passed in the embedding levels array to the {@link
846      * java.text.Bidi} constructor.
847      *
848      * <p><em>Note:</em> When this attribute is present anywhere in
849      * a paragraph, then any Unicode bidi control characters (RLO,
850      * LRO, RLE, LRE, and PDF) in the paragraph are
851      * disregarded, and runs of text where this attribute is not
852      * present are treated as though it were present and had the value
853      * 0.
854      *
855      * @see java.text.Bidi
856      */
857     public static final TextAttribute BIDI_EMBEDDING =
858         new TextAttribute("bidi_embedding");
859 
860     /**
861      * Attribute key for the justification of a paragraph.  Values are
862      * instances of <b><code>Number</code></b>.  The default value is
863      * 1, indicating that justification should use the full width
864      * provided.  Values are pinned to the range [0..1].
865      *
866      * <p>The constants {@link #JUSTIFICATION_FULL} and {@link
867      * #JUSTIFICATION_NONE} are provided.
868      *
869      * <p>Specifies the fraction of the extra space to use when
870      * justification is requested on a <code>TextLayout</code>. For
871      * example, if the line is 50 points wide and it is requested to
872      * justify to 70 points, a value of 0.75 will pad to use
873      * three-quarters of the remaining space, or 15 points, so that
874      * the resulting line will be 65 points in length.
875      *
876      * <p><em>Note:</em> This should have the same value for all the
877      * text in a paragraph, otherwise the behavior is undetermined.
878      *
879      * @see TextLayout#getJustifiedLayout
880      */
881     public static final TextAttribute JUSTIFICATION =
882         new TextAttribute("justification");
883 
884     /**
885      * Justify the line to the full requested width.  This is the
886      * default value for <code>JUSTIFICATION</code>.
887      * @see #JUSTIFICATION
888      */
889     public static final Float JUSTIFICATION_FULL =
890         Float.valueOf(1.0f);
891 
892     /**
893      * Do not allow the line to be justified.
894      * @see #JUSTIFICATION
895      */
896     public static final Float JUSTIFICATION_NONE =
897         Float.valueOf(0.0f);
898 
899     //
900     // For use by input method.
901     //
902 
903     /**
904      * Attribute key for input method highlight styles.
905      *
906      * The default value is <code>null</code>,
907      * which means that input method styles should not be applied
908      * before rendering.
909      *
910      * @see java.text.Annotation
911      */
912     // Android-removed
913     //
914     // <p>Values are instances of {@link
915     // java.awt.im.InputMethodHighlight} or {@link
916     // java.text.Annotation}.
917     //
918     // <p>If adjacent runs of text with the same
919     // <code>InputMethodHighlight</code> need to be rendered
920     // separately, the <code>InputMethodHighlights</code> should be
921     // wrapped in <code>Annotation</code> instances.
922     //
923     // <p>Input method highlights are used while text is being
924     // composed by an input method. Text editing components should
925     // retain them even if they generally only deal with unstyled
926     // text, and make them available to the drawing routines.
927     //
928     // @see java.awt.Font
929     // @see java.awt.im.InputMethodHighlight
930     public static final TextAttribute INPUT_METHOD_HIGHLIGHT =
931         new TextAttribute("input method highlight");
932 
933     /**
934      * Attribute key for input method underlines.  Values
935      * are instances of <b><code>Integer</code></b>.  The default
936      * value is <code>-1</code>, which means no underline.
937      *
938      * <p>Several constant values are provided, see {@link
939      * #UNDERLINE_LOW_ONE_PIXEL}, {@link #UNDERLINE_LOW_TWO_PIXEL},
940      * {@link #UNDERLINE_LOW_DOTTED}, {@link #UNDERLINE_LOW_GRAY}, and
941      * {@link #UNDERLINE_LOW_DASHED}.
942      *
943      * <p>This may be used in conjunction with {@link #UNDERLINE} if
944      * desired.  The primary purpose is for use by input methods.
945      * Other use of these underlines for simple ornamentation might
946      * confuse users.
947      *
948      * <p>The input method underline affects both the visual bounds and
949      * the outline of the text.
950      *
951      * @since 1.3
952      */
953     public static final TextAttribute INPUT_METHOD_UNDERLINE =
954         new TextAttribute("input method underline");
955 
956     /**
957      * Single pixel solid low underline.
958      * @see #INPUT_METHOD_UNDERLINE
959      * @since 1.3
960      */
961     public static final Integer UNDERLINE_LOW_ONE_PIXEL =
962         Integer.valueOf(1);
963 
964     /**
965      * Double pixel solid low underline.
966      * @see #INPUT_METHOD_UNDERLINE
967      * @since 1.3
968      */
969     public static final Integer UNDERLINE_LOW_TWO_PIXEL =
970         Integer.valueOf(2);
971 
972     /**
973      * Single pixel dotted low underline.
974      * @see #INPUT_METHOD_UNDERLINE
975      * @since 1.3
976      */
977     public static final Integer UNDERLINE_LOW_DOTTED =
978         Integer.valueOf(3);
979 
980     /**
981      * Double pixel gray low underline.
982      * @see #INPUT_METHOD_UNDERLINE
983      * @since 1.3
984      */
985     public static final Integer UNDERLINE_LOW_GRAY =
986         Integer.valueOf(4);
987 
988     /**
989      * Single pixel dashed low underline.
990      * @see #INPUT_METHOD_UNDERLINE
991      * @since 1.3
992      */
993     public static final Integer UNDERLINE_LOW_DASHED =
994         Integer.valueOf(5);
995 
996     /**
997      * Attribute key for swapping foreground and background
998      * <code>Paints</code>.  Values are instances of
999      * <b><code>Boolean</code></b>.  The default value is
1000      * <code>false</code>, which means do not swap colors.
1001      *
1002      * <p>The constant value {@link #SWAP_COLORS_ON} is defined.
1003      *
1004      * <p>If the {@link #FOREGROUND} attribute is set, its
1005      * <code>Paint</code> will be used as the background, otherwise
1006      * the <code>Paint</code> currently on the <code>Graphics</code>
1007      * will be used.  If the {@link #BACKGROUND} attribute is set, its
1008      * <code>Paint</code> will be used as the foreground, otherwise
1009      * the system will find a contrasting color to the
1010      * (resolved) background so that the text will be visible.
1011      *
1012      * @see #FOREGROUND
1013      * @see #BACKGROUND
1014      */
1015     public static final TextAttribute SWAP_COLORS =
1016         new TextAttribute("swap_colors");
1017 
1018     /**
1019      * Swap foreground and background.
1020      * @see #SWAP_COLORS
1021      * @since 1.3
1022      */
1023     public static final Boolean SWAP_COLORS_ON =
1024         Boolean.TRUE;
1025 
1026     /**
1027      * Attribute key for converting ASCII decimal digits to other
1028      * decimal ranges.  Values are instances of {@link NumericShaper}.
1029      * The default is <code>null</code>, which means do not perform
1030      * numeric shaping.
1031      *
1032      * <p>When a numeric shaper is defined, the text is first
1033      * processed by the shaper before any other analysis of the text
1034      * is performed.
1035      *
1036      * <p><em>Note:</em> This should have the same value for all the
1037      * text in the paragraph, otherwise the behavior is undetermined.
1038      *
1039      * @see NumericShaper
1040      * @since 1.4
1041      */
1042     public static final TextAttribute NUMERIC_SHAPING =
1043         new TextAttribute("numeric_shaping");
1044 
1045     /**
1046      * Attribute key to request kerning. Values are instances of
1047      * <b><code>Integer</code></b>.  The default value is
1048      * <code>0</code>, which does not request kerning.
1049      *
1050      * <p>The constant value {@link #KERNING_ON} is provided.
1051      *
1052      * <p>The default advances of single characters are not
1053      * appropriate for some character sequences, for example "To" or
1054      * "AWAY".  Without kerning the adjacent characters appear to be
1055      * separated by too much space.  Kerning causes selected sequences
1056      * of characters to be spaced differently for a more pleasing
1057      * visual appearance.
1058      *
1059      * @since 1.6
1060      */
1061     public static final TextAttribute KERNING =
1062         new TextAttribute("kerning");
1063 
1064     /**
1065      * Request standard kerning.
1066      * @see #KERNING
1067      * @since 1.6
1068      */
1069     public static final Integer KERNING_ON =
1070         Integer.valueOf(1);
1071 
1072 
1073     /**
1074      * Attribute key for enabling optional ligatures. Values are
1075      * instances of <b><code>Integer</code></b>.  The default value is
1076      * <code>0</code>, which means do not use optional ligatures.
1077      *
1078      * <p>The constant value {@link #LIGATURES_ON} is defined.
1079      *
1080      * <p>Ligatures required by the writing system are always enabled.
1081      *
1082      * @since 1.6
1083      */
1084     public static final TextAttribute LIGATURES =
1085         new TextAttribute("ligatures");
1086 
1087     /**
1088      * Request standard optional ligatures.
1089      * @see #LIGATURES
1090      * @since 1.6
1091      */
1092     public static final Integer LIGATURES_ON =
1093         Integer.valueOf(1);
1094 
1095     /**
1096      * Attribute key to control tracking.  Values are instances of
1097      * <b><code>Number</code></b>.  The default value is
1098      * <code>0</code>, which means no additional tracking.
1099      *
1100      * <p>The constant values {@link #TRACKING_TIGHT} and {@link
1101      * #TRACKING_LOOSE} are provided.
1102      *
1103      * <p>The tracking value is multiplied by the font point size and
1104      * passed through the font transform to determine an additional
1105      * amount to add to the advance of each glyph cluster.  Positive
1106      * tracking values will inhibit formation of optional ligatures.
1107      * Tracking values are typically between <code>-0.1</code> and
1108      * <code>0.3</code>; values outside this range are generally not
1109      * desireable.
1110      *
1111      * @since 1.6
1112      */
1113     public static final TextAttribute TRACKING =
1114         new TextAttribute("tracking");
1115 
1116     /**
1117      * Perform tight tracking.
1118      * @see #TRACKING
1119      * @since 1.6
1120      */
1121     public static final Float TRACKING_TIGHT =
1122         Float.valueOf(-.04f);
1123 
1124     /**
1125      * Perform loose tracking.
1126      * @see #TRACKING
1127      * @since 1.6
1128      */
1129     public static final Float TRACKING_LOOSE =
1130         Float.valueOf(.04f);
1131 }
1132