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