mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Fix bug #61761
Fix issue with saving text appearance in pdf in case of multiline text
This commit is contained in:
@ -1247,16 +1247,23 @@ HRESULT CPdfWriter::AddFormField(NSFonts::IApplicationFonts* pAppFonts, IFormFie
|
||||
{
|
||||
unsigned short* pCodes2 = new unsigned short[unLen];
|
||||
unsigned int* pWidths = new unsigned int[unLen];
|
||||
|
||||
unsigned short ushSpaceCode = 0xFFFF;
|
||||
|
||||
unsigned short ushSpaceCode = 0xFFFF;
|
||||
unsigned short ushNewLineCode = 0xFFFE;
|
||||
for (unsigned int unIndex = 0; unIndex < unLen; ++unIndex)
|
||||
{
|
||||
pCodes2[unIndex] = (0x0020 == pUnicodes[unIndex] ? ushSpaceCode : 0);
|
||||
unsigned short ushCode = 0;
|
||||
if (0x0020 == pUnicodes[unIndex])
|
||||
ushCode = ushSpaceCode;
|
||||
else if (0x000D == pUnicodes[unIndex] || 0x000A == pUnicodes[unIndex])
|
||||
ushCode = ushNewLineCode;
|
||||
|
||||
pCodes2[unIndex] = ushCode;
|
||||
pWidths[unIndex] = ppFonts[unIndex]->GetWidth(pCodes[unIndex]);
|
||||
}
|
||||
|
||||
m_oLinesManager.Init(pCodes2, pWidths, unLen, ushSpaceCode, pFontTT->GetLineHeight(), pFontTT->GetAscent());
|
||||
|
||||
|
||||
m_oLinesManager.Init(pCodes2, pWidths, unLen, ushSpaceCode, ushNewLineCode, pFontTT->GetLineHeight(), pFontTT->GetAscent());
|
||||
|
||||
// TODO: Разобраться более детально по какой именно высоте идет в Adobe расчет
|
||||
// пока временно оставим (H - 3 * margin)
|
||||
if (pPr->IsAutoFit())
|
||||
|
||||
@ -1507,25 +1507,27 @@ public:
|
||||
m_nAscent = 0;
|
||||
m_nDescent = 0;
|
||||
}
|
||||
void Init(unsigned short* pCodes, unsigned int* pWidths, const unsigned int& unLen, const unsigned short& ushSpaceCode, const unsigned int& unLineHeight, const int& nAscent)
|
||||
void Init(unsigned short* pCodes, unsigned int* pWidths, const unsigned int& unLen, const unsigned short& ushSpaceCode, const unsigned short& ushNewLineCode, const unsigned int& unLineHeight, const int& nAscent)
|
||||
{
|
||||
m_pCodes = pCodes;
|
||||
m_pWidths = pWidths;
|
||||
m_unLen = unLen;
|
||||
m_ushSpaceCode = ushSpaceCode;
|
||||
m_unLineHeight = unLineHeight;
|
||||
m_nAscent = nAscent;
|
||||
m_nDescent = unLineHeight - nAscent;
|
||||
m_pCodes = pCodes;
|
||||
m_pWidths = pWidths;
|
||||
m_unLen = unLen;
|
||||
m_ushSpaceCode = ushSpaceCode;
|
||||
m_ushNewLineCode = ushNewLineCode;
|
||||
m_unLineHeight = unLineHeight;
|
||||
m_nAscent = nAscent;
|
||||
m_nDescent = unLineHeight - nAscent;
|
||||
}
|
||||
void Clear()
|
||||
{
|
||||
m_pCodes = NULL;
|
||||
m_pWidths = NULL;
|
||||
m_unLen = 0;
|
||||
m_ushSpaceCode = 0;
|
||||
m_unLineHeight = 0;
|
||||
m_nAscent = 0;
|
||||
m_nDescent = 0;
|
||||
m_pCodes = NULL;
|
||||
m_pWidths = NULL;
|
||||
m_unLen = 0;
|
||||
m_ushSpaceCode = 0;
|
||||
m_ushNewLineCode = 0;
|
||||
m_unLineHeight = 0;
|
||||
m_nAscent = 0;
|
||||
m_nDescent = 0;
|
||||
}
|
||||
void CalculateLines(const double& dFontSize, const double& dW)
|
||||
{
|
||||
@ -1547,6 +1549,15 @@ public:
|
||||
bLineStart = false;
|
||||
bFirstItemOnLine = false;
|
||||
}
|
||||
else if (IsNewLine(unPos))
|
||||
{
|
||||
bLineStart = true;
|
||||
bFirstItemOnLine = true;
|
||||
bWord = false;
|
||||
dX = 0;
|
||||
dWordWidth = 0;
|
||||
m_vBreaks.push_back(unPos + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
double dLetterWidth = m_pWidths[unPos] * dKoef;
|
||||
@ -1656,13 +1667,15 @@ public:
|
||||
|
||||
return m_vBreaks[nLineIndex - 1];
|
||||
}
|
||||
unsigned int GetLineEndPos(const int& nLineIndex) const
|
||||
{
|
||||
if (nLineIndex >= m_vBreaks.size())
|
||||
return m_unLen;
|
||||
|
||||
return m_vBreaks[nLineIndex];
|
||||
}
|
||||
unsigned int GetLineEndPos(const int& nLineIndex) const
|
||||
{
|
||||
unsigned int unLineStart = GetLineStartPos(nLineIndex);
|
||||
unsigned int unLineEnd = nLineIndex >= m_vBreaks.size() ? m_unLen : m_vBreaks[nLineIndex];
|
||||
while (unLineEnd > 0 && unLineEnd > unLineStart && IsNewLine(unLineEnd - 1))
|
||||
--unLineEnd;
|
||||
|
||||
return unLineEnd;
|
||||
}
|
||||
double GetLineWidth(const int& nLineIndex, const double& dFontSize = 10.0)
|
||||
{
|
||||
if (nLineIndex < 0 || nLineIndex > m_vBreaks.size())
|
||||
@ -1699,9 +1712,13 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
inline bool IsSpace(const unsigned int& unPos) const
|
||||
inline bool IsSpace(const unsigned int& unPos) const
|
||||
{
|
||||
return (m_pCodes[unPos] == m_ushSpaceCode);
|
||||
}
|
||||
inline bool IsNewLine(const unsigned int& unPos) const
|
||||
{
|
||||
return (m_pCodes[unPos] == m_ushSpaceCode);
|
||||
return (m_pCodes[unPos] == m_ushNewLineCode);
|
||||
}
|
||||
inline bool CheckHeight(const double& dH, const double& dFontSize) const
|
||||
{
|
||||
@ -1714,6 +1731,7 @@ private:
|
||||
unsigned int* m_pWidths;
|
||||
unsigned int m_unLen;
|
||||
unsigned short m_ushSpaceCode;
|
||||
unsigned short m_ushNewLineCode;
|
||||
unsigned int m_unLineHeight;
|
||||
int m_nAscent;
|
||||
int m_nDescent;
|
||||
|
||||
Reference in New Issue
Block a user