Commit 52d190d8 authored by Albert Astals Cid's avatar Albert Astals Cid

[xpdf303] tiling "merges" from Thomas, using mostly our "old" code instead of xpdf's

parent bf75a957
......@@ -751,7 +751,7 @@ void CairoOutputDev::eoFill(GfxState *state) {
}
GBool CairoOutputDev::tilingPatternFill(GfxState *state, Catalog *cat, Object *str,
GBool CairoOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx1, Catalog *cat, Object *str,
double *pmat, int paintType, int /*tilingType*/, Dict *resDict,
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
......
......@@ -159,7 +159,7 @@ public:
virtual void fill(GfxState *state);
virtual void eoFill(GfxState *state);
virtual void clipToStrokePath(GfxState *state);
virtual GBool tilingPatternFill(GfxState *state, Catalog *cat, Object *str,
virtual GBool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str,
double *pmat, int paintType, int tilingType, Dict *resDict,
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
......@@ -432,7 +432,7 @@ public:
virtual void stroke(GfxState *state) { }
virtual void fill(GfxState *state) { }
virtual void eoFill(GfxState *state) { }
virtual GBool tilingPatternFill(GfxState *state, Catalog *cat, Object *str,
virtual GBool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str,
double *pmat, int paintType, int tilingType, Dict *resDict,
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
......
......@@ -1985,7 +1985,7 @@ void Gfx::doTilingPatternFill(GfxTilingPattern *tPat,
GfxPatternColorSpace *patCS;
GfxColorSpace *cs;
GfxColor color;
GfxPath *savedPath;
GfxState *savedState;
double xMin, yMin, xMax, yMax, x, y, x1, y1;
double cxMin, cyMin, cxMax, cyMax;
int xi0, yi0, xi1, yi1, xi, yi;
......@@ -2036,12 +2036,13 @@ void Gfx::doTilingPatternFill(GfxTilingPattern *tPat,
imb[5] = (m1[1] * m1[4] - m1[0] * m1[5]) * det;
// save current graphics state
savedPath = state->getPath()->copy();
saveState();
savedState = saveStateStack();
// set underlying color space (for uncolored tiling patterns); set
// various other parameters (stroke color, line width) to match
// Adobe's behavior
state->setFillPattern(NULL);
state->setStrokePattern(NULL);
if (tPat->getPaintType() == 2 && (cs = patCS->getUnder())) {
state->setFillColorSpace(cs->copy());
out->updateFillColorSpace(state);
......@@ -2052,6 +2053,8 @@ void Gfx::doTilingPatternFill(GfxTilingPattern *tPat,
} else {
state->setStrokeColor(state->getFillColor());
}
out->updateFillColor(state);
out->updateStrokeColor(state);
} else {
cs = new GfxDeviceGrayColorSpace();
state->setFillColorSpace(cs);
......@@ -2062,10 +2065,10 @@ void Gfx::doTilingPatternFill(GfxTilingPattern *tPat,
state->setStrokeColor(&color);
out->updateStrokeColorSpace(state);
}
state->setFillPattern(NULL);
out->updateFillColor(state);
state->setStrokePattern(NULL);
out->updateStrokeColor(state);
if (!stroke) {
state->setLineWidth(0);
out->updateLineWidth(state);
}
// clip to current path
if (stroke) {
......@@ -2080,8 +2083,6 @@ void Gfx::doTilingPatternFill(GfxTilingPattern *tPat,
}
}
state->clearPath();
state->setLineWidth(0);
out->updateLineWidth(state);
// get the clip region, check for empty
state->getClipBBox(&cxMin, &cyMin, &cxMax, &cyMax);
......@@ -2145,7 +2146,7 @@ void Gfx::doTilingPatternFill(GfxTilingPattern *tPat,
m1[4] = m[4];
m1[5] = m[5];
if (out->useTilingPatternFill() &&
out->tilingPatternFill(state, catalog, tPat->getContentStream(),
out->tilingPatternFill(state, this, catalog, tPat->getContentStream(),
tPat->getMatrix(), tPat->getPaintType(), tPat->getTilingType(),
tPat->getResDict(), m1, tPat->getBBox(),
xi0, yi0, xi1, yi1, xstep, ystep)) {
......@@ -2166,8 +2167,7 @@ void Gfx::doTilingPatternFill(GfxTilingPattern *tPat,
// restore graphics state
restore:
restoreState();
state->setPath(savedPath);
restoreStateStack(savedState);
}
void Gfx::doShadingPatternFill(GfxShadingPattern *sPat,
......@@ -5100,6 +5100,27 @@ void Gfx::restoreState() {
stackHeight--;
}
// Create a new state stack, and initialize it with a copy of the
// current state.
GfxState *Gfx::saveStateStack() {
GfxState *oldState;
out->saveState(state);
oldState = state;
state = state->copy(gTrue);
return oldState;
}
// Switch back to the previous state stack.
void Gfx::restoreStateStack(GfxState *oldState) {
while (state->hasSaves()) {
restoreState();
}
delete state;
state = oldState;
out->restoreState(state);
}
void Gfx::pushResources(Dict *resDict) {
res = new GfxResources(xref, resDict, res);
}
......
......@@ -181,6 +181,13 @@ public:
// Get the current graphics state object.
GfxState *getState() { return state; }
void doForm1(Object *str, Dict *resDict, double *matrix, double *bbox,
GBool transpGroup = gFalse, GBool softMask = gFalse,
GfxColorSpace *blendingColorSpace = NULL,
GBool isolated = gFalse, GBool knockout = gFalse,
GBool alpha = gFalse, Function *transferFunc = NULL,
GfxColor *backdropColor = NULL);
void pushResources(Dict *resDict);
void popResources();
......@@ -347,12 +354,6 @@ private:
void opXObject(Object args[], int numArgs);
void doImage(Object *ref, Stream *str, GBool inlineImg);
void doForm(Object *str);
void doForm1(Object *str, Dict *resDict, double *matrix, double *bbox,
GBool transpGroup = gFalse, GBool softMask = gFalse,
GfxColorSpace *blendingColorSpace = NULL,
GBool isolated = gFalse, GBool knockout = gFalse,
GBool alpha = gFalse, Function *transferFunc = NULL,
GfxColor *backdropColor = NULL);
// in-line image operators
void opBeginImage(Object args[], int numArgs);
......@@ -372,6 +373,8 @@ private:
void opBeginMarkedContent(Object args[], int numArgs);
void opEndMarkedContent(Object args[], int numArgs);
void opMarkPoint(Object args[], int numArgs);
GfxState *saveStateStack();
void restoreStateStack(GfxState *oldState);
GBool contentIsHidden();
void pushMarkedContent();
void popMarkedContent();
......
......@@ -5580,7 +5580,7 @@ GfxState::~GfxState() {
}
// Used for copy();
GfxState::GfxState(GfxState *state) {
GfxState::GfxState(GfxState *state, GBool copyPath) {
int i;
memcpy(this, state, sizeof(GfxState));
......@@ -5608,6 +5608,9 @@ GfxState::GfxState(GfxState *state) {
if (font)
font->incRefCnt();
if (copyPath) {
path = state->path->copy();
}
saved = NULL;
}
......
......@@ -1312,8 +1312,9 @@ public:
// Destructor.
~GfxState();
// Copy.
GfxState *copy() { return new GfxState(this); }
// Copy.
GfxState *copy(GBool copyPath = gFalse)
{ return new GfxState(this, copyPath); }
// Accessors.
double getHDPI() { return hDPI; }
......@@ -1539,7 +1540,7 @@ private:
GfxState *saved; // next GfxState on stack
GfxState(GfxState *state);
GfxState(GfxState *state, GBool copyPath);
};
#endif
......@@ -43,6 +43,7 @@ class Dict;
class GooHash;
class GooString;
class GfxState;
class Gfx;
struct GfxColor;
class GfxColorSpace;
class GfxImageColorMap;
......@@ -196,7 +197,7 @@ public:
virtual void stroke(GfxState * /*state*/) {}
virtual void fill(GfxState * /*state*/) {}
virtual void eoFill(GfxState * /*state*/) {}
virtual GBool tilingPatternFill(GfxState * /*state*/, Catalog * /*cat*/, Object * /*str*/,
virtual GBool tilingPatternFill(GfxState * /*state*/, Gfx * /*gfx*/, Catalog * /*cat*/, Object * /*str*/,
double * /*pmat*/, int /*paintType*/, int /*tilingType*/, Dict * /*resDict*/,
double * /*mat*/, double * /*bbox*/,
int /*x0*/, int /*y0*/, int /*x1*/, int /*y1*/,
......
......@@ -4124,7 +4124,7 @@ GBool PSOutputDev::tilingPatternFillL2(GfxState *state, Catalog *cat, Object *st
return gTrue;
}
GBool PSOutputDev::tilingPatternFill(GfxState *state, Catalog *cat, Object *str,
GBool PSOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str,
double *pmat, int paintType, int tilingType, Dict *resDict,
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
......
......@@ -209,7 +209,7 @@ public:
virtual void stroke(GfxState *state);
virtual void fill(GfxState *state);
virtual void eoFill(GfxState *state);
virtual GBool tilingPatternFill(GfxState *state, Catalog *cat, Object *str,
virtual GBool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str,
double *pmat, int paintType, int tilingType, Dict *resDict,
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
......
......@@ -81,18 +81,17 @@ void PreScanOutputDev::eoFill(GfxState *state) {
state->getFillOpacity(), state->getBlendMode());
}
GBool PreScanOutputDev::tilingPatternFill(GfxState *state, Catalog *catalog, Object *str,
GBool PreScanOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *catalog, Object *str,
double *pmat, int paintType, int /*tilingType*/, Dict *resDict,
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
double xStep, double yStep) {
PDFRectangle box;
Gfx *gfx;
box.x1 = bbox[0]; box.y1 = bbox[1];
box.x2 = bbox[2]; box.y2 = bbox[3];
gfx = new Gfx(doc, this, resDict, &box, NULL);
gfx->display(str);
delete gfx;
if (paintType == 1) {
gfx->doForm1(str, resDict, mat, bbox);
} else {
check(state->getFillColorSpace(), state->getFillColor(),
state->getFillOpacity(), state->getBlendMode());
}
return gTrue;
}
......
......@@ -80,7 +80,7 @@ public:
virtual void stroke(GfxState *state);
virtual void fill(GfxState *state);
virtual void eoFill(GfxState *state);
virtual GBool tilingPatternFill(GfxState *state, Catalog *cat, Object *str,
virtual GBool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str,
double *pmat, int paintType, int tilingType, Dict *resDict,
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
......
......@@ -1359,6 +1359,7 @@ SplashOutputDev::SplashOutputDev(SplashColorMode colorModeA,
textClipPath = NULL;
haveCSPattern = gFalse;
transpGroupStack = NULL;
nestCount = 0;
}
void SplashOutputDev::setupScreenParams(double hDPI, double vDPI) {
......@@ -2384,6 +2385,7 @@ void SplashOutputDev::endType3Char(GfxState *state) {
double *ctm;
if (t3GlyphStack->cacheTag) {
--nestCount;
memcpy(t3GlyphStack->cacheData, bitmap->getDataPtr(),
t3GlyphStack->cache->glyphSize);
delete bitmap;
......@@ -2525,6 +2527,7 @@ void SplashOutputDev::type3D1(GfxState *state, double wx, double wy,
state->setCTM(ctm[0], ctm[1], ctm[2], ctm[3],
-t3Font->glyphX, -t3Font->glyphY);
updateCTM(state, 0, 0, 0, 0, 0, 0);
++nestCount;
}
void SplashOutputDev::drawType3Glyph(GfxState *state, T3FontCache *t3Font,
......@@ -3681,10 +3684,12 @@ void SplashOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
transpGroup->tBitmap = bitmap;
state->shiftCTM(-tx, -ty);
updateCTM(state, 0, 0, 0, 0, 0, 0);
++nestCount;
}
void SplashOutputDev::endTransparencyGroup(GfxState *state) {
// restore state
--nestCount;
delete splash;
bitmap = transpGroupStack->origBitmap;
splash = transpGroupStack->origSplash;
......@@ -3896,7 +3901,7 @@ void SplashOutputDev::setFreeTypeHinting(GBool enable, GBool enableSlightHinting
enableSlightHinting = enableSlightHintingA;
}
GBool SplashOutputDev::tilingPatternFill(GfxState *state, Catalog *catalog, Object *str,
GBool SplashOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx1, Catalog *catalog, Object *str,
double *ptm, int paintType, int /*tilingType*/, Dict *resDict,
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
......@@ -4056,7 +4061,6 @@ GBool SplashOutputDev::tilingPatternFill(GfxState *state, Catalog *catalog, Obje
matc[1] = ctm[1];
matc[2] = ctm[2];
matc[3] = ctm[3];
splash->setOverprintMask(0xffffffff);
splash->drawImage(&tilingBitmapSrc, &imgData, colorMode, gTrue, result_width, result_height, matc);
delete tBitmap;
delete gfx;
......
......@@ -273,7 +273,7 @@ public:
virtual void stroke(GfxState *state);
virtual void fill(GfxState *state);
virtual void eoFill(GfxState *state);
virtual GBool tilingPatternFill(GfxState *state, Catalog *catalog, Object *str,
virtual GBool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *catalog, Object *str,
double *pmat, int paintType, int tilingType, Dict *resDict,
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
......@@ -441,6 +441,7 @@ private:
SplashTransparencyGroup * // transparency group stack
transpGroupStack;
SplashBitmap *maskBitmap; // for image masks in pattern colorspace
int nestCount;
};
#endif
......@@ -2636,7 +2636,7 @@ SplashError Splash::fillImageMask(SplashImageMaskSource src, void *srcData,
blitMask(scaledMask, x0, y0, clipRes);
delete scaledMask;
}
// scaling plus vertical flip
} else if (mat[0] > 0 && minorAxisZero && mat[3] < 0) {
x0 = imgCoordMungeLowerC(mat[4], glyphMode);
......@@ -3412,7 +3412,7 @@ SplashError Splash::drawImage(SplashImageSource src, void *srcData,
blitImage(scaledImg, srcAlpha, x0, y0, clipRes);
delete scaledImg;
}
// scaling plus vertical flip
} else if (mat[0] > 0 && minorAxisZero && mat[3] < 0) {
x0 = imgCoordMungeLower(mat[4]);
......@@ -3467,7 +3467,7 @@ SplashError Splash::arbitraryTransformImage(SplashImageSource src, void *srcData
SplashClipResult clipRes, clipRes2;
SplashPipe pipe;
SplashColor pixel;
int scaledWidth, scaledHeight, t0, t1;
int scaledWidth, scaledHeight, t0, t1, th;
SplashCoord r00, r01, r10, r11, det, ir00, ir01, ir10, ir11;
SplashCoord vx[4], vy[4];
int xMin, yMin, xMax, yMax;
......@@ -3524,13 +3524,29 @@ SplashError Splash::arbitraryTransformImage(SplashImageSource src, void *srcData
scaledWidth = t0 > t1 ? t0 : t1;
if (mat[2] >= 0) {
t0 = imgCoordMungeUpper(mat[2] + mat[4]) - imgCoordMungeLower(mat[4]);
if (splashAbs(mat[1]) >= 1) {
th = imgCoordMungeUpper(mat[2]) - imgCoordMungeLower(mat[0] * mat[3] / mat[1]);
if (th > t0) t0 = th;
}
} else {
t0 = imgCoordMungeUpper(mat[4]) - imgCoordMungeLower(mat[2] + mat[4]);
if (splashAbs(mat[1]) >= 1) {
th = imgCoordMungeUpper(mat[0] * mat[3] / mat[1]) - imgCoordMungeLower(mat[2]);
if (th > t0) t0 = th;
}
}
if (mat[3] >= 0) {
t1 = imgCoordMungeUpper(mat[3] + mat[5]) - imgCoordMungeLower(mat[5]);
if (splashAbs(mat[0]) >= 1) {
th = imgCoordMungeUpper(mat[3]) - imgCoordMungeLower(mat[1] * mat[2] / mat[0]);
if (th > t1) t1 = th;
}
} else {
t1 = imgCoordMungeUpper(mat[5]) - imgCoordMungeLower(mat[3] + mat[5]);
if (splashAbs(mat[0]) >= 1) {
th = imgCoordMungeUpper(mat[1] * mat[2] / mat[0]) - imgCoordMungeLower(mat[3]);
if (th > t1) t1 = th;
}
}
scaledHeight = t0 > t1 ? t0 : t1;
if (scaledWidth == 0) {
......@@ -3901,7 +3917,7 @@ void Splash::scaleImageYdXd(SplashImageSource src, void *srcData,
*destPtr++ = (Guchar)pix2;
*destPtr++ = (Guchar)pix1;
*destPtr++ = (Guchar)pix0;
*destPtr++ = (Guchar)255;
*destPtr++ = (Guchar)255;
break;
case splashModeBGR8:
......@@ -4081,7 +4097,7 @@ void Splash::scaleImageYdXu(SplashImageSource src, void *srcData,
*destPtr++ = (Guchar)pix[2];
*destPtr++ = (Guchar)pix[1];
*destPtr++ = (Guchar)pix[0];
*destPtr++ = (Guchar)255;
*destPtr++ = (Guchar)255;
}
break;
case splashModeBGR8:
......@@ -4222,7 +4238,7 @@ void Splash::scaleImageYuXd(SplashImageSource src, void *srcData,
*destPtr++ = (Guchar)pix[2];
*destPtr++ = (Guchar)pix[1];
*destPtr++ = (Guchar)pix[0];
*destPtr++ = (Guchar)255;
*destPtr++ = (Guchar)255;
}
break;
case splashModeBGR8:
......@@ -4365,7 +4381,7 @@ void Splash::scaleImageYuXu(SplashImageSource src, void *srcData,
*destPtr++ = (Guchar)pix[2];
*destPtr++ = (Guchar)pix[1];
*destPtr++ = (Guchar)pix[0];
*destPtr++ = (Guchar)255;
*destPtr++ = (Guchar)255;
}
}
break;
......@@ -5243,7 +5259,7 @@ SplashError Splash::blitTransparent(SplashBitmap *src, int xSrc, int ySrc,
SplashPath *Splash::makeStrokePath(SplashPath *path, SplashCoord w,
GBool flatten) {
SplashPath *pathIn, *dashPath, *pathOut;
SplashPath *pathIn, *dashPath, *pathOut;
SplashCoord d, dx, dy, wdx, wdy, dxNext, dyNext, wdxNext, wdyNext;
SplashCoord crossprod, dotprod, miter, m;
GBool first, last, closed;
......
......@@ -70,7 +70,7 @@ void ImageOutputDev::setFilename(const char *fileExt) {
}
}
GBool ImageOutputDev::tilingPatternFill(GfxState *state, Catalog *cat, Object *str,
GBool ImageOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str,
double *pmat, int paintType, int tilingType, Dict *resDict,
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
......
......@@ -84,7 +84,7 @@ public:
virtual GBool useDrawChar() { return gFalse; }
//----- path painting
virtual GBool tilingPatternFill(GfxState *state, Catalog *cat, Object *str,
virtual GBool tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, Object *str,
double *pmat, int paintType, int tilingType, Dict *resDict,
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment