mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Write Text Widget AP
This commit is contained in:
@ -959,8 +959,11 @@ void CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr::Read(NSOnlineOfficeBinToP
|
|||||||
int CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr::GetMaxLen() const { return m_nMaxLen; }
|
int CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr::GetMaxLen() const { return m_nMaxLen; }
|
||||||
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr::GetV() { return m_wsV; }
|
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr::GetV() { return m_wsV; }
|
||||||
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr::GetRV() { return m_wsRV; }
|
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr::GetRV() { return m_wsRV; }
|
||||||
const std::vector<int>& CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr::GetGID() { return m_arrGID; }
|
BYTE* CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr::GetRender(LONG& nLen)
|
||||||
const std::vector< std::pair<int, unsigned int*> >& CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr::GetUnicode() { return m_arrUnicode; }
|
{
|
||||||
|
nLen = m_nRenderLen;
|
||||||
|
return m_pRender;
|
||||||
|
}
|
||||||
void CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags, int nWidgetFlag)
|
void CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags, int nWidgetFlag)
|
||||||
{
|
{
|
||||||
if (nFlags & (1 << 9))
|
if (nFlags & (1 << 9))
|
||||||
@ -971,25 +974,22 @@ void CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr::Read(NSOnlineOfficeBinToPdf
|
|||||||
m_wsRV = pReader->ReadString();
|
m_wsRV = pReader->ReadString();
|
||||||
if (nFlags & (1 << 12))
|
if (nFlags & (1 << 12))
|
||||||
{
|
{
|
||||||
int nLen = pReader->ReadInt();
|
m_nRenderLen = pReader->ReadInt() - 4;
|
||||||
for (int i = 0; i < nLen; ++i)
|
m_pRender = pReader->GetCurrentBuffer();
|
||||||
{
|
pReader->Skip(m_nRenderLen);
|
||||||
int nGID = pReader->ReadInt();
|
|
||||||
m_arrGID.push_back(nGID);
|
|
||||||
int nLen2 = pReader->ReadInt();
|
|
||||||
m_arrUnicode.push_back(std::make_pair(nLen2, new unsigned int[nLen2]));
|
|
||||||
for (int j = 0; j < nLen2; ++j)
|
|
||||||
m_arrUnicode.back().second[j] = pReader->ReadInt();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::GetTI() const { return m_nTI; }
|
int CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::GetTI() const { return m_nTI; }
|
||||||
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::GetV() { return m_wsV; }
|
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::GetV() { return m_wsV; }
|
||||||
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::GetAPV() { return m_wsAPV; }
|
|
||||||
const std::vector<int>& CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::GetI() { return m_arrI; }
|
const std::vector<int>& CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::GetI() { return m_arrI; }
|
||||||
const std::vector<std::wstring>& CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::GetArrV() { return m_arrV; }
|
const std::vector<std::wstring>& CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::GetArrV() { return m_arrV; }
|
||||||
const std::vector< std::pair<std::wstring, std::wstring> >& CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::GetOpt() { return m_arrOpt; }
|
const std::vector< std::pair<std::wstring, std::wstring> >& CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::GetOpt() { return m_arrOpt; }
|
||||||
|
BYTE* CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::GetRender(LONG& nLen)
|
||||||
|
{
|
||||||
|
nLen = m_nRenderLen;
|
||||||
|
return m_pRender;
|
||||||
|
}
|
||||||
void CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags)
|
void CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags)
|
||||||
{
|
{
|
||||||
if (nFlags & (1 << 9))
|
if (nFlags & (1 << 9))
|
||||||
@ -1007,7 +1007,11 @@ void CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr::Read(NSOnlineOfficeBinToP
|
|||||||
if (nFlags & (1 << 11))
|
if (nFlags & (1 << 11))
|
||||||
m_nTI = pReader->ReadInt();
|
m_nTI = pReader->ReadInt();
|
||||||
if (nFlags & (1 << 12))
|
if (nFlags & (1 << 12))
|
||||||
m_wsAPV = pReader->ReadString();
|
{
|
||||||
|
m_nRenderLen = pReader->ReadInt() - 4;
|
||||||
|
m_pRender = pReader->GetCurrentBuffer();
|
||||||
|
pReader->Skip(m_nRenderLen);
|
||||||
|
}
|
||||||
if (nFlags & (1 << 13))
|
if (nFlags & (1 << 13))
|
||||||
{
|
{
|
||||||
int n = pReader->ReadInt();
|
int n = pReader->ReadInt();
|
||||||
|
|||||||
@ -85,8 +85,7 @@ public:
|
|||||||
int GetMaxLen() const;
|
int GetMaxLen() const;
|
||||||
const std::wstring& GetV();
|
const std::wstring& GetV();
|
||||||
const std::wstring& GetRV();
|
const std::wstring& GetRV();
|
||||||
const std::vector<int>& GetGID();
|
BYTE* GetRender(LONG& nLen);
|
||||||
const std::vector< std::pair<int, unsigned int*> >& GetUnicode();
|
|
||||||
|
|
||||||
void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags, int nWidgetFlag);
|
void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags, int nWidgetFlag);
|
||||||
|
|
||||||
@ -94,8 +93,8 @@ public:
|
|||||||
int m_nMaxLen;
|
int m_nMaxLen;
|
||||||
std::wstring m_wsV;
|
std::wstring m_wsV;
|
||||||
std::wstring m_wsRV;
|
std::wstring m_wsRV;
|
||||||
std::vector<int> m_arrGID;
|
LONG m_nRenderLen;
|
||||||
std::vector< std::pair<int, unsigned int*> > m_arrUnicode;
|
BYTE* m_pRender;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GRAPHICS_DECL CChoiceWidgetPr
|
class GRAPHICS_DECL CChoiceWidgetPr
|
||||||
@ -103,20 +102,21 @@ public:
|
|||||||
public:
|
public:
|
||||||
int GetTI() const;
|
int GetTI() const;
|
||||||
const std::wstring& GetV();
|
const std::wstring& GetV();
|
||||||
const std::wstring& GetAPV();
|
|
||||||
const std::vector<int>& GetI();
|
const std::vector<int>& GetI();
|
||||||
const std::vector<std::wstring>& GetArrV();
|
const std::vector<std::wstring>& GetArrV();
|
||||||
const std::vector< std::pair<std::wstring, std::wstring> >& GetOpt();
|
const std::vector< std::pair<std::wstring, std::wstring> >& GetOpt();
|
||||||
|
BYTE* GetRender(LONG& nLen);
|
||||||
|
|
||||||
void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags);
|
void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_nTI;
|
int m_nTI;
|
||||||
std::wstring m_wsV;
|
std::wstring m_wsV;
|
||||||
std::wstring m_wsAPV;
|
|
||||||
std::vector<int> m_arrI;
|
std::vector<int> m_arrI;
|
||||||
std::vector<std::wstring> m_arrV;
|
std::vector<std::wstring> m_arrV;
|
||||||
std::vector< std::pair<std::wstring, std::wstring> > m_arrOpt;
|
std::vector< std::pair<std::wstring, std::wstring> > m_arrOpt;
|
||||||
|
LONG m_nRenderLen;
|
||||||
|
BYTE* m_pRender;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GRAPHICS_DECL CSignatureWidgetPr
|
class GRAPHICS_DECL CSignatureWidgetPr
|
||||||
|
|||||||
@ -1462,9 +1462,14 @@ void CPdfEditor::EndMarkedContent()
|
|||||||
bool CPdfEditor::IsBase14(const std::wstring& wsFontName, bool& bBold, bool& bItalic, std::wstring& wsFontPath)
|
bool CPdfEditor::IsBase14(const std::wstring& wsFontName, bool& bBold, bool& bItalic, std::wstring& wsFontPath)
|
||||||
{
|
{
|
||||||
std::map<std::wstring, std::wstring>::iterator it = m_mFonts.find(wsFontName);
|
std::map<std::wstring, std::wstring>::iterator it = m_mFonts.find(wsFontName);
|
||||||
if (it == m_mFonts.end())
|
if (it != m_mFonts.end())
|
||||||
|
wsFontPath = it->second;
|
||||||
|
std::map<std::wstring, std::wstring> mFonts = pReader->GetFonts();
|
||||||
|
std::map<std::wstring, std::wstring>::iterator it2 = mFonts.find(wsFontName);
|
||||||
|
if (it2 != mFonts.end())
|
||||||
|
wsFontPath = it2->second;
|
||||||
|
if (wsFontPath.empty())
|
||||||
return false;
|
return false;
|
||||||
wsFontPath = it->second;
|
|
||||||
if (wsFontName == L"Helvetica")
|
if (wsFontName == L"Helvetica")
|
||||||
return true;
|
return true;
|
||||||
if (wsFontName == L"Helvetica-Bold")
|
if (wsFontName == L"Helvetica-Bold")
|
||||||
@ -1501,7 +1506,7 @@ bool CPdfEditor::IsBase14(const std::wstring& wsFontName, bool& bBold, bool& bIt
|
|||||||
bItalic = true;
|
bItalic = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (wsFontName == L"Times")
|
if (wsFontName == L"Times" || wsFontName == L"Times-Roman")
|
||||||
return true;
|
return true;
|
||||||
if (wsFontName == L"Times-Bold")
|
if (wsFontName == L"Times-Bold")
|
||||||
{
|
{
|
||||||
|
|||||||
@ -83,6 +83,7 @@ public:
|
|||||||
BYTE* GetAPAnnots (int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nAnnot = -1, const char* sView = NULL);
|
BYTE* GetAPAnnots (int nRasterW, int nRasterH, int nBackgroundColor, int nPageIndex, int nAnnot = -1, const char* sView = NULL);
|
||||||
BYTE* GetButtonIcon(int nBackgroundColor, int nPageIndex, bool bBase64 = false, int nBWidget = -1, const char* sIView = NULL);
|
BYTE* GetButtonIcon(int nBackgroundColor, int nPageIndex, bool bBase64 = false, int nBWidget = -1, const char* sIView = NULL);
|
||||||
std::map<std::wstring, std::wstring> GetAnnotFonts(Object* pRefAnnot);
|
std::map<std::wstring, std::wstring> GetAnnotFonts(Object* pRefAnnot);
|
||||||
|
std::map<std::wstring, std::wstring> GetFonts() { return m_mFonts; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PDFDoc* m_pPDFDocument;
|
PDFDoc* m_pPDFDocument;
|
||||||
|
|||||||
@ -2406,13 +2406,25 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
|||||||
{
|
{
|
||||||
bAPValue = true;
|
bAPValue = true;
|
||||||
pTextWidget->SetAPV();
|
pTextWidget->SetAPV();
|
||||||
|
|
||||||
|
PdfWriter::CFontCidTrueType* pWasFont = m_pFont;
|
||||||
|
|
||||||
|
LONG nLen = 0;
|
||||||
|
BYTE* pRender = pPr->GetRender(nLen);
|
||||||
|
DrawWidgetAP(pAnnot, pRender, nLen);
|
||||||
|
|
||||||
|
PdfWriter::CFontDict* pFont = NULL;
|
||||||
|
if (m_pFont14)
|
||||||
|
pFont = m_pFont14;
|
||||||
|
else if (m_pFont && m_pFont != pWasFont)
|
||||||
|
pFont = m_pDocument->CreateTrueTypeFont(m_pFont);
|
||||||
|
if (pFont)
|
||||||
|
pWidgetAnnot->SetDA(pFont, oInfo.GetWidgetAnnotPr()->GetFontSize(), dFontSize, oInfo.GetWidgetAnnotPr()->GetTC());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ВНЕШНИЙ ВИД
|
// ВНЕШНИЙ ВИД
|
||||||
pTextWidget->SetFont(m_pFont, dFontSize, isBold, isItalic);
|
pTextWidget->SetFont(m_pFont, dFontSize, isBold, isItalic);
|
||||||
if (bAPValue)
|
if (!bAPValue && bValue && pTextWidget->Get("T"))
|
||||||
DrawTextWidget(pAppFonts, pTextWidget, pPr->GetGID(), pPr->GetUnicode());
|
|
||||||
else if (bValue && pTextWidget->Get("T"))
|
|
||||||
DrawTextWidget(pAppFonts, pTextWidget, wsValue);
|
DrawTextWidget(pAppFonts, pTextWidget, wsValue);
|
||||||
}
|
}
|
||||||
else if (oInfo.IsChoiceWidget())
|
else if (oInfo.IsChoiceWidget())
|
||||||
@ -2430,8 +2442,14 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
|||||||
pChoiceWidget->SetOpt(pPr->GetOpt());
|
pChoiceWidget->SetOpt(pPr->GetOpt());
|
||||||
if (nFlags & (1 << 11))
|
if (nFlags & (1 << 11))
|
||||||
pChoiceWidget->SetTI(pPr->GetTI());
|
pChoiceWidget->SetTI(pPr->GetTI());
|
||||||
|
bool bAPValue = false;
|
||||||
if (nFlags & (1 << 12))
|
if (nFlags & (1 << 12))
|
||||||
arrValue[arrValue.size()] = pPr->GetAPV();
|
{
|
||||||
|
bAPValue = true;
|
||||||
|
LONG nLen = 0;
|
||||||
|
BYTE* pRender = pPr->GetRender(nLen);
|
||||||
|
DrawWidgetAP(pAnnot, pRender, nLen);
|
||||||
|
}
|
||||||
if (nFlags & (1 << 13))
|
if (nFlags & (1 << 13))
|
||||||
pChoiceWidget->SetV(pPr->GetArrV());
|
pChoiceWidget->SetV(pPr->GetArrV());
|
||||||
if (nFlags & (1 << 13))
|
if (nFlags & (1 << 13))
|
||||||
@ -2441,7 +2459,7 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
|||||||
|
|
||||||
// ВНЕШНИЙ ВИД
|
// ВНЕШНИЙ ВИД
|
||||||
pChoiceWidget->SetFont(m_pFont, dFontSize, isBold, isItalic);
|
pChoiceWidget->SetFont(m_pFont, dFontSize, isBold, isItalic);
|
||||||
if (!arrValue.empty())
|
if (!bAPValue && !arrValue.empty())
|
||||||
DrawChoiceWidget(pAppFonts, pChoiceWidget, arrValue);
|
DrawChoiceWidget(pAppFonts, pChoiceWidget, arrValue);
|
||||||
}
|
}
|
||||||
else if (oInfo.IsSignatureWidget())
|
else if (oInfo.IsSignatureWidget())
|
||||||
@ -2966,7 +2984,7 @@ int CPdfWriter::IsEmbeddedBase14(const std::wstring& wsName)
|
|||||||
return 6;
|
return 6;
|
||||||
if (sSub == L"Courier-BoldOblique")
|
if (sSub == L"Courier-BoldOblique")
|
||||||
return 7;
|
return 7;
|
||||||
if (sSub == L"Times")
|
if (sSub == L"Times" || sSub == L"Times-Roman")
|
||||||
return 8;
|
return 8;
|
||||||
if (sSub == L"Times-Bold")
|
if (sSub == L"Times-Bold")
|
||||||
return 9;
|
return 9;
|
||||||
@ -3621,198 +3639,39 @@ void CPdfWriter::DrawAP(PdfWriter::CAnnotation* pAnnot, BYTE* pRender, LONG nLen
|
|||||||
m_pDocument->SetCurPage(pCurPage);
|
m_pDocument->SetCurPage(pCurPage);
|
||||||
RELEASEOBJECT(pFakePage);
|
RELEASEOBJECT(pFakePage);
|
||||||
}
|
}
|
||||||
void CPdfWriter::DrawTextWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CTextWidget* pTextWidget, const std::vector<int>& arrGID, const std::vector< std::pair<int, unsigned int*> >& arrUnicode)
|
void CPdfWriter::DrawWidgetAP(PdfWriter::CAnnotation* pA, BYTE* pRender, LONG nLenRender)
|
||||||
{
|
{
|
||||||
if (!pAppFonts || !pTextWidget)
|
if (!pA || !pRender)
|
||||||
return;
|
return;
|
||||||
PdfWriter::CFontCidTrueType* pFont = pTextWidget->GetFont();
|
|
||||||
if (!pFont)
|
|
||||||
return;
|
|
||||||
PdfWriter::CFontTrueType* pFontTT = m_pDocument->CreateTrueTypeFont(pFont);
|
|
||||||
double dFontSize = pTextWidget->GetFontSize();
|
|
||||||
bool isBold = pTextWidget->GetFontIsBold();
|
|
||||||
bool isItalic = pTextWidget->GetFontIsItalic();
|
|
||||||
bool isComb = pTextWidget->IsCombFlag();
|
|
||||||
double dWidth = pTextWidget->GetWidth();
|
|
||||||
double dHeight = pTextWidget->GetHeight();
|
|
||||||
BYTE nAlign = pTextWidget->GetQ();
|
|
||||||
|
|
||||||
if (!pTextWidget->HaveBorder() && pTextWidget->HaveBC())
|
PdfWriter::CWidgetAnnotation* pAnnot = (PdfWriter::CWidgetAnnotation*)pA;
|
||||||
pTextWidget->SetBorder(0, 1, {});
|
|
||||||
double dShiftBorder = pTextWidget->GetBorderWidth();
|
|
||||||
BYTE nType = pTextWidget->GetBorderType();
|
|
||||||
if (nType == 1 || nType == 3)
|
|
||||||
dShiftBorder *= 2;
|
|
||||||
|
|
||||||
// Коды, шрифты, количество
|
PdfWriter::CPage* pCurPage = m_pPage;
|
||||||
unsigned int unLen = arrGID.size();
|
PdfWriter::CPage* pFakePage = m_pDocument->CreateFakePage();
|
||||||
unsigned int* pUnicodes = new unsigned int[unLen];
|
m_pPage = pFakePage;
|
||||||
unsigned short* pCodes = new unsigned short[unLen];
|
m_pDocument->SetCurPage(pFakePage);
|
||||||
PdfWriter::CFontCidTrueType** ppFonts = new PdfWriter::CFontCidTrueType*[unLen];
|
m_oTransform.Set(1, 0, 0, 1, PT_2_MM(-pAnnot->GetPageX() - pAnnot->GetRect().fLeft), PT_2_MM(pAnnot->GetRect().fBottom));
|
||||||
|
|
||||||
for (unsigned int i = 0; i < unLen; ++i)
|
PdfWriter::CAnnotAppearanceObject* pAP = pAnnot->StartAP();
|
||||||
{
|
pAP->EndText();
|
||||||
//unsigned char* pCodes = new unsigned char[2];
|
|
||||||
unsigned short ushCode = pFont->EncodeGID(arrGID[i], arrUnicode[i].second, arrUnicode[i].first);
|
|
||||||
//pCodes[0] = (ushCode >> 8) & 0xFF;
|
|
||||||
//pCodes[1] = ushCode & 0xFF;
|
|
||||||
|
|
||||||
//unsigned char* pCodes = EncodeGID(arrGID->at(i).first, pUnicodes, unUnicodeCount);
|
pFakePage->SetStream(pAP->GetStream());
|
||||||
|
pFakePage->Add("Resources", (PdfWriter::CObjectBase*)m_pDocument->GetFieldsResources());
|
||||||
|
|
||||||
/*
|
IMetafileToRenderter* pCorrector = new IMetafileToRenderter(m_pRenderer);
|
||||||
unsigned int unUnicode = pUnicodes[unIndex];
|
NSOnlineOfficeBinToPdf::ConvertBufferToRenderer(pRender, nLenRender, pCorrector);
|
||||||
|
RELEASEOBJECT(pCorrector);
|
||||||
|
|
||||||
if (!pFont->HaveChar(unUnicode))
|
m_oCommandManager.Flush();
|
||||||
{
|
|
||||||
std::wstring wsFontFamily = pAppFonts->GetFontBySymbol(unUnicode);
|
|
||||||
PdfWriter::CFontCidTrueType* pTempFont = GetFont(wsFontFamily, bBold, bItalic);
|
|
||||||
if (pTempFont)
|
|
||||||
{
|
|
||||||
pCodes[unIndex] = pTempFont->EncodeUnicode(unUnicode);
|
|
||||||
ppFonts[unIndex] = pTempFont;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
pCodes[i] = ushCode;
|
|
||||||
ppFonts[i] = pFont;
|
|
||||||
|
|
||||||
pUnicodes[i] = arrUnicode[i].second[0];
|
pAP->StartText(NULL, 10);
|
||||||
}
|
pAnnot->EndAP();
|
||||||
|
|
||||||
bool bFont = true;
|
pAnnot->APFromFakePage(pFakePage);
|
||||||
//GetFontData(pAppFonts, wsValue, pFont, isBold, isItalic, pUnicodes, unLen, pCodes, ppFonts);
|
|
||||||
if (!bFont)
|
|
||||||
{
|
|
||||||
pTextWidget->SetEmptyAP();
|
|
||||||
RELEASEARRAYOBJECTS(pUnicodes);
|
|
||||||
RELEASEARRAYOBJECTS(pCodes);
|
|
||||||
RELEASEARRAYOBJECTS(ppFonts);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isComb && pTextWidget->IsMultiLine() && pFontTT)
|
m_pPage = pCurPage;
|
||||||
{
|
m_pDocument->SetCurPage(pCurPage);
|
||||||
unsigned short* pCodes2 = new unsigned short[unLen];
|
RELEASEOBJECT(pFakePage);
|
||||||
unsigned int* pWidths = new unsigned int[unLen];
|
|
||||||
|
|
||||||
unsigned short ushSpaceCode = 0xFFFF;
|
|
||||||
unsigned short ushNewLineCode = 0xFFFE;
|
|
||||||
for (unsigned int unIndex = 0; unIndex < unLen; ++unIndex)
|
|
||||||
{
|
|
||||||
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, ushNewLineCode, pFontTT->GetLineHeight(), pFontTT->GetAscent());
|
|
||||||
|
|
||||||
double dKoef = dFontSize / pFontTT->m_dUnitsPerEm;
|
|
||||||
double dLineHeight = (pFontTT->m_dAscent + std::abs(pFontTT->m_dDescent)) * dKoef;
|
|
||||||
|
|
||||||
m_oLinesManager.CalculateLines(dFontSize, dWidth - dShiftBorder * 4);
|
|
||||||
|
|
||||||
pTextWidget->StartAP();
|
|
||||||
|
|
||||||
unsigned int unLinesCount = m_oLinesManager.GetLinesCount();
|
|
||||||
double dLineShiftY = dHeight - dShiftBorder * 2 - dLineHeight;
|
|
||||||
for (unsigned int unIndex = 0; unIndex < unLinesCount; ++unIndex)
|
|
||||||
{
|
|
||||||
unsigned int unLineStart = m_oLinesManager.GetLineStartPos(unIndex);
|
|
||||||
double dLineShiftX = dShiftBorder * 2;
|
|
||||||
double dLineWidth = m_oLinesManager.GetLineWidth(unIndex, dFontSize);
|
|
||||||
if (2 == nAlign)
|
|
||||||
dLineShiftX = dWidth - dLineWidth - dShiftBorder * 2;
|
|
||||||
else if (1 == nAlign)
|
|
||||||
dLineShiftX = (dWidth - dLineWidth) / 2;
|
|
||||||
|
|
||||||
int nInLineCount = m_oLinesManager.GetLineEndPos(unIndex) - m_oLinesManager.GetLineStartPos(unIndex);
|
|
||||||
if (nInLineCount > 0)
|
|
||||||
pTextWidget->AddLineToAP(dLineShiftX, dLineShiftY, pCodes + unLineStart, nInLineCount, ppFonts + unLineStart, NULL);
|
|
||||||
|
|
||||||
dLineShiftY -= dLineHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
pTextWidget->EndAP();
|
|
||||||
|
|
||||||
m_oLinesManager.Clear();
|
|
||||||
|
|
||||||
RELEASEARRAYOBJECTS(pCodes2);
|
|
||||||
RELEASEARRAYOBJECTS(pWidths);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
double* pShifts = NULL;
|
|
||||||
unsigned int unShiftsCount = 0;
|
|
||||||
double dShiftX = dShiftBorder * 2;
|
|
||||||
if (dShiftX == 0)
|
|
||||||
dShiftX = 2;
|
|
||||||
|
|
||||||
if (isComb)
|
|
||||||
{
|
|
||||||
unShiftsCount = unLen;
|
|
||||||
pShifts = new double[unShiftsCount];
|
|
||||||
if (pShifts && unShiftsCount)
|
|
||||||
{
|
|
||||||
dShiftX = 0;
|
|
||||||
unsigned int unCellsCount = std::max(unShiftsCount, pTextWidget->GetMaxLen());
|
|
||||||
double dPrevW = 0;
|
|
||||||
double dCellW = dWidth / unCellsCount;
|
|
||||||
|
|
||||||
if (1 == nAlign)
|
|
||||||
{
|
|
||||||
unsigned int unCells = (unCellsCount - unShiftsCount) / 2;
|
|
||||||
dPrevW = unCells * dCellW;
|
|
||||||
}
|
|
||||||
if (2 == nAlign)
|
|
||||||
dPrevW = (unCellsCount - unShiftsCount) * dCellW;
|
|
||||||
|
|
||||||
for (unsigned int unIndex = 0; unIndex < unShiftsCount; ++unIndex)
|
|
||||||
{
|
|
||||||
unsigned short ushCode = pCodes[unIndex];
|
|
||||||
double dGlyphWidth = ppFonts[unIndex]->GetGlyphWidth(ushCode) / 1000.0 * dFontSize;
|
|
||||||
double dTempShift = (dCellW - dGlyphWidth) / 2;
|
|
||||||
pShifts[unIndex] = dPrevW + dTempShift;
|
|
||||||
dPrevW = dCellW - dTempShift;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (1 == nAlign || 2 == nAlign)
|
|
||||||
{
|
|
||||||
double dLineWidth = 0;
|
|
||||||
for (unsigned int unIndex = 0; unIndex < unLen; ++unIndex)
|
|
||||||
{
|
|
||||||
unsigned short ushCode = pCodes[unIndex];
|
|
||||||
double dLetterWidth = ppFonts[unIndex]->GetWidth(ushCode) / 1000.0 * dFontSize;
|
|
||||||
dLineWidth += dLetterWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (2 == nAlign)
|
|
||||||
dShiftX = dWidth - dLineWidth - dShiftBorder * 2;
|
|
||||||
else if (1 == nAlign)
|
|
||||||
dShiftX = (dWidth - dLineWidth) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
double dBaseLine = (dHeight - dFontSize) / 2.0 - dShiftBorder;
|
|
||||||
if (pFontTT)
|
|
||||||
{
|
|
||||||
double dKoef = dFontSize / pFontTT->m_dUnitsPerEm;
|
|
||||||
double dLineHeight = (pFontTT->m_dAscent + std::abs(pFontTT->m_dDescent)) * dKoef;;
|
|
||||||
dBaseLine = (dHeight - dLineHeight) / 2.0 + std::abs(pFontTT->m_dDescent * dKoef);
|
|
||||||
}
|
|
||||||
|
|
||||||
pTextWidget->SetAP(L"", pCodes, unLen, dShiftX, dBaseLine, ppFonts, pShifts);
|
|
||||||
RELEASEARRAYOBJECTS(pShifts);
|
|
||||||
}
|
|
||||||
|
|
||||||
RELEASEARRAYOBJECTS(pUnicodes);
|
|
||||||
RELEASEARRAYOBJECTS(pCodes);
|
|
||||||
RELEASEARRAYOBJECTS(ppFonts);
|
|
||||||
}
|
}
|
||||||
void CPdfWriter::DrawTextWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CTextWidget* pTextWidget, const std::wstring& wsValue)
|
void CPdfWriter::DrawTextWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CTextWidget* pTextWidget, const std::wstring& wsValue)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -247,8 +247,8 @@ private:
|
|||||||
unsigned char* EncodeGID(const unsigned int& unGID, const unsigned int* pUnicodes, const unsigned int& unUnicodesCount);
|
unsigned char* EncodeGID(const unsigned int& unGID, const unsigned int* pUnicodes, const unsigned int& unUnicodesCount);
|
||||||
std::wstring GetDownloadFile(const std::wstring& sUrl, const std::wstring& wsTempDirectory);
|
std::wstring GetDownloadFile(const std::wstring& sUrl, const std::wstring& wsTempDirectory);
|
||||||
void DrawAP(PdfWriter::CAnnotation* pAnnot, BYTE* pRender, LONG nLenRender);
|
void DrawAP(PdfWriter::CAnnotation* pAnnot, BYTE* pRender, LONG nLenRender);
|
||||||
|
void DrawWidgetAP(PdfWriter::CAnnotation* pAnnot, BYTE* pRender, LONG nLenRender);
|
||||||
void DrawTextWidget (NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CTextWidget* pTextWidget, const std::wstring& wsValue);
|
void DrawTextWidget (NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CTextWidget* pTextWidget, const std::wstring& wsValue);
|
||||||
void DrawTextWidget (NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CTextWidget* pTextWidget, const std::vector<int>& arrGID, const std::vector< std::pair<int, unsigned int*> >& arrUnicode);
|
|
||||||
void DrawChoiceWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CChoiceWidget* pChoiceWidget, const std::vector<std::wstring>& arrValue);
|
void DrawChoiceWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CChoiceWidget* pChoiceWidget, const std::vector<std::wstring>& arrValue);
|
||||||
void DrawButtonWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CPushButtonWidget* pButtonWidget, BYTE nAP, PdfWriter::CXObject* pForm);
|
void DrawButtonWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CPushButtonWidget* pButtonWidget, BYTE nAP, PdfWriter::CXObject* pForm);
|
||||||
|
|
||||||
|
|||||||
@ -1654,6 +1654,22 @@ namespace PdfWriter
|
|||||||
CObjectBase* pObj = m_pMK->Get("BC");
|
CObjectBase* pObj = m_pMK->Get("BC");
|
||||||
return pObj && pObj->GetType() == object_type_ARRAY;
|
return pObj && pObj->GetType() == object_type_ARRAY;
|
||||||
}
|
}
|
||||||
|
void CWidgetAnnotation::APFromFakePage(CPage* pFakePage)
|
||||||
|
{
|
||||||
|
if (!m_pAppearance)
|
||||||
|
return;
|
||||||
|
CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal();
|
||||||
|
|
||||||
|
CArrayObject* pArray = new CArrayObject();
|
||||||
|
if (!pArray)
|
||||||
|
return;
|
||||||
|
pNormal->Add("BBox", pArray);
|
||||||
|
|
||||||
|
pArray->Add(0);
|
||||||
|
pArray->Add(0);
|
||||||
|
pArray->Add(GetWidth());
|
||||||
|
pArray->Add(GetHeight());
|
||||||
|
}
|
||||||
void CWidgetAnnotation::SetEmptyAP()
|
void CWidgetAnnotation::SetEmptyAP()
|
||||||
{
|
{
|
||||||
if (!m_pAppearance)
|
if (!m_pAppearance)
|
||||||
@ -1675,14 +1691,15 @@ namespace PdfWriter
|
|||||||
CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal();
|
CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal();
|
||||||
pNormal->DrawSimpleText(wsValue, pCodes, unCount, m_pFont, m_dFontSize, dX, dY, 0, 0, 0, NULL, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop), ppFonts, pShifts);
|
pNormal->DrawSimpleText(wsValue, pCodes, unCount, m_pFont, m_dFontSize, dX, dY, 0, 0, 0, NULL, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop), ppFonts, pShifts);
|
||||||
}
|
}
|
||||||
void CWidgetAnnotation::StartAP()
|
CAnnotAppearanceObject* CWidgetAnnotation::StartAP()
|
||||||
{
|
{
|
||||||
m_pAppearance = new CAnnotAppearance(m_pXref, this);
|
m_pAppearance = new CAnnotAppearance(m_pXref, this);
|
||||||
if (!m_pAppearance)
|
if (!m_pAppearance)
|
||||||
return;
|
return NULL;
|
||||||
Add("AP", m_pAppearance);
|
Add("AP", m_pAppearance);
|
||||||
CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal();
|
CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal();
|
||||||
pNormal->StartDrawText(m_pFont, m_dFontSize, 0, 0, 0, NULL, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop));
|
pNormal->StartDrawText(m_pFont, m_dFontSize, 0, 0, 0, NULL, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop));
|
||||||
|
return pNormal;
|
||||||
}
|
}
|
||||||
void CWidgetAnnotation::AddLineToAP(const double& dX, const double& dY, unsigned short* pCodes, const unsigned int& unCodesCount, CFontCidTrueType** ppFonts, const double* pShifts)
|
void CWidgetAnnotation::AddLineToAP(const double& dX, const double& dY, unsigned short* pCodes, const unsigned int& unCodesCount, CFontCidTrueType** ppFonts, const double* pShifts)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -459,9 +459,10 @@ namespace PdfWriter
|
|||||||
bool HaveBC();
|
bool HaveBC();
|
||||||
BYTE GetQ() { return m_nQ; }
|
BYTE GetQ() { return m_nQ; }
|
||||||
|
|
||||||
|
void APFromFakePage(CPage* pFakePage);
|
||||||
void SetEmptyAP();
|
void SetEmptyAP();
|
||||||
void SetAP(const std::wstring& wsValue, unsigned short* pCodes, unsigned int unCount, double dX, double dY, CFontCidTrueType** ppFonts, double* pShifts);
|
void SetAP(const std::wstring& wsValue, unsigned short* pCodes, unsigned int unCount, double dX, double dY, CFontCidTrueType** ppFonts, double* pShifts);
|
||||||
void StartAP();
|
CAnnotAppearanceObject* StartAP();
|
||||||
void AddLineToAP(const double& dX, const double& dY, unsigned short* pCodes, const unsigned int& unCodesCount, CFontCidTrueType** ppFonts = NULL, const double* pShifts = NULL);
|
void AddLineToAP(const double& dX, const double& dY, unsigned short* pCodes, const unsigned int& unCodesCount, CFontCidTrueType** ppFonts = NULL, const double* pShifts = NULL);
|
||||||
void EndAP();
|
void EndAP();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1513,7 +1513,7 @@ namespace PdfWriter
|
|||||||
}
|
}
|
||||||
CPage* CDocument::CreateFakePage()
|
CPage* CDocument::CreateFakePage()
|
||||||
{
|
{
|
||||||
return new CPage(this, m_pXref);
|
return new CPage(this, NULL);
|
||||||
}
|
}
|
||||||
bool CDocument::EditCO(const std::vector<int>& arrCO)
|
bool CDocument::EditCO(const std::vector<int>& arrCO)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1930,7 +1930,7 @@ namespace PdfWriter
|
|||||||
void CAnnotAppearanceObject::StartDrawText(CFontDict* pFont, const double& dFontSize, const double& dR, const double& dG, const double& dB, const char* sExtGStateName, const double& dWidth, const double& dHeight)
|
void CAnnotAppearanceObject::StartDrawText(CFontDict* pFont, const double& dFontSize, const double& dR, const double& dG, const double& dB, const char* sExtGStateName, const double& dWidth, const double& dHeight)
|
||||||
{
|
{
|
||||||
CResourcesDict* pResources = dynamic_cast<CResourcesDict*>(Get("Resources"));
|
CResourcesDict* pResources = dynamic_cast<CResourcesDict*>(Get("Resources"));
|
||||||
if (!m_pStream || !pFont || !pResources)
|
if (!m_pStream || !pResources)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CWidgetAnnotation* pAnnot = NULL;
|
CWidgetAnnotation* pAnnot = NULL;
|
||||||
@ -2221,7 +2221,7 @@ namespace PdfWriter
|
|||||||
m_pStream->WriteReal(m_dFontSize);
|
m_pStream->WriteReal(m_dFontSize);
|
||||||
m_pStream->WriteStr(" Tf\012");
|
m_pStream->WriteStr(" Tf\012");
|
||||||
}
|
}
|
||||||
else
|
else if (pFont)
|
||||||
m_pStream->WriteStr(pAnnot->GetDAforAP(pFont).c_str());
|
m_pStream->WriteStr(pAnnot->GetDAforAP(pFont).c_str());
|
||||||
|
|
||||||
m_bStart = true;
|
m_bStart = true;
|
||||||
@ -2288,7 +2288,8 @@ namespace PdfWriter
|
|||||||
m_bStart = true;
|
m_bStart = true;
|
||||||
|
|
||||||
m_pStream->WriteStr("BT\012");
|
m_pStream->WriteStr("BT\012");
|
||||||
m_pStream->WriteStr(pAnnot->GetDAforAP(pFont).c_str());
|
if (pFont)
|
||||||
|
m_pStream->WriteStr(pAnnot->GetDAforAP(pFont).c_str());
|
||||||
}
|
}
|
||||||
void CAnnotAppearanceObject::DrawPictureInline(const char* sImageName, const double& dX, const double& dY, const double& dW, const double& dH, const bool& bRespectBorder)
|
void CAnnotAppearanceObject::DrawPictureInline(const char* sImageName, const double& dX, const double& dY, const double& dW, const double& dH, const bool& bRespectBorder)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -417,7 +417,7 @@ namespace PdfWriter
|
|||||||
void DrawTextUpArrow(const std::string& sColor);
|
void DrawTextUpArrow(const std::string& sColor);
|
||||||
void DrawTextUpLeftArrow(const std::string& sColor);
|
void DrawTextUpLeftArrow(const std::string& sColor);
|
||||||
|
|
||||||
CStream* GetStream() { return m_pStream; }
|
CStream* GetStream() const { return m_pStream; }
|
||||||
CFontDict* GetFont() { return m_pFont; }
|
CFontDict* GetFont() { return m_pFont; }
|
||||||
|
|
||||||
bool m_bStart;
|
bool m_bStart;
|
||||||
|
|||||||
@ -452,11 +452,11 @@ namespace PdfWriter
|
|||||||
void Add(const std::string& sKey, double dReal);
|
void Add(const std::string& sKey, double dReal);
|
||||||
void Add(const std::string& sKey, bool bBool);
|
void Add(const std::string& sKey, bool bBool);
|
||||||
const char* GetKey(const CObjectBase* pObject);
|
const char* GetKey(const CObjectBase* pObject);
|
||||||
CStream* GetStream() const
|
virtual CStream* GetStream() const
|
||||||
{
|
{
|
||||||
return m_pStream;
|
return m_pStream;
|
||||||
}
|
}
|
||||||
void SetStream(CStream* pStream);
|
virtual void SetStream(CStream* pStream);
|
||||||
unsigned int GetFilter() const
|
unsigned int GetFilter() const
|
||||||
{
|
{
|
||||||
return m_unFilter;
|
return m_unFilter;
|
||||||
|
|||||||
@ -105,6 +105,14 @@ namespace PdfWriter
|
|||||||
{
|
{
|
||||||
return dict_type_PAGE;
|
return dict_type_PAGE;
|
||||||
}
|
}
|
||||||
|
CStream* GetStream() const
|
||||||
|
{
|
||||||
|
return m_pStream;
|
||||||
|
}
|
||||||
|
void SetStream(CStream* pStream)
|
||||||
|
{
|
||||||
|
m_pStream = pStream;
|
||||||
|
}
|
||||||
void BeforeWrite();
|
void BeforeWrite();
|
||||||
|
|
||||||
void MoveTo(double dX, double dY);
|
void MoveTo(double dX, double dY);
|
||||||
|
|||||||
@ -374,6 +374,8 @@ TEST_F(CPdfFileTest, EditPdfFromBase64)
|
|||||||
{
|
{
|
||||||
//GTEST_SKIP();
|
//GTEST_SKIP();
|
||||||
|
|
||||||
|
NSFonts::NSApplicationFontStream::SetGlobalMemoryStorage(NSFonts::NSApplicationFontStream::CreateDefaultGlobalMemoryStorage());
|
||||||
|
|
||||||
LoadFromFile();
|
LoadFromFile();
|
||||||
ASSERT_TRUE(pdfFile->EditPdf(wsDstFile));
|
ASSERT_TRUE(pdfFile->EditPdf(wsDstFile));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user