mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Split with changes
This commit is contained in:
@ -283,10 +283,10 @@ public:
|
||||
return NULL;
|
||||
return m_pFile->ConvertToPixels(nPageIndex, nRasterW, nRasterH, true, m_pFontManager, nBackgroundColor, (nBackgroundColor == 0xFFFFFF) ? false : true);
|
||||
}
|
||||
BYTE* SplitPages(int* arrPageIndex, int nLength)
|
||||
BYTE* SplitPages(int* arrPageIndex, int nLength, BYTE* data, LONG size)
|
||||
{
|
||||
if (m_nType == 0)
|
||||
return ((CPdfFile*)m_pFile)->SplitPages(arrPageIndex, nLength);
|
||||
return ((CPdfFile*)m_pFile)->SplitPages(arrPageIndex, nLength, data, size);
|
||||
return NULL;
|
||||
}
|
||||
bool MergePages(BYTE* data, LONG size, int nMaxID, const std::string& sPrefixForm)
|
||||
|
||||
@ -177,9 +177,9 @@ WASM_EXPORT BYTE* ScanPage(CDrawingFile* pFile, int nPageIndex, int mode)
|
||||
{
|
||||
return pFile->ScanPage(nPageIndex, mode);
|
||||
}
|
||||
WASM_EXPORT BYTE* SplitPages(CDrawingFile* pFile, int* arrPageIndex, int nLength)
|
||||
WASM_EXPORT BYTE* SplitPages(CDrawingFile* pFile, int* arrPageIndex, int nLength, BYTE* data, LONG size)
|
||||
{
|
||||
return pFile->SplitPages(arrPageIndex, nLength);
|
||||
return pFile->SplitPages(arrPageIndex, nLength, data, size);
|
||||
}
|
||||
WASM_EXPORT int MergePages(CDrawingFile* pFile, BYTE* data, LONG size, int nMaxID, const char* sPrefixForm)
|
||||
{
|
||||
|
||||
@ -1909,13 +1909,13 @@ bool CPdfEditor::SplitPages(const int* arrPageIndex, unsigned int unLength, PDFD
|
||||
|
||||
return true;
|
||||
}
|
||||
BYTE* CPdfEditor::SplitPages(const int* arrPageIndex, unsigned int unLength)
|
||||
bool CPdfEditor::SplitPages(const int* arrPageIndex, unsigned int unLength)
|
||||
{
|
||||
if (m_nMode != Mode::Unknown)
|
||||
return NULL;
|
||||
return false;
|
||||
PdfWriter::CDocument* pDoc = m_pWriter->GetDocument();
|
||||
if (!pDoc)
|
||||
return NULL;
|
||||
return false;
|
||||
|
||||
int nTotalPages = 0;
|
||||
int nPDFIndex = 0;
|
||||
@ -1941,26 +1941,9 @@ BYTE* CPdfEditor::SplitPages(const int* arrPageIndex, unsigned int unLength)
|
||||
{
|
||||
pPDFDocument = m_pReader->GetPDFDocument(it.first);
|
||||
if (!SplitPages(it.second.data(), it.second.size(), pPDFDocument, m_pReader->GetStartRefID(pPDFDocument)))
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
BYTE* pRes = NULL;
|
||||
int nLength = 0;
|
||||
if (m_pWriter->SaveToMemory(&pRes, &nLength) == 0)
|
||||
{
|
||||
NSWasm::CData oRes;
|
||||
oRes.SkipLen();
|
||||
|
||||
oRes.Write(pRes, nLength);
|
||||
RELEASEARRAYOBJECTS(pRes);
|
||||
|
||||
oRes.WriteLen();
|
||||
BYTE* bRes = oRes.GetBuffer();
|
||||
oRes.ClearWithoutAttack();
|
||||
return bRes;
|
||||
}
|
||||
RELEASEARRAYOBJECTS(pRes);
|
||||
return NULL;
|
||||
return true;
|
||||
}
|
||||
void CreateOutlines(PDFDoc* pdfDoc, PdfWriter::CDocument* pDoc, OutlineItem* pOutlineItem, PdfWriter::COutline* pParent)
|
||||
{
|
||||
|
||||
@ -93,7 +93,7 @@ public:
|
||||
void EndMarkedContent();
|
||||
bool IsBase14(const std::wstring& wsFontName, bool& bBold, bool& bItalic, std::wstring& wsFontPath);
|
||||
|
||||
BYTE* SplitPages(const int* arrPageIndex, unsigned int unLength);
|
||||
bool SplitPages(const int* arrPageIndex, unsigned int unLength);
|
||||
bool MergePages(const std::wstring& wsPath, const std::wstring& wsPrefixForm);
|
||||
|
||||
private:
|
||||
|
||||
@ -429,7 +429,7 @@ BYTE* CPdfFile::GetAnnots(int nPageIndex)
|
||||
return NULL;
|
||||
return m_pInternal->pReader->GetAnnots(nPageIndex);
|
||||
}
|
||||
BYTE* CPdfFile::SplitPages(const int* arrPageIndex, unsigned int unLength)
|
||||
BYTE* CPdfFile::SplitPages(const int* arrPageIndex, unsigned int unLength, BYTE* pChanges, DWORD nLength)
|
||||
{
|
||||
if (!m_pInternal->pReader)
|
||||
return NULL;
|
||||
@ -439,7 +439,13 @@ BYTE* CPdfFile::SplitPages(const int* arrPageIndex, unsigned int unLength)
|
||||
RELEASEOBJECT(m_pInternal->pEditor);
|
||||
m_pInternal->pEditor = new CPdfEditor(m_pInternal->wsSrcFile, m_pInternal->wsPassword, L"", m_pInternal->pReader, m_pInternal->pWriter);
|
||||
|
||||
BYTE* pRes = m_pInternal->pEditor->SplitPages(arrPageIndex, unLength);
|
||||
BYTE* pRes = NULL;
|
||||
int nLen = 0;
|
||||
if (m_pInternal->pEditor->SplitPages(arrPageIndex, unLength))
|
||||
{
|
||||
if (m_pInternal->pWriter->SaveToMemory(&pRes, &nLen, true) != 0)
|
||||
RELEASEMEM(pRes);
|
||||
}
|
||||
|
||||
RELEASEOBJECT(m_pInternal->pWriter);
|
||||
RELEASEOBJECT(m_pInternal->pEditor);
|
||||
|
||||
@ -135,7 +135,7 @@ public:
|
||||
BYTE* GetAnnotEmbeddedFonts();
|
||||
BYTE* GetAnnotStandardFonts();
|
||||
BYTE* GetAnnots (int nPageIndex = -1);
|
||||
BYTE* SplitPages (const int* arrPageIndex, unsigned int unLength);
|
||||
BYTE* SplitPages (const int* arrPageIndex, unsigned int unLength, BYTE* pChanges = NULL, DWORD nLength = 0);
|
||||
BYTE* VerifySign (const std::wstring& sFile, ICertificate* pCertificate, int nWidget = -1);
|
||||
BYTE* GetAPWidget (int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nWidget = -1, const char* sView = NULL, const char* sBView = NULL);
|
||||
BYTE* GetAPAnnots (int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nAnnot = -1, const char* sView = NULL);
|
||||
|
||||
@ -207,7 +207,7 @@ int CPdfWriter::SaveToFile(const std::wstring& wsPath)
|
||||
|
||||
return 0;
|
||||
}
|
||||
int CPdfWriter::SaveToMemory(BYTE** pData, int* pLength)
|
||||
int CPdfWriter::SaveToMemory(BYTE** pData, int* pLength, bool bEmbedLength)
|
||||
{
|
||||
// TODO: Переделать на код ошибки
|
||||
if (!IsValid())
|
||||
@ -215,7 +215,7 @@ int CPdfWriter::SaveToMemory(BYTE** pData, int* pLength)
|
||||
|
||||
m_oCommandManager.Flush();
|
||||
|
||||
if (!m_pDocument->SaveToMemory(pData, pLength))
|
||||
if (!m_pDocument->SaveToMemory(pData, pLength, bEmbedLength))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
||||
@ -67,7 +67,7 @@ public:
|
||||
CPdfWriter(NSFonts::IApplicationFonts* pAppFonts, bool isPDFA = false, IRenderer* pRenderer = NULL, bool bCreate = true);
|
||||
~CPdfWriter();
|
||||
int SaveToFile(const std::wstring& wsPath);
|
||||
int SaveToMemory(BYTE** pData, int* pLength);
|
||||
int SaveToMemory(BYTE** pData, int* pLength, bool bEmbedLength = false);
|
||||
void SetPassword(const std::wstring& wsPassword);
|
||||
void SetDocumentID(const std::wstring& wsDocumentID);
|
||||
void SetDocumentInfo(const std::wstring& wsTitle, const std::wstring& wsCreator, const std::wstring& wsSubject, const std::wstring& wsKeywords);
|
||||
|
||||
@ -236,7 +236,7 @@ namespace PdfWriter
|
||||
|
||||
return true;
|
||||
}
|
||||
bool CDocument::SaveToMemory(BYTE** pData, int* pLength)
|
||||
bool CDocument::SaveToMemory(BYTE** pData, int* pLength, bool bEmbedLength)
|
||||
{
|
||||
CMemoryStream* pStream = new CMemoryStream();
|
||||
if (!pStream)
|
||||
@ -245,10 +245,14 @@ namespace PdfWriter
|
||||
if (m_pJbig2)
|
||||
m_pJbig2->FlushStreams();
|
||||
|
||||
if (bEmbedLength)
|
||||
pStream->SkipLength();
|
||||
SaveToStream(pStream);
|
||||
|
||||
*pData = pStream->GetBuffer();
|
||||
*pLength = pStream->Size();
|
||||
if (bEmbedLength)
|
||||
pStream->WriteLength();
|
||||
pStream->ClearWithoutAttack();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ namespace PdfWriter
|
||||
bool CreateNew();
|
||||
void Close();
|
||||
bool SaveToFile(const std::wstring& wsPath);
|
||||
bool SaveToMemory(BYTE** pData, int* pLength);
|
||||
bool SaveToMemory(BYTE** pData, int* pLength, bool bEmbedLength);
|
||||
bool SaveNewWithPassword(CXref* pXref, CXref* _pXref, const std::wstring& wsPath, const std::wstring& wsOwnerPassword, const std::wstring& wsUserPassword, CDictObject* pTrailer);
|
||||
|
||||
void SetPasswords(const std::wstring & wsOwnerPassword, const std::wstring & wsUserPassword);
|
||||
|
||||
@ -826,6 +826,18 @@ namespace PdfWriter
|
||||
m_nBufferSize = unSize;
|
||||
}
|
||||
}
|
||||
void CMemoryStream::SkipLength()
|
||||
{
|
||||
Shrink(5);
|
||||
Seek(4, EWhenceMode::SeekSet);
|
||||
}
|
||||
void CMemoryStream::WriteLength()
|
||||
{
|
||||
unsigned int nLength = m_unSize - 4;
|
||||
Seek(0, EWhenceMode::SeekSet);
|
||||
std::memcpy(m_pCur, &nLength, sizeof(unsigned int));
|
||||
Seek(0, EWhenceMode::SeekEnd);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
// CFileStream
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
@ -161,6 +161,8 @@ namespace PdfWriter
|
||||
}
|
||||
BYTE* GetBuffer();
|
||||
void ClearWithoutAttack();
|
||||
void SkipLength();
|
||||
void WriteLength();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user