Fix bug 74314

This commit is contained in:
Svetlana Kulikova
2025-05-13 14:32:07 +03:00
parent 992bc0095f
commit f7a46174ad
3 changed files with 54 additions and 2 deletions

View File

@ -44,6 +44,7 @@
#include "SrcWriter/Destination.h"
#include "SrcWriter/Field.h"
#include "SrcWriter/Outline.h"
#include "SrcWriter/Utils.h"
#include "Resources/BaseFonts.h"
#include "../DesktopEditor/graphics/Image.h"
@ -1275,6 +1276,7 @@ HRESULT CPdfWriter::AddFormField(NSFonts::IApplicationFonts* pAppFonts, CFormFie
{
const CFormFieldInfo::CTextFormPr* pPr = oInfo.GetTextFormPr();
std::wstring wsValue = pPr->GetTextValue();
wsValue = PdfWriter::NormalizeWhitespace(wsValue);
unsigned int unLen = 0;
unsigned int* pUnicodes = NULL;
@ -1456,6 +1458,7 @@ HRESULT CPdfWriter::AddFormField(NSFonts::IApplicationFonts* pAppFonts, CFormFie
pField->SetDefaultAppearance(pFontTT, m_oFont.GetSize(), PdfWriter::TRgb(oColor.r, oColor.g, oColor.b));
std::wstring wsPlaceHolder = pPr->GetPlaceHolder();
wsPlaceHolder = PdfWriter::NormalizeWhitespace(wsPlaceHolder);
if (!wsPlaceHolder.empty())
{
unsigned int unMaxLen = pPr->GetMaxCharacters();
@ -1530,9 +1533,11 @@ HRESULT CPdfWriter::AddFormField(NSFonts::IApplicationFonts* pAppFonts, CFormFie
pFontTT = m_pDocument->CreateTrueTypeFont(m_pFont);
pField->SetDefaultAppearance(pFontTT, m_oFont.GetSize(), oInfo.IsPlaceHolder() ? oPlaceHolderColor : oNormalColor);
if (!pPr->GetPlaceHolder().empty())
std::wstring wsPlaceHolder = pPr->GetPlaceHolder();
wsPlaceHolder = PdfWriter::NormalizeWhitespace(wsPlaceHolder);
if (!wsPlaceHolder.empty())
{
pField->SetPlaceHolderText(pPr->GetPlaceHolder(), oNormalColor, oPlaceHolderColor);
pField->SetPlaceHolderText(wsPlaceHolder, oNormalColor, oPlaceHolderColor);
if (!pPr->IsEditComboBox())
{

View File

@ -32,6 +32,7 @@
#include "Utils.h"
#include <vector>
#include <ctime>
#include <cwctype>
namespace PdfWriter
{
@ -270,4 +271,49 @@ namespace PdfWriter
std::string sRes(sTemp);
return sRes;
}
std::wstring NormalizeWhitespace(const std::wstring& s)
{
std::wstring sRes;
sRes.reserve(s.size());
for (wchar_t c : s)
{
switch(c)
{
/*
case 0x0009: // Character tabulation
case 0x000A: // Line feed
case 0x000B: // Line tabulation
case 0x000C: // Form feed
case 0x000D: // Carriage return
*/
case 0x00A0: // No-break space
case 0x1680: // Ogham space mark
case 0x2000: // En quad
case 0x2001: // Em quad
case 0x2002: // En space
case 0x2003: // Em space
case 0x2004: // Three-per-em space
case 0x2005: // Four-per-em space
case 0x2006: // Six-per-em space
case 0x2007: // Figure space
case 0x2008: // Punctuation space
case 0x2009: // Thin space
case 0x200A: // Hair space
case 0x2028: // Line separator
case 0x2029: // Paragraph separator
case 0x202F: // Narrow no-break space
case 0x205F: // Medium mathematical space
case 0x2060: // Word joiner
case 0x3000: // Ideographic space
case 0xFEFF: // Zero width no-break space
sRes += L' ';
break;
default:
sRes += c;
}
}
return sRes;
}
}

View File

@ -140,6 +140,7 @@ namespace PdfWriter
void UIntChangeBit2(unsigned int& nValue, short nBit);
std::string DateNow();
std::wstring NormalizeWhitespace(const std::wstring& s);
}
#endif // _PDF_WRITER_SRC_UTILS_H