mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-04-07 13:55:33 +08:00
Fix Opt for radiobutton, fix unicode for JS
This commit is contained in:
@ -718,6 +718,13 @@
|
||||
for (let i = 0; i < n; ++i)
|
||||
rec["value"].push(reader.readString());
|
||||
}
|
||||
if (flags & (1 << 6))
|
||||
{
|
||||
let n = reader.readInt();
|
||||
rec["Opt"] = [];
|
||||
for (let i = 0; i < n; ++i)
|
||||
rec["Opt"].push(reader.readString());
|
||||
}
|
||||
res["Parents"].push(rec);
|
||||
}
|
||||
|
||||
|
||||
@ -356,6 +356,21 @@ void ReadInteractiveForms(BYTE* pWidgets, int& i)
|
||||
}
|
||||
std::cout << ", ";
|
||||
}
|
||||
if (nFlags & (1 << 6))
|
||||
{
|
||||
int nILength = READ_INT(pWidgets + i);
|
||||
i += 4;
|
||||
std::cout << "Opt [";
|
||||
|
||||
for (int j = 0; j < nILength; ++j)
|
||||
{
|
||||
nPathLength = READ_INT(pWidgets + i);
|
||||
i += 4;
|
||||
std::cout << " " << std::string((char*)(pWidgets + i), nPathLength);
|
||||
i += nPathLength;
|
||||
}
|
||||
std::cout << " ], ";
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
@ -101,7 +101,7 @@ void DictToCDictObject(Object* obj, PdfWriter::CObjectBase* pObj, bool bBinary,
|
||||
{
|
||||
TextString* s = new TextString(obj->getString());
|
||||
std::string sValue = NSStringExt::CConverter::GetUtf8FromUTF32(s->getUnicode(), s->getLength());
|
||||
AddToObject(new PdfWriter::CStringObject(sValue.c_str()))
|
||||
AddToObject(new PdfWriter::CStringObject(sValue.c_str(), true))
|
||||
delete s;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -2253,16 +2253,17 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
||||
pTextWidget->SetMaxLen(pPr->GetMaxLen());
|
||||
if (nWidgetFlag & (1 << 25))
|
||||
pTextWidget->SetRV(pPr->GetRV());
|
||||
bool bAPValue = false;
|
||||
if (nFlags & (1 << 12))
|
||||
{
|
||||
bValue = true;
|
||||
bAPValue = true;
|
||||
wsValue = pPr->GetAPV();
|
||||
pTextWidget->SetAPV();
|
||||
}
|
||||
|
||||
// ВНЕШНИЙ ВИД
|
||||
pTextWidget->SetFont(m_pFont, dFontSize, isBold, isItalic);
|
||||
if (bValue)
|
||||
if ((bValue && pTextWidget->Get("T")) || bAPValue)
|
||||
DrawTextWidget(pAppFonts, pTextWidget, wsValue);
|
||||
}
|
||||
else if (oInfo.IsChoiceWidget())
|
||||
@ -2383,7 +2384,7 @@ HRESULT CPdfWriter::EditWidgetParents(NSFonts::IApplicationFonts* pAppFonts, CWi
|
||||
if (nFlags & (1 << 1))
|
||||
{
|
||||
std::string sV = U_TO_UTF8(pParent->sV);
|
||||
pParentObj->Add("V", new PdfWriter::CStringObject(sV.c_str(), true));
|
||||
bool bName = !sV.empty() && (iswdigit(pParent->sV[0]) || sV == "Off");
|
||||
|
||||
PdfWriter::CObjectBase* pKids = pParentObj->Get("Kids");
|
||||
if (pKids && pKids->GetType() == PdfWriter::object_type_ARRAY)
|
||||
@ -2407,15 +2408,22 @@ HRESULT CPdfWriter::EditWidgetParents(NSFonts::IApplicationFonts* pAppFonts, CWi
|
||||
{
|
||||
PdfWriter::CChoiceWidget* pKid = dynamic_cast<PdfWriter::CChoiceWidget*>(pObj);
|
||||
DrawChoiceWidget(pAppFonts, pKid, {pParent->sV});
|
||||
bName = false;
|
||||
}
|
||||
if (nType == PdfWriter::WidgetText)
|
||||
{
|
||||
PdfWriter::CTextWidget* pKid = dynamic_cast<PdfWriter::CTextWidget*>(pObj);
|
||||
if (!pKid->HaveAPV())
|
||||
DrawTextWidget(pAppFonts, pKid, pParent->sV);
|
||||
bName = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bName)
|
||||
pParentObj->Add("V", sV.c_str());
|
||||
else
|
||||
pParentObj->Add("V", new PdfWriter::CStringObject(sV.c_str(), true));
|
||||
}
|
||||
if (nFlags & (1 << 2))
|
||||
pParentObj->Add("DV", new PdfWriter::CStringObject((U_TO_UTF8(pParent->sDV)).c_str(), true));
|
||||
|
||||
@ -587,6 +587,9 @@ CAnnotWidgetBtn::CAnnotWidgetBtn(PDFDoc* pdfDoc, AcroFormField* pField) : CAnnot
|
||||
}
|
||||
oMK.free();
|
||||
|
||||
Object oOpt;
|
||||
pField->fieldLookup("Opt", &oOpt);
|
||||
|
||||
// 15 - Имя вкл состояния - AP - N - Yes
|
||||
Object oNorm;
|
||||
if (pField->fieldLookup("AP", &oObj)->isDict() && oObj.dictLookup("N", &oNorm)->isDict())
|
||||
@ -598,11 +601,41 @@ CAnnotWidgetBtn::CAnnotWidgetBtn(PDFDoc* pdfDoc, AcroFormField* pField) : CAnnot
|
||||
{
|
||||
m_unFlags |= (1 << 14);
|
||||
m_sAP_N_Yes = sNormName;
|
||||
|
||||
int nOptI;
|
||||
if (oOpt.isArray() && isdigit(sNormName[0]) && (nOptI = std::stoi(sNormName)) >= 0 && nOptI < oOpt.arrayGetLength())
|
||||
{
|
||||
Object oOptJ;
|
||||
if (!oOpt.arrayGet(nOptI, &oOptJ) || !(oOptJ.isString() || oOptJ.isArray()))
|
||||
{
|
||||
oOptJ.free();
|
||||
break;
|
||||
}
|
||||
|
||||
if (oOptJ.isString())
|
||||
{
|
||||
TextString* s = new TextString(oOptJ.getString());
|
||||
m_sAP_N_Yes = NSStringExt::CConverter::GetUtf8FromUTF32(s->getUnicode(), s->getLength());
|
||||
delete s;
|
||||
}
|
||||
else if (oOptJ.isArray() && oOptJ.arrayGetLength() > 0)
|
||||
{
|
||||
Object oOptJ2;
|
||||
if (oOptJ.arrayGet(0, &oOptJ2)->isString())
|
||||
{
|
||||
TextString* s = new TextString(oOptJ2.getString());
|
||||
m_sAP_N_Yes = NSStringExt::CConverter::GetUtf8FromUTF32(s->getUnicode(), s->getLength());
|
||||
delete s;
|
||||
}
|
||||
oOptJ2.free();
|
||||
}
|
||||
oOptJ.free();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
oNorm.free(); oObj.free();
|
||||
oNorm.free(); oObj.free(); oOpt.free();
|
||||
}
|
||||
|
||||
CAnnotWidgetTx::CAnnotWidgetTx(PDFDoc* pdfDoc, AcroFormField* pField) : CAnnotWidget(pdfDoc, pField)
|
||||
@ -907,6 +940,9 @@ CAnnotWidget::CAnnotWidget(PDFDoc* pdfDoc, AcroFormField* pField) : CAnnot(pdfDo
|
||||
Object oAA;
|
||||
Object parent, parent2;
|
||||
bool bParent = oField.dictLookup("Parent", &parent)->isDict();
|
||||
bool bAA = bParent && parent.dictLookup("AA", &oAA)->isDict();
|
||||
oAA.free();
|
||||
|
||||
if (oField.dictLookup("AA", &oAA)->isDict())
|
||||
{
|
||||
for (int j = 0; j < oAA.dictGetLength(); ++j)
|
||||
@ -914,7 +950,7 @@ CAnnotWidget::CAnnotWidget(PDFDoc* pdfDoc, AcroFormField* pField) : CAnnot(pdfDo
|
||||
if (oAA.dictGetVal(j, &oAction)->isDict())
|
||||
{
|
||||
std::string sAA(oAA.dictGetKey(j));
|
||||
if (bParent && (sAA == "K" || sAA == "F" || sAA == "V" || sAA == "C"))
|
||||
if (bAA && (sAA == "K" || sAA == "F" || sAA == "V" || sAA == "C"))
|
||||
continue;
|
||||
CAction* pA = getAction(pdfDoc, &oAction);
|
||||
if (pA)
|
||||
@ -2033,6 +2069,29 @@ void CAnnots::getParents(XRef* xref, Object* oFieldRef)
|
||||
}
|
||||
oI.free();
|
||||
|
||||
Object oOpt;
|
||||
// 6 - Opt
|
||||
if (oField.dictLookup("Opt", &oOpt)->isArray())
|
||||
{
|
||||
int nOptLength = oOpt.arrayGetLength();
|
||||
for (int j = 0; j < nOptLength; ++j)
|
||||
{
|
||||
Object oOptJ;
|
||||
if (!oOpt.arrayGet(j, &oOptJ) || !oOptJ.isString())
|
||||
{
|
||||
oOptJ.free();
|
||||
continue;
|
||||
}
|
||||
|
||||
TextString* s = new TextString(oOptJ.getString());
|
||||
pAnnotParent->arrOpt.push_back(NSStringExt::CConverter::GetUtf8FromUTF32(s->getUnicode(), s->getLength()));
|
||||
delete s;
|
||||
}
|
||||
if (!pAnnotParent->arrOpt.empty())
|
||||
pAnnotParent->unFlags |= (1 << 6);
|
||||
}
|
||||
oOpt.free();
|
||||
|
||||
m_arrParents.push_back(pAnnotParent);
|
||||
|
||||
Object oParentRefObj;
|
||||
@ -2758,6 +2817,12 @@ void CAnnots::CAnnotParent::ToWASM(NSWasm::CData& oRes)
|
||||
for (int i = 0; i < arrV.size(); ++i)
|
||||
oRes.WriteString(arrV[i]);
|
||||
}
|
||||
if (unFlags & (1 << 6))
|
||||
{
|
||||
oRes.AddInt((unsigned int)arrOpt.size());
|
||||
for (int i = 0; i < arrOpt.size(); ++i)
|
||||
oRes.WriteString(arrOpt[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void CAnnot::ToWASM(NSWasm::CData& oRes)
|
||||
|
||||
@ -572,6 +572,7 @@ private:
|
||||
unsigned int unRefNumParent; // Номер ссылки на объект родителя
|
||||
std::vector<int> arrI;
|
||||
std::vector<std::string> arrV;
|
||||
std::vector<std::string> arrOpt;
|
||||
std::string sT;
|
||||
std::string sV;
|
||||
std::string sDV;
|
||||
|
||||
@ -968,7 +968,7 @@ namespace PdfWriter
|
||||
CDictObject* pOwner = GetObjOwnValue("TU");
|
||||
if (!pOwner)
|
||||
pOwner = this;
|
||||
pOwner->Add("TU", new CStringObject(sValue.c_str()));
|
||||
pOwner->Add("TU", new CStringObject(sValue.c_str(), true));
|
||||
}
|
||||
void CWidgetAnnotation::SetDS(const std::wstring& wsDS)
|
||||
{
|
||||
@ -1024,14 +1024,7 @@ namespace PdfWriter
|
||||
std::string sAA = pAction->m_sType;
|
||||
CDictObject* pAA = NULL;
|
||||
if (m_pParent && (sAA == "K" || sAA == "F" || sAA == "V" || sAA == "C"))
|
||||
{
|
||||
pAA = (CDictObject*)m_pParent->Get("AA");
|
||||
if (!pAA)
|
||||
{
|
||||
pAA = new CDictObject();
|
||||
m_pParent->Add("AA", pAA);
|
||||
}
|
||||
}
|
||||
else if (sAA == "E" || sAA == "X" || sAA == "D" || sAA == "U" || sAA == "Fo" || sAA == "Bl" || sAA == "PO" || sAA == "PC" || sAA == "PV" || sAA == "PI")
|
||||
{
|
||||
pAA = (CDictObject*)Get("AA");
|
||||
@ -1411,7 +1404,11 @@ namespace PdfWriter
|
||||
CDictObject* pOwner = GetObjOwnValue("V");
|
||||
if (!pOwner)
|
||||
pOwner = this;
|
||||
pOwner->Add("V", new CStringObject(sV.c_str(), true));
|
||||
|
||||
if (isdigit(sV[0]))
|
||||
pOwner->Add("V", sV.c_str());
|
||||
else
|
||||
pOwner->Add("V", new CStringObject(sV.c_str(), true));
|
||||
}
|
||||
std::wstring CCheckBoxWidget::SetStyle(BYTE nStyle)
|
||||
{
|
||||
@ -1446,7 +1443,11 @@ namespace PdfWriter
|
||||
}
|
||||
void CCheckBoxWidget::SwitchAP(const std::string& sV)
|
||||
{
|
||||
Add("AS", sV == m_sAP_N_Yes ? sV.c_str() : "Off");
|
||||
CObjectBase* pAP, *pAPN;
|
||||
if ((pAP = Get("AP")) && pAP->GetType() == object_type_DICT && (pAPN = ((CDictObject*)pAP)->Get("N")) && pAPN->GetType() == object_type_DICT && ((CDictObject*)pAPN)->Get(sV))
|
||||
Add("AS", sV.c_str());
|
||||
else
|
||||
Add("AS", "Off");
|
||||
}
|
||||
void CCheckBoxWidget::SetFlag(const int& nFlag)
|
||||
{
|
||||
@ -1701,7 +1702,7 @@ namespace PdfWriter
|
||||
for (const std::wstring& A : arrFileds)
|
||||
{
|
||||
std::string sValue = U_TO_UTF8(A);
|
||||
pArray->Add(new CStringObject(sValue.c_str()));
|
||||
pArray->Add(new CStringObject(sValue.c_str(), true));
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
@ -1712,7 +1713,7 @@ namespace PdfWriter
|
||||
void CActionJavaScript::SetJS(const std::wstring& wsJS)
|
||||
{
|
||||
std::string sValue = U_TO_UTF8(wsJS);
|
||||
Add("JS", new CStringObject(sValue.c_str()));
|
||||
Add("JS", new CStringObject(sValue.c_str(), true));
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
CActionGoTo::CActionGoTo(CXref* pXref) : CAction(pXref)
|
||||
@ -1753,7 +1754,7 @@ namespace PdfWriter
|
||||
for (const std::wstring& A : arrT)
|
||||
{
|
||||
std::string sValue = U_TO_UTF8(A);
|
||||
pArray->Add(new CStringObject(sValue.c_str()));
|
||||
pArray->Add(new CStringObject(sValue.c_str(), true));
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
@ -1936,7 +1936,17 @@ namespace PdfWriter
|
||||
|
||||
double dBorderSize = 0;
|
||||
double dBorderSizeStyle = 0;
|
||||
if ((m_pField && m_pField->HaveBorder()) || (pAnnot && pAnnot->HaveBorder()))
|
||||
|
||||
if (pAnnot && pAnnot->HaveBorder())
|
||||
{
|
||||
dBorderSize = pAnnot->GetBorderWidth();
|
||||
dBorderSizeStyle = dBorderSize;
|
||||
|
||||
if (pAnnot->GetBorderType() == 1 || pAnnot->GetBorderType() == 3)
|
||||
dBorderSizeStyle *= 2;
|
||||
}
|
||||
|
||||
if ((m_pField && m_pField->HaveBorder()) || (pAnnot && pAnnot->HaveBorder() && pAnnot->HaveBC()))
|
||||
{
|
||||
m_pStream->WriteStr("q\012");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user