From e362cec58fb273941e3aea562ba042e2e9b95c98 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sun, 24 May 2015 13:11:43 +0200 Subject: Respect PDF image 'interpolate' value on import. (bzr r14171) --- src/extension/internal/pdfinput/pdf-parser.cpp | 47 ++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'src/extension/internal/pdfinput/pdf-parser.cpp') diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp index cc0b38515..836c34c32 100644 --- a/src/extension/internal/pdfinput/pdf-parser.cpp +++ b/src/extension/internal/pdfinput/pdf-parser.cpp @@ -2780,12 +2780,14 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) Dict *dict; int width, height; int bits; + GBool interpolate; StreamColorSpaceMode csMode; GBool mask; GBool invert; Object maskObj, smaskObj; GBool haveColorKeyMask, haveExplicitMask, haveSoftMask; GBool maskInvert; + GBool maskInterpolate; Object obj1, obj2; // get info from the stream @@ -2828,6 +2830,19 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) } obj1.free(); + // image interpolation + dict->lookup("Interpolate", &obj1); + if (obj1.isNull()) { + obj1.free(); + dict->lookup("I", &obj1); + } + if (obj1.isBool()) + interpolate = obj1.getBool(); + else + interpolate = gFalse; + obj1.free(); + maskInterpolate = gFalse; + // image or mask? dict->lookup(const_cast("ImageMask"), &obj1); if (obj1.isNull()) { @@ -2884,7 +2899,7 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) obj1.free(); // draw it - builder->addImageMask(state, str, width, height, invert); + builder->addImageMask(state, str, width, height, invert, interpolate); } else { // get color space and color map @@ -2986,6 +3001,16 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) } int maskBits = obj1.getInt(); obj1.free(); + maskDict->lookup("Interpolate", &obj1); + if (obj1.isNull()) { + obj1.free(); + maskDict->lookup("I", &obj1); + } + if (obj1.isBool()) + maskInterpolate = obj1.getBool(); + else + maskInterpolate = gFalse; + obj1.free(); maskDict->lookup(const_cast("ColorSpace"), &obj1); if (obj1.isNull()) { obj1.free(); @@ -3071,6 +3096,16 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) goto err2; } obj1.free(); + maskDict->lookup("Interpolate", &obj1); + if (obj1.isNull()) { + obj1.free(); + maskDict->lookup("I", &obj1); + } + if (obj1.isBool()) + maskInterpolate = obj1.getBool(); + else + maskInterpolate = gFalse; + obj1.free(); maskInvert = gFalse; maskDict->lookup(const_cast("Decode"), &obj1); if (obj1.isNull()) { @@ -3092,14 +3127,14 @@ void PdfParser::doImage(Object * /*ref*/, Stream *str, GBool inlineImg) // draw it if (haveSoftMask) { - builder->addSoftMaskedImage(state, str, width, height, colorMap, - maskStr, maskWidth, maskHeight, maskColorMap); + builder->addSoftMaskedImage(state, str, width, height, colorMap, interpolate, + maskStr, maskWidth, maskHeight, maskColorMap, maskInterpolate); delete maskColorMap; } else if (haveExplicitMask) { - builder->addMaskedImage(state, str, width, height, colorMap, - maskStr, maskWidth, maskHeight, maskInvert); + builder->addMaskedImage(state, str, width, height, colorMap, interpolate, + maskStr, maskWidth, maskHeight, maskInvert, maskInterpolate); } else { - builder->addImage(state, str, width, height, colorMap, + builder->addImage(state, str, width, height, colorMap, interpolate, haveColorKeyMask ? maskColors : static_cast(NULL)); } delete colorMap; -- cgit v1.2.3 From ebcbea982c7b7dce6a5d3641e3a5d3a556b4d69f Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 27 May 2015 22:02:55 +0200 Subject: Add 'font-variant-xxx' to properties that should not be set on non-text elements. (bzr r14179) --- src/extension/internal/pdfinput/pdf-parser.cpp | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/extension/internal/pdfinput/pdf-parser.cpp') diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp index 836c34c32..a70b42d41 100644 --- a/src/extension/internal/pdfinput/pdf-parser.cpp +++ b/src/extension/internal/pdfinput/pdf-parser.cpp @@ -409,6 +409,7 @@ PdfParser::~PdfParser() { } } +// Equivalent to Gfx::display() void PdfParser::parse(Object *obj, GBool topLevel) { Object obj2; @@ -1578,11 +1579,13 @@ void PdfParser::opCloseStroke(Object * /*args[]*/, int /*numArgs*/) { void PdfParser::opFill(Object /*args*/[], int /*numArgs*/) { + std::cout << "PdfParser::opFill" << std::endl; if (!state->isCurPt()) { //error(getPos(), const_cast("No path in fill")); return; } if (state->isPath()) { + std::cout << " isPath" << std::endl; if (state->getFillColorSpace()->getMode() == csPattern && !builder->isPatternTypeSupported(state->getFillPattern())) { doPatternFillFallback(gFalse); @@ -1595,6 +1598,7 @@ void PdfParser::opFill(Object /*args*/[], int /*numArgs*/) void PdfParser::opEOFill(Object /*args*/[], int /*numArgs*/) { + std::cout << "PdfParser::opEOFill" << std::endl; if (!state->isCurPt()) { //error(getPos(), const_cast("No path in eofill")); return; @@ -1663,6 +1667,7 @@ void PdfParser::opCloseEOFillStroke(Object /*args*/[], int /*numArgs*/) } void PdfParser::doFillAndStroke(GBool eoFill) { + std::cout << "PdfParser::doFillandStroke()" << std::endl; GBool fillOk = gTrue, strokeOk = gTrue; if (state->getFillColorSpace()->getMode() == csPattern && !builder->isPatternTypeSupported(state->getFillPattern())) { @@ -1673,14 +1678,17 @@ void PdfParser::doFillAndStroke(GBool eoFill) { strokeOk = gFalse; } if (fillOk && strokeOk) { + std::cout << " ... fillOk and StrokeOk" << std::endl; builder->addPath(state, true, true, eoFill); } else { + std::cout << " ... fillOk or StrokeOk not OK" << std::endl; doPatternFillFallback(eoFill); doPatternStrokeFallback(); } } void PdfParser::doPatternFillFallback(GBool eoFill) { + std::cout << "PdfParser::doPatternFillFallback: " << eoFill << std::endl; GfxPattern *pattern; if (!(pattern = state->getFillPattern())) { @@ -1704,6 +1712,7 @@ void PdfParser::doPatternFillFallback(GBool eoFill) { } void PdfParser::doPatternStrokeFallback() { + std::cout << "PdfParser::doPatternStrokeFallback" << std::endl; GfxPattern *pattern; if (!(pattern = state->getStrokePattern())) { @@ -1737,6 +1746,8 @@ void PdfParser::doShadingPatternFillFallback(GfxShadingPattern *sPat, shading = sPat->getShading(); + std::cout << "PdfParser::doShadingPatternFillFallback: " << shading->getType() << std::endl; + // save current graphics state savedPath = state->getPath()->copy(); saveState(); @@ -1823,6 +1834,12 @@ void PdfParser::doShadingPatternFillFallback(GfxShadingPattern *sPat, break; case 6: case 7: + std::cout << " Type 6/7: calling doPatchMeshShFill()" + << " Clip path? " << (clipHistory->getClipPath()?"true":"false") << std::endl; + if (clipHistory->getClipPath()) { + builder->addShadedFill(shading, NULL, clipHistory->getClipPath(), + clipHistory->getClipType() == clipEO ? true : false); + } doPatchMeshShFill(static_cast(shading)); break; } @@ -1856,6 +1873,7 @@ void PdfParser::opShFill(Object args[], int /*numArgs*/) return; } #endif + std::cout << "PdfParser::opShFill: type: " << shading->getType() << std::endl; // save current graphics state if (shading->getType() != 2 && shading->getType() != 3) { @@ -1943,6 +1961,12 @@ void PdfParser::opShFill(Object args[], int /*numArgs*/) break; case 6: case 7: + std::cout << " Type 6/7: calling doPatchMeshShFill()" + << " Clip path? " << (clipHistory->getClipPath()?"true":"false") << std::endl; + if (clipHistory->getClipPath()) { + builder->addShadedFill(shading, matrix, clipHistory->getClipPath(), + clipHistory->getClipType() == clipEO ? true : false); + } doPatchMeshShFill(static_cast(shading)); break; } @@ -2141,6 +2165,10 @@ void PdfParser::gouraudFillTriangle(double x0, double y0, GfxColor *color0, void PdfParser::doPatchMeshShFill(GfxPatchMeshShading *shading) { int start, i; + // if( true ) { + // builder->patchMeshShadedFill( state, shading ); + // } + std::cout << "PdfParser::doPatchMeshShFill: Number of patches: " << shading->getNPatches() << std::endl; if (shading->getNPatches() > 128) { start = 3; } else if (shading->getNPatches() > 64) { @@ -2690,6 +2718,7 @@ void PdfParser::doShowText(GooString *s) { state->textTransformDelta(0, state->getRise(), &riseX, &riseY); p = s->getCString(); len = s->getLength(); + // std::cout << "PDFParser::doShowText: p: " << (p?p:"null") << " " << len << std::endl; while (len > 0) { n = font->getNextChar(p, len, &code, &u, &uLen, /* TODO: This looks like a memory leak for u. */ @@ -2713,6 +2742,12 @@ void PdfParser::doShowText(GooString *s) { originX *= state->getFontSize(); originY *= state->getFontSize(); state->textTransformDelta(originX, originY, &tOriginX, &tOriginY); + // std::cout << " dx: " << dx << " dy: " << dy + // << " originX: " << originX << " originY: " << originY + // << " tOriginX: " << tOriginX << " tOriginY: " << tOriginY + // << " riseX: " << riseX << " riseY: " << riseY + // << " curX: " << state->getCurX() + riseX + // << " curY: " << state->getCurY() + riseY << std::endl; builder->addChar(state, state->getCurX() + riseX, state->getCurY() + riseY, dx, dy, tOriginX, tOriginY, code, n, u, uLen); state->shift(tdx, tdy); -- cgit v1.2.3 From 158e9e378bd4875a27b57883d3f75415fb119e01 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Wed, 27 May 2015 22:31:43 +0200 Subject: Revert unintended changes. (bzr r14181) --- src/extension/internal/pdfinput/pdf-parser.cpp | 35 -------------------------- 1 file changed, 35 deletions(-) (limited to 'src/extension/internal/pdfinput/pdf-parser.cpp') diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp index a70b42d41..836c34c32 100644 --- a/src/extension/internal/pdfinput/pdf-parser.cpp +++ b/src/extension/internal/pdfinput/pdf-parser.cpp @@ -409,7 +409,6 @@ PdfParser::~PdfParser() { } } -// Equivalent to Gfx::display() void PdfParser::parse(Object *obj, GBool topLevel) { Object obj2; @@ -1579,13 +1578,11 @@ void PdfParser::opCloseStroke(Object * /*args[]*/, int /*numArgs*/) { void PdfParser::opFill(Object /*args*/[], int /*numArgs*/) { - std::cout << "PdfParser::opFill" << std::endl; if (!state->isCurPt()) { //error(getPos(), const_cast("No path in fill")); return; } if (state->isPath()) { - std::cout << " isPath" << std::endl; if (state->getFillColorSpace()->getMode() == csPattern && !builder->isPatternTypeSupported(state->getFillPattern())) { doPatternFillFallback(gFalse); @@ -1598,7 +1595,6 @@ void PdfParser::opFill(Object /*args*/[], int /*numArgs*/) void PdfParser::opEOFill(Object /*args*/[], int /*numArgs*/) { - std::cout << "PdfParser::opEOFill" << std::endl; if (!state->isCurPt()) { //error(getPos(), const_cast("No path in eofill")); return; @@ -1667,7 +1663,6 @@ void PdfParser::opCloseEOFillStroke(Object /*args*/[], int /*numArgs*/) } void PdfParser::doFillAndStroke(GBool eoFill) { - std::cout << "PdfParser::doFillandStroke()" << std::endl; GBool fillOk = gTrue, strokeOk = gTrue; if (state->getFillColorSpace()->getMode() == csPattern && !builder->isPatternTypeSupported(state->getFillPattern())) { @@ -1678,17 +1673,14 @@ void PdfParser::doFillAndStroke(GBool eoFill) { strokeOk = gFalse; } if (fillOk && strokeOk) { - std::cout << " ... fillOk and StrokeOk" << std::endl; builder->addPath(state, true, true, eoFill); } else { - std::cout << " ... fillOk or StrokeOk not OK" << std::endl; doPatternFillFallback(eoFill); doPatternStrokeFallback(); } } void PdfParser::doPatternFillFallback(GBool eoFill) { - std::cout << "PdfParser::doPatternFillFallback: " << eoFill << std::endl; GfxPattern *pattern; if (!(pattern = state->getFillPattern())) { @@ -1712,7 +1704,6 @@ void PdfParser::doPatternFillFallback(GBool eoFill) { } void PdfParser::doPatternStrokeFallback() { - std::cout << "PdfParser::doPatternStrokeFallback" << std::endl; GfxPattern *pattern; if (!(pattern = state->getStrokePattern())) { @@ -1746,8 +1737,6 @@ void PdfParser::doShadingPatternFillFallback(GfxShadingPattern *sPat, shading = sPat->getShading(); - std::cout << "PdfParser::doShadingPatternFillFallback: " << shading->getType() << std::endl; - // save current graphics state savedPath = state->getPath()->copy(); saveState(); @@ -1834,12 +1823,6 @@ void PdfParser::doShadingPatternFillFallback(GfxShadingPattern *sPat, break; case 6: case 7: - std::cout << " Type 6/7: calling doPatchMeshShFill()" - << " Clip path? " << (clipHistory->getClipPath()?"true":"false") << std::endl; - if (clipHistory->getClipPath()) { - builder->addShadedFill(shading, NULL, clipHistory->getClipPath(), - clipHistory->getClipType() == clipEO ? true : false); - } doPatchMeshShFill(static_cast(shading)); break; } @@ -1873,7 +1856,6 @@ void PdfParser::opShFill(Object args[], int /*numArgs*/) return; } #endif - std::cout << "PdfParser::opShFill: type: " << shading->getType() << std::endl; // save current graphics state if (shading->getType() != 2 && shading->getType() != 3) { @@ -1961,12 +1943,6 @@ void PdfParser::opShFill(Object args[], int /*numArgs*/) break; case 6: case 7: - std::cout << " Type 6/7: calling doPatchMeshShFill()" - << " Clip path? " << (clipHistory->getClipPath()?"true":"false") << std::endl; - if (clipHistory->getClipPath()) { - builder->addShadedFill(shading, matrix, clipHistory->getClipPath(), - clipHistory->getClipType() == clipEO ? true : false); - } doPatchMeshShFill(static_cast(shading)); break; } @@ -2165,10 +2141,6 @@ void PdfParser::gouraudFillTriangle(double x0, double y0, GfxColor *color0, void PdfParser::doPatchMeshShFill(GfxPatchMeshShading *shading) { int start, i; - // if( true ) { - // builder->patchMeshShadedFill( state, shading ); - // } - std::cout << "PdfParser::doPatchMeshShFill: Number of patches: " << shading->getNPatches() << std::endl; if (shading->getNPatches() > 128) { start = 3; } else if (shading->getNPatches() > 64) { @@ -2718,7 +2690,6 @@ void PdfParser::doShowText(GooString *s) { state->textTransformDelta(0, state->getRise(), &riseX, &riseY); p = s->getCString(); len = s->getLength(); - // std::cout << "PDFParser::doShowText: p: " << (p?p:"null") << " " << len << std::endl; while (len > 0) { n = font->getNextChar(p, len, &code, &u, &uLen, /* TODO: This looks like a memory leak for u. */ @@ -2742,12 +2713,6 @@ void PdfParser::doShowText(GooString *s) { originX *= state->getFontSize(); originY *= state->getFontSize(); state->textTransformDelta(originX, originY, &tOriginX, &tOriginY); - // std::cout << " dx: " << dx << " dy: " << dy - // << " originX: " << originX << " originY: " << originY - // << " tOriginX: " << tOriginX << " tOriginY: " << tOriginY - // << " riseX: " << riseX << " riseY: " << riseY - // << " curX: " << state->getCurX() + riseX - // << " curY: " << state->getCurY() + riseY << std::endl; builder->addChar(state, state->getCurX() + riseX, state->getCurY() + riseY, dx, dy, tOriginX, tOriginY, code, n, u, uLen); state->shift(tdx, tdy); -- cgit v1.2.3