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