mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Create write caption for pushbutton
This commit is contained in:
@ -2163,14 +2163,22 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
||||
CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr* pPr = oInfo.GetWidgetAnnotPr()->GetButtonWidgetPr();
|
||||
PdfWriter::CPushButtonWidget* pButtonWidget = (PdfWriter::CPushButtonWidget*)pAnnot;
|
||||
|
||||
std::wstring wsValue;
|
||||
if (nFlags & (1 << 10))
|
||||
pButtonWidget->SetCA(pPr->GetCA());
|
||||
{
|
||||
wsValue = pPr->GetCA();
|
||||
pButtonWidget->SetCA(wsValue);
|
||||
}
|
||||
if (nFlags & (1 << 11))
|
||||
pButtonWidget->SetRC(pPr->GetRC());
|
||||
if (nFlags & (1 << 12))
|
||||
pButtonWidget->SetAC(pPr->GetAC());
|
||||
BYTE nTP = 0;
|
||||
if (nFlags & (1 << 13))
|
||||
pButtonWidget->SetTP(pPr->GetTP());
|
||||
{
|
||||
nTP = pPr->GetTP();
|
||||
pButtonWidget->SetTP(nTP);
|
||||
}
|
||||
|
||||
int nIFFlags = pPr->GetIFFlag();
|
||||
pButtonWidget->SetIFFlag(nIFFlags);
|
||||
@ -2194,6 +2202,75 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
||||
pButtonWidget->SetRI(pPr->GetRI());
|
||||
if (nIFFlags & (1 << 7))
|
||||
pButtonWidget->SetIX(pPr->GetIX());
|
||||
|
||||
// ВНЕШНИЙ ВИД
|
||||
// Caption
|
||||
if (wsValue.empty())
|
||||
return S_OK;
|
||||
|
||||
unsigned int unLen;
|
||||
unsigned int* pUnicodes = NSStringExt::CConverter::GetUtf32FromUnicode(wsValue, unLen);
|
||||
if (!pUnicodes)
|
||||
return S_FALSE;
|
||||
unsigned short* pCodes = new unsigned short[unLen];
|
||||
if (!pCodes)
|
||||
{
|
||||
RELEASEARRAYOBJECTS(pUnicodes);
|
||||
return S_FALSE;
|
||||
}
|
||||
PdfWriter::CFontCidTrueType** ppFonts = new PdfWriter::CFontCidTrueType*[unLen];
|
||||
if (!ppFonts)
|
||||
{
|
||||
RELEASEARRAYOBJECTS(pUnicodes);
|
||||
RELEASEARRAYOBJECTS(pCodes);
|
||||
return S_FALSE;
|
||||
}
|
||||
|
||||
for (unsigned int unIndex = 0; unIndex < unLen; ++unIndex)
|
||||
{
|
||||
unsigned int unUnicode = pUnicodes[unIndex];
|
||||
|
||||
if (!m_pFont->HaveChar(unUnicode))
|
||||
{
|
||||
std::wstring wsFontFamily = pAppFonts->GetFontBySymbol(unUnicode);
|
||||
PdfWriter::CFontCidTrueType* pTempFont = GetFont(wsFontFamily, isBold, isItalic);
|
||||
if (pTempFont)
|
||||
{
|
||||
pCodes[unIndex] = pTempFont->EncodeUnicode(unUnicode);
|
||||
ppFonts[unIndex] = pTempFont;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
pCodes[unIndex] = m_pFont->EncodeUnicode(unUnicode);
|
||||
ppFonts[unIndex] = m_pFont;
|
||||
}
|
||||
|
||||
double dMargin = 2; // Отступ используемый в Adobe
|
||||
double dShiftX = dMargin;
|
||||
double dBaseLine = (dY2 - dY1 - dFontSize + dMargin) / 2.0;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
switch (nTP)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
dShiftX += (dX2 - dX1 - dSumWidth) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
pButtonWidget->SetCaptionAP(pCodes, unLen, dShiftX, dBaseLine, ppFonts);
|
||||
|
||||
RELEASEARRAYOBJECTS(pUnicodes);
|
||||
RELEASEARRAYOBJECTS(pCodes);
|
||||
RELEASEARRAYOBJECTS(ppFonts);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -1137,6 +1137,7 @@ namespace PdfWriter
|
||||
|
||||
std::string sValue = U_TO_UTF8(wsCA);
|
||||
m_pMK->Add("CA", new CStringObject(sValue.c_str()));
|
||||
m_wsCA = wsCA;
|
||||
}
|
||||
void CPushButtonWidget::SetRC(const std::wstring& wsRC)
|
||||
{
|
||||
@ -1152,7 +1153,7 @@ namespace PdfWriter
|
||||
std::string sValue = U_TO_UTF8(wsAC);
|
||||
m_pMK->Add("AC", new CStringObject(sValue.c_str()));
|
||||
}
|
||||
CXObject* CPushButtonWidget::SetAP(CImageDict* pImage, const char* pImgName, const char* pFrmName)
|
||||
void CPushButtonWidget::SetAP(CImageDict* pImage, const std::string& sAP, const std::string& sImgName, const std::string& sFrmName)
|
||||
{
|
||||
if (!m_oBorder.bHave)
|
||||
{
|
||||
@ -1161,10 +1162,13 @@ namespace PdfWriter
|
||||
m_oBorder.dWidth = 1;
|
||||
}
|
||||
|
||||
CAnnotAppearance* pAppearance = new CAnnotAppearance(m_pXref, this);
|
||||
Add("AP", pAppearance);
|
||||
if (!m_pAppearance)
|
||||
m_pAppearance = new CAnnotAppearance(m_pXref, this);
|
||||
if (!m_pAppearance)
|
||||
return;
|
||||
Add("AP", m_pAppearance);
|
||||
|
||||
CAnnotAppearanceObject* pNormal = pAppearance->GetNormal();
|
||||
CAnnotAppearanceObject* pNormal = m_pAppearance->GetNormal();
|
||||
CResourcesDict* pFieldsResources = m_pDocument->GetFieldsResources();
|
||||
|
||||
std::string sDA = "0.909 0.941 0.992 rg";
|
||||
@ -1241,10 +1245,7 @@ namespace PdfWriter
|
||||
pFormMatrix->Add(1);
|
||||
pFormMatrix->Add(0);
|
||||
pFormMatrix->Add(0);
|
||||
if (pFrmName)
|
||||
pForm->Add("Name", pFrmName);
|
||||
else
|
||||
pForm->Add("Name", "FRM");
|
||||
pForm->Add("Name", sFrmName.c_str());
|
||||
|
||||
CDictObject* pFormRes = new CDictObject();
|
||||
CArrayObject* pFormResProcset = new CArrayObject();
|
||||
@ -1254,10 +1255,7 @@ namespace PdfWriter
|
||||
CDictObject* pFormResXObject = new CDictObject();
|
||||
pFormRes->Add("XObject", pFormResXObject);
|
||||
|
||||
if (pImgName)
|
||||
pFormResXObject->Add(pImgName, pImage);
|
||||
else
|
||||
pFormResXObject->Add("Img", pImage);
|
||||
pFormResXObject->Add(sImgName, pImage);
|
||||
pForm->Add("Resources", pFormRes);
|
||||
|
||||
pForm->Add("Subtype", "Form");
|
||||
@ -1268,51 +1266,42 @@ namespace PdfWriter
|
||||
pStream->WriteStr(" 0 0 ");
|
||||
pStream->WriteReal(dOriginH);
|
||||
pStream->WriteStr(" 0 0 cm\012/");
|
||||
if (pImgName)
|
||||
pStream->WriteStr(pImgName);
|
||||
else
|
||||
pStream->WriteStr("Img");
|
||||
pStream->WriteStr(sImgName.c_str());
|
||||
pStream->WriteStr(" Do\012Q");
|
||||
|
||||
pFieldsResources->AddXObjectWithName(pFrmName ? pFrmName : "FRM", pForm);
|
||||
pNormal->DrawPicture(pFrmName ? pFrmName : "FRM", dDstX, dDstY, dDstW / dOriginW, dDstH / dOriginH, m_bRespectBorders);
|
||||
pFieldsResources->AddXObjectWithName(sFrmName.c_str(), pForm);
|
||||
pNormal->DrawPicture(sFrmName.c_str(), dDstX, dDstY, dDstW / dOriginW, dDstH / dOriginH, m_bRespectBorders);
|
||||
}
|
||||
else
|
||||
{
|
||||
pNormal->DrawPicture();
|
||||
|
||||
if (!m_sCaptionForAP.empty())
|
||||
pNormal->GetStream()->WriteStr(m_sCaptionForAP.c_str());
|
||||
|
||||
if (pForm)
|
||||
{
|
||||
CheckMK();
|
||||
m_pMK->Add(sAP, pForm);
|
||||
}
|
||||
|
||||
return pForm;
|
||||
}
|
||||
void CPushButtonWidget::SetI(CImageDict* pI, const char* pImgName, const char* pFrmName)
|
||||
void CPushButtonWidget::SetCaptionAP(unsigned short* pCodes, unsigned int unCount, double dX, double dY, CFontCidTrueType** ppFonts)
|
||||
{
|
||||
CXObject* pForm = SetAP(pI, pImgName, pFrmName);
|
||||
if (!pForm)
|
||||
return;
|
||||
m_sCaptionForAP.append("\012q\012BT\012");
|
||||
|
||||
CheckMK();
|
||||
CAnnotAppearanceObject* pNormal = new CAnnotAppearanceObject(NULL, this);
|
||||
pNormal->m_bStart = true;
|
||||
pNormal->DrawTextLine(dX, dY, pCodes, unCount, ppFonts, NULL);
|
||||
|
||||
m_pMK->Add("I", pForm);
|
||||
}
|
||||
void CPushButtonWidget::SetRI(CImageDict* pI, const char* pImgName, const char* pFrmName)
|
||||
{
|
||||
CXObject* pForm = SetAP(pI, pImgName, pFrmName);
|
||||
if (!pForm)
|
||||
return;
|
||||
CStream* pStream = pNormal->GetStream();
|
||||
pStream->Seek(0, SeekSet);
|
||||
unsigned int nBufferSize = pStream->Size();
|
||||
BYTE* pBuffer = new BYTE[nBufferSize];
|
||||
pStream->Read(pBuffer, NULL);
|
||||
m_sCaptionForAP.append((char*)pBuffer, nBufferSize);
|
||||
RELEASEARRAYOBJECTS(pBuffer);
|
||||
RELEASEOBJECT(pNormal);
|
||||
|
||||
CheckMK();
|
||||
|
||||
m_pMK->Add("RI", pForm);
|
||||
}
|
||||
void CPushButtonWidget::SetIX(CImageDict* pI, const char* pImgName, const char* pFrmName)
|
||||
{
|
||||
CXObject* pForm = SetAP(pI, pImgName, pFrmName);
|
||||
if (!pForm)
|
||||
return;
|
||||
|
||||
CheckMK();
|
||||
|
||||
m_pMK->Add("IX", pForm);
|
||||
m_sCaptionForAP.append("ET\012Q\012");
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
// CCheckBoxWidget
|
||||
|
||||
@ -391,10 +391,13 @@ namespace PdfWriter
|
||||
BYTE m_nScaleType;
|
||||
double m_dShiftX;
|
||||
double m_dShiftY;
|
||||
std::wstring m_wsCA;
|
||||
CDictObject* m_pIF;
|
||||
std::string m_sCaptionForAP;
|
||||
|
||||
void CheckIF();
|
||||
|
||||
|
||||
public:
|
||||
CPushButtonWidget(CXref* pXref);
|
||||
virtual EWidgetType GetWidgetType() const override
|
||||
@ -416,11 +419,10 @@ namespace PdfWriter
|
||||
void SetCA(const std::wstring& wsCA);
|
||||
void SetRC(const std::wstring& wsRC);
|
||||
void SetAC(const std::wstring& wsAC);
|
||||
void SetI(CImageDict* pI, const char* pImgName, const char* pFrmName);
|
||||
void SetRI(CImageDict* pRI, const char* pImgName, const char* pFrmName);
|
||||
void SetIX(CImageDict* pIX, const char* pImgName, const char* pFrmName);
|
||||
|
||||
CXObject* SetAP(CImageDict* pImage, const char* pImgName, const char* pFrmName);
|
||||
void SetAP(CImageDict* pImage, const std::string& sAP, const std::string& sImgName, const std::string& sFrmName);
|
||||
void SetCaptionAP(unsigned short* pCodes, unsigned int unCount, double dX, double dY, CFontCidTrueType** ppFonts);
|
||||
|
||||
int m_nI, m_nRI, m_nIX;
|
||||
};
|
||||
class CCheckBoxWidget : public CWidgetAnnotation
|
||||
|
||||
@ -1401,19 +1401,19 @@ namespace PdfWriter
|
||||
{
|
||||
std::string sFrmName = "FRM" + std::to_string(it->first) + "I";
|
||||
std::string sImgName = "Img" + std::to_string(pPBWidget->m_nI);
|
||||
pPBWidget->SetI(arrButtonImg[pPBWidget->m_nI], sImgName.c_str(), sFrmName.c_str());
|
||||
pPBWidget->SetAP(arrButtonImg[pPBWidget->m_nI], "I", sImgName, sFrmName);
|
||||
}
|
||||
if (pPBWidget->m_nRI >= 0)
|
||||
{
|
||||
std::string sFrmName = "FRM" + std::to_string(it->first) + "RI";
|
||||
std::string sImgName = "Img" + std::to_string(pPBWidget->m_nRI);
|
||||
pPBWidget->SetRI(arrButtonImg[pPBWidget->m_nRI], sImgName.c_str(), sFrmName.c_str());
|
||||
pPBWidget->SetAP(arrButtonImg[pPBWidget->m_nRI], "RI", sImgName, sFrmName);
|
||||
}
|
||||
if (pPBWidget->m_nIX >= 0)
|
||||
{
|
||||
std::string sFrmName = "FRM" + std::to_string(it->first) + "IX";
|
||||
std::string sImgName = "Img" + std::to_string(pPBWidget->m_nIX);
|
||||
pPBWidget->SetIX(arrButtonImg[pPBWidget->m_nIX], sImgName.c_str(), sFrmName.c_str());
|
||||
pPBWidget->SetAP(arrButtonImg[pPBWidget->m_nIX], "IX", sImgName, sFrmName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1613,12 +1613,13 @@ namespace PdfWriter
|
||||
//----------------------------------------------------------------------------------------
|
||||
void CAnnotAppearanceObject::Init(CXref* pXref, CResourcesDict* pResources, TRect* pRect)
|
||||
{
|
||||
m_pXref = pXref;
|
||||
m_pXref = pXref ? pXref : NULL;
|
||||
m_pStream = new CMemoryStream();
|
||||
m_pFont = NULL;
|
||||
m_dFontSize = 10.0;
|
||||
|
||||
SetStream(m_pXref, m_pStream);
|
||||
if (m_pXref)
|
||||
SetStream(m_pXref, m_pStream);
|
||||
|
||||
Add("Type", "XObject");
|
||||
Add("Subtype", "Form");
|
||||
|
||||
@ -391,6 +391,9 @@ namespace PdfWriter
|
||||
void EndDrawText();
|
||||
|
||||
void DrawTextComment();
|
||||
CStream* GetStream() { return m_pStream; }
|
||||
|
||||
bool m_bStart;
|
||||
|
||||
private:
|
||||
void Init(CXref* pXref, CResourcesDict* pResources, TRect* pRect);
|
||||
@ -400,7 +403,6 @@ namespace PdfWriter
|
||||
CFieldBase* m_pField;
|
||||
double m_dCurX;
|
||||
double m_dCurY;
|
||||
bool m_bStart;
|
||||
CFontDict* m_pFont;
|
||||
double m_dFontSize;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user