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