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

📄 pdf.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 3 页
字号:
				 * Adobe-conforming CMYK file				 * applying workaround for color inversion				 */				vFPprintf(pOutFile,					"\t/Decode [1 0 1 0 1 0 1 0]\n");			}			break;		default:			DBG_DEC(pImg->iComponents);			break;		}		vFPprintf(pOutFile, "\t/BitsPerComponent 8\n");		vFPprintf(pOutFile,			"\t/Filter [ /ASCII85Decode /DCTDecode ]\n");		break;	case imagetype_is_png:		if (pImg->iComponents == 3 || pImg->iComponents == 4) {			vFPprintf(pOutFile, "\t/ColorSpace /DeviceRGB\n");			vFPprintf(pOutFile, "\t/BitsPerComponent 8\n");		} else if (pImg->iColorsUsed > 0) {			vPrintPalette(pOutFile, pImg);			fail(pImg->uiBitsPerComponent > 8);			vFPprintf(pOutFile, "\t/BitsPerComponent %u\n",					pImg->uiBitsPerComponent);		} else {			vFPprintf(pOutFile, "\t/ColorSpace /DeviceGray\n");			vFPprintf(pOutFile, "\t/BitsPerComponent 8\n");		}		vFPprintf(pOutFile,			"\t/Filter [ /ASCII85Decode /FlateDecode ]\n");		vFPprintf(pOutFile, "\t/DecodeParms [ null <<\n");		vFPprintf(pOutFile, "\t\t/Predictor 10\n");		vFPprintf(pOutFile, "\t\t/Colors %d\n", pImg->iComponents);		vFPprintf(pOutFile, "\t\t/BitsPerComponent %u\n",						pImg->uiBitsPerComponent);		vFPprintf(pOutFile, "\t\t/Columns %d\n", pImg->iWidth);		vFPprintf(pOutFile, "\t\t>> ]\n");		break;	case imagetype_is_dib:		if (pImg->uiBitsPerComponent <= 8) {			vPrintPalette(pOutFile, pImg);		} else {			vFPprintf(pOutFile, "\t/ColorSpace /DeviceRGB\n");		}		vFPprintf(pOutFile, "\t/BitsPerComponent 8\n");		vFPprintf(pOutFile, "\t/Filter /ASCII85Decode\n");		break;	default:		vFPprintf(pOutFile, "\t/ColorSpace /Device%s\n",			pImg->bColorImage ? "RGB" : "Gray");		vFPprintf(pOutFile, "\t/BitsPerComponent 8\n");		vFPprintf(pOutFile, "\t/Filter /ASCIIHexDecode\n");		break;	}	vFPprintf(pOutFile, "ID\n");} /* end of vImageProloguePDF *//* * vImageEpiloguePDF - clean up after the image */voidvImageEpiloguePDF(diagram_type *pDiag){	FILE	*pOutFile;	fail(pDiag == NULL);	fail(pDiag->pOutFile == NULL);	pOutFile = pDiag->pOutFile;	/* Correction for the image bytes */	lFilePosition = ftell(pOutFile);	vFPprintf(pOutFile, "EI\n");	vFPprintf(pOutFile, "Q\n");	vFPprintf(pOutFile, "BT\n");	pDiag->lXleft = 0;} /* end of vImageEpiloguePDF *//* * bAddDummyImagePDF - add a dummy image * * return TRUE when successful, otherwise FALSE */BOOLbAddDummyImagePDF(diagram_type *pDiag, const imagedata_type *pImg){	FILE	*pOutFile;	fail(pDiag == NULL);	fail(pDiag->pOutFile == NULL);	fail(pImg == NULL);	if (pImg->iVerSizeScaled <= 0 || pImg->iHorSizeScaled <= 0) {		return FALSE;	}	iImageCount++;	DBG_DEC_C(pDiag->lXleft != 0, pDiag->lXleft);	pDiag->lYtop -= lPoints2DrawUnits(pImg->iVerSizeScaled);	vMoveTo(pDiag, lPoints2DrawUnits(pImg->iVerSizeScaled));	pOutFile = pDiag->pOutFile;	vFPprintf(pOutFile, "ET\n");	vFPprintf(pOutFile, "q %% Image %03d\n", iImageCount);	vFPprintf(pOutFile, "\t1.0 w\n");	vFPprintf(pOutFile, "\t0.3 G\n");	vFPprintf(pOutFile, "\t%.2f %.2f %d %d re\n",			dDrawUnits2Points(pDiag->lXleft + PS_LEFT_MARGIN),			dDrawUnits2Points(pDiag->lYtop),			pImg->iHorSizeScaled,			pImg->iVerSizeScaled);	vFPprintf(pOutFile, "\tS\n");	vFPprintf(pOutFile, "Q\n");	vFPprintf(pOutFile, "BT\n");	pDiag->lXleft = 0;	return TRUE;} /* end of bAddDummyImagePDF *//* * vAddFontsPDF - add the font information */voidvAddFontsPDF(diagram_type *pDiag){	FILE	*pOutFile;	size_t	tIndex;	fail(pDiag == NULL);	fail(pDiag->pOutFile == NULL);	pOutFile = pDiag->pOutFile;	/* The font encoding */	vSetLocation(4);	vFPprintf(pOutFile, "4 0 obj\n");	vFPprintf(pOutFile, "<<\n");	vFPprintf(pOutFile, "/Type /Encoding\n");	vFPprintf(pOutFile, "/BaseEncoding /StandardEncoding\n");	vFPprintf(pOutFile, "/Differences [\n");	switch (eEncoding) {	case encoding_latin_1:		for (tIndex = 0;		     tIndex < elementsof(iso_8859_1);		     tIndex++) {			vFPprintf(pOutFile, "%s\n", iso_8859_1[tIndex]);		}		break;	case encoding_latin_2:		for (tIndex = 0;		     tIndex < elementsof(iso_8859_2);		     tIndex++) {			vFPprintf(pOutFile, "%s\n", iso_8859_2[tIndex]);		}		break;	case encoding_cyrillic:		werr(1,		"The combination PDF and Cyrillic is not supported");		break;	case encoding_utf_8:		werr(1,		"The combination PDF and UTF-8 is not supported");		break;	default:		DBG_DEC(eEncoding);		break;	}	vFPprintf(pOutFile, "]\n");	vFPprintf(pOutFile, ">>\n");	vFPprintf(pOutFile, "endobj\n");	/* Twelve of the standard type 1 fonts */	for (tIndex = 0; tIndex < 12; tIndex++) {		vSetLocation(5 + tIndex);		vFPprintf(pOutFile, "%u 0 obj\n", 5 + tIndex);		vFPprintf(pOutFile, "<<\n");		vFPprintf(pOutFile, "/Type /Font\n");		vFPprintf(pOutFile, "/Subtype /Type1\n");		vFPprintf(pOutFile, "/Name /F%u\n", 1 + tIndex);		vFPprintf(pOutFile, "/BaseFont /%s\n",						atFontname[tIndex].szPDFname);		vFPprintf(pOutFile, "/Encoding 4 0 R\n");		vFPprintf(pOutFile, ">>\n");		vFPprintf(pOutFile, "endobj\n");	}	/* The Resources */	vSetLocation(17);	vFPprintf(pOutFile, "17 0 obj\n");	vFPprintf(pOutFile, "<<\n");	vFPprintf(pOutFile, "/ProcSet [ /PDF /Text ]\n");	vFPprintf(pOutFile, "/Font <<\n");	for (tIndex = 0; tIndex < 12; tIndex++) {		vFPprintf(pOutFile, "\t/F%u %u 0 R\n", 1 + tIndex, 5 + tIndex);	}	vFPprintf(pOutFile, "\t>>\n");	vFPprintf(pOutFile, ">>\n");	vFPprintf(pOutFile, "endobj\n");	vAddHeader(pDiag);} /* end of vAddFontsPDF *//* * vPrintPDF - print a PDF string */static voidvPrintPDF(FILE *pFile, const char *szString, size_t tStringLength,	USHORT usFontstyle){	const UCHAR	*aucBytes;	double	dMove;	size_t	tCount;	fail(szString == NULL);	if (szString == NULL || szString[0] == '\0' || tStringLength == 0) {		return;	}	DBG_DEC_C(usFontSizeCurr < MIN_FONT_SIZE, usFontSizeCurr);	dMove = 0.0;	/* Up for superscript */	if (bIsSuperscript(usFontstyle) && usFontSizeCurr != 0) {		dMove = (double)((usFontSizeCurr + 1) / 2) * 0.375;		vFPprintf(pFile, "%.2f Ts\n", dMove);	}	/* Down for subscript */	if (bIsSubscript(usFontstyle) && usFontSizeCurr != 0) {		dMove = (double)usFontSizeCurr * 0.125;		vFPprintf(pFile, "%.2f Ts\n", -dMove);	}	/* Generate and print the PDF output */	aucBytes = (UCHAR *)szString;	vFPprintf(pFile, "(");	for (tCount = 0; tCount < tStringLength ; tCount++) {		switch (aucBytes[tCount]) {		case '(':		case ')':		case '\\':			vFPprintf(pFile, "\\%c", szString[tCount]);			break;		default:			if (aucBytes[tCount] < 0x20 ||			    aucBytes[tCount] == 0x7f ||			    (aucBytes[tCount] >= 0x81 &&			     aucBytes[tCount] < 0x8c)) {				DBG_HEX(aucBytes[tCount]);				vFPprintf(pFile, " ");			} else if (aucBytes[tCount] >= 0x80) {				vFPprintf(pFile, "\\%03o",						(UINT)aucBytes[tCount]);			} else {				vFPprintf(pFile, "%c", szString[tCount]);			}			break;		}	}	vFPprintf(pFile, ") Tj\n");	/* Undo the superscript/subscript move */	if (dMove != 0.0) {		vFPprintf(pFile, "0 Ts\n");	}} /* end of vPrintPDF *//* * vSetColor - move to the specified color */static voidvSetColor(FILE *pFile, UCHAR ucFontColor){	ULONG	ulTmp, ulRed, ulGreen, ulBlue;	ulTmp = ulColor2Color(ucFontColor);	ulRed   = (ulTmp & 0x0000ff00) >> 8;	ulGreen = (ulTmp & 0x00ff0000) >> 16;	ulBlue  = (ulTmp & 0xff000000) >> 24;	vFPprintf(pFile, "%.3f %.3f %.3f rg\n",			ulRed / 255.0, ulGreen / 255.0, ulBlue / 255.0);} /* end of vSetColor *//* * vMove2NextLinePDF - move to the next line */voidvMove2NextLinePDF(diagram_type *pDiag, USHORT usFontSize){	fail(pDiag == NULL);	fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE);	pDiag->lYtop -= lComputeLeading(usFontSize);} /* end of vMove2NextLinePDF *//* * vSubstringPDF - print a sub string */voidvSubstringPDF(diagram_type *pDiag,	char *szString, size_t tStringLength, long lStringWidth,	UCHAR ucFontColor, USHORT usFontstyle, drawfile_fontref tFontRef,	USHORT usFontSize, USHORT usMaxFontSize){	size_t	tFontIndex;	fail(pDiag == NULL || szString == NULL);	fail(pDiag->pOutFile == NULL);	fail(pDiag->lXleft < 0);	fail(tStringLength != strlen(szString));	fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE);	fail(usMaxFontSize < MIN_FONT_SIZE || usMaxFontSize > MAX_FONT_SIZE);	fail(usFontSize > usMaxFontSize);	if (szString[0] == '\0' || tStringLength == 0) {		return;	}	vMoveTo(pDiag, lComputeLeading(usMaxFontSize));	if (tFontRef != tFontRefCurr || usFontSize != usFontSizeCurr) {		tFontIndex = tGetFontIndex(tFontRef);		vFPprintf(pDiag->pOutFile, "/F%u %.1f Tf\n",			 1 + tFontIndex, (double)usFontSize / 2.0);		tFontRefCurr = tFontRef;		usFontSizeCurr = usFontSize;	}	if ((int)ucFontColor != iFontColorCurr) {		vSetColor(pDiag->pOutFile, ucFontColor);		iFontColorCurr = (int)ucFontColor;	}	vPrintPDF(pDiag->pOutFile, szString, tStringLength, usFontstyle);	pDiag->lXleft += lStringWidth;} /* end of vSubstringPDF *//* * Create an start of paragraph by moving the y-top mark */voidvStartOfParagraphPDF(diagram_type *pDiag, long lBeforeIndentation){	fail(pDiag == NULL);	fail(lBeforeIndentation < 0);	pDiag->lXleft = 0;	pDiag->lYtop -= lMilliPoints2DrawUnits(lBeforeIndentation);} /* end of vStartOfParagraphPDF *//* * Create an end of paragraph by moving the y-top mark */voidvEndOfParagraphPDF(diagram_type *pDiag,	USHORT usFontSize, long lAfterIndentation){	fail(pDiag == NULL);	fail(pDiag->pOutFile == NULL);	fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE);	fail(lAfterIndentation < 0);	if (pDiag->lXleft > 0) {		/* To the start of the line */		vMove2NextLinePDF(pDiag, usFontSize);	}	pDiag->lXleft = 0;	pDiag->lYtop -= lMilliPoints2DrawUnits(lAfterIndentation);} /* end of vEndOfParagraphPDF *//* * Create an end of page */voidvEndOfPagePDF(diagram_type *pDiag, BOOL bNewSection){	vMove2NextPage(pDiag, bNewSection);} /* end of vEndOfPagePDF */

⌨️ 快捷键说明

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