From a95d8712d32ca37e5ee3e756cdde3ebd231dcbe8 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Wed, 22 Apr 2026 13:51:34 +0300 Subject: [PATCH] Create IOfficeDrawingFilePainter --- DesktopEditor/doctrenderer/drawingfile.h | 5 +++ .../graphics/pro/js/drawingfile.json | 1 + .../graphics/pro/js/wasm/src/drawingfile.cpp | 4 ++ .../graphics/pro/officedrawingfile.cpp | 2 + .../graphics/pro/officedrawingfile.h | 23 +++++++++++ PdfFile/PdfFile.cpp | 6 +++ PdfFile/PdfFile.h | 1 + PdfFile/PdfReader.cpp | 40 ++++++++++++++++++- PdfFile/PdfReader.h | 2 + 9 files changed, 83 insertions(+), 1 deletion(-) diff --git a/DesktopEditor/doctrenderer/drawingfile.h b/DesktopEditor/doctrenderer/drawingfile.h index 5c33a0b2bc..491260cf0e 100644 --- a/DesktopEditor/doctrenderer/drawingfile.h +++ b/DesktopEditor/doctrenderer/drawingfile.h @@ -288,6 +288,11 @@ public: return bRes; } + void SetPainter(IOfficeDrawingFilePainter* pPainter) + { + if (m_pFile) + m_pFile->SetPainter(pPainter); + } BYTE* GetPixmap(int nPageIndex, int nRasterW, int nRasterH, int nBackgroundColor) { if (!m_pFile) diff --git a/DesktopEditor/graphics/pro/js/drawingfile.json b/DesktopEditor/graphics/pro/js/drawingfile.json index ddb71f55e3..a817af2e86 100644 --- a/DesktopEditor/graphics/pro/js/drawingfile.json +++ b/DesktopEditor/graphics/pro/js/drawingfile.json @@ -31,6 +31,7 @@ "_Close", "_GetErrorCode", "_GetInfo", + "_SetPainter", "_GetPixmap", "_GetGlyphs", "_GetLinks", diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp index 87737b5f51..f1b0b9e046 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp @@ -106,6 +106,10 @@ WASM_EXPORT BYTE* GetInfo(CDrawingFile* pFile) { return pFile->GetInfo(); } +WASM_EXPORT void SetPainter(CDrawingFile* pFile, IOfficeDrawingFilePainter* pPainter) +{ + pFile->SetPainter(pPainter); +} WASM_EXPORT BYTE* GetPixmap(CDrawingFile* pFile, int nPageIndex, int nRasterW, int nRasterH, int nBackgroundColor) { return pFile->GetPixmap(nPageIndex, nRasterW, nRasterH, nBackgroundColor); diff --git a/DesktopEditor/graphics/pro/officedrawingfile.cpp b/DesktopEditor/graphics/pro/officedrawingfile.cpp index cd066c7a77..b705a92d2c 100644 --- a/DesktopEditor/graphics/pro/officedrawingfile.cpp +++ b/DesktopEditor/graphics/pro/officedrawingfile.cpp @@ -141,3 +141,5 @@ void IOfficeDrawingFile::ConvertToRaster(int nPageIndex, const std::wstring& pat pFrame->SaveFile(path, nImageType); RELEASEOBJECT(pFrame); } + +void IOfficeDrawingFile::SetPainter(IOfficeDrawingFilePainter* pPainter) {} diff --git a/DesktopEditor/graphics/pro/officedrawingfile.h b/DesktopEditor/graphics/pro/officedrawingfile.h index 836d038bc3..d0406aca01 100644 --- a/DesktopEditor/graphics/pro/officedrawingfile.h +++ b/DesktopEditor/graphics/pro/officedrawingfile.h @@ -56,6 +56,26 @@ struct COfficeDrawingPageParams } }; +class IOfficeDrawingFilePainter +{ +public: + enum class State + { + Paused, + Stopped, + Runned + }; + + enum class Status + { + Ok, + Cancel + }; + + virtual State GetState() = 0; + virtual void OnPaint(const Status&) = 0; +}; + class GRAPHICS_DECL IOfficeDrawingFile { public: @@ -103,6 +123,9 @@ public: virtual std::wstring GetInfo() = 0; virtual unsigned char* GetStructure() = 0; virtual unsigned char* GetLinks(int nPageIndex) = 0; + + // DrawingFile control + virtual void SetPainter(IOfficeDrawingFilePainter* pPainter); }; #endif // _OFFICE_DRAWING_FILE_H diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 257eecd0ff..d811a6e34b 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -481,6 +481,12 @@ void CPdfFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pB m_pInternal->pReader->SetParams(pParams); m_pInternal->pReader->DrawPageOnRenderer(pRenderer, nPageIndex, pBreak); } +void CPdfFile::SetPainter(IOfficeDrawingFilePainter* pPainter) +{ + if (!m_pInternal->pReader) + return; + m_pInternal->pReader->SetPainter(pPainter); +} std::wstring CPdfFile::GetInfo() { if (!m_pInternal->pReader) diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index 19de091ebe..0c75721176 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -136,6 +136,7 @@ public: virtual std::wstring GetInfo(); virtual BYTE* GetStructure(); virtual BYTE* GetLinks(int nPageIndex); + virtual void SetPainter(IOfficeDrawingFilePainter* pPainter); bool ValidMetaData(); // Takes ownership of malloc data memory diff --git a/PdfFile/PdfReader.cpp b/PdfFile/PdfReader.cpp index 1eebc24691..64ffb58771 100644 --- a/PdfFile/PdfReader.cpp +++ b/PdfFile/PdfReader.cpp @@ -39,6 +39,7 @@ #include "../DesktopEditor/common/StringExt.h" #include "../DesktopEditor/graphics/pro/js/wasm/src/serialize.h" #include "../DesktopEditor/graphics/MetafileToRenderer.h" +#include "../DesktopEditor/graphics/BaseThread.h" #include "SrcReader/Adaptors.h" #include "SrcReader/PdfAnnot.h" @@ -67,6 +68,34 @@ NSFonts::IFontManager* InitFontManager(NSFonts::IApplicationFonts* pAppFonts) pMeasurerCache->SetCacheSize(1); return m_pFontManager; } +static GBool CheckPainter(void* p) +{ + if (!p) + return gFalse; + + IOfficeDrawingFilePainter* pPainter = static_cast(p); + IOfficeDrawingFilePainter::State eState = pPainter->GetState(); + + if (IOfficeDrawingFilePainter::State::Stopped == eState) + { + pPainter->OnPaint(IOfficeDrawingFilePainter::Status::Cancel); + return gTrue; + } + + if (IOfficeDrawingFilePainter::State::Paused == eState) + { + while (IOfficeDrawingFilePainter::State::Paused == pPainter->GetState()) + { + pPainter->OnPaint(IOfficeDrawingFilePainter::Status::Ok); + NSThreads::Sleep(10); + } + } + + // IOfficeDrawingFilePainter::State::Runned == eState + pPainter->OnPaint(IOfficeDrawingFilePainter::Status::Ok); + + return gFalse; +} CPdfReaderContext::~CPdfReaderContext() { @@ -103,6 +132,7 @@ CPdfReader::CPdfReader(NSFonts::IApplicationFonts* pAppFonts) #endif m_eError = errNone; + m_pPainter = NULL; } CPdfReader::~CPdfReader() { @@ -652,6 +682,10 @@ bool CPdfReader::CheckPerm(int nPerm) return ownerPasswordOk || (permFlags & (1 << --nPerm)); } +void CPdfReader::SetPainter(IOfficeDrawingFilePainter* pPainter) +{ + m_pPainter = pPainter; +} void CPdfReader::DrawPageOnRenderer(IRenderer* pRenderer, int _nPageIndex, bool* pbBreak) { PDFDoc* pDoc = NULL; @@ -673,7 +707,7 @@ void CPdfReader::DrawPageOnRenderer(IRenderer* pRenderer, int _nPageIndex, bool* #ifdef BUILDING_WASM_MODULE nRotate = -pDoc->getPageRotate(nPageIndex); #endif - pDoc->displayPage(&oRendererOut, nPageIndex, 72.0, 72.0, nRotate, gFalse, gTrue, gFalse); + pDoc->displayPage(&oRendererOut, nPageIndex, 72.0, 72.0, nRotate, gFalse, gTrue, gFalse, m_pPainter ? CheckPainter : NULL, m_pPainter ? m_pPainter : NULL); ((GlobalParamsAdaptor*)globalParams)->ClearRedact(); @@ -720,6 +754,10 @@ void CPdfReader::DrawPageOnRenderer(IRenderer* pRenderer, int _nPageIndex, bool* // RELEASEOBJECT(pCorrector); } } + + // TODO Report successful completion + // if (m_pPainter && IOfficeDrawingFilePainter::State::Stopped != m_pPainter->GetState()) + // m_pPainter->OnPaint(IOfficeDrawingFilePainter::Status::Ok); } void CPdfReader::SetTempDirectory(const std::wstring& wsTempFolder) { diff --git a/PdfFile/PdfReader.h b/PdfFile/PdfReader.h index 81cce2ce9f..964875b9bf 100644 --- a/PdfFile/PdfReader.h +++ b/PdfFile/PdfReader.h @@ -99,6 +99,7 @@ public: bool CheckPerm(int nPerm); void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY); void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak); + void SetPainter(IOfficeDrawingFilePainter* pPainter); std::wstring GetInfo(); BYTE* GetGIDByUnicode(const std::wstring& wsFontName); std::wstring GetFontPath(const std::wstring& wsFontName, bool bSave = true); @@ -134,6 +135,7 @@ private: NSFonts::IFontManager* m_pFontManager; DWORD m_nFileLength; int m_eError; + IOfficeDrawingFilePainter* m_pPainter; std::vector m_vPDFContext; std::vector m_vRedact; std::map m_mFonts;