mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Prepare to write pdf
This commit is contained in:
@ -188,6 +188,10 @@ namespace NSOnlineOfficeBinToPdf
|
||||
ctPageStart = 202,
|
||||
ctPageEnd = 203,
|
||||
|
||||
ctDocumentEdit = 204,
|
||||
ctDocumentClose = 205,
|
||||
ctPageEdit = 206,
|
||||
|
||||
// gradients
|
||||
|
||||
ctGradientFill = 220,
|
||||
|
||||
@ -1001,7 +1001,7 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
// RASTER
|
||||
if (true && nPagesCount > 0)
|
||||
if (false && nPagesCount > 0)
|
||||
{
|
||||
BYTE* res = NULL;
|
||||
res = GetPixmap(pGrFile, nTestPage, nWidth, nHeight, 0xFFFFFF);
|
||||
@ -1085,10 +1085,11 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
// GLYPHS
|
||||
if (false && nPagesCount > 0)
|
||||
if (true && nPagesCount > 0)
|
||||
{
|
||||
// TODO:
|
||||
BYTE* pGlyphs = GetGlyphs(pGrFile, nTestPage);
|
||||
DestroyTextInfo(pGrFile);
|
||||
}
|
||||
|
||||
// INTERACTIVE FORMS
|
||||
|
||||
@ -622,7 +622,7 @@ bool CPdfFile::EditPage(int nPageIndex)
|
||||
{
|
||||
Object oTemp;
|
||||
char* chKey = pageObj.dictGetKey(nIndex);
|
||||
if (strcmp("Resources", chKey) == 0 || strcmp("AcroForm", chKey) == 0)
|
||||
if (strcmp("Resources", chKey) == 0 || strcmp("AcroForm", chKey) == 0 || strcmp("Annots", chKey) == 0)
|
||||
pageObj.dictGetVal(nIndex, &oTemp);
|
||||
else
|
||||
pageObj.dictGetValNF(nIndex, &oTemp);
|
||||
@ -803,6 +803,17 @@ int CPdfFile::GetRotate(int nPageIndex)
|
||||
{
|
||||
if (!m_pInternal->pReader)
|
||||
return 0;
|
||||
#ifndef BUILDING_WASM_MODULE
|
||||
if (m_pInternal->bEdit && m_pInternal->pWriter && m_pInternal->pWriter->m_pDocument)
|
||||
{
|
||||
PdfWriter::CPage* pPage = m_pInternal->pWriter->m_pDocument->GetPage(nPageIndex);
|
||||
if (!pPage)
|
||||
return 0;
|
||||
|
||||
return pPage->GetRotate();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
return m_pInternal->pReader->GetRotate(nPageIndex);
|
||||
}
|
||||
void CPdfFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak)
|
||||
|
||||
@ -1678,6 +1678,7 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
||||
|
||||
CAnnotFieldInfo& oInfo = *pFieldInfo;
|
||||
|
||||
// TODO внести Widget в PdfWriter::CAnnotation
|
||||
if (oInfo.isWidget())
|
||||
return AddFormField(pAppFonts, (CFormFieldInfo*)pFieldInfo);
|
||||
|
||||
@ -1729,11 +1730,14 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
||||
if (!pAnnot)
|
||||
return S_FALSE;
|
||||
|
||||
PdfWriter::CPage* pPage = m_pDocument->GetPage(oInfo.GetPage());
|
||||
pPage->AddAnnotation(pAnnot);
|
||||
|
||||
int nID = oInfo.GetID();
|
||||
pAnnot->SetID(nID);
|
||||
|
||||
PdfWriter::CPage* pPage = m_pDocument->GetPage(oInfo.GetPage());
|
||||
if (!pPage)
|
||||
pPage = m_pPage;
|
||||
pPage->AddAnnotation(pAnnot, nID);
|
||||
|
||||
m_pDocument->AddAnnotation(nID, pAnnot);
|
||||
|
||||
pAnnot->SetAnnotFlag(oInfo.GetAnnotFlag());
|
||||
@ -1741,7 +1745,7 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
||||
|
||||
double dX1, dY1, dX2, dY2;
|
||||
oInfo.GetBounds(dX1, dY1, dX2, dY2);
|
||||
PdfWriter::TRect oRect(MM_2_PT(dX1), pPage->GetHeight() - MM_2_PT(dY1), MM_2_PT(dX2), pPage->GetHeight() - MM_2_PT(dY2));
|
||||
PdfWriter::TRect oRect(dX1, pPage->GetHeight() - dY1, dX2, pPage->GetHeight() - dY2);
|
||||
pAnnot->SetRect(oRect);
|
||||
|
||||
int nFlags = oInfo.GetFlag();
|
||||
|
||||
@ -97,9 +97,9 @@ namespace PdfWriter
|
||||
protected:
|
||||
CAnnotation(CXref* pXref, EAnnotType eType);
|
||||
|
||||
public:
|
||||
int m_nID; // Идентификатор сопоставления
|
||||
|
||||
public:
|
||||
EDictType GetDictType() const
|
||||
{
|
||||
return dict_type_ANNOTATION;
|
||||
|
||||
@ -1125,7 +1125,7 @@ namespace PdfWriter
|
||||
|
||||
return sKey;
|
||||
}
|
||||
void CPage::AddAnnotation(CDictObject* pAnnot)
|
||||
void CPage::AddAnnotation(CDictObject* pAnnot, unsigned int nID)
|
||||
{
|
||||
CArrayObject* pArray = (CArrayObject*)Get("Annots");
|
||||
if (!pArray)
|
||||
@ -1136,6 +1136,21 @@ namespace PdfWriter
|
||||
|
||||
Add("Annots", pArray);
|
||||
}
|
||||
|
||||
if (nID)
|
||||
{
|
||||
for (int i = 0; i < pArray->GetCount(); i++)
|
||||
{
|
||||
CObjectBase* pObj = pArray->Get(i, false);
|
||||
if (pObj->GetType() == object_type_PROXY && ((CProxyObject*)pObj)->Get()->GetObjId() == nID)
|
||||
{
|
||||
CObjectBase* pDelete = pArray->Remove(i);
|
||||
RELEASEOBJECT(pDelete);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return pArray->Add(pAnnot);
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ namespace PdfWriter
|
||||
void Concat(double dM11, double dM12, double dM21, double dM22, double dX, double dY);
|
||||
void SetTransform(double dM11, double dM12, double dM21, double dM22, double dX, double dY);
|
||||
void SetExtGrState(CExtGrState* pExtGrState);
|
||||
void AddAnnotation(CDictObject* pAnnot);
|
||||
void AddAnnotation(CDictObject* pAnnot, unsigned int nID = 0);
|
||||
void DrawShading(CShading* pShading);
|
||||
void SetStrokeAlpha(unsigned char unAlpha);
|
||||
void SetFillAlpha(unsigned char unAlpha);
|
||||
|
||||
@ -34,6 +34,7 @@
|
||||
#include "../../DesktopEditor/fontengine/ApplicationFontsWorker.h"
|
||||
#include "../../DesktopEditor/xmlsec/src/include/CertificateCommon.h"
|
||||
#include "../../DesktopEditor/graphics/MetafileToGraphicsRenderer.h"
|
||||
#include "../../DesktopEditor/graphics/commands/AnnotField.h"
|
||||
#include "../PdfFile.h"
|
||||
|
||||
void TEST(IRenderer* pRenderer)
|
||||
@ -154,7 +155,7 @@ int main()
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (true)
|
||||
if (false)
|
||||
{
|
||||
double dPageDpiX, dPageDpiY, dWidth, dHeight;
|
||||
int i = 0;
|
||||
@ -212,25 +213,73 @@ int main()
|
||||
pdfFile.Sign(0, 0, 0, 0, L"", pCertificate);
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (true)
|
||||
{
|
||||
if (pdfFile.EditPage(0))
|
||||
{
|
||||
CAnnotFieldInfo* pInfo = new CAnnotFieldInfo();
|
||||
|
||||
pInfo->SetType(8);
|
||||
pInfo->SetID(80);
|
||||
pInfo->SetAnnotFlag(4);
|
||||
pInfo->SetPage(0); // та что в EditPage
|
||||
|
||||
pInfo->SetBounds(42, 660, 145, 677);
|
||||
|
||||
pInfo->SetFlag(8);
|
||||
|
||||
std::vector<double> arrC;
|
||||
arrC.push_back(1);
|
||||
arrC.push_back(0.4);
|
||||
arrC.push_back(0);
|
||||
pInfo->SetC(arrC);
|
||||
|
||||
CAnnotFieldInfo::CMarkupAnnotPr* pPrm = pInfo->GetMarkupAnnotPr();
|
||||
pPrm->SetFlag(4);
|
||||
|
||||
pPrm->SetCA(0.4);
|
||||
|
||||
CAnnotFieldInfo::CTextMarkupAnnotPr* pPr = pInfo->GetTextMarkupAnnotPr();
|
||||
pPr->SetSubtype(8);
|
||||
std::vector<double> arrQuadPoints;
|
||||
|
||||
arrQuadPoints.push_back(47);
|
||||
arrQuadPoints.push_back(676);
|
||||
|
||||
arrQuadPoints.push_back(140);
|
||||
arrQuadPoints.push_back(676);
|
||||
|
||||
arrQuadPoints.push_back(47);
|
||||
arrQuadPoints.push_back(660);
|
||||
|
||||
arrQuadPoints.push_back(140);
|
||||
arrQuadPoints.push_back(660);
|
||||
|
||||
pPr->SetQuadPoints(arrQuadPoints);
|
||||
|
||||
pdfFile.AdvancedCommand(pInfo);
|
||||
RELEASEOBJECT(pInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pdfFile.EditPage(0))
|
||||
{
|
||||
TEST(&pdfFile);
|
||||
pdfFile.RotatePage(90);
|
||||
TEST(&pdfFile);
|
||||
pdfFile.RotatePage(90);
|
||||
}
|
||||
|
||||
pdfFile.DeletePage(1);
|
||||
pdfFile.DeletePage(1);
|
||||
|
||||
if (pdfFile.EditPage(1))
|
||||
{
|
||||
TEST2(&pdfFile);
|
||||
}
|
||||
if (pdfFile.EditPage(1))
|
||||
{
|
||||
TEST2(&pdfFile);
|
||||
}
|
||||
|
||||
if (pdfFile.AddPage(3))
|
||||
{
|
||||
TEST3(&pdfFile);
|
||||
}
|
||||
if (pdfFile.AddPage(3))
|
||||
{
|
||||
TEST3(&pdfFile);
|
||||
}
|
||||
}
|
||||
|
||||
pdfFile.Close();
|
||||
|
||||
Reference in New Issue
Block a user