📄 psgraphics.java
字号:
/* * class PSGraphics - a PrintGraphics PostScript implementation * * Copyright (c) 1998 * Transvirtual Technologies, Inc. All rights reserved. * * Copyright (c) 2004 * The Kaffe.org's developers. See ChangeLog for details. * * See the file "license.terms" for information on usage and redistribution * of this file. * * @author J.Mehlitz */package java.awt;import java.awt.image.ColorModel;import java.awt.image.ImageConsumer;import java.awt.image.ImageObserver;import java.awt.image.ImageProducer;import java.io.FileOutputStream;import java.io.IOException;import java.io.PrintStream;import java.util.Hashtable;public class PSGraphics extends Graphics implements PrintGraphics{ PrintStream ps; Font fnt; Color clr; static float dpm = (float)2.835; static float dpi = 72; static float scaleX; static float scaleY; static int maxScaledWidth; static int maxScaledHeight; static int bxl; static int bxr; static int byt; static int byb; PrintJob pj;static { tuneDevice( 10, 10, 10, 10, "Letter");}public PSGraphics ( PrintStream ps) { this.ps = ps; printProlog();}public PSGraphics ( String pathName) { try { ps = new PrintStream( new FileOutputStream( pathName)); printProlog(); } catch ( IOException e) {}}void arc ( int x0, int y0, float r, int startAngle, int endAngle){ ps.print( x0); ps.print( " "); ps.print( y0); ps.print( " "); ps.print( r); ps.print( " "); ps.print( startAngle); ps.print( " "); ps.print( endAngle); ps.println( " arc");}void arcTo ( int x1, int y1, int x2, int y2, int ah){ ps.print( x1); ps.print( " "); ps.print( y1); ps.print( " "); ps.print( x2); ps.print( " "); ps.print( y2); ps.print( " "); ps.print( ah); ps.println( " arcto"); ps.println( "4 {pop} repeat");}public void clearRect ( int x, int y, int width, int height ) { ps.println( "gsave"); ps.println( "1 1 1 setrgbcolor"); psRect( x, y, width, height, true); ps.println( "grestore");}public void clipRect ( int x, int y, int width, int height ) {}public void copyArea ( int x, int y, int width, int height, int dx, int dy ){}public Graphics create () { return this;}public void dispose () { ps.flush(); try { ps.close(); } catch ( Exception e) {}}public void draw3DRect ( int x, int y, int width, int height, boolean raised ){ Color c1 = clr.brighter(); Color c2 = clr.darker(); setColor( raised ? c1 : c2); drawLine( x, y, x, y + height); drawLine( x + 1, y, x + width - 1, y); setColor( raised ? c2 : c1); drawLine( x + 1, y + height, x + width, y + height); drawLine( x + width, y, x + width, y + height); setColor( clr);}public void drawArc ( int x, int y, int width, int height) { psArc( x, y, width, height, 0, 360, false);}public void drawArc ( int x, int y, int width, int height, int startAngle, int arcAngle ){ psArc( x, y, width, height, startAngle, arcAngle, false);}public void drawBytes ( byte data[], int offset, int length, int x, int y ){ y = maxScaledHeight - y; moveTo( x, y, true); ps.print( "(" ); ps.write( data, offset, length); ps.println( ") show stroke");}public void drawChars ( char data[], int offset, int length, int x, int y ){ drawString( new String( data, offset, length), x, y);}public boolean drawImage (Image img, int x, int y, Color bgcolor, ImageObserver observer) { return drawImage( img, x, y, 0, 0, bgcolor, observer);}public boolean drawImage ( Image img, int x, int y, ImageObserver observer) { return drawImage( img, x, y, 0, 0, null, observer);}public boolean drawImage ( Image img, int x, int y, int width, int height, Color background, ImageObserver observer ) { return psImage( img, x, y, width, height, observer, background);}public boolean drawImage ( Image img, int x, int y, int width, int height, ImageObserver observer){ return drawImage( img, x, y, width, height, null, observer);}public boolean drawImage ( Image img, int dx0, int dy0, int dx1, int dy1, int sx0, int sy0, int sx1, int sy1, Color bgColor, ImageObserver observer) { return false;}public boolean drawImage ( Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { return false;}void drawImgScaled ( Image img, int dx0, int dy0, int dx1, int dy1, int sx0, int sy0, int sx1, int sy1, Color background ){}public void drawLine ( int x1, int y1, int x2, int y2 ){ y1 = maxScaledHeight - y1; y2 = maxScaledHeight - y2; moveTo( x1, y1, true); lineTo( x2, y2, true); stroke( false);}public void drawOval ( int x, int y, int width, int height ){ psArc( x, y, width, height, 0, 360, false);}public void drawPolygon ( Polygon p ){ psPoly( p.xpoints, p.ypoints, p.npoints, false);}public void drawPolygon ( int xPoints[], int yPoints[], int nPoints ){ psPoly( xPoints, yPoints, nPoints, false);}public void drawPolyline ( int xPoints[], int yPoints[], int nPoints ){ psPoly( xPoints, yPoints, nPoints, false);}public void drawRect ( int x, int y, int width, int height ){ psRect( x, y, width, height, false);}public void drawRoundRect ( int x, int y, int width, int height, int arcWidth, int arcHeight){ psRoundRect( x, y, width, height, arcWidth, arcHeight, false);}public void drawString ( String str, int x, int y ){ y = maxScaledHeight - y; moveTo( x, y, true); ps.print( '('); ps.print( str); ps.print( ") show " ); stroke( false);}public void fill3DRect ( int x, int y, int width, int height, boolean raised ){ Color c1 = clr.brighter(); Color c2 = clr.darker(); if ( !raised ) setColor( c2); fillRect( x + 1, y + 1, width - 2, height - 2); setColor( raised ? c1 : c2); drawLine( x, y, x, y + height - 1); drawLine( x + 1, y, x + width - 2, y); setColor( raised ? c2 : c1); drawLine( x + 1, y + height - 1, x + width - 1, y + height - 1); drawLine( x + width - 1, y, x + width - 1, y + height - 1); setColor( clr);}public void fillArc ( int x, int y, int width, int height, int startAngle, int arcAngle ){ psArc( x, y, width, height, startAngle, arcAngle, true);}public void fillOval ( int x, int y, int width, int height ){ psArc( x, y, width, height, 0, 360, true);}public void fillPolygon ( Polygon p ){ psPoly( p.xpoints, p.ypoints, p.npoints, true);}public void fillPolygon ( int xPoints[], int yPoints[], int nPoints ){ psPoly( xPoints, yPoints, nPoints, false);}public void fillRect ( int x, int y, int width, int height ){ psRect( x, y, width, height, true);}public void fillRoundRect ( int x, int y, int width, int height, int arcWidth, int arcHeight ){ psRoundRect( x, y, width, height, arcWidth, arcHeight, true);}protected void finalize () throws Throwable { dispose(); super.finalize();}public Shape getClip (){ return null;}public Rectangle getClipBounds() { return null;}public Rectangle getClipBounds(Rectangle rect) { return rect;}public Color getColor() { return clr;}public Font getFont() { return fnt;}public FontMetrics getFontMetrics () { return FontMetrics.getFontMetrics( fnt);}public FontMetrics getFontMetrics ( Font fnt ) { return FontMetrics.getFontMetrics( fnt);}String getPSFont (){ String psn; String jn = fnt.getName(); int js = fnt.getStyle(); if ( jn.equals( "Times") ) { psn = "Times-"; if ( js == Font.PLAIN ) psn += "Roman"; if ( (js & Font.BOLD) > 0 ) psn += "Bold"; if ( (js & Font.ITALIC) > 0 ) psn += "Italic"; } else if ( jn.equals( "Helvetica") ) { psn = "Helvetica"; if ( js != Font.PLAIN ) psn += "-"; if ( (js & Font.BOLD) > 0 ) psn += "Bold"; if ( (js & Font.ITALIC) > 0 ) psn += "Oblique"; } else if ( jn.equals( "Courier") ) { psn = "Courier"; if ( js != Font.PLAIN ) psn += "-"; if ( (js & Font.BOLD) > 0 ) psn += "Bold"; if ( (js & Font.ITALIC) > 0 ) psn += "Oblique"; } else if ( jn.equals( "Symbol") ) psn = "Symbol"; else psn = "Courier"; return psn;}public PrintJob getPrintJob() { return pj;}void lineTo ( int x, int y, boolean cont){ ps.print( x); ps.print( " "); ps.print( y); if ( cont ) ps.print( " lineto "); else ps.println( " lineto ");}void moveTo ( int x, int y, boolean cont){ ps.print( x); ps.print( " "); ps.print( y);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -