📄 postscript.c
字号:
#if 0 /* defined(DEBUG) */ fprintf(pDiag->pOutFile, "(FOOTER: FileOffset 0x%04lx-0x%04lx; Bottom %ld-%ld) show\n", ulCharPos2FileOffset(pFtrInfo->ulCharPosStart), ulCharPos2FileOffset(pFtrInfo->ulCharPosNext), pDiag->lYtop, pFtrInfo->lHeight + PS_BOTTOM_MARGIN);#endif vAddHdrFtr(pDiag, pFtrInfo); bInFtrSpace = FALSE;} /* end of vAddFooter *//* * vMove2NextPage - move to the start of the next page */static voidvMove2NextPage(diagram_type *pDiag, BOOL bNewSection){ fail(pDiag == NULL); vAddFooter(pDiag); fprintf(pDiag->pOutFile, "showpage\n"); iPageCount++; fprintf(pDiag->pOutFile, "%%%%Page: %d %d\n", iPageCount, iPageCount); if (bNewSection) { iSectionIndex++; bFirstInSection = TRUE; } vAddPageSetup(pDiag->pOutFile); pDiag->lYtop = lPageHeight - PS_TOP_MARGIN; lYtopCurr = -1; vAddHeader(pDiag);} /* end of vMove2NextPage *//* * vMoveTo - move to the specified X,Y coordinates * * Move the current position of the specified diagram to its X,Y coordinates, * start on a new page if needed */static voidvMoveTo(diagram_type *pDiag, long lLastVerticalMovement){ fail(pDiag == NULL); fail(pDiag->pOutFile == NULL); if (pDiag->lYtop <= lFooterHeight + PS_BOTTOM_MARGIN && !bInFtrSpace) { vMove2NextPage(pDiag, FALSE); /* Repeat the last vertical movement on the new page */ pDiag->lYtop -= lLastVerticalMovement; } fail(pDiag->lYtop < lFooterHeight + PS_BOTTOM_MARGIN && !bInFtrSpace); DBG_DEC_C(pDiag->lYtop < PS_BOTTOM_MARGIN, pDiag->lYtop); fail(pDiag->lYtop < PS_BOTTOM_MARGIN / 3); if (pDiag->lYtop != lYtopCurr) { fprintf(pDiag->pOutFile, "%.2f %.2f moveto\n", dDrawUnits2Points(pDiag->lXleft + PS_LEFT_MARGIN), dDrawUnits2Points(pDiag->lYtop)); lYtopCurr = pDiag->lYtop; }} /* end of vMoveTo *//* * vProloguePS - set options and perform the PostScript initialization */voidvProloguePS(diagram_type *pDiag, const char *szTask, const char *szFilename, const options_type *pOptions){ FILE *pOutFile; const char *szTmp; time_t tTime; fail(pDiag == NULL); fail(pDiag->pOutFile == NULL); fail(szTask == NULL || szTask[0] == '\0'); fail(pOptions == NULL); pOutFile = pDiag->pOutFile; bUseLandscape = pOptions->bUseLandscape; eEncoding = pOptions->eEncoding; eImageLevel = pOptions->eImageLevel; if (pOptions->iPageHeight == INT_MAX) { lPageHeight = LONG_MAX; } else { lPageHeight = lPoints2DrawUnits(pOptions->iPageHeight); } DBG_DEC(lPageHeight); if (pOptions->iPageWidth == INT_MAX) { lPageWidth = LONG_MAX; } else { lPageWidth = lPoints2DrawUnits(pOptions->iPageWidth); } DBG_DEC(lPageWidth); lFooterHeight = 0; bInFtrSpace = FALSE; tFontRefCurr = (drawfile_fontref)-1; usFontSizeCurr = 0; iFontColorCurr = -1; lYtopCurr = -1; iPageCount = 0; iImageCount = 0; iSectionIndex = 0; bFirstInSection = TRUE; pDiag->lXleft = 0; pDiag->lYtop = lPageHeight - PS_TOP_MARGIN; szCreator = szTask; fprintf(pOutFile, "%%!PS-Adobe-2.0\n"); fprintf(pOutFile, "%%%%Title: %s\n", szBasename(szFilename)); fprintf(pOutFile, "%%%%Creator: %s %s\n", szCreator, VERSIONSTRING); szTmp = getenv("LOGNAME"); if (szTmp == NULL || szTmp[0] == '\0') { szTmp = getenv("USER"); if (szTmp == NULL || szTmp[0] == '\0') { szTmp = "unknown"; } } fprintf(pOutFile, "%%%%For: %.50s\n", szTmp); errno = 0; tTime = time(NULL); if (tTime == (time_t)-1 && errno != 0) { szCreationDate = NULL; } else { szCreationDate = ctime(&tTime); } if (szCreationDate == NULL || szCreationDate[0] == '\0') { szCreationDate = "unknown\n"; } fprintf(pOutFile, "%%%%CreationDate: %s", szCreationDate); if (bUseLandscape) { fprintf(pOutFile, "%%%%Orientation: Landscape\n"); fprintf(pOutFile, "%%%%BoundingBox: 0 0 %.0f %.0f\n", dDrawUnits2Points(lPageHeight), dDrawUnits2Points(lPageWidth)); } else { fprintf(pOutFile, "%%%%Orientation: Portrait\n"); fprintf(pOutFile, "%%%%BoundingBox: 0 0 %.0f %.0f\n", dDrawUnits2Points(lPageWidth), dDrawUnits2Points(lPageHeight)); }} /* end of vProloguePS *//* * vEpiloguePS - clean up after everything is done */voidvEpiloguePS(diagram_type *pDiag){ fail(pDiag == NULL); fail(pDiag->pOutFile == NULL); if (pDiag->lYtop < lPageHeight - PS_TOP_MARGIN) { vAddFooter(pDiag); fprintf(pDiag->pOutFile, "showpage\n"); } fprintf(pDiag->pOutFile, "%%%%Trailer\n"); fprintf(pDiag->pOutFile, "%%%%Pages: %d\n", iPageCount); fprintf(pDiag->pOutFile, "%%%%EOF\n"); szCreationDate = NULL; szCreator = NULL;} /* end of vEpiloguePS *//* * vPrintPalette - print a postscript palette */static voidvPrintPalette(FILE *pOutFile, const imagedata_type *pImg){ int iIndex; fail(pOutFile == NULL); fail(pImg == NULL); fail(pImg->iColorsUsed < 2); fail(pImg->iColorsUsed > 256); fprintf(pOutFile, "[ /Indexed\n"); fprintf(pOutFile, "\t/Device%s %d\n", pImg->bColorImage ? "RGB" : "Gray", pImg->iColorsUsed - 1); fprintf(pOutFile, "<"); for (iIndex = 0; iIndex < pImg->iColorsUsed; iIndex++) { fprintf(pOutFile, "%02x", (unsigned int)pImg->aucPalette[iIndex][0]); if (pImg->bColorImage) { fprintf(pOutFile, "%02x%02x", (unsigned int)pImg->aucPalette[iIndex][1], (unsigned int)pImg->aucPalette[iIndex][2]); } if (iIndex % 8 == 7) { fprintf(pOutFile, "\n"); } else { fprintf(pOutFile, " "); } } fprintf(pOutFile, ">\n"); fprintf(pOutFile, "] setcolorspace\n");} /* end of vPrintPalette *//* * vImageProloguePS - perform the Encapsulated PostScript initialization */voidvImageProloguePS(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; } fail(szCreationDate == NULL); fail(szCreator == NULL); fail(eImageLevel == level_no_images); iImageCount++; DBG_DEC_C(pDiag->lXleft != 0, pDiag->lXleft); pDiag->lYtop -= lPoints2DrawUnits(pImg->iVerSizeScaled); vMoveTo(pDiag, lPoints2DrawUnits(pImg->iVerSizeScaled)); pOutFile = pDiag->pOutFile; fprintf(pOutFile, "BeginEPSF\n"); fprintf(pOutFile, "%%%%BeginDocument: image%03d.eps\n", iImageCount); fprintf(pOutFile, "%%!PS-Adobe-2.0 EPSF-2.0\n"); fprintf(pOutFile, "%%%%Creator: %s %s\n", szCreator, VERSIONSTRING); fprintf(pOutFile, "%%%%Title: Image %03d\n", iImageCount); fprintf(pOutFile, "%%%%CreationDate: %s", szCreationDate); fprintf(pOutFile, "%%%%BoundingBox: 0 0 %d %d\n", pImg->iHorSizeScaled, pImg->iVerSizeScaled); fprintf(pOutFile, "%%%%DocumentData: Clean7Bit\n"); fprintf(pOutFile, "%%%%LanguageLevel: 2\n"); fprintf(pOutFile, "%%%%EndComments\n"); fprintf(pOutFile, "%%%%BeginProlog\n"); fprintf(pOutFile, "%%%%EndProlog\n"); fprintf(pOutFile, "%%%%Page: 1 1\n"); fprintf(pOutFile, "save\n"); switch (pImg->eImageType) { case imagetype_is_jpeg: fprintf(pOutFile, "/Data1 currentfile "); fprintf(pOutFile, "/ASCII85Decode filter def\n"); fprintf(pOutFile, "/Data Data1 << "); fprintf(pOutFile, ">> /DCTDecode filter def\n"); switch (pImg->iComponents) { case 1: fprintf(pOutFile, "/DeviceGray setcolorspace\n"); break; case 3: fprintf(pOutFile, "/DeviceRGB setcolorspace\n"); break; case 4: fprintf(pOutFile, "/DeviceCMYK setcolorspace\n"); break; default: DBG_DEC(pImg->iComponents); break; } break; case imagetype_is_png: if (eImageLevel == level_gs_special) { fprintf(pOutFile, "/Data2 currentfile /ASCII85Decode filter def\n"); fprintf(pOutFile, "/Data1 Data2 << >> /FlateDecode filter def\n"); fprintf(pOutFile, "/Data Data1 <<\n"); fprintf(pOutFile, "\t/Colors %d\n", pImg->iComponents); fprintf(pOutFile, "\t/BitsPerComponent %u\n", pImg->uiBitsPerComponent); fprintf(pOutFile, "\t/Columns %d\n", pImg->iWidth); fprintf(pOutFile, ">> /PNGPredictorDecode filter def\n"); } else { fprintf(pOutFile, "/Data1 currentfile /ASCII85Decode filter def\n"); fprintf(pOutFile, "/Data Data1 << >> /FlateDecode filter def\n"); } if (pImg->iComponents == 3 || pImg->iComponents == 4) { fprintf(pOutFile, "/DeviceRGB setcolorspace\n"); } else if (pImg->iColorsUsed > 0) { vPrintPalette(pOutFile, pImg); } else { fprintf(pOutFile, "/DeviceGray setcolorspace\n"); } break; case imagetype_is_dib: fprintf(pOutFile, "/Data currentfile "); fprintf(pOutFile, "/ASCII85Decode filter def\n"); if (pImg->uiBitsPerComponent <= 8) { vPrintPalette(pOutFile, pImg); } else { fprintf(pOutFile, "/DeviceRGB setcolorspace\n"); } break; default: fprintf(pOutFile, "/Data currentfile "); fprintf(pOutFile, "/ASCIIHexDecode filter def\n"); fprintf(pOutFile, "/Device%s setcolorspace\n", pImg->bColorImage ? "RGB" : "Gray"); break; } /* Translate to lower left corner of image */ fprintf(pOutFile, "%.2f %.2f translate\n", dDrawUnits2Points(pDiag->lXleft + PS_LEFT_MARGIN), dDrawUnits2Points(pDiag->lYtop)); fprintf(pOutFile, "%d %d scale\n", pImg->iHorSizeScaled, pImg->iVerSizeScaled); fprintf(pOutFile, "{ <<\n"); fprintf(pOutFile, "\t/ImageType 1\n"); fprintf(pOutFile, "\t/Width %d\n", pImg->iWidth); fprintf(pOutFile, "\t/Height %d\n", pImg->iHeight); if (pImg->eImageType == imagetype_is_dib) { /* Scanning from left to right and bottom to top */ fprintf(pOutFile, "\t/ImageMatrix [ %d 0 0 %d 0 0 ]\n", pImg->iWidth, pImg->iHeight); } else { /* Scanning from left to right and top to bottom */ fprintf(pOutFile, "\t/ImageMatrix [ %d 0 0 %d 0 %d ]\n", pImg->iWidth, -pImg->iHeight, pImg->iHeight); } fprintf(pOutFile, "\t/DataSource Data\n"); switch (pImg->eImageType) { case imagetype_is_jpeg: fprintf(pOutFile, "\t/BitsPerComponent 8\n"); switch (pImg->iComponents) { case 1: fprintf(pOutFile, "\t/Decode [0 1]\n"); break; case 3: fprintf(pOutFile, "\t/Decode [0 1 0 1 0 1]\n"); break; case 4: if (pImg->bAdobe) { /* * Adobe-conforming CMYK file * applying workaround for color inversion */ fprintf(pOutFile, "\t/Decode [1 0 1 0 1 0 1 0]\n"); } else { fprintf(pOutFile, "\t/Decode [0 1 0 1 0 1 0 1]\n"); } break; default: DBG_DEC(pImg->iComponents); break; } break; case imagetype_is_png: if (pImg->iComponents == 3) { fprintf(pOutFile, "\t/BitsPerComponent 8\n"); fprintf(pOutFile, "\t/Decode [0 1 0 1 0 1]\n"); } else if (pImg->iColorsUsed > 0) { fail(pImg->uiBitsPerComponent > 8); fprintf(pOutFile, "\t/BitsPerComponent %u\n", pImg->uiBitsPerComponent); fprintf(pOutFile, "\t/Decode [0 %d]\n", (1 << pImg->uiBitsPerComponent) - 1); } else { fprintf(pOutFile, "\t/BitsPerComponent 8\n"); fprintf(pOutFile, "\t/Decode [0 1]\n"); } break; case imagetype_is_dib: fprintf(pOutFile, "\t/BitsPerComponent 8\n"); if (pImg->uiBitsPerComponent <= 8) { fprintf(pOutFile, "\t/Decode [0 255]\n"); } else { fprintf(pOutFile, "\t/Decode [0 1 0 1 0 1]\n"); } break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -