From e31e02d993b85d01be64c79550cb3869db30e700 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Tue, 9 Dec 2025 10:42:13 +0300 Subject: [PATCH] Font substitution info --- DesktopEditor/doctrenderer/drawingfile.h | 3 +++ DesktopEditor/graphics/IRenderer.h | 1 + .../pro/js/wasm/src/drawingfile_test.cpp | 23 +++++++++++-------- PdfFile/PdfFile.cpp | 5 ++++ PdfFile/PdfFile.h | 1 + PdfFile/PdfReader.cpp | 18 +++++++++++++++ PdfFile/PdfReader.h | 1 + PdfFile/SrcReader/RendererOutputDev.cpp | 22 +++++++++++++----- PdfFile/SrcReader/RendererOutputDev.h | 5 ++-- 9 files changed, 61 insertions(+), 18 deletions(-) diff --git a/DesktopEditor/doctrenderer/drawingfile.h b/DesktopEditor/doctrenderer/drawingfile.h index 24bd1fd258..47bf314044 100644 --- a/DesktopEditor/doctrenderer/drawingfile.h +++ b/DesktopEditor/doctrenderer/drawingfile.h @@ -479,6 +479,9 @@ public: return NULL; } + if (m_nType == 0) + ((CPdfFile*)m_pFile)->SetPageFonts(nPageIndex); + BYTE* res = oRes.GetBuffer(); oRes.ClearWithoutAttack(); return res; diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index 90d6273819..a6bad0f876 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -117,6 +117,7 @@ const long c_nDarkMode = 0x0008; const long c_nUseDictionaryFonts = 0x0010; const long c_nPenWidth0As1px = 0x0020; const long c_nSupportPathTextAsText = 0x0040; +const long c_nFontSubstitution = 0x0080; // типы рендерера const long c_nUnknownRenderer = 0x0000; diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp index 1629ee7d95..82fd656dca 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp @@ -1134,17 +1134,17 @@ int main(int argc, char* argv[]) std::cout << "Redact false" << std::endl; } - int i = nTestPage; - //for (int i = 0; i < nPagesCount; ++i) + // RASTER + if (false) { - // RASTER - if (true) + int i = nTestPage; + //for (int i = 0; i < nPagesCount; ++i) { nWidth = READ_INT(pInfo + i * 16 + 12); nHeight = READ_INT(pInfo + i * 16 + 16); - //nWidth *= 3; - //nHeight *= 3; + //nWidth *= 2; + //nHeight *= 2; BYTE* res = NULL; res = GetPixmap(pGrFile, i, nWidth, nHeight, 0xFFFFFF); @@ -1164,7 +1164,7 @@ int main(int argc, char* argv[]) free(pInfo); // LINKS - if (true && nPagesCount > 0) + if (false && nPagesCount > 0) { BYTE* pLinks = GetLinks(pGrFile, nTestPage); nLength = READ_INT(pLinks); @@ -1200,7 +1200,7 @@ int main(int argc, char* argv[]) } // STRUCTURE - if (true) + if (false) { BYTE* pStructure = GetStructure(pGrFile); nLength = READ_INT(pStructure); @@ -2155,11 +2155,14 @@ int main(int argc, char* argv[]) } // SCAN PAGE - if (false) + if (true) { - BYTE* pScan = ScanPage(pGrFile, nTestPage, 1); + BYTE* pScan = ScanPage(pGrFile, nTestPage, 2); if (pScan) free(pScan); + + ReadInteractiveFormsFonts(pGrFile, 1); + ReadInteractiveFormsFonts(pGrFile, 2); } Close(pGrFile); diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 3d8024c432..a5dac89843 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -428,6 +428,11 @@ BYTE* CPdfFile::GetWidgets() return NULL; return m_pInternal->pReader->GetWidgets(); } +void CPdfFile::SetPageFonts(int nPageIndex) +{ + if (m_pInternal->pReader) + m_pInternal->pReader->SetFonts(nPageIndex); +} BYTE* CPdfFile::GetAnnotEmbeddedFonts() { if (!m_pInternal->pReader) diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index 711e5b1426..9c89debeb5 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -135,6 +135,7 @@ public: bool UndoRedact(); int GetRotate(int nPageIndex); int GetMaxRefID(); + void SetPageFonts(int nPageIndex); BYTE* GetWidgets(); BYTE* GetAnnotEmbeddedFonts(); BYTE* GetAnnotStandardFonts(); diff --git a/PdfFile/PdfReader.cpp b/PdfFile/PdfReader.cpp index 96e05af7da..733998c52d 100644 --- a/PdfFile/PdfReader.cpp +++ b/PdfFile/PdfReader.cpp @@ -1387,6 +1387,24 @@ BYTE* CPdfReader::GetWidgets() oRes.ClearWithoutAttack(); return bRes; } +void CPdfReader::SetFonts(int _nPageIndex) +{ + if (m_vPDFContext.empty()) + return; + + PDFDoc* pDoc = NULL; + PdfReader::CPdfFontList* pFontList = NULL; + GetPageIndex(_nPageIndex, &pDoc, &pFontList); + + const std::map& mapFonts = pFontList->GetFonts(); + for (std::map::const_iterator it = mapFonts.begin(); it != mapFonts.end(); ++it) + { + PdfReader::TFontEntry* pEntry = it->second; + if (!pEntry) + continue; + m_mFonts.insert(std::make_pair(pEntry->wsFontName, pEntry->wsFilePath)); + } +} BYTE* CPdfReader::GetFonts(bool bStandart) { NSWasm::CData oRes; diff --git a/PdfFile/PdfReader.h b/PdfFile/PdfReader.h index 8e2ae637c3..4a35f79963 100644 --- a/PdfFile/PdfReader.h +++ b/PdfFile/PdfReader.h @@ -111,6 +111,7 @@ public: int FindRefNum(int nObjID, PDFDoc** pDoc = NULL, int* nStartRefID = NULL); int GetPageIndex(int nPageIndex, PDFDoc** pDoc = NULL, PdfReader::CPdfFontList** pFontList = NULL, int* nStartRefID = NULL); + void SetFonts(int nPageIndex); BYTE* GetStructure(); BYTE* GetLinks(int nPageIndex); BYTE* GetWidgets(); diff --git a/PdfFile/SrcReader/RendererOutputDev.cpp b/PdfFile/SrcReader/RendererOutputDev.cpp index 13660c88a5..1ce592cd3e 100644 --- a/PdfFile/SrcReader/RendererOutputDev.cpp +++ b/PdfFile/SrcReader/RendererOutputDev.cpp @@ -347,7 +347,7 @@ namespace PdfReader } void CPdfFontList::Remove(Ref oRef) { - CRefFontMap::iterator oPos = m_oFontMap.find(oRef); + std::map::iterator oPos = m_oFontMap.find(oRef); if (m_oFontMap.end() != oPos) { TFontEntry* pEntry = oPos->second; @@ -385,7 +385,7 @@ namespace PdfReader } TFontEntry* CPdfFontList::Lookup(Ref& oRef) { - CRefFontMap::const_iterator oPos = m_oFontMap.find(oRef); + std::map::const_iterator oPos = m_oFontMap.find(oRef); return m_oFontMap.end() == oPos ? NULL : oPos->second; } void CPdfFontList::Add(Ref& oRef, TFontEntry* pFontEntry) @@ -393,6 +393,10 @@ namespace PdfReader // До вызова данной функции надо проверять есть ли элемент с данным ключом m_oFontMap.insert(std::pair(oRef, pFontEntry)); } + const std::map& CPdfFontList::GetFonts() + { + return m_oFontMap; + } //-------------------------------------------------------------------------------------- // RendererOutputDev //-------------------------------------------------------------------------------------- @@ -1562,6 +1566,7 @@ namespace PdfReader pEntry->unLenGID = (unsigned int)nLen; pEntry->unLenUnicode = (unsigned int)nToUnicodeLen; pEntry->bAvailable = true; + pEntry->bFontSubstitution = bFontSubstitution; } else if (NULL != pEntry) { @@ -1589,6 +1594,14 @@ namespace PdfReader { m_pRenderer->put_FontPath(wsFileName); m_pRenderer->put_FontName(wsFontName); + if (c_nDocxWriter == m_lRendererType) + { + TFontEntry oEntry; + if (!m_pFontList->GetFont(pFont->getID(), &oEntry)) + return; + if (oEntry.bFontSubstitution) + m_pRenderer->CommandLong(c_nFontSubstitution, 0); + } } } void RendererOutputDev::stroke(GfxState* pGState) @@ -2562,11 +2575,8 @@ namespace PdfReader m_pRenderer->put_FontPath(sFontPath); } - LONG lRendererType = 0; - m_pRenderer->get_Type(&lRendererType); - bool bIsEmulateBold = false; - if (c_nDocxWriter == lRendererType && 2 == nRenderMode) + if (c_nDocxWriter == m_lRendererType && 2 == nRenderMode) bIsEmulateBold = (S_OK == m_pRenderer->CommandLong(c_nSupportPathTextAsText, 0)) ? true : false; if (bIsEmulateBold) diff --git a/PdfFile/SrcReader/RendererOutputDev.h b/PdfFile/SrcReader/RendererOutputDev.h index 359008925b..8a5851728f 100644 --- a/PdfFile/SrcReader/RendererOutputDev.h +++ b/PdfFile/SrcReader/RendererOutputDev.h @@ -55,6 +55,7 @@ namespace PdfReader unsigned int unLenGID; unsigned int unLenUnicode; bool bAvailable; // Доступен ли шрифт. Сделано для многопотоковости + bool bFontSubstitution = false; }; @@ -69,13 +70,13 @@ namespace PdfReader TFontEntry* Add(Ref oRef, const std::wstring& wsFileName, int* pCodeToGID, int* pCodeToUnicode, unsigned int unLenGID, unsigned int unLenUnicode); void Clear(); bool GetFont(Ref* pRef, TFontEntry* pEntry); + const std::map& GetFonts(); private: TFontEntry* Lookup(Ref& oRef); void Add(Ref& oRef, TFontEntry* pFontEntry); private: - typedef std::map CRefFontMap; - CRefFontMap m_oFontMap; + std::map m_oFontMap; NSCriticalSection::CRITICAL_SECTION m_oCS; // Критическая секция };