mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Write combobox/listbox forms
This commit is contained in:
@ -2233,37 +2233,27 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
||||
CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr* pPr = oInfo.GetWidgetAnnotPr()->GetChoiceWidgetPr();
|
||||
PdfWriter::CChoiceWidget* pChoiceWidget = (PdfWriter::CChoiceWidget*)pAnnot;
|
||||
|
||||
std::wstring wsValue;
|
||||
std::vector<std::wstring> arrValue;
|
||||
if (nFlags & (1 << 9))
|
||||
{
|
||||
wsValue = pPr->GetV();
|
||||
pChoiceWidget->SetV(wsValue);
|
||||
arrValue.push_back(pPr->GetV());
|
||||
pChoiceWidget->SetV(arrValue.back());
|
||||
}
|
||||
if (nFlags & (1 << 10))
|
||||
pChoiceWidget->SetOpt(pPr->GetOpt());
|
||||
if (nFlags & (1 << 11))
|
||||
pChoiceWidget->SetTI(pPr->GetTI());
|
||||
if (nFlags & (1 << 12))
|
||||
wsValue = pPr->GetAPV();
|
||||
arrValue[arrValue.size()] = pPr->GetAPV();
|
||||
if (nFlags & (1 << 13))
|
||||
pChoiceWidget->SetV(pPr->GetArrV());
|
||||
if (nFlags & (1 << 13))
|
||||
pChoiceWidget->SetI(pPr->GetI());
|
||||
|
||||
pChoiceWidget->SetFont(m_pFont, m_oFont.GetSize(), isBold, isItalic);
|
||||
|
||||
// ВНЕШНИЙ ВИД
|
||||
unsigned int unLen = 0;
|
||||
unsigned int* pUnicodes = NULL;
|
||||
unsigned short* pCodes = NULL;
|
||||
PdfWriter::CFontCidTrueType** ppFonts = NULL;
|
||||
bool bFont = GetFontData(pAppFonts, wsValue, m_pFont, isBold, isItalic, pUnicodes, unLen, pCodes, ppFonts);
|
||||
if (bFont)
|
||||
pChoiceWidget->SetTextAppearance(wsValue, pCodes, unLen, 0, dY2 - dY1 - dFontSize - 2, ppFonts);
|
||||
|
||||
RELEASEARRAYOBJECTS(pUnicodes);
|
||||
RELEASEARRAYOBJECTS(pCodes);
|
||||
RELEASEARRAYOBJECTS(ppFonts);
|
||||
pChoiceWidget->SetFont(m_pFont, dFontSize, isBold, isItalic);
|
||||
if (!arrValue.empty())
|
||||
DrawChoiceWidget(pAppFonts, pChoiceWidget, arrValue);
|
||||
}
|
||||
else if (oInfo.IsSignatureWidget())
|
||||
{
|
||||
@ -2379,20 +2369,7 @@ HRESULT CPdfWriter::EditWidgetParents(NSFonts::IApplicationFonts* pAppFonts, CWi
|
||||
if (nType == PdfWriter::WidgetCombobox || nType == PdfWriter::WidgetListbox)
|
||||
{
|
||||
PdfWriter::CChoiceWidget* pKid = dynamic_cast<PdfWriter::CChoiceWidget*>(pObj);
|
||||
|
||||
std::wstring wsValue = pParent->sV;
|
||||
// ВНЕШНИЙ ВИД
|
||||
unsigned int unLen = 0;
|
||||
unsigned int* pUnicodes = NULL;
|
||||
unsigned short* pCodes = NULL;
|
||||
PdfWriter::CFontCidTrueType** ppFonts = NULL;
|
||||
bool bFont = GetFontData(pAppFonts, wsValue, pKid->GetFont(), pKid->GetFontIsBold(), pKid->GetFontIsItalic(), pUnicodes, unLen, pCodes, ppFonts);
|
||||
if (bFont)
|
||||
pKid->SetTextAppearance(wsValue, pCodes, unLen, 0, -1, ppFonts);
|
||||
|
||||
RELEASEARRAYOBJECTS(pUnicodes);
|
||||
RELEASEARRAYOBJECTS(pCodes);
|
||||
RELEASEARRAYOBJECTS(ppFonts);
|
||||
DrawChoiceWidget(pAppFonts, pKid, {pParent->sV});
|
||||
}
|
||||
if (nType == PdfWriter::WidgetText)
|
||||
{
|
||||
@ -2423,6 +2400,25 @@ HRESULT CPdfWriter::EditWidgetParents(NSFonts::IApplicationFonts* pAppFonts, CWi
|
||||
pParentObj->Add("V", pArray);
|
||||
for (int i = 0; i < pParent->arrV.size(); ++i)
|
||||
pArray->Add(new PdfWriter::CStringObject(U_TO_UTF8(pParent->arrV[i]).c_str()));
|
||||
PdfWriter::CObjectBase* pKids = pParentObj->Get("Kids");
|
||||
if (pKids && pKids->GetType() == PdfWriter::object_type_ARRAY)
|
||||
{
|
||||
PdfWriter::CArrayObject* pAKids = (PdfWriter::CArrayObject*)pKids;
|
||||
for (int i = 0; i < pAKids->GetCount(); ++i)
|
||||
{
|
||||
PdfWriter::CObjectBase* pObj = pAKids->Get(i);
|
||||
if (pObj->GetType() != PdfWriter::object_type_DICT ||
|
||||
((PdfWriter::CDictObject*)pObj)->GetDictType() != PdfWriter::dict_type_ANNOTATION ||
|
||||
((PdfWriter::CAnnotation*)pObj)->GetAnnotationType() != PdfWriter::AnnotWidget)
|
||||
continue;
|
||||
PdfWriter::EWidgetType nType = ((PdfWriter::CWidgetAnnotation*)pObj)->GetWidgetType();
|
||||
if (nType == PdfWriter::WidgetCombobox || nType == PdfWriter::WidgetListbox)
|
||||
{
|
||||
PdfWriter::CChoiceWidget* pKid = dynamic_cast<PdfWriter::CChoiceWidget*>(pObj);
|
||||
DrawChoiceWidget(pAppFonts, pKid, pParent->arrV);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3237,10 +3233,20 @@ void CPdfWriter::DrawTextWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter
|
||||
if (!pFont)
|
||||
return;
|
||||
PdfWriter::CFontTrueType* pFontTT = m_pDocument->CreateTrueTypeFont(pFont);
|
||||
|
||||
double dFontSize = pTextWidget->GetFontSize();
|
||||
bool isBold = pTextWidget->GetFontIsBold();
|
||||
bool isItalic = pTextWidget->GetFontIsItalic();
|
||||
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())
|
||||
pTextWidget->SetBorder(0, 1, {});
|
||||
double dShiftBorder = pTextWidget->GetBorderWidth();
|
||||
BYTE nType = pTextWidget->GetBorderType();
|
||||
if (nType == 1 || nType == 3)
|
||||
dShiftBorder *= 2;
|
||||
|
||||
// Коды, шрифты, количество
|
||||
unsigned int unLen = 0;
|
||||
@ -3256,18 +3262,6 @@ void CPdfWriter::DrawTextWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter
|
||||
return;
|
||||
}
|
||||
|
||||
bool isComb = pTextWidget->IsCombFlag();
|
||||
double dWidth = pTextWidget->GetWidth();
|
||||
double dHeight = pTextWidget->GetHeight();
|
||||
BYTE nAlign = pTextWidget->GetQ();
|
||||
|
||||
if (!pTextWidget->HaveBorder())
|
||||
pTextWidget->SetBorder(1, 1, {});
|
||||
double dShiftBorder = pTextWidget->GetBorderWidth();
|
||||
BYTE nType = pTextWidget->GetBorderType();
|
||||
if (nType == 1 || nType == 3)
|
||||
dShiftBorder *= 2;
|
||||
|
||||
if (!isComb && pTextWidget->IsMultiLine() && pFontTT)
|
||||
{
|
||||
unsigned short* pCodes2 = new unsigned short[unLen];
|
||||
@ -3293,7 +3287,7 @@ void CPdfWriter::DrawTextWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter
|
||||
|
||||
m_oLinesManager.CalculateLines(dFontSize, dWidth);
|
||||
|
||||
pTextWidget->StartAP(pFont, dFontSize, 1.0);
|
||||
pTextWidget->StartAP();
|
||||
|
||||
unsigned int unLinesCount = m_oLinesManager.GetLinesCount();
|
||||
double dLineShiftY = dHeight - pFontTT->GetLineHeight() * dFontSize / 1000.0 - dShiftBorder;
|
||||
@ -3326,6 +3320,8 @@ void CPdfWriter::DrawTextWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter
|
||||
double* pShifts = NULL;
|
||||
unsigned int unShiftsCount = 0;
|
||||
double dShiftX = dShiftBorder * 2;
|
||||
if (dShiftX == 0)
|
||||
dShiftX = 2;
|
||||
|
||||
if (isComb)
|
||||
{
|
||||
@ -3366,9 +3362,9 @@ void CPdfWriter::DrawTextWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter
|
||||
dSumWidth += dLetterWidth;
|
||||
}
|
||||
|
||||
if (2 == nAlign && dWidth - dSumWidth > 0)
|
||||
if (2 == nAlign)
|
||||
dShiftX = dWidth - dSumWidth - dShiftBorder * 2;
|
||||
else if (1 == nAlign && (dWidth - dSumWidth) / 2 > 0)
|
||||
else if (1 == nAlign)
|
||||
dShiftX = (dWidth - dSumWidth) / 2;
|
||||
}
|
||||
|
||||
@ -3390,7 +3386,7 @@ void CPdfWriter::DrawTextWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter
|
||||
// dBaseLine = (dHeight - dMidPoint) / 2.0;
|
||||
}
|
||||
|
||||
pTextWidget->SetAP(wsValue, pCodes, unLen, pFont, dFontSize, dShiftX, dBaseLine, ppFonts, pShifts);
|
||||
pTextWidget->SetAP(wsValue, pCodes, unLen, dShiftX, dBaseLine, ppFonts, pShifts);
|
||||
RELEASEARRAYOBJECTS(pShifts);
|
||||
}
|
||||
|
||||
@ -3398,3 +3394,149 @@ void CPdfWriter::DrawTextWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter
|
||||
RELEASEARRAYOBJECTS(pCodes);
|
||||
RELEASEARRAYOBJECTS(ppFonts);
|
||||
}
|
||||
void CPdfWriter::DrawChoiceWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CChoiceWidget* pChoiceWidget, const std::vector<std::wstring>& arrValue)
|
||||
{
|
||||
if (!pAppFonts || !pChoiceWidget || arrValue.empty())
|
||||
return;
|
||||
PdfWriter::CFontCidTrueType* pFont = pChoiceWidget->GetFont();
|
||||
if (!pFont)
|
||||
return;
|
||||
PdfWriter::CFontTrueType* pFontTT = m_pDocument->CreateTrueTypeFont(pFont);
|
||||
double dFontSize = pChoiceWidget->GetFontSize();
|
||||
bool isBold = pChoiceWidget->GetFontIsBold();
|
||||
bool isItalic = pChoiceWidget->GetFontIsItalic();
|
||||
double dWidth = pChoiceWidget->GetWidth();
|
||||
double dHeight = pChoiceWidget->GetHeight();
|
||||
BYTE nAlign = pChoiceWidget->GetQ();
|
||||
|
||||
if (!pChoiceWidget->HaveBorder() && pChoiceWidget->HaveBC())
|
||||
pChoiceWidget->SetBorder(0, 1, {});
|
||||
double dShiftBorder = pChoiceWidget->GetBorderWidth();
|
||||
BYTE nType = pChoiceWidget->GetBorderType();
|
||||
if (nType == 1 || nType == 3)
|
||||
dShiftBorder *= 2;
|
||||
|
||||
|
||||
|
||||
if (pChoiceWidget->GetWidgetType() == PdfWriter::WidgetCombobox)
|
||||
{
|
||||
std::wstring wsValue = arrValue.back();
|
||||
unsigned int unLen = 0;
|
||||
unsigned int* pUnicodes = NULL;
|
||||
unsigned short* pCodes = NULL;
|
||||
PdfWriter::CFontCidTrueType** ppFonts = NULL;
|
||||
bool bFont = GetFontData(pAppFonts, wsValue, pFont, isBold, isItalic, pUnicodes, unLen, pCodes, ppFonts);
|
||||
if (!bFont)
|
||||
{
|
||||
RELEASEARRAYOBJECTS(pUnicodes);
|
||||
RELEASEARRAYOBJECTS(pCodes);
|
||||
RELEASEARRAYOBJECTS(ppFonts);
|
||||
return;
|
||||
}
|
||||
|
||||
double dShiftX = dShiftBorder * 2;
|
||||
if (dShiftX == 0)
|
||||
dShiftX = 2;
|
||||
if (1 == nAlign || 2 == nAlign)
|
||||
{
|
||||
double dSumWidth = 0;
|
||||
for (unsigned int unIndex = 0; unIndex < unLen; ++unIndex)
|
||||
{
|
||||
unsigned short ushCode = pCodes[unIndex];
|
||||
double dLetterWidth = ppFonts[unIndex]->GetWidth(ushCode) / 1000.0 * dFontSize;
|
||||
dSumWidth += dLetterWidth;
|
||||
}
|
||||
|
||||
if (2 == nAlign)
|
||||
dShiftX = dWidth - dSumWidth - dShiftBorder * 2;
|
||||
else if (1 == nAlign)
|
||||
dShiftX = (dWidth - dSumWidth) / 2;
|
||||
}
|
||||
|
||||
double dBaseLine = (dHeight - dFontSize) / 2.0 - dShiftBorder;
|
||||
if (pFontTT)
|
||||
dBaseLine = (dHeight - pFontTT->m_dHeight * dFontSize / pFontTT->m_dUnitsPerEm) / 2.0;
|
||||
|
||||
pChoiceWidget->SetAP(wsValue, pCodes, unLen, dShiftX, dBaseLine, ppFonts, NULL);
|
||||
|
||||
RELEASEARRAYOBJECTS(pUnicodes);
|
||||
RELEASEARRAYOBJECTS(pCodes);
|
||||
RELEASEARRAYOBJECTS(ppFonts);
|
||||
}
|
||||
else // ListBox
|
||||
{
|
||||
std::wstring wsValue = pChoiceWidget->GetValue(arrValue.front());
|
||||
unsigned int unLen = 0;
|
||||
unsigned int* pUnicodes = NULL;
|
||||
unsigned short* pCodes = NULL;
|
||||
PdfWriter::CFontCidTrueType** ppFonts = NULL;
|
||||
bool bFont = GetFontData(pAppFonts, wsValue, pFont, isBold, isItalic, pUnicodes, unLen, pCodes, ppFonts);
|
||||
if (!bFont)
|
||||
{
|
||||
RELEASEARRAYOBJECTS(pUnicodes);
|
||||
RELEASEARRAYOBJECTS(pCodes);
|
||||
RELEASEARRAYOBJECTS(ppFonts);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned short* pCodes2 = new unsigned short[unLen];
|
||||
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 dLineHeight = pFontTT->GetLineHeight() * dFontSize / 1000.0;
|
||||
|
||||
m_oLinesManager.CalculateLines(dFontSize, dWidth);
|
||||
|
||||
pChoiceWidget->SetListBoxHeight(pFontTT->m_dHeight * dFontSize / pFontTT->m_dUnitsPerEm);
|
||||
pChoiceWidget->StartAP();
|
||||
|
||||
unsigned int unLinesCount = m_oLinesManager.GetLinesCount();
|
||||
double dLineShiftY = dHeight - pFontTT->GetLineHeight() * dFontSize / 1000.0 - dShiftBorder;
|
||||
for (unsigned int unIndex = 0; unIndex < unLinesCount; ++unIndex)
|
||||
{
|
||||
unsigned int unLineStart = m_oLinesManager.GetLineStartPos(unIndex);
|
||||
double dLineShiftX = dShiftBorder * 2;
|
||||
if (dLineShiftX == 0)
|
||||
dLineShiftX = 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)
|
||||
pChoiceWidget->AddLineToAP(dLineShiftX, dLineShiftY, pCodes + unLineStart, nInLineCount, ppFonts + unLineStart, NULL);
|
||||
|
||||
dLineShiftY -= dLineHeight;
|
||||
if (dLineShiftY < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
pChoiceWidget->EndAP();
|
||||
|
||||
m_oLinesManager.Clear();
|
||||
|
||||
RELEASEARRAYOBJECTS(pCodes2);
|
||||
RELEASEARRAYOBJECTS(pWidths);
|
||||
|
||||
RELEASEARRAYOBJECTS(pUnicodes);
|
||||
RELEASEARRAYOBJECTS(pCodes);
|
||||
RELEASEARRAYOBJECTS(ppFonts);
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,6 +244,7 @@ private:
|
||||
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);
|
||||
void DrawTextWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CTextWidget* pTextWidget, const std::wstring& wsValue);
|
||||
void DrawChoiceWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CChoiceWidget* pChoiceWidget, const std::vector<std::wstring>& arrValue);
|
||||
|
||||
private:
|
||||
NSFonts::IFontManager* m_pFontManager;
|
||||
|
||||
@ -160,6 +160,10 @@ namespace PdfWriter
|
||||
|
||||
// Для PDFA нужно, чтобы 0, 1, 4 биты были выключены, а второй включен
|
||||
Add("F", 4);
|
||||
|
||||
m_oBorder.bHave = false;
|
||||
m_oBorder.nType = 0;
|
||||
m_oBorder.dWidth = 0;
|
||||
}
|
||||
void CAnnotation::SetRect(const TRect& oRect)
|
||||
{
|
||||
@ -1046,6 +1050,38 @@ namespace PdfWriter
|
||||
{
|
||||
return GetColor(m_arrBC, true) + "\012";
|
||||
}
|
||||
void CWidgetAnnotation::SetAP(const std::wstring& wsValue, unsigned short* pCodes, unsigned int unCount, double dX, double dY, CFontCidTrueType** ppFonts, double* pShifts)
|
||||
{
|
||||
m_pAppearance = new CAnnotAppearance(m_pXref, this);
|
||||
if (!m_pAppearance)
|
||||
return;
|
||||
Add("AP", m_pAppearance);
|
||||
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);
|
||||
}
|
||||
void CWidgetAnnotation::StartAP()
|
||||
{
|
||||
m_pAppearance = new CAnnotAppearance(m_pXref, this);
|
||||
if (!m_pAppearance)
|
||||
return;
|
||||
Add("AP", m_pAppearance);
|
||||
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));
|
||||
}
|
||||
void CWidgetAnnotation::AddLineToAP(const double& dX, const double& dY, unsigned short* pCodes, const unsigned int& unCodesCount, CFontCidTrueType** ppFonts, const double* pShifts)
|
||||
{
|
||||
if (!m_pAppearance)
|
||||
return;
|
||||
CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal();
|
||||
pNormal->DrawTextLine(dX, dY, pCodes, unCodesCount, ppFonts, pShifts);
|
||||
}
|
||||
void CWidgetAnnotation::EndAP()
|
||||
{
|
||||
if (!m_pAppearance)
|
||||
return;
|
||||
CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal();
|
||||
pNormal->EndDrawText();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
// CPushButtonWidget
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -1447,51 +1483,6 @@ namespace PdfWriter
|
||||
pOwner = this;
|
||||
pOwner->Add("RV", new CStringObject(sValue.c_str()));
|
||||
}
|
||||
void CTextWidget::SetAP(const std::wstring& wsValue, unsigned short* pCodes, unsigned int unCount, CFontDict* pFont, double dFontSize, double dX, double dY, CFontCidTrueType** ppFonts, double* pShifts)
|
||||
{
|
||||
m_pAppearance = new CAnnotAppearance(m_pXref, this);
|
||||
if (!m_pAppearance)
|
||||
return;
|
||||
Add("AP", m_pAppearance);
|
||||
CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal();
|
||||
pNormal->DrawSimpleText(wsValue, pCodes, unCount, pFont, dFontSize, dX, dY, 0, 0, 0, NULL, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop), ppFonts, pShifts);
|
||||
}
|
||||
void CTextWidget::StartAP(CFontDict* pFont, const double& dFontSize, const double& dAlpha)
|
||||
{
|
||||
m_pAppearance = new CAnnotAppearance(m_pXref, this);
|
||||
if (!m_pAppearance)
|
||||
return;
|
||||
|
||||
Add("AP", m_pAppearance);
|
||||
|
||||
CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal();
|
||||
CResourcesDict* pFieldsResources = m_pDocument->GetFieldsResources();
|
||||
|
||||
const char* sExtGrStateName = NULL;
|
||||
if (fabs(dAlpha - 1.0) > 0.001)
|
||||
{
|
||||
CExtGrState* pExtGrState = m_pDocument->GetFillAlpha(dAlpha);
|
||||
sExtGrStateName = pFieldsResources->GetExtGrStateName(pExtGrState);
|
||||
}
|
||||
|
||||
pNormal->StartDrawText(pFont, dFontSize, 0, 0, 0, sExtGrStateName, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop));
|
||||
}
|
||||
void CTextWidget::AddLineToAP(const double& dX, const double& dY, unsigned short* pCodes, const unsigned int& unCodesCount, CFontCidTrueType** ppFonts, const double* pShifts)
|
||||
{
|
||||
if (!m_pAppearance)
|
||||
return;
|
||||
|
||||
CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal();
|
||||
pNormal->DrawTextLine(dX, dY, pCodes, unCodesCount, ppFonts, pShifts);
|
||||
}
|
||||
void CTextWidget::EndAP()
|
||||
{
|
||||
if (!m_pAppearance)
|
||||
return;
|
||||
|
||||
CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal();
|
||||
pNormal->EndDrawText();
|
||||
}
|
||||
bool CTextWidget::IsCombFlag()
|
||||
{
|
||||
int nFlags = ((CNumberObject*)GetObjValue("Ff"))->Get();
|
||||
@ -1512,39 +1503,38 @@ namespace PdfWriter
|
||||
//----------------------------------------------------------------------------------------
|
||||
CChoiceWidget::CChoiceWidget(CXref* pXref) : CWidgetAnnotation(pXref, AnnotWidget)
|
||||
{
|
||||
m_dHeight = 0;
|
||||
m_nTI = 0;
|
||||
}
|
||||
void CChoiceWidget::SetFlag(const int& nFlag)
|
||||
{
|
||||
// TODO
|
||||
Remove("AP");
|
||||
|
||||
int nFlags = nFlag;
|
||||
if (m_nSubtype == WidgetCombobox)
|
||||
nFlags |= (1 << 17);
|
||||
|
||||
CDictObject* pOwner = GetObjOwnValue("Ff");
|
||||
if (!pOwner)
|
||||
pOwner = GetObjOwnValue("FT");
|
||||
pOwner = this;
|
||||
else
|
||||
{
|
||||
int nFlags2 = ((CNumberObject*)(pOwner->Get("Ff")))->Get();
|
||||
if (nFlags2 & (1 << 19))
|
||||
nFlags |= (1 << 19);
|
||||
}
|
||||
if (!pOwner)
|
||||
pOwner = this;
|
||||
pOwner->Add("Ff", nFlags);
|
||||
}
|
||||
void CChoiceWidget::SetTI(const int& nTI)
|
||||
{
|
||||
Add("TI", nTI);
|
||||
m_nTI = nTI;
|
||||
CDictObject* pOwner = GetObjOwnValue("TI");
|
||||
if (!pOwner)
|
||||
pOwner = this;
|
||||
pOwner->Add("TI", nTI);
|
||||
}
|
||||
void CChoiceWidget::SetV(const std::wstring& wsV)
|
||||
{
|
||||
std::string sValue = U_TO_UTF8(wsV);
|
||||
CDictObject* pOwner = GetObjOwnValue("V");
|
||||
if (!pOwner)
|
||||
pOwner = GetObjOwnValue("FT");
|
||||
if (!pOwner)
|
||||
pOwner = this;
|
||||
pOwner->Add("V", new CStringObject(sValue.c_str()));
|
||||
@ -1555,7 +1545,10 @@ namespace PdfWriter
|
||||
if (!pArray)
|
||||
return;
|
||||
|
||||
Add("I", pArray);
|
||||
CDictObject* pOwner = GetObjOwnValue("I");
|
||||
if (!pOwner)
|
||||
pOwner = this;
|
||||
pOwner->Add("I", pArray);
|
||||
|
||||
for (int i = 0; i < arrI.size(); ++i)
|
||||
pArray->Add(arrI[i]);
|
||||
@ -1566,13 +1559,17 @@ namespace PdfWriter
|
||||
if (!pArray)
|
||||
return;
|
||||
|
||||
Add("V", pArray);
|
||||
CDictObject* pOwner = GetObjOwnValue("V");
|
||||
if (!pOwner)
|
||||
pOwner = this;
|
||||
pOwner->Add("V", pArray);
|
||||
|
||||
for (int i = 0; i < arrV.size(); ++i)
|
||||
pArray->Add(new PdfWriter::CStringObject(U_TO_UTF8(arrV[i]).c_str()));
|
||||
}
|
||||
void CChoiceWidget::SetOpt(const std::vector< std::pair<std::wstring, std::wstring> >& arrOpt)
|
||||
{
|
||||
m_arrOpt = arrOpt;
|
||||
CArrayObject* pArray = new CArrayObject();
|
||||
if (!pArray)
|
||||
return;
|
||||
@ -1602,18 +1599,30 @@ namespace PdfWriter
|
||||
}
|
||||
}
|
||||
}
|
||||
void CChoiceWidget::SetTextAppearance(const std::wstring& wsValue, unsigned short* pCodes, unsigned int unCount, double dX, double dY, CFontCidTrueType** ppFonts)
|
||||
std::wstring CChoiceWidget::GetValue(const std::wstring& wsValue)
|
||||
{
|
||||
return;
|
||||
CAnnotAppearance* pAppearance = new CAnnotAppearance(m_pXref, this);
|
||||
Add("AP", pAppearance);
|
||||
std::wstring sRes;
|
||||
int i = 0;
|
||||
if (!m_nTI)
|
||||
{
|
||||
for (; i < m_arrOpt.size(); ++i)
|
||||
{
|
||||
if (( m_arrOpt[i].first.empty() && m_arrOpt[i].second == wsValue) ||
|
||||
(!m_arrOpt[i].first.empty() && m_arrOpt[i].first == wsValue))
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
i = m_nTI;
|
||||
|
||||
CAnnotAppearanceObject* pNormal = pAppearance->GetNormal();
|
||||
|
||||
if (dY == -1)
|
||||
dY = fabs(m_oRect.fTop - m_oRect.fBottom) - m_dFontSize - 2;
|
||||
|
||||
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, NULL);
|
||||
for (; i < m_arrOpt.size(); ++i)
|
||||
sRes += (m_arrOpt[i].second + L"\n");
|
||||
if (!sRes.empty())
|
||||
{
|
||||
sRes.pop_back();
|
||||
return sRes;
|
||||
}
|
||||
return L"";
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
// CSignatureWidget
|
||||
|
||||
@ -399,7 +399,13 @@ namespace PdfWriter
|
||||
bool GetFontIsBold() { return m_bBold; }
|
||||
bool GetFontIsItalic() { return m_bItalic; }
|
||||
bool HaveBG() { return !m_arrBG.empty(); }
|
||||
bool HaveBC() { return !m_arrBC.empty(); }
|
||||
BYTE GetQ() { return m_nQ; }
|
||||
|
||||
void SetAP(const std::wstring& wsValue, unsigned short* pCodes, unsigned int unCount, double dX, double dY, CFontCidTrueType** ppFonts, double* pShifts);
|
||||
void StartAP();
|
||||
void AddLineToAP(const double& dX, const double& dY, unsigned short* pCodes, const unsigned int& unCodesCount, CFontCidTrueType** ppFonts = NULL, const double* pShifts = NULL);
|
||||
void EndAP();
|
||||
};
|
||||
class CPushButtonWidget : public CWidgetAnnotation
|
||||
{
|
||||
@ -466,16 +472,17 @@ namespace PdfWriter
|
||||
void SetV (const std::wstring& wsV);
|
||||
void SetRV(const std::wstring& wsRV);
|
||||
|
||||
void SetAP(const std::wstring& wsValue, unsigned short* pCodes, unsigned int unCount, CFontDict* pFont, double dFontSize, double dX, double dY, CFontCidTrueType** ppFonts, double* pShifts);
|
||||
void StartAP(CFontDict* pFont, const double& dFontSize, const double& dAlpha);
|
||||
void AddLineToAP(const double& dX, const double& dY, unsigned short* pCodes, const unsigned int& unCodesCount, CFontCidTrueType** ppFonts = NULL, const double* pShifts = NULL);
|
||||
void EndAP();
|
||||
bool IsCombFlag();
|
||||
bool IsMultiLine();
|
||||
unsigned int GetMaxLen();
|
||||
};
|
||||
class CChoiceWidget : public CWidgetAnnotation
|
||||
{
|
||||
private:
|
||||
std::vector< std::pair<std::wstring, std::wstring> > m_arrOpt;
|
||||
double m_dHeight;
|
||||
int m_nTI;
|
||||
std::vector<int> m_arrIndex;
|
||||
public:
|
||||
CChoiceWidget(CXref* pXref);
|
||||
|
||||
@ -486,7 +493,11 @@ namespace PdfWriter
|
||||
void SetV(const std::vector<std::wstring>& arrV);
|
||||
void SetOpt(const std::vector< std::pair<std::wstring, std::wstring> >& arrOpt);
|
||||
|
||||
void SetTextAppearance(const std::wstring& wsValue, unsigned short* pCodes, unsigned int unCount, double dX = 0.0, double dY = 0.0, CFontCidTrueType** ppFonts = NULL);
|
||||
std::wstring GetValue(const std::wstring& wsValue);
|
||||
void SetListBoxHeight(double dHeight) { m_dHeight = dHeight; }
|
||||
double GetListBoxHeight() { return m_dHeight; }
|
||||
std::vector<int> GetListBoxIndex() { return m_arrIndex; }
|
||||
int GetTI() { return m_nTI; }
|
||||
};
|
||||
class CSignatureWidget : public CWidgetAnnotation
|
||||
{
|
||||
|
||||
@ -2003,6 +2003,25 @@ namespace PdfWriter
|
||||
m_pStream->WriteReal(std::max(dHeight - dBorderSizeStyle * 2, 0.0));
|
||||
m_pStream->WriteStr(" re\012W\012n\012");
|
||||
|
||||
if (pAnnot && pAnnot->GetWidgetType() == WidgetListbox)
|
||||
{
|
||||
CChoiceWidget* pAnnot = dynamic_cast<CChoiceWidget*>(m_pAnnot);
|
||||
double dBaseLine = pAnnot->GetListBoxHeight();
|
||||
std::vector<int> arrIndex = pAnnot->GetListBoxIndex();
|
||||
m_pStream->WriteStr("0.60 0.75 0.85 rg\012");
|
||||
for (int i = 0; i < arrIndex.size(); ++i)
|
||||
{
|
||||
m_pStream->WriteReal(dBorderSizeStyle);
|
||||
m_pStream->WriteChar(' ');
|
||||
m_pStream->WriteReal(std::max(dHeight - dBorderSizeStyle - dBaseLine * (double)(arrIndex[i] + 1), 0.0));
|
||||
m_pStream->WriteChar(' ');
|
||||
m_pStream->WriteReal(std::max(dWidth - dBorderSizeStyle * 2.0, 0.0));
|
||||
m_pStream->WriteChar(' ');
|
||||
m_pStream->WriteReal(dBaseLine);
|
||||
m_pStream->WriteStr(" re\012f\012");
|
||||
}
|
||||
}
|
||||
|
||||
m_pStream->WriteStr("BT\012");
|
||||
|
||||
m_dFontSize = std::min(1000.0, std::max(0.0, dFontSize));
|
||||
|
||||
Reference in New Issue
Block a user