1. /*
  2. * @(#)Graphics2D.java 1.63 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. package java.awt;
  8. import java.awt.RenderingHints.Key;
  9. import java.awt.geom.AffineTransform;
  10. import java.awt.image.ImageObserver;
  11. import java.awt.image.BufferedImageOp;
  12. import java.awt.image.BufferedImage;
  13. import java.awt.image.RenderedImage;
  14. import java.awt.image.renderable.RenderableImage;
  15. import java.awt.font.GlyphVector;
  16. import java.awt.font.FontRenderContext;
  17. import java.text.AttributedCharacterIterator;
  18. import java.util.Map;
  19. /**
  20. * This <code>Graphics2D</code> class extends the
  21. * {@link Graphics} class to provide more sophisticated
  22. * control over geometry, coordinate transformations, color management,
  23. * and text layout. This is the fundamental class for rendering
  24. * 2-dimensional shapes, text and images on the Java(tm) platform.
  25. * <p>
  26. * <h2>Coordinate Spaces</h2>
  27. * All coordinates passed to a <code>Graphics2D</code> object are specified
  28. * in a device-independent coordinate system called User Space, which is
  29. * used by applications. The <code>Graphics2D</code> object contains
  30. * an {@link AffineTransform} object as part of its rendering state
  31. * that defines how to convert coordinates from user space to
  32. * device-dependent coordinates in Device Space.
  33. * <p>
  34. * Coordinates in device space usually refer to individual device pixels
  35. * and are aligned on the infinitely thin gaps between these pixels.
  36. * Some <code>Graphics2D</code> objects can be used to capture rendering
  37. * operations for storage into a graphics metafile for playback on a
  38. * concrete device of unknown physical resolution at a later time. Since
  39. * the resolution might not be known when the rendering operations are
  40. * captured, the <code>Graphics2D</code> <code>Transform</code> is set up
  41. * to transform user coordinates to a virtual device space that
  42. * approximates the expected resolution of the target device. Further
  43. * transformations might need to be applied at playback time if the
  44. * estimate is incorrect.
  45. * <p>
  46. * Some of the operations performed by the rendering attribute objects
  47. * occur in the device space, but all <code>Graphics2D</code> methods take
  48. * user space coordinates.
  49. * <p>
  50. * Every <code>Graphics2D</code> object is associated with a target that
  51. * defines where rendering takes place. A
  52. * {@link GraphicsConfiguration} object defines the characteristics
  53. * of the rendering target, such as pixel format and resolution.
  54. * The same rendering target is used throughout the life of a
  55. * <code>Graphics2D</code> object.
  56. * <p>
  57. * When creating a <code>Graphics2D</code> object, the
  58. * <code>GraphicsConfiguration</code>
  59. * specifies the <a name="#deftransform">default transform</a> for
  60. * the target of the <code>Graphics2D</code> (a
  61. * {@link Component} or {@link Image}). This default transform maps the
  62. * user space coordinate system to screen and printer device coordinates
  63. * such that the origin maps to the upper left hand corner of the
  64. * target region of the device with increasing X coordinates extending
  65. * to the right and increasing Y coordinates extending downward.
  66. * The scaling of the default transform is set to identity for those devices
  67. * that are close to 72 dpi, such as screen devices.
  68. * The scaling of the default transform is set to approximately 72 user
  69. * space coordinates per square inch for high resolution devices, such as
  70. * printers. For image buffers, the default transform is the
  71. * <code>Identity</code> transform.
  72. *
  73. * <h2>Rendering Process</h2>
  74. * The Rendering Process can be broken down into four phases that are
  75. * controlled by the <code>Graphics2D</code> rendering attributes.
  76. * The renderer can optimize many of these steps, either by caching the
  77. * results for future calls, by collapsing multiple virtual steps into
  78. * a single operation, or by recognizing various attributes as common
  79. * simple cases that can be eliminated by modifying other parts of the
  80. * operation.
  81. * <p>
  82. * The steps in the rendering process are:
  83. * <ol>
  84. * <li>
  85. * Determine what to render.
  86. * <li>
  87. * Constrain the rendering operation to the current <code>Clip</code>.
  88. * The <code>Clip</code> is specified by a {@link Shape} in user
  89. * space and is controlled by the program using the various clip
  90. * manipulation methods of <code>Graphics</code> and
  91. * <code>Graphics2D</code>. This <i>user clip</i>
  92. * is transformed into device space by the current
  93. * <code>Transform</code> and combined with the
  94. * <i>device clip</i>, which is defined by the visibility of windows and
  95. * device extents. The combination of the user clip and device clip
  96. * defines the <i>composite clip</i>, which determines the final clipping
  97. * region. The user clip is not modified by the rendering
  98. * system to reflect the resulting composite clip.
  99. * <li>
  100. * Determine what colors to render.
  101. * <li>
  102. * Apply the colors to the destination drawing surface using the current
  103. * {@link Composite} attribute in the <code>Graphics2D</code> context.
  104. * </ol>
  105. * <br>
  106. * The three types of rendering operations, along with details of each
  107. * of their particular rendering processes are:
  108. * <ol>
  109. * <li>
  110. * <b><a name="rendershape"><code>Shape</code> operations</a></b>
  111. * <ol>
  112. * <li>
  113. * If the operation is a <code>draw(Shape)</code> operation, then
  114. * the {@link Stroke#createStrokedShape(Shape) createStrokedShape}
  115. * method on the current {@link Stroke} attribute in the
  116. * <code>Graphics2D</code> context is used to construct a new
  117. * <code>Shape</code> object that contains the outline of the specified
  118. * <code>Shape</code>.
  119. * <li>
  120. * The <code>Shape</code> is transformed from user space to device space
  121. * using the current <code>Transform</code>
  122. * in the <code>Graphics2D</code> context.
  123. * <li>
  124. * The outline of the <code>Shape</code> is extracted using the
  125. * {@link Shape#getPathIterator(AffineTransform) getPathIterator} method of
  126. * <code>Shape</code>, which returns a
  127. * {@link java.awt.geom.PathIterator PathIterator}
  128. * object that iterates along the boundary of the <code>Shape</code>.
  129. * <li>
  130. * If the <code>Graphics2D</code> object cannot handle the curved segments
  131. * that the <code>PathIterator</code> object returns then it can call the
  132. * alternate
  133. * {@link Shape#getPathIterator(AffineTransform, double) getPathIterator}
  134. * method of <code>Shape</code>, which flattens the <code>Shape</code>.
  135. * <li>
  136. * The current {@link Paint} in the <code>Graphics2D</code> context
  137. * is queried for a {@link PaintContext}, which specifies the
  138. * colors to render in device space.
  139. * </ol>
  140. * <li>
  141. * <b><a name=rendertext>Text operations</a></b>
  142. * <ol>
  143. * <li>
  144. * The following steps are used to determine the set of glyphs required
  145. * to render the indicated <code>String</code>:
  146. * <ol>
  147. * <li>
  148. * If the argument is a <code>String</code>, then the current
  149. * <code>Font</code> in the <code>Graphics2D</code> context is asked to
  150. * convert the Unicode characters in the <code>String</code> into a set of
  151. * glyphs for presentation with whatever basic layout and shaping
  152. * algorithms the font implements.
  153. * <li>
  154. * If the argument is an
  155. * {@link AttributedCharacterIterator},
  156. * the iterator is asked to convert itself to a
  157. * {@link java.awt.font.TextLayout TextLayout}
  158. * using its embedded font attributes. The <code>TextLayout</code>
  159. * implements more sophisticated glyph layout algorithms that
  160. * perform Unicode bi-directional layout adjustments automatically
  161. * for multiple fonts of differing writing directions.
  162. * <li>
  163. * If the argument is a
  164. * {@link GlyphVector}, then the
  165. * <code>GlyphVector</code> object already contains the appropriate
  166. * font-specific glyph codes with explicit coordinates for the position of
  167. * each glyph.
  168. * </ol>
  169. * <li>
  170. * The current <code>Font</code> is queried to obtain outlines for the
  171. * indicated glyphs. These outlines are treated as shapes in user space
  172. * relative to the position of each glyph that was determined in step 1.
  173. * <li>
  174. * The character outlines are filled as indicated above
  175. * under <a href="#rendershape"><code>Shape</code> operations</a>.
  176. * <li>
  177. * The current <code>Paint</code> is queried for a
  178. * <code>PaintContext</code>, which specifies
  179. * the colors to render in device space.
  180. * </ol>
  181. * <li>
  182. * <b><a name= renderingimage><code>Image</code> Operations</a></b>
  183. * <ol>
  184. * <li>
  185. * The region of interest is defined by the bounding box of the source
  186. * <code>Image</code>.
  187. * This bounding box is specified in Image Space, which is the
  188. * <code>Image</code> object's local coordinate system.
  189. * <li>
  190. * If an <code>AffineTransform</code> is passed to
  191. * {@link #drawImage(java.awt.Image, java.awt.geom.AffineTransform, java.awt.image.ImageObserver) drawImage(Image, AffineTransform, ImageObserver)},
  192. * the <code>AffineTransform</code> is used to transform the bounding
  193. * box from image space to user space. If no <code>AffineTransform</code>
  194. * is supplied, the bounding box is treated as if it is already in user space.
  195. * <li>
  196. * The bounding box of the source <code>Image</code> is transformed from user
  197. * space into device space using the current <code>Transform</code>.
  198. * Note that the result of transforming the bounding box does not
  199. * necessarily result in a rectangular region in device space.
  200. * <li>
  201. * The <code>Image</code> object determines what colors to render,
  202. * sampled according to the source to destination
  203. * coordinate mapping specified by the current <code>Transform</code> and the
  204. * optional image transform.
  205. * </ol>
  206. * </ol>
  207. *
  208. * <h2>Default Rendering Attributes</h2>
  209. * The default values for the <code>Graphics2D</code> rendering attributes are:
  210. * <dl compact>
  211. * <dt><i><code>Paint</code></i>
  212. * <dd>The color of the <code>Component</code>.
  213. * <dt><i><code>Font</code></i>
  214. * <dd>The <code>Font</code> of the <code>Component</code>.
  215. * <dt><i><code>Stroke</code></i>
  216. * <dd>A square pen with a linewidth of 1, no dashing, miter segment joins
  217. * and square end caps.
  218. * <dt><i><code>Transform</code></i>
  219. * <dd>The
  220. * {@link GraphicsConfiguration#getDefaultTransform() getDefaultTransform}
  221. * for the <code>GraphicsConfiguration</code> of the <code>Component</code>.
  222. * <dt><i><code>Composite</code></i>
  223. * <dd>The {@link AlphaComposite#SRC_OVER} rule.
  224. * <dt><i><code>Clip</code></i>
  225. * <dd>No rendering <code>Clip</code>, the output is clipped to the
  226. * <code>Component</code>.
  227. * </dl>
  228. *
  229. * <h2>Rendering Compatibility Issues</h2>
  230. * The JDK(tm) 1.1 rendering model is based on a pixelization model
  231. * that specifies that coordinates
  232. * are infinitely thin, lying between the pixels. Drawing operations are
  233. * performed using a one-pixel wide pen that fills the
  234. * pixel below and to the right of the anchor point on the path.
  235. * The JDK 1.1 rendering model is consistent with the
  236. * capabilities of most of the existing class of platform
  237. * renderers that need to resolve integer coordinates to a
  238. * discrete pen that must fall completely on a specified number of pixels.
  239. * <p>
  240. * The Java(tm) 2D (JDK(tm) 1.2) API supports antialiasing renderers.
  241. * A pen with a width of one pixel does not need to fall
  242. * completely on pixel N as opposed to pixel N+1. The pen can fall
  243. * partially on both pixels. It is not necessary to choose a bias
  244. * direction for a wide pen since the blending that occurs along the
  245. * pen traversal edges makes the sub-pixel position of the pen
  246. * visible to the user. On the other hand, when antialiasing is
  247. * turned off with the ANTIALIAS_OFF hint, the renderer might need
  248. * to apply a bias to determine which pixel to modify when the pen
  249. * is straddling a pixel boundary, such as when it is drawn
  250. * along an integer coordinate in device space. While the capabilities
  251. * of an antialiasing renderer make it no longer necessary for the
  252. * rendering model to specify a bias for the pen, it is desirable for the
  253. * antialiasing and non-antialiasing renderers to perform similarly for
  254. * the common cases of drawing one-pixel wide horizontal and vertical
  255. * lines on the screen. To ensure that turning on the ANTIALIAS hint
  256. * does not cause such lines to suddenly become twice as wide and half
  257. * as opaque, it is desirable to have the model specify a path for such
  258. * lines so that they completely cover a particular set of pixels to help
  259. * increase their crispness.
  260. * <p>
  261. * Java 2D API maintains compatibility with JDK 1.1 rendering
  262. * behavior, such that legacy operations and existing renderer
  263. * behavior is unchanged under Java 2D API. Legacy
  264. * methods that map onto general <code>draw</code> and
  265. * <code>fill</code> methods are defined, which clearly indicates
  266. * how <code>Graphics2D</code> extends <code>Graphics</code> based
  267. * on settings of <code>Stroke</code> and <code>Transform</code>
  268. * attributes and rendering hints. The definition
  269. * performs identically under default attribute settings.
  270. * For example, the default <code>Stroke</code> is a
  271. * <code>BasicStroke</code> with a width of 1 and no dashing and the
  272. * default Transform for screen drawing is an Identity transform.
  273. * <p>
  274. * The following two rules provide predictable rendering behavior whether
  275. * aliasing or antialiasing is being used.
  276. * <ul>
  277. * <li> Device coordinates are defined to be between device pixels which
  278. * avoids any inconsistent results between aliased and antaliased
  279. * rendering. If coordinates were defined to be at a pixel's center, some
  280. * of the pixels covered by a shape, such as a rectangle, would only be
  281. * half covered.
  282. * With aliased rendering, the half covered pixels would either be
  283. * rendered inside the shape or outside the shape. With anti-aliased
  284. * rendering, the pixels on the entire edge of the shape would be half
  285. * covered. On the other hand, since coordinates are defined to be
  286. * between pixels, a shape like a rectangle would have no half covered
  287. * pixels, whether or not it is rendered using antialiasing.
  288. * <li> The <code>BasicStroke</code> object always applies a
  289. * (0.5, 0.5) user space translation to its pen before stroking a
  290. * path. The result of this translation is that for the default
  291. * <code>BasicStroke</code> with a width of 1 user space unit, the
  292. * line is offset entirely below and to the right of the path.
  293. * This rule also maintains similar visual results when the same path is
  294. * stroked in a scaled coordinate system, such as when rendered to a
  295. * printer, and also when antialiasing is turned on. In all 3 cases, the
  296. * bias that was required when the line was drawn in a 1:1 coordinate
  297. * system and discrete pixels had to be chosen are consistent
  298. * regardless of coordinate scaling or choice of antialiasing hint.
  299. * </ul>
  300. * <p>
  301. * The following definitions of general legacy methods
  302. * perform identically to previously specified behavior under default
  303. * attribute settings:
  304. * <ul>
  305. * <li>
  306. * For <code>fill</code> operations, including <code>fillRect</code>,
  307. * <code>fillRoundRect</code>, <code>fillOval</code>,
  308. * <code>fillArc</code>, <code>fillPolygon</code>, and
  309. * <code>clearRect</code>, {@link #fill(Shape) fill} can now be called
  310. * with the desired <code>Shape</code>. For example, when filling a
  311. * rectangle:
  312. * <pre>
  313. * fill(new Rectangle(x, y, w, h));
  314. * </pre>
  315. * is called.
  316. * <p>
  317. * <li>
  318. * Similarly, for draw operations, including <code>drawLine</code>,
  319. * <code>drawRect</code>, <code>drawRoundRect</code>,
  320. * <code>drawOval</code>, <code>drawArc</code>, <code>drawPolyline</code>,
  321. * and <code>drawPolygon</code>, {@link #draw(Shape) draw} can now be
  322. * called with the desired <code>Shape</code>. For example, when drawing a
  323. * rectangle:
  324. * <pre>
  325. * draw(new Rectangle(x, y, w, h));
  326. * </pre>
  327. * is called.
  328. * <p>
  329. * <li>
  330. * The <code>draw3DRect</code> and <code>fill3DRect</code> methods were
  331. * implemented in terms of the <code>drawLine</code> and
  332. * <code>fillRect</code> methods in the <code>Graphics</code> class which
  333. * would predicate their behavior upon the current <code>Stroke</code>
  334. * and <code>Paint</code> objects in a <code>Graphics2D</code> context.
  335. * This class overrides those implementations with versions that use
  336. * the current <code>Color</code> exclusively, overriding the current
  337. * <code>Paint</code> and which uses <code>fillRect</code> to describe
  338. * the exact same behavior as the preexisting methods regardless of the
  339. * setting of the current <code>Stroke</code>.
  340. * </ul>
  341. * The <code>Graphics</code> class defines only the <code>setColor</code>
  342. * method to control the color to be painted. Since the Java 2D API extends
  343. * the <code>Color</code> object to implement the new <code>Paint</code>
  344. * interface, the existing
  345. * <code>setColor</code> method is now a convenience method for setting the
  346. * current <code>Paint</code> attribute to a <code>Color</code> object.
  347. * <code>setColor(c)</code> is equivalent to <code>setPaint(c)</code>.
  348. * <p>
  349. * The <code>Graphics</code> class defines two methods for controlling
  350. * how colors are applied to the destination.
  351. * <ol>
  352. * <li>
  353. * The <code>setPaintMode</code> method is implemented as a convenience
  354. * method to set the default <code>Composite</code>, equivalent to
  355. * <code>setComposite(new AlphaComposite.SrcOver)</code>.
  356. * <li>
  357. * The <code>setXORMode(Color xorcolor)</code> method is implemented
  358. * as a convenience method to set a special <code>Composite</code> object that
  359. * ignores the <code>Alpha</code> components of source colors and sets the
  360. * destination color to the value:
  361. * <pre>
  362. * dstpixel = (PixelOf(srccolor) ^ PixelOf(xorcolor) ^ dstpixel);
  363. * </pre>
  364. * </ol>
  365. *
  366. * @version 10-Feb-97
  367. * @author Jim Graham
  368. */
  369. public abstract class Graphics2D extends Graphics {
  370. /**
  371. * Constructs a new <code>Graphics2D</code> object. Since
  372. * <code>Graphics2D</code> is an abstract class, and since it must be
  373. * customized by subclasses for different output devices,
  374. * <code>Graphics2D</code> objects cannot be created directly.
  375. * Instead, <code>Graphics2D</code> objects must be obtained from another
  376. * <code>Graphics2D</code> object, created by a
  377. * <code>Component</code>, or obtained from images such as
  378. * {@link BufferedImage} objects.
  379. * @see java.awt.Component#getGraphics
  380. * @see java.awt.Graphics#create
  381. */
  382. protected Graphics2D() {
  383. }
  384. /**
  385. * Draws a 3-D highlighted outline of the specified rectangle.
  386. * The edges of the rectangle are highlighted so that they
  387. * appear to be beveled and lit from the upper left corner.
  388. * <p>
  389. * The colors used for the highlighting effect are determined
  390. * based on the current color.
  391. * The resulting rectangle covers an area that is
  392. * <code>width + 1</code> pixels wide
  393. * by <code>height + 1</code> pixels tall. This method
  394. * uses the current <code>Color</code> exclusively and ignores
  395. * the current <code>Paint</code>.
  396. * @param x, y the coordinates of the rectangle to be drawn.
  397. * @param width the width of the rectangle to be drawn.
  398. * @param height the height of the rectangle to be drawn.
  399. * @param raised a boolean that determines whether the rectangle
  400. * appears to be raised above the surface
  401. * or sunk into the surface.
  402. * @see java.awt.Graphics#fill3DRect
  403. */
  404. public void draw3DRect(int x, int y, int width, int height,
  405. boolean raised) {
  406. Paint p = getPaint();
  407. Color c = getColor();
  408. Color brighter = c.brighter();
  409. Color darker = c.darker();
  410. setColor(raised ? brighter : darker);
  411. //drawLine(x, y, x, y + height);
  412. fillRect(x, y, 1, height + 1);
  413. //drawLine(x + 1, y, x + width - 1, y);
  414. fillRect(x + 1, y, width - 1, 1);
  415. setColor(raised ? darker : brighter);
  416. //drawLine(x + 1, y + height, x + width, y + height);
  417. fillRect(x + 1, y + height, width, 1);
  418. //drawLine(x + width, y, x + width, y + height - 1);
  419. fillRect(x + width, y, 1, height);
  420. setPaint(p);
  421. }
  422. /**
  423. * Paints a 3-D highlighted rectangle filled with the current color.
  424. * The edges of the rectangle are highlighted so that it appears
  425. * as if the edges were beveled and lit from the upper left corner.
  426. * The colors used for the highlighting effect and for filling are
  427. * determined from the current <code>Color</code>. This method uses
  428. * the current <code>Color</code> exclusively and ignores the current
  429. * <code>Paint</code>.
  430. * @param x, y the coordinates of the rectangle to be filled.
  431. * @param width the width of the rectangle to be filled.
  432. * @param height the height of the rectangle to be filled.
  433. * @param raised a boolean value that determines whether the
  434. * rectangle appears to be raised above the surface
  435. * or etched into the surface.
  436. * @see java.awt.Graphics#draw3DRect
  437. */
  438. public void fill3DRect(int x, int y, int width, int height,
  439. boolean raised) {
  440. Paint p = getPaint();
  441. Color c = getColor();
  442. Color brighter = c.brighter();
  443. Color darker = c.darker();
  444. if (!raised) {
  445. setColor(darker);
  446. } else if (p != c) {
  447. setColor(c);
  448. }
  449. fillRect(x+1, y+1, width-2, height-2);
  450. setColor(raised ? brighter : darker);
  451. //drawLine(x, y, x, y + height - 1);
  452. fillRect(x, y, 1, height);
  453. //drawLine(x + 1, y, x + width - 2, y);
  454. fillRect(x + 1, y, width - 2, 1);
  455. setColor(raised ? darker : brighter);
  456. //drawLine(x + 1, y + height - 1, x + width - 1, y + height - 1);
  457. fillRect(x + 1, y + height - 1, width - 1, 1);
  458. //drawLine(x + width - 1, y, x + width - 1, y + height - 2);
  459. fillRect(x + width - 1, y, 1, height - 1);
  460. setPaint(p);
  461. }
  462. /**
  463. * Strokes the outline of a <code>Shape</code> using the settings of the
  464. * current <code>Graphics2D</code> context. The rendering attributes
  465. * applied include the <code>Clip</code>, <code>Transform</code>,
  466. * <code>Paint</code>, <code>Composite</code> and
  467. * <code>Stroke</code> attributes.
  468. * @param s the <code>Shape</code> to be rendered
  469. * @see #setStroke
  470. * @see #setPaint
  471. * @see java.awt.Graphics#setColor
  472. * @see #transform
  473. * @see #setTransform
  474. * @see #clip
  475. * @see #setClip
  476. * @see #setComposite
  477. */
  478. public abstract void draw(Shape s);
  479. /**
  480. * Renders an image, applying a transform from image space into user space
  481. * before drawing.
  482. * The transformation from user space into device space is done with
  483. * the current <code>Transform</code> in the <code>Graphics2D</code>.
  484. * The specified transformation is applied to the image before the
  485. * transform attribute in the <code>Graphics2D</code> context is applied.
  486. * The rendering attributes applied include the <code>Clip</code>,
  487. * <code>Transform</code>, and <code>Composite</code> attributes.
  488. * Note that no rendering is done if the specified transform is
  489. * noninvertible.
  490. * @param img the <code>Image</code> to be rendered
  491. * @param xform the transformation from image space into user space
  492. * @param obs the {@link ImageObserver}
  493. * to be notified as more of the <code>Image</code>
  494. * is converted
  495. * @return <code>true</code> if the <code>Image</code> is
  496. * fully loaded and completely rendered;
  497. * <code>false</code> if the <code>Image</code> is still being loaded.
  498. * @see #transform
  499. * @see #setTransform
  500. * @see #setComposite
  501. * @see #clip
  502. * @see #setClip
  503. */
  504. public abstract boolean drawImage(Image img,
  505. AffineTransform xform,
  506. ImageObserver obs);
  507. /**
  508. * Renders a <code>BufferedImage</code> that is
  509. * filtered with a
  510. * {@link BufferedImageOp}.
  511. * The rendering attributes applied include the <code>Clip</code>,
  512. * <code>Transform</code>
  513. * and <code>Composite</code> attributes. This is equivalent to:
  514. * <pre>
  515. * img1 = op.filter(img, null);
  516. * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null);
  517. * </pre>
  518. * @param op the filter to be applied to the image before rendering
  519. * @param img the <code>BufferedImage</code> to be rendered
  520. * @param x, y the location in user space where the upper left
  521. * corner of the
  522. * image is rendered
  523. * @see #transform
  524. * @see #setTransform
  525. * @see #setComposite
  526. * @see #clip
  527. * @see #setClip
  528. */
  529. public abstract void drawImage(BufferedImage img,
  530. BufferedImageOp op,
  531. int x,
  532. int y);
  533. /**
  534. * Renders a {@link RenderedImage},
  535. * applying a transform from image
  536. * space into user space before drawing.
  537. * The transformation from user space into device space is done with
  538. * the current <code>Transform</code> in the <code>Graphics2D</code>.
  539. * The specified transformation is applied to the image before the
  540. * transform attribute in the <code>Graphics2D</code> context is applied.
  541. * The rendering attributes applied include the <code>Clip</code>,
  542. * <code>Transform</code>, and <code>Composite</code> attributes. Note
  543. * that no rendering is done if the specified transform is
  544. * noninvertible.
  545. * @param img the image to be rendered
  546. * @param xform the transformation from image space into user space
  547. * @see #transform
  548. * @see #setTransform
  549. * @see #setComposite
  550. * @see #clip
  551. * @see #setClip
  552. */
  553. public abstract void drawRenderedImage(RenderedImage img,
  554. AffineTransform xform);
  555. /**
  556. * Renders a
  557. * {@link RenderableImage},
  558. * applying a transform from image space into user space before drawing.
  559. * The transformation from user space into device space is done with
  560. * the current <code>Transform</code> in the <code>Graphics2D</code>.
  561. * The specified transformation is applied to the image before the
  562. * transform attribute in the <code>Graphics2D</code> context is applied.
  563. * The rendering attributes applied include the <code>Clip</code>,
  564. * <code>Transform</code>, and <code>Composite</code> attributes. Note
  565. * that no rendering is done if the specified transform is
  566. * noninvertible.
  567. *<p>
  568. * Rendering hints set on the <code>Graphics2D</code> object might
  569. * be used in rendering the <code>RenderableImage</code>.
  570. * If explicit control is required over specific hints recognized by a
  571. * specific <code>RenderableImage</code>, or if knowledge of which hints
  572. * are used is required, then a <code>RenderedImage</code> should be
  573. * obtained directly from the <code>RenderableImage</code>
  574. * and rendered using
  575. *{@link #drawRenderedImage(RenderedImage, AffineTransform) drawRenderedImage}.
  576. * @param img the image to be rendered
  577. * @param xform the transformation from image space into user space
  578. * @see #transform
  579. * @see #setTransform
  580. * @see #setComposite
  581. * @see #clip
  582. * @see #setClip
  583. * @see #drawRenderedImage
  584. */
  585. public abstract void drawRenderableImage(RenderableImage img,
  586. AffineTransform xform);
  587. /**
  588. * Renders the text of the specified <code>String</code>, using the
  589. * current <code>Font</code> and <code>Paint</code> attributes in the
  590. * <code>Graphics2D</code> context.
  591. * The baseline of the
  592. * first character is at position (<i>x</i>, <i>y</i>) in
  593. * the User Space.
  594. * The rendering attributes applied include the <code>Clip</code>,
  595. * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
  596. * <code>Composite</code> attributes. For characters in script
  597. * systems such as Hebrew and Arabic, the glyphs can be rendered from
  598. * right to left, in which case the coordinate supplied is the
  599. * location of the leftmost character on the baseline.
  600. * @param str the string to be rendered
  601. * @param x, y the coordinates where the <code>String</code>
  602. * should be rendered
  603. * @see java.awt.Graphics#drawBytes
  604. * @see java.awt.Graphics#drawChars
  605. * @since JDK1.0
  606. */
  607. public abstract void drawString(String str, int x, int y);
  608. /**
  609. * Renders the text specified by the specified <code>String</code>,
  610. * using the current <code>Font</code> and <code>Paint</code> attributes
  611. * in the <code>Graphics2D</code> context.
  612. * The baseline of the first character is at position
  613. * (<i>x</i>, <i>y</i>) in the User Space.
  614. * The rendering attributes applied include the <code>Clip</code>,
  615. * <code>Transform</code>, <code>Paint</code>, <code>Font</code> and
  616. * <code>Composite</code> attributes. For characters in script systems
  617. * such as Hebrew and Arabic, the glyphs can be rendered from right to
  618. * left, in which case the coordinate supplied is the location of the
  619. * leftmost character on the baseline.
  620. * @param s the <code>String</code> to be rendered
  621. * @param x, y the coordinates where the <code>String</code>
  622. * should be rendered
  623. * @see #setPaint
  624. * @see java.awt.Graphics#setColor
  625. * @see java.awt.Graphics#setFont
  626. * @see #setTransform
  627. * @see #setComposite
  628. * @see #setClip
  629. */
  630. public abstract void drawString(String s, float x, float y);
  631. /**
  632. * Renders the text of the specified iterator, using the
  633. * <code>Graphics2D</code> context's current <code>Paint</code>. The
  634. * iterator has to specify a font
  635. * for each character. The baseline of the
  636. * first character is at position (<i>x</i>, <i>y</i>) in the
  637. * User Space.
  638. * The rendering attributes applied include the <code>Clip</code>,
  639. * <code>Transform</code>, <code>Paint</code>, and
  640. * <code>Composite</code> attributes.
  641. * For characters in script systems such as Hebrew and Arabic,
  642. * the glyphs can be rendered from right to left, in which case the
  643. * coordinate supplied is the location of the leftmost character
  644. * on the baseline.
  645. * @param iterator the iterator whose text is to be rendered
  646. * @param x, y the coordinates where the iterator's text is to be
  647. * rendered
  648. * @see #setPaint
  649. * @see java.awt.Graphics#setColor
  650. * @see #setTransform
  651. * @see #setComposite
  652. * @see #setClip
  653. */
  654. public abstract void drawString(AttributedCharacterIterator iterator,
  655. int x, int y);
  656. /**
  657. * Renders the text of the specified iterator, using the
  658. * <code>Graphics2D</code> context's current <code>Paint</code>. The
  659. * iterator must specify a font
  660. * for each character. The baseline of the
  661. * first character is at position (<i>x</i>, <i>y</i>) in the
  662. * User Space.
  663. * The rendering attributes applied include the <code>Clip</code>,
  664. * <code>Transform</code>, <code>Paint</code>, and
  665. * <code>Composite</code> attributes.
  666. * For characters in script systems such as Hebrew and Arabic,
  667. * the glyphs can be rendered from right to left, in which case the
  668. * coordinate supplied is the location of the leftmost character
  669. * on the baseline.
  670. * @param iterator the iterator whose text is to be rendered
  671. * @param x, y the coordinates where the iterator's text is to be
  672. * rendered
  673. * @see #setPaint
  674. * @see java.awt.Graphics#setColor
  675. * @see #setTransform
  676. * @see #setComposite
  677. * @see #setClip
  678. */
  679. public abstract void drawString(AttributedCharacterIterator iterator,
  680. float x, float y);
  681. /**
  682. * Renders the text of the specified
  683. * {@link GlyphVector} using
  684. * the <code>Graphics2D</code> context's rendering attributes.
  685. * The rendering attributes applied include the <code>Clip</code>,
  686. * <code>Transform</code>, <code>Paint</code>, and
  687. * <code>Composite</code> attributes. The <code>GlyphVector</code>
  688. * specifies individual glyphs from a {@link Font}.
  689. * The <code>GlyphVector</code> can also contain the glyph positions.
  690. * This is the fastest way to render a set of characters to the
  691. * screen.
  692. * @param g the <code>GlyphVector</code> to be rendered
  693. * @param x, y the position in User Space where the glyphs should
  694. * be rendered
  695. *
  696. * @see java.awt.font#createGlyphVector
  697. * @see java.awt.font.GlyphVector
  698. * @see #setPaint
  699. * @see java.awt.Graphics#setColor
  700. * @see #setTransform
  701. * @see #setComposite
  702. * @see #setClip
  703. */
  704. public abstract void drawGlyphVector(GlyphVector g, float x, float y);
  705. /**
  706. * Fills the interior of a <code>Shape</code> using the settings of the
  707. * <code>Graphics2D</code> context. The rendering attributes applied
  708. * include the <code>Clip</code>, <code>Transform</code>,
  709. * <code>Paint</code>, and <code>Composite</code>.
  710. * @param s the <code>Shape</code> to be filled
  711. * @see #setPaint
  712. * @see java.awt.Graphics#setColor
  713. * @see #transform
  714. * @see #setTransform
  715. * @see #setComposite
  716. * @see #clip
  717. * @see #setClip
  718. */
  719. public abstract void fill(Shape s);
  720. /**
  721. * Checks whether or not the specified <code>Shape</code> intersects
  722. * the specified {@link Rectangle}, which is in device
  723. * space. If <code>onStroke</code> is false, this method checks
  724. * whether or not the interior of the specified <code>Shape</code>
  725. * intersects the specified <code>Rectangle</code>. If
  726. * <code>onStroke</code> is <code>true</code>, this method checks
  727. * whether or not the <code>Stroke</code> of the specified
  728. * <code>Shape</code> outline intersects the specified
  729. * <code>Rectangle</code>.
  730. * The rendering attributes taken into account include the
  731. * <code>Clip</code>, <code>Transform</code>, and <code>Stroke</code>
  732. * attributes.
  733. * @param rect the area in device space to check for a hit
  734. * @param s the <code>Shape</code> to check for a hit
  735. * @param onStroke flag used to choose between testing the
  736. * stroked or the filled shape. If the flag is <code>true</code>, the
  737. * <code>Stroke</code> oultine is tested. If the flag is
  738. * <code>false</code>, the filled <code>Shape</code> is tested.
  739. * @return <code>true</code> if there is a hit; <code>false</code>
  740. * otherwise.
  741. * @see #setStroke
  742. * @see #fill
  743. * @see #draw
  744. * @see #transform
  745. * @see #setTransform
  746. * @see #clip
  747. * @see #setClip
  748. */
  749. public abstract boolean hit(Rectangle rect,
  750. Shape s,
  751. boolean onStroke);
  752. /**
  753. * Returns the device configuration associated with this
  754. * <code>Graphics2D</code>.
  755. */
  756. public abstract GraphicsConfiguration getDeviceConfiguration();
  757. /**
  758. * Sets the <code>Composite</code> for the <code>Graphics2D</code> context.
  759. * The <code>Composite</code> is used in all drawing methods such as
  760. * <code>drawImage</code>, <code>drawString</code>, <code>draw</code>,
  761. * and <code>fill</code>. It specifies how new pixels are to be combined
  762. * with the existing pixels on the graphics device during the rendering
  763. * process.
  764. * <p>If this <code>Graphics2D</code> context is drawing to a
  765. * <code>Component</code> on the display screen and the
  766. * <code>Composite</code> is a custom object rather than an
  767. * instance of the <code>AlphaComposite</code> class, and if
  768. * there is a security manager, its <code>checkPermission</code>
  769. * method is called with an <code>AWTPermission("readDisplayPixels")</code>
  770. * permission.
  771. * @throws SecurityException
  772. * if a custom <code>Composite</code> object is being
  773. * used to render to the screen and a security manager
  774. * is set and its <code>checkPermission</code> method
  775. * does not allow the operation.
  776. * @param comp the <code>Composite</code> object to be used for rendering
  777. * @see java.awt.Graphics#setXORMode
  778. * @see java.awt.Graphics#setPaintMode
  779. * @see AlphaComposite
  780. * @see SecurityManager#checkPermission
  781. * @see java.awt.AWTPermission
  782. */
  783. public abstract void setComposite(Composite comp);
  784. /**
  785. * Sets the <code>Paint</code> attribute for the
  786. * <code>Graphics2D</code> context. Calling this method
  787. * with a <code>null</code> <code>Paint</code> object does
  788. * not have any effect on the current <code>Paint</code> attribute
  789. * of this <code>Graphics2D</code>.
  790. * @param paint the <code>Paint</code> object to be used to generate
  791. * color during the rendering process, or <code>null</code>
  792. * @see java.awt.Graphics#setColor
  793. * @see GradientPaint
  794. * @see TexturePaint
  795. */
  796. public abstract void setPaint( Paint paint );
  797. /**
  798. * Sets the <code>Stroke</code> for the <code>Graphics2D</code> context.
  799. * @param s the <code>Stroke</code> object to be used to stroke a
  800. * <code>Shape</code> during the rendering process
  801. * @see BasicStroke
  802. */
  803. public abstract void setStroke(Stroke s);
  804. /**
  805. * Sets the value of a single preference for the rendering algorithms.
  806. * Hint categories include controls for rendering quality and overall
  807. * time/quality trade-off in the rendering process. Refer to the
  808. * <code>RenderingHints</code> class for definitions of some common
  809. * keys and values.
  810. * @param hintKey the key of the hint to be set.
  811. * @param hintValue the value indicating preferences for the specified
  812. * hint category.
  813. * @see RenderingHints
  814. */
  815. public abstract void setRenderingHint(Key hintKey, Object hintValue);
  816. /**
  817. * Returns the value of a single preference for the rendering algorithms.
  818. * Hint categories include controls for rendering quality and overall
  819. * time/quality trade-off in the rendering process. Refer to the
  820. * <code>RenderingHints</code> class for definitions of some common
  821. * keys and values.
  822. * @param hintKey the key corresponding to the hint to get.
  823. * @return an object representing the value for the specified hint key.
  824. * Some of the keys and their associated values are defined in the
  825. * <code>RenderingHints</code> class.
  826. * @see RenderingHints
  827. */
  828. public abstract Object getRenderingHint(Key hintKey);
  829. /**
  830. * Replaces the values of all preferences for the rendering
  831. * algorithms with the specified <code>hints</code>.
  832. * The existing values for all rendering hints are discarded and
  833. * the new set of known hints and values are initialized from the
  834. * specified {@link Map} object.
  835. * Hint categories include controls for rendering quality and
  836. * overall time/quality trade-off in the rendering process.
  837. * Refer to the <code>RenderingHints</code> class for definitions of
  838. * some common keys and values.
  839. * @param hints the rendering hints to be set
  840. * @see RenderingHints
  841. */
  842. public abstract void setRenderingHints(Map hints);
  843. /**
  844. * Sets the values of an arbitrary number of preferences for the
  845. * rendering algorithms.
  846. * Only values for the rendering hints that are present in the
  847. * specified <code>Map</code> object are modified.
  848. * All other preferences not present in the specified
  849. * object are left unmodified.
  850. * Hint categories include controls for rendering quality and
  851. * overall time/quality trade-off in the rendering process.
  852. * Refer to the <code>RenderingHints</code> class for definitions of
  853. * some common keys and values.
  854. * @param hints the rendering hints to be set
  855. * @see RenderingHints
  856. */
  857. public abstract void addRenderingHints(Map hints);
  858. /**
  859. * Gets the preferences for the rendering algorithms. Hint categories
  860. * include controls for rendering quality and overall time/quality
  861. * trade-off in the rendering process.
  862. * Returns all of the hint key/value pairs that were ever specified in
  863. * one operation. Refer to the
  864. * <code>RenderingHints</code> class for definitions of some common
  865. * keys and values.
  866. * @return a reference to an instance of <code>RenderingHints</code>
  867. * that contains the current preferences.
  868. * @see RenderingHints
  869. */
  870. public abstract RenderingHints getRenderingHints();
  871. /**
  872. * Translates the origin of the <code>Graphics2D</code> context to the
  873. * point (<i>x</i>, <i>y</i>) in the current coordinate system.
  874. * Modifies the <code>Graphics2D</code> context so that its new origin
  875. * corresponds to the point (<i>x</i>, <i>y</i>) in the
  876. * <code>Graphics2D</code> context's former coordinate system. All
  877. * coordinates used in subsequent rendering operations on this graphics
  878. * context are relative to this new origin.
  879. * @param x, y the specified coordinates
  880. * @since JDK1.0
  881. */
  882. public abstract void translate(int x, int y);
  883. /**
  884. * Concatenates the current
  885. * <code>Graphics2D</code> <code>Transform</code>
  886. * with a translation transform.
  887. * Subsequent rendering is translated by the specified
  888. * distance relative to the previous position.
  889. * This is equivalent to calling transform(T), where T is an
  890. * <code>AffineTransform</code> represented by the following matrix:
  891. * <pre>
  892. * [ 1 0 tx ]
  893. * [ 0 1 ty ]
  894. * [ 0 0 1 ]
  895. * </pre>
  896. * @param tx the distance to translate along the x-axis
  897. * @param ty the distance to translate along the y-axis
  898. */
  899. public abstract void translate(double tx, double ty);
  900. /**
  901. * Concatenates the current <code>Graphics2D</code>
  902. * <code>Transform</code> with a rotation transform.
  903. * Subsequent rendering is rotated by the specified radians relative
  904. * to the previous origin.
  905. * This is equivalent to calling <code>transform(R)</code>, where R is an
  906. * <code>AffineTransform</code> represented by the following matrix:
  907. * <pre>
  908. * [ cos(theta) -sin(theta) 0 ]
  909. * [ sin(theta) cos(theta) 0 ]
  910. * [ 0 0 1 ]
  911. * </pre>
  912. * Rotating with a positive angle theta rotates points on the positive
  913. * x axis toward the positive y axis.
  914. * @param theta the angle of rotation in radians
  915. */
  916. public abstract void rotate(double theta);
  917. /**
  918. * Concatenates the current <code>Graphics2D</code>
  919. * <code>Transform</code> with a translated rotation
  920. * transform. Subsequent rendering is transformed by a transform
  921. * which is constructed by translating to the specified location,
  922. * rotating by the specified radians, and translating back by the same
  923. * amount as the original translation. This is equivalent to the
  924. * following sequence of calls:
  925. * <pre>
  926. * translate(x, y);
  927. * rotate(theta);
  928. * translate(-x, -y);
  929. * </pre>
  930. * Rotating with a positive angle theta rotates points on the positive
  931. * x axis toward the positive y axis.
  932. * @param theta the angle of rotation in radians
  933. * @param x, y coordinates of the origin of the rotation
  934. */
  935. public abstract void rotate(double theta, double x, double y);
  936. /**
  937. * Concatenates the current <code>Graphics2D</code>
  938. * <code>Transform</code> with a scaling transformation
  939. * Subsequent rendering is resized according to the specified scaling
  940. * factors relative to the previous scaling.
  941. * This is equivalent to calling <code>transform(S)</code>, where S is an
  942. * <code>AffineTransform</code> represented by the following matrix:
  943. * <pre>
  944. * [ sx 0 0 ]
  945. * [ 0 sy 0 ]
  946. * [ 0 0 1 ]
  947. * </pre>
  948. * @param sx the amount by which X coordinates in subsequent
  949. * rendering operations are multiplied relative to previous
  950. * rendering operations.
  951. * @param sy the amount by which Y coordinates in subsequent
  952. * rendering operations are multiplied relative to previous
  953. * rendering operations.
  954. */
  955. public abstract void scale(double sx, double sy);
  956. /**
  957. * Concatenates the current <code>Graphics2D</code>
  958. * <code>Transform</code> with a shearing transform.
  959. * Subsequent renderings are sheared by the specified
  960. * multiplier relative to the previous position.
  961. * This is equivalent to calling <code>transform(SH)</code>, where SH
  962. * is an <code>AffineTransform</code> represented by the following
  963. * matrix:
  964. * <pre>
  965. * [ 1 shx 0 ]
  966. * [ shy 1 0 ]
  967. * [ 0 0 1 ]
  968. * </pre>
  969. * @param shx the multiplier by which coordinates are shifted in
  970. * the positive X axis direction as a function of their Y coordinate
  971. * @param shy the multiplier by which coordinates are shifted in
  972. * the positive Y axis direction as a function of their X coordinate
  973. */
  974. public abstract void shear(double shx, double shy);
  975. /**
  976. * Composes an <code>AffineTransform</code> object with the
  977. * <code>Transform</code> in this <code>Graphics2D</code> according
  978. * to the rule last-specified-first-applied. If the current
  979. * <code>Transform</code> is Cx, the result of composition
  980. * with Tx is a new <code>Transform</code> Cx'. Cx' becomes the
  981. * current <code>Transform</code> for this <code>Graphics2D</code>.
  982. * Transforming a point p by the updated <code>Transform</code> Cx' is
  983. * equivalent to first transforming p by Tx and then transforming
  984. * the result by the original <code>Transform</code> Cx. In other
  985. * words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary,
  986. * so further modifications to Tx do not affect rendering.
  987. * @param Tx the <code>AffineTransform</code> object to be composed with
  988. * the current <code>Transform</code>
  989. * @see #setTransform
  990. * @see AffineTransform
  991. */
  992. public abstract void transform(AffineTransform Tx);
  993. /**
  994. * Sets the <code>Transform</code> in the <code>Graphics2D</code>
  995. * context.
  996. * @param Tx the <code>AffineTransform</code> object to be used in the
  997. * rendering process
  998. * @see #transform
  999. * @see AffineTransform
  1000. */
  1001. public abstract void setTransform(AffineTransform Tx);
  1002. /**
  1003. * Returns a copy of the current <code>Transform</code> in the
  1004. * <code>Graphics2D</code> context.
  1005. * @return the current <code>AffineTransform</code> in the
  1006. * <code>Graphics2D</code> context.
  1007. * @see #transform
  1008. * @see #setTransform
  1009. */
  1010. public abstract AffineTransform getTransform();
  1011. /**
  1012. * Returns the current <code>Paint</code> of the
  1013. * <code>Graphics2D</code> context.
  1014. * @return the current <code>Graphics2D</code> <code>Paint</code>,
  1015. * which defines a color or pattern.
  1016. * @see #setPaint
  1017. * @see java.awt.Graphics#setColor
  1018. */
  1019. public abstract Paint getPaint();
  1020. /**
  1021. * Returns the current <code>Composite</code> in the
  1022. * <code>Graphics2D</code> context.
  1023. * @return the current <code>Graphics2D</code> <code>Composite</code>,
  1024. * which defines a compositing style.
  1025. * @see #setComposite
  1026. */
  1027. public abstract Composite getComposite();
  1028. /**
  1029. * Sets the background color for the <code>Graphics2D</code> context.
  1030. * The background color is used for clearing a region.
  1031. * When a <code>Graphics2D</code> is constructed for a
  1032. * <code>Component</code>, the background color is
  1033. * inherited from the <code>Component</code>. Setting the background color
  1034. * in the <code>Graphics2D</code> context only affects the subsequent
  1035. * <code>clearRect</code> calls and not the background color of the
  1036. * <code>Component</code>. To change the background
  1037. * of the <code>Component</code>, use appropriate methods of
  1038. * the <code>Component</code>.
  1039. * @param color the background color that isused in
  1040. * subsequent calls to <code>clearRect</code>
  1041. * @see #getBackground
  1042. * @see java.awt.Graphics#clearRect
  1043. */
  1044. public abstract void setBackground(Color color);
  1045. /**
  1046. * Returns the background color used for clearing a region.
  1047. * @return the current <code>Graphics2D</code> <code>Color</code>,
  1048. * which defines the background color.
  1049. * @see #setBackground
  1050. */
  1051. public abstract Color getBackground();
  1052. /**
  1053. * Returns the current <code>Stroke</code> in the
  1054. * <code>Graphics2D</code> context.
  1055. * @return the current <code>Graphics2D</code> <code>Stroke</code>,
  1056. * which defines the line style.
  1057. * @see #setStroke
  1058. */
  1059. public abstract Stroke getStroke();
  1060. /**
  1061. * Intersects the current <code>Clip</code> with the interior of the
  1062. * specified <code>Shape</code> and sets the <code>Clip</code> to the
  1063. * resulting intersection. The specified <code>Shape</code> is
  1064. * transformed with the current <code>Graphics2D</code>
  1065. * <code>Transform</code> before being intersected with the current
  1066. * <code>Clip</code>. This method is used to make the current
  1067. * <code>Clip</code> smaller.
  1068. * To make the <code>Clip</code> larger, use <code>setClip</code>.
  1069. * The <i>user clip</i> modified by this method is independent of the
  1070. * clipping associated with device bounds and visibility. If no clip has
  1071. * previously been set, or if the clip has been cleared using
  1072. * {@link Graphics#setClip(Shape) setClip} with a <code>null</code>
  1073. * argument, the specified <code>Shape</code> becomes the new
  1074. * user clip.
  1075. * @param s the <code>Shape</code> to be intersected with the current
  1076. * <code>Clip</code>. If <code>s</code> is <code>null</code>,
  1077. * this method clears the current <code>Clip</code>.
  1078. */
  1079. public abstract void clip(Shape s);
  1080. /**
  1081. * Get the rendering context of the <code>Font</code> within this
  1082. * <code>Graphics2D</code> context.
  1083. * The {@link FontRenderContext}
  1084. * encapsulates application hints such as anti-aliasing and
  1085. * fractional metrics, as well as target device specific information
  1086. * such as dots-per-inch. This information should be provided by the
  1087. * application when using objects that perform typographical
  1088. * formatting, such as <code>Font</code> and
  1089. * <code>TextLayout</code>. This information should also be provided
  1090. * by applications that perform their own layout and need accurate
  1091. * measurements of various characteristics of glyphs such as advance
  1092. * and line height when various rendering hints have been applied to
  1093. * the text rendering.
  1094. *
  1095. * @return a reference to an instance of FontRenderContext.
  1096. * @see java.awt.font.FontRenderContext
  1097. * @see java.awt.Font#createGlyphVector
  1098. * @see java.awt.font.TextLayout
  1099. * @since JDK1.2
  1100. */
  1101. public abstract FontRenderContext getFontRenderContext();
  1102. }