mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
PathCommandText for CPdfWriter
analogue of PathCommandText from graphic renderer for CPdfWriter
This commit is contained in:
@ -52,6 +52,7 @@
|
||||
#include "../../DesktopEditor/graphics/pro/Image.h"
|
||||
#include "../../DesktopEditor/common/StringExt.h"
|
||||
#include "../../DesktopEditor/graphics/FormField.h"
|
||||
#include "../../DesktopEditor/graphics/GraphicsPath.h"
|
||||
|
||||
#include "../../UnicodeConverter/UnicodeConverter.h"
|
||||
#include "../../Common/Network/FileTransporter/include/FileTransporter.h"
|
||||
@ -95,13 +96,14 @@ static const long c_BrushTypeRadialGradient = 8002;
|
||||
// CPdfRenderer
|
||||
//
|
||||
//----------------------------------------------------------------------------------------
|
||||
CPdfWriter::CPdfWriter(NSFonts::IApplicationFonts* pAppFonts, bool isPDFA) : m_oCommandManager(this)
|
||||
CPdfWriter::CPdfWriter(NSFonts::IApplicationFonts* pAppFonts, bool isPDFA, IRenderer* pRenderer) : m_oCommandManager(this)
|
||||
{
|
||||
// Создаем менеджер шрифтов с собственным кэшем
|
||||
m_pFontManager = pAppFonts->GenerateFontManager();
|
||||
NSFonts::IFontsCache* pMeasurerCache = NSFonts::NSFontCache::Create();
|
||||
pMeasurerCache->SetStreams(pAppFonts->GetStreams());
|
||||
m_pFontManager->SetOwnerCache(pMeasurerCache);
|
||||
m_pRenderer = pRenderer;
|
||||
|
||||
m_pDocument = new PdfWriter::CDocument();
|
||||
|
||||
@ -630,6 +632,8 @@ HRESULT CPdfWriter::CommandDrawTextExCHAR(const LONG& lUnicode, const LONG& lGid
|
||||
unsigned int unUnicode = lUnicode;
|
||||
unsigned int unGID = 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;
|
||||
}
|
||||
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)
|
||||
@ -667,8 +671,10 @@ HRESULT CPdfWriter::CommandDrawTextEx(const std::wstring& wsUnicodeText, const u
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
unsigned char* pCodes = EncodeString(pUnicodes, unLen, pGids);
|
||||
unsigned char* pCodes = EncodeString(pUnicodes, unLen, pGids);
|
||||
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;
|
||||
}
|
||||
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)
|
||||
@ -677,6 +683,8 @@ HRESULT CPdfWriter::CommandDrawTextCHAR2(unsigned int* pUnicodes, const unsigned
|
||||
return S_FALSE;
|
||||
|
||||
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;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -1810,6 +1818,20 @@ bool CPdfWriter::DrawText(unsigned char* pCodes, const unsigned int& unLen, cons
|
||||
|
||||
return true;
|
||||
}
|
||||
bool CPdfWriter::DrawTextToRenderer(const unsigned int* unGid, const unsigned int& unLen, const double& dX, const double& dY)
|
||||
{
|
||||
Aggplus::CGraphicsPathSimpleConverter simplifier;
|
||||
simplifier.SetRenderer(m_pRenderer);
|
||||
m_pFontManager->LoadFontByName(m_oFont.GetName(), m_oFont.GetSize(), (int)m_oFont.GetFaceIndex(), 72.0, 72.0);
|
||||
PathCommandEnd();
|
||||
if (simplifier.PathCommandText2(L"", (const int*)unGid, unLen, m_pFontManager, dX, dY, 0, 0))
|
||||
{
|
||||
DrawPath(NULL, L"", c_nWindingFillMode);
|
||||
PathCommandEnd();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool CPdfWriter::PathCommandDrawText(unsigned int* pUnicodes, unsigned int unLen, const double& dX, const double& dY, const unsigned int* pGids)
|
||||
{
|
||||
unsigned char* pCodes = EncodeString(pUnicodes, unLen, pGids);
|
||||
@ -1819,13 +1841,16 @@ bool CPdfWriter::PathCommandDrawText(unsigned int* pUnicodes, unsigned int unLen
|
||||
m_oPath.AddText(m_pFont, pCodes, unLen * 2, MM_2_PT(dX), MM_2_PT(m_dPageHeight - dY), m_oFont.GetSize(), MM_2_PT(m_oFont.GetCharSpace()));
|
||||
return true;
|
||||
}
|
||||
void CPdfWriter::UpdateFont()
|
||||
bool CPdfWriter::UpdateFont()
|
||||
{
|
||||
m_bNeedUpdateTextFont = false;
|
||||
std::wstring wsFontPath = m_oFont.GetPath();
|
||||
LONG lFaceIndex = m_oFont.GetFaceIndex();
|
||||
if (L"" == wsFontPath)
|
||||
GetFontPath(m_oFont.GetName(), m_oFont.IsBold(), m_oFont.IsItalic(), wsFontPath, lFaceIndex);
|
||||
{
|
||||
if (!GetFontPath(m_oFont.GetName(), m_oFont.IsBold(), m_oFont.IsItalic(), wsFontPath, lFaceIndex))
|
||||
return false;
|
||||
}
|
||||
|
||||
m_oFont.SetNeedDoBold(false);
|
||||
m_oFont.SetNeedDoItalic(false);
|
||||
@ -1843,8 +1868,9 @@ void CPdfWriter::UpdateFont()
|
||||
m_oFont.SetNeedDoBold(true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void CPdfWriter::GetFontPath(const std::wstring &wsFontName, const bool &bBold, const bool &bItalic, std::wstring& wsFontPath, LONG& lFaceIndex)
|
||||
bool CPdfWriter::GetFontPath(const std::wstring &wsFontName, const bool &bBold, const bool &bItalic, std::wstring& wsFontPath, LONG& lFaceIndex)
|
||||
{
|
||||
bool bFind = false;
|
||||
for (int nIndex = 0, nCount = m_vFonts.size(); nIndex < nCount; nIndex++)
|
||||
@ -1868,6 +1894,8 @@ void CPdfWriter::GetFontPath(const std::wstring &wsFontName, const bool &bBold,
|
||||
NSFonts::CFontInfo* pFontInfo = m_pFontManager->GetFontInfoByParams(oFontSelect, false);
|
||||
if (!NSFonts::CFontInfo::CanEmbedForPreviewAndPrint(pFontInfo->m_usType))
|
||||
{
|
||||
return false;
|
||||
|
||||
oFontSelect.Fill(pFontInfo);
|
||||
if (NULL != oFontSelect.usType)
|
||||
*oFontSelect.usType = NSFONTS_EMBEDDING_RIGHTS_PRINT_AND_PREVIEW;
|
||||
@ -1882,6 +1910,7 @@ void CPdfWriter::GetFontPath(const std::wstring &wsFontName, const bool &bBold,
|
||||
|
||||
m_vFonts.push_back(TFontInfo(wsFontName, bBold, bItalic, wsFontPath, lFaceIndex));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
PdfWriter::CFontCidTrueType* CPdfWriter::GetFont(const std::wstring& wsFontPath, const LONG& lFaceIndex)
|
||||
{
|
||||
@ -2220,7 +2249,10 @@ void CPdfWriter::SetError()
|
||||
unsigned char* CPdfWriter::EncodeString(const unsigned int *pUnicodes, const unsigned int& unCount, const unsigned int *pGIDs)
|
||||
{
|
||||
if (m_bNeedUpdateTextFont)
|
||||
UpdateFont();
|
||||
{
|
||||
if (!UpdateFont())
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!m_pFont)
|
||||
return NULL;
|
||||
@ -2246,7 +2278,10 @@ unsigned char* CPdfWriter::EncodeString(const unsigned int *pUnicodes, const uns
|
||||
unsigned char* CPdfWriter::EncodeGID(const unsigned int& unGID, const unsigned int* pUnicodes, const unsigned int& unUnicodesCount)
|
||||
{
|
||||
if (m_bNeedUpdateTextFont)
|
||||
UpdateFont();
|
||||
{
|
||||
if (!UpdateFont())
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!m_pFont)
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user