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

📄 postscript.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * postscript.c * Copyright (C) 1999-2005 A.J. van Os; Released under GNU GPL * * Description: * Functions to deal with the PostScript format * *================================================================ * The function vImagePrologue is based on: * jpeg2ps - convert JPEG compressed images to PostScript Level 2 * Copyright (C) 1994-99 Thomas Merz (tm@muc.de) *================================================================ * The credit should go to him, but all the bugs are mine. */#include <stdlib.h>#include <errno.h>#include <time.h>#include <string.h>#include "version.h"#include "antiword.h"/* The character set */static encoding_type	eEncoding = encoding_neutral;/* The image level */static image_level_enum	eImageLevel = level_default;/* The output must use landscape orientation */static BOOL		bUseLandscape = FALSE;/* The height and width of a PostScript page (in DrawUnits) */static long		lPageHeight = LONG_MAX;static long		lPageWidth = LONG_MAX;/* The height of the footer on the current page (in DrawUnits) */static long		lFooterHeight = 0;/* Inside a footer (to prevent an infinite loop when the footer is too big) */static BOOL		bInFtrSpace = FALSE;/* Current time for a PS header */static const char	*szCreationDate = NULL;/* Current creator for a PS header */static const char	*szCreator = NULL;/* Current font information */static drawfile_fontref	tFontRefCurr = (drawfile_fontref)-1;static USHORT		usFontSizeCurr = 0;static int		iFontColorCurr = -1;/* Current vertical position information */static long		lYtopCurr = -1;/* PostScript page counter */static int		iPageCount = 0;/* Image counter */static int		iImageCount = 0;/* Section index */static int		iSectionIndex = 0;/* Are we on the first page of the section? */static BOOL		bFirstInSection = TRUE;static void		vMoveTo(diagram_type *, long);static const char *iso_8859_1_data[] = {"/newcodes	% ISO-8859-1 character encodings","[","140/ellipsis 141/trademark 142/perthousand 143/bullet","144/quoteleft 145/quoteright 146/guilsinglleft 147/guilsinglright","148/quotedblleft 149/quotedblright 150/quotedblbase 151/endash 152/emdash","153/minus 154/OE 155/oe 156/dagger 157/daggerdbl 158/fi 159/fl","160/space 161/exclamdown 162/cent 163/sterling 164/currency","165/yen 166/brokenbar 167/section 168/dieresis 169/copyright","170/ordfeminine 171/guillemotleft 172/logicalnot 173/hyphen 174/registered","175/macron 176/degree 177/plusminus 178/twosuperior 179/threesuperior","180/acute 181/mu 182/paragraph 183/periodcentered 184/cedilla","185/onesuperior 186/ordmasculine 187/guillemotright 188/onequarter","189/onehalf 190/threequarters 191/questiondown 192/Agrave 193/Aacute","194/Acircumflex 195/Atilde 196/Adieresis 197/Aring 198/AE 199/Ccedilla","200/Egrave 201/Eacute 202/Ecircumflex 203/Edieresis 204/Igrave 205/Iacute","206/Icircumflex 207/Idieresis 208/Eth 209/Ntilde 210/Ograve 211/Oacute","212/Ocircumflex 213/Otilde 214/Odieresis 215/multiply 216/Oslash","217/Ugrave 218/Uacute 219/Ucircumflex 220/Udieresis 221/Yacute 222/Thorn","223/germandbls 224/agrave 225/aacute 226/acircumflex 227/atilde","228/adieresis 229/aring 230/ae 231/ccedilla 232/egrave 233/eacute","234/ecircumflex 235/edieresis 236/igrave 237/iacute 238/icircumflex","239/idieresis 240/eth 241/ntilde 242/ograve 243/oacute 244/ocircumflex","245/otilde 246/odieresis 247/divide 248/oslash 249/ugrave 250/uacute","251/ucircumflex 252/udieresis 253/yacute 254/thorn 255/ydieresis","] bind def","","/reencdict 12 dict def","",};static const char *iso_8859_2_data[] = {"/newcodes	% ISO-8859-2 character encodings","[","160/space 161/Aogonek 162/breve 163/Lslash 164/currency 165/Lcaron","166/Sacute 167/section 168/dieresis 169/Scaron 170/Scommaaccent","171/Tcaron 172/Zacute 173/hyphen 174/Zcaron 175/Zdotaccent 176/degree","177/aogonek 178/ogonek 179/lslash 180/acute 181/lcaron 182/sacute","183/caron 184/cedilla 185/scaron 186/scommaaccent 187/tcaron","188/zacute 189/hungarumlaut 190/zcaron 191/zdotaccent 192/Racute","193/Aacute 194/Acircumflex 195/Abreve 196/Adieresis 197/Lacute","198/Cacute 199/Ccedilla 200/Ccaron 201/Eacute 202/Eogonek","203/Edieresis 204/Ecaron 205/Iacute 206/Icircumflex 207/Dcaron","208/Dcroat 209/Nacute 210/Ncaron 211/Oacute 212/Ocircumflex","213/Ohungarumlaut 214/Odieresis 215/multiply 216/Rcaron 217/Uring","218/Uacute 219/Uhungarumlaut 220/Udieresis 221/Yacute 222/Tcommaaccent","223/germandbls 224/racute 225/aacute 226/acircumflex 227/abreve","228/adieresis 229/lacute 230/cacute 231/ccedilla 232/ccaron 233/eacute","234/eogonek 235/edieresis 236/ecaron 237/iacute 238/icircumflex","239/dcaron 240/dcroat 241/nacute 242/ncaron 243/oacute 244/ocircumflex","245/ohungarumlaut 246/odieresis 247/divide 248/rcaron 249/uring","250/uacute 251/uhungarumlaut 252/udieresis 253/yacute 254/tcommaaccent","255/dotaccent","] bind def","","/reencdict 12 dict def","",};static const char *iso_8859_5_data[] = {"/newcodes	% ISO-8859-5 character encodings","[","160/space     161/afii10023 162/afii10051 163/afii10052 164/afii10053","165/afii10054 166/afii10055 167/afii10056 168/afii10057 169/afii10058","170/afii10059 171/afii10060 172/afii10061 173/hyphen    174/afii10062","175/afii10145 176/afii10017 177/afii10018 178/afii10019 179/afii10020","180/afii10021 181/afii10022 182/afii10024 183/afii10025 184/afii10026","185/afii10027 186/afii10028 187/afii10029 188/afii10030 189/afii10031","190/afii10032 191/afii10033 192/afii10034 193/afii10035 194/afii10036","195/afii10037 196/afii10038 197/afii10039 198/afii10040 199/afii10041","200/afii10042 201/afii10043 202/afii10044 203/afii10045 204/afii10046","205/afii10047 206/afii10048 207/afii10049 208/afii10065 209/afii10066","210/afii10067 211/afii10068 212/afii10069 213/afii10070 214/afii10072","215/afii10073 216/afii10074 217/afii10075 218/afii10076 219/afii10077","220/afii10078 221/afii10079 222/afii10080 223/afii10081 224/afii10082","225/afii10083 226/afii10084 227/afii10085 228/afii10086 229/afii10087","230/afii10088 231/afii10089 232/afii10090 233/afii10091 234/afii10092","235/afii10093 236/afii10094 237/afii10095 238/afii10096 239/afii10097","240/afii61352 241/afii10071 242/afii10099 243/afii10100 244/afii10101","245/afii10102 246/afii10103 247/afii10104 248/afii10105 249/afii10106","250/afii10107 251/afii10108 252/afii10109 253/section   254/afii10110","255/afii10193","] bind def","","/reencdict 12 dict def","",};static const char *iso_8859_x_func[] = {"% change fonts using ISO-8859-x characters","/ChgFnt		% size psname natname => font","{","	dup FontDirectory exch known		% is re-encoded name known?","	{ exch pop }				% yes, get rid of long name","	{ dup 3 1 roll ReEncode } ifelse	% no, re-encode it","	findfont exch scalefont setfont","} bind def","","/ReEncode","{","reencdict begin","	/newname exch def","	/basename exch def","	/basedict basename findfont def","	/newfont basedict maxlength dict def","	basedict","	{ exch dup /FID ne","		{ dup /Encoding eq","			{ exch dup length array copy newfont 3 1 roll put }","			{ exch newfont 3 1 roll put } ifelse","		}","		{ pop pop } ifelse","	} forall","	newfont /FontName newname put","	newcodes aload pop newcodes length 2 idiv","	{ newfont /Encoding get 3 1 roll put } repeat","	newname newfont definefont pop","end","} bind def","",};static const char *misc_func[] = {"% draw a line and show the string","/LineShow	% string linewidth movement","{","	gsave","		0 exch rmoveto","		setlinewidth","		dup","		stringwidth pop","		0 rlineto stroke","	grestore","	show","} bind def","","% begin an EPS file (level 2 and up)","/BeginEPSF","{","	/b4_Inc_state save def","	/dict_count countdictstack def","	/op_count count 1 sub def","	userdict begin","		/showpage { } def","		0 setgray 0 setlinecap","		1 setlinewidth 0 setlinejoin","		10 setmiterlimit [ ] 0 setdash newpath","		false setstrokeadjust false setoverprint","} bind def","","% end an EPS file","/EndEPSF {","	count op_count sub { pop } repeat","	countdictstack dict_count sub { end } repeat","	b4_Inc_state restore","} bind def","",};/* * vAddPageSetup - add the page setup */static voidvAddPageSetup(FILE *pOutFile){	if (bUseLandscape) {		fprintf(pOutFile, "%%%%BeginPageSetup\n");		fprintf(pOutFile, "90 rotate\n");		fprintf(pOutFile, "0.00 %.2f translate\n",					-dDrawUnits2Points(lPageHeight));		fprintf(pOutFile, "%%%%EndPageSetup\n");	}} /* end of vAddPageSetup *//* * vAddHdrFtr - add a header or footer */static voidvAddHdrFtr(diagram_type *pDiag, const hdrftr_block_type *pHdrFtrInfo){	output_type	*pStart, *pPrev, *pNext;	fail(pDiag == NULL);	fail(pHdrFtrInfo == NULL);	vStartOfParagraphPS(pDiag, 0);	pStart = pHdrFtrInfo->pText;	while (pStart != NULL) {		pNext = pStart;		while (pNext != NULL &&		       (pNext->tNextFree != 1 ||		        (pNext->szStorage[0] != PAR_END &&		         pNext->szStorage[0] != HARD_RETURN))) {			pNext = pNext->pNext;		}		if (pNext == NULL) {			if (bOutputContainsText(pStart)) {				vAlign2Window(pDiag, pStart,					lChar2MilliPoints(DEFAULT_SCREEN_WIDTH),					ALIGNMENT_LEFT);			} else {				vMove2NextLinePS(pDiag, pStart->usFontSize);			}			break;		}		fail(pNext->tNextFree != 1);		fail(pNext->szStorage[0] != PAR_END &&			pNext->szStorage[0] != HARD_RETURN);		if (pStart != pNext) {			/* There is something to print */			pPrev = pNext->pPrev;			fail(pPrev->pNext != pNext);			/* Cut the chain */			pPrev->pNext = NULL;			if (bOutputContainsText(pStart)) {				/* Print it */				vAlign2Window(pDiag, pStart,					lChar2MilliPoints(DEFAULT_SCREEN_WIDTH),					ALIGNMENT_LEFT);			} else {				/* Just an empty line */				vMove2NextLinePS(pDiag, pStart->usFontSize);			}			/* Repair the chain */			pPrev->pNext = pNext;		}		if (pNext->szStorage[0] == PAR_END) {			vEndOfParagraphPS(pDiag, pNext->usFontSize,					(long)pNext->usFontSize * 200);		}		pStart = pNext->pNext;	}} /* end of vAddHdrFtr *//* * vAddHeader - add a page header */static voidvAddHeader(diagram_type *pDiag){	const hdrftr_block_type	*pHdrInfo;	const hdrftr_block_type	*pFtrInfo;	fail(pDiag == NULL);	NO_DBG_MSG("vAddHeader");	pHdrInfo = pGetHdrFtrInfo(iSectionIndex, TRUE,					odd(iPageCount), bFirstInSection);	pFtrInfo = pGetHdrFtrInfo(iSectionIndex, FALSE,					odd(iPageCount), bFirstInSection);	/* Set the height of the footer of this page */	lFooterHeight = pFtrInfo == NULL ? 0 : pFtrInfo->lHeight;	fail(lFooterHeight < 0);	if (pHdrInfo == NULL ||	    pHdrInfo->pText == NULL ||	    pHdrInfo->lHeight <= 0) {		fail(pHdrInfo != NULL && pHdrInfo->lHeight < 0);		fail(pHdrInfo != NULL &&			pHdrInfo->pText != NULL &&			pHdrInfo->lHeight == 0);		return;	}	vAddHdrFtr(pDiag, pHdrInfo);	DBG_DEC_C(pHdrInfo->lHeight !=		lPageHeight - PS_TOP_MARGIN - pDiag->lYtop,		pHdrInfo->lHeight);	DBG_DEC_C(pHdrInfo->lHeight !=		lPageHeight - PS_TOP_MARGIN - pDiag->lYtop,		lPageHeight - PS_TOP_MARGIN - pDiag->lYtop);#if 0 /* defined(DEBUG) */	fprintf(pDiag->pOutFile,	"(HEADER: FileOffset 0x%04lx-0x%04lx; Height %ld-%ld) show\n",		ulCharPos2FileOffset(pHdrInfo->ulCharPosStart),		ulCharPos2FileOffset(pHdrInfo->ulCharPosNext),		pHdrInfo->lHeight,		lPageHeight - PS_TOP_MARGIN - pDiag->lYtop);#endif} /* end of vAddHeader *//* * vAddFooter - add a page footer */static voidvAddFooter(diagram_type *pDiag){	const hdrftr_block_type	*pFtrInfo;	fail(pDiag == NULL);	NO_DBG_MSG("vAddFooter");	pFtrInfo = pGetHdrFtrInfo(iSectionIndex, FALSE,					odd(iPageCount), bFirstInSection);	bFirstInSection = FALSE;	if (pFtrInfo == NULL ||	    pFtrInfo->pText == NULL ||	    pFtrInfo->lHeight <= 0) {		fail(pFtrInfo != NULL && pFtrInfo->lHeight < 0);		fail(pFtrInfo != NULL &&			pFtrInfo->pText != NULL &&			pFtrInfo->lHeight == 0);		return;	}	bInFtrSpace = TRUE;	DBG_DEC_C(pFtrInfo->lHeight != lFooterHeight, pFtrInfo->lHeight);	DBG_DEC_C(pFtrInfo->lHeight != lFooterHeight, lFooterHeight);	DBG_DEC_C(pDiag->lYtop < lFooterHeight + PS_BOTTOM_MARGIN,			pDiag->lYtop);	DBG_DEC_C(pDiag->lYtop < lFooterHeight + PS_BOTTOM_MARGIN,			lFooterHeight + PS_BOTTOM_MARGIN);	if (pDiag->lYtop > lFooterHeight + PS_BOTTOM_MARGIN) {		/* Move down to the start of the footer */		pDiag->lYtop = lFooterHeight + PS_BOTTOM_MARGIN;		vMoveTo(pDiag, 0);	} else if (pDiag->lYtop < lFooterHeight + PS_BOTTOM_MARGIN / 2) {		DBG_FIXME();		/*		 * Move up to the start of the footer, to prevent moving		 * of the bottom edge of the paper		 */		pDiag->lYtop = lFooterHeight + PS_BOTTOM_MARGIN;		vMoveTo(pDiag, 0);	}	DBG_FLT_C(pDiag->lYtop < lFooterHeight + PS_BOTTOM_MARGIN,	dDrawUnits2Points(lFooterHeight + PS_BOTTOM_MARGIN - pDiag->lYtop));

⌨️ 快捷键说明

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