📄 postscript.c
字号:
default: fprintf(pOutFile, "\t/BitsPerComponent 8\n"); if (pImg->bColorImage) { fprintf(pOutFile, "\t/Decode [0 1 0 1 0 1]\n"); } else { fprintf(pOutFile, "\t/Decode [0 1]\n"); } break; } fprintf(pOutFile, " >> image\n"); fprintf(pOutFile, " Data closefile\n"); fprintf(pOutFile, " showpage\n"); fprintf(pOutFile, " restore\n"); fprintf(pOutFile, "} exec\n");} /* end of vImageProloguePS *//* * vImageEpiloguePS - clean up after Encapsulated PostScript */voidvImageEpiloguePS(diagram_type *pDiag){ FILE *pOutFile; fail(pDiag == NULL); fail(pDiag->pOutFile == NULL); pOutFile = pDiag->pOutFile; fprintf(pOutFile, "%%%%EOF\n"); fprintf(pOutFile, "%%%%EndDocument\n"); fprintf(pOutFile, "EndEPSF\n"); pDiag->lXleft = 0;} /* end of vImageEpiloguePS *//* * bAddDummyImagePS - add a dummy image * * return TRUE when successful, otherwise FALSE */BOOLbAddDummyImagePS(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; fprintf(pOutFile, "gsave %% Image %03d\n", iImageCount); fprintf(pOutFile, "\tnewpath\n"); fprintf(pOutFile, "\t%.2f %.2f moveto\n", dDrawUnits2Points(pDiag->lXleft + PS_LEFT_MARGIN), dDrawUnits2Points(pDiag->lYtop)); fprintf(pOutFile, "\t1.0 setlinewidth\n"); fprintf(pOutFile, "\t0.3 setgray\n"); fprintf(pOutFile, "\t0 %d rlineto\n", pImg->iVerSizeScaled); fprintf(pOutFile, "\t%d 0 rlineto\n", pImg->iHorSizeScaled); fprintf(pOutFile, "\t0 %d rlineto\n", -pImg->iVerSizeScaled); fprintf(pOutFile, "\tclosepath\n"); fprintf(pOutFile, "\tstroke\n"); fprintf(pOutFile, "grestore\n"); pDiag->lXleft = 0; return TRUE;} /* end of bAddDummyImagePS *//* * vAddFontsPS - add the list of fonts and complete the prologue */voidvAddFontsPS(diagram_type *pDiag){ FILE *pOutFile; const font_table_type *pTmp, *pTmp2; size_t tIndex; int iLineLen, iOurFontnameLen; BOOL bFound; fail(pDiag == NULL); fail(pDiag->pOutFile == NULL); pOutFile = pDiag->pOutFile; iLineLen = fprintf(pOutFile, "%%%%DocumentFonts:"); if (tGetFontTableLength() == 0) { iLineLen += fprintf(pOutFile, " Courier"); } else { pTmp = NULL; while ((pTmp = pGetNextFontTableRecord(pTmp)) != NULL) { /* Print the document fonts */ bFound = FALSE; pTmp2 = NULL; while ((pTmp2 = pGetNextFontTableRecord(pTmp2)) != NULL && pTmp2 < pTmp) { bFound = STREQ(pTmp2->szOurFontname, pTmp->szOurFontname); if (bFound) { break; } } iOurFontnameLen = (int)strlen(pTmp->szOurFontname); if (bFound || iOurFontnameLen <= 0) { continue; } if (iLineLen + iOurFontnameLen > 76) { fprintf(pOutFile, "\n%%%%+"); iLineLen = 3; } iLineLen += fprintf(pOutFile, " %s", pTmp->szOurFontname); } } fprintf(pOutFile, "\n"); fprintf(pOutFile, "%%%%Pages: (atend)\n"); fprintf(pOutFile, "%%%%EndComments\n"); fprintf(pOutFile, "%%%%BeginProlog\n"); switch (eEncoding) { case encoding_latin_1: for (tIndex = 0; tIndex < elementsof(iso_8859_1_data); tIndex++) { fprintf(pOutFile, "%s\n", iso_8859_1_data[tIndex]); } fprintf(pOutFile, "\n"); for (tIndex = 0; tIndex < elementsof(iso_8859_x_func); tIndex++) { fprintf(pOutFile, "%s\n", iso_8859_x_func[tIndex]); } break; case encoding_latin_2: for (tIndex = 0; tIndex < elementsof(iso_8859_2_data); tIndex++) { fprintf(pOutFile, "%s\n", iso_8859_2_data[tIndex]); } fprintf(pOutFile, "\n"); for (tIndex = 0; tIndex < elementsof(iso_8859_x_func); tIndex++) { fprintf(pOutFile, "%s\n", iso_8859_x_func[tIndex]); } break; case encoding_cyrillic: for (tIndex = 0; tIndex < elementsof(iso_8859_5_data); tIndex++) { fprintf(pOutFile, "%s\n", iso_8859_5_data[tIndex]); } fprintf(pOutFile, "\n"); for (tIndex = 0; tIndex < elementsof(iso_8859_x_func); tIndex++) { fprintf(pOutFile, "%s\n", iso_8859_x_func[tIndex]); } break; case encoding_utf_8: werr(1, "The combination PostScript and UTF-8 is not supported"); break; default: DBG_DEC(eEncoding); break; } /* The rest of the functions */ for (tIndex = 0; tIndex < elementsof(misc_func); tIndex++) { fprintf(pOutFile, "%s\n", misc_func[tIndex]); } fprintf(pOutFile, "%%%%EndProlog\n"); iPageCount = 1; fprintf(pDiag->pOutFile, "%%%%Page: %d %d\n", iPageCount, iPageCount); vAddPageSetup(pDiag->pOutFile); vAddHeader(pDiag);} /* end of vAddFontsPS *//* * vPrintPS - print a PostScript string */static voidvPrintPS(FILE *pFile, const char *szString, size_t tStringLength, USHORT usFontstyle){ double dSuperscriptMove, dSubscriptMove; const UCHAR *ucBytes; size_t tCount; fail(szString == NULL); if (szString == NULL || szString[0] == '\0' || tStringLength == 0) { return; } DBG_DEC_C(usFontSizeCurr < MIN_FONT_SIZE, usFontSizeCurr); dSuperscriptMove = 0.0; dSubscriptMove = 0.0; /* Up for superscript */ if (bIsSuperscript(usFontstyle) && usFontSizeCurr != 0) { dSuperscriptMove = (double)((usFontSizeCurr + 1) / 2) * 0.375; fprintf(pFile, "0 %.2f rmoveto\n", dSuperscriptMove); } /* Down for subscript */ if (bIsSubscript(usFontstyle) && usFontSizeCurr != 0) { dSubscriptMove = (double)usFontSizeCurr * 0.125; fprintf(pFile, "0 %.2f rmoveto\n", -dSubscriptMove); } /* Generate and print the PostScript output */ ucBytes = (UCHAR *)szString; (void)putc('(', pFile); for (tCount = 0; tCount < tStringLength ; tCount++) { switch (ucBytes[tCount]) { case '(': case ')': case '\\': (void)putc('\\', pFile); (void)putc(szString[tCount], pFile); break; default: if (ucBytes[tCount] < 0x20 || (ucBytes[tCount] >= 0x7f && ucBytes[tCount] < 0x8c)) { DBG_HEX(ucBytes[tCount]); (void)putc(' ', pFile); } else if (ucBytes[tCount] >= 0x80) { fprintf(pFile, "\\%03o", (UINT)ucBytes[tCount]); } else { (void)putc(szString[tCount], pFile); } break; } } fprintf(pFile, ") "); if ((bIsStrike(usFontstyle) || bIsMarkDel(usFontstyle)) && usFontSizeCurr != 0) { fprintf(pFile, "%.2f %.2f LineShow\n", (double)usFontSizeCurr * 0.02, (double)usFontSizeCurr * 0.12); } else if (bIsUnderline(usFontstyle) && usFontSizeCurr != 0) { fprintf(pFile, "%.2f %.2f LineShow\n", (double)usFontSizeCurr * 0.02, (double)usFontSizeCurr * -0.06); } else { fprintf(pFile, "show\n"); } /* Undo the superscript move */ if (bIsSuperscript(usFontstyle) && usFontSizeCurr != 0) { fprintf(pFile, "0 %.2f rmoveto\n", -dSuperscriptMove); } /* Undo the subscript move */ if (bIsSubscript(usFontstyle) && usFontSizeCurr != 0) { fprintf(pFile, "0 %.2f rmoveto\n", dSubscriptMove); }} /* end of vPrintPS *//* * 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; fprintf(pFile, "%.3f %.3f %.3f setrgbcolor\n", ulRed / 255.0, ulGreen / 255.0, ulBlue / 255.0);} /* end of vSetColor *//* * vMove2NextLinePS - move to the next line */voidvMove2NextLinePS(diagram_type *pDiag, USHORT usFontSize){ fail(pDiag == NULL); fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE); pDiag->lYtop -= lComputeLeading(usFontSize);} /* end of vMove2NextLinePS *//* * vSubstringPS - print a sub string */voidvSubstringPS(diagram_type *pDiag, char *szString, size_t tStringLength, long lStringWidth, UCHAR ucFontColor, USHORT usFontstyle, drawfile_fontref tFontRef, USHORT usFontSize, USHORT usMaxFontSize){ const char *szOurFontname; 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; } if (tFontRef != tFontRefCurr || usFontSize != usFontSizeCurr) { szOurFontname = szGetFontname(tFontRef); fail(szOurFontname == NULL); fprintf(pDiag->pOutFile, "%.1f /%s /%s-ISO-8859-x ChgFnt\n", (double)usFontSize / 2.0, szOurFontname, szOurFontname); tFontRefCurr = tFontRef; usFontSizeCurr = usFontSize; } if ((int)ucFontColor != iFontColorCurr) { vSetColor(pDiag->pOutFile, ucFontColor); iFontColorCurr = (int)ucFontColor; } vMoveTo(pDiag, lComputeLeading(usMaxFontSize)); vPrintPS(pDiag->pOutFile, szString, tStringLength, usFontstyle); pDiag->lXleft += lStringWidth;} /* end of vSubstringPS *//* * Create an start of paragraph by moving the y-top mark */voidvStartOfParagraphPS(diagram_type *pDiag, long lBeforeIndentation){ fail(pDiag == NULL); fail(lBeforeIndentation < 0); pDiag->lXleft = 0; pDiag->lYtop -= lMilliPoints2DrawUnits(lBeforeIndentation);} /* end of vStartOfParagraphPS *//* * Create an end of paragraph by moving the y-top mark */voidvEndOfParagraphPS(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 */ vMove2NextLinePS(pDiag, usFontSize); } pDiag->lXleft = 0; pDiag->lYtop -= lMilliPoints2DrawUnits(lAfterIndentation);} /* end of vEndOfParagraphPS *//* * Create an end of page */voidvEndOfPagePS(diagram_type *pDiag, BOOL bNewSection){ vMove2NextPage(pDiag, bNewSection);} /* end of vEndOfPagePS */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -