Merge remote-tracking branch 'origin/fix/pdf-redact' into develop

This commit is contained in:
Svetlana Kulikova
2025-11-24 15:16:17 +03:00
19 changed files with 925 additions and 166 deletions

View File

@ -996,6 +996,7 @@ void CPdfEditor::SetMode(Mode nMode)
m_mObjManager.SetDoc(pDoc);
int nPages = m_pReader->GetNumPages();
pPageTree->CreateFakePages(nPages);
m_pWriter->SetNeedAddHelvetica(false);
}
}
bool CPdfEditor::IncrementalUpdates()
@ -3675,7 +3676,7 @@ void CPdfEditor::Redact(IAdvancedCommand* _pCommand)
if (bEditPage)
{
PdfWriter::RedactOutputDev oRedactOut(m_pWriter);
PdfWriter::RedactOutputDev oRedactOut(m_pWriter, &m_mObjManager);
oRedactOut.NewPDF(pPDFDocument->getXRef());
oRedactOut.SetRedact(arrAllQuads);

View File

@ -1696,6 +1696,7 @@ namespace PdfReader
m_pRendererOut->NewPDF(gfx->getDoc()->getXRef());
Gfx* m_gfx = new Gfx(gfx->getDoc(), m_pRendererOut, -1, pResourcesDict, dDpiX, dDpiY, &box, NULL, 0);
m_gfx->takeContentStreamStack(gfx);
m_gfx->display(pStream);
pFrame->ClearNoAttack();
@ -2707,7 +2708,7 @@ namespace PdfReader
RELEASEOBJECT(pCommand);
}
}
void RendererOutputDev::drawImageMask(GfxState* pGState, Object* pRef, Stream* pStream, int nWidth, int nHeight, GBool bInvert, GBool bInlineImage, GBool interpolate)
void RendererOutputDev::drawImageMask(GfxState* pGState, Gfx *gfx, Object* pRef, Stream* pStream, int nWidth, int nHeight, GBool bInvert, GBool bInlineImage, GBool interpolate)
{
if (m_bDrawOnlyText || pGState->getFillColorSpace()->isNonMarking())
return;
@ -2783,7 +2784,7 @@ namespace PdfReader
DoTransform(arrMatrix, &dShiftX, &dShiftY, true);
m_pRenderer->DrawImage(&oImage, dShiftX, dShiftY, PDFCoordsToMM(1), PDFCoordsToMM(1));
}
void RendererOutputDev::setSoftMaskFromImageMask(GfxState* pGState, Object* pRef, Stream* pStream, int nWidth, int nHeight, GBool bInvert, GBool bInlineImage, GBool interpolate)
void RendererOutputDev::setSoftMaskFromImageMask(GfxState* pGState, Gfx *gfx, Object* pRef, Stream* pStream, int nWidth, int nHeight, GBool bInvert, GBool bInlineImage, GBool interpolate)
{
if (m_bDrawOnlyText || pGState->getFillColorSpace()->isNonMarking())
return;
@ -3004,7 +3005,7 @@ namespace PdfReader
RELEASEARRAYOBJECTS(pBuffer);
return false;
}
void RendererOutputDev::drawImage(GfxState* pGState, Object* pRef, Stream* pStream, int nWidth, int nHeight, GfxImageColorMap* pColorMap, int* pMaskColors, GBool bInlineImg, GBool interpolate)
void RendererOutputDev::drawImage(GfxState* pGState, Gfx *gfx, Object* pRef, Stream* pStream, int nWidth, int nHeight, GfxImageColorMap* pColorMap, int* pMaskColors, GBool bInlineImg, GBool interpolate)
{
if (m_bDrawOnlyText)
return;
@ -3041,13 +3042,13 @@ namespace PdfReader
DoTransform(arrMatrix, &dShiftX, &dShiftY, true);
m_pRenderer->DrawImage(&oImage, dShiftX, dShiftY, PDFCoordsToMM(1), PDFCoordsToMM(1));
}
void RendererOutputDev::drawMaskedImage(GfxState* pGState, Object* pRef, Stream* pStream, int nWidth, int nHeight, GfxImageColorMap* pColorMap, Object* pStreamRef, Stream* pMaskStream, int nMaskWidth, int nMaskHeight, GBool bMaskInvert, GBool interpolate)
void RendererOutputDev::drawMaskedImage(GfxState* pGState, Gfx *gfx, Object* pRef, Stream* pStream, int nWidth, int nHeight, GfxImageColorMap* pColorMap, Object* pStreamRef, Stream* pMaskStream, int nMaskWidth, int nMaskHeight, GBool bMaskInvert, GBool interpolate)
{
if (m_bDrawOnlyText)
return;
if (nMaskWidth <= 0 || nMaskHeight <= 0)
drawImage(pGState, pRef, pStream, nWidth, nHeight, pColorMap, NULL, false, interpolate);
drawImage(pGState, gfx, pRef, pStream, nWidth, nHeight, pColorMap, NULL, false, interpolate);
if (nMaskWidth > nWidth || nMaskHeight > nHeight)
{
@ -3064,7 +3065,7 @@ namespace PdfReader
maskDecode.arrayAdd(&decodeHigh);
maskColorMap = new GfxImageColorMap(1, &maskDecode, new GfxDeviceGrayColorSpace());
maskDecode.free();
drawSoftMaskedImage(pGState, pRef, pStream, nWidth, nHeight,
drawSoftMaskedImage(pGState, gfx, pRef, pStream, nWidth, nHeight,
pColorMap, pStreamRef, pMaskStream, nMaskWidth, nMaskHeight, maskColorMap, NULL, interpolate);
delete maskColorMap;
return;
@ -3186,7 +3187,7 @@ namespace PdfReader
DoTransform(arrMatrix, &dShiftX, &dShiftY, true);
m_pRenderer->DrawImage(&oImage, dShiftX, dShiftY, PDFCoordsToMM(1), PDFCoordsToMM(1));
}
void RendererOutputDev::drawSoftMaskedImage(GfxState* pGState, Object* pRef, Stream* pStream, int nWidth, int nHeight, GfxImageColorMap* pColorMap, Object* maskRef, Stream* pMaskStream, int nMaskWidth, int nMaskHeight, GfxImageColorMap* pMaskColorMap, double* pMatteColor, GBool interpolate)
void RendererOutputDev::drawSoftMaskedImage(GfxState* pGState, Gfx *gfx, Object* pRef, Stream* pStream, int nWidth, int nHeight, GfxImageColorMap* pColorMap, Object* maskRef, Stream* pMaskStream, int nMaskWidth, int nMaskHeight, GfxImageColorMap* pMaskColorMap, double* pMatteColor, GBool interpolate)
{
if (m_bDrawOnlyText)
return;

View File

@ -223,12 +223,12 @@ namespace PdfReader
virtual void endMarkedContent(GfxState *state) override;
//----- Вывод картинок
bool ReadImage(Aggplus::CImage* pImageRes, Object *pRef, Stream *pStream);
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;
virtual void drawImage(GfxState *pGState, Object *pRef, Stream *pStream, int nWidth, int nHeight, GfxImageColorMap *pColorMap, int *pMaskColors, GBool bInlineImg, GBool interpolate) override;
virtual void drawMaskedImage(GfxState *pGState, Object *pRef, Stream *pStream, int nWidth, int nHeight, GfxImageColorMap *pColorMap,
virtual void drawImageMask(GfxState *pGState, Gfx *gfx, Object *pRef, Stream *pStream, int nWidth, int nHeight, GBool bInvert, GBool bInlineImage, GBool interpolate) override;
virtual void setSoftMaskFromImageMask(GfxState *pGState, Gfx *gfx, Object *pRef, Stream *pStream, int nWidth, int nHeight, GBool bInvert, GBool bInlineImage, GBool interpolate) override;
virtual void drawImage(GfxState *pGState, Gfx *gfx, Object *pRef, Stream *pStream, int nWidth, int nHeight, GfxImageColorMap *pColorMap, int *pMaskColors, GBool bInlineImg, GBool interpolate) override;
virtual void drawMaskedImage(GfxState *pGState, Gfx *gfx, Object *pRef, Stream *pStream, int nWidth, int nHeight, GfxImageColorMap *pColorMap,
Object* pMaskRef, Stream *pMaskStream, int nMaskWidth, int nMaskHeight, GBool bMaskInvert, GBool interpolate) override;
virtual void drawSoftMaskedImage(GfxState *pGState, Object *pRef, Stream *pStream, int nWidth, int nHeight, GfxImageColorMap *pColorMap,
virtual void drawSoftMaskedImage(GfxState *pGState, Gfx *gfx, Object *pRef, Stream *pStream, int nWidth, int nHeight, GfxImageColorMap *pColorMap,
Object *maskRef, Stream *pMaskStream, int nMaskWidth, int nMaskHeight, GfxImageColorMap *pMaskColorMap, double *pMatte, GBool interpolate) override;
//----- Transparency groups и SMasks
virtual void beginTransparencyGroup(GfxState *pGState, double *pBBox, GfxColorSpace *pBlendingColorSpace, GBool bIsolated, GBool bKnockout, GBool bForSoftMask) override;

View File

@ -95,7 +95,7 @@
#define LIMIT_MAX_STRING_LEN 65535
#define LIMIT_MAX_NAME_LEN 127
#define LIMIT_MAX_ARRAY 8191
#define LIMIT_MAX_ARRAY 65535
#define LIMIT_MAX_DICT_ELEMENT 4095
#define LIMIT_MAX_XREF_ELEMENT 8388607
#define MAX_GENERATION_NUM 65535

View File

@ -773,14 +773,8 @@ namespace PdfWriter
{
return new CImageDict(m_pXref, this);
}
CXObject* CDocument::CreateForm(CImageDict* pImage, const std::string& sName)
CXObject* CDocument::CreateForm()
{
if (!pImage)
return NULL;
std::string sFrmName = "FRM" + sName;
std::string sImgName = "Img" + sName;
CXObject* pForm = new CXObject();
CStream* pStream = new CMemoryStream();
pForm->SetStream(m_pXref, pStream);
@ -789,6 +783,18 @@ namespace PdfWriter
if (m_unCompressMode & COMP_TEXT)
pForm->SetFilter(STREAM_FILTER_FLATE_DECODE);
#endif
return pForm;
}
CXObject* CDocument::CreateForm(CImageDict* pImage, const std::string& sName)
{
if (!pImage)
return NULL;
std::string sFrmName = "FRM" + sName;
std::string sImgName = "Img" + sName;
CXObject* pForm = CreateForm();
double dOriginW = pImage->GetWidth();
double dOriginH = pImage->GetHeight();
pForm->SetWidth(dOriginW);
@ -826,6 +832,7 @@ namespace PdfWriter
pForm->Add("Subtype", "Form");
pForm->Add("Type", "XObject");
CStream* pStream = pForm->GetStream();
pStream->WriteStr("q\012");
pStream->WriteReal(dOriginW);
pStream->WriteStr(" 0 0 ");
@ -1569,6 +1576,17 @@ namespace PdfWriter
{
m_mParents[nID] = pParent;
}
void CDocument::AddXObject(int nID, CDictObject* pXObject)
{
m_mXObjects[nID] = pXObject;
}
CDictObject* CDocument::GetXObject(int nID)
{
std::map<int, CDictObject*>::iterator p = m_mXObjects.find(nID);
if (p != m_mXObjects.end())
return p->second;
return NULL;
}
CDictObject* CDocument::CreateParent(int nID)
{
CDictObject* pParent = new CDictObject();

View File

@ -148,6 +148,7 @@ namespace PdfWriter
CImageDict* CreateImage();
CXObject* CreateForm(CImageDict* pImage, const std::string& sName);
CXObject* CreateForm();
CFont14* CreateFont14(const std::wstring& wsFontPath, unsigned int unIndex, EStandard14Fonts eType);
CFont14* FindFont14 (const std::wstring& wsFontPath, unsigned int unIndex);
CFontCidTrueType* CreateCidTrueTypeFont(const std::wstring& wsFontPath, unsigned int unIndex);
@ -203,6 +204,8 @@ namespace PdfWriter
std::string SetParentKids(int nParentID);
const std::map<int, CAnnotation*>& GetAnnots() { return m_mAnnotations; }
const std::map<int, CDictObject*>& GetParents() { return m_mParents; }
CDictObject* GetXObject(int nID);
void AddXObject(int nID, CDictObject* pXObject);
CPageTree* GetPageTree() { return m_pPageTree; }
CEncryptDict* GetEncrypt() { return m_pEncryptDict; }
void AddShapeXML(const std::string& sXML);
@ -316,6 +319,7 @@ namespace PdfWriter
std::map<int, CAnnotation*> m_mAnnotations;
std::map<int, CDictObject*> m_mParents;
std::map<int, CPage*> m_mEditPages;
std::map<int, CDictObject*> m_mXObjects;
friend class CFontCidTrueType;
friend class CFontTrueType;

View File

@ -788,6 +788,13 @@ namespace PdfWriter
while (oCoreReader.ReadNextSiblingNode(nDeath))
ReadDict(oCoreReader, this);
}
void CDictObject::ClearStream()
{
m_unFilter = STREAM_FILTER_NONE;
m_unPredictor = STREAM_PREDICTOR_NONE;
if (m_pStream)
m_pStream->Clear();
}
//----------------------------------------------------------------------------------------
// CXref
//----------------------------------------------------------------------------------------

View File

@ -492,6 +492,7 @@ namespace PdfWriter
unsigned int GetSize() { return m_mList.size(); }
std::map<std::string, CObjectBase*> GetDict() { return m_mList; }
void FromXml(const std::wstring& sXml);
void ClearStream();
protected:
std::map<std::string, CObjectBase*> m_mList;

View File

@ -194,6 +194,7 @@ namespace PdfWriter
void ClearContent(CXref* pXref);
void ClearContentFull(CXref* pXref);
CResourcesDict* GetResourcesItem();
void AddResource(CXref* pXref = NULL);
private:
@ -204,7 +205,6 @@ namespace PdfWriter
CObjectBase* GetRotateItem();
TBox GetMediaBox();
void SetMediaBoxValue(unsigned int unIndex, double dValue);
void AddResource(CXref* pXref = NULL);
void SetGrMode(EGrMode eMode);
void CheckGrMode(EGrMode eMode);
void WriteText(const BYTE* sText, unsigned int unLen);

File diff suppressed because it is too large Load Diff

View File

@ -33,11 +33,7 @@
#define _PDF_WRITER_SRC_REDACT_OUTPUTDEV_H
#include "../PdfWriter.h"
//#include "../../DesktopEditor/graphics/IRenderer.h"
//#include "../../DesktopEditor/graphics/pro/Fonts.h"
//#include "../../DesktopEditor/graphics/AlphaMask.h"
//#include "../../DesktopEditor/graphics/TemporaryCS.h"
//#include "../../DesktopEditor/graphics/structures.h"
#include "../PdfEditor.h"
#include "../SrcReader/GfxClip.h"
@ -51,7 +47,7 @@ namespace PdfWriter
class RedactOutputDev : public OutputDev
{
public:
RedactOutputDev(CPdfWriter* pRenderer);
RedactOutputDev(CPdfWriter* pRenderer, CObjectsManager* pObjMng);
virtual ~RedactOutputDev();
void SetRedact(const std::vector<double>& arrQuadPoints);
@ -102,19 +98,19 @@ namespace PdfWriter
virtual void updateLineCap(GfxState *pGState) override;
virtual void updateMiterLimit(GfxState *pGState) override;
virtual void updateLineWidth(GfxState *pGState) override;
// updateStrokeAdjust -> setExtGState
// updateStrokeAdjust -> setExtGState
// updateFillColorSpace
// updateStrokeColorSpace
virtual void updateFillColor(GfxState *pGState) override;
virtual void updateStrokeColor(GfxState *pGState) override;
// updateBlendMode -> setExtGState
// updateFillOpacity -> setExtGState
// updateStrokeOpacity -> setExtGState
// updateFillOverprint -> setExtGState
// updateBlendMode -> setExtGState
// updateFillOpacity -> setExtGState
// updateStrokeOpacity -> setExtGState
// updateFillOverprint -> setExtGState
// updateStrokeOverprint -> setExtGState
// updateOverprintMode -> setExtGState
// updateOverprintMode -> setExtGState
virtual void updateRenderingIntent(GfxState *pGState) override;
// updateTransfer -> setExtGState
// updateTransfer -> setExtGState
//----- update text state
virtual void updateFont(GfxState *pGState) override;
// updateTextMat -> drawChar
@ -123,7 +119,7 @@ namespace PdfWriter
virtual void updateRise(GfxState *pGState) override;
virtual void updateWordSpace(GfxState *pGState) override;
virtual void updateHorizScaling(GfxState *pGState) override;
// updateTextPos -> drawChar
// updateTextPos -> drawChar
// updateTextShift -> drawChar
// saveTextPos
// restoreTextPos
@ -162,25 +158,25 @@ namespace PdfWriter
virtual void setStrokeColorN(Object* args, int numArgs) override;
virtual void setShading(GfxState *state, const char* name) 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;
virtual void drawImage(GfxState *pGState, Object *pRef, Stream *pStream, int nWidth, int nHeight, GfxImageColorMap *pColorMap, int *pMaskColors, GBool bInlineImg, GBool interpolate) override;
virtual void drawMaskedImage(GfxState *pGState, Object *pRef, Stream *pStream, int nWidth, int nHeight, GfxImageColorMap *pColorMap,
virtual void drawImageMask(GfxState *pGState, Gfx *gfx, Object *pRef, Stream *pStream, int nWidth, int nHeight, GBool bInvert, GBool bInlineImage, GBool interpolate) override;
// setSoftMaskFromImageMask -> drawImageMask
virtual void drawImage(GfxState *pGState, Gfx *gfx, Object *pRef, Stream *pStream, int nWidth, int nHeight, GfxImageColorMap *pColorMap, int *pMaskColors, GBool bInlineImg, GBool interpolate) override;
virtual void drawMaskedImage(GfxState *pGState, Gfx *gfx, Object *pRef, Stream *pStream, int nWidth, int nHeight, GfxImageColorMap *pColorMap,
Object* pMaskRef, Stream *pMaskStream, int nMaskWidth, int nMaskHeight, GBool bMaskInvert, GBool interpolate) override;
virtual void drawSoftMaskedImage(GfxState *pGState, Object *pRef, Stream *pStream, int nWidth, int nHeight, GfxImageColorMap *pColorMap,
virtual void drawSoftMaskedImage(GfxState *pGState, Gfx *gfx, Object *pRef, Stream *pStream, int nWidth, int nHeight, GfxImageColorMap *pColorMap,
Object *maskRef, Stream *pMaskStream, int nMaskWidth, int nMaskHeight, GfxImageColorMap *pMaskColorMap, double *pMatte, GBool interpolate) override;
//----- Type 3 font operators
virtual void type3D0(GfxState *pGState, double wx, double wy) override;
virtual void type3D1(GfxState *pGState, double wx, double wy, double llx, double lly, double urx, double ury) override;
//----- form XObjects
virtual void drawForm(GfxState *pGState, Ref id, const char *name = NULL) override;
virtual void drawImage(GfxState *pGState, Ref id, const char* name = NULL) override;
virtual void drawForm(GfxState *pGState, Gfx *gfx, Ref id, const char *name = NULL) override;
virtual void drawImage(GfxState *pGState, Gfx *gfx, Ref id, const char* name = NULL) override;
//----- transparency groups and soft masks
virtual void beginTransparencyGroup(GfxState *pGState, double *pBBox, GfxColorSpace *pBlendingColorSpace, GBool bIsolated, GBool bKnockout, GBool bForSoftMask) override;
virtual void endTransparencyGroup(GfxState *pGState) override;
virtual void paintTransparencyGroup(GfxState *pGState, double *pBBox) override;
virtual void setSoftMask(GfxState *pGState, double *pBBox, GBool bAlpha, Function *pTransferFunc, GfxColor *pBackdropColor) override;
virtual void clearSoftMask(GfxState *pGState) override;
// beginTransparencyGroup -> drawForm
// endTransparencyGroup -> drawForm
// paintTransparencyGroup -> drawForm
// setSoftMask -> drawForm
// clearSoftMask -> drawForm
private:
struct GfxRedactState
@ -196,22 +192,26 @@ namespace PdfWriter
};
void DoPathRedact(GfxState* pGState, GfxPath* pPath, double* pCTM, bool bStroke = false, bool bEoFill = false);
void DrawPathRedact(Aggplus::CGraphicsPath* oPath, bool bStroke, const std::vector<CSegment>& arrForStroke = {});
void DrawPathRedact(Aggplus::CGraphicsPath* oPath, bool bStroke, double& dXEnd, double& dYEnd, const std::vector<CSegment>& arrForStroke = {});
void DoPath(GfxState* pGState, GfxPath* pPath, double* pCTM);
void DoTransform(double* pMatrix, double* pdShiftX, double* pdShiftY, bool bActual = false);
void DrawPath(const LONG& lType);
void UpdateTransform();
void AddClip(GfxState* pGState, GfxRedactState* pState, int nIndex);
void DoStateOp();
void DrawXObject(const char* name);
CObjectBase* CreateImage(Gfx *gfx, int nWidth, int nHeight, unsigned int nFilter, int nBPC, const char* sCS);
XRef* m_pXref;
std::vector<double> m_arrQuadPoints;
Aggplus::CGraphicsPath m_oPathRedact;
CPdfWriter* m_pRenderer;
CObjectsManager* m_mObjManager;
CDocument* m_pDoc;
CPage* m_pPage;
double m_arrMatrix[6];
std::string m_sImageName;
bool m_bUpdateAll;
std::deque<GfxRedactState> m_sStates;

View File

@ -851,6 +851,11 @@ namespace PdfWriter
{
return m_unSize;
}
void CMemoryStream::Clear()
{
m_pCur = m_pBuffer;
m_unSize = 0;
}
BYTE* CMemoryStream::GetBuffer()
{
return m_pBuffer;
@ -1005,9 +1010,9 @@ namespace PdfWriter
{
switch (eMode)
{
case SeekCur: m_nFilePos += nPos; break;
case SeekEnd: m_nFilePos = std::max(0, (m_nFileSize - nPos)); break;
case SeekSet: m_nFilePos = nPos; break;
case SeekCur: m_nFilePos += nPos; break;
case SeekEnd: m_nFilePos = std::max(0, (m_nFileSize - nPos)); break;
case SeekSet: m_nFilePos = nPos; break;
}
}
int CImageFileStream::Tell()

View File

@ -97,6 +97,7 @@ namespace PdfWriter
virtual int Tell() = 0;
virtual void Close() = 0;
virtual unsigned int Size() = 0;
virtual void Clear() {}
virtual EStreamType GetType()
{
return StreamUnknown;
@ -159,6 +160,7 @@ namespace PdfWriter
int Tell();
void Close();
unsigned int Size();
void Clear();
EStreamType GetType()
{
return StreamMemory;

View File

@ -363,6 +363,15 @@ namespace PdfWriter
}
return true; // Пересекаются
}
bool isPolygonInsidePolygon(const std::vector<CPoint>& inner, const std::vector<CPoint>& outer)
{
for (const CPoint& point : inner)
{
if (!isPointInQuad(point.x, point.y, outer[0].x, outer[0].y, outer[1].x, outer[1].y, outer[2].x, outer[2].y, outer[3].x, outer[3].y))
return false;
}
return true;
}
double crossProduct(double x1, double y1, double x2, double y2, double x3, double y3)
{
return (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);

View File

@ -144,6 +144,8 @@ namespace PdfWriter
// Пересечение многоугольников по теореме о разделяющей оси
bool SAT(const std::vector<CPoint>& poly1, const std::vector<CPoint>& poly2);
// Проверка, что все точки внутреннего полигона находятся внутри внешнего
bool isPolygonInsidePolygon(const std::vector<CPoint>& inner, const std::vector<CPoint>& outer);
// Проверка принадлежности точки выпуклому четырехугольнику
bool isPointInQuad(double px, double py,
double x1, double y1, double x2, double y2,

View File

@ -1528,16 +1528,16 @@ void Gfx::opSetFillColor(Object args[], int numArgs) {
" in uncolored Type 3 char or tiling pattern");
return;
}
if (numArgs != state->getFillColorSpace()->getNComps()) {
error(errSyntaxError, getPos(),
"Incorrect number of arguments in 'sc' command");
return;
}
if (out->useNameOp())
{
out->setFillColor(args, numArgs);
return;
}
if (numArgs != state->getFillColorSpace()->getNComps()) {
error(errSyntaxError, getPos(),
"Incorrect number of arguments in 'sc' command");
return;
}
state->setFillPattern(NULL);
for (i = 0; i < numArgs; ++i) {
color.c[i] = dblToCol(args[i].getNum());
@ -2028,7 +2028,7 @@ void Gfx::doPatternImageMask(Object *ref, Stream *str, int width, int height,
GBool invert, GBool inlineImg, GBool interpolate) {
saveState();
out->setSoftMaskFromImageMask(state, ref, str,
out->setSoftMaskFromImageMask(state, this, ref, str,
width, height, invert, inlineImg, interpolate);
state->clearPath();
@ -4117,16 +4117,15 @@ void Gfx::opXObject(Object args[], int numArgs) {
if (out->needNonText()) {
res->lookupXObjectNF(name, &refObj);
if (out->useNameOp() && refObj.isRef())
out->drawImage(state, refObj.getRef(), name);
else
doImage(&refObj, obj1.getStream(), gFalse);
out->drawImage(state, this, refObj.getRef(), name);
doImage(&refObj, obj1.getStream(), gFalse);
refObj.free();
}
} else if (obj2.isName("Form")) {
res->lookupXObjectNF(name, &refObj);
if (out->useDrawForm() && refObj.isRef()) {
if (ocState) {
out->drawForm(state, refObj.getRef(), name);
out->drawForm(state, this, refObj.getRef(), name);
}
} else {
doForm(&refObj, &obj1);
@ -4305,7 +4304,7 @@ GBool Gfx::doImage(Object *ref, Stream *str, GBool inlineImg) {
doPatternImageMask(ref, str, width, height, invert, inlineImg,
interpolate);
} else {
out->drawImageMask(state, ref, str, width, height, invert, inlineImg,
out->drawImageMask(state, this, ref, str, width, height, invert, inlineImg,
interpolate);
}
}
@ -4314,7 +4313,8 @@ GBool Gfx::doImage(Object *ref, Stream *str, GBool inlineImg) {
// rendering intent
if (dict->lookup("Intent", &obj1)->isName()) {
opSetRenderingIntent(&obj1, 1);
if (!out->useNameOp())
opSetRenderingIntent(&obj1, 1);
}
obj1.free();
@ -4646,7 +4646,7 @@ GBool Gfx::doImage(Object *ref, Stream *str, GBool inlineImg) {
} else {
if (haveSoftMask) {
dict->lookupNF("Mask", &maskRef);
out->drawSoftMaskedImage(state, ref, str, width, height, colorMap,
out->drawSoftMaskedImage(state, this, ref, str, width, height, colorMap,
&maskRef, maskStr, maskWidth, maskHeight,
maskColorMap,
haveMatte ? matte : (double *)NULL,
@ -4655,12 +4655,12 @@ GBool Gfx::doImage(Object *ref, Stream *str, GBool inlineImg) {
delete maskColorMap;
} else if (haveExplicitMask) {
dict->lookupNF("Mask", &maskRef);
out->drawMaskedImage(state, ref, str, width, height, colorMap,
out->drawMaskedImage(state, this, ref, str, width, height, colorMap,
&maskRef, maskStr, maskWidth, maskHeight,
maskInvert, interpolate);
maskRef.free();
} else {
out->drawImage(state, ref, str, width, height, colorMap,
out->drawImage(state, this, ref, str, width, height, colorMap,
haveColorKeyMask ? maskColors : (int *)NULL, inlineImg,
interpolate);
}
@ -4932,6 +4932,12 @@ void Gfx::takeContentStreamStack(Gfx *oldGfx) {
contentStreamStack->append(oldGfx->contentStreamStack);
}
Object* Gfx::getTopContentStreamStack() {
if (!contentStreamStack->getLength())
return NULL;
return (Object*)contentStreamStack->get(contentStreamStack->getLength() - 1);
}
void Gfx::endOfPage() {
while (state->hasSaves()) {
restoreState();

View File

@ -177,6 +177,7 @@ public:
// Gfx constructor, i.e., before processing any content streams with
// the new Gfx object.
void takeContentStreamStack(Gfx *oldGfx);
Object* getTopContentStreamStack();
// Clear the state stack and the marked content stack.
void endOfPage();

View File

@ -82,7 +82,7 @@ GBool OutputDev::beginType3Char(GfxState *state, double x, double y,
return gFalse;
}
void OutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
void OutputDev::drawImageMask(GfxState *state, Gfx *gfx, Object *ref, Stream *str,
int width, int height, GBool invert,
GBool inlineImg, GBool interpolate) {
if (inlineImg) {
@ -92,14 +92,14 @@ void OutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
}
}
void OutputDev::setSoftMaskFromImageMask(GfxState *state,
void OutputDev::setSoftMaskFromImageMask(GfxState *state, Gfx *gfx,
Object *ref, Stream *str,
int width, int height, GBool invert,
GBool inlineImg, GBool interpolate) {
drawImageMask(state, ref, str, width, height, invert, inlineImg, interpolate);
drawImageMask(state, gfx, ref, str, width, height, invert, inlineImg, interpolate);
}
void OutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
void OutputDev::drawImage(GfxState *state, Gfx *gfx, Object *ref, Stream *str,
int width, int height, GfxImageColorMap *colorMap,
int *maskColors, GBool inlineImg, GBool interpolate) {
if (inlineImg) {
@ -110,24 +110,24 @@ void OutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
}
}
void OutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
void OutputDev::drawMaskedImage(GfxState *state, Gfx *gfx, Object *ref, Stream *str,
int width, int height,
GfxImageColorMap *colorMap,
Object *maskRef, Stream *maskStr,
int maskWidth, int maskHeight,
GBool maskInvert, GBool interpolate) {
drawImage(state, ref, str, width, height, colorMap, NULL, gFalse,
drawImage(state, gfx, ref, str, width, height, colorMap, NULL, gFalse,
interpolate);
}
void OutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
void OutputDev::drawSoftMaskedImage(GfxState *state, Gfx *gfx, Object *ref, Stream *str,
int width, int height,
GfxImageColorMap *colorMap,
Object *maskRef, Stream *maskStr,
int maskWidth, int maskHeight,
GfxImageColorMap *maskColorMap,
double *matte, GBool interpolate) {
drawImage(state, ref, str, width, height, colorMap, NULL, gFalse,
drawImage(state, gfx, ref, str, width, height, colorMap, NULL, gFalse,
interpolate);
}

View File

@ -201,23 +201,23 @@ public:
virtual void setShading(GfxState *state, const char* name) {}
//----- image drawing
virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
virtual void drawImageMask(GfxState *state, Gfx *gfx, Object *ref, Stream *str,
int width, int height, GBool invert,
GBool inlineImg, GBool interpolate);
virtual void setSoftMaskFromImageMask(GfxState *state,
virtual void setSoftMaskFromImageMask(GfxState *state, Gfx *gfx,
Object *ref, Stream *str,
int width, int height, GBool invert,
GBool inlineImg, GBool interpolate);
virtual void drawImage(GfxState *state, Object *ref, Stream *str,
virtual void drawImage(GfxState *state, Gfx *gfx, Object *ref, Stream *str,
int width, int height, GfxImageColorMap *colorMap,
int *maskColors, GBool inlineImg, GBool interpolate);
virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
virtual void drawMaskedImage(GfxState *state, Gfx *gfx, Object *ref, Stream *str,
int width, int height,
GfxImageColorMap *colorMap,
Object *maskRef, Stream *maskStr,
int maskWidth, int maskHeight,
GBool maskInvert, GBool interpolate);
virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
virtual void drawSoftMaskedImage(GfxState *state, Gfx *gfx, Object *ref, Stream *str,
int width, int height,
GfxImageColorMap *colorMap,
Object *maskRef, Stream *maskStr,
@ -237,8 +237,8 @@ public:
double llx, double lly, double urx, double ury) {}
//----- form XObjects
virtual void drawForm(GfxState *state, Ref id, const char *name = nullptr) {}
virtual void drawImage(GfxState *pGState, Ref id, const char* name = nullptr) {}
virtual void drawForm(GfxState *state, Gfx *gfx, Ref id, const char *name = nullptr) {}
virtual void drawImage(GfxState *pGState, Gfx *gfx, Ref id, const char* name = nullptr) {}
//----- PostScript XObjects
virtual void psXObject(Stream *psStream, Stream *level1Stream) {}