📄 psoutputdev.cc
字号:
color.c[0] = 1; sepCS->getCMYK(&color, &cmyk); cc = new PSOutCustomColor(cmyk.c, cmyk.m, cmyk.y, cmyk.k, sepCS->getName()->copy()); cc->next = customColors; customColors = cc;}void PSOutputDev::updateFont(GfxState *state) { if (state->getFont()) { writePSFmt("/F%d_%d %g Tf\n", state->getFont()->getID()->num, state->getFont()->getID()->gen, state->getFontSize()); }}void PSOutputDev::updateTextMat(GfxState *state) { double *mat; mat = state->getTextMat(); writePSFmt("[%g %g %g %g %g %g] Tm\n", mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]);}void PSOutputDev::updateCharSpace(GfxState *state) { writePSFmt("%g Tc\n", state->getCharSpace());}void PSOutputDev::updateRender(GfxState *state) { int rm; rm = state->getRender(); writePSFmt("%d Tr\n", rm); rm &= 3; if (rm != 0 && rm != 3) { t3Cacheable = gFalse; }}void PSOutputDev::updateRise(GfxState *state) { writePSFmt("%g Ts\n", state->getRise());}void PSOutputDev::updateWordSpace(GfxState *state) { writePSFmt("%g Tw\n", state->getWordSpace());}void PSOutputDev::updateHorizScaling(GfxState *state) { writePSFmt("%g Tz\n", state->getHorizScaling());}void PSOutputDev::updateTextPos(GfxState *state) { writePSFmt("%g %g Td\n", state->getLineX(), state->getLineY());}void PSOutputDev::updateTextShift(GfxState *state, double shift) { if (state->getFont()->getWMode()) { writePSFmt("%g TJmV\n", shift); } else { writePSFmt("%g TJm\n", shift); }}void PSOutputDev::stroke(GfxState *state) { doPath(state->getPath()); if (t3String) { // if we're construct a cacheable Type 3 glyph, we need to do // everything in the fill color writePS("Sf\n"); } else { writePS("S\n"); }}void PSOutputDev::fill(GfxState *state) { doPath(state->getPath()); writePS("f\n");}void PSOutputDev::eoFill(GfxState *state) { doPath(state->getPath()); writePS("f*\n");}void PSOutputDev::clip(GfxState *state) { doPath(state->getPath()); writePS("W\n");}void PSOutputDev::eoClip(GfxState *state) { doPath(state->getPath()); writePS("W*\n");}void PSOutputDev::doPath(GfxPath *path) { GfxSubpath *subpath; double x0, y0, x1, y1, x2, y2, x3, y3, x4, y4; int n, m, i, j; n = path->getNumSubpaths(); if (n == 1 && path->getSubpath(0)->getNumPoints() == 5) { subpath = path->getSubpath(0); x0 = subpath->getX(0); y0 = subpath->getY(0); x4 = subpath->getX(4); y4 = subpath->getY(4); if (x4 == x0 && y4 == y0) { x1 = subpath->getX(1); y1 = subpath->getY(1); x2 = subpath->getX(2); y2 = subpath->getY(2); x3 = subpath->getX(3); y3 = subpath->getY(3); if (x0 == x1 && x2 == x3 && y0 == y3 && y1 == y2) { writePSFmt("%g %g %g %g re\n", x0 < x2 ? x0 : x2, y0 < y1 ? y0 : y1, fabs(x2 - x0), fabs(y1 - y0)); return; } else if (x0 == x3 && x1 == x2 && y0 == y1 && y2 == y3) { writePSFmt("%g %g %g %g re\n", x0 < x1 ? x0 : x1, y0 < y2 ? y0 : y2, fabs(x1 - x0), fabs(y2 - y0)); return; } } } for (i = 0; i < n; ++i) { subpath = path->getSubpath(i); m = subpath->getNumPoints(); writePSFmt("%g %g m\n", subpath->getX(0), subpath->getY(0)); j = 1; while (j < m) { if (subpath->getCurve(j)) { writePSFmt("%g %g %g %g %g %g c\n", subpath->getX(j), subpath->getY(j), subpath->getX(j+1), subpath->getY(j+1), subpath->getX(j+2), subpath->getY(j+2)); j += 3; } else { writePSFmt("%g %g l\n", subpath->getX(j), subpath->getY(j)); ++j; } } if (subpath->isClosed()) { writePS("h\n"); } }}void PSOutputDev::drawString(GfxState *state, GString *s) { GfxFont *font; int wMode; GString *s2; double dx, dy, dx2, dy2, originX, originY; char *p; UnicodeMap *uMap; CharCode code; Unicode u[8]; char buf[8]; int len, nChars, uLen, n, m, i, j; // check for invisible text -- this is used by Acrobat Capture if ((state->getRender() & 3) == 3) { return; } // ignore empty strings if (s->getLength() == 0) { return; } // get the font if (!(font = state->getFont())) { return; } wMode = font->getWMode(); // check for a subtitute 16-bit font uMap = NULL; if (font->isCIDFont()) { for (i = 0; i < font16EncLen; ++i) { if (font->getID()->num == font16Enc[i].fontID.num && font->getID()->gen == font16Enc[i].fontID.gen) { uMap = globalParams->getUnicodeMap(font16Enc[i].enc); break; } } } // compute width of chars in string, ignoring char spacing and word // spacing -- the Tj operator will adjust for the metrics of the // font that's actually used dx = dy = 0; nChars = 0; p = s->getCString(); len = s->getLength(); if (font->isCIDFont()) { s2 = new GString(); } else { s2 = s; } while (len > 0) { n = font->getNextChar(p, len, &code, u, (int)(sizeof(u) / sizeof(Unicode)), &uLen, &dx2, &dy2, &originX, &originY); if (font->isCIDFont()) { if (uMap) { for (i = 0; i < uLen; ++i) { m = uMap->mapUnicode(u[i], buf, (int)sizeof(buf)); for (j = 0; j < m; ++j) { s2->append(buf[j]); } } //~ this really needs to get the number of chars in the target //~ encoding - which may be more than the number of Unicode //~ chars nChars += uLen; } else { s2->append((char)((code >> 8) & 0xff)); s2->append((char)(code & 0xff)); ++nChars; } } dx += dx2; dy += dy2; p += n; len -= n; } dx *= state->getFontSize() * state->getHorizScaling(); dy *= state->getFontSize(); if (uMap) { uMap->decRefCnt(); } if (s2->getLength() > 0) { writePSString(s2); if (font->isCIDFont()) { if (wMode) { writePSFmt(" %d %g Tj16V\n", nChars, dy); } else { writePSFmt(" %d %g Tj16\n", nChars, dx); } } else { writePSFmt(" %g Tj\n", dx); } } if (font->isCIDFont()) { delete s2; }}void PSOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool inlineImg) { int len; len = height * ((width + 7) / 8); if (level == psLevel1 || level == psLevel1Sep) { doImageL1(NULL, invert, inlineImg, str, width, height, len); } else { doImageL2(ref, NULL, invert, inlineImg, str, width, height, len); }}void PSOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, int *maskColors, GBool inlineImg) { int len; len = height * ((width * colorMap->getNumPixelComps() * colorMap->getBits() + 7) / 8); switch (level) { case psLevel1: doImageL1(colorMap, gFalse, inlineImg, str, width, height, len); break; case psLevel1Sep: //~ handle indexed, separation, ... color spaces doImageL1Sep(colorMap, gFalse, inlineImg, str, width, height, len); break; case psLevel2: case psLevel2Sep: case psLevel3: case psLevel3Sep: doImageL2(ref, colorMap, gFalse, inlineImg, str, width, height, len); break; } t3Cacheable = gFalse;}void PSOutputDev::doImageL1(GfxImageColorMap *colorMap, GBool invert, GBool inlineImg, Stream *str, int width, int height, int len) { ImageStream *imgStr; Guchar pixBuf[gfxColorMaxComps]; double gray; int x, y, i; // width, height, matrix, bits per component if (colorMap) { writePSFmt("%d %d 8 [%d 0 0 %d 0 %d] pdfIm1\n", width, height, width, -height, height); } else { writePSFmt("%d %d %s [%d 0 0 %d 0 %d] pdfImM1\n", width, height, invert ? "true" : "false", width, -height, height); } // image if (colorMap) { // set up to process the data stream imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits()); imgStr->reset(); // process the data stream i = 0; for (y = 0; y < height; ++y) { // write the line for (x = 0; x < width; ++x) { imgStr->getPixel(pixBuf); colorMap->getGray(pixBuf, &gray); writePSFmt("%02x", (int)(gray * 255 + 0.5)); if (++i == 32) { writePSChar('\n'); i = 0; } } } if (i != 0) { writePSChar('\n'); } delete imgStr; // imagemask } else { str->reset(); i = 0; for (y = 0; y < height; ++y) { for (x = 0; x < width; x += 8) { writePSFmt("%02x", str->getChar() & 0xff); if (++i == 32) { writePSChar('\n'); i = 0; } } } if (i != 0) { writePSChar('\n'); } str->close(); }}void PSOutputDev::doImageL1Sep(GfxImageColorMap *colorMap, GBool invert, GBool inlineImg, Stream *str, int width, int height, int len) { ImageStream *imgStr; Guchar *lineBuf; Guchar pixBuf[gfxColorMaxComps]; GfxCMYK cmyk; int x, y, i, comp; // width, height, matrix, bits per component writePSFmt("%d %d 8 [%d 0 0 %d 0 %d] pdfIm1Sep\n", width, height, width, -height, height); // allocate a line buffer lineBuf = (Guchar *)gmalloc(4 * width); // set up to process the data stream imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits()); imgStr->reset(); // process the data stream i = 0; for (y = 0; y < height; ++y) { // read the line for (x = 0; x < width; ++x) { imgStr->getPixel(pixBuf); colorMap->getCMYK(pixBuf, &cmyk); lineBuf[4*x+0] = (int)(255 * cmyk.c + 0.5); lineBuf[4*x+1] = (int)(255 * cmyk.m + 0.5); lineBuf[4*x+2] = (int)(255 * cmyk.y + 0.5); lineBuf[4*x+3] = (int)(255 * cmyk.k + 0.5); addProcessColor(cmyk.c, cmyk.m, cmyk.y, cmyk.k); } // write one line of each color component for (comp = 0; comp < 4; ++comp) { for (x = 0; x < width; ++x) { writePSFmt("%02x", lineBuf[4*x + comp]); if (++i == 32) { writePSChar('\n'); i = 0; } } } } if (i != 0) { writePSChar('\n'); } delete imgStr; gfree(lineBuf);}void PSOutputDev::doImageL2(Object *ref, GfxImageColorMap *colorMap, GBool invert, GBool inlineImg, Stream *str, int width, int height, int len) { GString *s; int n, numComps; GBool useRLE, useASCII, useCompressed; GfxSeparationColorSpace *sepCS; GfxColor color; GfxCMYK cmyk; int c; int line, col, i; // color space if (colorMap) { dumpColorSpaceL2(colorMap->getColorSpace()); writePS(" setcolorspace\n"); } // set up the image data if (mode == psModeForm || inType3Char) { if (inlineImg) { // create an array str = new FixedLengthEncoder(str, len); if (globalParams->getPSASCIIHex()) { str = new ASCIIHexEncoder(str); } else { str = new ASCII85Encoder(str); } str->reset(); line = col = 0; writePS("[<~"); 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("~>\n"); ++line; writePSFmt("<~", line); col = 0; } } while (c != '~' && c != EOF); writePS("~>]\n"); writePS("0\n"); delete str; } else { // set up to use the array already created by setupImages() writePSFmt("ImDat
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -