From eaf2c02b86e403cfc018732ab382087548dadeae Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Sat, 20 Jul 2024 13:37:23 +0300 Subject: [PATCH] Fix bug 69284 --- PdfFile/PdfWriter.cpp | 18 ++++++++++-------- PdfFile/SrcWriter/Field.cpp | 8 ++++++++ PdfFile/SrcWriter/Field.h | 4 +++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/PdfFile/PdfWriter.cpp b/PdfFile/PdfWriter.cpp index 01f158a069..d6e3bedc48 100644 --- a/PdfFile/PdfWriter.cpp +++ b/PdfFile/PdfWriter.cpp @@ -1192,14 +1192,6 @@ HRESULT CPdfWriter::AddFormField(NSFonts::IApplicationFonts* pAppFonts, CFormFie } } - PdfWriter::CFontTrueType* pFontTT = NULL; - if (oInfo.IsTextField() || oInfo.IsDropDownList()) - { - pFontTT = m_pDocument->CreateTrueTypeFont(m_pFont); - if (!pFontTT) - return S_OK; - } - double dX, dY, dW, dH; oInfo.GetBounds(dX, dY, dW, dH); @@ -1337,6 +1329,7 @@ HRESULT CPdfWriter::AddFormField(NSFonts::IApplicationFonts* pAppFonts, CFormFie if (!isPlaceHolder) pField->SetTextValue(wsValue); + PdfWriter::CFontTrueType* pFontTT = NULL; if (!isComb && pPr->IsMultiLine()) { @@ -1356,6 +1349,8 @@ HRESULT CPdfWriter::AddFormField(NSFonts::IApplicationFonts* pAppFonts, CFormFie pCodes2[unIndex] = ushCode; pWidths[unIndex] = ppFonts[unIndex]->GetWidth(pCodes[unIndex]); } + + pFontTT = m_pDocument->CreateTrueTypeFont(m_pFont); m_oLinesManager.Init(pCodes2, pWidths, unLen, ushSpaceCode, ushNewLineCode, pFontTT->GetLineHeight(), pFontTT->GetAscent()); @@ -1459,6 +1454,8 @@ HRESULT CPdfWriter::AddFormField(NSFonts::IApplicationFonts* pAppFonts, CFormFie RELEASEARRAYOBJECTS(pCodes); RELEASEARRAYOBJECTS(ppFonts); + if (pField->GetFont() && pField->GetFont() != m_pFont && pField->GetFont()->GetFontType() == PdfWriter::fontCIDType2) + pFontTT = m_pDocument->CreateTrueTypeFont((PdfWriter::CFontCidTrueType*)pField->GetFont()); pField->SetDefaultAppearance(pFontTT, m_oFont.GetSize(), PdfWriter::TRgb(oColor.r, oColor.g, oColor.b)); std::wstring wsPlaceHolder = pPr->GetPlaceHolder(); @@ -1529,6 +1526,11 @@ HRESULT CPdfWriter::AddFormField(NSFonts::IApplicationFonts* pAppFonts, CFormFie pField->SetComboFlag(true); pField->SetEditFlag(pPr->IsEditComboBox()); + PdfWriter::CFontTrueType* pFontTT = NULL; + if (pField->GetFont() && pField->GetFont() != m_pFont && pField->GetFont()->GetFontType() == PdfWriter::fontCIDType2) + pFontTT = m_pDocument->CreateTrueTypeFont((PdfWriter::CFontCidTrueType*)pField->GetFont()); + else + pFontTT = m_pDocument->CreateTrueTypeFont(m_pFont); pField->SetDefaultAppearance(pFontTT, m_oFont.GetSize(), oInfo.IsPlaceHolder() ? oPlaceHolderColor : oNormalColor); if (!pPr->GetPlaceHolder().empty()) diff --git a/PdfFile/SrcWriter/Field.cpp b/PdfFile/SrcWriter/Field.cpp index 4c769c1a0e..8b3afd0095 100644 --- a/PdfFile/SrcWriter/Field.cpp +++ b/PdfFile/SrcWriter/Field.cpp @@ -77,6 +77,7 @@ namespace PdfWriter m_pAppearance = NULL; m_pFocus = NULL; m_pBlur = NULL; + m_pFont = NULL; } void CFieldBase::SetReadOnlyFlag(bool isReadOnly) { @@ -268,6 +269,7 @@ namespace PdfWriter } pNormal->DrawSimpleText(wsValue, pCodes, unCount, pFont, dFontSize, dX, dY, oColor.r, oColor.g, oColor.b, sExtGrStateName, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop), ppFonts, pShifts); + m_pFont = pNormal->GetFont(); } void CFieldBase::StartTextAppearance(CFontDict* pFont, const double& dFontSize, const TRgb& oColor, const double& dAlpha) { @@ -288,6 +290,7 @@ namespace PdfWriter } pNormal->StartDrawText(pFont, dFontSize, oColor.r, oColor.g, oColor.b, sExtGrStateName, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop)); + m_pFont = pNormal->GetFont(); } void CFieldBase::AddLineToTextAppearance(const double& dX, const double& dY, unsigned short* pCodes, const unsigned int& unCodesCount, CFontCidTrueType** ppFonts, const double* pShifts) { @@ -296,6 +299,7 @@ namespace PdfWriter CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal(); pNormal->DrawTextLine(dX, dY, pCodes, unCodesCount, ppFonts, pShifts); + m_pFont = pNormal->GetFont(); } void CFieldBase::EndTextAppearance() { @@ -698,6 +702,10 @@ namespace PdfWriter AddScriptToAA("F", scriptF, pAA); } } + CFontDict* CFieldBase::GetFont() + { + return m_pFont; + } //---------------------------------------------------------------------------------------- // CTextField //---------------------------------------------------------------------------------------- diff --git a/PdfFile/SrcWriter/Field.h b/PdfFile/SrcWriter/Field.h index 0fb7548e7d..87269f9ae7 100644 --- a/PdfFile/SrcWriter/Field.h +++ b/PdfFile/SrcWriter/Field.h @@ -165,7 +165,7 @@ namespace PdfWriter const TRgb& GetNormalColor(); const TRgb& GetPlaceHolderColor(); void SetFormat(const CFormFieldInfo::CTextFormFormat* pFormat); - + CFontDict* GetFont(); protected: @@ -194,6 +194,7 @@ namespace PdfWriter TRgb m_oPlaceHolderColor; CDictObject* m_pFocus; CDictObject* m_pBlur; + CFontDict* m_pFont; }; class CTextField : public CFieldBase @@ -417,6 +418,7 @@ namespace PdfWriter void DrawTextUpLeftArrow(const std::string& sColor); CStream* GetStream() { return m_pStream; } + CFontDict* GetFont() { return m_pFont; } bool m_bStart;