summaryrefslogtreecommitdiff
path: root/libjava/classpath/java/awt/font/TextAttribute.java
blob: bfade21bb7358321ee200cc2820b87a2fbcb1996 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/* TextAttribute.java --
   Copyright (C) 2003, 2004, 2005  Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */


package java.awt.font;

import java.io.InvalidObjectException;
import java.text.AttributedCharacterIterator;

/**
 * Attributes (and associated values) that can be used to define an
 * {@link java.text.AttributedString}.
 */
public final class TextAttribute extends AttributedCharacterIterator.Attribute
{
  private static final long serialVersionUID = 7744112784117861702L;

  /** A key for the background paint attribute. */
  public static final TextAttribute BACKGROUND =
    new TextAttribute("background");

  /** A key for the BIDI_EMBEDDING attribute. */
  public static final TextAttribute BIDI_EMBEDDING =
    new TextAttribute("bidi_embedding");

  /** A key for the CHAR_REPLACEMENT attribute. */
  public static final TextAttribute CHAR_REPLACEMENT =
    new TextAttribute("char_replacement");

  /** A key for the FAMILY attribute. */
  public static final TextAttribute FAMILY = new TextAttribute("family");

  /** A key for the font attribute. */
  public static final TextAttribute FONT = new TextAttribute("font");

  /** A key for the foreground paint attribute. */
  public static final TextAttribute FOREGROUND =
    new TextAttribute("foreground");

  /** A key for the INPUT_METHOD_HIGHLIGHT attribute. */
  public static final TextAttribute INPUT_METHOD_HIGHLIGHT =
    new TextAttribute("input method highlight");

  /** A key for the INPUT_METHOD_UNDERLINE attribute. */
  public static final TextAttribute INPUT_METHOD_UNDERLINE =
    new TextAttribute("input method underline");

  /** A key for the text justification attribute. */
  public static final TextAttribute JUSTIFICATION =
    new TextAttribute("justification");

  /**
   * A value that can be used with the {@link #JUSTIFICATION} attribute to
   * indicate full justification of the text.
   */
  public static final Float JUSTIFICATION_FULL = new Float(1.0);

  /**
   * A value that can be used with the {@link #JUSTIFICATION} attribute to
   * indicate no justification of the text.
   */
  public static final Float JUSTIFICATION_NONE = new Float(0.0);

  /** A key for the NUMERIC_SHAPING attribute. */
  public static final TextAttribute NUMERIC_SHAPING =
    new TextAttribute("numeric_shaping");

  /** A key for the POSTURE attribute. */
  public static final TextAttribute POSTURE = new TextAttribute("posture");

  /** A value that can be used with the {@link #POSTURE} attribute. */
  public static final Float POSTURE_OBLIQUE = new Float(0.2);

  /** A value that can be used with the {@link #POSTURE} attribute. */
  public static final Float POSTURE_REGULAR = new Float(0.0);

  /** A key for the RUN_DIRECTION attribute. */
  public static final TextAttribute RUN_DIRECTION =
    new TextAttribute("run_direction");

  /** A value that can be used with the {@link #RUN_DIRECTION} attribute. */
  public static final Boolean RUN_DIRECTION_LTR = Boolean.FALSE;

  /** A value that can be used with the {@link #RUN_DIRECTION} attribute. */
  public static final Boolean RUN_DIRECTION_RTL = Boolean.TRUE;

  /** A key for the text size attribute. */
  public static final TextAttribute SIZE = new TextAttribute("size");

  /** A key for the STRIKETHROUGH attribute. */
  public static final TextAttribute STRIKETHROUGH =
    new TextAttribute("strikethrough");

  /** A value that can be used with the {@link #STRIKETHROUGH} attribute. */
  public static final Boolean STRIKETHROUGH_ON = Boolean.TRUE;

  /** A key for the SUPERSCRIPT attribute. */
  public static final TextAttribute SUPERSCRIPT =
    new TextAttribute("superscript");

  /** A value that can be used with the {@link #SUPERSCRIPT} attribute. */
  public static final Integer SUPERSCRIPT_SUB = new Integer(-1);

  /** A value that can be used with the {@link #SUPERSCRIPT} attribute. */
  public static final Integer SUPERSCRIPT_SUPER = new Integer(1);

  /** A key for the SWAP_COLORS attribute. */
  public static final TextAttribute SWAP_COLORS =
    new TextAttribute("swap_colors");

  /** A value that can be used with the {@link #SWAP_COLORS} attribute. */
  public static final Boolean SWAP_COLORS_ON = Boolean.TRUE;

  /** A key for the TRANFORM attribute. */
  public static final TextAttribute TRANSFORM = new TextAttribute("transform");

  /** A key for the UNDERLINE attribute. */
  public static final TextAttribute UNDERLINE = new TextAttribute("underline");

  /** A value that can be used with the {@link #UNDERLINE} attribute. */
  public static final Integer UNDERLINE_LOW_DASHED = new Integer(5);

  /** A value that can be used with the {@link #UNDERLINE} attribute. */
  public static final Integer UNDERLINE_LOW_DOTTED = new Integer(3);

