1. /*
  2. * @(#)FontRenderContext.java 1.17 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. * @author Charlton Innovations, Inc.
  9. */
  10. package java.awt.font;
  11. import java.awt.geom.AffineTransform;
  12. /**
  13. * The <code>FontRenderContext</code> class is a container for the
  14. * information needed to correctly measure text. The measurement of text
  15. * can vary because of rules that map outlines to pixels, and rendering
  16. * hints provided by an application.
  17. * <p>
  18. * One such piece of information is a transform that scales
  19. * typographical points to pixels. (A point is defined to be exactly 1/72
  20. * of an inch, which is slightly different than
  21. * the traditional mechanical measurement of a point.) A character that
  22. * is rendered at 12pt on a 600dpi device might have a different size
  23. * than the same character rendered at 12pt on a 72dpi device because of
  24. * such factors as rounding to pixel boundaries and hints that the font
  25. * designer may have specified.
  26. * <p>
  27. * Anti-aliasing and Fractional-metrics specified by an application can also
  28. * affect the size of a character because of rounding to pixel
  29. * boundaries.
  30. * @see java.awt.RenderingHints#KEY_TEXT_ANTIALIASING
  31. * @see java.awt.RenderingHints#KEY_FRACTIONALMETRICS
  32. * @see java.awt.Graphics2D#getFontRenderContext
  33. * @see java.awt.font.LineMetrics
  34. */
  35. public class FontRenderContext {
  36. private transient AffineTransform tx;
  37. private transient boolean bIsAntiAliased;
  38. private transient boolean bUsesFractionalMetrics;
  39. /**
  40. * Constructs a new <code>FontRenderContext</code>
  41. * object.
  42. *
  43. */
  44. protected FontRenderContext() {
  45. this.tx = new AffineTransform();
  46. this.bIsAntiAliased = false;
  47. this.bUsesFractionalMetrics = false;
  48. }
  49. /**
  50. * Constructs a <code>FontRenderContext</code> object from an
  51. * optional {@link AffineTransform} and two <code>boolean</code>
  52. * values that determine if the newly constructed object has
  53. * anti-aliasing or fractional metrics.
  54. * @param tx the optional <code>AffineTransform</code>
  55. * @param isAntiAliased determines if the newly contructed object has
  56. * anti-aliasing
  57. * @param usesFractionalMetrics determines if the newly constructed
  58. * object uses fractional metrics
  59. */
  60. public FontRenderContext(AffineTransform tx,
  61. boolean isAntiAliased,
  62. boolean usesFractionalMetrics) {
  63. if (tx == null) {
  64. tx = new AffineTransform();
  65. }
  66. this.tx = tx;
  67. this.bIsAntiAliased = isAntiAliased;
  68. this.bUsesFractionalMetrics = usesFractionalMetrics;
  69. }
  70. /**
  71. * Gets the transform that is used to scale typographical points
  72. * to pixels in this <code>FontRenderContext</code>.
  73. * @returns the <code>AffineTransform</code> of this
  74. * <code>FontRenderContext</code>.
  75. * @see AffineTransform
  76. */
  77. public AffineTransform getTransform() {
  78. return new AffineTransform(tx);
  79. }
  80. /**
  81. * Gets the text anti-aliasing mode used in this
  82. * <code>FontRenderContext</code>.
  83. * @returns <code>true</code>, if text is anti-aliased in this
  84. * <code>FontRenderContext</code> <code>false</code> otherwise.
  85. * @see java.awt.RenderingHints#KEY_TEXT_ANTIALIASING
  86. */
  87. public boolean isAntiAliased() {
  88. return this.bIsAntiAliased;
  89. }
  90. /**
  91. * Gets the text fractional metrics mode requested by the application
  92. * for use in this <code>FontRenderContext</code>.
  93. * @returns <code>true</code>, if layout should be performed with
  94. * fractional metrics; <code>false</code> otherwise.
  95. * in this <code>FontRenderContext</code>.
  96. * @see java.awt.RenderingHints#KEY_FRACTIONALMETRICS
  97. */
  98. public boolean usesFractionalMetrics() {
  99. return this.bUsesFractionalMetrics;
  100. }
  101. }