mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Fix bug 68951
This commit is contained in:
@ -152,7 +152,7 @@ void CPdfWriter::AddFont(const std::wstring& wsFontName, const bool& bBold, cons
|
||||
void CPdfWriter::SetHeadings(CHeadings* pCommand) {}
|
||||
PdfWriter::CImageDict* CPdfWriter::LoadImage(Aggplus::CImage* pImage, BYTE nAlpha) { return NULL; }
|
||||
PdfWriter::CImageDict* CPdfWriter::DrawImage(Aggplus::CImage* pImage, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha) { return NULL; }
|
||||
bool CPdfWriter::DrawText(unsigned char* pCodes, const unsigned int& unLen, const double& dX, const double& dY) { return false; }
|
||||
bool CPdfWriter::DrawText(unsigned char* pCodes, const unsigned int& unLen, const double& dX, const double& dY, const std::string& sPUA) { return false; }
|
||||
bool CPdfWriter::DrawTextToRenderer(const unsigned int* unGid, const unsigned int& unLen, const double& dX, const double& dY) { return false; }
|
||||
bool CPdfWriter::PathCommandDrawText(unsigned int* pUnicodes, unsigned int unLen, const double& dX, const double& dY, const unsigned int* pGids) { return false; }
|
||||
bool CPdfWriter::UpdateFont() { return false; }
|
||||
|
||||
@ -622,6 +622,19 @@ HRESULT CPdfWriter::put_FontFaceIndex(const int& nFaceIndex)
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Функции для вывода текста
|
||||
//----------------------------------------------------------------------------------------
|
||||
bool UnicodePUA(unsigned int unUnicode)
|
||||
{
|
||||
return (unUnicode >= 0xE000 && unUnicode <= 0xF8FF) || (unUnicode >= 0xF0000 && unUnicode <= 0xFFFFD) || (unUnicode >= 0x100000 && unUnicode <= 0x10FFFD);
|
||||
}
|
||||
bool UnicodesPUA(unsigned int* pUnicodes, unsigned int unLen)
|
||||
{
|
||||
for (int i = 0; i < unLen; ++i)
|
||||
{
|
||||
if (UnicodePUA(pUnicodes[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
HRESULT CPdfWriter::CommandDrawTextCHAR(const LONG& lUnicode, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
if (!IsPageValid())
|
||||
@ -629,7 +642,7 @@ HRESULT CPdfWriter::CommandDrawTextCHAR(const LONG& lUnicode, const double& dX,
|
||||
|
||||
unsigned int unUnicode = lUnicode;
|
||||
unsigned char* pCodes = EncodeString(&unUnicode, 1);
|
||||
return DrawText(pCodes, 2, dX, dY) ? S_OK : S_FALSE;
|
||||
return DrawText(pCodes, 2, dX, dY, UnicodePUA(unUnicode) ? NSStringExt::CConverter::GetUtf8FromUTF32(&unUnicode, 1) : "") ? S_OK : S_FALSE;
|
||||
}
|
||||
HRESULT CPdfWriter::CommandDrawText(const std::wstring& wsUnicodeText, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
@ -642,6 +655,9 @@ HRESULT CPdfWriter::CommandDrawText(const std::wstring& wsUnicodeText, const dou
|
||||
return S_FALSE;
|
||||
|
||||
unsigned char* pCodes = EncodeString(pUnicodes, unLen);
|
||||
std::string sPUA;
|
||||
if (UnicodesPUA(pUnicodes, unLen))
|
||||
sPUA = NSStringExt::CConverter::GetUtf8FromUTF32(pUnicodes, unLen);
|
||||
delete[] pUnicodes;
|
||||
|
||||
if (!pCodes)
|
||||
@ -678,11 +694,12 @@ HRESULT CPdfWriter::CommandDrawText(const std::wstring& wsUnicodeText, const dou
|
||||
pText->SetMode(PdfWriter::textrenderingmode_Invisible);
|
||||
if (fabs(dStringWidth) > 0.001)
|
||||
pText->SetHorScaling(dResultWidth / dStringWidth * 100);
|
||||
pText->SetPUA(sPUA);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
return DrawText(pCodes, unLen * 2, dX, dY) ? S_OK : S_FALSE;
|
||||
return DrawText(pCodes, unLen * 2, dX, dY, sPUA) ? S_OK : S_FALSE;
|
||||
}
|
||||
HRESULT CPdfWriter::CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
@ -694,7 +711,7 @@ HRESULT CPdfWriter::CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid
|
||||
unsigned char* pCodes = EncodeGID(unGID, &unUnicode, 1);
|
||||
if (!pCodes)
|
||||
return DrawTextToRenderer(&unGID, 1, dX, dY) ? S_OK : S_FALSE;
|
||||
return DrawText(pCodes, 2, dX, dY) ? S_OK : S_FALSE;
|
||||
return DrawText(pCodes, 2, dX, dY, UnicodePUA(unUnicode) ? NSStringExt::CConverter::GetUtf8FromUTF32(&unUnicode, 1) : "") ? S_OK : S_FALSE;
|
||||
}
|
||||
HRESULT CPdfWriter::CommandDrawTextEx(const std::wstring& wsUnicodeText, const unsigned int* pGids, const unsigned int unGidsCount, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
@ -732,10 +749,13 @@ HRESULT CPdfWriter::CommandDrawTextEx(const std::wstring& wsUnicodeText, const u
|
||||
}
|
||||
|
||||
unsigned char* pCodes = EncodeString(pUnicodes, unLen, pGids);
|
||||
std::string sPUA;
|
||||
if (UnicodesPUA(pUnicodes, unLen))
|
||||
sPUA = NSStringExt::CConverter::GetUtf8FromUTF32(pUnicodes, unLen);
|
||||
RELEASEARRAYOBJECTS(pUnicodes);
|
||||
if (!pCodes)
|
||||
return DrawTextToRenderer(pGids, unGidsCount, dX, dY) ? S_OK : S_FALSE;
|
||||
return DrawText(pCodes, unLen * 2, dX, dY) ? S_OK : S_FALSE;
|
||||
return DrawText(pCodes, unLen * 2, dX, dY, sPUA) ? S_OK : S_FALSE;
|
||||
}
|
||||
HRESULT CPdfWriter::CommandDrawTextCHAR2(unsigned int* pUnicodes, const unsigned int& unUnicodeCount, const unsigned int& unGid, const double& dX, const double& dY, const double& dW, const double& dH)
|
||||
{
|
||||
@ -745,7 +765,7 @@ HRESULT CPdfWriter::CommandDrawTextCHAR2(unsigned int* pUnicodes, const unsigned
|
||||
unsigned char* pCodes = EncodeGID(unGid, pUnicodes, unUnicodeCount);
|
||||
if (!pCodes)
|
||||
return DrawTextToRenderer(&unGid, 1, dX, dY) ? S_OK : S_FALSE;
|
||||
return DrawText(pCodes, 2, dX, dY) ? S_OK : S_FALSE;
|
||||
return DrawText(pCodes, 2, dX, dY, UnicodesPUA(pUnicodes, unUnicodeCount) ? NSStringExt::CConverter::GetUtf8FromUTF32(pUnicodes, unUnicodeCount) : "") ? S_OK : S_FALSE;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
// Маркеры команд
|
||||
@ -2906,7 +2926,7 @@ PdfWriter::CImageDict* CPdfWriter::DrawImage(Aggplus::CImage* pImage, const doub
|
||||
|
||||
return pPdfImage;
|
||||
}
|
||||
bool CPdfWriter::DrawText(unsigned char* pCodes, const unsigned int& unLen, const double& dX, const double& dY)
|
||||
bool CPdfWriter::DrawText(unsigned char* pCodes, const unsigned int& unLen, const double& dX, const double& dY, const std::string& sPUA)
|
||||
{
|
||||
if (!pCodes || !unLen)
|
||||
return false;
|
||||
@ -2925,6 +2945,7 @@ bool CPdfWriter::DrawText(unsigned char* pCodes, const unsigned int& unLen, cons
|
||||
pText->SetCharSpace(MM_2_PT(m_oFont.GetCharSpace()));
|
||||
pText->SetNeedDoBold(m_oFont.IsNeedDoBold());
|
||||
pText->SetNeedDoItalic(m_oFont.IsNeedDoItalic());
|
||||
pText->SetPUA(sPUA);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -223,7 +223,7 @@ public:
|
||||
private:
|
||||
PdfWriter::CImageDict* LoadImage(Aggplus::CImage* pImage, BYTE nAlpha);
|
||||
PdfWriter::CImageDict* DrawImage(Aggplus::CImage* pImage, const double& dX, const double& dY, const double& dW, const double& dH, const BYTE& nAlpha);
|
||||
bool DrawText(unsigned char* pCodes, const unsigned int& unLen, const double& dX, const double& dY);
|
||||
bool DrawText(unsigned char* pCodes, const unsigned int& unLen, const double& dX, const double& dY, const std::string& sPUA);
|
||||
bool DrawTextToRenderer(const unsigned int* unGid, const unsigned int& unLen, const double& dX, const double& dY);
|
||||
bool PathCommandDrawText(unsigned int* pUnicodes, unsigned int unLen, const double& dX, const double& dY, const unsigned int* pGids = NULL);
|
||||
int IsEmbeddedBase14(const std::wstring& wsFontName);
|
||||
|
||||
@ -357,10 +357,14 @@ namespace PdfWriter
|
||||
pS->WriteStr(c_sToUnicodeHeader);
|
||||
pS->WriteStr(c_sToUnicodeInfo);
|
||||
|
||||
int pCodesCount = pS->Tell();
|
||||
int nCodesCount = 0;
|
||||
pS->WriteInt(m_ushCodesCount);
|
||||
pS->WriteStr(" beginbfchar\n");
|
||||
for (unsigned short ushCode = 0; ushCode < m_ushCodesCount; ushCode++)
|
||||
{
|
||||
if (!m_mGlyphs[m_vCodeToGid[ushCode]])
|
||||
continue;
|
||||
pS->WriteChar('<');
|
||||
pS->WriteHex(ushCode, 4);
|
||||
pS->WriteStr("> <");
|
||||
@ -384,9 +388,12 @@ namespace PdfWriter
|
||||
}
|
||||
|
||||
pS->WriteStr(">\n");
|
||||
nCodesCount++;
|
||||
}
|
||||
pS->WriteStr("endbfchar\n");
|
||||
m_pToUnicodeStream->WriteStr(c_sToUnicodeFooter);
|
||||
pS->WriteStr(c_sToUnicodeFooter);
|
||||
pS->Seek(pCodesCount, SeekSet);
|
||||
pS->WriteInt(nCodesCount);
|
||||
}
|
||||
void CFontCidTrueType::CloseFontFace()
|
||||
{
|
||||
@ -521,7 +528,7 @@ namespace PdfWriter
|
||||
FT_Matrix oMatrix;
|
||||
FT_Get_SubGlyph_Info(m_pFace->glyph, nSubIndex, &nSubGID, &unFlags, &nArg1, &nArg2, &oMatrix);
|
||||
|
||||
m_mGlyphs.insert(std::pair<unsigned short, bool>(nSubGID, true));
|
||||
m_mGlyphs.insert(std::pair<unsigned short, bool>(nSubGID, false));
|
||||
|
||||
EncodeGID(nSubGID, NULL, 0); // TODO необходимо верно указать Unicode для случая записи подсимволов
|
||||
FT_Load_Glyph(m_pFace, unGID, FT_LOAD_NO_SCALE | FT_LOAD_NO_RECURSE);
|
||||
|
||||
@ -171,6 +171,15 @@ void CCommandManager::Flush()
|
||||
isNeedDoItalic = pText->IsNeedDoItalic();
|
||||
}
|
||||
|
||||
if (!pText->GetPUA().empty())
|
||||
{
|
||||
oTextLine.Flush(pPage);
|
||||
PdfWriter::CDictObject* pBDC = new PdfWriter::CDictObject();
|
||||
pBDC->Add("ActualText", new PdfWriter::CStringObject(pText->GetPUA().c_str(), true));
|
||||
pPage->BeginMarkedContentDict("Span", pBDC);
|
||||
RELEASEOBJECT(pBDC);
|
||||
}
|
||||
|
||||
unsigned char* pCodes = pText->GetCodes();
|
||||
unsigned short ushCode = (pCodes[0] << 8) + pCodes[1];
|
||||
unsigned int unLen = pText->GetCodesLen();
|
||||
@ -187,6 +196,12 @@ void CCommandManager::Flush()
|
||||
pPage->DrawText(dX, dY, pCodes, unLen);
|
||||
}
|
||||
}
|
||||
|
||||
if (!pText->GetPUA().empty())
|
||||
{
|
||||
oTextLine.Flush(pPage);
|
||||
pPage->EndMarkedContent();
|
||||
}
|
||||
}
|
||||
|
||||
oTextLine.Flush(pPage);
|
||||
|
||||
@ -143,6 +143,10 @@ public:
|
||||
{
|
||||
m_bNeedDoBold = bBold;
|
||||
}
|
||||
inline void SetPUA(const std::string& sPUA)
|
||||
{
|
||||
m_sPUA = sPUA;
|
||||
}
|
||||
inline PdfWriter::CFontDict* GetFont() const
|
||||
{
|
||||
return m_pFont;
|
||||
@ -179,6 +183,10 @@ public:
|
||||
{
|
||||
return m_bNeedDoBold;
|
||||
}
|
||||
inline std::string GetPUA() const
|
||||
{
|
||||
return m_sPUA;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -196,6 +204,7 @@ private:
|
||||
double m_dCharSpace;
|
||||
int m_nMode;
|
||||
double m_dHorScaling;
|
||||
std::string m_sPUA;
|
||||
};
|
||||
struct TFontInfo
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user