  /** A value that can be used with the {@link #UNDERLINE} attribute. */
  public static final Integer UNDERLINE_LOW_GRAY = new Integer(4);

  /** A value that can be used with the {@link #UNDERLINE} attribute. */
  public static final Integer UNDERLINE_LOW_ONE_PIXEL = new Integer(1);

  /** A value that can be used with the {@link #UNDERLINE} attribute. */
  public static final Integer UNDERLINE_LOW_TWO_PIXEL = new Integer(2);

  /** A value that can be used with the {@link #UNDERLINE} attribute. */
  public static final Integer UNDERLINE_ON = new Integer(0);

  /** A key for the WEIGHT attribute. */
  public static final TextAttribute WEIGHT = new TextAttribute("weight");

  /** A value that can be used with the {@link #WEIGHT} attribute. */
  public static final Float WEIGHT_BOLD = new Float(2.0);

  /** A value that can be used with the {@link #WEIGHT} attribute. */
  public static final Float WEIGHT_DEMIBOLD = new Float(1.75);

  /** A value that can be used with the {@link #WEIGHT} attribute. */
  public static final Float WEIGHT_DEMILIGHT = new Float(0.875);

  /** A value that can be used with the {@link #WEIGHT} attribute. */
  public static final Float WEIGHT_EXTRA_LIGHT = new Float(0.5);

  /** A value that can be used with the {@link #WEIGHT} attribute. */
  public static final Float WEIGHT_EXTRABOLD = new Float(2.5);

  /** A value that can be used with the {@link #WEIGHT} attribute. */
  public static final Float WEIGHT_HEAVY = new Float(2.25);

  /** A value that can be used with the {@link #WEIGHT} attribute. */
  public static final Float WEIGHT_LIGHT = new Float(0.75);

  /** A value that can be used with the {@link #WEIGHT} attribute. */
  public static final Float WEIGHT_MEDIUM = new Float(1.5);

  /** A value that can be used with the {@link #WEIGHT} attribute. */
  public static final Float WEIGHT_REGULAR = new Float(1.0);

  /** A value that can be used with the {@link #WEIGHT} attribute. */
  public static final Float WEIGHT_SEMIBOLD = new Float(1.25);

  /** A value that can be used with the {@link #WEIGHT} attribute. */
  public static final Float WEIGHT_ULTRABOLD = new Float(2.75);

  /** A key for the WIDTH attribute. */
  public static final TextAttribute WIDTH = new TextAttribute("width");

  /** A value that can be used with the {@link #WIDTH} attribute. */
  public static final Float WIDTH_CONDENSED = new Float(0.75);

  /** A value that can be used with the {@link #WIDTH} attribute. */
  public static final Float WIDTH_EXTENDED = new Float(1.5);

  /** A value that can be used with the {@link #WIDTH} attribute. */
  public static final Float WIDTH_REGULAR = new Float(1.0);

  /** A value that can be used with the {@link #WIDTH} attribute. */
  public static final Float WIDTH_SEMI_CONDENSED = new Float(0.875);

  /** A value that can be used with the {@link #WIDTH} attribute. */
  public static final Float WIDTH_SEMI_EXTENDED = new Float(1.25);

  /**
   * Creates a new attribute.
   *
   * @param name  the name.
   */
  protected TextAttribute(String name)
  {
    super(name);
  }

  /**
   * After deserialization, this method ensures that only one instance of
   * each attribute is used.
   *
   * @return The (single) attribute instance.
   *
   * @throws InvalidObjectException if the attribute is not recognised.
   */
  protected Object readResolve()
    throws InvalidObjectException
  {
    if (this.getName().equals("background"))
      return BACKGROUND;

    if (this.getName().equals("bidi_embedding"))
      return BIDI_EMBEDDING;

    if (this.getName().equals("char_replacement"))
      return CHAR_REPLACEMENT;

    if (this.getName().equals("family"))
      return FAMILY;

    if (this.getName().equals("font"))
      return FONT;

    if (this.getName().equals("foreground"))
      return FOREGROUND;

    if (this.getName().equals("input method highlight"))
      return INPUT_METHOD_HIGHLIGHT;

    if (this.getName().equals("input method underline"))
      return INPUT_METHOD_UNDERLINE;

    if (this.getName().equals("justification"))
      return JUSTIFICATION;

    if (this.getName().equals("numeric_shaping"))
      return NUMERIC_SHAPING;

    if (this.getName().equals("posture"))
      return POSTURE;

    if (this.getName().equals("run_direction"))
      return RUN_DIRECTION;

    if (this.getName().equals("size"))
      return SIZE;

    if (this.getName().equals("strikethrough"))
      return STRIKETHROUGH;

    if (this.getName().equals("superscript"))
      return SUPERSCRIPT;

    if (this.getName().equals("swap_colors"))
      return SWAP_COLORS;

    if (this.getName().equals("transform"))
      return TRANSFORM;

    if (this.getName().equals("underline"))
      return UNDERLINE;

    if (this.getName().equals("weight"))
      return WEIGHT;

    if (this.getName().equals("width"))
      return WIDTH;

    throw new InvalidObjectException("Can't resolve Attribute: " + getName());
  }
}