📄 gdkgraphics2d.java
字号:
} public boolean drawImage(Image img, int x, int y, ImageObserver observer) { return drawImage(img, new AffineTransform(1f, 0f, 0f, 1f, x, y), bg, observer); } /////////////////////////////////////////////// ////// Unimplemented Stubs and Overloads ////// /////////////////////////////////////////////// public boolean hit(Rectangle rect, Shape text, boolean onStroke) { throw new java.lang.UnsupportedOperationException(); } public GraphicsConfiguration getDeviceConfiguration() { throw new java.lang.UnsupportedOperationException(); } public void setComposite(Composite comp) { this.comp = comp; if (comp instanceof AlphaComposite) { AlphaComposite a = (AlphaComposite) comp; cairoSetOperator(a.getRule()); Color c = getColor(); setColor(new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (a.getAlpha() * ((float) c.getAlpha())))); } else throw new java.lang.UnsupportedOperationException(); } public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) { hints.put(hintKey, hintValue); if (hintKey.equals(RenderingHints.KEY_INTERPOLATION) || hintKey.equals(RenderingHints.KEY_ALPHA_INTERPOLATION)) { if (hintValue.equals(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) cairoSurfaceSetFilter(0); else if (hintValue.equals(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) cairoSurfaceSetFilter(1); else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)) cairoSurfaceSetFilter(2); else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)) cairoSurfaceSetFilter(3); else if (hintValue.equals(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)) cairoSurfaceSetFilter(4); } shiftDrawCalls = hints.containsValue(RenderingHints.VALUE_STROKE_NORMALIZE) || hints.containsValue(RenderingHints.VALUE_STROKE_DEFAULT); } public Object getRenderingHint(RenderingHints.Key hintKey) { return hints.get(hintKey); } public void setRenderingHints(Map hints) { this.hints = new RenderingHints(getDefaultHints()); this.hints.add(new RenderingHints(hints)); if (hints.containsKey(RenderingHints.KEY_INTERPOLATION)) { if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) cairoSurfaceSetFilter(0); else if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) cairoSurfaceSetFilter(1); } if (hints.containsKey(RenderingHints.KEY_ALPHA_INTERPOLATION)) { if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)) cairoSurfaceSetFilter(2); else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)) cairoSurfaceSetFilter(3); else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)) cairoSurfaceSetFilter(4); } shiftDrawCalls = hints.containsValue(RenderingHints.VALUE_STROKE_NORMALIZE) || hints.containsValue(RenderingHints.VALUE_STROKE_DEFAULT); } public void setRenderingHintsUnlocked(Map hints) { this.hints = new RenderingHints(getDefaultHints()); this.hints.add(new RenderingHints(hints)); if (hints.containsKey(RenderingHints.KEY_INTERPOLATION)) { if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR)) cairoSurfaceSetFilterUnlocked(0); else if (hints.containsValue(RenderingHints.VALUE_INTERPOLATION_BILINEAR)) cairoSurfaceSetFilterUnlocked(1); } if (hints.containsKey(RenderingHints.KEY_ALPHA_INTERPOLATION)) { if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED)) cairoSurfaceSetFilterUnlocked(2); else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY)) cairoSurfaceSetFilterUnlocked(3); else if (hints.containsValue(RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT)) cairoSurfaceSetFilterUnlocked(4); } shiftDrawCalls = hints.containsValue(RenderingHints.VALUE_STROKE_NORMALIZE) || hints.containsValue(RenderingHints.VALUE_STROKE_DEFAULT); } public void addRenderingHints(Map hints) { this.hints.add(new RenderingHints(hints)); } public RenderingHints getRenderingHints() { return hints; } public Composite getComposite() { if (comp == null) return AlphaComposite.SrcOver; else return comp; } public FontRenderContext getFontRenderContext() { return new FontRenderContext(transform, true, true); } public void copyArea(int x, int y, int width, int height, int dx, int dy) { GdkGraphics2D g = (GdkGraphics2D) create(x, y, width, height); gdkDrawDrawable(g, x + dx, y + dy); } public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { draw(new Arc2D.Double((double) x, (double) y, (double) width, (double) height, (double) startAngle, (double) arcAngle, Arc2D.OPEN)); } public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { return drawImage(img, x, y, img.getWidth(observer), img.getHeight(observer), bgcolor, observer); } public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) { double scaleX = width / (double) img.getWidth(observer); double scaleY = height / (double) img.getHeight(observer); return drawImage(img, new AffineTransform(scaleX, 0f, 0f, scaleY, x, y), bgcolor, observer); } public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) { return drawImage(img, x, y, width, height, bg, observer); } public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) { if (img == null) return false; Image subImage; int sourceWidth = sx2 - sx1; int sourceHeight = sy2 - sy1; int destWidth = dx2 - dx1; int destHeight = dy2 - dy1; double scaleX = destWidth / (double) sourceWidth; double scaleY = destHeight / (double) sourceHeight; // Get the subimage of the source enclosed in the // rectangle specified by sx1, sy1, sx2, sy2 if (img instanceof BufferedImage) { BufferedImage b = (BufferedImage) img; subImage = b.getSubimage(sx1, sy1, sx2, sy2); } else { // FIXME: This code currently doesn't work. Null Pointer // exception is thrown in this case. This happens // because img.getSource() always returns null, since source gets // never initialized when it is created with the help of // createImage(int width, int height). CropImageFilter filter = new CropImageFilter(sx1, sx2, sx2, sy2); FilteredImageSource src = new FilteredImageSource(img.getSource(), filter); subImage = Toolkit.getDefaultToolkit().createImage(src); } return drawImage(subImage, new AffineTransform(scaleX, 0, 0, scaleY, dx1, dy1), bgcolor, observer); } public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bg, observer); } public void drawOval(int x, int y, int width, int height) { drawArc(x, y, width, height, 0, 360); } public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { if (arcWidth > width) arcWidth = width; if (arcHeight > height) arcHeight = height; int xx = x + width - arcWidth; int yy = y + height - arcHeight; drawArc(x, y, arcWidth, arcHeight, 90, 90); drawArc(xx, y, arcWidth, arcHeight, 0, 90); drawArc(xx, yy, arcWidth, arcHeight, 270, 90); drawArc(x, yy, arcWidth, arcHeight, 180, 90); int y1 = y + arcHeight / 2; int y2 = y + height - arcHeight / 2; drawLine(x, y1, x, y2); drawLine(x + width, y1, x + width, y2); int x1 = x + arcWidth / 2; int x2 = x + width - arcWidth / 2; drawLine(x1, y, x2, y); drawLine(x1, y + height, x2, y + height); } // these are the most accelerated painting paths native void cairoDrawGlyphVector(GdkFontPeer font, float x, float y, int n, int[] codes, float[] positions); native void cairoDrawGdkTextLayout(GdkTextLayout gl, float x, float y); GdkFontPeer getFontPeer() { return (GdkFontPeer) getFont().getPeer(); } public void drawGdkTextLayout(GdkTextLayout gl, float x, float y) { cairoDrawGdkTextLayout (gl, x, y); updateBufferedImage (); } public void drawString(String str, float x, float y) { if (str == null || str.length() == 0) return; drawGlyphVector(getFont().createGlyphVector(null, str), x, y); updateBufferedImage (); } public void drawString(String str, int x, int y) { drawString (str, (float) x, (float) y); } public void drawString(AttributedCharacterIterator ci, int x, int y) { drawString (ci, (float) x, (float) y); } public void drawGlyphVector(GlyphVector gv, float x, float y) { int n = gv.getNumGlyphs (); int[] codes = gv.getGlyphCodes (0, n, null); float[] positions = gv.getGlyphPositions (0, n, null); setFont (gv.getFont ()); cairoDrawGlyphVector (getFontPeer(), x, y, n, codes, positions); updateBufferedImage (); } public void drawString(AttributedCharacterIterator ci, float x, float y) { GlyphVector gv = getFont().createGlyphVector(getFontRenderContext(), ci); drawGlyphVector(gv, x, y); } public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { fill(new Arc2D.Double((double) x, (double) y, (double) width, (double) height, (double) startAngle, (double) arcAngle, Arc2D.OPEN)); } public void fillOval(int x, int y, int width, int height) { fillArc(x, y, width, height, 0, 360); } public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { if (arcWidth > width) arcWidth = width; if (arcHeight > height) arcHeight = height; int xx = x + width - arcWidth; int yy = y + height - arcHeight; fillArc(x, y, arcWidth, arcHeight, 90, 90); fillArc(xx, y, arcWidth, arcHeight, 0, 90); fillArc(xx, yy, arcWidth, arcHeight, 270, 90); fillArc(x, yy, arcWidth, arcHeight, 180, 90); fillRect(x, y + arcHeight / 2, width, height - arcHeight + 1); fillRect(x + arcWidth / 2, y, width - arcWidth + 1, height); } public Font getFont() { if (font == null) return new Font("SansSerif", Font.PLAIN, 12); return font; } // Until such time as pango is happy to talk directly to cairo, we // actually need to redirect some calls from the GtkFontPeer and // GtkFontMetrics into the drawing kit and ask cairo ourselves. static native void releasePeerGraphicsResource(GdkFontPeer f); public FontMetrics getFontMetrics() { return getFontMetrics(getFont()); } public FontMetrics getFontMetrics(Font f) { // the reason we go via the toolkit here is to try to get // a cached object. the toolkit keeps such a cache. return Toolkit.getDefaultToolkit().getFontMetrics(f); } public void setFont(Font f) { // Sun's JDK does not throw NPEs, instead it leaves the current setting // unchanged. So do we. if (f == null) return; if (f.getPeer() instanceof GdkFontPeer) font = f; else font = ((ClasspathToolkit)(Toolkit.getDefaultToolkit())) .getFont(f.getName(), f.getAttributes()); } public void setFontUnlocked(Font f) { setFont (f); } public String toString() { return (getClass().getName() + "[font=" + getFont().toString() + ",color=" + fg.toString() + "]"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -