📄 pdfgraphics2d.java
字号:
transform.rotate(theta, x, y); } /** * @see Graphics2D#scale(double, double) */ public void scale(double sx, double sy) { transform.scale(sx, sy); } /** * @see Graphics2D#shear(double, double) */ public void shear(double shx, double shy) { transform.shear(shx, shy); } /** * @see Graphics2D#transform(AffineTransform) */ public void transform(AffineTransform tx) { transform.concatenate(tx); } /** * @see Graphics2D#setTransform(AffineTransform) */ public void setTransform(AffineTransform t) { transform=t; } /** * @see Graphics2D#getTransform() */ public AffineTransform getTransform() { return new AffineTransform(transform); } /** * @see Graphics2D#getPaint() */ public Paint getPaint() { return paint; } /** * @see Graphics2D#getComposite() */ public Composite getComposite() { return null; } /** * @see Graphics2D#setBackground(Color) */ public void setBackground(Color color) { background = color; } /** * @see Graphics2D#getBackground() */ public Color getBackground() { return background; } /** * @see Graphics2D#getStroke() */ public Stroke getStroke() { return stroke; } /** * @see Graphics2D#getFontRenderContext() */ public FontRenderContext getFontRenderContext() { return new FontRenderContext(null, true, true); } /** * @see Graphics#create() */ public Graphics create() { PdfGraphics2D g2 = new PdfGraphics2D(); g2.onlyShapes = this.onlyShapes; g2.transform = new AffineTransform(this.transform); g2.baseFonts = this.baseFonts; g2.fontMapper = this.fontMapper; g2.kids = this.kids; g2.paint = this.paint; g2.background = this.background; g2.setFont(this.font); g2.stroke = this.stroke; g2.cb = this.cb.getDuplicate(); g2.cb.saveState(); g2.width = this.width; g2.height = this.height; g2.clip = new Area(new Rectangle2D.Float(0, 0, width, height)); g2.clip(g2.clip); g2.cb.saveState(); g2.followPath(this.clip, CLIP); g2.kid = true; synchronized (kids) { kids.add(g2); } return g2; } /** * @see Graphics#getColor() */ public Color getColor() { if (paint instanceof Color) { return (Color)paint; } else { return Color.black; } } /** * @see Graphics#setColor(Color) */ public void setColor(Color color) { setPaint(color); } /** * @see Graphics#setPaintMode() */ public void setPaintMode() {} /** * @see Graphics#setXORMode(Color) */ public void setXORMode(Color c1) { throw new UnsupportedOperationException(); } /** * @see Graphics#getFont() */ public Font getFont() { return font; } /** * @see Graphics#setFont(Font) */ /** * Sets the current font. */ public void setFont(Font f) { if (onlyShapes) { font = f; return; } if (f == font) return; fontMetrics = null; font = f; fontSize = f.getSize2D(); baseFont = getCachedBaseFont(f); } private BaseFont getCachedBaseFont(Font f) { synchronized (baseFonts) { BaseFont bf = (BaseFont)baseFonts.get(f.getFontName()); if (bf == null) { bf = fontMapper.awtToPdf(f); baseFonts.put(f.getFontName(), bf); } return bf; } } /** * @see Graphics#getFontMetrics(Font) */ public FontMetrics getFontMetrics(Font f) { if (onlyShapes) { return dg2.getFontMetrics(f); } if (f == font) { if (fontMetrics == null) fontMetrics = new PdfFontMetrics(f, getCachedBaseFont(f)); return fontMetrics; } return new PdfFontMetrics(f, getCachedBaseFont(f)); } /** * @see Graphics#getClipBounds() */ public Rectangle getClipBounds() { if (clip == null) return null; return getClip().getBounds(); } /** * @see Graphics#clipRect(int, int, int, int) */ public void clipRect(int x, int y, int width, int height) { Rectangle2D rect = new Rectangle2D.Double(x,y,width,height); clip(rect); } /** * @see Graphics#setClip(int, int, int, int) */ public void setClip(int x, int y, int width, int height) { Rectangle2D rect = new Rectangle2D.Double(x,y,width,height); setClip(rect); } /** * @see Graphics2D#clip(Shape) */ public void clip(Shape s) { if (s != null) s = transform.createTransformedShape(s); if (clip == null) clip = new Area(s); else clip.intersect(new Area(s)); followPath(s, CLIP); } /** * @see Graphics#getClip() */ public Shape getClip() { try { return transform.createInverse().createTransformedShape(clip); } catch (NoninvertibleTransformException e) { return null; } } /** * @see Graphics#setClip(Shape) */ public void setClip(Shape s) { cb.restoreState(); cb.saveState(); if (s != null) s = transform.createTransformedShape(s); if (s == null) { clip = null; } else { clip = new Area(s); followPath(s, CLIP); } setPaint(paint); } /** * @see Graphics#copyArea(int, int, int, int, int, int) */ public void copyArea(int x, int y, int width, int height, int dx, int dy) { throw new UnsupportedOperationException(); } /** * @see Graphics#drawLine(int, int, int, int) */ public void drawLine(int x1, int y1, int x2, int y2) { Line2D line = new Line2D.Double((double)x1, (double)y1, (double)x2, (double)y2); draw(line); } /** * @see Graphics#fillRect(int, int, int, int) */ public void drawRect(int x, int y, int width, int height) { draw(new Rectangle(x, y, width, height)); } /** * @see Graphics#fillRect(int, int, int, int) */ public void fillRect(int x, int y, int width, int height) { fill(new Rectangle(x,y,width,height)); } /** * @see Graphics#clearRect(int, int, int, int) */ public void clearRect(int x, int y, int width, int height) { setPaint(background); fillRect(x,y,width,height); setPaint(paint); } /** * @see Graphics#drawRoundRect(int, int, int, int, int, int) */ public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { RoundRectangle2D rect = new RoundRectangle2D.Double(x,y,width,height,arcWidth, arcHeight); draw(rect); } /** * @see Graphics#fillRoundRect(int, int, int, int, int, int) */ public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { RoundRectangle2D rect = new RoundRectangle2D.Double(x,y,width,height,arcWidth, arcHeight); fill(rect); } /** * @see Graphics#drawOval(int, int, int, int) */ public void drawOval(int x, int y, int width, int height) { Ellipse2D oval = new Ellipse2D.Float((float)x, (float)y, (float)width, (float)height); draw(oval); } /** * @see Graphics#fillOval(int, int, int, int) */ public void fillOval(int x, int y, int width, int height) { Ellipse2D oval = new Ellipse2D.Float((float)x, (float)y, (float)width, (float)height); fill(oval); } /** * @see Graphics#drawArc(int, int, int, int, int, int) */ public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { Arc2D arc = new Arc2D.Double(x,y,width,height,startAngle, arcAngle, Arc2D.OPEN); draw(arc); } /** * @see Graphics#fillArc(int, int, int, int, int, int) */ public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { Arc2D arc = new Arc2D.Double(x,y,width,height,startAngle, arcAngle, Arc2D.OPEN); fill(arc); } /** * @see Graphics#drawPolyline(int[], int[], int) */ public void drawPolyline(int[] x, int[] y, int nPoints) { Line2D line = new Line2D.Double(x[0],y[0],x[0],y[0]); for (int i = 1; i < nPoints; i++) { line.setLine(line.getX2(), line.getY2(), x[i], y[i]); draw(line); } } /** * @see Graphics#drawPolygon(int[], int[], int) */ public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) { Polygon poly = new Polygon(); for (int i = 0; i < nPoints; i++) { poly.addPoint(xPoints[i], yPoints[i]); } draw(poly); } /** * @see Graphics#fillPolygon(int[], int[], int) */ public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) { Polygon poly = new Polygon(); for (int i = 0; i < nPoints; i++) { poly.addPoint(xPoints[i], yPoints[i]); } fill(poly); } /** * @see Graphics#drawImage(Image, int, int, ImageObserver) */ public boolean drawImage(Image img, int x, int y, ImageObserver observer) { return drawImage(img, x, y, null, observer); } /** * @see Graphics#drawImage(Image, int, int, int, int, ImageObserver) */ public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) { return drawImage(img, x, y, width, height, null, observer); } /** * @see Graphics#drawImage(Image, int, int, Color, ImageObserver) */ 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); } /** * @see Graphics#drawImage(Image, int, int, int, int, Color, ImageObserver) */ 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); AffineTransform tx = AffineTransform.getTranslateInstance(x,y); tx.scale(scalex,scaley); return drawImage(img, null, tx, bgcolor, observer);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -