From 8a89a05b32850a02cc60c8d3b913272c8be7cebd Mon Sep 17 00:00:00 2001 From: Kulikova Svetlana Date: Fri, 17 Mar 2023 17:43:57 +0300 Subject: [PATCH] Create graphics widgets --- .../graphics/pro/js/wasm/src/drawingfile.cpp | 9 ++-- .../graphics/pro/js/wasm/src/drawingfile.h | 4 +- PdfFile/PdfFile.cpp | 8 ++-- PdfFile/PdfFile.h | 2 +- PdfFile/PdfReader.cpp | 41 ++++++++++++++----- PdfFile/PdfReader.h | 6 ++- 6 files changed, 45 insertions(+), 25 deletions(-) diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp index f5228c3d25..02b44ceabb 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp @@ -150,9 +150,9 @@ WASM_EXPORT BYTE* GetStructure(CGraphicsFileDrawing* pGraphics) { return pGraphics->GetStructure(); } -WASM_EXPORT BYTE* GetInteractiveForms(CGraphicsFileDrawing* pGraphics) +WASM_EXPORT BYTE* GetInteractiveForms(CGraphicsFileDrawing* pGraphics, int nPageIndex, int nRasterW, int nRasterH) { - return pGraphics->GetInteractiveForms(); + return pGraphics->GetInteractiveForms(nPageIndex, nRasterW, nRasterH); } WASM_EXPORT void DestroyTextInfo(CGraphicsFileDrawing* pGraphics) { @@ -374,7 +374,7 @@ int main(int argc, char* argv[]) // INTERACTIVE FORMS if (true) { - BYTE* pWidgets = GetInteractiveForms(pGrFile); + BYTE* pWidgets = GetInteractiveForms(pGrFile, nTestPage, nWidth, nHeight); nLength = READ_INT(pWidgets); DWORD i = 4; nLength -= 4; @@ -389,9 +389,6 @@ int main(int argc, char* argv[]) i += nPathLength; nPathLength = READ_INT(pWidgets + i); i += 4; - std::cout << "Page " << nPathLength << ", "; - nPathLength = READ_INT(pWidgets + i); - i += 4; std::cout << "X1 " << (double)nPathLength / 100.0 << ", "; nPathLength = READ_INT(pWidgets + i); i += 4; diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h index baf838090c..3f23047e36 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h @@ -110,10 +110,10 @@ public: { return pReader->GetStructure(); } - BYTE* GetInteractiveForms() + BYTE* GetInteractiveForms(int nPageIndex, int nRasterW, int nRasterH) { if (nType == 0) - return ((CPdfFile*)pReader)->GetWidgets(); + return ((CPdfFile*)pReader)->GetWidgets(nPageIndex, nRasterW, nRasterH); return NULL; } std::wstring GetInfo() diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 3c5bfde467..ef20da0d34 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -702,7 +702,7 @@ void CPdfFile::SetCMapFile(const std::wstring& sFile) bool CPdfFile::LoadFromFile(const std::wstring& file, const std::wstring& options, const std::wstring& owner_password, const std::wstring& user_password) { - m_pInternal->pReader = new CPdfReader(m_pInternal->pAppFonts); + m_pInternal->pReader = new CPdfReader(m_pInternal->pAppFonts, this); if (!m_pInternal->pReader) return false; m_pInternal->wsSrcFile = file; @@ -713,7 +713,7 @@ bool CPdfFile::LoadFromFile(const std::wstring& file, const std::wstring& option } bool CPdfFile::LoadFromMemory(BYTE* data, DWORD length, const std::wstring& options, const std::wstring& owner_password, const std::wstring& user_password) { - m_pInternal->pReader = new CPdfReader(m_pInternal->pAppFonts); + m_pInternal->pReader = new CPdfReader(m_pInternal->pAppFonts, this); if (!m_pInternal->pReader) return false; m_pInternal->wsSrcFile = L""; @@ -811,11 +811,11 @@ BYTE* CPdfFile::GetLinks(int nPageIndex) return NULL; return m_pInternal->pReader->GetLinks(nPageIndex); } -BYTE* CPdfFile::GetWidgets() +BYTE* CPdfFile::GetWidgets(int nPageIndex, int nRasterW, int nRasterH) { if (!m_pInternal->pReader) return NULL; - return m_pInternal->pReader->GetWidgets(); + return m_pInternal->pReader->GetWidgets(nPageIndex, nRasterW, nRasterH); } // ------------------------------------------------------------------------ diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index 541622546a..cd7a9f908a 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -124,7 +124,7 @@ public: virtual std::wstring GetInfo(); virtual BYTE* GetStructure(); virtual BYTE* GetLinks(int nPageIndex); - BYTE* GetWidgets(); + BYTE* GetWidgets(int nPageIndex, int nRasterW, int nRasterH); // --- WRITER --- diff --git a/PdfFile/PdfReader.cpp b/PdfFile/PdfReader.cpp index 8be32a4756..5515f78561 100644 --- a/PdfFile/PdfReader.cpp +++ b/PdfFile/PdfReader.cpp @@ -55,8 +55,9 @@ #include -CPdfReader::CPdfReader(NSFonts::IApplicationFonts* pAppFonts) +CPdfReader::CPdfReader(NSFonts::IApplicationFonts* pAppFonts, IOfficeDrawingFile* pRenderer) { + m_pRenderer = pRenderer; m_wsTempFolder = L""; m_pPDFDocument = NULL; m_nFileLength = 0; @@ -717,7 +718,7 @@ BYTE* CPdfReader::GetLinks(int nPageIndex) return oLinks.Serialize(); } -BYTE* CPdfReader::GetWidgets() +BYTE* CPdfReader::GetWidgets(int nPageIndex, int nRasterW, int nRasterH) { if (!m_pPDFDocument || !m_pPDFDocument->getCatalog()) return NULL; @@ -726,6 +727,29 @@ BYTE* CPdfReader::GetWidgets() if (!pAcroForms) return NULL; + GBool bDrawContent = globalParams->getDrawContent(); + GBool bDrawAnnotations = globalParams->getDrawAnnotations(); + GBool bDrawFormFileds = globalParams->getDrawFormFields(); + + globalParams->setDrawContent(gFalse); + globalParams->setDrawAnnotations(gFalse); + globalParams->setDrawFormFields(gTrue); + + BYTE* pPixData = m_pRenderer->ConvertToPixels(nPageIndex, nRasterW, nRasterH, true, m_pFontManager, 0, false); + + globalParams->setDrawContent(bDrawContent); + globalParams->setDrawAnnotations(bDrawAnnotations); + globalParams->setDrawFormFields(bDrawFormFileds); + + CBgraFrame oFrame; + oFrame.put_Data(pPixData); + oFrame.put_Width(nRasterW); + oFrame.put_Height(nRasterH); + oFrame.put_Stride(4 * nRasterW); + oFrame.put_IsRGBA(true); + oFrame.SaveFile(NSFile::GetProcessDirectory() + L"/res2.png", _CXIMAGE_FORMAT_PNG); + oFrame.ClearNoAttack(); + NSWasm::CData oRes; oRes.SkipLen(); @@ -734,7 +758,7 @@ BYTE* CPdfReader::GetWidgets() AcroFormField* pField = pAcroForms->getField(i); Object oFieldRef, oField; XRef* xref = m_pPDFDocument->getXRef(); - if (!xref || !pField->getFieldRef(&oFieldRef) || !oFieldRef.isRef() || !oFieldRef.fetch(xref, &oField) || !oField.isDict()) + if (!xref || !pField->getFieldRef(&oFieldRef) || !oFieldRef.isRef() || !oFieldRef.fetch(xref, &oField) || !oField.isDict() || pField->getPageNum() != nPageIndex + 1) { oFieldRef.free(); oField.free(); continue; @@ -755,14 +779,10 @@ BYTE* CPdfReader::GetWidgets() oRes.WriteString((BYTE*)sTName.c_str(), (unsigned int)sTName.length()); gfree(uName); - // Номер страницы - P - int nPage = pField->getPageNum(); - oRes.AddInt(nPage - 1); - // Координаты - BBox double dx1, dy1, dx2, dy2; pField->getBBox(&dx1, &dy1, &dx2, &dy2); - double height = m_pPDFDocument->getPageCropHeight(nPage); + double height = m_pPDFDocument->getPageCropHeight(nPageIndex + 1); oRes.AddDouble(dx1); oRes.AddDouble(height - dy1); oRes.AddDouble(dx2); @@ -801,8 +821,8 @@ BYTE* CPdfReader::GetWidgets() // pField->getColor(&r, &g, &b); // Шрифт и размер шрифта - операторы Tf и Tm в DA - // Ref pFontRef; double dFontSize; - // pField->getFont(&pFontRef, &dFontSize); + Ref pFontRef; double dFontSize; + pField->getFont(&pFontRef, &dFontSize); // Флаг - Ff unsigned int nFieldFlag = pField->getFlags(); @@ -1382,6 +1402,7 @@ oObj.free();\ oRes.AddInt(nFlags, nFlagPos); } + RELEASEARRAYOBJECTS(pPixData); oRes.WriteLen(); BYTE* bRes = oRes.GetBuffer(); oRes.ClearWithoutAttack(); diff --git a/PdfFile/PdfReader.h b/PdfFile/PdfReader.h index eb105fc73a..6308abdd5a 100644 --- a/PdfFile/PdfReader.h +++ b/PdfFile/PdfReader.h @@ -34,6 +34,7 @@ #include "../../DesktopEditor/graphics/pro/Fonts.h" #include "../../DesktopEditor/graphics/IRenderer.h" +#include "../../DesktopEditor/graphics/pro/officedrawingfile.h" #include "SrcReader/RendererOutputDev.h" class PDFDoc; @@ -41,7 +42,7 @@ class CPdfReader { public: - CPdfReader(NSFonts::IApplicationFonts* pAppFonts); + CPdfReader(NSFonts::IApplicationFonts* pAppFonts, IOfficeDrawingFile* pRenderer); ~CPdfReader(); bool LoadFromFile (NSFonts::IApplicationFonts* pAppFonts, const std::wstring& file, const std::wstring& owner_password = L"", const std::wstring& user_password = L""); @@ -69,9 +70,10 @@ public: BYTE* GetStructure(); BYTE* GetLinks(int nPageIndex); - BYTE* GetWidgets(); + BYTE* GetWidgets(int nPageIndex, int nRasterW, int nRasterH); private: + IOfficeDrawingFile* m_pRenderer; PDFDoc* m_pPDFDocument; std::wstring m_wsTempFolder; NSFonts::IFontManager* m_pFontManager;