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