⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 postscript.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
				numSyncs++;			}		}		if (numSyncs == 0)			System.out.println("No PostScript files needed to be written");		return false;	}	/****************************** POSTSCRIPT OUTPUT METHODS ******************************/	/**	 * Method to set the PostScript color.	 * @param col the color to write.	 */	private void setColor(Color col)	{		if (psUseColor)		{			if (col.getRGB() != lastColor)			{				lastColor = col.getRGB();				printWriter.println(col.getRed()/255.0f + " " + col.getGreen()/255.0f + " " + col.getBlue()/255.0f + " setrgbcolor");			}		}	}	/**	 * Method to plot a polygon.	 * @param poly the polygon to plot.	 */	private void psPoly(PolyBase poly)	{		// ignore null layers		Layer layer = poly.getLayer();		EGraphics gra = null;		int index = 0;		Color col = Color.BLACK;		Technology tech = Technology.getCurrent();		if (layer != null)		{			tech = layer.getTechnology();			index = layer.getIndex();			if (!layer.isVisible()) return;			gra = layer.getGraphics();			col = gra.getColor();		}		// ignore layers that are not supposed to be dumped at this time		if (currentLayer >= 0)		{			if (currentLayer == 0)			{				if (tech == Technology.getCurrent()) return;			} else			{				if (tech != Technology.getCurrent() || currentLayer-1 != index)					return;			}		}		// set color if requested		setColor(col);		Poly.Type type = poly.getStyle();		Point2D [] points = poly.getPoints();		if (type == Poly.Type.FILLED)		{			Rectangle2D polyBox = poly.getBox();			if (polyBox != null)			{				if (polyBox.getWidth() == 0)				{					if (polyBox.getHeight() == 0)					{						psDot(new Point2D.Double(polyBox.getCenterX(), polyBox.getCenterY()));					} else					{						psLine(new Point2D.Double(polyBox.getCenterX(), polyBox.getMinY()),							new Point2D.Double(polyBox.getCenterX(), polyBox.getMaxY()), 0);					}					return;				} else if (polyBox.getHeight() == 0)				{					psLine(new Point2D.Double(polyBox.getMinX(), polyBox.getCenterY()),						new Point2D.Double(polyBox.getMaxX(), polyBox.getCenterY()), 0);					return;				}				psPolygon(poly);				return;			}			if (points.length == 1)			{				psDot(points[0]);				return;			}			if (points.length == 2)			{				psLine(points[0], points[1], 0);				return;			}			psPolygon(poly);			return;		}		if (type == Poly.Type.CLOSED)		{			Point2D lastPt = points[points.length-1];			for (int k = 0; k < points.length; k++)			{				psLine(lastPt, points[k], 0);				lastPt = points[k];			}			return;		}		if (type == Poly.Type.OPENED || type == Poly.Type.OPENEDT1 ||			type == Poly.Type.OPENEDT2 || type == Poly.Type.OPENEDT3)		{			int lineType = 0;			if (type == Poly.Type.OPENEDT1) lineType = 1; else			if (type == Poly.Type.OPENEDT2) lineType = 2; else			if (type == Poly.Type.OPENEDT3) lineType = 3;			for (int k = 1; k < points.length; k++)				psLine(points[k-1], points[k], lineType);			return;		}		if (type == Poly.Type.VECTORS)		{			for(int k=0; k<points.length; k += 2)				psLine(points[k], points[k+1], 0);			return;		}		if (type == Poly.Type.CROSS || type == Poly.Type.BIGCROSS)		{			double x = poly.getCenterX();			double y = poly.getCenterY();			drawCross(x, y, type == Poly.Type.BIGCROSS);			return;		}		if (type == Poly.Type.CROSSED)		{			Rectangle2D bounds = poly.getBounds2D();			psLine(new Point2D.Double(bounds.getMinX(), bounds.getMinY()), new Point2D.Double(bounds.getMinX(), bounds.getMaxY()), 0);			psLine(new Point2D.Double(bounds.getMinX(), bounds.getMaxY()), new Point2D.Double(bounds.getMaxX(), bounds.getMaxY()), 0);			psLine(new Point2D.Double(bounds.getMaxX(), bounds.getMaxY()), new Point2D.Double(bounds.getMaxX(), bounds.getMinY()), 0);			psLine(new Point2D.Double(bounds.getMaxX(), bounds.getMinY()), new Point2D.Double(bounds.getMinX(), bounds.getMinY()), 0);			psLine(new Point2D.Double(bounds.getMinX(), bounds.getMinY()), new Point2D.Double(bounds.getMaxX(), bounds.getMaxY()), 0);			psLine(new Point2D.Double(bounds.getMinX(), bounds.getMaxY()), new Point2D.Double(bounds.getMaxX(), bounds.getMinY()), 0);			return;		}		if (type == Poly.Type.DISC)		{			psDisc(points[0], points[1]);			type = Poly.Type.CIRCLE;		}		if (type == Poly.Type.CIRCLE || type == Poly.Type.THICKCIRCLE)		{			psCircle(points[0], points[1]);			return;		}		if (type == Poly.Type.CIRCLEARC || type == Poly.Type.THICKCIRCLEARC)		{			psArc(points[0], points[1], points[2]);			return;		}		// text		psText((Poly)poly);	}	/**	 * Method to draw a cross.	 * @param x X center of the cross.	 * @param y Y Center of the cross.	 * @param bigCross true for a big cross, false for a small one	 */	private void drawCross(double x, double y, boolean bigCross)	{		double amount = 0.25;		if (bigCross) amount = 0.5;		psLine(new Point2D.Double(x-amount, y), new Point2D.Double(x+amount, y), 0);		psLine(new Point2D.Double(x, y+amount), new Point2D.Double(x, y-amount), 0);	}	/**	 * Method to draw a dot	 * @param pt the center of the dot.	 */	private void psDot(Point2D pt)	{		Point2D ps = psXform(pt);		putPSHeader(HEADERDOT);		printWriter.println(TextUtils.formatDouble(ps.getX()) + " " + TextUtils.formatDouble(ps.getY()) + " Putdot");	}	/**	 * Method to draw a line.	 * @param from the starting point of the line.	 * @param to the ending point of the line.	 * @param pattern the line texture (0 for solid, positive for dot/dash patterns).	 */	private void psLine(Point2D from, Point2D to, int pattern)	{		Point2D pt1 = psXform(from);		Point2D pt2 = psXform(to);		putPSHeader(HEADERLINE);		int i = PSSCALE / 2;		switch (pattern)		{			case 0:				printWriter.println(TextUtils.formatDouble(pt1.getX()) + " " + TextUtils.formatDouble(pt1.getY()) + " " +					TextUtils.formatDouble(pt2.getX()) + " " + TextUtils.formatDouble(pt2.getY()) + " Drawline");				break;			case 1:				printWriter.print("[" + i + " " + i*3 + "] 0 setdash ");				printWriter.println(TextUtils.formatDouble(pt1.getX()) + " " + TextUtils.formatDouble(pt1.getY()) + " " +					TextUtils.formatDouble(pt2.getX()) + " " + TextUtils.formatDouble(pt2.getY()) + " Drawline");				printWriter.println(" [] 0 setdash");				break;			case 2:				printWriter.print("[" + i*6 + " " + i*3 + "] 0 setdash ");				printWriter.println(TextUtils.formatDouble(pt1.getX()) + " " + TextUtils.formatDouble(pt1.getY()) + " " +					TextUtils.formatDouble(pt2.getX()) + " " + TextUtils.formatDouble(pt2.getY()) + " Drawline");				printWriter.println(" [] 0 setdash");				break;			case 3:				printWriter.print((lineWidth*2) + " setlinewidth ");				printWriter.println(TextUtils.formatDouble(pt1.getX()) + " " + TextUtils.formatDouble(pt1.getY()) + " " +					TextUtils.formatDouble(pt2.getX()) + " " + TextUtils.formatDouble(pt2.getY()) + " Drawline");				printWriter.println(lineWidth + " setlinewidth");				break;		}	}	/**	 * Method to draw an arc of a circle.	 * @param center the center of the arc's circle.	 * @param pt1 the starting point of the arc.	 * @param pt2 the ending point of the arc.	 */	private void psArc(Point2D center, Point2D pt1, Point2D pt2)	{		Point2D pc = psXform(center);		Point2D ps1 = psXform(pt1);		Point2D ps2 = psXform(pt2);		double radius = pc.distance(ps1);		int startAngle = (DBMath.figureAngle(pc, ps2) + 5) / 10;		int endAngle = (DBMath.figureAngle(pc, ps1) + 5) / 10;		printWriter.println("newpath " + TextUtils.formatDouble(pc.getX()) + " " + TextUtils.formatDouble(pc.getY()) + " " + radius + " " +			startAngle + " " + endAngle + " arc stroke");	}	/**	 * Method to draw an unfilled circle.	 * @param center the center of the circle.	 * @param pt a point on the circle.	 */	private void psCircle(Point2D center, Point2D pt)	{		Point2D pc = psXform(center);		Point2D ps = psXform(pt);		double radius = pc.distance(ps);		printWriter.println("newpath " + TextUtils.formatDouble(pc.getX()) + " " + TextUtils.formatDouble(pc.getY()) + " " + radius + " 0 360 arc stroke");	}	/**	 * Method to draw a filled circle.	 * @param center the center of the circle.	 * @param pt a point on the circle.	 */	private void psDisc(Point2D center, Point2D pt)	{		Point2D pc = psXform(center);		Point2D ps = psXform(pt);		double radius = pc.distance(ps);		printWriter.println("newpath " + TextUtils.formatDouble(pc.getX()) + " " + TextUtils.formatDouble(pc.getY()) + " " + radius + " 0 360 arc fill");	}	/**	 * Method to draw an irregular polygon.	 * @param poly the polygon to draw.	 */	private void psPolygon(PolyBase poly)	{		Point2D [] points = poly.getPoints();		if (points.length == 0) return;//		// ignore if too small//		Rectangle2D polyBounds = null;//		for(int i=0; i<points.length; i++)//		{//			Point2D pu = psXform(points[i]);//			if (polyBounds == null) polyBounds = new Rectangle2D.Double(pu.getX(), pu.getY(), 0, 0); else//				polyBounds.add(pu);//		}//		if (polyBounds.getWidth() < 1 || polyBounds.getHeight() < 1) return;		EGraphics desc = poly.getLayer().getGraphics();		// use solid color if solid pattern or no pattern		boolean stipplePattern = desc.isPatternedOnPrinter();		// if stipple pattern is solid, just use solid fill		if (stipplePattern)		{			int [] pattern = desc.getPattern();			boolean solid = true;			for(int i=0; i<8; i++)				if (pattern[i] != 0xFFFF) { solid = false;   break; }			if (solid) stipplePattern = false;		}		// put out solid fill if appropriate		if (!stipplePattern)		{			putPSHeader(HEADERPOLYGON);			printWriter.print("[");			for(int i=0; i<points.length; i++)			{				if (i != 0) printWriter.print(" ");				Point2D ps = psXform(points[i]);				printWriter.print(TextUtils.formatDouble(ps.getX()) + " " + TextUtils.formatDouble(ps.getY()));			}			printWriter.println("] Polygon fill");			return;		}		/*		 * patterned fill: the hard one		 * Generate filled polygons by defining a stipple font and then tiling the		 * polygon to fill with 128x128 pixel characters, clipping to the polygon edge.		 */		putPSHeader(HEADERPOLYGON);		putPSHeader(HEADERFPOLYGON);		printWriter.print("(" + psPattern(desc) + ") [");		Point2D ps = psXform(points[0]);		double lx = ps.getX();		double hx = lx;		double ly = ps.getY();		double hy = ly;		for(int i=0; i<points.length; i++)		{			if (i != 0) printWriter.print(" ");			Point2D psi = psXform(points[i]);			printWriter.print(psi.getX() + " " + psi.getY());			if (psi.getX() < lx) lx = psi.getX();   if (psi.getX() > hx) hx = psi.getX();			if (psi.getY() < ly) ly = psi.getY();   if (psi.getY() > hy) hy = psi.getY();		}		printWriter.println("] " + TextUtils.formatDouble(hx-lx+1) + " " + TextUtils.formatDouble(hy-ly+1) + " " +			TextUtils.formatDouble(lx) + " " + TextUtils.formatDouble(ly) + " Filledpolygon");	}	/**	 * Method to draw text.	 * @param poly the text polygon to draw.	 */	private void psText(Poly poly)	{		Poly.Type style = poly.getStyle();		TextDescriptor td = poly.getTextDescriptor();		if (td == null) return;		int size = (int)(td.getTrueSize(wnd) * PSTEXTSCALE * PSSCALE);		Rectangle2D bounds = poly.getBounds2D();		// get the font size		if (size <= 0) return;		// make sure the string is valid		String text = poly.getString().trim();		if (text.length() == 0) return;		// write header information		Point2D psL = psXform(new Point2D.Double(bounds.getMinX(), bounds.getMinY()));		Point2D psH = psXform(new Point2D.Double(bounds.getMaxX(), bounds.getMaxY()));		double cX = (psL.getX() + psH.getX()) / 2;		double cY = (psL.getY() + psH.getY()) / 2;		double sX = Math.abs(psH.getX() - psL.getX());		double sY = Math.abs(psH.getY() - psL.getY());		putPSHeader(HEADERSTRING);		boolean changedFont = false;		String faceName = null;		int faceNumber = td.getFace();		if (faceNumber != 0)		{			TextDescriptor.ActiveFont af = TextDescriptor.ActiveFont.findActiveFont(faceNumber);			if (af != null) faceName = af.getName();		}		if (faceName != null)		{			String fixedFaceName = faceName.replace(' ', '-');			printWriter.println("/DefaultFont /" + fixedFaceName + " def");			changedFont = true;		} else		{			if (td.isItalic())			{				if (td.isBold())				{					printWriter.println("/DefaultFont /" + DEFAULTFONTBI + " def");					changedFont = true;				} else				{					printWriter.println("/DefaultFont /" + DEFAULTFONTITALIC + " def");					changedFont = true;				}			} else if (td.isBold())			{				printWriter.println("/DefaultFont /" + DEFAULTFONTBOLD + " def");				changedFont = true;			}		}		if (poly.getStyle() == Poly.Type.TEXTBOX)		{			printWriter.print(TextUtils.formatDouble(cX) + " " + TextUtils.formatDouble(cY) + " " +				TextUtils.formatDouble(sX) + " " + TextUtils.formatDouble(sY) + " ");			writePSString(text);			printWriter.println(" " + size + " Boxstring");		} else		{			String opName = null;			double x = 0, y = 0;			if (style == Poly.Type.TEXTCENT)			{				x = cX;   y = cY;				opName = "Centerstring";			} else if (style == Poly.Type.TEXTTOP)			{				x = cX;   y = psH.getY();				opName = "Topstring";			} else if (style == Poly.Type.TEXTBOT)			{				x = cX;   y = psL.getY();				opName = "Botstring";			} else if (style == Poly.Type.TEXTLEFT)			{				x = psL.getX();   y = cY;				opName = "Leftstring";			} else if (style == Poly.Type.TEXTRIGHT)			{				x = psH.getX();   y = cY;				opName = "Rightstring";			} else if (style == Poly.Type.TEXTTOPLEFT)			{				x = psL.getX();   y = psH.getY();				opName = "Topleftstring";			} else if (style == Poly.Type.TEXTTOPRIGHT)			{				x = psH.getX();   y = psH.getY();				opName = "Toprightstring";			} else if (style == Poly.Type.TEXTBOTLEFT)			{				x = psL.getX();   y = psL.getY();				opName = "Botleftstring";			} else if (style == Poly.Type.TEXTBOTRIGHT)			{				x = psH.getX();   y = psL.getY();				opName = "Botrightstring";			}			int xoff = (int)x,  yoff = (int)y;			double descenderoffset = size / 12;			TextDescriptor.Rotation rot = td.getRotation();			if (rot == TextDescriptor.Rotation.ROT0) y += descenderoffset; else			if (rot == TextDescriptor.Rotation.ROT90) x -= descenderoffset; else			if (rot == TextDescriptor.Rotation.ROT180) y -= descenderoffset; else			if (rot == TextDescriptor.Rotation.ROT270) x += descenderoffset;			if (rot != TextDescriptor.Rotation.ROT0)			{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -