1. /*
  2. * @(#)TextAttribute.java 1.35 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. /*
  11. * (C) Copyright Taligent, Inc. 1996 - 1997, All Rights Reserved
  12. * (C) Copyright IBM Corp. 1996 - 1998, All Rights Reserved
  13. *
  14. * The original version of this source code and documentation is
  15. * copyrighted and owned by Taligent, Inc., a wholly-owned subsidiary
  16. * of IBM. These materials are provided under terms of a License
  17. * Agreement between Taligent and Sun. This technology is protected
  18. * by multiple US and International patents.
  19. *
  20. * This notice and attribution to Taligent may not be removed.
  21. * Taligent is a registered trademark of Taligent, Inc.
  22. *
  23. */
  24. package java.awt.font;
  25. import java.io.InvalidObjectException;
  26. import java.text.AttributedCharacterIterator.Attribute;
  27. import java.util.Map;
  28. import java.util.HashMap;
  29. /**
  30. * The <code>TextAttribute</code> class defines attribute keys and
  31. * attribute values used for text rendering.
  32. * <p>
  33. * <code>TextAttribute</code> instances are used as attribute keys to
  34. * identify attributes in
  35. * {@link java.text.AttributedCharacterIterator AttributedCharacterIterator},
  36. * {@link java.awt.Font Font}, and other classes handling text
  37. * attributes. Other constants defined in this class are used
  38. * as attribute values.
  39. * <p>
  40. * For each text attribute, the documentation describes:
  41. * <UL>
  42. * <LI>the type of their values,
  43. * <LI>the valid values if there are limitations
  44. * <LI>relevant constants
  45. * <LI>the default effect if the attribute is absent (or has a
  46. * <code>null</code> value).
  47. * <LI>a description of the effect.
  48. * <LI>the fallback behavior if the exact attribute requested is not
  49. * available.
  50. * </UL>
  51. * <p>
  52. * <H4>Types of Values</H4>
  53. * <UL>
  54. * <LI>The values of attributes must always be immutable.
  55. * <LI>Where a list of limitations is given, any value outside of that
  56. * set is reserved for future use, and ignored at present.
  57. * <LI>If the value is <code>null</code> or not of the proper type
  58. * then it has the default effect. The effect of a particular value
  59. * can be interpolated, especially in the case of multiple master
  60. * fonts. This interpolation is done based on the nearest defined
  61. * constants above and below the request:<BR>
  62. * <BLOCKQUOTE><TT>
  63. * interpolation = (request - below)/(above - below);
  64. * </BLOCKQUOTE></TT>
  65. * </UL>
  66. * <p>
  67. * <H4>Interpolation</H4>
  68. * <UL>
  69. * <LI>Fonts should interpolate values in certain circumstances. For example,
  70. * when the WEIGHT value is 2.13. If the nearest surrounding values
  71. * in the font are WEIGHT_BOLD = 2.0 and WEIGHT_HEAVY = 2.25 then font would
  72. * then interpret the WEIGHT request as being 52% of the way between what
  73. * it considers BOLD and what it considers HEAVY. If the nearest surrounding
  74. * values are WEIGHT_SEMIBOLD = 1.25 and WEIGHT_ULTRABOLD = 2.75 then the
  75. * WEIGHT request is interpreted as being 58.67% of the way between SEMIBOLD
  76. * and ULTRABOLD.
  77. * <LI>Where a font does not have enough capability to handle a given
  78. * request, such as superscript, then it should simulate it to the best of
  79. * its ability. To determine if simulation is being performed, the client
  80. * should query the font to see what actual attributes were used.
  81. * </UL>
  82. *
  83. * @see java.text.AttributedCharacterIterator
  84. * @see java.awt.Font
  85. */
  86. public final class TextAttribute extends Attribute {
  87. // table of all instances in this class, used by readResolve
  88. private static final Map instanceMap = new HashMap(29);
  89. /**
  90. * Constructs a <code>TextAttribute</code> with the specified name.
  91. * @param name the attribute name to assign to this
  92. * <code>TextAttribute</code>
  93. */
  94. protected TextAttribute(String name) {
  95. super(name);
  96. if (this.getClass() == TextAttribute.class) {
  97. instanceMap.put(name, this);
  98. }
  99. }
  100. /**
  101. * Resolves instances being deserialized to the predefined constants.
  102. */
  103. protected Object readResolve() throws InvalidObjectException {
  104. if (this.getClass() != TextAttribute.class) {
  105. throw new InvalidObjectException("subclass didn't correctly implement readResolve");
  106. }
  107. TextAttribute instance = (TextAttribute) instanceMap.get(getName());
  108. if (instance != null) {
  109. return instance;
  110. } else {
  111. throw new InvalidObjectException("unknown attribute name");
  112. }
  113. }
  114. // Serialization compatibility with Java 2 platform v1.2.
  115. // 1.2 will throw an InvalidObjectException if ever asked to deserialize INPUT_METHOD_UNDERLINE.
  116. // This shouldn't happen in real life.
  117. static final long serialVersionUID = 7744112784117861702L;
  118. //
  119. // For use with Font.
  120. //
  121. /**
  122. * Attribute key for the unlocalized font family name.
  123. *
  124. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  125. * <TR>
  126. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  127. * <TD VALIGN="TOP">FAMILY</TD></TR>
  128. * <TR>
  129. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  130. * <TD VALIGN="TOP">String</TD></TR>
  131. * <TR>
  132. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
  133. * <TD VALIGN="TOP">"Serif", "SansSerif"</TD></TR>
  134. * <TR>
  135. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  136. * <TD VALIGN="TOP">Host default;</TD></TR>
  137. * <TR>
  138. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  139. * <TD VALIGN="TOP">The name of the font family. If the family name is not
  140. * found, the default font is used. The name should not be the full
  141. * font name or specify other attributes (such as the name
  142. * "Helvetica Bold"). Such names might result in the default
  143. * font if the name does not match a known
  144. * family name.</TD></TR>
  145. * </TABLE>
  146. */
  147. public static final TextAttribute FAMILY = new TextAttribute("family");
  148. /**
  149. * Attribute key for the weight of a font.
  150. *
  151. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  152. * <TR>
  153. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  154. * <TD VALIGN="TOP">WEIGHT</TD></TR>
  155. * <TR>
  156. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  157. * <TD VALIGN="TOP">Float</TD></TR>
  158. * <TR>
  159. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
  160. * <TD VALIGN="TOP">WEIGHT_ULTRA_LIGHT = 0.25,<BR>
  161. * WEIGHT_EXTRA_LIGHT = 0.5,<BR>
  162. * WEIGHT_LIGHT = 0.75,<BR>
  163. * WEIGHT_DEMILIGHT = 0.875,<BR>
  164. * WEIGHT_REGULAR = 1.0,<BR>
  165. * WEIGHT_SEMIBOLD = 1.25,<BR>
  166. * WEIGHT_MEDIUM = 1.5,<BR>
  167. * WEIGHT_DEMIBOLD = 1.75,<BR>
  168. * WEIGHT_BOLD = 2.0,<BR>
  169. * WEIGHT_HEAVY = 2.25,<BR>
  170. * WEIGHT_EXTRABOLD = 2.5,<BR>
  171. * WEIGHT_ULTRABOLD = 2.75</TD></TR>
  172. * <TR>
  173. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  174. * <TD VALIGN="TOP">WEIGHT_REGULAR</TD></TR>
  175. * <TR>
  176. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  177. * <TD VALIGN="TOP">The value is roughly the ratio of the stem width to
  178. * that of the regular weight. If the font has a different value for
  179. * specific constants, then the value is interpolated as described in
  180. * the class description.</TD></TR>
  181. * <TR>
  182. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Fallback</TH>
  183. * <TD VALIGN="TOP">Currently none. However, in the future, shape
  184. * manipulations might be<BR> available to simulate weight variations
  185. * for fonts that don't have them.</TD></TR>
  186. * </TABLE>
  187. * <BR>
  188. */
  189. public static final TextAttribute WEIGHT = new TextAttribute("weight");
  190. /**
  191. * The lightest predefined weight.
  192. * @see #WEIGHT
  193. */
  194. public static final Float WEIGHT_EXTRA_LIGHT = new Float(0.5f);
  195. /**
  196. * The standard light weight.
  197. * @see #WEIGHT
  198. */
  199. public static final Float WEIGHT_LIGHT = new Float(0.75f);
  200. /**
  201. * An intermediate weight between LIGHT and STANDARD.
  202. * @see #WEIGHT
  203. */
  204. public static final Float WEIGHT_DEMILIGHT = new Float(0.875f);
  205. /**
  206. * The standard weight. This weight is used if WEIGHT is unspecified.
  207. * @see #WEIGHT
  208. */
  209. public static final Float WEIGHT_REGULAR = new Float(1.0f);
  210. /**
  211. * A moderately heavier weight than REGULAR.
  212. * @see #WEIGHT
  213. */
  214. public static final Float WEIGHT_SEMIBOLD = new Float(1.25f);
  215. /**
  216. * An intermediate weight between the REGULAR and BOLD weights.
  217. * @see #WEIGHT
  218. */
  219. public static final Float WEIGHT_MEDIUM = new Float(1.5f);
  220. /**
  221. * A moderately lighter weight than BOLD.
  222. * @see #WEIGHT
  223. */
  224. public static final Float WEIGHT_DEMIBOLD = new Float(1.75f);
  225. /**
  226. * The standard bold weight.
  227. * @see #WEIGHT
  228. */
  229. public static final Float WEIGHT_BOLD = new Float(2.0f);
  230. /**
  231. * A moderately heavier weight than BOLD.
  232. * @see #WEIGHT
  233. */
  234. public static final Float WEIGHT_HEAVY = new Float(2.25f);
  235. /**
  236. * An extra heavy weight.
  237. * @see #WEIGHT
  238. */
  239. public static final Float WEIGHT_EXTRABOLD = new Float(2.5f);
  240. /**
  241. * The heaviest predefined weight.
  242. * @see #WEIGHT
  243. */
  244. public static final Float WEIGHT_ULTRABOLD = new Float(2.75f);
  245. /**
  246. * Attribute key for the width of a font.
  247. *
  248. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  249. * <TR>
  250. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  251. * <TD VALIGN="TOP">WIDTH</TD></TR>
  252. * <TR>
  253. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  254. * <TD VALIGN="TOP">Float</TD></TR>
  255. * <TR>
  256. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
  257. * <TD VALIGN="TOP">WIDTH_CONDENSED = 0.75,<BR>
  258. * WIDTH_SEMI_CONDENSED = 0.875,<BR>
  259. * WIDTH_REGULAR = 1.0,<BR>
  260. * WIDTH_SEMI_EXTENDED = 1.25,<BR>
  261. * WIDTH_EXTENDED = 1.5</TD></TR>
  262. * <TR>
  263. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  264. * <TD VALIGN="TOP">WIDTH_REGULAR</TD></TR>
  265. * <TR>
  266. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  267. * <TD VALIGN="TOP">The value is roughly the ratio of the advance width
  268. * to that of the regular width. If the font has a different value for
  269. * specific constants, then the value is interpolated as described in
  270. * the class description.</TD></TR>
  271. * <TR>
  272. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Fallback</TH>
  273. * <TD VALIGN="TOP">If a Narrow font is available and matches, use that.
  274. * Otherwise scale with a transform based on the value.</TD></TR>
  275. * </TABLE>
  276. */
  277. public static final TextAttribute WIDTH = new TextAttribute("width");
  278. /**
  279. * The most condensed predefined width.
  280. * @see #WIDTH
  281. */
  282. public static final Float WIDTH_CONDENSED = new Float(0.75f);
  283. /**
  284. * A moderately condensed width.
  285. * @see #WIDTH
  286. */
  287. public static final Float WIDTH_SEMI_CONDENSED = new Float(0.875f);
  288. /**
  289. * The standard width. This width is used if WIDTH is unspecified.
  290. * @see #WIDTH
  291. */
  292. public static final Float WIDTH_REGULAR = new Float(1.0f);
  293. /**
  294. * A moderately extended width.
  295. * @see #WIDTH
  296. */
  297. public static final Float WIDTH_SEMI_EXTENDED = new Float(1.25f);
  298. /**
  299. * The most extended predefined width.
  300. * @see #WIDTH
  301. */
  302. public static final Float WIDTH_EXTENDED = new Float(1.5f);
  303. /**
  304. * Attribute key for the posture of a font.
  305. *
  306. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  307. * <TR>
  308. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  309. * <TD VALIGN="TOP">POSTURE</TD></TR>
  310. * <TR>
  311. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  312. * <TD VALIGN="TOP">Float</TD></TR>
  313. * <TR>
  314. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
  315. * <TD VALIGN="TOP">POSTURE_REGULAR = 0, <BR>
  316. * POSTURE_OBLIQUE = 0.20</TD></TR>
  317. * <TR>
  318. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  319. * <TD VALIGN="TOP">POSTURE_REGULAR</TD></TR>
  320. * <TR>
  321. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  322. * <TD VALIGN="TOP">The value is interpreted generally as a skew slope,
  323. * positive leans to the right. If the font has a different value for
  324. * specific constants, then the value is interpolated as described in
  325. * the class description. With fonts that have italic faces, not only
  326. * the skew of the character changes, but also the letter shapes
  327. * might change.<BR>
  328. * <B>Notes: </B><BR>
  329. * To set the value by angle, use:<BR>
  330. * <TT>value = new Float(Math.tan(Math.PI*degrees/180.0)</TT><BR>
  331. * To determine the angle from the value, use:<BR>
  332. * <TT>angle = Math.atan(value.floatValue())*180/Math.PI</TT></TD></TR>
  333. * <TR>
  334. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Fallback</TH>
  335. * <TD VALIGN="TOP">If an Oblique font is available and matches, use that.
  336. * Otherwise skew with a transform using the posture value interpreted as
  337. * run/rise.</TD></TR>
  338. * </TABLE>
  339. *
  340. * @see java.awt.Font#getItalicAngle()
  341. */
  342. public static final TextAttribute POSTURE = new TextAttribute("posture");
  343. /**
  344. * The standard posture, upright.
  345. * @see #POSTURE
  346. */
  347. public static final Float POSTURE_REGULAR = new Float(0.0f);
  348. /**
  349. * The standard italic posture.
  350. * @see #POSTURE
  351. */
  352. public static final Float POSTURE_OBLIQUE = new Float(0.20f);
  353. /**
  354. * Attribute key for the font size.
  355. *
  356. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  357. * <TR>
  358. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  359. * <TD VALIGN="TOP">SIZE</TD></TR>
  360. * <TR>
  361. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  362. * <TD VALIGN="TOP">Float</TD></TR>
  363. * <TR>
  364. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  365. * <TD VALIGN="TOP">from System Properties</TD></TR>
  366. * <TR>
  367. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  368. * <TD VALIGN="TOP">Represents point size. Note that the appearance and
  369. * metrics of a 12pt font with a 2X transform might be different than
  370. * that of a 24 point font with no transform.</TD></TR>
  371. * <TR>
  372. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Fallback</TH>
  373. * <TD VALIGN="TOP">Scale to provided size.</TD></TR>
  374. * </TABLE>
  375. */
  376. public static final TextAttribute SIZE = new TextAttribute("size");
  377. /**
  378. * Attribute key for the transform of a font.
  379. *
  380. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  381. * <TR>
  382. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  383. * <TD VALIGN="TOP">TRANSFORM</TD></TR>
  384. * <TR>
  385. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  386. * <TD VALIGN="TOP">TransformAttribute</TD></TR>
  387. * <TR>
  388. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  389. * <TD VALIGN="TOP">Identity transform</TD></TR>
  390. * <TR>
  391. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  392. * <TD VALIGN="TOP"><P>Used to transform glyphs rendered by this font. The
  393. * primary intent is to support scaling, skewing, and translation. In
  394. * general, large rotations do not produce very useful results. The
  395. * transform modifies both the glyph and the advance. The translations
  396. * in the transform are interpreted as a ratio of the point size. That
  397. * is, with a point size of 12, a translation of 0.5 results in a
  398. * movement of 6 points.
  399. * <p>
  400. * The advance point of the transformed glyph is the transform of the
  401. * advance point projected onto the baseline. If the advance ends up
  402. * to the left (top) of the glyph origin, the two points are swapped.
  403. * <p>
  404. * <P><EM>Example one</EM>: The point
  405. * size is 20, the original advance is 10.0, and the transform is a 60
  406. * degree counterclockwise rotation plus an offset up and to the right
  407. * of 0.1, -0.1. The translation results in an offset of <2.0, -2.0>.
  408. * The original advance point is <10.0, 0.0>; after the rotation it
  409. * is <6.0, -8.0>; when adding the offset this becomes
  410. * <8.0,-10.0>, when projecting on the (horizontal) baseline this
  411. * becomes the new advance point: <8.0, 0.0>. The advance width is
  412. * the distance from the origin to the advance point: 8.0. The rotated
  413. * glyph is rendered two points up and to the right of its origin and
  414. * rotated. This does not affect the baseline for subsequent
  415. * glyphs.</P></TD></TR>
  416. * </TABLE>
  417. */
  418. public static final TextAttribute TRANSFORM = new TextAttribute("transform");
  419. /**
  420. * Attribute key for super and subscripting.
  421. *
  422. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  423. * <TR>
  424. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  425. * <TD VALIGN="TOP">SUPERSCRIPT</TD></TR>
  426. * <TR>
  427. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  428. * <TD VALIGN="TOP">Integer</TD></TR>
  429. * <TR>
  430. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
  431. * <TD VALIGN="TOP">SUPERSCRIPT_NONE = 0,<BR>
  432. * SUPERSCRIPT_SUPER = 1,<BR>
  433. * SUPERSCRIPT_SUB = -1</TD></TR>
  434. * <TR>
  435. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  436. * <TD VALIGN="TOP">SUPERSCRIPT_NONE</TD></TR>
  437. * <TR>
  438. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  439. * <TD VALIGN="TOP">Requests that the font display the characters with
  440. * glyphs at a particular superscript level: 0 = none, 1 =
  441. * superscript, 2 = superscript of superscript,...-1
  442. * = subscript, -2 = subscript of subscript,... Requests that the font
  443. * display text using default superscript (or subscript) glyphs and/or
  444. * scaling.</TD></TR>
  445. * <TR>
  446. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Fallback</TH>
  447. * <TD VALIGN="TOP">Use transform with translation of +/-1/2 and scale
  448. * of 2/3, progressively for each level. That is, for the transform at
  449. * level N (with N != 0):<BR>
  450. * <TT>offset = sign(N)*1/2*(2/3)^(abs(N)-1)<BR>
  451. * scale = (2/3)^abs(N)</TT></TD></TR>
  452. * </TABLE>
  453. */
  454. public static final TextAttribute SUPERSCRIPT = new TextAttribute("superscript");
  455. /**
  456. * Standard superscript.
  457. * @see #SUPERSCRIPT
  458. */
  459. public static final Integer SUPERSCRIPT_SUPER = new Integer(1);
  460. /**
  461. * Standard subscript.
  462. * @see #SUPERSCRIPT
  463. */
  464. public static final Integer SUPERSCRIPT_SUB = new Integer(-1);
  465. /**
  466. * Attribute key for the font to use to render text.
  467. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  468. * <TR>
  469. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  470. * <TD VALIGN="TOP">FONT</TD></TR>
  471. * <TR>
  472. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  473. * <TD VALIGN="TOP">Font</TD></TR>
  474. * <TR>
  475. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  476. * <TD VALIGN="TOP">None, perform default resolution</TD></TR>
  477. * <TR>
  478. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  479. * <TD VALIGN="TOP">A way for users to override the resolution of font
  480. * attributes into a <code>Font</code>, or force use of a particular
  481. * <code>Font</code> instance.
  482. * This also allows users to specify subclasses of <code>Font</code> in
  483. * cases where a <code>Font</code> can be subclassed.</TD></TR>
  484. * </TABLE>
  485. */
  486. public static final TextAttribute FONT = new TextAttribute("font");
  487. /**
  488. * Attribute key for a user_defined glyph to display in the text in lieu
  489. * of a character.
  490. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  491. * <TR>
  492. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  493. * <TD VALIGN="TOP">CHAR_REPLACEMENT</TD></TR>
  494. * <TR>
  495. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  496. * <TD VALIGN="TOP">GraphicAttribute</TD></TR>
  497. * <TR>
  498. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  499. * <TD VALIGN="TOP">Allows the user to specify an empty position plus
  500. * metric information. This method is used to reserve space for a graphic
  501. * or other embedded component. Required for
  502. * correct BIDI position of 'inline' components within a line. An optional
  503. * convenience method allows drawing for simple cases. Follows the
  504. * Microsoft model: the character that this is applied to should be
  505. * \uFFFC.</TD></TR>
  506. * </TABLE>
  507. */
  508. public static final TextAttribute CHAR_REPLACEMENT = new TextAttribute("char_replacement");
  509. //
  510. // Adornments added to text.
  511. //
  512. /**
  513. * Attribute key for the foreground paint
  514. * adornment.
  515. *
  516. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  517. * <TR>
  518. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  519. * <TD VALIGN="TOP">FOREGROUND</TD></TR>
  520. * <TR>
  521. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  522. * <TD VALIGN="TOP">Paint</TD></TR>
  523. * <TR>
  524. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  525. * <TD VALIGN="TOP">Color.black</TD></TR>
  526. * <TR>
  527. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  528. * <TD VALIGN="TOP">Specify the foreground Paint (or Color) of the text.</TD></TR>
  529. * </TABLE>
  530. */
  531. public static final TextAttribute FOREGROUND = new TextAttribute("foreground");
  532. /**
  533. * Attribute key for the background Paint adornment.
  534. *
  535. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  536. * <TR>
  537. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  538. * <TD VALIGN="TOP">BACKGROUND</TD></TR>
  539. * <TR>
  540. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  541. * <TD VALIGN="TOP">Paint</TD></TR>
  542. * <TR>
  543. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  544. * <TD VALIGN="TOP">null</TD></TR>
  545. * <TR>
  546. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  547. * <TD VALIGN="TOP">Specify the background Paint (or Color) of the text.</TD></TR>
  548. * </TABLE>
  549. */
  550. public static final TextAttribute BACKGROUND = new TextAttribute("background");
  551. /**
  552. * Attribute key for underline adornments.
  553. *
  554. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  555. * <TR>
  556. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  557. * <TD VALIGN="TOP">UNDERLINE</TD></TR>
  558. * <TR>
  559. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  560. * <TD VALIGN="TOP">Integer</TD></TR>
  561. * <TR>
  562. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
  563. * <TD VALIGN="TOP">UNDERLINE_ON = 0</TD></TR>
  564. * <TR>
  565. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  566. * <TD VALIGN="TOP">none</TD></TR>
  567. * <TR>
  568. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  569. * <TD VALIGN="TOP">An embellishment added to the glyphs rendered by a
  570. * font.</TD></TR>
  571. * <TR>
  572. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Fallback</TH>
  573. * <TD VALIGN="TOP"></TD></TR>
  574. * </TABLE>
  575. */
  576. public static final TextAttribute UNDERLINE = new TextAttribute("underline");
  577. /**
  578. * Standard underline at the roman baseline for roman text, and below
  579. * the decenders for other text.
  580. *
  581. * @see #UNDERLINE
  582. */
  583. public static final Integer UNDERLINE_ON = new Integer((byte)0);
  584. /**
  585. * Attribute key for the strikethrough adornment.
  586. *
  587. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  588. * <TR>
  589. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  590. * <TD VALIGN="TOP">STRIKETHROUGH</TD></TR>
  591. * <TR>
  592. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  593. * <TD VALIGN="TOP">Boolean</TD></TR>
  594. * <TR>
  595. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
  596. * <TD VALIGN="TOP">true = on, false = off</TD></TR>
  597. * <TR>
  598. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  599. * <TD VALIGN="TOP">off</TD></TR>
  600. * <TR>
  601. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  602. * <TD VALIGN="TOP">An embellishment added to the glyphs rendered by a
  603. * font.</TD></TR>
  604. * </TABLE>
  605. */
  606. public static final TextAttribute STRIKETHROUGH = new TextAttribute("strikethrough");
  607. /**
  608. * A single strikethrough.
  609. *
  610. * @see #STRIKETHROUGH
  611. */
  612. public static final Boolean STRIKETHROUGH_ON = new Boolean(true);
  613. //
  614. // Attributes use to control layout of text on a line.
  615. //
  616. /**
  617. * Attribute key for the run direction of the line.
  618. *
  619. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  620. * <TR>
  621. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  622. * <TD VALIGN="TOP">RUN_DIRECTION</TD></TR>
  623. * <TR>
  624. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  625. * <TD VALIGN="TOP">Boolean</TD></TR>
  626. * <TR>
  627. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
  628. * <TD VALIGN="TOP">RUN_DIRECTION_LTR = true, RUN_DIRECTION_RTL = false
  629. * </TD></TR>
  630. * <TR>
  631. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  632. * <TD VALIGN="TOP">Use the default Unicode base direction from the BIDI
  633. * algorithm.</TD></TR>
  634. * <TR>
  635. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  636. * <TD VALIGN="TOP"><P>Specifies which base run direction to use when
  637. * positioning mixed directional runs within a paragraph. If this value is
  638. * RUN_DIRECTION_DEFAULT, <code>TextLayout</code> uses the default Unicode
  639. * base direction from the BIDI algorithm.</P>
  640. * <P><I>This attribute should have the same value over the whole
  641. * paragraph.</I></TD></TR>
  642. * </TABLE>
  643. */
  644. public static final TextAttribute RUN_DIRECTION = new TextAttribute("run_direction");
  645. /**
  646. * Left-to-right run direction.
  647. * @see #RUN_DIRECTION
  648. */
  649. public static final Boolean RUN_DIRECTION_LTR = new Boolean(false);
  650. /**
  651. * Right-to-left run direction.
  652. * @see #RUN_DIRECTION
  653. */
  654. public static final Boolean RUN_DIRECTION_RTL = new Boolean(true);
  655. /**
  656. * Attribute key for the embedding level for nested bidirectional runs.
  657. *
  658. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  659. * <TR>
  660. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  661. * <TD VALIGN="TOP">BIDI_EMBEDDING</TD></TR>
  662. * <TR>
  663. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  664. * <TD VALIGN="TOP">Integer</TD></TR>
  665. * <TR>
  666. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>
  667. * <TD VALIGN="TOP">Positive values 1 through 15 are <I>embedding</I>
  668. * levels, negative values<BR> through -15 are <I>override</I> levels
  669. * </TD></TR>
  670. * <TR>
  671. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  672. * <TD VALIGN="TOP">Use standard BIDI to compute levels from formatting
  673. * characters in the text.</TD></TR>
  674. * <TR>
  675. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  676. * <TD VALIGN="TOP">Specifies the bidi embedding level of the character.
  677. * When this attribute is present anywhere in a paragraph, then the
  678. * Unicode characters RLO, LRO, RLE, LRE, PDF are disregarded in the BIDI
  679. * analysis of that paragraph.
  680. * See the Unicode Standard v. 2.0, section 3-11.
  681. * </TD></TR>
  682. * </TABLE>
  683. */
  684. public static final TextAttribute BIDI_EMBEDDING = new TextAttribute("bidi_embedding");
  685. /**
  686. * Attribute key for the justification of a paragraph.
  687. *
  688. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  689. * <TR>
  690. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  691. * <TD VALIGN="TOP">JUSTIFICATION</TD></TR>
  692. * <TR>
  693. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  694. * <TD VALIGN="TOP">Float</TD></TR>
  695. * <TR>
  696. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>
  697. * <TD VALIGN="TOP">0.0 through1.0</TD></TR>
  698. * <TR>
  699. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  700. * <TD VALIGN="TOP">1.0</TD></TR>
  701. * <TR>
  702. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
  703. * <TD VALIGN="TOP"><P>Specifies which fraction of the extra space to use
  704. * when justification is requested. For example, if the line is 50 points
  705. * wide and the margins are 70 points apart, a value of 0.5 means that the
  706. * line is padded to reach a width of 60 points.</P>
  707. * <P><I>This attribute should have the same value over the whole
  708. * paragraph.</I></TD></TR>
  709. * </TABLE>
  710. */
  711. public static final TextAttribute JUSTIFICATION = new TextAttribute("justification");
  712. /**
  713. * Justify the line to the full requested width.
  714. * @see #JUSTIFICATION
  715. */
  716. public static final Float JUSTIFICATION_FULL = new Float(1.0f);
  717. /**
  718. * Do not allow the line to be justified.
  719. * @see #JUSTIFICATION
  720. */
  721. public static final Float JUSTIFICATION_NONE = new Float(0.0f);
  722. //
  723. // For use by input method.
  724. //
  725. /**
  726. * Attribute key for input method highlight styles.
  727. * <p>Values are instances of
  728. * {@link java.awt.im.InputMethodHighlight InputMethodHighlight}.
  729. * These instances should be wrapped in
  730. * {@link java.text.Annotation Annotation} instances
  731. * if segments need to be highlighted separately.
  732. * <p>
  733. * Input method highlights are used while text is being composed
  734. * using an input method. Text editing components should retain them
  735. * even if they generally only deal with unstyled text, and make them
  736. * available to the drawing routines.
  737. * @see java.awt.im.InputMethodHighlight
  738. */
  739. public static final TextAttribute INPUT_METHOD_HIGHLIGHT = new TextAttribute("input method highlight");
  740. /**
  741. * Attribute key for input method underline adornments.
  742. *
  743. * <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
  744. * <TR>
  745. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
  746. * <TD VALIGN="TOP">INPUT_METHOD_UNDERLINE</TD></TR>
  747. * <TR>
  748. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
  749. * <TD VALIGN="TOP">Integer</TD></TR>
  750. * <TR>
  751. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
  752. * <TD VALIGN="TOP">UNDERLINE_LOW_ONE_PIXEL, UNDERLINE_LOW_TWO_PIXEL,
  753. * UNDERLINE_LOW_DOTTED, UNDERLINE_LOW_GRAY, UNDERLINE_LOW_DASHED</TD></TR>
  754. * <TR>
  755. * <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
  756. * <TD VALIGN="TOP">no underline</TD></TR>
  757. * </TABLE>
  758. * @since 1.3
  759. */
  760. public static final TextAttribute INPUT_METHOD_UNDERLINE
  761. = new TextAttribute("input method underline");
  762. /**
  763. * Single pixel solid low underline.
  764. * @see #INPUT_METHOD_UNDERLINE
  765. * @since 1.3
  766. */
  767. public static final Integer UNDERLINE_LOW_ONE_PIXEL = new Integer(1);
  768. /**
  769. * Double pixel solid low underline.
  770. * @see #INPUT_METHOD_UNDERLINE
  771. * @since 1.3
  772. */
  773. public static final Integer UNDERLINE_LOW_TWO_PIXEL = new Integer(2);
  774. /**
  775. * Single pixel dotted low underline.
  776. * @see #INPUT_METHOD_UNDERLINE
  777. * @since 1.3
  778. */
  779. public static final Integer UNDERLINE_LOW_DOTTED = new Integer(3);
  780. /**
  781. * Double pixel gray low underline.
  782. * @see #INPUT_METHOD_UNDERLINE
  783. * @since 1.3
  784. */
  785. public static final Integer UNDERLINE_LOW_GRAY = new Integer(4);
  786. /**
  787. * Single pixel dashed low underline.
  788. * @see #INPUT_METHOD_UNDERLINE
  789. * @since 1.3
  790. */
  791. public static final Integer UNDERLINE_LOW_DASHED = new Integer(5);
  792. /**
  793. * Attribute key for swapping foreground and background Paints (or Colors).
  794. *
  795. * <p>Values are instances of <code>Boolean</code>.
  796. * The default is not to swap the foreground and background.
  797. * If the foreground and background attributes are both defined,
  798. * this causes them to be swapped when rendering text. If either is
  799. * defaulted, the exact effect is undefined--generally it will produce
  800. * an 'inverted' appearance.
  801. */
  802. public static final TextAttribute SWAP_COLORS = new TextAttribute("swap_colors");
  803. /** Swap foreground and background. */
  804. public static final Boolean SWAP_COLORS_ON = new Boolean(true);
  805. }