Add CWidgetAnnot

This commit is contained in:
Svetlana Kulikova
2023-10-06 18:43:28 +03:00
parent e5e8262839
commit 92b43a26f5
15 changed files with 957 additions and 216 deletions

View File

@ -64,6 +64,7 @@ CAnnotFieldInfo::CAnnotFieldInfo() : IAdvancedCommand(AdvancedCommandType::Annot
m_pPopupPr = NULL;
m_pFreeTextPr = NULL;
m_pCaretPr = NULL;
m_pWidgetPr = NULL;
}
CAnnotFieldInfo::~CAnnotFieldInfo()
{
@ -77,16 +78,16 @@ CAnnotFieldInfo::~CAnnotFieldInfo()
RELEASEOBJECT(m_pPopupPr);
RELEASEOBJECT(m_pFreeTextPr);
RELEASEOBJECT(m_pCaretPr);
RELEASEOBJECT(m_pWidgetPr);
}
void CAnnotFieldInfo::SetType(int nType)
{
switch (nType)
{
case 0:
{
m_nType = 7;
m_nType = 15;
RELEASEOBJECT(m_pMarkupPr);
m_pMarkupPr = new CAnnotFieldInfo::CMarkupAnnotPr();
@ -185,6 +186,21 @@ void CAnnotFieldInfo::SetType(int nType)
m_pPopupPr = new CAnnotFieldInfo::CPopupAnnotPr();
break;
}
case 26:
case 27:
case 28:
case 29:
case 30:
case 31:
case 32:
case 33:
{
m_nType = nType - 26;
RELEASEOBJECT(m_pWidgetPr);
m_pWidgetPr = new CAnnotFieldInfo::CWidgetAnnotPr(nType);
break;
}
}
}
bool CAnnotFieldInfo::IsValid() const
@ -222,17 +238,33 @@ void CAnnotFieldInfo::GetBorder(BYTE& nType, double& dWidth, double& dDashesAlte
}
// Common
bool CAnnotFieldInfo::isWidget() const
bool CAnnotFieldInfo::IsWidget() const
{
return (m_nType != 0 && m_nType < 7);
return (m_nType < 8);
}
bool CAnnotFieldInfo::isMarkup() const
bool CAnnotFieldInfo::IsButtonWidget() const
{
return (m_nType == 1 || m_nType == 2 || m_nType == 3);
}
bool CAnnotFieldInfo::IsTextWidget() const
{
return (m_nType == 4);
}
bool CAnnotFieldInfo::IsChoiceWidget() const
{
return (m_nType == 5 || m_nType == 6);
}
bool CAnnotFieldInfo::IsSignatureWidget() const
{
return (m_nType == 7);
}
bool CAnnotFieldInfo::IsMarkup() const
{
return (m_nType > 6 && m_nType < 24);
}
bool CAnnotFieldInfo::IsText() const
{
return (m_nType == 7);
return (m_nType == 15);
}
bool CAnnotFieldInfo::IsInk() const
{
@ -267,6 +299,145 @@ bool CAnnotFieldInfo::IsCaret() const
return (m_nType == 14);
}
CAnnotFieldInfo::CWidgetAnnotPr::CWidgetAnnotPr(BYTE nType)
{
m_pButtonPr = NULL;
m_pTextPr = NULL;
m_pChoicePr = NULL;
m_pSignaturePr = NULL;
m_nType = nType;
switch (nType)
{
case 26:
{
// Unknown widget
break;
}
case 27:
case 28:
case 29:
{
RELEASEOBJECT(m_pButtonPr);
m_pButtonPr = new CWidgetAnnotPr::CButtonWidgetPr();
break;
}
case 30:
{
RELEASEOBJECT(m_pTextPr);
m_pTextPr = new CWidgetAnnotPr::CTextWidgetPr();
break;
}
case 31:
case 32:
{
RELEASEOBJECT(m_pChoicePr);
m_pChoicePr = new CWidgetAnnotPr::CChoiceWidgetPr();
break;
}
case 33:
{
RELEASEOBJECT(m_pSignaturePr);
m_pSignaturePr = new CWidgetAnnotPr::CSignatureWidgetPr();
break;
}
}
}
CAnnotFieldInfo::CWidgetAnnotPr::~CWidgetAnnotPr()
{
RELEASEOBJECT(m_pButtonPr);
RELEASEOBJECT(m_pTextPr);
RELEASEOBJECT(m_pChoicePr);
RELEASEOBJECT(m_pSignaturePr);
for (int i = 0; i < m_arrAction.size(); ++i)
RELEASEOBJECT(m_arrAction[i]);
}
CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* ReadAction(NSOnlineOfficeBinToPdf::CBufferReader* pReader)
{
CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* pRes = new CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget();
pRes->nActionType = pReader->ReadByte();
switch (pRes->nActionType)
{
case 14: // JavaScript
{
pRes->wsStr1 = pReader->ReadString();
break;
}
case 1: // GoTo
{
pRes->nInt1 = pReader->ReadInt();
pRes->nKind = pReader->ReadByte();
switch (pRes->nKind)
{
case 0:
case 2:
case 3:
case 6:
case 7:
{
pRes->nFlags = pReader->ReadByte();
if (pRes->nFlags & (1 << 0))
pRes->dD[0] = pReader->ReadDouble();
if (pRes->nFlags & (1 << 1))
pRes->dD[1] = pReader->ReadDouble();
if (pRes->nFlags & (1 << 2))
pRes->dD[2] = pReader->ReadDouble();
break;
}
case 4:
{
pRes->dD[0] = pReader->ReadDouble();
pRes->dD[1] = pReader->ReadDouble();
pRes->dD[2] = pReader->ReadDouble();
pRes->dD[3] = pReader->ReadDouble();
break;
}
case 1:
case 5:
default:
{
break;
}
}
break;
}
case 10: // Named
{
pRes->wsStr1 = pReader->ReadString();
break;
}
case 6: // URI
{
pRes->wsStr1 = pReader->ReadString();
break;
}
case 9: // Hide
{
pRes->nInt1 = pReader->ReadInt();
int n = pReader->ReadInt();
for (int i = 0; i < n; ++i)
pRes->arrStr.push_back(pReader->ReadString());
break;
}
case 12: // ResetForm
{
pRes->nInt1 = pReader->ReadInt();
int n = pReader->ReadInt();
for (int i = 0; i < n; ++i)
pRes->arrStr.push_back(pReader->ReadString());
break;
}
}
if (pReader->ReadByte())
pRes->pNext = ReadAction(pReader);
return pRes;
}
bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector)
{
BYTE nType = pReader->ReadByte();
@ -318,7 +489,7 @@ bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMeta
if (nFlags & (1 << 5))
SetLM(pReader->ReadString());
if (isMarkup())
if (IsMarkup())
{
CAnnotFieldInfo::CMarkupAnnotPr* pPr = GetMarkupAnnotPr();
@ -527,5 +698,136 @@ bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMeta
pPr->SetSy(pReader->ReadByte());
}
if (IsWidget())
{
CAnnotFieldInfo::CWidgetAnnotPr* pPr = GetWidgetAnnotPr();
int n = pReader->ReadInt();
std::vector<double> arrTC;
for (int i = 0; i < n; ++i)
arrTC.push_back(pReader->ReadDouble());
pPr->SetTC(arrTC);
pPr->SetQ(pReader->ReadByte());
int nWidgetFlag = pReader->ReadInt();
pPr->SetFlag(nWidgetFlag);
int nFlags = pReader->ReadInt();
pPr->SetFlags(nFlags);
if (nFlags & (1 << 0))
pPr->SetTU(pReader->ReadString());
if (nFlags & (1 << 1))
pPr->SetDS(pReader->ReadString());
if (nFlags & (1 << 3))
pPr->SetH(pReader->ReadByte());
if (nFlags & (1 << 5))
{
int n = pReader->ReadInt();
std::vector<double> arrBC;
for (int i = 0; i < n; ++i)
arrBC.push_back(pReader->ReadDouble());
pPr->SetBC(arrBC);
}
if (nFlags & (1 << 6))
pPr->SetR(pReader->ReadInt());
if (nFlags & (1 << 7))
{
int n = pReader->ReadInt();
std::vector<double> arrBG;
for (int i = 0; i < n; ++i)
arrBG.push_back(pReader->ReadDouble());
pPr->SetBG(arrBG);
}
if (nFlags & (1 << 8))
pPr->SetDV(pReader->ReadString());
if (nFlags & (1 << 17))
pPr->SetParentID(pReader->ReadInt());
if (nFlags & (1 << 18))
pPr->SetT(pReader->ReadString());
// Action
int nAction = pReader->ReadInt();
for (int i = 0; i < nAction; ++i)
{
std::wstring wsType = pReader->ReadString();
CAnnotFieldInfo::CWidgetAnnotPr::CActionWidget* pA = ReadAction(pReader);
if (pA)
{
pA->wsType = wsType;
pPr->AddAction(pA);
}
}
if (nType == 29 || nType == 28 || nType == 27)
{
CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr* pPr1 = pPr->GetButtonWidgetPr();
int nIFFlags = pReader->ReadInt();
pPr1->SetIFFlag(nIFFlags);
if (nType == 27)
{
if (nFlags & (1 << 10))
pPr1->SetCA(pReader->ReadString());
if (nFlags & (1 << 11))
pPr1->SetRC(pReader->ReadString());
if (nFlags & (1 << 12))
pPr1->SetAC(pReader->ReadString());
}
else
pPr1->SetS(pReader->ReadByte());
if (nFlags & (1 << 13))
pPr1->SetTP(pReader->ReadByte());
if (nIFFlags & (1 << 0))
{
if (nIFFlags & (1 << 1))
pPr1->SetSW(pReader->ReadByte());
if (nIFFlags & (1 << 2))
pPr1->SetS(pReader->ReadByte());
if (nIFFlags & (1 << 3))
{
double d1 = pReader->ReadDouble();
double d2 = pReader->ReadDouble();
pPr1->SetA(d1, d2);
}
}
if (nFlags & (1 << 14))
pPr1->SetAP_N_Yes(pReader->ReadString());
}
else if (nType == 30)
{
CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr* pPr1 = pPr->GetTextWidgetPr();
if (nFlags & (1 << 9))
pPr1->SetV(pReader->ReadString());
if (nFlags & (1 << 10))
pPr1->SetMaxLen(pReader->ReadInt());
if (nWidgetFlag & (1 << 25))
pPr1->SetRV(pReader->ReadString());
}
else if (nType == 31 || nType == 32)
{
CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr* pPr1 = pPr->GetChoiceWidgetPr();
if (nFlags & (1 << 9))
pPr1->SetV(pReader->ReadString());
if (nFlags & (1 << 10))
{
int n = pReader->ReadInt();
std::vector< std::pair<std::wstring, std::wstring> > arrOpt;
for (int i = 0; i < n; ++i)
{
std::wstring s1 = pReader->ReadString();
std::wstring s2 = pReader->ReadString();
arrOpt.push_back(std::make_pair(s2, s1));
}
pPr1->SetOpt(arrOpt);
}
if (nFlags & (1 << 11))
pPr1->SetTI(pReader->ReadInt());
}
}
return IsValid();
}

View File

@ -36,6 +36,9 @@
#include "../MetafileToRendererReader.h"
class IMetafileToRenderter;
// void Set(const BYTE& n) { m_n = n; }
// BYTE Get() const { return m_n; }
// void Set(const int& n) { m_n = n; }
// int Get() const { return m_n; }
@ -53,17 +56,74 @@ public:
public:
class CButtonWidgetPr
{
public:
void SetS (const BYTE& nS) { m_nS = nS; }
void SetTP(const BYTE& nTP) { m_nTP = nTP; }
void SetSW(const BYTE& nSW) { m_nSW = nSW; }
void SetStyle(const BYTE& nStyle) { m_nStyle = nStyle; }
void SetIFFlag(const int& nIFFlag) { m_nIFFlag = nIFFlag; }
void SetA(const double& dA1, const double& dA2) { m_dA1 = dA1; m_dA2 = dA2; }
void SetCA(const std::wstring& wsCA) { m_wsCA = wsCA; }
void SetRC(const std::wstring& wsRC) { m_wsRC = wsRC; }
void SetAC(const std::wstring& wsAC) { m_wsAC = wsAC; }
void SetAP_N_Yes(const std::wstring& wsAP_N_Yes) { m_wsAP_N_Yes = wsAP_N_Yes; }
BYTE GetS() const { return m_nS; }
BYTE GetTP() const { return m_nTP; }
BYTE GetSW() const { return m_nSW; }
BYTE GetStyle() const { return m_nStyle; }
int GetIFFlag() const { return m_nIFFlag; }
void GetA(double& dA1, double& dA2) const { dA1 = m_dA1; dA2 = m_dA2; }
const std::wstring& GetCA() const { return m_wsCA; }
const std::wstring& GetRC() const { return m_wsRC; }
const std::wstring& GetAC() const { return m_wsAC; }
const std::wstring& GetAP_N_Yes() const { return m_wsAP_N_Yes; }
private:
BYTE m_nS;
BYTE m_nTP;
BYTE m_nSW;
BYTE m_nStyle;
int m_nIFFlag;
double m_dA1, m_dA2;
std::wstring m_wsCA;
std::wstring m_wsRC;
std::wstring m_wsAC;
std::wstring m_wsAP_N_Yes;
};
class CTextWidgetPr
{
public:
void SetMaxLen(const int& nMaxLen) { m_nMaxLen = nMaxLen; }
void SetV (const std::wstring& wsV) { m_wsV = wsV; }
void SetRV(const std::wstring& wsRV) { m_wsRV = wsRV; }
int GetMaxLen() const { return m_nMaxLen; }
const std::wstring& GetV() const { return m_wsV; }
const std::wstring& GetRV() const { return m_wsRV; }
private:
int m_nMaxLen;
std::wstring m_wsV;
std::wstring m_wsRV;
};
class CChoiceWidgetPr
{
public:
void SetTI(const int& nTI) { m_nTI = nTI; }
void SetV(const std::wstring& wsV) { m_wsV = wsV; }
void SetOpt(const std::vector< std::pair<std::wstring, std::wstring> >& arrOpt) { m_arrOpt = arrOpt; }
int GetTI() const { return m_nTI; }
const std::wstring& GetV() const { return m_wsV; }
const std::vector< std::pair<std::wstring, std::wstring> >& GetOpt() const { return m_arrOpt; }
private:
int m_nTI;
std::wstring m_wsV;
std::vector< std::pair<std::wstring, std::wstring> > m_arrOpt;
};
class CSignatureWidgetPr
@ -71,27 +131,49 @@ public:
};
private:
class CActionWidget
{
public:
CActionWidget() : pNext(NULL) {}
~CActionWidget() { RELEASEOBJECT(pNext); }
BYTE nKind;
BYTE nFlags;
BYTE nActionType;
int nInt1;
double dD[4];
std::wstring wsType;
std::wstring wsStr1;
std::vector<std::wstring> arrStr;
CActionWidget* pNext;
};
public:
CWidgetAnnotPr(BYTE nType);
~CWidgetAnnotPr();
void SetQ(const BYTE& nQ) { m_nQ = nQ; }
void SetH(const BYTE& nH) { m_nH = nH; }
void SetR(const int& nR) { m_nR = nR; }
void SetFlag (const int& nFlag) { m_nFlag = nFlag; }
void SetFlags (const int& nFlags) { m_nFlags = nFlags; }
void SetParentID(const int& nParentID) { m_nParentID = nParentID; }
void SetTU(const std::wstring& wsTU) { m_wsTU = wsTU; }
void SetDS(const std::wstring& wsDS) { m_wsDS = wsDS; }
void SetDV(const std::wstring& wsDV) { m_wsDV = wsDV; }
void SetT (const std::wstring& wsT) { m_wsT = wsT; }
void SetT (const std::wstring& wsT) { m_wsT = wsT; }
void SetTC(const std::vector<double>& arrTC) { m_arrTC = arrTC; }
void SetBC(const std::vector<double>& arrBC) { m_arrBC = arrBC; }
void SetBG(const std::vector<double>& arrBG) { m_arrBG = arrBG; }
void AddAction(CActionWidget* pA) { m_arrAction.push_back(pA); }
BYTE GetQ() const { return m_nQ; }
BYTE GetH() const { return m_nH; }
int GetR() const { return m_nR; }
BYTE GetQ() const { return m_nQ; }
BYTE GetH() const { return m_nH; }
BYTE GetType() const { return m_nType; }
int GetR() const { return m_nR; }
int GetFlag() const { return m_nFlag; }
int GetFlags() const { return m_nFlags; }
int GetParentID() const { return m_nParentID; }
const std::wstring& GetTU() const { return m_wsTU; }
const std::wstring& GetDS() const { return m_wsDS; }
const std::wstring& GetDV() const { return m_wsDV; }
@ -108,7 +190,11 @@ public:
private:
BYTE m_nQ;
BYTE m_nH;
BYTE m_nType;
int m_nR;
int m_nFlag;
int m_nFlags;
int m_nParentID;
std::wstring m_wsTU;
std::wstring m_wsDS;
std::wstring m_wsDV;
@ -385,17 +471,21 @@ public:
const std::wstring& GetContents() const { return m_wsContents; }
const std::vector<double>& GetC() const { return m_arrC; }
bool isWidget() const;
bool isMarkup() const;
bool IsText() const;
bool IsInk() const;
bool IsLine() const;
bool IsTextMarkup() const;
bool IsSquareCircle() const;
bool IsPolygonLine() const;
bool IsPopup() const;
bool IsFreeText() const;
bool IsCaret() const;
bool IsWidget() const;
bool IsButtonWidget() const;
bool IsTextWidget() const;
bool IsChoiceWidget() const;
bool IsSignatureWidget() const;
bool IsMarkup() const;
bool IsText() const;
bool IsInk() const;
bool IsLine() const;
bool IsTextMarkup() const;
bool IsSquareCircle() const;
bool IsPolygonLine() const;
bool IsPopup() const;
bool IsFreeText() const;
bool IsCaret() const;
CMarkupAnnotPr* GetMarkupAnnotPr() { return m_pMarkupPr; }
CTextAnnotPr* GetTextAnnotPr() { return m_pTextPr; }
@ -407,7 +497,7 @@ public:
CPopupAnnotPr* GetPopupAnnotPr() { return m_pPopupPr; }
CFreeTextAnnotPr* GetFreeTextAnnotPr() { return m_pFreeTextPr; }
CCaretAnnotPr* GetCaretAnnotPr() { return m_pCaretPr; }
CWidgetAnnotPr* GetWidgetAnnotPr() { return m_pWidgetPr; }
CWidgetAnnotPr* GetWidgetAnnotPr() { return m_pWidgetPr; }
bool Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector);

View File

@ -665,6 +665,9 @@
for (let q = 0; reader.isValid() && q < k; ++q)
{
let rec = {};
// Тип аннотации виджета - FT
// 26 - Unknown, 27 - button, 28 - radiobutton, 29 - checkbox, 30 - text, 31 - combobox, 32 - listbox, 33 - signature
rec["type"] = reader.readByte();
// Annot
readAnnot(reader, rec);
// Widget
@ -677,10 +680,6 @@
}
// 0 - left-justified, 1 - centered, 2 - right-justified
rec["alignment"] = reader.readByte();
// Тип аннотации виджета - FT
// 0 - Unknown, 1 - button, 2 - radiobutton, 3 - checkbox
// 4 - text, 5 - combobox, 6 - listbox, 7 - signature
rec["type"] = reader.readByte();
rec["flag"] = reader.readInt();
// 12.7.3.1
rec["readOnly"] = (rec["flag"] >> 0) & 1; // ReadOnly
@ -735,12 +734,12 @@
readAction(reader, rec["AA"][AAType]);
}
// Widget types
if (rec["type"] == 3 || rec["type"] == 2 || rec["type"] == 1)
if (rec["type"] == 29 || rec["type"] == 28 || rec["type"] == 27)
{
rec["value"] = (flags & (1 << 9)) ? "Yes" : "Off";
let IFflags = reader.readInt();
// Характеристики внешнего вида - MK
if (rec["type"] == 1)
if (rec["type"] == 27)
{
// Заголовок - СА
if (flags & (1 << 10))
@ -789,7 +788,7 @@
rec["NoToggleToOff"] = (rec["flag"] >> 14) & 1; // NoToggleToOff
rec["radiosInUnison"] = (rec["flag"] >> 25) & 1; // RadiosInUnison
}
else if (rec["type"] == 4)
else if (rec["type"] == 30)
{
if (flags & (1 << 9))
rec["value"] = reader.readString();
@ -806,7 +805,7 @@
rec["comb"] = (rec["flag"] >> 24) & 1; // Comb
rec["richText"] = (rec["flag"] >> 25) & 1; // RichText
}
else if (rec["type"] == 5 || rec["type"] == 6)
else if (rec["type"] == 31 || rec["type"] == 32)
{
if (flags & (1 << 9))
rec["value"] = reader.readString();
@ -1219,7 +1218,7 @@
rec["RD"].push(reader.readDouble());
}
// Связанный символ - Sy
// 0 - P, 1 - None
// 0 - None, 1 - P, 2 - S
if (flags & (1 << 16))
rec["Sy"] = reader.readByte();
}

View File

@ -229,6 +229,9 @@ unsigned int READ_INT(BYTE* x)
{
return x ? (x[0] | x[1] << 8 | x[2] << 16 | x[3] << 24) : 4;
}
std::string arrAnnots[] = {"Text", "Link", "FreeText", "Line", "Square", "Circle", "Polygon", "PolyLine", "Highlight", "Underline", "Squiggly", "StrikeOut", "Stamp", "Caret", "Ink", "Popup",
"FileAttachment", "Sound", "Movie", "Widget", "Screen", "PrinterMark", "TrapNet", "Watermark", "3D", "Redact", "unknown", "button", "radiobutton", "checkbox", "text",
"combobox", "listbox", "signature"};
void ReadAction(BYTE* pWidgets, int& i)
{
@ -544,13 +547,17 @@ void ReadInteractiveForms(BYTE* pWidgets, int& i)
for (int q = 0; q < nAnnots; ++q)
{
int nPathLength = READ_BYTE(pWidgets + i);
i += 1;
std::string sType = arrAnnots[nPathLength];
std::cout << "Widget type " << sType << ", ";
// Annot
ReadAnnot(pWidgets, i);
// Widget
int nPathLength;
int nTCLength = READ_INT(pWidgets + i);
i += 4;
if (nTCLength)
@ -569,12 +576,6 @@ void ReadInteractiveForms(BYTE* pWidgets, int& i)
i += 1;
std::cout << "Q " << arrQ[nPathLength] << ", ";
std::string arrType[] = {"", "button", "radiobutton", "checkbox", "text", "combobox", "listbox", "signature"};
nPathLength = READ_BYTE(pWidgets + i);
i += 1;
std::string sType = arrType[nPathLength];
std::cout << "Widget type " << sType << ", ";
int nFieldFlag = READ_INT(pWidgets + i);
i += 4;
std::cout << "Field Flag " << nFieldFlag << ", ";
@ -1191,10 +1192,6 @@ int main(int argc, char* argv[])
{
int nPathLength = READ_BYTE(pAnnots + i);
i += 1;
std::string arrAnnots[] = {"Text", "Link", "FreeText", "Line", "Square", "Circle", "Polygon", "PolyLine",
"Highlight", "Underline", "Squiggly", "StrikeOut", "Stamp", "Caret", "Ink",
"Popup", "FileAttachment", "Sound", "Movie", "Widget", "Screen", "PrinterMark",
"TrapNet", "Watermark", "3D", "Redact"};
std::string sType = arrAnnots[nPathLength];
std::cout << "Type " << sType << ", ";
@ -1577,7 +1574,7 @@ int main(int argc, char* argv[])
{
nPathLength = READ_BYTE(pAnnots + i);
i += 1;
std::string arrSy[] = {"P", "None"};
std::string arrSy[] = {"None", "P", "S"};
std::cout << "Sy " << arrSy[nPathLength] << ", ";
}
}

View File

@ -181,24 +181,24 @@ namespace NSOnlineOfficeBinToPdf
return false;
}
// TODO: помечаем страницу в writer (nPageNum)
switch (CommandType)
{
case AddCommandType::Annotation:
{
NSOnlineOfficeBinToPdf::ConvertBufferToRenderer(oReader.GetCurrentBuffer(), (LONG)(nLen - 9) , &oCorrector);
oReader.Skip(nLen - 9);
break;
}
case AddCommandType::AddPage:
case AddCommandType::RemovePage:
{
// TODO: version 7.6+
break;
}
default:
return false;
case AddCommandType::Annotation:
{
pPdf->EditPage(nPageNum);
NSOnlineOfficeBinToPdf::ConvertBufferToRenderer(oReader.GetCurrentBuffer(), (LONG)(nLen - 9) , &oCorrector);
oReader.Skip(nLen - 9);
break;
}
case AddCommandType::AddPage:
case AddCommandType::RemovePage:
{
// TODO: version 7.6+
break;
}
default:
return false;
}
}

View File

@ -929,7 +929,7 @@ HRESULT CPdfFile::OnlineWordToPdfFromBinary(const std::wstring& wsSrcFile, const
HRESULT CPdfFile::AddToPdfFromBinary(BYTE* pBuffer, unsigned int nLen, CConvertFromBinParams* pParams)
{
#ifndef BUILDING_WASM_MODULE
if (!m_pInternal->pWriter || !NSOnlineOfficeBinToPdf::AddBinToPdf(this, pBuffer, nLen, pParams))
if (!m_pInternal->pReader || !m_pInternal->pWriter || !m_pInternal->bEdit || !NSOnlineOfficeBinToPdf::AddBinToPdf(this, pBuffer, nLen, pParams))
return S_FALSE;
#endif
return S_OK;
@ -1610,11 +1610,3 @@ HRESULT CPdfFile::AdvancedCommand(IAdvancedCommand* command)
}
return S_FALSE;
}
bool CPdfFile::AddCommandsToFile(BYTE* pBuffer, unsigned int& nLen, CConvertFromBinParams* pParams)
{
if (!m_pInternal->pReader || !m_pInternal->pWriter)
return false;
return NSOnlineOfficeBinToPdf::AddBinToPdf(this, pBuffer, nLen, pParams);
}

View File

@ -290,8 +290,6 @@ public:
virtual HRESULT IsSupportAdvancedCommand(const IAdvancedCommand::AdvancedCommandType& type);
virtual HRESULT AdvancedCommand(IAdvancedCommand* command);
bool AddCommandsToFile(BYTE* pBuffer, unsigned int& nLen, CConvertFromBinParams* pParams);
private:
CPdfFile_Private* m_pInternal;
};

View File

@ -1678,15 +1678,10 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
CAnnotFieldInfo& oInfo = *pFieldInfo;
// TODO внести Widget в PdfWriter::CAnnotation
if (oInfo.isWidget())
return AddFormField(pAppFonts, (CFormFieldInfo*)pFieldInfo);
// if (m_bNeedUpdateTextFont)
// UpdateFont();
if (!m_pFont)
return S_OK;
// if (!m_pFont)
// return S_OK;
PdfWriter::CAnnotation* pAnnot = NULL;
@ -1727,6 +1722,45 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
pAnnot = m_pDocument->CreateCaretAnnot();
}
BYTE nWidgetType = 0;
if (oInfo.IsWidget())
{
CAnnotFieldInfo::CWidgetAnnotPr* pPr = oInfo.GetWidgetAnnotPr();
nWidgetType = pPr->GetType();
switch (nWidgetType)
{
case 26:
{
pAnnot = m_pDocument->CreateWidgetAnnot();
break;
}
case 27:
case 28:
case 29:
{
pAnnot = m_pDocument->CreateButtonWidget();
break;
}
case 30:
{
pAnnot = m_pDocument->CreateTextWidget();
break;
}
case 31:
case 32:
{
pAnnot = m_pDocument->CreateChoiceWidget();
break;
}
case 33:
{
pAnnot = m_pDocument->CreateSignatureWidget();
break;
}
}
}
if (!pAnnot)
return S_FALSE;
@ -1775,7 +1809,7 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
if (nFlags & (1 << 5))
pAnnot->SetLM(oInfo.GetLM());
if (oInfo.isMarkup())
if (oInfo.IsMarkup())
{
CAnnotFieldInfo::CMarkupAnnotPr* pPr = oInfo.GetMarkupAnnotPr();
PdfWriter::CMarkupAnnotation* pMarkupAnnot = (PdfWriter::CMarkupAnnotation*)pAnnot;
@ -1946,6 +1980,90 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
pCaretAnnot->SetSy(pPr->GetSy());
}
if (oInfo.IsWidget())
{
CAnnotFieldInfo::CWidgetAnnotPr* pPr = oInfo.GetWidgetAnnotPr();
PdfWriter::CWidgetAnnotation* pWidgetAnnot = (PdfWriter::CWidgetAnnotation*)pAnnot;
pWidgetAnnot->SetTC(pPr->GetTC());
pWidgetAnnot->SetQ(pPr->GetQ());
int nWidgetFlag = pPr->GetFlag();
pWidgetAnnot->SetFlag(nWidgetFlag);
int nFlags = pPr->GetFlags();
if (nFlags & (1 << 0))
pWidgetAnnot->SetTU(pPr->GetTU());
if (nFlags & (1 << 1))
pWidgetAnnot->SetDS(pPr->GetDS());
if (nFlags & (1 << 3))
pWidgetAnnot->SetH(pPr->GetH());
if (nFlags & (1 << 5))
pWidgetAnnot->SetBC(pPr->GetBC());
if (nFlags & (1 << 6))
pWidgetAnnot->SetR(pPr->GetR());
if (nFlags & (1 << 7))
pWidgetAnnot->SetBG(pPr->GetBG());
if (nFlags & (1 << 8))
pWidgetAnnot->SetDV(pPr->GetDV());
if (nFlags & (1 << 17))
pWidgetAnnot->SetParentID(pPr->GetParentID());
if (nFlags & (1 << 18))
pWidgetAnnot->SetT(pPr->GetT());
}
if (oInfo.IsButtonWidget())
{
CAnnotFieldInfo::CWidgetAnnotPr::CButtonWidgetPr* pPr = oInfo.GetWidgetAnnotPr()->GetButtonWidgetPr();
PdfWriter::CButtonWidget* pButtonWidget = (PdfWriter::CButtonWidget*)pAnnot;
int nIFFlags = pPr->GetIFFlag();
pButtonWidget->SetIFFlag(nIFFlags);
if (nWidgetType == 27)
{
if (nFlags & (1 << 10))
pButtonWidget->SetCA(pPr->GetCA());
if (nFlags & (1 << 11))
pButtonWidget->SetRC(pPr->GetRC());
if (nFlags & (1 << 12))
pButtonWidget->SetAC(pPr->GetAC());
}
else
pButtonWidget->SetS(pPr->GetS());
if (nFlags & (1 << 13))
pButtonWidget->SetTP(pPr->GetTP());
if (nIFFlags & (1 << 0))
{
if (nIFFlags & (1 << 1))
pButtonWidget->SetSW(pPr->GetSW());
if (nIFFlags & (1 << 2))
pButtonWidget->SetS(pPr->GetS());
if (nIFFlags & (1 << 3))
{
double d1, d2;
pPr->GetA(d1, d2);
pButtonWidget->SetA(d1, d2);
}
}
if (nFlags & (1 << 14))
pButtonWidget->SetAP_N_Yes(pPr->GetAP_N_Yes());
}
else if (oInfo.IsTextWidget())
{
CAnnotFieldInfo::CWidgetAnnotPr::CTextWidgetPr* pPr = oInfo.GetWidgetAnnotPr()->GetTextWidgetPr();
PdfWriter::CTextWidget* pTextWidget = (PdfWriter::CTextWidget*)pAnnot;
}
else if (oInfo.IsChoiceWidget())
{
CAnnotFieldInfo::CWidgetAnnotPr::CChoiceWidgetPr* pPr = oInfo.GetWidgetAnnotPr()->GetChoiceWidgetPr();
PdfWriter::CChoiceWidget* pChoiceWidget = (PdfWriter::CChoiceWidget*)pAnnot;
}
else if (oInfo.IsSignatureWidget())
{
CAnnotFieldInfo::CWidgetAnnotPr::CSignatureWidgetPr* pPr = oInfo.GetWidgetAnnotPr()->GetSignatureWidgetPr();
PdfWriter::CSignatureWidget* pSignatureWidget = (PdfWriter::CSignatureWidget*)pAnnot;
}
return S_OK;
}
//----------------------------------------------------------------------------------------

View File

@ -680,20 +680,20 @@ CAnnotWidget::CAnnotWidget(PDFDoc* pdfDoc, AcroFormField* pField) : CAnnot(pdfDo
// Тип - FT + флаги
AcroFormFieldType oType = pField->getAcroFormFieldType();
m_nType = 0; // Unknown
m_nType = 26; // Unknown
switch (oType)
{
case acroFormFieldPushbutton: m_nType = 1;/*sType = "button";*/ break;
case acroFormFieldRadioButton: m_nType = 2;/*sType = "radiobutton";*/ break;
case acroFormFieldCheckbox: m_nType = 3;/*sType = "checkbox";*/ break;
case acroFormFieldFileSelect: m_nType = 4;/*sType = "text""fileselect"*/ break;
case acroFormFieldMultilineText: m_nType = 4;/*sType = "text""multilinetext"*/ break;
case acroFormFieldText: m_nType = 4;/*sType = "text";*/ break;
case acroFormFieldBarcode: m_nType = 4;/*sType = "text""barcode"*/ break;
case acroFormFieldComboBox: m_nType = 5;/*sType = "combobox";*/ break;
case acroFormFieldListBox: m_nType = 6;/*sType = "listbox";*/ break;
case acroFormFieldSignature: m_nType = 7;/*sType = "signature";*/ break;
default: m_nType = 0;/*sType = "";*/ break;
case acroFormFieldPushbutton: m_nType = 27; break;
case acroFormFieldRadioButton: m_nType = 28; break;
case acroFormFieldCheckbox: m_nType = 29; break;
case acroFormFieldFileSelect: m_nType = 30; break;
case acroFormFieldMultilineText: m_nType = 30; break;
case acroFormFieldText: m_nType = 30; break;
case acroFormFieldBarcode: m_nType = 30; break;
case acroFormFieldComboBox: m_nType = 31; break;
case acroFormFieldListBox: m_nType = 32; break;
case acroFormFieldSignature: m_nType = 33; break;
default: m_nType = 26; break;
}
// Флаг - Ff
@ -1306,7 +1306,7 @@ CAnnotFreeText::CAnnotFreeText(PDFDoc* pdfDoc, Object* oAnnotRef, int nPageIndex
}
//------------------------------------------------------------------------
// FreeText
// Caret
//------------------------------------------------------------------------
CAnnotCaret::CAnnotCaret(PDFDoc* pdfDoc, Object* oAnnotRef, int nPageIndex) : CMarkupAnnot(pdfDoc, oAnnotRef, nPageIndex)
@ -1330,9 +1330,11 @@ CAnnotCaret::CAnnotCaret(PDFDoc* pdfDoc, Object* oAnnotRef, int nPageIndex) : CM
if (oAnnot.dictLookup("Sy", &oObj)->isName())
{
m_unFlags |= (1 << 16);
m_nSy = 1; // None
m_nSy = 0; // None
if (oObj.isName("P"))
m_nSy = 0;
m_nSy = 1;
if (oObj.isName("S"))
m_nSy = 2;
}
oObj.free();
@ -2230,13 +2232,14 @@ void CAnnot::CBorderType::ToWASM(NSWasm::CData& oRes)
void CAnnotWidget::ToWASM(NSWasm::CData& oRes)
{
oRes.WriteBYTE(m_nType);
CAnnot::ToWASM(oRes);
oRes.AddInt(m_arrTC.size());
for (int i = 0; i < m_arrTC.size(); ++i)
oRes.AddDouble(m_arrTC[i]);
oRes.WriteBYTE(m_nQ);
oRes.WriteBYTE(m_nType);
oRes.AddInt(m_unFieldFlag);
oRes.AddInt(m_unFlags);
if (m_unFlags & (1 << 0))
@ -2374,7 +2377,7 @@ void CAnnotWidgetBtn::ToWASM(NSWasm::CData& oRes)
CAnnotWidget::ToWASM(oRes);
oRes.AddInt(m_unIFFlag);
if (m_nType == 1)
if (m_nType == 27)
{
if (m_unFlags & (1 << 10))
oRes.WriteString(m_sCA);

View File

@ -277,7 +277,7 @@ public:
void ToWASM(NSWasm::CData& oRes) override;
private:
std::string m_sV;
std::vector<std::pair<std::string, std::string>> m_arrOpt;
std::vector< std::pair<std::string, std::string> > m_arrOpt;
unsigned int m_unTI;
};

View File

@ -60,7 +60,8 @@ namespace PdfWriter
"Squiggly",
"Polygon",
"PolyLine",
"Caret"
"Caret",
"Widget"
};
const static char* c_sAnnotIconNames[] =
{
@ -196,16 +197,20 @@ namespace PdfWriter
std::string sValue = U_TO_UTF8(wsLM);
Add("M", new CStringObject(sValue.c_str()));
}
void CAnnotation::SetC(const std::vector<double>& arrC)
void AddToVectorD(CDictObject* pObj, const std::string& sName, const std::vector<double>& arrV)
{
CArrayObject* pArray = new CArrayObject();
if (!pArray)
return;
Add("C", pArray);
pObj->Add(sName, pArray);
for (const double& dC : arrC)
pArray->Add(dC);
for (const double& dV : arrV)
pArray->Add(dV);
}
void CAnnotation::SetC(const std::vector<double>& arrC)
{
AddToVectorD(this, "C", arrC);
}
//----------------------------------------------------------------------------------------
// CMarkupAnnotation
@ -505,20 +510,9 @@ namespace PdfWriter
pArray->Add(dCO1);
pArray->Add(dCO2);
}
void AddIC(CAnnotation* pAnnot, const std::vector<double>& arrIC)
{
CArrayObject* pArray = new CArrayObject();
if (!pArray)
return;
pAnnot->Add("IC", pArray);
for (const double& dIC : arrIC)
pArray->Add(dIC);
}
void CLineAnnotation::SetIC(const std::vector<double>& arrIC)
{
AddIC(this, arrIC);
AddToVectorD(this, "IC", arrIC);
}
//----------------------------------------------------------------------------------------
// CPopupAnnotation
@ -589,14 +583,7 @@ namespace PdfWriter
}
void CFreeTextAnnotation::SetCL(const std::vector<double>& arrCL)
{
CArrayObject* pArray = new CArrayObject();
if (!pArray)
return;
Add("CL", pArray);
for (const double& dCL : arrCL)
pArray->Add(dCL);
AddToVectorD(this, "CL", arrCL);
}
//----------------------------------------------------------------------------------------
// CTextMarkupAnnotation
@ -623,14 +610,7 @@ namespace PdfWriter
}
void CTextMarkupAnnotation::SetQuadPoints(const std::vector<double>& arrQuadPoints)
{
CArrayObject* pArray = new CArrayObject();
if (!pArray)
return;
Add("QuadPoints", pArray);
for (const double& dQuadPoints : arrQuadPoints)
pArray->Add(dQuadPoints);
AddToVectorD(this, "QuadPoints", arrQuadPoints);
}
//----------------------------------------------------------------------------------------
// CSquareCircleAnnotation
@ -666,7 +646,7 @@ namespace PdfWriter
}
void CSquareCircleAnnotation::SetIC(const std::vector<double>& arrIC)
{
AddIC(this, arrIC);
AddToVectorD(this, "IC", arrIC);
}
//----------------------------------------------------------------------------------------
// CPolygonLineAnnotation
@ -715,18 +695,11 @@ namespace PdfWriter
}
void CPolygonLineAnnotation::SetIC(const std::vector<double>& arrIC)
{
AddIC(this, arrIC);
AddToVectorD(this, "IC", arrIC);
}
void CPolygonLineAnnotation::SetVertices(const std::vector<double>& arrVertices)
{
CArrayObject* pArray = new CArrayObject();
if (!pArray)
return;
Add("Vertices", pArray);
for (const double& dVertices : arrVertices)
pArray->Add(dVertices);
AddToVectorD(this, "Vertices", arrVertices);
}
//----------------------------------------------------------------------------------------
// CCaretAnnotation
@ -761,4 +734,208 @@ namespace PdfWriter
Add("IT", sValue.c_str());
}
//----------------------------------------------------------------------------------------
// CWidgetAnnotation
//----------------------------------------------------------------------------------------
CWidgetAnnotation::CWidgetAnnotation(CXref* pXref, EAnnotType eType) : CAnnotation(pXref, eType)
{
m_pMK = NULL;
}
void CWidgetAnnotation::CheckMK()
{
if (!m_pMK)
{
m_pMK = new CDictObject();
Add("MK", m_pMK);
}
}
void CWidgetAnnotation::SetQ(const BYTE& nQ)
{
Add("Q", (int)nQ);
}
void CWidgetAnnotation::SetH(const BYTE& nH)
{
std::string sValue;
switch (nH)
{
case 0:
{ sValue = "N"; break; }
case 1:
{ sValue = "I"; break; }
case 2:
{ sValue = "P"; break; }
case 3:
{ sValue = "O"; break; }
}
Add("H", sValue.c_str());
}
void CWidgetAnnotation::SetR(const int& nR)
{
CheckMK();
m_pMK->Add("R", nR);
}
void CWidgetAnnotation::SetFlag(const int& nFlag)
{
Add("Ff", nFlag);
}
void CWidgetAnnotation::SetParentID(const int& nParentID)
{
}
void CWidgetAnnotation::SetTU(const std::wstring& wsTU)
{
std::string sValue = U_TO_UTF8(wsTU);
Add("TU", new CStringObject(sValue.c_str()));
}
void CWidgetAnnotation::SetDS(const std::wstring& wsDS)
{
}
void CWidgetAnnotation::SetDV(const std::wstring& wsDV)
{
}
void CWidgetAnnotation::SetT(const std::wstring& wsT)
{
std::string sValue = U_TO_UTF8(wsT);
Add("T", new CStringObject(sValue.c_str()));
}
void CWidgetAnnotation::SetTC(const std::vector<double>& arrTC)
{
// Text color из DA
}
void CWidgetAnnotation::SetBC(const std::vector<double>& arrBC)
{
CheckMK();
AddToVectorD(m_pMK, "BC", arrBC);
}
void CWidgetAnnotation::SetBG(const std::vector<double>& arrBG)
{
CheckMK();
AddToVectorD(m_pMK, "BG", arrBG);
}
//----------------------------------------------------------------------------------------
// CButtonWidget
//----------------------------------------------------------------------------------------
CButtonWidget::CButtonWidget(CXref* pXref) : CWidgetAnnotation(pXref, AnnotWidget)
{
m_pIF = NULL;
}
void CButtonWidget::CheckIF()
{
CheckMK();
if (!m_pIF)
{
m_pIF = new CDictObject();
m_pMK->Add("IF", m_pIF);
}
}
void CButtonWidget::SetS(const BYTE& nS)
{
CheckIF();
std::string sValue;
switch (nS)
{
case 0:
{ sValue = "P"; break; }
case 1:
{ sValue = "A"; break; }
}
m_pIF->Add("S", sValue.c_str());
}
void CButtonWidget::SetTP(const BYTE& nTP)
{
Add("TP", nTP);
}
void CButtonWidget::SetSW(const BYTE& nSW)
{
CheckIF();
std::string sValue;
switch (nSW)
{
case 0:
{ sValue = "A"; break; }
case 1:
{ sValue = "N"; break; }
case 2:
{ sValue = "B"; break; }
case 3:
{ sValue = "S"; break; }
}
m_pIF->Add("SW", sValue.c_str());
}
void CButtonWidget::SetStyle(const BYTE& nStyle)
{
CheckMK();
std::string sValue;
switch (nStyle)
{
case 0:
{ sValue = "4"; break; }
case 1:
{ sValue = "8"; break; }
case 2:
{ sValue = "u"; break; }
case 3:
{ sValue = "l"; break; }
case 4:
{ sValue = "H"; break; }
case 5:
{ sValue = "n"; break; }
}
m_pMK->Add("CA", new CStringObject(sValue.c_str()));
}
void CButtonWidget::SetIFFlag(const int& nIFFlag)
{
CheckIF();
m_pIF->Add("FB", (nIFFlag & (1 << 4)) ? true : false);
}
void CButtonWidget::SetA(const double& dA1, const double& dA2)
{
CheckIF();
CArrayObject* pArray = new CArrayObject();
if (!pArray)
return;
m_pIF->Add("A", pArray);
pArray->Add(dA1);
pArray->Add(dA2);
}
void CButtonWidget::SetCA(const std::wstring& wsCA)
{
CheckMK();
std::string sValue = U_TO_UTF8(wsCA);
m_pMK->Add("CA", new CStringObject(sValue.c_str()));
}
void CButtonWidget::SetRC(const std::wstring& wsRC)
{
CheckMK();
std::string sValue = U_TO_UTF8(wsRC);
m_pMK->Add("RC", new CStringObject(sValue.c_str()));
}
void CButtonWidget::SetAC(const std::wstring& wsAC)
{
CheckMK();
std::string sValue = U_TO_UTF8(wsAC);
m_pMK->Add("AC", new CStringObject(sValue.c_str()));
}
void CButtonWidget::SetAP_N_Yes(const std::wstring& wsAP_N_Yes)
{
}
}

