diff --git a/PdfFile/PdfWriter.cpp b/PdfFile/PdfWriter.cpp index 6205b8f17a..0aa4ad988a 100644 --- a/PdfFile/PdfWriter.cpp +++ b/PdfFile/PdfWriter.cpp @@ -168,6 +168,8 @@ CPdfWriter::CPdfWriter(NSFonts::IApplicationFonts* pAppFonts, bool isPDFA, IRend m_pRenderer = pRenderer; m_bNeedAddHelvetica = true; m_wsTempDirectory = wsTempDirectory; + m_pShading = NULL; + m_pShadingExtGrState = NULL; m_pDocument = new PdfWriter::CDocument(); diff --git a/PdfFile/SrcWriter/RedactOutputDev.cpp b/PdfFile/SrcWriter/RedactOutputDev.cpp index 9075314211..72ed1f3163 100644 --- a/PdfFile/SrcWriter/RedactOutputDev.cpp +++ b/PdfFile/SrcWriter/RedactOutputDev.cpp @@ -527,19 +527,29 @@ void RedactOutputDev::setExtGState(const char* name) { if (m_sStates.empty()) return; - m_sStates.back().m_arrOp.push_back(std::make_pair(name, "gs")); + m_sStates.back().m_arrOp.push_back(std::make_pair("/" + std::string(name), "gs")); } void RedactOutputDev::setFillColorSpace(const char* name) { if (m_sStates.empty()) return; - m_sStates.back().m_arrOp.push_back(std::make_pair(name, "cs")); + m_sStates.back().m_arrOp.push_back(std::make_pair("/" + std::string(name), "cs")); } -void RedactOutputDev::setFillColorN(const char* name) +void RedactOutputDev::setFillColorN(Object* args, int numArgs) { if (m_sStates.empty()) return; - m_sStates.back().m_arrOp.push_back(std::make_pair(name, "scn")); + std::string sOp; + for (int i = 0; i < numArgs; ++i) + { + if (args[i].isName()) + sOp += ("/" + std::string(args[i].getName()) + " "); + else if (args[i].isInt()) + sOp += (std::to_string(args[i].getInt()) + " "); + else if (args[i].isReal()) + sOp += (std::to_string(args[i].getReal()) + " "); + } + m_sStates.back().m_arrOp.push_back(std::make_pair(sOp, "scn")); } //----- image drawing void RedactOutputDev::drawImageMask(GfxState *pGState, Object *pRef, Stream *pStream, int nWidth, int nHeight, GBool bInvert, GBool bInlineImage, GBool interpolate) @@ -632,7 +642,7 @@ void RedactOutputDev::drawForm(GfxState *pGState, Ref id, const char* name) { for (int j = 0; j < m_sStates[i].m_arrOp.size(); ++j) { - pStream->WriteEscapeName(m_sStates[i].m_arrOp[j].first.c_str()); + pStream->WriteStr(m_sStates[i].m_arrOp[j].first.c_str()); pStream->WriteChar(' '); pStream->WriteStr(m_sStates[i].m_arrOp[j].second.c_str()); pStream->WriteStr("\012"); @@ -697,6 +707,20 @@ void RedactOutputDev::drawImage(GfxState *pGState, Ref id, const char* name) Transform(m_arrMatrix, dXmin, dYmin, &dXmin, &dYmin); Transform(m_arrMatrix, dXmax, dYmax, &dXmax, &dYmax); + m_pPage->GrSave(); + UpdateTransform(); + CStream* pStream = m_pPage->GetStream(); + for (int i = 0; i < m_sStates.size(); ++i) + { + for (int j = 0; j < m_sStates[i].m_arrOp.size(); ++j) + { + pStream->WriteStr(m_sStates[i].m_arrOp[j].first.c_str()); + pStream->WriteChar(' '); + pStream->WriteStr(m_sStates[i].m_arrOp[j].second.c_str()); + pStream->WriteStr("\012"); + } + } + for (int i = 0; i < m_arrQuadPoints.size(); i += 4) { double xMin = m_arrQuadPoints[i + 0]; @@ -705,23 +729,13 @@ void RedactOutputDev::drawImage(GfxState *pGState, Ref id, const char* name) double yMax = m_arrQuadPoints[i + 3]; if (!(dXmax < xMin || dXmin > xMax || dYmax < yMin || dYmin > yMax)) + { + m_pPage->GrRestore(); return; + } } oImage.free(); - m_pPage->GrSave(); - UpdateTransform(); - CStream* pStream = m_pPage->GetStream(); - for (int i = 0; i < m_sStates.size(); ++i) - { - for (int j = 0; j < m_sStates[i].m_arrOp.size(); ++j) - { - pStream->WriteEscapeName(m_sStates[i].m_arrOp[j].first.c_str()); - pStream->WriteChar(' '); - pStream->WriteStr(m_sStates[i].m_arrOp[j].second.c_str()); - pStream->WriteStr("\012"); - } - } m_pPage->ExecuteXObject(name); m_pPage->GrRestore(); } @@ -1400,7 +1414,7 @@ void RedactOutputDev::DrawPath(const LONG& lType) { for (int j = 0; j < m_sStates[i].m_arrOp.size(); ++j) { - pStream->WriteEscapeName(m_sStates[i].m_arrOp[j].first.c_str()); + pStream->WriteStr(m_sStates[i].m_arrOp[j].first.c_str()); pStream->WriteChar(' '); pStream->WriteStr(m_sStates[i].m_arrOp[j].second.c_str()); pStream->WriteStr("\012"); diff --git a/PdfFile/SrcWriter/RedactOutputDev.h b/PdfFile/SrcWriter/RedactOutputDev.h index 2198cb4715..5d22fecc26 100644 --- a/PdfFile/SrcWriter/RedactOutputDev.h +++ b/PdfFile/SrcWriter/RedactOutputDev.h @@ -156,7 +156,7 @@ namespace PdfWriter virtual GBool useNameOp() override; virtual void setExtGState(const char* name) override; virtual void setFillColorSpace(const char* name) override; - virtual void setFillColorN(const char* name) override; + virtual void setFillColorN(Object* args, int numArgs) override; //----- image drawing virtual void drawImageMask(GfxState *pGState, Object *pRef, Stream *pStream, int nWidth, int nHeight, GBool bInvert, GBool bInlineImage, GBool interpolate) override; virtual void setSoftMaskFromImageMask(GfxState *pGState, Object *pRef, Stream *pStream, int nWidth, int nHeight, GBool bInvert, GBool bInlineImage, GBool interpolate) override; diff --git a/PdfFile/lib/xpdf/Gfx.cc b/PdfFile/lib/xpdf/Gfx.cc index d8e6ea0e68..d5b1913a4f 100644 --- a/PdfFile/lib/xpdf/Gfx.cc +++ b/PdfFile/lib/xpdf/Gfx.cc @@ -1569,7 +1569,7 @@ void Gfx::opSetFillColorN(Object args[], int numArgs) { } if (out->useNameOp()) { - out->setFillColorN(args[numArgs-1].getName()); + out->setFillColorN(args, numArgs); return; } if (state->getFillColorSpace()->getMode() == csPattern) { diff --git a/PdfFile/lib/xpdf/OutputDev.h b/PdfFile/lib/xpdf/OutputDev.h index 4a11cd0e7c..85d9ffb199 100644 --- a/PdfFile/lib/xpdf/OutputDev.h +++ b/PdfFile/lib/xpdf/OutputDev.h @@ -193,7 +193,7 @@ public: virtual GBool useNameOp() { return gFalse; } virtual void setExtGState(const char* name) {} virtual void setFillColorSpace(const char* name) {} - virtual void setFillColorN(const char* name) {} + virtual void setFillColorN(Object* args, int numArgs) {} //----- image drawing virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,