Skip to content

Commit bd838da

Browse files
committed
Merge pull request 'Feature forms' (#246) from feature/forms into release/v9.0.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/core/pulls/246
2 parents d76ddde + 484d934 commit bd838da

File tree

12 files changed

+72
-3
lines changed

12 files changed

+72
-3
lines changed

DesktopEditor/graphics/commands/AnnotField.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::GetDV() { return m_wsDV; }
686686
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::GetT() { return m_wsT; }
687687
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::GetFontName() { return m_wsFN; }
688688
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::GetFontKey() { return m_wsFK; }
689+
const std::wstring& CAnnotFieldInfo::CWidgetAnnotPr::GetOMetadata() { return m_wsOMetadata; }
689690
const std::vector<double>& CAnnotFieldInfo::CWidgetAnnotPr::GetTC() { return m_arrTC; }
690691
const std::vector<double>& CAnnotFieldInfo::CWidgetAnnotPr::GetBC() { return m_arrBC; }
691692
const std::vector<double>& CAnnotFieldInfo::CWidgetAnnotPr::GetBG() { return m_arrBG; }
@@ -886,6 +887,8 @@ void CAnnotFieldInfo::CWidgetAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader
886887
m_nParentID = pReader->ReadInt();
887888
if (nFlags & (1 << 18))
888889
m_wsT = pReader->ReadString();
890+
if (nFlags & (1 << 20))
891+
m_wsOMetadata = pReader->ReadString();
889892

890893
// Action
891894
int nAction = pReader->ReadInt();

DesktopEditor/graphics/commands/AnnotField.h

+2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ class GRAPHICS_DECL CAnnotFieldInfo : public IAdvancedCommand
194194
const std::wstring& GetT();
195195
const std::wstring& GetFontName();
196196
const std::wstring& GetFontKey();
197+
const std::wstring& GetOMetadata();
197198
const std::vector<double>& GetTC();
198199
const std::vector<double>& GetBC();
199200
const std::vector<double>& GetBG();
@@ -223,6 +224,7 @@ class GRAPHICS_DECL CAnnotFieldInfo : public IAdvancedCommand
223224
std::wstring m_wsT;
224225
std::wstring m_wsFN;
225226
std::wstring m_wsFK;
227+
std::wstring m_wsOMetadata;
226228
std::vector<double> m_arrTC;
227229
std::vector<double> m_arrBC;
228230
std::vector<double> m_arrBG;

DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js

+5
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ function readAnnotAP(reader, AP)
519519
// 0 - Normal, 1 - Multiply, 2 - Screen, 3 - Overlay, 4 - Darken, 5 - Lighten, 6 - ColorDodge, 7 - ColorBurn, 8 - HardLight,
520520
// 9 - SoftLight, 10 - Difference, 11 - Exclusion, 12 - Hue, 13 - Saturation, 14 - Color, 15 - Luminosity
521521
APi["BlendMode"] = reader.readByte();
522+
let k = reader.readByte();
523+
if (k != 0)
524+
APi["apValue"] = reader.readString();
522525
}
523526
}
524527

@@ -651,6 +654,8 @@ CFile.prototype["getInteractiveFormsInfo"] = function()
651654
rec["name"] = reader.readString();
652655
if (flags & (1 << 19))
653656
rec["font"]["AP"] = reader.readString();
657+
if (flags & (1 << 20))
658+
rec["meta"] = reader.readString();
654659
// Action
655660
let nAction = reader.readInt();
656661
if (nAction > 0)

DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,13 @@ void ReadInteractiveForms(BYTE* pWidgets, int& i)
542542
std::cout << "Font button " << std::string((char*)(pWidgets + i), nPathLength) << ", ";
543543
i += nPathLength;
544544
}
545+
if (nFlags & (1 << 20))
546+
{
547+
nPathLength = READ_INT(pWidgets + i);
548+
i += 4;
549+
std::cout << "OMetadata " << std::string((char*)(pWidgets + i), nPathLength) << ", ";
550+
i += nPathLength;
551+
}
545552

546553
//Action
547554

@@ -807,6 +814,16 @@ void ReadAnnotAP(BYTE* pWidgetsAP, int& i)
807814
std::string arrBlendMode[] = { "Normal", "Multiply", "Screen", "Overlay", "Darken", "Lighten", "ColorDodge", "ColorBurn", "HardLight",
808815
"SoftLight", "Difference", "Exclusion", "Hue", "Saturation", "Color", "Luminosity" };
809816
std::cout << "Type " << arrBlendMode[nPathLength] << ", ";
817+
818+
int bText = READ_BYTE(pWidgetsAP + i);
819+
i += 1;
820+
if (bText != 0)
821+
{
822+
nPathLength = READ_INT(pWidgetsAP + i);
823+
i += 4;
824+
std::cout << "Text " << std::string((char*)(pWidgetsAP + i), nPathLength) << ", ";
825+
i += nPathLength;
826+
}
810827
}
811828
std::cout << std::endl;
812829
}
@@ -1090,7 +1107,7 @@ int main(int argc, char* argv[])
10901107
}
10911108

10921109
// GLYPHS
1093-
if (true && nPagesCount > 0)
1110+
if (false && nPagesCount > 0)
10941111
{
10951112
BYTE* pGlyphs = GetGlyphs(pGrFile, nTestPage);
10961113
nLength = READ_INT(pGlyphs);
@@ -1165,7 +1182,7 @@ int main(int argc, char* argv[])
11651182
}
11661183

11671184
// INTERACTIVE FORMS
1168-
if (false)
1185+
if (true)
11691186
{
11701187
ReadInteractiveFormsFonts(pGrFile, 1);
11711188
ReadInteractiveFormsFonts(pGrFile, 2);

PdfFile/PdfWriter.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2176,6 +2176,8 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
21762176
pWidgetAnnot->SetDV(pPr->GetDV());
21772177
if (nFlags & (1 << 18))
21782178
pWidgetAnnot->SetT(pPr->GetT());
2179+
if (nFlags & (1 << 20))
2180+
pWidgetAnnot->SetOMetadata(pPr->GetOMetadata());
21792181

21802182
const std::vector<CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget*> arrActions = pPr->GetActions();
21812183
for (CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* pAction : arrActions)

PdfFile/SrcReader/Adaptors.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ bool GlobalParamsAdaptor::GetCMap(const char* sName, char*& pData, unsigned int&
185185

186186
return false;
187187
}
188+
void GlobalParamsAdaptor::AddTextFormField(const std::wstring& sText)
189+
{
190+
m_sTextFormField += sText;
191+
}
192+
std::string GlobalParamsAdaptor::GetTextFormField()
193+
{
194+
return U_TO_UTF8(m_sTextFormField);
195+
}
188196

189197
bool operator==(const Ref &a, const Ref &b)
190198
{

PdfFile/SrcReader/Adaptors.h

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class GlobalParamsAdaptor : public GlobalParams
5959
BYTE* m_bCMapData;
6060
DWORD m_nCMapDataLength;
6161

62+
std::wstring m_sTextFormField;
6263
bool m_bDrawFormField;
6364

6465
public:
@@ -90,6 +91,8 @@ class GlobalParamsAdaptor : public GlobalParams
9091
void SetCMapMemory(BYTE* pData, DWORD nSizeData);
9192
bool GetCMap(const char* sName, char*& pData, unsigned int& nSize);
9293

94+
void AddTextFormField(const std::wstring& sText);
95+
std::string GetTextFormField();
9396
void setDrawFormField(bool bDrawFormField) { m_bDrawFormField = bDrawFormField; }
9497
bool getDrawFormField() { return m_bDrawFormField; }
9598
private:

PdfFile/SrcReader/PdfAnnot.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ CAnnotWidgetCh::CAnnotWidgetCh(PDFDoc* pdfDoc, AcroFormField* pField) : CAnnotWi
12741274

12751275
Object oOpt;
12761276
// 10 - Список значений
1277-
if (pField->fieldLookup("Opt", &oOpt)->isArray())
1277+
if (oField.dictLookup("Opt", &oOpt)->isArray())
12781278
{
12791279
m_unFlags |= (1 << 10);
12801280
int nOptLength = oOpt.arrayGetLength();
@@ -1502,6 +1502,9 @@ CAnnotWidget::CAnnotWidget(PDFDoc* pdfDoc, AcroFormField* pField) : CAnnot(pdfDo
15021502
// 18 - Частичное имя поля - T
15031503
m_sT = DictLookupString(&oField, "T", 18);
15041504

1505+
// 20 - OO метаданные форм - OMetadata
1506+
m_sOMetadata = DictLookupString(&oField, "OMetadata", 20);
1507+
15051508
// Action - A
15061509
Object oAction;
15071510
if (pField->fieldLookup("A", &oAction)->isDict())
@@ -3545,6 +3548,7 @@ void CAnnotAP::WriteAppearance(unsigned int nColor, CAnnotAPView* pView)
35453548
}
35463549

35473550
pView->pAP = pSubMatrix;
3551+
pView->sText = ((GlobalParamsAdaptor*)globalParams)->GetTextFormField();
35483552
}
35493553
BYTE CAnnotAP::GetBlendMode()
35503554
{
@@ -3577,6 +3581,14 @@ void CAnnotAP::ToWASM(NSWasm::CData& oRes)
35773581
oRes.AddInt(npSubMatrix >> 32);
35783582

35793583
oRes.WriteBYTE(m_arrAP[i]->nBlendMode);
3584+
3585+
if (m_arrAP[i]->sText.empty())
3586+
oRes.WriteBYTE(0);
3587+
else
3588+
{
3589+
oRes.WriteBYTE(1);
3590+
oRes.WriteString(m_arrAP[i]->sText);
3591+
}
35803592
}
35813593
}
35823594
void CAnnots::ToWASM(NSWasm::CData& oRes)
@@ -3720,6 +3732,8 @@ void CAnnotWidget::ToWASM(NSWasm::CData& oRes)
37203732
oRes.WriteString(m_sT);
37213733
if (m_unFlags & (1 << 19))
37223734
oRes.WriteString(m_sButtonFontName);
3735+
if (m_unFlags & (1 << 20))
3736+
oRes.WriteString(m_sOMetadata);
37233737
oRes.AddInt(m_arrAction.size());
37243738
for (int i = 0; i < m_arrAction.size(); ++i)
37253739
{

PdfFile/SrcReader/PdfAnnot.h

+2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class CAnnotAP final
129129
BYTE nBlendMode;
130130
std::string sAPName;
131131
std::string sASName;
132+
std::string sText;
132133
BYTE* pAP;
133134
};
134135

@@ -246,6 +247,7 @@ class CAnnotWidget : public CAnnot
246247
std::string m_sT; // Частичное имя поля - T
247248
std::string m_sFontKey; // Уникальный идентификатор шрифта
248249
std::string m_sFontName; // Имя шрифта - из DA
250+
std::string m_sOMetadata; // OO метаданные формы
249251
std::string m_sActualFontName; // Имя замененного шрифта
250252
std::string m_sButtonFontName; // Имя шрифта кнопки
251253
};