View File

@ -68,7 +68,8 @@ namespace PdfWriter
AnnotSquiggly = 14,
AnnotPolygon = 15,
AnnotPolyLine = 16,
AnnotCaret = 17
AnnotCaret = 17,
AnnotWidget = 18
};
enum EAnnotHighlightMode
{
@ -308,8 +309,7 @@ namespace PdfWriter
{
public:
CCaretAnnotation(CXref* pXref);
EAnnotType
GetAnnotationType() const override
EAnnotType GetAnnotationType() const override
{
return AnnotCaret;
}
@ -317,5 +317,90 @@ namespace PdfWriter
void SetSy(const BYTE& nSy);
void SetRD(const double& dRD1, const double& dRD2, const double& dRD3, const double& dRD4);
};
class CWidgetAnnotation : public CAnnotation
{
protected:
CDictObject* m_pMK;
void CheckMK();
public:
CWidgetAnnotation(CXref* pXref, EAnnotType eType);
void SetQ(const BYTE& nQ);
void SetH(const BYTE& nH);
void SetR(const int& nR);
void SetFlag (const int& nFlag);
void SetParentID(const int& nParentID);
void SetTU(const std::wstring& wsTU);
void SetDS(const std::wstring& wsDS);
void SetDV(const std::wstring& wsDV);
void SetT (const std::wstring& wsT);
void SetTC(const std::vector<double>& arrTC);
void SetBC(const std::vector<double>& arrBC);
void SetBG(const std::vector<double>& arrBG);
};
class CButtonWidget : public CWidgetAnnotation
{
private:
EAnnotType m_nSubtype;
CDictObject* m_pIF;
void CheckIF();
public:
CButtonWidget(CXref* pXref);
EAnnotType GetAnnotationType() const override
{
return m_nSubtype;
}
void SetS(const BYTE& nS);
void SetTP(const BYTE& nTP);
void SetSW(const BYTE& nSW);
void SetStyle(const BYTE& nStyle);
void SetIFFlag(const int& nIFFlag);
void SetA(const double& dA1, const double& dA2);
void SetCA(const std::wstring& wsCA);
void SetRC(const std::wstring& wsRC);
void SetAC(const std::wstring& wsAC);
void SetAP_N_Yes(const std::wstring& wsAP_N_Yes);
};
class CTextWidget : public CWidgetAnnotation
{
private:
EAnnotType m_nSubtype;
public:
CTextWidget(CXref* pXref);
EAnnotType GetAnnotationType() const override
{
return m_nSubtype;
}
};
class CChoiceWidget : public CWidgetAnnotation
{
private:
EAnnotType m_nSubtype;
public:
CChoiceWidget(CXref* pXref);
EAnnotType GetAnnotationType() const override
{
return m_nSubtype;
}
};
class CSignatureWidget : public CWidgetAnnotation
{
private:
EAnnotType m_nSubtype;
public:
CSignatureWidget(CXref* pXref);
EAnnotType GetAnnotationType() const override
{
return m_nSubtype;
}
};
}
#endif // _PDF_WRITER_SRC_ANNOTATION_H

