📄 splash.cc
字号:
*pipe->destColorPtr++ = cResult0; *pipe->destColorPtr++ = cResult1; *pipe->destColorPtr++ = cResult2; break; case splashModeBGR8: *pipe->destColorPtr++ = cResult2; *pipe->destColorPtr++ = cResult1; *pipe->destColorPtr++ = cResult0; break;#if SPLASH_CMYK case splashModeCMYK8: *pipe->destColorPtr++ = cResult0; *pipe->destColorPtr++ = cResult1; *pipe->destColorPtr++ = cResult2; *pipe->destColorPtr++ = cResult3; break;#endif } if (pipe->destAlphaPtr) { *pipe->destAlphaPtr++ = aResult; } } ++pipe->x;}inline void Splash::pipeSetXY(SplashPipe *pipe, int x, int y) { pipe->x = x; pipe->y = y; if (state->softMask) { pipe->softMaskPtr = &state->softMask->data[y * state->softMask->rowSize + x]; } switch (bitmap->mode) { case splashModeMono1: pipe->destColorPtr = &bitmap->data[y * bitmap->rowSize + (x >> 3)]; pipe->destColorMask = 0x80 >> (x & 7); break; case splashModeMono8: pipe->destColorPtr = &bitmap->data[y * bitmap->rowSize + x]; break; case splashModeRGB8: case splashModeBGR8: pipe->destColorPtr = &bitmap->data[y * bitmap->rowSize + 3 * x]; break;#if SPLASH_CMYK case splashModeCMYK8: pipe->destColorPtr = &bitmap->data[y * bitmap->rowSize + 4 * x]; break;#endif } if (bitmap->alpha) { pipe->destAlphaPtr = &bitmap->alpha[y * bitmap->width + x]; } else { pipe->destAlphaPtr = NULL; } if (state->inNonIsolatedGroup && alpha0Bitmap->alpha) { pipe->alpha0Ptr = &alpha0Bitmap->alpha[(alpha0Y + y) * alpha0Bitmap->width + (alpha0X + x)]; } else { pipe->alpha0Ptr = NULL; }}inline void Splash::pipeIncX(SplashPipe *pipe) { ++pipe->x; if (state->softMask) { ++pipe->softMaskPtr; } switch (bitmap->mode) { case splashModeMono1: if (!(pipe->destColorMask >>= 1)) { pipe->destColorMask = 0x80; ++pipe->destColorPtr; } break; case splashModeMono8: ++pipe->destColorPtr; break; case splashModeRGB8: case splashModeBGR8: pipe->destColorPtr += 3; break;#if SPLASH_CMYK case splashModeCMYK8: pipe->destColorPtr += 4; break;#endif } if (pipe->destAlphaPtr) { ++pipe->destAlphaPtr; } if (pipe->alpha0Ptr) { ++pipe->alpha0Ptr; }}inline void Splash::drawPixel(SplashPipe *pipe, int x, int y, GBool noClip) { if (noClip || state->clip->test(x, y)) { pipeSetXY(pipe, x, y); pipeRun(pipe); updateModX(x); updateModY(y); }}inline void Splash::drawAAPixelInit() { aaBufY = -1;}inline void Splash::drawAAPixel(SplashPipe *pipe, int x, int y) {#if splashAASize == 4 static int bitCount4[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; int w;#else int xx, yy;#endif SplashColorPtr p; int x0, x1, t; if (x < 0 || x >= bitmap->width || y < state->clip->getYMinI() || y > state->clip->getYMaxI()) { return; } // update aaBuf if (y != aaBufY) { memset(aaBuf->getDataPtr(), 0xff, aaBuf->getRowSize() * aaBuf->getHeight()); x0 = 0; x1 = bitmap->width - 1; state->clip->clipAALine(aaBuf, &x0, &x1, y); aaBufY = y; } // compute the shape value#if splashAASize == 4 p = aaBuf->getDataPtr() + (x >> 1); w = aaBuf->getRowSize(); if (x & 1) { t = bitCount4[*p & 0x0f] + bitCount4[p[w] & 0x0f] + bitCount4[p[2*w] & 0x0f] + bitCount4[p[3*w] & 0x0f]; } else { t = bitCount4[*p >> 4] + bitCount4[p[w] >> 4] + bitCount4[p[2*w] >> 4] + bitCount4[p[3*w] >> 4]; }#else t = 0; for (yy = 0; yy < splashAASize; ++yy) { for (xx = 0; xx < splashAASize; ++xx) { p = aaBuf->getDataPtr() + yy * aaBuf->getRowSize() + ((x * splashAASize + xx) >> 3); t += (*p >> (7 - ((x * splashAASize + xx) & 7))) & 1; } }#endif // draw the pixel if (t != 0) { pipeSetXY(pipe, x, y); pipe->shape *= aaGamma[t]; pipeRun(pipe); updateModX(x); updateModY(y); }}inline void Splash::drawSpan(SplashPipe *pipe, int x0, int x1, int y, GBool noClip) { int x; pipeSetXY(pipe, x0, y); if (noClip) { for (x = x0; x <= x1; ++x) { pipeRun(pipe); } updateModX(x0); updateModX(x1); updateModY(y); } else { for (x = x0; x <= x1; ++x) { if (state->clip->test(x, y)) { pipeRun(pipe); updateModX(x); updateModY(y); } else { pipeIncX(pipe); } } }}inline void Splash::drawAALine(SplashPipe *pipe, int x0, int x1, int y) {#if splashAASize == 4 static int bitCount4[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; SplashColorPtr p0, p1, p2, p3; int t;#else SplashColorPtr p; int xx, yy, t;#endif int x;#if splashAASize == 4 p0 = aaBuf->getDataPtr() + (x0 >> 1); p1 = p0 + aaBuf->getRowSize(); p2 = p1 + aaBuf->getRowSize(); p3 = p2 + aaBuf->getRowSize();#endif pipeSetXY(pipe, x0, y); for (x = x0; x <= x1; ++x) { // compute the shape value#if splashAASize == 4 if (x & 1) { t = bitCount4[*p0 & 0x0f] + bitCount4[*p1 & 0x0f] + bitCount4[*p2 & 0x0f] + bitCount4[*p3 & 0x0f]; ++p0; ++p1; ++p2; ++p3; } else { t = bitCount4[*p0 >> 4] + bitCount4[*p1 >> 4] + bitCount4[*p2 >> 4] + bitCount4[*p3 >> 4]; }#else t = 0; for (yy = 0; yy < splashAASize; ++yy) { for (xx = 0; xx < splashAASize; ++xx) { p = aaBuf->getDataPtr() + yy * aaBuf->getRowSize() + ((x * splashAASize + xx) >> 3); t += (*p >> (7 - ((x * splashAASize + xx) & 7))) & 1; } }#endif if (t != 0) { pipe->shape = aaGamma[t]; pipeRun(pipe); updateModX(x); updateModY(y); } else { pipeIncX(pipe); } }}//------------------------------------------------------------------------// Transform a point from user space to device space.inline void Splash::transform(SplashCoord *matrix, SplashCoord xi, SplashCoord yi, SplashCoord *xo, SplashCoord *yo) { // [ m[0] m[1] 0 ] // [xo yo 1] = [xi yi 1] * [ m[2] m[3] 0 ] // [ m[4] m[5] 1 ] *xo = xi * matrix[0] + yi * matrix[2] + matrix[4]; *yo = xi * matrix[1] + yi * matrix[3] + matrix[5];}//------------------------------------------------------------------------// Splash//------------------------------------------------------------------------Splash::Splash(SplashBitmap *bitmapA, GBool vectorAntialiasA, SplashScreenParams *screenParams) { int i; bitmap = bitmapA; vectorAntialias = vectorAntialiasA; state = new SplashState(bitmap->width, bitmap->height, vectorAntialias, screenParams); if (vectorAntialias) { aaBuf = new SplashBitmap(splashAASize * bitmap->width, splashAASize, 1, splashModeMono1, gFalse); for (i = 0; i <= splashAASize * splashAASize; ++i) { aaGamma[i] = splashPow((SplashCoord)i / (SplashCoord)(splashAASize * splashAASize), 1.5); } } else { aaBuf = NULL; } clearModRegion(); debugMode = gFalse;}Splash::Splash(SplashBitmap *bitmapA, GBool vectorAntialiasA, SplashScreen *screenA) { int i; bitmap = bitmapA; vectorAntialias = vectorAntialiasA; state = new SplashState(bitmap->width, bitmap->height, vectorAntialias, screenA); if (vectorAntialias) { aaBuf = new SplashBitmap(splashAASize * bitmap->width, splashAASize, 1, splashModeMono1, gFalse); for (i = 0; i <= splashAASize * splashAASize; ++i) { aaGamma[i] = splashPow((SplashCoord)i / (SplashCoord)(splashAASize * splashAASize), 1.5); } } else { aaBuf = NULL; } clearModRegion(); debugMode = gFalse;}Splash::~Splash() { while (state->next) { restoreState(); } delete state; if (vectorAntialias) { delete aaBuf; }}//------------------------------------------------------------------------// state read//------------------------------------------------------------------------SplashCoord *Splash::getMatrix() { return state->matrix;}SplashPattern *Splash::getStrokePattern() { return state->strokePattern;}SplashPattern *Splash::getFillPattern() { return state->fillPattern;}SplashScreen *Splash::getScreen() { return state->screen;}SplashBlendFunc Splash::getBlendFunc() { return state->blendFunc;}SplashCoord Splash::getStrokeAlpha() { return state->strokeAlpha;}SplashCoord Splash::getFillAlpha() { return state->fillAlpha;}SplashCoord Splash::getLineWidth() { return state->lineWidth;}int Splash::getLineCap() { return state->lineCap;}int Splash::getLineJoin() { return state->lineJoin;}SplashCoord Splash::getMiterLimit() { return state->miterLimit;}SplashCoord Splash::getFlatness() { return state->flatness;}SplashCoord *Splash::getLineDash() { return state->lineDash;}int Splash::getLineDashLength() { return state->lineDashLength;}SplashCoord Splash::getLineDashPhase() { return state->lineDashPhase;}SplashClip *Splash::getClip() { return state->clip;}SplashBitmap *Splash::getSoftMask() { return state->softMask;}GBool Splash::getInNonIsolatedGroup() { return state->inNonIsolatedGroup;}//------------------------------------------------------------------------// state write//------------------------------------------------------------------------void Splash::setMatrix(SplashCoord *matrix) { memcpy(state->matrix, matrix, 6 * sizeof(SplashCoord));}void Splash::setStrokePattern(SplashPattern *strokePattern) { state->setStrokePattern(strokePattern);}void Splash::setFillPattern(SplashPattern *fillPattern) { state->setFillPattern(fillPattern);}void Splash::setScreen(SplashScreen *screen) { state->setScreen(screen);}void Splash::setBlendFunc(SplashBlendFunc func) { state->blendFunc = func;}void Splash::setStrokeAlpha(SplashCoord alpha) { state->strokeAlpha = alpha;}void Splash::setFillAlpha(SplashCoord alpha) { state->fillAlpha = alpha;}void Splash::setLineWidth(SplashCoord lineWidth) { state->lineWidth = lineWidth;}void Splash::setLineCap(int lineCap) { state->lineCap = lineCap;}void Splash::setLineJoin(int lineJoin) { state->lineJoin = lineJoin;}void Splash::setMiterLimit(SplashCoord miterLimit) { state->miterLimit = miterLimit;}void Splash::setFlatness(SplashCoord flatness) { if (flatness < 1) { state->flatness = 1; } else { state->flatness = flatness; }}void Splash::setLineDash(SplashCoord *lineDash, int lineDashLength, SplashCoord lineDashPhase) { state->setLineDash(lineDash, lineDashLength, lineDashPhase);}void Splash::setStrokeAdjust(GBool strokeAdjust) { state->strokeAdjust = strokeAdjust;}void Splash::clipResetToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1) { state->clip->resetToRect(x0, y0, x1, y1);}SplashError Splash::clipToRect(SplashCoord x0, SplashCoord y0, SplashCoord x1, SplashCoord y1) { return state->clip->clipToRect(x0, y0, x1, y1);}SplashError Splash::clipToPath(SplashPath *path, GBool eo) { return state->clip->clipToPath(path, state->matrix, state->flatness, eo);}void Splash::setSoftMask(SplashBitmap *softMask) { state->setSoftMask(softMask);}void Splash::setInNonIsolatedGroup(SplashBitmap *alpha0BitmapA, int alpha0XA, int alpha0YA) { alpha0Bitmap = alpha0BitmapA; alpha0X = alpha0XA; alpha0Y = alpha0YA; state->inNonIsolatedGroup = gTrue;}//------------------------------------------------------------------------// state save/restore//------------------------------------------------------------------------void Splash::saveState() { SplashState *newState; newState = state->copy(); newState->next = state; state = newState;}SplashError Splash::restoreState() { SplashState *oldState; if (!state->next) { return splashErrNoSave;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -