From 7890f5b87f2fe4b4b903aa9bdfb61c1464acdb25 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Tue, 28 Apr 2026 14:49:38 +0300 Subject: [PATCH] Fix Embedded font use in pushbutton --- .../graphics/commands/AnnotField.cpp | 1 + DesktopEditor/graphics/commands/AnnotField.h | 2 ++ PdfFile/PdfFile.cpp | 28 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/DesktopEditor/graphics/commands/AnnotField.cpp b/DesktopEditor/graphics/commands/AnnotField.cpp index 7c4fb94a5f..db166795e3 100644 --- a/DesktopEditor/graphics/commands/AnnotField.cpp +++ b/DesktopEditor/graphics/commands/AnnotField.cpp @@ -897,6 +897,7 @@ CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr* CAnnotFieldInfo::CWidgetAnn CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr* CAnnotFieldInfo::CWidgetAnnotPr::GetTextWidgetPr() { return m_pTextPr; } CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr* CAnnotFieldInfo::CWidgetAnnotPr::GetChoiceWidgetPr() { return m_pChoicePr; } CAnnotFieldInfo::CWidgetAnnotPr::CSignatureWidgetPr* CAnnotFieldInfo::CWidgetAnnotPr::GetSignatureWidgetPr() { return m_pSignaturePr; } +void CAnnotFieldInfo::CWidgetAnnotPr::SetFontName(const std::wstring& sName) { m_wsFN = sName; } CAnnotFieldInfo::CWidgetAnnotPr::CWidgetAnnotPr(BYTE nType) { m_pButtonPr = NULL; diff --git a/DesktopEditor/graphics/commands/AnnotField.h b/DesktopEditor/graphics/commands/AnnotField.h index ee74ea2d5f..2b333f030d 100644 --- a/DesktopEditor/graphics/commands/AnnotField.h +++ b/DesktopEditor/graphics/commands/AnnotField.h @@ -203,6 +203,8 @@ public: const std::vector& GetBG(); const std::vector& GetActions(); + void SetFontName(const std::wstring& sName); + CButtonWidgetPr* GetButtonWidgetPr(); CTextWidgetPr* GetTextWidgetPr(); CChoiceWidgetPr* GetChoiceWidgetPr(); diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 4fd5cf7bcf..5eb1d254c6 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -1449,6 +1449,34 @@ HRESULT CPdfFile::AdvancedCommand(IAdvancedCommand* command) if (nFlags & (1 << 15)) m_pInternal->pEditor->EditAnnot(pCommand->GetPage(), pCommand->GetCopyAP()); } + if (pCommand->IsWidget()) + { + CAnnotFieldInfo::CWidgetAnnotPr* pPr = pCommand->GetWidgetAnnotPr(); + std::wstring wsFontName = pPr->GetFontName(); + + size_t lastSpace = wsFontName.find_last_of(L' '); + if (lastSpace != std::wstring::npos && lastSpace + 1 == wsFontName.size() - 32) + { + std::wstring sHash = wsFontName.substr(lastSpace + 1); + bool bValidHash = true; + for (wchar_t c : sHash) + { + if (!((c >= L'A' && c <= L'F') || (c >= L'0' && c <= L'9'))) + { + bValidHash = false; + break; + } + } + + if (bValidHash) + { + std::wstring sName = wsFontName.substr(0, lastSpace); + wsFontName = sName; + } + } + + pPr->SetFontName(wsFontName); + } } return m_pInternal->pWriter->AddAnnotField(m_pInternal->pAppFonts, pCommand); }