ppgraphics2d.java
来自「EXCEL read and write」· Java 代码 · 共 1,499 行 · 第 1/5 页
JAVA
1,499 行
* formatting, such as <code>Font</code> and * <code>TextLayout</code>. This information should also be provided * by applications that perform their own layout and need accurate * measurements of various characteristics of glyphs such as advance * and line height when various rendering hints have been applied to * the text rendering. * * @return a reference to an instance of FontRenderContext. * @see java.awt.font.FontRenderContext * @see java.awt.Font#createGlyphVector(FontRenderContext,char[]) * @see java.awt.font.TextLayout * @since JDK1.2 */ public FontRenderContext getFontRenderContext() { boolean isAntiAliased = RenderingHints.VALUE_TEXT_ANTIALIAS_ON.equals( getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING)); boolean usesFractionalMetrics = RenderingHints.VALUE_FRACTIONALMETRICS_ON.equals( getRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS)); return new FontRenderContext(new AffineTransform(), isAntiAliased, usesFractionalMetrics); } /** * Composes an <code>AffineTransform</code> object with the * <code>Transform</code> in this <code>Graphics2D</code> according * to the rule last-specified-first-applied. If the current * <code>Transform</code> is Cx, the result of composition * with Tx is a new <code>Transform</code> Cx'. Cx' becomes the * current <code>Transform</code> for this <code>Graphics2D</code>. * Transforming a point p by the updated <code>Transform</code> Cx' is * equivalent to first transforming p by Tx and then transforming * the result by the original <code>Transform</code> Cx. In other * words, Cx'(p) = Cx(Tx(p)). A copy of the Tx is made, if necessary, * so further modifications to Tx do not affect rendering. * @param Tx the <code>AffineTransform</code> object to be composed with * the current <code>Transform</code> * @see #setTransform * @see AffineTransform */ public void transform(AffineTransform Tx) { transform.concatenate(Tx); } /** * Renders a <code>BufferedImage</code> that is * filtered with a * {@link BufferedImageOp}. * The rendering attributes applied include the <code>Clip</code>, * <code>Transform</code> * and <code>Composite</code> attributes. This is equivalent to: * <pre> * img1 = op.filter(img, null); * drawImage(img1, new AffineTransform(1f,0f,0f,1f,x,y), null); * </pre> * @param img the <code>BufferedImage</code> to be rendered * @param op the filter to be applied to the image before rendering * @param x the x coordinate in user space where the image is rendered * @param y the y coordinate in user space where the image is rendered * @see #transform * @see #setTransform * @see #setComposite * @see #clip * @see #setClip(Shape) */ public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y){ img = op.filter(img, null); drawImage(img, x, y, null); } /** * Sets the background color for the <code>Graphics2D</code> context. * The background color is used for clearing a region. * When a <code>Graphics2D</code> is constructed for a * <code>Component</code>, the background color is * inherited from the <code>Component</code>. Setting the background color * in the <code>Graphics2D</code> context only affects the subsequent * <code>clearRect</code> calls and not the background color of the * <code>Component</code>. To change the background * of the <code>Component</code>, use appropriate methods of * the <code>Component</code>. * @param color the background color that isused in * subsequent calls to <code>clearRect</code> * @see #getBackground * @see java.awt.Graphics#clearRect */ public void setBackground(Color color) { if(color == null) return; background = color; } /** * Returns the background color used for clearing a region. * @return the current <code>Graphics2D</code> <code>Color</code>, * which defines the background color. * @see #setBackground */ public Color getBackground(){ return background; } /** * Sets the <code>Composite</code> for the <code>Graphics2D</code> context. * The <code>Composite</code> is used in all drawing methods such as * <code>drawImage</code>, <code>drawString</code>, <code>draw</code>, * and <code>fill</code>. It specifies how new pixels are to be combined * with the existing pixels on the graphics device during the rendering * process. * <p>If this <code>Graphics2D</code> context is drawing to a * <code>Component</code> on the display screen and the * <code>Composite</code> is a custom object rather than an * instance of the <code>AlphaComposite</code> class, and if * there is a security manager, its <code>checkPermission</code> * method is called with an <code>AWTPermission("readDisplayPixels")</code> * permission. * * @param comp the <code>Composite</code> object to be used for rendering * @throws SecurityException * if a custom <code>Composite</code> object is being * used to render to the screen and a security manager * is set and its <code>checkPermission</code> method * does not allow the operation. * @see java.awt.Graphics#setXORMode * @see java.awt.Graphics#setPaintMode * @see java.awt.AlphaComposite */ public void setComposite(Composite comp){ log.log(POILogger.WARN, "Not implemented"); } /** * Returns the current <code>Composite</code> in the * <code>Graphics2D</code> context. * @return the current <code>Graphics2D</code> <code>Composite</code>, * which defines a compositing style. * @see #setComposite */ public Composite getComposite(){ log.log(POILogger.WARN, "Not implemented"); return null; } /** * Returns the value of a single preference for the rendering algorithms. * Hint categories include controls for rendering quality and overall * time/quality trade-off in the rendering process. Refer to the * <code>RenderingHints</code> class for definitions of some common * keys and values. * @param hintKey the key corresponding to the hint to get. * @return an object representing the value for the specified hint key. * Some of the keys and their associated values are defined in the * <code>RenderingHints</code> class. * @see RenderingHints */ public Object getRenderingHint(RenderingHints.Key hintKey){ return hints.get(hintKey); } /** * Sets the value of a single preference for the rendering algorithms. * Hint categories include controls for rendering quality and overall * time/quality trade-off in the rendering process. Refer to the * <code>RenderingHints</code> class for definitions of some common * keys and values. * @param hintKey the key of the hint to be set. * @param hintValue the value indicating preferences for the specified * hint category. * @see RenderingHints */ public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue){ hints.put(hintKey, hintValue); } /** * Renders the text of the specified * {@link GlyphVector} using * the <code>Graphics2D</code> context's rendering attributes. * The rendering attributes applied include the <code>Clip</code>, * <code>Transform</code>, <code>Paint</code>, and * <code>Composite</code> attributes. The <code>GlyphVector</code> * specifies individual glyphs from a {@link Font}. * The <code>GlyphVector</code> can also contain the glyph positions. * This is the fastest way to render a set of characters to the * screen. * * @param g the <code>GlyphVector</code> to be rendered * @param x the x position in user space where the glyphs should be * rendered * @param y the y position in user space where the glyphs should be * rendered * * @see java.awt.Font#createGlyphVector(FontRenderContext, char[]) * @see java.awt.font.GlyphVector * @see #setPaint * @see java.awt.Graphics#setColor * @see #setTransform * @see #setComposite * @see #setClip(Shape) */ public void drawGlyphVector(GlyphVector g, float x, float y) { Shape glyphOutline = g.getOutline(x, y); fill(glyphOutline); } /** * Returns the device configuration associated with this * <code>Graphics2D</code>. * @return the device configuration */ public GraphicsConfiguration getDeviceConfiguration() { return GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); } /** * Sets the values of an arbitrary number of preferences for the * rendering algorithms. * Only values for the rendering hints that are present in the * specified <code>Map</code> object are modified. * All other preferences not present in the specified * object are left unmodified. * Hint categories include controls for rendering quality and * overall time/quality trade-off in the rendering process. * Refer to the <code>RenderingHints</code> class for definitions of * some common keys and values. * @param hints the rendering hints to be set * @see RenderingHints */ public void addRenderingHints(Map hints){ this.hints.putAll(hints); } /** * Concatenates the current * <code>Graphics2D</code> <code>Transform</code> * with a translation transform. * Subsequent rendering is translated by the specified * distance relative to the previous position. * This is equivalent to calling transform(T), where T is an * <code>AffineTransform</code> represented by the following matrix: * <pre> * [ 1 0 tx ] * [ 0 1 ty ] * [ 0 0 1 ] * </pre> * @param tx the distance to translate along the x-axis * @param ty the distance to translate along the y-axis */ public void translate(double tx, double ty){ transform.translate(tx, ty); } /** * Renders the text of the specified iterator, using the * <code>Graphics2D</code> context's current <code>Paint</code>. The * iterator must specify a font * for each character. The baseline of the * first character is at position (<i>x</i>, <i>y</i>) in the * User Space. * The rendering attributes applied include the <code>Clip</code>, * <code>Transform</code>, <code>Paint</code>, and * <code>Composite</code> attributes. * For characters in script systems such as Hebrew and Arabic, * the glyphs can be rendered from right to left, in which case the * coordinate supplied is the location of the leftmost character * on the baseline. * @param iterator the iterator whose text is to be rendered * @param x the x coordinate where the iterator's text is to be * rendered * @param y the y coordinate where the iterator's text is to be * rendered * @see #setPaint * @see java.awt.Graphics#setColor * @see #setTransform * @see #setComposite * @see #setClip */ public void drawString(AttributedCharacterIterator iterator, float x, float y) { log.log(POILogger.WARN, "Not implemented"); } /** * Checks whether or not the specified <code>Shape</code> intersects * the specified {@link Rectangle}, which is in device * space. If <code>onStroke</code> is false, this method checks * whether or not the interior of the specified <code>Shape</code> * intersects the specified <code>Rectangle</code>. If * <code>onStroke</code> is <code>true</code>, this method checks * whether or not the <code>Stroke</code> of the specified * <code>Shape</code> outline intersects the specified * <code>Rectangle</code>. * The rendering attributes taken into account include the * <code>Clip</code>,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?