PdfFile/SrcReader/RendererOutputDev.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,8 @@ namespace PdfReader
25182518
}
25192519
}
25202520
}
2521+
if (((GlobalParamsAdaptor*)globalParams)->getDrawFormField())
2522+
((GlobalParamsAdaptor*)globalParams)->AddTextFormField(wsUnicodeText);
25212523
#endif
25222524
m_pRenderer->CommandDrawTextEx(wsUnicodeText, &unGid, unGidsCount, PDFCoordsToMM(dShiftX), PDFCoordsToMM(dShiftY), PDFCoordsToMM(dDx), PDFCoordsToMM(dDy));
25232525
if (bReplace)

PdfFile/SrcWriter/Annotation.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,16 @@ namespace PdfWriter
16281628
pOwner->Add("T", new CStringObject(sValue.c_str(), true));
16291629
}
16301630
}
1631+
void CWidgetAnnotation::SetOMetadata(const std::wstring& wsOMetadata)
1632+
{
1633+
std::string sValue = U_TO_UTF8(wsOMetadata);
1634+
CDictObject* pOwner = GetObjOwnValue("OMetadata");
1635+
if (!pOwner)
1636+
{
1637+
pOwner = this;
1638+
pOwner->Add("OMetadata", new CStringObject(sValue.c_str(), true));
1639+
}
1640+
}
16311641
void CWidgetAnnotation::SetBC(const std::vector<double>& arrBC)
16321642
{
16331643
CheckMK();

PdfFile/SrcWriter/Annotation.h

+1
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ namespace PdfWriter
447447
void SetDS(const std::wstring& wsDS);
448448
void SetDV(const std::wstring& wsDV);
449449
void SetT (const std::wstring& wsT);
450+
void SetOMetadata(const std::wstring& wsOMetadata);
450451
void SetBC(const std::vector<double>& arrBC);
451452
void SetBG(const std::vector<double>& arrBG);
452453
void AddAction(CAction* pAction);

0 commit comments

Comments
 (0)