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

📄 postscript.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
				if (rot == TextDescriptor.Rotation.ROT90 || rot == TextDescriptor.Rotation.ROT270)				{					if (style == Poly.Type.TEXTTOP) opName = "Rightstring"; else					if (style == Poly.Type.TEXTBOT) opName = "Leftstring"; else					if (style == Poly.Type.TEXTLEFT) opName = "Botstring"; else					if (style == Poly.Type.TEXTRIGHT) opName = "Topstring"; else					if (style == Poly.Type.TEXTTOPLEFT) opName = "Botrightstring"; else					if (style == Poly.Type.TEXTBOTRIGHT) opName = "Topleftstring";				}				x = y = 0;				if (rot == TextDescriptor.Rotation.ROT90)				{					// 90 degrees counterclockwise					printWriter.println(xoff + " " + yoff + " translate 90 rotate");				} else if (rot == TextDescriptor.Rotation.ROT180)				{					// 180 degrees					printWriter.println(xoff + " " + yoff + " translate 180 rotate");				} else if (rot == TextDescriptor.Rotation.ROT270)				{					// 90 degrees clockwise					printWriter.println(xoff + " " + yoff + " translate 270 rotate");				}			}			printWriter.print(TextUtils.formatDouble(x) + " " + TextUtils.formatDouble(y) + " ");			writePSString(text);			printWriter.println(" " + size + " " + opName);			if (rot != TextDescriptor.Rotation.ROT0)			{				if (rot == TextDescriptor.Rotation.ROT90)				{					// 90 degrees counterclockwise					printWriter.println("-90 rotate " + (-xoff) + " " + (-yoff) + " translate");				} else if (rot == TextDescriptor.Rotation.ROT180)				{					// 180 degrees					printWriter.println("-180 rotate " + (-xoff) + " " + (-yoff) + " translate");				} else if (rot == TextDescriptor.Rotation.ROT270)				{					// 90 degrees clockwise					printWriter.println("-270 rotate " + (-xoff) + " " + (-yoff) + " translate");				}			}		}		if (changedFont)		{			printWriter.println("/DefaultFont /" + DEFAULTFONT + " def");		}	}	/****************************** SUPPORT ******************************/	private String [] headerDot =	{		"/Putdot {",				// print dot at stack pos		"    newpath moveto 0 0 rlineto stroke} def"	};	private String [] headerLine =	{		"/Drawline {",				// draw line on stack		"    newpath moveto lineto stroke} def"	};	private String [] headerPolygon =	{		"/Polygon {",				// put array into path		"    aload",		"    length 2 idiv /len exch def",		"    newpath",		"    moveto",		"    len 1 sub {lineto} repeat",		"    closepath",		"} def"	};	private String [] headerFilledPolygon =	{		"/BuildCharDict 10 dict def",	// ref Making a User Defined (PostScript Cookbook)		"/StippleFont1 7 dict def",		"StippleFont1 begin",		"    /FontType 3 def",		"    /FontMatrix [1 0 0 1 0 0] def",		"    /FontBBox [0 0 1 1] def",		"    /Encoding 256 array def",		"    0 1 255 {Encoding exch /.notdef put} for",		"    /CharacterDefs 40 dict def",		"    CharacterDefs /.notdef {} put",		"    /BuildChar",		"        { BuildCharDict begin",		"            /char exch def",		"            /fontdict exch def",		"            /charname fontdict /Encoding get",		"            char get def",		"            /charproc fontdict /CharacterDefs get",		"            charname get def",		"            1 0 0 0 1 1 setcachedevice",		"            gsave charproc grestore",		"        end",		"    } def",		"end",		"/StippleFont StippleFont1 definefont pop",		"/StippleCharYSize 128 def",		"/StippleCharXSize StippleCharYSize def",		"/Filledpolygon {",		"    gsave",		"    /StippleFont findfont StippleCharYSize scalefont setfont",		"    /LowY exch def /LowX exch def",		"    /HighY exch LowY add def /HighX exch LowX add def",		"    Polygon clip",		"    /Char exch def",		"    /LowY LowY StippleCharYSize div truncate StippleCharYSize mul def",		"    /LowX LowX StippleCharXSize div truncate StippleCharXSize mul def",		"    /HighY HighY StippleCharYSize div 1 add truncate StippleCharYSize mul def",		"    /HighX HighX StippleCharXSize div 1 add truncate StippleCharXSize mul def",		"    LowY StippleCharYSize HighY ",		"    { LowX exch moveto ",		"        LowX StippleCharXSize HighX ",		"        { Char show pop ",		"        } for ",		"    } for",		"    grestore",		"} def"	};	String [] headerString =	{		/*		* Code to do super and subscripts:		*		* example:		*	"NORMAL\dSUB\}   NORMAL\ uSUP\}"		*		* will subscript "SUB" and superscript "SUP", so "\d"  starts a		* subscript, "\ u" starts a superscript, "\}" returns to		* normal.  Sub-subscripts, and super-superscripts are not		* supported.  To print a "\", use "\\".		*		* changes:		*		* all calls to stringwidth were changed to calls to StringLength,		*    which returns the same info (assumes non-rotated text), but		*    takes sub- and super-scripts into account.		* all calls to show were changes to calls to StringShow, which		*    handles sub- and super-scripts.		* note that TSize is set to the text height, and is passed to		*    StringLength and StringShow.		*/		"/ComStart 92 def",								// "\", enter command mode		"/ComSub  100 def",								// "d", start subscript		"/ComSup  117 def",								// "u", start superscript		"/ComNorm 125 def",								// "}", return to normal		"/SSSize .70 def",								// sub- and super-script size		"/SubDy  -.20 def",								// Dy for sub-script		"/SupDy   .40 def",								// Dy for super-script*/		"/StringShow {",								// str size StringShow		"    /ComMode 0 def",							// command mode flag		"    /TSize exch def",							// text size		"    /TString exch def",						// string to draw		"    /NormY currentpoint exch pop def",			// save Y coord of string		"    TSize scaleFont",		"    TString {",								// scan string char by char		"        /CharCode exch def",					// save char		"        ComMode 1 eq {",		"            /ComMode 0 def",					// command mode		"            CharCode ComSub eq {",				// start subscript		"                TSize SSSize mul scaleFont",		"                currentpoint pop NormY TSize SubDy mul add moveto",		"            } if",		"            CharCode ComSup eq {",				// start superscript		"                TSize SSSize mul scaleFont",		"                currentpoint pop NormY TSize SupDy mul add moveto",		"            } if",		"            CharCode ComNorm eq {",			// end sub- or super-script		"                TSize scaleFont",		"                currentpoint pop NormY moveto",		"            } if",		"            CharCode ComStart eq {",			// print a "\"		"                ( ) dup 0 CharCode put show",		"            } if",		"        }",		"        {",		"            CharCode ComStart eq {",		"                /ComMode 1 def",				// enter command mode		"            }",		"            {",		"                ( ) dup 0 CharCode put show",	// print char		"            } ifelse",		"        } ifelse",		"    } forall ",		"} def",		"/StringLength {",								// str size StringLength		"    /ComMode 0 def",							// command mode flag		"    /StrLen 0 def",							// total string length		"    /TSize exch def",							// text size		"    /TString exch def",						// string to draw		"    TSize scaleFont",		"    TString {",								// scan string char by char		"        /CharCode exch def",					// save char		"        ComMode 1 eq {",		"            /ComMode 0 def",					// command mode		"            CharCode ComSub eq {",				// start subscript		"                TSize SSSize mul scaleFont",		"            } if",		"            CharCode ComSup eq {",				// start superscript		"                TSize SSSize mul scaleFont",		"            } if",		"            CharCode ComNorm eq {",			// end sub- or super-script		"                TSize scaleFont",		"            } if",		"            CharCode ComStart eq {",			// add "\" to length		"                ( ) dup 0 CharCode put stringwidth pop StrLen add",		"                /StrLen exch def",		"            } if",		"        }",		"        {",		"            CharCode ComStart eq {",		"                /ComMode 1 def",				// enter command mode		"            }",		"            {",								// add char to length		"                ( ) dup 0 CharCode put stringwidth pop StrLen add",		"                /StrLen exch def",		"            } ifelse",		"        } ifelse",		"    } forall ",		"    StrLen 0",									// return info like stringwidth		"} def",		"/Centerstring {",								// x y str sca		"    dup /TSize exch def",						// save size		"    dup scaleFont exch dup TSize StringLength", // x y sca str xw yw		"    pop 3 -1 roll .5 mul",						// x y str xw sca*.5 (was .8)		"    exch 5 -1 roll exch 2 div sub",			// y str sca*.5 x-xw/2		"    exch 4 -1 roll exch 2 div sub",			// str x-xw/2 y-sca*.5/2		"    moveto TSize StringShow",		"} def",		"/Topstring {",									// x y str sca		"    dup /TSize exch def",						// save size		"    dup scaleFont exch dup TSize StringLength", // x y sca str xw yw		"    pop 3 -1 roll .5 mul",						// x y str xw sca*.5 (was .8)		"    exch 5 -1 roll exch 2 div sub",			// y str sca*.5 x-xw/2		"    exch 4 -1 roll exch sub",					// str x-xw/2 y-sca*.5		"    moveto TSize StringShow",		"} def",		"/Botstring {",									// x y str sca		"    dup /TSize exch def",						// save size		"    scaleFont dup TSize StringLength pop",		// x y str xw		"    4 -1 roll exch 2 div sub",					// y str x-xw/2		"    3 -1 roll moveto TSize StringShow",		"} def",		"/Leftstring {",								// x y str sca		"    dup /TSize exch def",						// save size		"    dup scaleFont .4 mul",						// x y str sca*.4		"    3 -1 roll exch sub",						// x str y-sca*.4		"    3 -1 roll exch",							// str x y-sca*.4		"    moveto TSize StringShow",		"} def",		"/Rightstring {",								// x y str sca		"    dup /TSize exch def",						// save size		"    dup scaleFont exch dup TSize StringLength", // x y sca str xw yw		"    pop 3 -1 roll .4 mul",						// x y str xw sca*.4		"    exch 5 -1 roll exch sub",					// y str sca*.4 x-xw		"    exch 4 -1 roll exch sub",					// str x-xw y-sca*.4		"    moveto TSize StringShow",		"} def",		"/Topleftstring {",								// x y str sca		"    dup /TSize exch def",						// save size		"    dup scaleFont .5 mul",						// x y str sca*.5 (was .8)		"    3 -1 roll exch sub",						// x str y-sca*.5		"    3 -1 roll exch",							// str x y-sca*.5		"    moveto TSize StringShow",		"} def",		"/Toprightstring {",							// x y str sca		"    dup /TSize exch def",						// save size		"    dup scaleFont exch dup TSize StringLength", // x y sca str xw yw		"    pop 3 -1 roll .5 mul",						// x y str xw sca*.5 (was .8)		"    exch 5 -1 roll exch sub",					// y str sca*.5 x-xw		"    exch 4 -1 roll exch sub",					// str x-xw y-sca*.5		"    moveto TSize StringShow",		"} def",		"/Botleftstring {",								// x y str sca		"    dup /TSize exch def",						// save size		"    scaleFont 3 1 roll moveto TSize StringShow",		"} def",		"/Botrightstring {",							// x y str sca		"    dup /TSize exch def",						// save size		"    scaleFont dup TSize StringLength",		"    pop 4 -1 roll exch",		"    sub 3 -1 roll",		"    moveto TSize StringShow",		"} def",		"/Min {",										// leave minimum of top two		"    dup 3 -1 roll dup",		"    3 1 roll gt",		"    {exch} if pop",		"} def",		"/Boxstring {",									// x y mx my str sca		"    dup /TSize exch def",						// save size		"    dup scaleFont",							// x y mx my str sca		"    exch dup TSize StringLength pop",			// x y mx my sca str xw		"    3 -1 roll dup",							// x y mx my str xw sca sca		"    6 -1 roll mul",							// x y my str xw sca sca*mx		"    3 -1 roll div",							// x y my str sca sca*mx/xw		"    4 -1 roll",								// x y str sca sca*mx/xw my		"    Min Min",									// x y str minsca		"    Centerstring",		"} def"	};	/**	 * Method to write boilerplate for different types of PostScript objects.	 * @param which the desired object.	 */	private void putPSHeader(int which)	{		switch (which)		{			case HEADERDOT:				if (putHeaderDot) return;				putHeaderDot = true;				for(int i=0; i<headerDot.length; i++)					printWriter.println(headerDot[i]);				break;			case HEADERLINE:				if (putHeaderLine) return;				putHeaderLine = true;				for(int i=0; i<headerLine.length; i++)					printWriter.println(headerLine[i]);				break;			case HEADERPOLYGON:				if (putHeaderPolygon) return;				putHeaderPolygon = true;				for(int i=0; i<headerPolygon.length; i++)					printWriter.println(headerPolygon[i]);				break;			case HEADERFPOLYGON:				if (putHeaderFilledPolygon) return;				putHeaderFilledPolygon = true;				for(int i=0; i<headerFilledPolygon.length; i++)					printWriter.println(headerFilledPolygon[i]);				break;			case HEADERSTRING:				if (putHeaderString) return;				putHeaderString = true;				for(int i=0; i<headerString.length; i++)					printWriter.println(headerString[i]);				break;		}	}	/**	 * Method to write a pattern.	 * @param col the pattern to write.	 * @return the letter associated with the pattern.	 */	private char psPattern(EGraphics col)	{		// see if this graphics has been seen already		Integer index = patternsEmitted.get(col);		if (index != null) return (char)('A' + index.intValue());		// add to list		patternsEmitted.put(col, new Integer(psNumPatternsEmitted));		int [] raster = col.getPattern();		char indexChar = (char)(psNumPatternsEmitted+'A');		psNumPatternsEmitted++;		/*		 * Generate filled polygons by defining a stipple font,		 * and then tiling the polygon to fill with 128x128 pixel		 * characters, clipping to the polygon edge.		 *		 * Take Electric's 16x8 bit images, double each bit,		 * and then output 4 times to get 128 bit wide image.		 * Double vertically by outputting each row twice.		 * Note that full vertical size need not be generated,		 * as PostScript will just reuse the lines until the 128		 * size is reached.		 *		 * see: "Making a User Defined Font", PostScript Cookbook		 */		printWriter.println("StippleFont1 begin");		printWriter.println("    Encoding (" + indexChar + ") 0 get /Stipple" + indexChar + " put");		printWriter.println("    CharacterDefs /Stipple" + indexChar + " {");		printWriter.println("        128 128 true [128 0 0 -128 0 128]");		printWriter.println("        { <");		for(int i=0; i<8; i++)		{			int bl = raster[i] & 0x00FF;			int bh = (raster[i] & 0xFF00) >> 8;			int bld = 0, bhd = 0;			for (int k=0; k<8; ++k)			{				bld = (bld << 1);				bld |= (bl & 0x1);				bld = (bld << 1);				bld |= (bl & 0x1);				bl = (bl >> 1);				bhd = (bhd << 1);				bhd |= (bh & 0x1);				bhd = (bhd << 1);				bhd |= (bh & 0x1);				bh = (bh >> 1);			}			for (int k=0; k<2; k++)			{				printWriter.print("            ");				for(int j=0; j<4; j++)					printWriter.print((bhd&0xFFFF) + " " + (bld&0xFFFF) + " ");				printWriter.println();			}		}		printWriter.println("        > } imagemask");		printWriter.println("    } put");		printWriter.println("end");		return indexChar;	}	/**	 * Method to convert coordinates for display.	 * @param pt the Electric coordinates.	 * @return the PostScript coordinates.	 */	private Point2D psXform(Point2D pt)	{		Point2D result = new Point2D.Double();		matrix.transform(pt, result);		return result;	}	/**	 * Method to write PostScript text.	 * @param str the text to write in PostScript format.	 */	public void writePSString(String str)	{		printWriter.print("(");		for(int i=0; i<str.length(); i++)		{			char ca = str.charAt(i);			if (ca == '(' || ca == ')' || ca == '\\') printWriter.print("\\");			printWriter.print(ca);		}		printWriter.print(")");	}}

⌨️ 快捷键说明

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