本文整理汇总了C++中CPDF_Document::AddIndirectObject方法的典型用法代码示例。如果您正苦于以下问题:C++ CPDF_Document::AddIndirectObject方法的具体用法?C++ CPDF_Document::AddIndirectObject怎么用?C++ CPDF_Document::AddIndirectObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CPDF_Document
的用法示例。
在下文中一共展示了CPDF_Document::AddIndirectObject方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteAppearance
void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
const CPDF_Rect& rcBBox,
const CFX_Matrix& matrix,
const CFX_ByteString& sContents,
const CFX_ByteString& sAPState) {
CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictBy("AP");
if (!pAPDict) {
pAPDict = new CPDF_Dictionary;
m_pAnnot->GetAnnotDict()->SetAt("AP", pAPDict);
}
CPDF_Stream* pStream = nullptr;
CPDF_Dictionary* pParentDict = nullptr;
if (sAPState.IsEmpty()) {
pParentDict = pAPDict;
pStream = pAPDict->GetStreamBy(sAPType);
} else {
CPDF_Dictionary* pAPTypeDict = pAPDict->GetDictBy(sAPType);
if (!pAPTypeDict) {
pAPTypeDict = new CPDF_Dictionary;
pAPDict->SetAt(sAPType, pAPTypeDict);
}
pParentDict = pAPTypeDict;
pStream = pAPTypeDict->GetStreamBy(sAPState);
}
if (!pStream) {
pStream = new CPDF_Stream(nullptr, 0, nullptr);
CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
int32_t objnum = pDoc->AddIndirectObject(pStream);
pParentDict->SetAtReference(sAPType, pDoc, objnum);
}
CPDF_Dictionary* pStreamDict = pStream->GetDict();
if (!pStreamDict) {
pStreamDict = new CPDF_Dictionary;
pStreamDict->SetAtName("Type", "XObject");
pStreamDict->SetAtName("Subtype", "Form");
pStreamDict->SetAtInteger("FormType", 1);
pStream->InitStream(nullptr, 0, pStreamDict);
}
if (pStreamDict) {
pStreamDict->SetAtMatrix("Matrix", matrix);
pStreamDict->SetAtRect("BBox", rcBBox);
}
pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength(), FALSE,
FALSE);
}
示例2: SetAction
void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
ASSERT(action);
if ((CPDF_Action&)action !=
CPDF_Action(m_pAnnot->GetAnnotDict()->GetDictBy("A"))) {
CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
CPDF_Dictionary* pDict = action.GetDict();
if (pDict && pDict->GetObjNum() == 0) {
pDoc->AddIndirectObject(pDict);
}
m_pAnnot->GetAnnotDict()->SetAtReference("A", pDoc, pDict->GetObjNum());
}
}
示例3: SetAction
void CPDFSDK_Annot::SetAction(const CPDF_Action& action)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
ASSERT(action != NULL);
if ((CPDF_Action&)action != m_pAnnot->m_pAnnotDict->GetDict("A"))
{
CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
ASSERT(pDoc != NULL);
if (action.m_pDict && (action.m_pDict->GetObjNum() == 0))
pDoc->AddIndirectObject(action.m_pDict);
m_pAnnot->m_pAnnotDict->SetAtReference("A", pDoc, action.m_pDict->GetObjNum());
}
}
示例4: rect
DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
FS_MATRIX* matrix,
FS_RECTF* clipRect) {
CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return FALSE;
CFX_ByteTextBuf textBuf;
textBuf << "q ";
CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right,
clipRect->top);
rect.Normalize();
CFX_ByteString bsClipping;
bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom,
rect.Width(), rect.Height());
textBuf << bsClipping;
CFX_ByteString bsMatix;
bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b, matrix->c,
matrix->d, matrix->e, matrix->f);
textBuf << bsMatix;
CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
CPDF_Object* pContentObj =
pPageDic ? pPageDic->GetElement("Contents") : nullptr;
if (!pContentObj)
pContentObj = pPageDic ? pPageDic->GetArrayBy("Contents") : nullptr;
if (!pContentObj)
return FALSE;
CPDF_Dictionary* pDic = new CPDF_Dictionary;
CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE);
CPDF_Document* pDoc = pPage->m_pDocument;
if (!pDoc)
return FALSE;
pDoc->AddIndirectObject(pStream);
pDic = new CPDF_Dictionary;
CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic);
pEndStream->SetData((const uint8_t*)" Q", 2, FALSE, FALSE);
pDoc->AddIndirectObject(pEndStream);
CPDF_Array* pContentArray = nullptr;
if (CPDF_Array* pArray = ToArray(pContentObj)) {
pContentArray = pArray;
CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
pContentArray->AddReference(pDoc, pEndStream);
} else if (CPDF_Reference* pReference = ToReference(pContentObj)) {
CPDF_Object* pDirectObj = pReference->GetDirect();
if (pDirectObj) {
if (CPDF_Array* pArray = pDirectObj->AsArray()) {
pContentArray = pArray;
CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
pContentArray->AddReference(pDoc, pEndStream);
} else if (pDirectObj->IsStream()) {
pContentArray = new CPDF_Array();
pContentArray->AddReference(pDoc, pStream->GetObjNum());
pContentArray->AddReference(pDoc, pDirectObj->GetObjNum());
pContentArray->AddReference(pDoc, pEndStream);
pPageDic->SetAtReference("Contents", pDoc,
pDoc->AddIndirectObject(pContentArray));
}
}
}
// Need to transform the patterns as well.
CPDF_Dictionary* pRes = pPageDic->GetDictBy("Resources");
if (pRes) {
CPDF_Dictionary* pPattenDict = pRes->GetDictBy("Pattern");
if (pPattenDict) {
for (const auto& it : *pPattenDict) {
CPDF_Object* pObj = it.second;
if (pObj->IsReference())
pObj = pObj->GetDirect();
CPDF_Dictionary* pDict = nullptr;
if (pObj->IsDictionary())
pDict = pObj->AsDictionary();
else if (CPDF_Stream* pStream = pObj->AsStream())
pDict = pStream->GetDict();
else
continue;
CFX_Matrix m = pDict->GetMatrixBy("Matrix");
CFX_Matrix t = *(CFX_Matrix*)matrix;
m.Concat(t);
pDict->SetAtMatrix("Matrix", m);
}
}
}
return TRUE;
}
示例5: CPDFPageFromFPDFPage
DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,
FPDF_CLIPPATH clipPath) {
CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!pPage)
return;
CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
CPDF_Object* pContentObj =
pPageDic ? pPageDic->GetElement("Contents") : nullptr;
if (!pContentObj)
pContentObj = pPageDic ? pPageDic->GetArrayBy("Contents") : nullptr;
if (!pContentObj)
return;
CFX_ByteTextBuf strClip;
CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath;
FX_DWORD i;
for (i = 0; i < pClipPath->GetPathCount(); i++) {
CPDF_Path path = pClipPath->GetPath(i);
int iClipType = pClipPath->GetClipType(i);
if (path.GetPointCount() == 0) {
// Empty clipping (totally clipped out)
strClip << "0 0 m W n ";
} else {
OutputPath(strClip, path);
if (iClipType == FXFILL_WINDING)
strClip << "W n\n";
else
strClip << "W* n\n";
}
}
CPDF_Dictionary* pDic = new CPDF_Dictionary;
CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE);
CPDF_Document* pDoc = pPage->m_pDocument;
if (!pDoc)
return;
pDoc->AddIndirectObject(pStream);
CPDF_Array* pContentArray = nullptr;
if (CPDF_Array* pArray = ToArray(pContentObj)) {
pContentArray = pArray;
CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
} else if (CPDF_Reference* pReference = ToReference(pContentObj)) {
CPDF_Object* pDirectObj = pReference->GetDirect();
if (pDirectObj) {
if (CPDF_Array* pArray = pDirectObj->AsArray()) {
pContentArray = pArray;
CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
} else if (pDirectObj->IsStream()) {
pContentArray = new CPDF_Array();
pContentArray->AddReference(pDoc, pStream->GetObjNum());
pContentArray->AddReference(pDoc, pDirectObj->GetObjNum());
pPageDic->SetAtReference("Contents", pDoc,
pDoc->AddIndirectObject(pContentArray));
}
}
}
}
示例6: rect
DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, FS_MATRIX* matrix, FS_RECTF* clipRect)
{
if(!page)
return FALSE;
CFX_ByteTextBuf textBuf;
textBuf<<"q ";
CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, clipRect->top);
rect.Normalize();
CFX_ByteString bsClipping;
bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, rect.Width(), rect.Height());
textBuf<<bsClipping;
CFX_ByteString bsMatix;
bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b,matrix->c,matrix->d,matrix->e,matrix->f);
textBuf<<bsMatix;
CPDF_Page* pPage = (CPDF_Page*)page;
CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
CPDF_Object* pContentObj = pPageDic->GetElement("Contents");
if(!pContentObj)
pContentObj = pPageDic->GetArray("Contents");
if(!pContentObj)
return FALSE;
CPDF_Dictionary* pDic = FX_NEW CPDF_Dictionary;
CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL,0, pDic);
pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize(), FALSE, FALSE);
CPDF_Document* pDoc = pPage->m_pDocument;
if(!pDoc)
return FALSE;
pDoc->AddIndirectObject(pStream);
pDic = FX_NEW CPDF_Dictionary;
CPDF_Stream* pEndStream = FX_NEW CPDF_Stream(NULL,0, pDic);
pEndStream->SetData((FX_LPCBYTE)" Q", 2, FALSE, FALSE);
pDoc->AddIndirectObject(pEndStream);
CPDF_Array* pContentArray = NULL;
if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY)
{
pContentArray = (CPDF_Array*)pContentObj;
CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
pContentArray->AddReference(pDoc,pEndStream);
}
else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE)
{
CPDF_Reference* pReference = (CPDF_Reference*)pContentObj;
CPDF_Object* pDirectObj = pReference->GetDirect();
if(pDirectObj != NULL)
{
if(pDirectObj->GetType() == PDFOBJ_ARRAY)
{
pContentArray = (CPDF_Array*)pDirectObj;
CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
pContentArray->AddReference(pDoc,pEndStream);
}
else if(pDirectObj->GetType() == PDFOBJ_STREAM)
{
pContentArray = FX_NEW CPDF_Array();
pContentArray->AddReference(pDoc,pStream->GetObjNum());
pContentArray->AddReference(pDoc,pDirectObj->GetObjNum());
pContentArray->AddReference(pDoc, pEndStream);
pPageDic->SetAtReference("Contents", pDoc, pDoc->AddIndirectObject(pContentArray));
}
}
}
//Need to transform the patterns as well.
CPDF_Dictionary* pRes = pPageDic->GetDict(FX_BSTRC("Resources"));
if(pRes)
{
CPDF_Dictionary* pPattenDict = pRes->GetDict(FX_BSTRC("Pattern"));
if(pPattenDict)
{
FX_POSITION pos = pPattenDict->GetStartPos();
while(pos)
{
CPDF_Dictionary* pDict = NULL;
CFX_ByteString key;
CPDF_Object* pObj = pPattenDict->GetNextElement(pos, key);
if(pObj->GetType() == PDFOBJ_REFERENCE)
pObj = pObj->GetDirect();
if(pObj->GetType() == PDFOBJ_DICTIONARY)
{
pDict = (CPDF_Dictionary*)pObj;
}
else if(pObj->GetType() == PDFOBJ_STREAM)
{
pDict = ((CPDF_Stream*)pObj)->GetDict();
}
else
continue;
CFX_AffineMatrix m = pDict->GetMatrix(FX_BSTRC("Matrix"));
//.........这里部分代码省略.........
示例7: if
DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,FPDF_CLIPPATH clipPath)
{
if(!page)
return;
CPDF_Page* pPage = (CPDF_Page*)page;
CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
CPDF_Object* pContentObj = pPageDic->GetElement("Contents");
if(!pContentObj)
pContentObj = pPageDic->GetArray("Contents");
if(!pContentObj)
return;
CFX_ByteTextBuf strClip;
CPDF_ClipPath* pClipPath = (CPDF_ClipPath*)clipPath;
FX_DWORD i;
for (i = 0; i < pClipPath->GetPathCount(); i ++) {
CPDF_Path path = pClipPath->GetPath(i);
int iClipType = pClipPath->GetClipType(i);
if (path.GetPointCount() == 0) {
// Empty clipping (totally clipped out)
strClip << "0 0 m W n ";
} else {
OutputPath(strClip, path);
if (iClipType == FXFILL_WINDING)
strClip << "W n\n";
else
strClip << "W* n\n";
}
}
CPDF_Dictionary* pDic = FX_NEW CPDF_Dictionary;
CPDF_Stream* pStream = FX_NEW CPDF_Stream(NULL,0, pDic);
pStream->SetData(strClip.GetBuffer(), strClip.GetSize(), FALSE, FALSE);
CPDF_Document* pDoc = pPage->m_pDocument;
if(!pDoc)
return;
pDoc->AddIndirectObject(pStream);
CPDF_Array* pContentArray = NULL;
if (pContentObj && pContentObj->GetType() == PDFOBJ_ARRAY)
{
pContentArray = (CPDF_Array*)pContentObj;
CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
}
else if(pContentObj && pContentObj->GetType() == PDFOBJ_REFERENCE)
{
CPDF_Reference* pReference = (CPDF_Reference*)pContentObj;
CPDF_Object* pDirectObj = pReference->GetDirect();
if(pDirectObj != NULL)
{
if(pDirectObj->GetType() == PDFOBJ_ARRAY)
{
pContentArray = (CPDF_Array*)pDirectObj;
CPDF_Reference* pRef = FX_NEW CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
}
else if(pDirectObj->GetType() == PDFOBJ_STREAM)
{
pContentArray = FX_NEW CPDF_Array();
pContentArray->AddReference(pDoc,pStream->GetObjNum());
pContentArray->AddReference(pDoc,pDirectObj->GetObjNum());
pPageDic->SetAtReference("Contents", pDoc, pDoc->AddIndirectObject(pContentArray));
}
}
}
}
示例8: WriteAppearance
void CPDFSDK_Annot::WriteAppearance(const CFX_ByteString& sAPType, const CPDF_Rect& rcBBox,
const CPDF_Matrix& matrix, const CFX_ByteString& sContents,
const CFX_ByteString& sAPState)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
CPDF_Dictionary* pAPDict = m_pAnnot->m_pAnnotDict->GetDict("AP");
if (!pAPDict)
{
pAPDict = FX_NEW CPDF_Dictionary;
m_pAnnot->m_pAnnotDict->SetAt("AP", pAPDict);
}
CPDF_Stream* pStream = NULL;
CPDF_Dictionary* pParentDict = NULL;
if (sAPState.IsEmpty())
{
pParentDict = pAPDict;
pStream = pAPDict->GetStream(sAPType);
}
else
{
CPDF_Dictionary* pAPTypeDict = pAPDict->GetDict(sAPType);
if (!pAPTypeDict)
{
pAPTypeDict = FX_NEW CPDF_Dictionary;
pAPDict->SetAt(sAPType, pAPTypeDict);
}
pParentDict = pAPTypeDict;
pStream = pAPTypeDict->GetStream(sAPState);
}
if (!pStream)
{
ASSERT(m_pPageView != NULL);
CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
ASSERT(pDoc != NULL);
pStream = FX_NEW CPDF_Stream(NULL, 0, NULL);
FX_INT32 objnum = pDoc->AddIndirectObject(pStream);
//pAPDict->SetAtReference(sAPType, pDoc, objnum);
ASSERT(pParentDict != NULL);
pParentDict->SetAtReference(sAPType, pDoc, objnum);
}
CPDF_Dictionary * pStreamDict = pStream->GetDict();
if (!pStreamDict)
{
pStreamDict = FX_NEW CPDF_Dictionary;
pStreamDict->SetAtName("Type", "XObject");
pStreamDict->SetAtName("Subtype", "Form");
pStreamDict->SetAtInteger("FormType", 1);
pStream->InitStream(NULL,0,pStreamDict);
}
if (pStreamDict)
{
pStreamDict->SetAtMatrix("Matrix",matrix);
pStreamDict->SetAtRect("BBox", rcBBox);
}
pStream->SetData((FX_BYTE*)sContents.c_str(), sContents.GetLength(), FALSE, FALSE);
}
示例9: if
DLLEXPORT int STDCALL FPDFPage_Flatten( FPDF_PAGE page, int nFlag)
{
if (!page)
{
return FLATTEN_FAIL;
}
CPDF_Page * pPage = (CPDF_Page*)( page );
CPDF_Document * pDocument = pPage->m_pDocument;
CPDF_Dictionary * pPageDict = pPage->m_pFormDict;
if ( !pDocument || !pPageDict )
{
return FLATTEN_FAIL;
}
CPDF_ObjectArray ObjectArray;
CPDF_RectArray RectArray;
int iRet = FLATTEN_FAIL;
iRet = ParserAnnots( pDocument, pPageDict, &RectArray, &ObjectArray, nFlag);
if (iRet == FLATTEN_NOTINGTODO)
{
return FLATTEN_NOTINGTODO;
}else if (iRet == FLATTEN_FAIL)
{
return FLATTEN_FAIL;
}
CPDF_Rect rcOriginalCB;
CPDF_Rect rcMerger = CalculateRect( &RectArray );
CPDF_Rect rcOriginalMB = pPageDict->GetRect("MediaBox");
if (pPageDict->KeyExist("CropBox"))
rcOriginalMB = pPageDict->GetRect("CropBox");
if (rcOriginalMB.IsEmpty())
{
rcOriginalMB = CPDF_Rect(0.0f, 0.0f, 612.0f, 792.0f);
}
rcMerger.left = rcMerger.left < rcOriginalMB.left? rcOriginalMB.left : rcMerger.left;
rcMerger.right = rcMerger.right > rcOriginalMB.right? rcOriginalMB.right : rcMerger.right;
rcMerger.top = rcMerger.top > rcOriginalMB.top? rcOriginalMB.top : rcMerger.top;
rcMerger.bottom = rcMerger.bottom < rcOriginalMB.bottom? rcOriginalMB.bottom : rcMerger.bottom;
if (pPageDict->KeyExist("ArtBox"))
rcOriginalCB = pPageDict->GetRect("ArtBox");
else
rcOriginalCB = rcOriginalMB;
if (!rcOriginalMB.IsEmpty())
{
CPDF_Array* pMediaBox = FX_NEW CPDF_Array();
pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.left));
pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.bottom));
pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.right));
pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.top));
pPageDict->SetAt("MediaBox",pMediaBox);
}
if (!rcOriginalCB.IsEmpty())
{
CPDF_Array* pCropBox = FX_NEW CPDF_Array();
pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.left));
pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.bottom));
pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.right));
pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.top));
pPageDict->SetAt("ArtBox", pCropBox);
}
CPDF_Dictionary* pRes = NULL;
pRes = pPageDict->GetDict("Resources");
if (!pRes)
{
pRes = FX_NEW CPDF_Dictionary;
pPageDict->SetAt( "Resources", pRes );
}
CPDF_Stream* pNewXObject = FX_NEW CPDF_Stream(NULL, 0, FX_NEW CPDF_Dictionary);
FX_DWORD dwObjNum = pDocument->AddIndirectObject(pNewXObject);
CPDF_Dictionary* pPageXObject = pRes->GetDict("XObject");
if (!pPageXObject)
{
pPageXObject = FX_NEW CPDF_Dictionary;
pRes->SetAt("XObject", pPageXObject);
}
CFX_ByteString key = "";
int nStreams = ObjectArray.GetSize();
if (nStreams > 0)
{
for (int iKey = 0; /*iKey < 100*/; iKey++)
{
char sExtend[5] = {0};
FXSYS_itoa(iKey, sExtend, 10);
key = CFX_ByteString("FFT") + CFX_ByteString(sExtend);
//.........这里部分代码省略.........
示例10: if
DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
if (!page) {
return FLATTEN_FAIL;
}
CPDF_Document* pDocument = pPage->m_pDocument;
CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
if (!pDocument || !pPageDict) {
return FLATTEN_FAIL;
}
CPDF_ObjectArray ObjectArray;
CPDF_RectArray RectArray;
int iRet = FLATTEN_FAIL;
iRet = ParserAnnots(pDocument, pPageDict, &RectArray, &ObjectArray, nFlag);
if (iRet == FLATTEN_NOTHINGTODO || iRet == FLATTEN_FAIL)
return iRet;
CFX_FloatRect rcOriginalCB;
CFX_FloatRect rcMerger = CalculateRect(&RectArray);
CFX_FloatRect rcOriginalMB = pPageDict->GetRectFor("MediaBox");
if (pPageDict->KeyExist("CropBox"))
rcOriginalMB = pPageDict->GetRectFor("CropBox");
if (rcOriginalMB.IsEmpty()) {
rcOriginalMB = CFX_FloatRect(0.0f, 0.0f, 612.0f, 792.0f);
}
rcMerger.left =
rcMerger.left < rcOriginalMB.left ? rcOriginalMB.left : rcMerger.left;
rcMerger.right =
rcMerger.right > rcOriginalMB.right ? rcOriginalMB.right : rcMerger.right;
rcMerger.top =
rcMerger.top > rcOriginalMB.top ? rcOriginalMB.top : rcMerger.top;
rcMerger.bottom = rcMerger.bottom < rcOriginalMB.bottom ? rcOriginalMB.bottom
: rcMerger.bottom;
if (pPageDict->KeyExist("ArtBox"))
rcOriginalCB = pPageDict->GetRectFor("ArtBox");
else
rcOriginalCB = rcOriginalMB;
if (!rcOriginalMB.IsEmpty()) {
CPDF_Array* pMediaBox = new CPDF_Array();
pMediaBox->Add(new CPDF_Number(rcOriginalMB.left));
pMediaBox->Add(new CPDF_Number(rcOriginalMB.bottom));
pMediaBox->Add(new CPDF_Number(rcOriginalMB.right));
pMediaBox->Add(new CPDF_Number(rcOriginalMB.top));
pPageDict->SetFor("MediaBox", pMediaBox);
}
if (!rcOriginalCB.IsEmpty()) {
CPDF_Array* pCropBox = new CPDF_Array();
pCropBox->Add(new CPDF_Number(rcOriginalCB.left));
pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom));
pCropBox->Add(new CPDF_Number(rcOriginalCB.right));
pCropBox->Add(new CPDF_Number(rcOriginalCB.top));
pPageDict->SetFor("ArtBox", pCropBox);
}
CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources");
if (!pRes) {
pRes = new CPDF_Dictionary(pDocument->GetByteStringPool());
pPageDict->SetFor("Resources", pRes);
}
CPDF_Stream* pNewXObject = new CPDF_Stream(
nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool()));
uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject);
CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject");
if (!pPageXObject) {
pPageXObject = new CPDF_Dictionary(pDocument->GetByteStringPool());
pRes->SetFor("XObject", pPageXObject);
}
CFX_ByteString key = "";
int nStreams = ObjectArray.GetSize();
if (nStreams > 0) {
for (int iKey = 0; /*iKey < 100*/; iKey++) {
char sExtend[5] = {};
FXSYS_itoa(iKey, sExtend, 10);
key = CFX_ByteString("FFT") + CFX_ByteString(sExtend);
if (!pPageXObject->KeyExist(key))
break;
}
}
SetPageContents(key, pPageDict, pDocument);
CPDF_Dictionary* pNewXORes = nullptr;
if (!key.IsEmpty()) {
pPageXObject->SetReferenceFor(key, pDocument, dwObjNum);
CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict();
//.........这里部分代码省略.........
示例11: _SaveXFADocumentData
//.........这里部分代码省略.........
CPDF_Stream* pTemplateStream = pArray->GetStream(iTemplate);
CPDF_StreamAcc streamAcc;
streamAcc.LoadAllData(pTemplateStream);
uint8_t* pData = (uint8_t*)streamAcc.GetData();
FX_DWORD dwSize2 = streamAcc.GetSize();
IFX_FileStream* pTemplate = FX_CreateMemoryStream(pData, dwSize2);
pContext->UpdateChecksum((IFX_FileRead*)pTemplate);
pTemplate->Release();
}
CPDF_Stream* pFormStream = NULL;
CPDF_Stream* pDataSetsStream = NULL;
if (iFormIndex != -1) {
// Get form CPDF_Stream
CPDF_Object* pFormPDFObj = pArray->GetElement(iFormIndex);
if (pFormPDFObj->GetType() == PDFOBJ_REFERENCE) {
CPDF_Object* pFormDircetObj = pFormPDFObj->GetDirect();
if (NULL != pFormDircetObj &&
pFormDircetObj->GetType() == PDFOBJ_STREAM) {
pFormStream = (CPDF_Stream*)pFormDircetObj;
}
} else if (pFormPDFObj->GetType() == PDFOBJ_STREAM) {
pFormStream = (CPDF_Stream*)pFormPDFObj;
}
}
if (iDataSetsIndex != -1) {
// Get datasets CPDF_Stream
CPDF_Object* pDataSetsPDFObj = pArray->GetElement(iDataSetsIndex);
if (pDataSetsPDFObj->GetType() == PDFOBJ_REFERENCE) {
CPDF_Reference* pDataSetsRefObj = (CPDF_Reference*)pDataSetsPDFObj;
CPDF_Object* pDataSetsDircetObj = pDataSetsRefObj->GetDirect();
if (NULL != pDataSetsDircetObj &&
pDataSetsDircetObj->GetType() == PDFOBJ_STREAM) {
pDataSetsStream = (CPDF_Stream*)pDataSetsDircetObj;
}
} else if (pDataSetsPDFObj->GetType() == PDFOBJ_STREAM) {
pDataSetsStream = (CPDF_Stream*)pDataSetsPDFObj;
}
}
// end
// L"datasets"
{
IFX_FileStream* pDsfileWrite = FX_CreateMemoryStream();
if (NULL == pDsfileWrite) {
pContext->Release();
pDsfileWrite->Release();
return FALSE;
}
if (pXFADocHandler->SavePackage(pXFADocView->GetDoc(),
CFX_WideStringC(L"datasets"),
pDsfileWrite) &&
pDsfileWrite->GetSize() > 0) {
// Datasets
pContext->UpdateChecksum((IFX_FileRead*)pDsfileWrite);
pContext->FinishChecksum();
CPDF_Dictionary* pDataDict = new CPDF_Dictionary;
if (iDataSetsIndex != -1) {
if (pDataSetsStream)
pDataSetsStream->InitStreamFromFile(pDsfileWrite, pDataDict);
} else {
CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL);
pData->InitStreamFromFile(pDsfileWrite, pDataDict);
pPDFDocument->AddIndirectObject(pData);
iLast = pArray->GetCount() - 2;
pArray->InsertAt(iLast, new CPDF_String("datasets", FALSE));
pArray->InsertAt(iLast + 1, pData, pPDFDocument);
}
fileList.Add(pDsfileWrite);
}
}
// L"form"
{
IFX_FileStream* pfileWrite = FX_CreateMemoryStream();
if (NULL == pfileWrite) {
pContext->Release();
return FALSE;
}
if (pXFADocHandler->SavePackage(pXFADocView->GetDoc(),
CFX_WideStringC(L"form"), pfileWrite,
pContext) &&
pfileWrite > 0) {
CPDF_Dictionary* pDataDict = new CPDF_Dictionary;
if (iFormIndex != -1) {
if (pFormStream)
pFormStream->InitStreamFromFile(pfileWrite, pDataDict);
} else {
CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL);
pData->InitStreamFromFile(pfileWrite, pDataDict);
pPDFDocument->AddIndirectObject(pData);
iLast = pArray->GetCount() - 2;
pArray->InsertAt(iLast, new CPDF_String("form", FALSE));
pArray->InsertAt(iLast + 1, pData, pPDFDocument);
}
fileList.Add(pfileWrite);
}
}
pContext->Release();
return TRUE;
}