mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Find dShiftY for pushbutton
This commit is contained in:
@ -2103,12 +2103,6 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
||||
CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr* pPr = oInfo.GetWidgetAnnotPr()->GetButtonWidgetPr();
|
||||
PdfWriter::CPushButtonWidget* pButtonWidget = (PdfWriter::CPushButtonWidget*)pAnnot;
|
||||
|
||||
if (nFlags & (1 << 10))
|
||||
pButtonWidget->SetCA(pPr->GetCA());
|
||||
if (nFlags & (1 << 11))
|
||||
pButtonWidget->SetRC(pPr->GetRC());
|
||||
if (nFlags & (1 << 12))
|
||||
pButtonWidget->SetAC(pPr->GetAC());
|
||||
BYTE nTP = 0;
|
||||
if (nFlags & (1 << 13))
|
||||
{
|
||||
@ -2141,6 +2135,24 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
||||
|
||||
// ВНЕШНИЙ ВИД
|
||||
pButtonWidget->SetFont(m_pFont, dFontSize, isBold, isItalic);
|
||||
if (nFlags & (1 << 10))
|
||||
{
|
||||
pButtonWidget->SetCA(pPr->GetCA());
|
||||
if (nTP == 0)
|
||||
DrawButtonWidget(pAppFonts, pButtonWidget, 0, NULL);
|
||||
}
|
||||
if (nFlags & (1 << 11))
|
||||
{
|
||||
pButtonWidget->SetRC(pPr->GetRC());
|
||||
if (nTP == 0)
|
||||
DrawButtonWidget(pAppFonts, pButtonWidget, 1, NULL);
|
||||
}
|
||||
if (nFlags & (1 << 12))
|
||||
{
|
||||
pButtonWidget->SetAC(pPr->GetAC());
|
||||
if (nTP == 0)
|
||||
DrawButtonWidget(pAppFonts, pButtonWidget, 2, NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2444,10 +2456,12 @@ HRESULT CPdfWriter::EditWidgetParents(NSFonts::IApplicationFonts* pAppFonts, CWi
|
||||
continue;
|
||||
|
||||
PdfWriter::CPushButtonWidget* pPBWidget = (PdfWriter::CPushButtonWidget*)pAnnot;
|
||||
DrawButtonWidget(pAppFonts, pPBWidget,
|
||||
pPBWidget->m_nI >= 0 ? arrForm[pPBWidget->m_nI] : NULL,
|
||||
pPBWidget->m_nRI >= 0 ? arrForm[pPBWidget->m_nRI] : NULL,
|
||||
pPBWidget->m_nIX >= 0 ? arrForm[pPBWidget->m_nIX] : NULL);
|
||||
if (pPBWidget->m_nI >= 0)
|
||||
DrawButtonWidget(pAppFonts, pPBWidget, 0, arrForm[pPBWidget->m_nI]);
|
||||
if (pPBWidget->m_nRI >= 0)
|
||||
DrawButtonWidget(pAppFonts, pPBWidget, 1, arrForm[pPBWidget->m_nRI]);
|
||||
if (pPBWidget->m_nIX >= 0)
|
||||
DrawButtonWidget(pAppFonts, pPBWidget, 2, arrForm[pPBWidget->m_nIX]);
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
@ -3519,22 +3533,30 @@ void CPdfWriter::DrawChoiceWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWrit
|
||||
RELEASEARRAYOBJECTS(ppFonts);
|
||||
}
|
||||
}
|
||||
void CPdfWriter::DrawButtonWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CPushButtonWidget* pButtonWidget, PdfWriter::CXObject* pFormI, PdfWriter::CXObject* pFormRI, PdfWriter::CXObject* pFormIX)
|
||||
void CPdfWriter::DrawButtonWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CPushButtonWidget* pButtonWidget, BYTE nAP, PdfWriter::CXObject* pForm)
|
||||
{
|
||||
if (!pAppFonts || !pButtonWidget || (!pFormI && !pFormRI && !pFormIX))
|
||||
if (!pAppFonts || !pButtonWidget)
|
||||
return;
|
||||
|
||||
double dShiftX = 0;
|
||||
double dShiftY = 0;
|
||||
double dLineW = 0;
|
||||
double dLineH = 0;
|
||||
unsigned int unLen = 0;
|
||||
unsigned int* pUnicodes = NULL;
|
||||
unsigned short* pCodes = NULL;
|
||||
PdfWriter::CFontCidTrueType** ppFonts = NULL;
|
||||
std::wstring wsValue = pButtonWidget->GetCA();
|
||||
BYTE nTP = pButtonWidget->GetTP();
|
||||
std::wstring wsValue;
|
||||
if (nAP == 0)
|
||||
wsValue = pButtonWidget->GetCA();
|
||||
else if (nAP == 1)
|
||||
wsValue = pButtonWidget->GetRC();
|
||||
else
|
||||
wsValue = pButtonWidget->GetAC();
|
||||
|
||||
if (!pButtonWidget->HaveBorder() && pButtonWidget->HaveBC())
|
||||
pButtonWidget->SetBorder(0, 1, {});
|
||||
if (!pButtonWidget->HaveBorder())
|
||||
pButtonWidget->SetEmptyBorder();
|
||||
|
||||
if (!wsValue.empty() && nTP != 1)
|
||||
{
|
||||
@ -3545,12 +3567,17 @@ void CPdfWriter::DrawButtonWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWrit
|
||||
double dFontSize = pButtonWidget->GetFontSize();
|
||||
bool isBold = pButtonWidget->GetFontIsBold();
|
||||
bool isItalic = pButtonWidget->GetFontIsItalic();
|
||||
double dWidth = pButtonWidget->GetWidth();
|
||||
double dHeight = pButtonWidget->GetHeight();
|
||||
|
||||
double dShiftBorder = pButtonWidget->GetBorderWidth();
|
||||
BYTE nType = pButtonWidget->GetBorderType();
|
||||
if (nType == 1 || nType == 3)
|
||||
dShiftBorder *= 2;
|
||||
if (dShiftBorder == 0)
|
||||
dShiftBorder = 1;
|
||||
if (!pButtonWidget->GetRespectBorder())
|
||||
dShiftBorder = 0;
|
||||
|
||||
bool bFont = GetFontData(pAppFonts, wsValue, pFont, isBold, isItalic, pUnicodes, unLen, pCodes, ppFonts);
|
||||
if (!bFont)
|
||||
@ -3561,35 +3588,48 @@ void CPdfWriter::DrawButtonWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWrit
|
||||
return;
|
||||
}
|
||||
|
||||
dShiftX = dShiftBorder * 2;
|
||||
if (dShiftX == 0)
|
||||
dShiftX = 2;
|
||||
dShiftY = (dHeight - dFontSize) / 2.0 - dShiftBorder;
|
||||
if (pFontTT)
|
||||
dShiftY = (dHeight - pFontTT->m_dHeight * dFontSize / pFontTT->m_dUnitsPerEm) / 2.0 + std::abs(pFontTT->m_dDescent * dFontSize / pFontTT->m_dUnitsPerEm);
|
||||
|
||||
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;
|
||||
dLineW += dLetterWidth;
|
||||
}
|
||||
|
||||
if (pFontTT)
|
||||
{
|
||||
double dKoef = dFontSize / pFontTT->m_dUnitsPerEm;
|
||||
dLineH = pFontTT->m_dHeight * dKoef;
|
||||
|
||||
if (nTP == 0 || nTP == 2 || nTP == 3 || nTP == 6)
|
||||
dShiftX = (dWidth - dLineW) / 2;
|
||||
else if (nTP == 4)
|
||||
dShiftX = dWidth - dLineW - dShiftBorder * 2;
|
||||
else if (nTP == 5)
|
||||
dShiftX = dShiftBorder * 2;
|
||||
|
||||
if (nTP == 0 || nTP == 4 || nTP == 5 || nTP == 6)
|
||||
dShiftY = (dHeight - dLineH) / 2.0 + std::abs(pFontTT->m_dDescent * dKoef);
|
||||
else if (nTP == 3)
|
||||
dShiftY = dHeight - dShiftBorder * 2 - dLineH + std::abs(pFontTT->m_dDescent * dKoef);
|
||||
else if (nTP == 2)
|
||||
{
|
||||
// double dLineHeight = pFontTT->m_dHeight * dKoef;
|
||||
// double dDescent = std::abs(pFontTT->m_dDescent * dKoef);
|
||||
// double dAscent1 = pFontTT->m_dAscent * dKoef;
|
||||
// double dAscent = dLineHeight - dDescent;
|
||||
// double dMin = pFontTT->m_dMinY * dKoef;
|
||||
// double dMax = pFontTT->m_dMaxY * dKoef;
|
||||
// double dMidPoint = dAscent - pFontTT->m_dMinY * dKoef + dAscent - pFontTT->m_dMaxY * dKoef;
|
||||
// double dDiff = dLineHeight - dMidPoint;
|
||||
// dShiftY = dLineHeight / 2.0;
|
||||
// dShiftY = dShiftY + dDescent;
|
||||
// Find! PERFECT!!!
|
||||
dShiftY = dShiftBorder * 2 + std::abs(pFontTT->m_dMinY * dKoef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (pButtonWidget->GetTP())
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (pFormI)
|
||||
pButtonWidget->SetAP(pFormI, "I", pCodes, unLen, dShiftX, dShiftY, ppFonts);
|
||||
if (pFormRI)
|
||||
pButtonWidget->SetAP(pFormRI, "RI", pCodes, unLen, dShiftX, dShiftY, ppFonts);
|
||||
if (pFormIX)
|
||||
pButtonWidget->SetAP(pFormIX, "IX", pCodes, unLen, dShiftX, dShiftY, ppFonts);
|
||||
pButtonWidget->SetAP(pForm, nAP, pCodes, unLen, dShiftX, dShiftY, dLineW, dLineH, ppFonts);
|
||||
|
||||
RELEASEARRAYOBJECTS(pUnicodes);
|
||||
RELEASEARRAYOBJECTS(pCodes);
|
||||
|
||||
@ -245,7 +245,7 @@ private:
|
||||
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);
|
||||
void DrawButtonWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CPushButtonWidget* pButtonWidget, PdfWriter::CXObject* pFormI, PdfWriter::CXObject* pFormRI, PdfWriter::CXObject* pFormIX);
|
||||
void DrawButtonWidget(NSFonts::IApplicationFonts* pAppFonts, PdfWriter::CPushButtonWidget* pButtonWidget, BYTE nAP, PdfWriter::CXObject* pForm);
|
||||
|
||||
private:
|
||||
NSFonts::IFontManager* m_pFontManager;
|
||||
|
||||
@ -219,6 +219,12 @@ namespace PdfWriter
|
||||
m_oBorder.dWidth = dWidth;
|
||||
m_oBorder.arrDash = arrDash;
|
||||
}
|
||||
void CAnnotation::SetEmptyBorder()
|
||||
{
|
||||
m_oBorder.bHave = true;
|
||||
m_oBorder.nType = 0;
|
||||
m_oBorder.dWidth = 1;
|
||||
}
|
||||
void CAnnotation::SetAnnotFlag(const int& nAnnotFlag)
|
||||
{
|
||||
Add("F", nAnnotFlag);
|
||||
@ -1218,6 +1224,7 @@ namespace PdfWriter
|
||||
|
||||
std::string sValue = U_TO_UTF8(wsRC);
|
||||
m_pMK->Add("RC", new CStringObject(sValue.c_str(), true));
|
||||
m_wsRC = wsRC;
|
||||
}
|
||||
void CPushButtonWidget::SetAC(const std::wstring& wsAC)
|
||||
{
|
||||
@ -1225,19 +1232,20 @@ namespace PdfWriter
|
||||
|
||||
std::string sValue = U_TO_UTF8(wsAC);
|
||||
m_pMK->Add("AC", new CStringObject(sValue.c_str(), true));
|
||||
m_wsAC = wsAC;
|
||||
}
|
||||
void CPushButtonWidget::SetAP(CXObject* pForm, const std::string& sAP, unsigned short* pCodes, unsigned int unCount, double dX, double dY, CFontCidTrueType** ppFonts)
|
||||
void CPushButtonWidget::SetAP(CXObject* pForm, BYTE nAP, unsigned short* pCodes, unsigned int unCount, double dX, double dY, double dLineW, double dLineH, CFontCidTrueType** ppFonts)
|
||||
{
|
||||
m_pAppearance = new CAnnotAppearance(m_pXref, this);
|
||||
if (!m_pAppearance)
|
||||
return;
|
||||
|
||||
CAnnotAppearanceObject* pAppearance = NULL;
|
||||
if (sAP == "I")
|
||||
if (nAP == 0)
|
||||
pAppearance = m_pAppearance->GetNormal();
|
||||
else if (sAP == "RI")
|
||||
else if (nAP == 1)
|
||||
pAppearance = m_pAppearance->GetRollover();
|
||||
else if (sAP == "IX")
|
||||
else if (nAP == 2)
|
||||
pAppearance = m_pAppearance->GetDown();
|
||||
if (!pAppearance)
|
||||
return;
|
||||
@ -1245,10 +1253,12 @@ namespace PdfWriter
|
||||
|
||||
if (pForm)
|
||||
{
|
||||
TRect oRect = GetRect();
|
||||
|
||||
double dH = fabs(oRect.fTop - oRect.fBottom);
|
||||
double dW = fabs(oRect.fRight - oRect.fLeft);
|
||||
double dH = fabs(m_oRect.fTop - m_oRect.fBottom);
|
||||
double dW = fabs(m_oRect.fRight - m_oRect.fLeft);
|
||||
if (m_nTP == 2 || m_nTP == 3)
|
||||
dH -= dLineH;
|
||||
if (m_nTP == 4 || m_nTP == 5)
|
||||
dW -= dLineW;
|
||||
|
||||
double dOriginW = pForm->GetWidth();
|
||||
double dOriginH = pForm->GetHeight();
|
||||
@ -1261,10 +1271,16 @@ namespace PdfWriter
|
||||
double dDstH = dOriginH;
|
||||
double dDstX = 0;
|
||||
double dDstY = 0;
|
||||
if (m_nTP == 2 || m_nTP == 3)
|
||||
dDstY += dLineH;
|
||||
if (m_nTP == 4 || m_nTP == 5)
|
||||
dDstX += dLineW;
|
||||
|
||||
if (m_bRespectBorders && HaveBorder())
|
||||
if (m_bRespectBorders && m_oBorder.bHave)
|
||||
{
|
||||
double dBorderSize = GetBorderWidth();
|
||||
double dBorderSize = m_oBorder.dWidth;
|
||||
if (m_oBorder.nType == 1 || m_oBorder.nType == 3)
|
||||
dBorderSize *= 2;
|
||||
dDstX += 2 * dBorderSize;
|
||||
dDstY += 2 * dBorderSize;
|
||||
dH -= 4 * dBorderSize;
|
||||
@ -1292,19 +1308,24 @@ namespace PdfWriter
|
||||
pAppearance->DrawPicture(pForm->GetName().c_str(), dDstX, dDstY, dDstW / dOriginW, dDstH / dOriginH, m_bRespectBorders);
|
||||
}
|
||||
else
|
||||
pAppearance->DrawPicture();
|
||||
pAppearance->StartDrawText(m_pFont, m_dFontSize, 0, 0, 0, NULL, fabs(m_oRect.fRight - m_oRect.fLeft), fabs(m_oRect.fBottom - m_oRect.fTop));
|
||||
|
||||
if (pCodes)
|
||||
{
|
||||
CStream* pStream = pAppearance->GetStream();
|
||||
pStream->WriteStr("\012q\012BT\012");
|
||||
if (pForm)
|
||||
pStream->WriteStr("\012q\012BT\012");
|
||||
pAppearance->DrawTextLine(dX, dY, pCodes, unCount, ppFonts, NULL);
|
||||
pStream->WriteStr("ET\012Q\012");
|
||||
if (pForm)
|
||||
pStream->WriteStr("ET\012Q\012");
|
||||
else
|
||||
pAppearance->EndDrawText();
|
||||
}
|
||||
|
||||
if (pForm)
|
||||
{
|
||||
CheckMK();
|
||||
std::string sAP = nAP == 0 ? "I" : (nAP == 1 ? "RI" : "IX");
|
||||
m_pMK->Add(sAP, pForm);
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,6 +141,7 @@ namespace PdfWriter
|
||||
|
||||
void SetRect(const TRect& oRect);
|
||||
void SetBorder(BYTE nType, double dWidth, const std::vector<double>& arrDash);
|
||||
void SetEmptyBorder();
|
||||
void SetAnnotFlag(const int& nAnnotFlag);
|
||||
void SetPage(CPage* pPage);
|
||||
void SetBE(BYTE nType, const double& dBE);
|
||||
@ -417,8 +418,9 @@ namespace PdfWriter
|
||||
double m_dShiftX;
|
||||
double m_dShiftY;
|
||||
std::wstring m_wsCA;
|
||||
std::wstring m_wsRC;
|
||||
std::wstring m_wsAC;
|
||||
CDictObject* m_pIF;
|
||||
std::string m_sCaptionForAP;
|
||||
|
||||
void CheckIF();
|
||||
|
||||
@ -439,9 +441,12 @@ namespace PdfWriter
|
||||
void SetRC(const std::wstring& wsRC);
|
||||
void SetAC(const std::wstring& wsAC);
|
||||
|
||||
void SetAP(CXObject* pForm, const std::string& sAP, unsigned short* pCodes, unsigned int unCount, double dX, double dY, CFontCidTrueType** ppFonts);
|
||||
void SetAP(CXObject* pForm, BYTE nAP, unsigned short* pCodes, unsigned int unCount, double dX, double dY, double dLineW, double dLineH, CFontCidTrueType** ppFonts);
|
||||
const std::wstring& GetCA() { return m_wsCA; }
|
||||
const std::wstring& GetRC() { return m_wsRC; }
|
||||
const std::wstring& GetAC() { return m_wsAC; }
|
||||
BYTE GetTP() { return m_nTP; }
|
||||
bool GetRespectBorder() { return m_bRespectBorders; }
|
||||
|
||||
int m_nI, m_nRI, m_nIX;
|
||||
};
|
||||
|
||||
@ -2100,13 +2100,23 @@ namespace PdfWriter
|
||||
|
||||
m_pStream->WriteStr("q\012");
|
||||
|
||||
m_pStream->WriteReal(dBorderSizeStyle);
|
||||
m_pStream->WriteChar(' ');
|
||||
m_pStream->WriteReal(dBorderSizeStyle);
|
||||
m_pStream->WriteChar(' ');
|
||||
m_pStream->WriteReal(std::max(dWidth - dBorderSizeStyle * 2, 0.0));
|
||||
m_pStream->WriteChar(' ');
|
||||
m_pStream->WriteReal(std::max(dHeight - dBorderSizeStyle * 2, 0.0));
|
||||
if (pAnnot && pAnnot->GetWidgetType() == WidgetPushbutton && !((CPushButtonWidget*)pAnnot)->GetRespectBorder())
|
||||
{
|
||||
m_pStream->WriteStr("0 0 ");
|
||||
m_pStream->WriteReal(std::max(dWidth, 0.0));
|
||||
m_pStream->WriteChar(' ');
|
||||
m_pStream->WriteReal(std::max(dHeight, 0.0));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pStream->WriteReal(dBorderSizeStyle);
|
||||
m_pStream->WriteChar(' ');
|
||||
m_pStream->WriteReal(dBorderSizeStyle);
|
||||
m_pStream->WriteChar(' ');
|
||||
m_pStream->WriteReal(std::max(dWidth - dBorderSizeStyle * 2, 0.0));
|
||||
m_pStream->WriteChar(' ');
|
||||
m_pStream->WriteReal(std::max(dHeight - dBorderSizeStyle * 2, 0.0));
|
||||
}
|
||||
m_pStream->WriteStr(" re\012W\012n\012");
|
||||
|
||||
if (pAnnot && pAnnot->GetWidgetType() == WidgetListbox)
|
||||
@ -2130,10 +2140,6 @@ namespace PdfWriter
|
||||
m_pStream->WriteStr(" re\012f\012");
|
||||
}
|
||||
}
|
||||
if (pAnnot && pAnnot->GetWidgetType() == WidgetPushbutton)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
m_pStream->WriteStr("BT\012");
|
||||
|
||||
|
||||
@ -179,6 +179,7 @@ namespace PdfWriter
|
||||
|
||||
m_dHeight = pFace->height;
|
||||
m_dDescent = pFace->descender;
|
||||
m_dAscent = pFace->ascender;
|
||||
m_dUnitsPerEm = pFace->units_per_EM;
|
||||
m_dMaxY = pFace->bbox.yMax;
|
||||
m_dMinY = pFace->bbox.yMin;
|
||||
|
||||
@ -75,6 +75,7 @@ namespace PdfWriter
|
||||
double m_dUnitsPerEm;
|
||||
double m_dHeight;
|
||||
double m_dDescent;
|
||||
double m_dAscent;
|
||||
double m_dMaxY;
|
||||
double m_dMinY;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user