📄 psoutputdev.cc
字号:
outputFunc, outputStream); } else { // otherwise: use a non-CID composite font ttFile->convertToType0(psName, ((GfxCIDFont *)font)->getCIDToGID(), ((GfxCIDFont *)font)->getCIDToGIDLen(), outputFunc, outputStream); } delete ttFile; gfree(fontBuf); // ending comment writePS("%%EndResource\n");}void PSOutputDev::setupType3Font(GfxFont *font, char *psName, Dict *parentResDict) { Dict *resDict; Dict *charProcs; Object charProc; Gfx *gfx; PDFRectangle box; double *m; char buf[256]; int i; // set up resources used by font if ((resDict = ((Gfx8BitFont *)font)->getResources())) { setupResources(resDict); } else { resDict = parentResDict; } // beginning comment writePSFmt("%%%%BeginResource: font %s\n", psName); embFontList->append("%%+ font "); embFontList->append(psName); embFontList->append("\n"); // font dictionary writePS("7 dict begin\n"); writePS("/FontType 3 def\n"); m = font->getFontMatrix(); writePSFmt("/FontMatrix [%g %g %g %g %g %g] def\n", m[0], m[1], m[2], m[3], m[4], m[5]); m = font->getFontBBox(); writePSFmt("/FontBBox [%g %g %g %g] def\n", m[0], m[1], m[2], m[3]); writePS("/Encoding 256 array def\n"); writePS(" 0 1 255 { Encoding exch /.notdef put } for\n"); writePS("/BuildGlyph {\n"); writePS(" exch /CharProcs get exch\n"); writePS(" 2 copy known not { pop /.notdef } if\n"); writePS(" get exec\n"); writePS("} bind def\n"); writePS("/BuildChar {\n"); writePS(" 1 index /Encoding get exch get\n"); writePS(" 1 index /BuildGlyph get exec\n"); writePS("} bind def\n"); if ((charProcs = ((Gfx8BitFont *)font)->getCharProcs())) { writePSFmt("/CharProcs %d dict def\n", charProcs->getLength()); writePS("CharProcs begin\n"); box.x1 = m[0]; box.y1 = m[1]; box.x2 = m[2]; box.y2 = m[3]; gfx = new Gfx(xref, this, resDict, &box, gFalse, NULL); inType3Char = gTrue; t3Cacheable = gFalse; for (i = 0; i < charProcs->getLength(); ++i) { writePS("/"); writePSName(charProcs->getKey(i)); writePS(" {\n"); gfx->display(charProcs->getVal(i, &charProc)); charProc.free(); if (t3String) { if (t3Cacheable) { sprintf(buf, "%g %g %g %g %g %g setcachedevice\n", t3WX, t3WY, t3LLX, t3LLY, t3URX, t3URY); } else { sprintf(buf, "%g %g setcharwidth\n", t3WX, t3WY); } (*outputFunc)(outputStream, buf, strlen(buf)); (*outputFunc)(outputStream, t3String->getCString(), t3String->getLength()); delete t3String; t3String = NULL; } (*outputFunc)(outputStream, "Q\n", 2); writePS("} def\n"); } inType3Char = gFalse; delete gfx; writePS("end\n"); } writePS("currentdict end\n"); writePSFmt("/%s exch definefont pop\n", psName); // ending comment writePS("%%EndResource\n");}void PSOutputDev::setupImages(Dict *resDict) { Object xObjDict, xObj, xObjRef, subtypeObj; int i; if (mode != psModeForm) { return; } resDict->lookup("XObject", &xObjDict); if (xObjDict.isDict()) { for (i = 0; i < xObjDict.dictGetLength(); ++i) { xObjDict.dictGetValNF(i, &xObjRef); xObjDict.dictGetVal(i, &xObj); if (xObj.isStream()) { xObj.streamGetDict()->lookup("Subtype", &subtypeObj); if (subtypeObj.isName("Image")) { if (xObjRef.isRef()) { setupImage(xObjRef.getRef(), xObj.getStream()); } else { error(-1, "Image in resource dict is not an indirect reference"); } } subtypeObj.free(); } xObj.free(); xObjRef.free(); } } xObjDict.free();}void PSOutputDev::setupImage(Ref id, Stream *str) { int c; int size, line, col, i; // construct an encoder stream if (globalParams->getPSASCIIHex()) { str = new ASCIIHexEncoder(str); } else { str = new ASCII85Encoder(str); } // compute image data size str->reset(); col = size = 0; do { do { c = str->getChar(); } while (c == '\n' || c == '\r'); if (c == '~' || c == EOF) { break; } if (c == 'z') { ++col; } else { ++col; for (i = 1; i <= 4; ++i) { do { c = str->getChar(); } while (c == '\n' || c == '\r'); if (c == '~' || c == EOF) { break; } ++col; } } if (col > 225) { ++size; col = 0; } } while (c != '~' && c != EOF); ++size; writePSFmt("%d array dup /ImData_%d_%d exch def\n", size, id.num, id.gen); // write the data into the array str->reset(); line = col = 0; writePS("dup 0 <~"); do { do { c = str->getChar(); } while (c == '\n' || c == '\r'); if (c == '~' || c == EOF) { break; } if (c == 'z') { writePSChar(c); ++col; } else { writePSChar(c); ++col; for (i = 1; i <= 4; ++i) { do { c = str->getChar(); } while (c == '\n' || c == '\r'); if (c == '~' || c == EOF) { break; } writePSChar(c); ++col; } } // each line is: "dup nnnnn <~...data...~> put<eol>" // so max data length = 255 - 20 = 235 // chunks are 1 or 4 bytes each, so we have to stop at 232 // but make it 225 just to be safe if (col > 225) { writePS("~> put\n"); ++line; writePSFmt("dup %d <~", line); col = 0; } } while (c != '~' && c != EOF); writePS("~> put\n"); writePS("pop\n"); delete str;}void PSOutputDev::startPage(int pageNum, GfxState *state) { int x1, y1, x2, y2, width, height, t; switch (mode) { case psModePS: writePSFmt("%%%%Page: %d %d\n", pageNum, seqPage); writePS("%%BeginPageSetup\n"); // rotate, translate, and scale page x1 = (int)(state->getX1() + 0.5); y1 = (int)(state->getY1() + 0.5); x2 = (int)(state->getX2() + 0.5); y2 = (int)(state->getY2() + 0.5); width = x2 - x1; height = y2 - y1; if (width > height && width > paperWidth) { landscape = gTrue; writePSFmt("%%%%PageOrientation: %s\n", state->getCTM()[0] ? "Landscape" : "Portrait"); writePS("pdfStartPage\n"); writePS("90 rotate\n"); tx = -x1; ty = -(y1 + paperWidth); t = width; width = height; height = t; } else { landscape = gFalse; writePSFmt("%%%%PageOrientation: %s\n", state->getCTM()[0] ? "Portrait" : "Landscape"); writePS("pdfStartPage\n"); tx = -x1; ty = -y1; } if (width < paperWidth) { tx += (paperWidth - width) / 2; } if (height < paperHeight) { ty += (paperHeight - height) / 2; } if (tx != 0 || ty != 0) { writePSFmt("%g %g translate\n", tx, ty); } if (width > paperWidth || height > paperHeight) { xScale = (double)paperWidth / (double)width; yScale = (double)paperHeight / (double)height; if (yScale < xScale) { xScale = yScale; } else { yScale = xScale; } writePSFmt("%0.4f %0.4f scale\n", xScale, xScale); } else { xScale = yScale = 1; } writePS("%%EndPageSetup\n"); ++seqPage; break; case psModeEPS: writePS("pdfStartPage\n"); tx = ty = 0; xScale = yScale = 1; landscape = gFalse; break; case psModeForm: writePS("/PaintProc {\n"); writePS("begin xpdf begin\n"); writePS("pdfStartPage\n"); tx = ty = 0; xScale = yScale = 1; landscape = gFalse; break; }}void PSOutputDev::endPage() { if (mode == psModeForm) { writePS("pdfEndPage\n"); writePS("end end\n"); writePS("} def\n"); writePS("end end\n"); } else { writePS("showpage\n"); writePS("%%PageTrailer\n"); writePS("pdfEndPage\n"); }}void PSOutputDev::saveState(GfxState *state) { writePS("q\n");}void PSOutputDev::restoreState(GfxState *state) { writePS("Q\n");}void PSOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32) { writePSFmt("[%g %g %g %g %g %g] cm\n", m11, m12, m21, m22, m31, m32);}void PSOutputDev::updateLineDash(GfxState *state) { double *dash; double start; int length, i; state->getLineDash(&dash, &length, &start); writePS("["); for (i = 0; i < length; ++i) writePSFmt("%g%s", dash[i], (i == length-1) ? "" : " "); writePSFmt("] %g d\n", start);}void PSOutputDev::updateFlatness(GfxState *state) { writePSFmt("%d i\n", state->getFlatness());}void PSOutputDev::updateLineJoin(GfxState *state) { writePSFmt("%d j\n", state->getLineJoin());}void PSOutputDev::updateLineCap(GfxState *state) { writePSFmt("%d J\n", state->getLineCap());}void PSOutputDev::updateMiterLimit(GfxState *state) { writePSFmt("%g M\n", state->getMiterLimit());}void PSOutputDev::updateLineWidth(GfxState *state) { writePSFmt("%g w\n", state->getLineWidth());}void PSOutputDev::updateFillColor(GfxState *state) { GfxColor color; double gray; GfxRGB rgb; GfxCMYK cmyk; GfxSeparationColorSpace *sepCS; switch (level) { case psLevel1: state->getFillGray(&gray); writePSFmt("%g g\n", gray); break; case psLevel1Sep: state->getFillCMYK(&cmyk); writePSFmt("%g %g %g %g k\n", cmyk.c, cmyk.m, cmyk.y, cmyk.k); addProcessColor(cmyk.c, cmyk.m, cmyk.y, cmyk.k); break; case psLevel2: case psLevel3: if (state->getFillColorSpace()->getMode() == csDeviceCMYK) { state->getFillCMYK(&cmyk); writePSFmt("%g %g %g %g k\n", cmyk.c, cmyk.m, cmyk.y, cmyk.k); } else { state->getFillRGB(&rgb); if (rgb.r == rgb.g && rgb.g == rgb.b) { writePSFmt("%g g\n", rgb.r); } else { writePSFmt("%g %g %g rg\n", rgb.r, rgb.g, rgb.b); } } break; case psLevel2Sep: case psLevel3Sep: if (state->getFillColorSpace()->getMode() == csSeparation) { sepCS = (GfxSeparationColorSpace *)state->getFillColorSpace(); color.c[0] = 1; sepCS->getCMYK(&color, &cmyk); writePSFmt("%g %g %g %g %g (%s) ck\n", state->getFillColor()->c[0], cmyk.c, cmyk.m, cmyk.y, cmyk.k, sepCS->getName()->getCString()); addCustomColor(sepCS); } else { state->getFillCMYK(&cmyk); writePSFmt("%g %g %g %g k\n", cmyk.c, cmyk.m, cmyk.y, cmyk.k); addProcessColor(cmyk.c, cmyk.m, cmyk.y, cmyk.k); } break; } t3Cacheable = gFalse;}void PSOutputDev::updateStrokeColor(GfxState *state) { GfxColor color; double gray; GfxRGB rgb; GfxCMYK cmyk; GfxSeparationColorSpace *sepCS; switch (level) { case psLevel1: state->getStrokeGray(&gray); writePSFmt("%g G\n", gray); break; case psLevel1Sep: state->getStrokeCMYK(&cmyk); writePSFmt("%g %g %g %g K\n", cmyk.c, cmyk.m, cmyk.y, cmyk.k); addProcessColor(cmyk.c, cmyk.m, cmyk.y, cmyk.k); break; case psLevel2: case psLevel3: if (state->getStrokeColorSpace()->getMode() == csDeviceCMYK) { state->getStrokeCMYK(&cmyk); writePSFmt("%g %g %g %g K\n", cmyk.c, cmyk.m, cmyk.y, cmyk.k); } else { state->getStrokeRGB(&rgb); if (rgb.r == rgb.g && rgb.g == rgb.b) { writePSFmt("%g G\n", rgb.r); } else { writePSFmt("%g %g %g RG\n", rgb.r, rgb.g, rgb.b); } } break; case psLevel2Sep: case psLevel3Sep: if (state->getStrokeColorSpace()->getMode() == csSeparation) { sepCS = (GfxSeparationColorSpace *)state->getStrokeColorSpace(); color.c[0] = 1; sepCS->getCMYK(&color, &cmyk); writePSFmt("%g %g %g %g %g (%s) CK\n", state->getStrokeColor()->c[0], cmyk.c, cmyk.m, cmyk.y, cmyk.k, sepCS->getName()->getCString()); addCustomColor(sepCS); } else { state->getStrokeCMYK(&cmyk); writePSFmt("%g %g %g %g K\n", cmyk.c, cmyk.m, cmyk.y, cmyk.k); addProcessColor(cmyk.c, cmyk.m, cmyk.y, cmyk.k); } break; } t3Cacheable = gFalse;}void PSOutputDev::addProcessColor(double c, double m, double y, double k) { if (c > 0) { processColors |= psProcessCyan; } if (m > 0) { processColors |= psProcessMagenta; } if (y > 0) { processColors |= psProcessYellow; } if (k > 0) { processColors |= psProcessBlack; }}void PSOutputDev::addCustomColor(GfxSeparationColorSpace *sepCS) { PSOutCustomColor *cc; GfxColor color; GfxCMYK cmyk; for (cc = customColors; cc; cc = cc->next) { if (!cc->name->cmp(sepCS->getName())) { return; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -