From db340198d632cca2517386464565dca0085a8088 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Thu, 29 Feb 2024 10:04:48 +0300 Subject: [PATCH] Create GetShapesXML --- .../graphics/commands/AnnotField.cpp | 2 +- DesktopEditor/graphics/commands/AnnotField.h | 5 ++++ .../graphics/pro/js/wasm/src/drawingfile.cpp | 4 ++++ .../graphics/pro/js/wasm/src/drawingfile.h | 6 +++++ PdfFile/PdfFile.cpp | 8 +++++++ PdfFile/PdfFile.h | 1 + PdfFile/PdfReader.cpp | 24 +++++++++++++++++++ PdfFile/PdfReader.h | 1 + PdfFile/PdfWriter.cpp | 5 ++++ PdfFile/PdfWriter.h | 1 + PdfFile/SrcWriter/Document.cpp | 18 ++++++++++++++ PdfFile/SrcWriter/Document.h | 1 + PdfFile/SrcWriter/Pages.cpp | 11 ++++++++- 13 files changed, 85 insertions(+), 2 deletions(-) diff --git a/DesktopEditor/graphics/commands/AnnotField.cpp b/DesktopEditor/graphics/commands/AnnotField.cpp index a2d112d18a..77b70a5345 100644 --- a/DesktopEditor/graphics/commands/AnnotField.cpp +++ b/DesktopEditor/graphics/commands/AnnotField.cpp @@ -882,7 +882,7 @@ bool CWidgetsInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafil CShapeStart::CShapeStart() : IAdvancedCommand(AdvancedCommandType::ShapeStart) {} bool CShapeStart::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector) { - std::string sShape = pReader->ReadStringA(); + m_sShapeXML = pReader->ReadStringA(); return true; } diff --git a/DesktopEditor/graphics/commands/AnnotField.h b/DesktopEditor/graphics/commands/AnnotField.h index 47a182327e..a402937f8d 100644 --- a/DesktopEditor/graphics/commands/AnnotField.h +++ b/DesktopEditor/graphics/commands/AnnotField.h @@ -529,7 +529,12 @@ class GRAPHICS_DECL CShapeStart : public IAdvancedCommand public: CShapeStart(); + const std::string& GetShapeXML() { return m_sShapeXML; } + bool Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector); + +private: + std::string m_sShapeXML; }; class GRAPHICS_DECL CShapeEnd : public IAdvancedCommand diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp index ccb252acb2..bb3e56f82a 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp @@ -243,6 +243,10 @@ WASM_EXPORT BYTE* GetFontBinary(CGraphicsFileDrawing* pGraphics, char* path) oRes.ClearWithoutAttack(); return bRes; } +WASM_EXPORT BYTE* GetShapesXML(CGraphicsFileDrawing* pGraphics, int nPageIndex) +{ + return pGraphics->GetShapesXML(nPageIndex); +} WASM_EXPORT void DestroyTextInfo(CGraphicsFileDrawing* pGraphics) { return pGraphics->DestroyText(); diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h index bcd36616c0..ca969e8beb 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h @@ -148,6 +148,12 @@ public: return ((CPdfFile*)pReader)->GetAnnots(nPageIndex); return NULL; } + BYTE* GetShapesXML(int nPageIndex) + { + if (nType == 0) + return ((CPdfFile*)pReader)->GetShapesXML(nPageIndex); + return NULL; + } BYTE* GetAPWidget (int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nWidget = -1, const char* sView = NULL, const char* sBView = NULL) { if (nType == 0) diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 7280c77854..7bcd6cca94 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -1580,6 +1580,12 @@ BYTE* CPdfFile::GetAnnots(int nPageIndex) return NULL; return m_pInternal->pReader->GetAnnots(nPageIndex); } +BYTE* CPdfFile::GetShapesXML(int nPageIndex) +{ + if (!m_pInternal->pReader) + return NULL; + return m_pInternal->pReader->GetShapes(nPageIndex); +} BYTE* CPdfFile::VerifySign(const std::wstring& sFile, ICertificate* pCertificate, int nWidget) { if (!m_pInternal->pReader) @@ -2365,6 +2371,8 @@ HRESULT CPdfFile::AdvancedCommand(IAdvancedCommand* command) } case IAdvancedCommand::AdvancedCommandType::ShapeStart: { + CShapeStart* pCommand = (CShapeStart*)command; + m_pInternal->pWriter->AddShapeXML(pCommand->GetShapeXML()); return S_OK; } case IAdvancedCommand::AdvancedCommandType::ShapeEnd: diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index 46c9a2aab4..cb444dcf65 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -134,6 +134,7 @@ public: BYTE* GetWidgetEmbeddedFonts(); BYTE* GetWidgetStandardFonts(); BYTE* GetAnnots (int nPageIndex = -1); + BYTE* GetShapesXML (int nPageIndex); 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); diff --git a/PdfFile/PdfReader.cpp b/PdfFile/PdfReader.cpp index 7d0c7c324a..b42299c6ad 100644 --- a/PdfFile/PdfReader.cpp +++ b/PdfFile/PdfReader.cpp @@ -1530,6 +1530,30 @@ BYTE* CPdfReader::GetAnnots(int nPageIndex) oRes.ClearWithoutAttack(); return bRes; } +BYTE* CPdfReader::GetShapes(int nPageIndex) +{ + if (!m_pPDFDocument || !m_pPDFDocument->getCatalog()) + return NULL; + Ref* pPageRef = m_pPDFDocument->getCatalog()->getPageRef(nPageIndex + 1); + if (!pPageRef) + return NULL; + + Object oPageObj; + XRef* xref = m_pPDFDocument->getXRef(); + if (!xref->fetch(pPageRef->num, pPageRef->gen, &oPageObj)->isDict()) + { + oPageObj.free(); + return NULL; + } + + NSWasm::CData oRes; + oRes.SkipLen(); + + oRes.WriteLen(); + BYTE* bRes = oRes.GetBuffer(); + oRes.ClearWithoutAttack(); + return bRes; +} BYTE* CPdfReader::GetAPAnnots(int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nAnnot, const char* sView) { if (!m_pPDFDocument || !m_pPDFDocument->getCatalog()) diff --git a/PdfFile/PdfReader.h b/PdfFile/PdfReader.h index 03a22536d0..50ed129191 100644 --- a/PdfFile/PdfReader.h +++ b/PdfFile/PdfReader.h @@ -76,6 +76,7 @@ public: BYTE* GetWidgets(); BYTE* GetWidgetFonts(int nTypeFonts); BYTE* GetAnnots(int nPageIndex = -1); + BYTE* GetShapes(int nPageIndex); 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); diff --git a/PdfFile/PdfWriter.cpp b/PdfFile/PdfWriter.cpp index 5ff8a24dc3..94d16e34e5 100644 --- a/PdfFile/PdfWriter.cpp +++ b/PdfFile/PdfWriter.cpp @@ -2345,6 +2345,11 @@ HRESULT CPdfWriter::AddMetaData(const std::wstring& sMetaName, BYTE* pMetaData, { return m_pDocument->AddMetaData(sMetaName, pMetaData, nMetaLength) ? S_OK : S_FALSE; } +HRESULT CPdfWriter::AddShapeXML(const std::string& sXML) +{ + m_pDocument->AddShapeXML(sXML); + return S_OK; +} //---------------------------------------------------------------------------------------- // Дополнительные функции Pdf рендерера //---------------------------------------------------------------------------------------- diff --git a/PdfFile/PdfWriter.h b/PdfFile/PdfWriter.h index ab64292c35..e0a970b613 100644 --- a/PdfFile/PdfWriter.h +++ b/PdfFile/PdfWriter.h @@ -198,6 +198,7 @@ public: HRESULT AddFormField (NSFonts::IApplicationFonts* pAppFonts, CFormFieldInfo* pFieldInfo, const std::wstring& wsTempDirectory); HRESULT AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotFieldInfo* pFieldInfo); HRESULT AddMetaData(const std::wstring& sMetaName, BYTE* pMetaData, DWORD nMetaLength); + HRESULT AddShapeXML(const std::string& sXML); //---------------------------------------------------------------------------------------- // Дополнительные функции Pdf рендерера //---------------------------------------------------------------------------------------- diff --git a/PdfFile/SrcWriter/Document.cpp b/PdfFile/SrcWriter/Document.cpp index 7310379f5b..f6bb3a064f 100644 --- a/PdfFile/SrcWriter/Document.cpp +++ b/PdfFile/SrcWriter/Document.cpp @@ -1688,4 +1688,22 @@ namespace PdfWriter RELEASEOBJECT(XRef); vXRefForWrite.clear(); } + void CDocument::AddShapeXML(const std::string& sXML) + { + CDictObject* pMetaOForm = m_pCurPage->GetMetaOForm(); + if (!pMetaOForm) + { + pMetaOForm = new CDictObject(); + m_pXref->Add(pMetaOForm); + pMetaOForm->Add("Type", "MetaOForm"); + m_pCurPage->SetMetaOForm(pMetaOForm); + } + CArrayObject* pArrayMeta = (CArrayObject*)pMetaOForm->Get("Medata"); + if (!pArrayMeta) + { + pArrayMeta = new CArrayObject(); + pMetaOForm->Add("Metadata", pArrayMeta); + } + pArrayMeta->Add(new CStringObject(sXML.c_str())); + } } diff --git a/PdfFile/SrcWriter/Document.h b/PdfFile/SrcWriter/Document.h index f8a1dbead2..baa1741732 100644 --- a/PdfFile/SrcWriter/Document.h +++ b/PdfFile/SrcWriter/Document.h @@ -198,6 +198,7 @@ namespace PdfWriter void SetCurPage(CPage* pPage) { m_pCurPage = pPage; } bool EditCO(const std::vector& arrCO); const std::map& GetAnnots() { return m_mAnnotations; } + void AddShapeXML(const std::string& sXML); private: char* GetTTFontTag(); diff --git a/PdfFile/SrcWriter/Pages.cpp b/PdfFile/SrcWriter/Pages.cpp index 9654560dc1..956e4cbb12 100644 --- a/PdfFile/SrcWriter/Pages.cpp +++ b/PdfFile/SrcWriter/Pages.cpp @@ -457,6 +457,7 @@ namespace PdfWriter m_eGrMode = grmode_PAGE; m_pGrState = new CGrState(NULL); + m_pMetaOForm = NULL; m_pExtGStates = NULL; m_unExtGStatesCount = 0; m_pFonts = NULL; @@ -1583,7 +1584,15 @@ namespace PdfWriter CNumberObject* pRotate = (CNumberObject*)GetRotateItem(); return pRotate ? pRotate->Get() : 0; } - //---------------------------------------------------------------------------------------- + void CPage::SetMetaOForm(CDictObject* pMetaOForm) + { + if (!m_pMetaOForm) + { + m_pMetaOForm = pMetaOForm; + Add("MetaOForm", m_pMetaOForm); + } + } + //---------------------------------------------------------------------------------------- // CTextWord //---------------------------------------------------------------------------------------- CTextWord::CTextWord()