mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
fix SignatureField name
This commit is contained in:
@ -95,10 +95,10 @@ namespace PdfReader
|
||||
}
|
||||
typeDict.free();
|
||||
|
||||
std::wstring sPageTree = XMLConverter::DictToXml(L"PageTree", &pagesObj);
|
||||
Ref topPagesRef = pPagesRefObj->getRef();
|
||||
std::wstring sPageTree = XMLConverter::DictToXml(L"PageTree", &pagesObj, topPagesRef.num, topPagesRef.gen);
|
||||
|
||||
m_pPdfWriter->CreatePageTree(sPageTree, std::make_pair(topPagesRef.num, topPagesRef.gen));
|
||||
m_pPdfWriter->CreatePageTree(sPageTree, topPagesRef.num);
|
||||
|
||||
Object kidsArrObj;
|
||||
if (!pagesObj.dictLookup("Kids", &kidsArrObj) || !kidsArrObj.isArray())
|
||||
@ -524,13 +524,33 @@ return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wstring sCatalog = XMLConverter::DictToXml(L"Catalog", &catDict);
|
||||
Ref catRef = catRefObj.getRef();
|
||||
std::wstring sCatalog = XMLConverter::DictToXml(L"Catalog", &catDict, catRef.num, catRef.gen);
|
||||
|
||||
unsigned int nFormField = 0;
|
||||
AcroForm* form = m_pInternal->m_pPDFDocument->getCatalog()->getForm();
|
||||
if (form)
|
||||
nFormField = form->getNumFields();
|
||||
{
|
||||
nFormField = form->getNumFields() + 1;
|
||||
std::wstring sSig = L"Sig" + std::to_wstring(nFormField);
|
||||
int i = 0, nFormFields = form->getNumFields();
|
||||
while (i < nFormFields)
|
||||
{
|
||||
int nLength;
|
||||
Unicode* uName = form->getField(i)->getName(&nLength);
|
||||
std::wstring sName = NSStringExt::CConverter::GetUnicodeFromUTF32(uName, nLength);
|
||||
RELEASEMEM(uName);
|
||||
if (sName == sSig)
|
||||
{
|
||||
i = 0;
|
||||
nFormField++;
|
||||
sSig = L"Sig" + std::to_wstring(nFormField);
|
||||
}
|
||||
else
|
||||
i++;
|
||||
}
|
||||
nFormField--;
|
||||
}
|
||||
|
||||
int nCryptAlgorithm = -1;
|
||||
std::wstring sEncrypt;
|
||||
@ -557,7 +577,7 @@ return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool bRes = m_pInternal->m_pPdfWriter->EditPdf(xref->getLastXRefPos(), xref->getNumObjects(), sCatalog, std::make_pair(catRef.num, catRef.gen), sEncrypt, sPassword, nCryptAlgorithm, nFormField);
|
||||
bool bRes = m_pInternal->m_pPdfWriter->EditPdf(xref->getLastXRefPos(), xref->getNumObjects(), sCatalog, catRef.num, sEncrypt, sPassword, nCryptAlgorithm, nFormField);
|
||||
if (bRes)
|
||||
m_pInternal->GetPageTree(xref, &pagesRefObj);
|
||||
pagesRefObj.free();
|
||||
@ -586,11 +606,11 @@ return 0;
|
||||
pageRefObj.free();
|
||||
return false;
|
||||
}
|
||||
std::wstring sPage = XMLConverter::DictToXml(L"Page", &pageObj);
|
||||
std::wstring sPage = XMLConverter::DictToXml(L"Page", &pageObj, pPageRef.first, pPageRef.second);
|
||||
pageObj.free();
|
||||
pageRefObj.free();
|
||||
|
||||
return m_pInternal->m_pPdfWriter->EditPage(sPage, pPageRef);
|
||||
return m_pInternal->m_pPdfWriter->EditPage(sPage, pPageRef.first);
|
||||
}
|
||||
bool CPdfReader::DeletePage(int nPageIndex)
|
||||
{
|
||||
|
||||
@ -410,9 +410,14 @@ void DictToXmlR(Object* obj, std::wstring& wsXml, bool bBinary)
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring XMLConverter::DictToXml(const std::wstring& wsName, Object* obj, bool bBinary)
|
||||
std::wstring XMLConverter::DictToXml(const std::wstring& wsName, Object* obj, int nNum, int nGen, bool bBinary)
|
||||
{
|
||||
std::wstring sRes = L"<" + wsName;
|
||||
if (nNum)
|
||||
{
|
||||
sRes += (L" num=\"" + std::to_wstring(nNum) + L"\"");
|
||||
sRes += (L" gen=\"" + std::to_wstring(nGen) + L"\"");
|
||||
}
|
||||
DictToXmlR(obj, sRes, bBinary);
|
||||
sRes += (L"</" + wsName + L">");
|
||||
return sRes;
|
||||
|
||||
@ -135,7 +135,7 @@ public:
|
||||
static void XRefToXml(XRef &xref, std::wstring &wsXml, bool parse_streams);
|
||||
static void StreamDictToXml(Dict *dict, std::wstring &wsXml);
|
||||
static void ObjectToXml(Object *obj, std::wstring &wsXml);
|
||||
static std::wstring DictToXml(const std::wstring& wsName, Object* obj, bool bBinary = false);
|
||||
static std::wstring DictToXml(const std::wstring& wsName, Object* obj, int nNum = 0, int nGen = 0, bool bBinary = false);
|
||||
|
||||
static void AppendStringToXml(std::wstring& wsXml, const std::string& sString)
|
||||
{
|
||||
|
||||
@ -535,8 +535,6 @@ CPdfRenderer::CPdfRenderer(NSFonts::IApplicationFonts* pAppFonts, bool isPDFA) :
|
||||
m_pPage = NULL;
|
||||
m_pFont = NULL;
|
||||
|
||||
m_nCounter = 0;
|
||||
|
||||
m_bNeedUpdateTextFont = true;
|
||||
m_bNeedUpdateTextColor = true;
|
||||
m_bNeedUpdateTextAlpha = true;
|
||||
@ -2035,7 +2033,7 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo)
|
||||
|
||||
pField->SetAppearance(pImage);
|
||||
|
||||
// TODO
|
||||
// TODO Реализовать, когда появится поддержка CSignatureField
|
||||
pField->SetCert();
|
||||
}
|
||||
|
||||
@ -2113,34 +2111,34 @@ HRESULT CPdfRenderer::DrawImageWith1bppMask(IGrObject* pImage, NSImages::CPixJbi
|
||||
m_pPage->GrRestore();
|
||||
return S_OK;
|
||||
}
|
||||
bool CPdfRenderer::EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, const std::pair<int, int>& pCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm, int nFormField)
|
||||
bool CPdfRenderer::EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, int nCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm, int nFormField)
|
||||
{
|
||||
bool bRes = m_pDocument->EditPdf(nPosLastXRef, nSizeXRef, sCatalog, pCatalog, sEncrypt, sPassword, nCryptAlgorithm, nFormField);
|
||||
bool bRes = m_pDocument->EditPdf(nPosLastXRef, nSizeXRef, sCatalog, nCatalog, sEncrypt, sPassword, nCryptAlgorithm, nFormField);
|
||||
if (bRes)
|
||||
{
|
||||
m_bEdit = true;
|
||||
}
|
||||
return bRes;
|
||||
}
|
||||
bool CPdfRenderer::CreatePageTree(const std::wstring& sPageTree, const std::pair<int, int>& pPageTree)
|
||||
bool CPdfRenderer::CreatePageTree(const std::wstring& sPageTree, int nPageTree)
|
||||
{
|
||||
if (!m_bEdit)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_pDocument->CreatePageTree(sPageTree, pPageTree);
|
||||
return m_pDocument->CreatePageTree(sPageTree, nPageTree);
|
||||
}
|
||||
std::pair<int, int> CPdfRenderer::GetPageRef(int nPageIndex)
|
||||
{
|
||||
return m_pDocument->GetPageRef(nPageIndex);
|
||||
}
|
||||
bool CPdfRenderer::EditPage(const std::wstring& sPage, const std::pair<int, int>& pPage)
|
||||
bool CPdfRenderer::EditPage(const std::wstring& sPage, int nPage)
|
||||
{
|
||||
if (!IsValid() || !m_bEdit)
|
||||
return false;
|
||||
m_oCommandManager.Flush();
|
||||
|
||||
m_pPage = m_pDocument->EditPage(sPage, pPage);
|
||||
m_pPage = m_pDocument->EditPage(sPage, nPage);
|
||||
if (m_pPage)
|
||||
{
|
||||
m_dPageWidth = PT_2_MM(m_pPage->GetWidth());
|
||||
|
||||
@ -232,10 +232,10 @@ public:
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Дополнительные функции для дозаписи Pdf
|
||||
//----------------------------------------------------------------------------------------
|
||||
bool EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, const std::pair<int, int>& pCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm, int nFormField);
|
||||
bool CreatePageTree(const std::wstring& sPageTree, const std::pair<int, int>& pPageTree);
|
||||
bool EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, int nCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm, int nFormField);
|
||||
bool CreatePageTree(const std::wstring& sPageTree, int nPageTree);
|
||||
std::pair<int, int> GetPageRef(int nPageIndex);
|
||||
bool EditPage(const std::wstring& sPage, const std::pair<int, int>& pPage);
|
||||
bool EditPage(const std::wstring& sPage, int nPage);
|
||||
bool AddPage(int nPageIndex);
|
||||
bool DeletePage(int nPageIndex);
|
||||
bool EditClose(const std::wstring& wsPath, const std::wstring& sTrailer, const std::wstring& sInfo);
|
||||
@ -1873,8 +1873,6 @@ private:
|
||||
bool m_bValid;
|
||||
bool m_bEdit;
|
||||
bool m_bEditPage;
|
||||
|
||||
int m_nCounter; // TODO: для теста, убрать потом
|
||||
};
|
||||
|
||||
#endif // _PDF_WRITER_PDFRENDERER_H
|
||||
|
||||
@ -52,7 +52,6 @@
|
||||
|
||||
#include "../../DesktopEditor/agg-2.4/include/agg_span_hatch.h"
|
||||
#include "../../DesktopEditor/common/SystemUtils.h"
|
||||
#include "../../Common/DocxFormat/Source/Base/Base.h"
|
||||
|
||||
#ifdef CreateFont
|
||||
#undef CreateFont
|
||||
@ -1087,7 +1086,7 @@ namespace PdfWriter
|
||||
|
||||
return (!!m_pAcroForm);
|
||||
}
|
||||
bool CDocument::EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, const std::pair<int, int>& pCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm, int nFormField)
|
||||
bool CDocument::EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, int nCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm, int nFormField)
|
||||
{
|
||||
Close();
|
||||
|
||||
@ -1103,13 +1102,12 @@ namespace PdfWriter
|
||||
|
||||
SetCompressionMode(COMP_ALL);
|
||||
|
||||
CXref* pXref = new CXref(this, pCatalog.first);
|
||||
CXref* pXref = new CXref(this, nCatalog);
|
||||
if (!pXref)
|
||||
return false;
|
||||
m_pCatalog = new CCatalog(pXref, sCatalog);
|
||||
if (!m_pCatalog)
|
||||
return false;
|
||||
m_pCatalog->SetRef(pCatalog.first, pCatalog.second);
|
||||
pXref->SetPrev(m_pLastXref);
|
||||
m_pLastXref = pXref;
|
||||
|
||||
@ -1137,9 +1135,9 @@ namespace PdfWriter
|
||||
m_unFormFields = nFormField;
|
||||
return true;
|
||||
}
|
||||
bool CDocument::CreatePageTree(const std::wstring& sPageTree, const std::pair<int, int>& pPageTree)
|
||||
bool CDocument::CreatePageTree(const std::wstring& sPageTree, int nPageTree)
|
||||
{
|
||||
CXref* pXref = new CXref(this, pPageTree.first);
|
||||
CXref* pXref = new CXref(this, nPageTree);
|
||||
if (!pXref)
|
||||
return false;
|
||||
|
||||
@ -1151,8 +1149,6 @@ namespace PdfWriter
|
||||
m_pPageTree = pPageT;
|
||||
else
|
||||
m_pPageTree->Join(pPageT);
|
||||
|
||||
pPageT->SetRef(pPageTree.first, pPageTree.second);
|
||||
pXref->SetPrev(m_pLastXref);
|
||||
m_pLastXref = pXref;
|
||||
|
||||
@ -1173,11 +1169,10 @@ namespace PdfWriter
|
||||
|
||||
return pRes;
|
||||
}
|
||||
CPage* CDocument::EditPage(const std::wstring& sPage, const std::pair<int, int>& pPage)
|
||||
CPage* CDocument::EditPage(const std::wstring& sPage, int nPage)
|
||||
{
|
||||
CXref* pXref = new CXref(this, pPage.first);
|
||||
CXref* pXref = new CXref(this, nPage);
|
||||
CPage* pNewPage = new CPage(pXref, this, sPage);
|
||||
pNewPage->SetRef(pPage.first, pPage.second);
|
||||
|
||||
pNewPage->AddContents(m_pXref);
|
||||
#ifndef FILTER_FLATE_DECODE_DISABLED
|
||||
|
||||
@ -152,10 +152,10 @@ namespace PdfWriter
|
||||
CSignatureField* CreateSignatureField();
|
||||
bool CheckFieldName(CFieldBase* pField, const std::string& sName);
|
||||
|
||||
bool EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, const std::pair<int, int>& pCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm, int nFormField);
|
||||
bool CreatePageTree(const std::wstring& sPageTree, const std::pair<int, int>& pPageTree);
|
||||
bool EditPdf(int nPosLastXRef, int nSizeXRef, const std::wstring& sCatalog, int nCatalog, const std::wstring& sEncrypt, const std::wstring& sPassword, int nCryptAlgorithm, int nFormField);
|
||||
bool CreatePageTree(const std::wstring& sPageTree, int nPageTree);
|
||||
std::pair<int, int> GetPageRef(int nPageIndex);
|
||||
CPage* EditPage(const std::wstring& sPage, const std::pair<int, int>& pPage);
|
||||
CPage* EditPage(const std::wstring& sPage, int nPage);
|
||||
CPage* AddPage(int nPageIndex);
|
||||
bool DeletePage(int nPageIndex);
|
||||
bool AddToFile(const std::wstring& wsPath, const std::wstring& sTrailer, const std::wstring& sInfo);
|
||||
|
||||
@ -253,7 +253,7 @@ namespace PdfWriter
|
||||
void SetContact(const std::wstring& wsValue);
|
||||
void SetReason(const std::wstring& wsValue);
|
||||
void SetPicture(const std::wstring& wsPath);
|
||||
void SetCert(); // TODO
|
||||
void SetCert();
|
||||
void SetDate(bool bDate);
|
||||
void SetAppearance(CImageDict* pImage = NULL);
|
||||
virtual CResourcesDict* GetResourcesDict();
|
||||
|
||||
@ -716,6 +716,21 @@ namespace PdfWriter
|
||||
XmlUtils::CXmlLiteReader oCoreReader;
|
||||
oCoreReader.FromString(sXml);
|
||||
oCoreReader.ReadNextNode();
|
||||
|
||||
int num = 0, gen = 0;
|
||||
while (oCoreReader.MoveToNextAttribute())
|
||||
{
|
||||
std::wstring sAName = oCoreReader.GetName();
|
||||
std::string sAText = oCoreReader.GetTextA();
|
||||
if (sAName == L"gen")
|
||||
gen = std::stoi(sAText);
|
||||
else if (sAName == L"num")
|
||||
num = std::stoi(sAText);
|
||||
}
|
||||
oCoreReader.MoveToElement();
|
||||
if (num)
|
||||
SetRef(num, gen);
|
||||
|
||||
int nDeath = oCoreReader.GetDepth();
|
||||
while (oCoreReader.ReadNextSiblingNode(nDeath))
|
||||
ReadDict(oCoreReader, this);
|
||||
|
||||
Reference in New Issue
Block a user