View File

@ -589,6 +589,26 @@ namespace PdfWriter
{
return new CCaretAnnotation(m_pXref);
}
CAnnotation* CDocument::CreateWidgetAnnot()
{
return new CWidgetAnnotation(m_pXref, EAnnotType::AnnotWidget);
}
CAnnotation* CDocument::CreateButtonWidget()
{
return new CButtonWidget(m_pXref);
}
CAnnotation* CDocument::CreateTextWidget()
{
return new CTextWidget(m_pXref);
}
CAnnotation* CDocument::CreateChoiceWidget()
{
return new CChoiceWidget(m_pXref);
}
CAnnotation* CDocument::CreateSignatureWidget()
{
return new CSignatureWidget(m_pXref);
}
void CDocument::AddAnnotation(const int& nID, CAnnotation* pAnnot)
{
m_mAnnotations[nID] = pAnnot;

View File

@ -140,6 +140,11 @@ namespace PdfWriter
CAnnotation* CreatePopupAnnot();
CAnnotation* CreateFreeTextAnnot();
CAnnotation* CreateCaretAnnot();
CAnnotation* CreateWidgetAnnot();
CAnnotation* CreateButtonWidget();
CAnnotation* CreateTextWidget();
CAnnotation* CreateChoiceWidget();
CAnnotation* CreateSignatureWidget();
void AddAnnotation(const int& nID, CAnnotation* pAnnot);
void MatchAnnotation();

View File

@ -216,81 +216,36 @@ int main()
}
else if (true)
{
if (pdfFile.EditPage(0))
// чтение и конвертации бинарника
NSFile::CFileBinary oFile;
if (!oFile.OpenFile(NSFile::GetProcessDirectory() + L"/base64.txt"))
return 0;
DWORD dwFileSize = oFile.GetFileSize();
BYTE* pFileContent = new BYTE[dwFileSize];
if (!pFileContent)
{
// чтение и конвертации бинарника
NSFile::CFileBinary oFile;
if (!oFile.OpenFile(NSFile::GetProcessDirectory() + L"/base64.txt"))
return false;
DWORD dwFileSize = oFile.GetFileSize();
BYTE* pFileContent = new BYTE[dwFileSize];
if (!pFileContent)
{
oFile.CloseFile();
return false;
}
DWORD dwReaded;
oFile.ReadFile(pFileContent, dwFileSize, dwReaded);
oFile.CloseFile();
int nBufferLen = NSBase64::Base64DecodeGetRequiredLength(dwFileSize);
BYTE* pBuffer = new BYTE[nBufferLen];
if (!pBuffer)
{
RELEASEARRAYOBJECTS(pFileContent);
return false;
}
if (NSBase64::Base64Decode((const char*)pFileContent, dwFileSize, pBuffer, &nBufferLen))
pdfFile.AddToPdfFromBinary(pBuffer, nBufferLen, NULL);//NSOnlineOfficeBinToPdf::AddBinToPdf(&pdfFile, pBuffer, nBufferLen, NULL);
/*
CAnnotFieldInfo* pInfo = new CAnnotFieldInfo();
pInfo->SetType(8);
pInfo->SetID(80);
pInfo->SetAnnotFlag(4);
pInfo->SetPage(0); // та что в EditPage
pInfo->SetBounds(42, 660, 145, 677);
pInfo->SetFlag(8);
std::vector<double> arrC;
arrC.push_back(1);
arrC.push_back(0.4);
arrC.push_back(0);
pInfo->SetC(arrC);
CAnnotFieldInfo::CMarkupAnnotPr* pPrm = pInfo->GetMarkupAnnotPr();
pPrm->SetFlag(4);
pPrm->SetCA(0.4);
CAnnotFieldInfo::CTextMarkupAnnotPr* pPr = pInfo->GetTextMarkupAnnotPr();
pPr->SetSubtype(8);
std::vector<double> arrQuadPoints;
arrQuadPoints.push_back(47);
arrQuadPoints.push_back(676);
arrQuadPoints.push_back(140);
arrQuadPoints.push_back(676);
arrQuadPoints.push_back(47);
arrQuadPoints.push_back(660);
arrQuadPoints.push_back(140);
arrQuadPoints.push_back(660);
pPr->SetQuadPoints(arrQuadPoints);
pdfFile.AdvancedCommand(pInfo);
RELEASEOBJECT(pInfo);
*/
return 0;
}
DWORD dwReaded;
oFile.ReadFile(pFileContent, dwFileSize, dwReaded);
oFile.CloseFile();
int nBufferLen = NSBase64::Base64DecodeGetRequiredLength(dwFileSize);
BYTE* pBuffer = new BYTE[nBufferLen];
if (!pBuffer)
{
RELEASEARRAYOBJECTS(pFileContent);
return 0;
}
if (NSBase64::Base64Decode((const char*)pFileContent, dwFileSize, pBuffer, &nBufferLen))
pdfFile.AddToPdfFromBinary(pBuffer, nBufferLen, NULL);
RELEASEARRAYOBJECTS(pBuffer);
RELEASEARRAYOBJECTS(pFileContent);
}
else
{