mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Write Redact
This commit is contained in:
@ -76,6 +76,7 @@ CAnnotFieldInfo::CAnnotFieldInfo() : IAdvancedCommand(AdvancedCommandType::Annot
|
||||
m_pFreeTextPr = NULL;
|
||||
m_pCaretPr = NULL;
|
||||
m_pStampPr = NULL;
|
||||
m_pRedactPr = NULL;
|
||||
m_pWidgetPr = NULL;
|
||||
}
|
||||
CAnnotFieldInfo::~CAnnotFieldInfo()
|
||||
@ -91,6 +92,7 @@ CAnnotFieldInfo::~CAnnotFieldInfo()
|
||||
RELEASEOBJECT(m_pFreeTextPr);
|
||||
RELEASEOBJECT(m_pCaretPr);
|
||||
RELEASEOBJECT(m_pStampPr);
|
||||
RELEASEOBJECT(m_pRedactPr);
|
||||
RELEASEOBJECT(m_pWidgetPr);
|
||||
}
|
||||
|
||||
@ -178,6 +180,13 @@ void CAnnotFieldInfo::SetType(int nType)
|
||||
m_pPopupPr = new CAnnotFieldInfo::CPopupAnnotPr();
|
||||
break;
|
||||
}
|
||||
case EAnnotType::Redact:
|
||||
{
|
||||
CreateMarkup();
|
||||
RELEASEOBJECT(m_pRedactPr);
|
||||
m_pRedactPr = new CAnnotFieldInfo::CRedactAnnotPr();
|
||||
break;
|
||||
}
|
||||
case EAnnotType::Widget:
|
||||
case EAnnotType::WidgetPushButton:
|
||||
case EAnnotType::WidgetRadioButton:
|
||||
@ -291,6 +300,10 @@ bool CAnnotFieldInfo::IsStamp() const
|
||||
{
|
||||
return (m_nType == 12);
|
||||
}
|
||||
bool CAnnotFieldInfo::IsRedact() const
|
||||
{
|
||||
return (m_nType == 25);
|
||||
}
|
||||
|
||||
CAnnotFieldInfo::CMarkupAnnotPr* CAnnotFieldInfo::GetMarkupAnnotPr() { return m_pMarkupPr; }
|
||||
CAnnotFieldInfo::CTextAnnotPr* CAnnotFieldInfo::GetTextAnnotPr() { return m_pTextPr; }
|
||||
@ -303,6 +316,7 @@ CAnnotFieldInfo::CPopupAnnotPr* CAnnotFieldInfo::GetPopupAnnotPr()
|
||||
CAnnotFieldInfo::CFreeTextAnnotPr* CAnnotFieldInfo::GetFreeTextAnnotPr() { return m_pFreeTextPr; }
|
||||
CAnnotFieldInfo::CCaretAnnotPr* CAnnotFieldInfo::GetCaretAnnotPr() { return m_pCaretPr; }
|
||||
CAnnotFieldInfo::CStampAnnotPr* CAnnotFieldInfo::GetStampAnnotPr() { return m_pStampPr; }
|
||||
CAnnotFieldInfo::CRedactAnnotPr* CAnnotFieldInfo::GetRedactAnnotPr() { return m_pRedactPr; }
|
||||
CAnnotFieldInfo::CWidgetAnnotPr* CAnnotFieldInfo::GetWidgetAnnotPr() { return m_pWidgetPr; }
|
||||
|
||||
bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector)
|
||||
@ -388,6 +402,8 @@ bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMeta
|
||||
m_pCaretPr->Read(pReader, nFlags);
|
||||
else if (IsStamp())
|
||||
m_pStampPr->Read(pReader, nFlags);
|
||||
else if (IsRedact())
|
||||
m_pRedactPr->Read(pReader, nFlags);
|
||||
}
|
||||
else if (IsPopup())
|
||||
m_pPopupPr->Read(pReader);
|
||||
@ -662,6 +678,46 @@ void CAnnotFieldInfo::CStampAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader*
|
||||
m_dInRect[3] = pReader->ReadDouble();
|
||||
}
|
||||
|
||||
BYTE CAnnotFieldInfo::CRedactAnnotPr::GetQ() const { return m_nQ; }
|
||||
int CAnnotFieldInfo::CRedactAnnotPr::GetFontStyle() const { return m_nFontStyle; }
|
||||
double CAnnotFieldInfo::CRedactAnnotPr::GetFontSize() const { return m_dFS; }
|
||||
const std::wstring& CAnnotFieldInfo::CRedactAnnotPr::GetFontName() { return m_wsFN; }
|
||||
const std::wstring& CAnnotFieldInfo::CRedactAnnotPr::GetOverlayText() { return m_wsOverlayText; }
|
||||
const std::vector<double>& CAnnotFieldInfo::CRedactAnnotPr::GetIC() { return m_arrIC; }
|
||||
const std::vector<double>& CAnnotFieldInfo::CRedactAnnotPr::GetFontColor() { return m_arrFC; }
|
||||
const std::vector<double>& CAnnotFieldInfo::CRedactAnnotPr::GetQuadPoints() { return m_arrQuadPoints; }
|
||||
void CAnnotFieldInfo::CRedactAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags)
|
||||
{
|
||||
if (nFlags & (1 << 15))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrQuadPoints.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrQuadPoints.push_back(pReader->ReadDouble());
|
||||
}
|
||||
if (nFlags & (1 << 16))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrIC.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrIC.push_back(pReader->ReadDouble());
|
||||
}
|
||||
if (nFlags & (1 << 17))
|
||||
m_wsOverlayText = pReader->ReadString();
|
||||
if (nFlags & (1 << 19))
|
||||
m_nQ = pReader->ReadByte();
|
||||
if (nFlags & (1 << 20))
|
||||
{
|
||||
int n = pReader->ReadInt();
|
||||
m_arrFC.reserve(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
m_arrFC.push_back(pReader->ReadDouble());
|
||||
m_dFS = pReader->ReadDouble();
|
||||
m_wsFN = pReader->ReadString();
|
||||
m_nFontStyle = pReader->ReadInt();
|
||||
}
|
||||
}
|
||||
|
||||
bool CAnnotFieldInfo::CPopupAnnotPr::IsOpen() const { return m_bOpen; }
|
||||
int CAnnotFieldInfo::CPopupAnnotPr::GetFlag() const { return m_nFlag; }
|
||||
int CAnnotFieldInfo::CPopupAnnotPr::GetParentID() const { return m_nParentID; }
|
||||
|
||||
@ -59,6 +59,7 @@ public:
|
||||
Ink = 14,
|
||||
Popup = 15,
|
||||
FileAttachment = 16,
|
||||
Redact = 25,
|
||||
Widget = 26,
|
||||
WidgetPushButton = 27,
|
||||
WidgetRadioButton = 28,
|
||||
@ -452,6 +453,31 @@ public:
|
||||
double m_dInRect[4]{};
|
||||
};
|
||||
|
||||
class GRAPHICS_DECL CRedactAnnotPr
|
||||
{
|
||||
public:
|
||||
BYTE GetQ() const;
|
||||
int GetFontStyle() const;
|
||||
double GetFontSize() const;
|
||||
const std::wstring& GetFontName();
|
||||
const std::wstring& GetOverlayText();
|
||||
const std::vector<double>& GetIC();
|
||||
const std::vector<double>& GetFontColor();
|
||||
const std::vector<double>& GetQuadPoints();
|
||||
|
||||
void Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, int nFlags);
|
||||
|
||||
private:
|
||||
BYTE m_nQ;
|
||||
int m_nFontStyle;
|
||||
double m_dFS;
|
||||
std::wstring m_wsFN;
|
||||
std::wstring m_wsOverlayText;
|
||||
std::vector<double> m_arrIC;
|
||||
std::vector<double> m_arrFC;
|
||||
std::vector<double> m_arrQuadPoints;
|
||||
};
|
||||
|
||||
CAnnotFieldInfo();
|
||||
virtual ~CAnnotFieldInfo();
|
||||
|
||||
@ -490,6 +516,7 @@ public:
|
||||
bool IsFreeText() const;
|
||||
bool IsCaret() const;
|
||||
bool IsStamp() const;
|
||||
bool IsRedact() const;
|
||||
|
||||
CMarkupAnnotPr* GetMarkupAnnotPr();
|
||||
CTextAnnotPr* GetTextAnnotPr();
|
||||
@ -502,6 +529,7 @@ public:
|
||||
CFreeTextAnnotPr* GetFreeTextAnnotPr();
|
||||
CCaretAnnotPr* GetCaretAnnotPr();
|
||||
CStampAnnotPr* GetStampAnnotPr();
|
||||
CRedactAnnotPr* GetRedactAnnotPr();
|
||||
CWidgetAnnotPr* GetWidgetAnnotPr();
|
||||
|
||||
bool Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector);
|
||||
@ -545,6 +573,7 @@ private:
|
||||
CFreeTextAnnotPr* m_pFreeTextPr;
|
||||
CCaretAnnotPr* m_pCaretPr;
|
||||
CStampAnnotPr* m_pStampPr;
|
||||
CRedactAnnotPr* m_pRedactPr;
|
||||
CWidgetAnnotPr* m_pWidgetPr;
|
||||
};
|
||||
|
||||
|
||||
@ -2228,6 +2228,39 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF
|
||||
|
||||
pStampAnnot->SetRotate(nRotate);
|
||||
}
|
||||
else if (oInfo.IsRedact())
|
||||
{
|
||||
CAnnotFieldInfo::CRedactAnnotPr* pPr = oInfo.GetRedactAnnotPr();
|
||||
PdfWriter::CRedactAnnotation* pRedactAnnot = (PdfWriter::CRedactAnnotation*)pAnnot;
|
||||
|
||||
if (nFlags & (1 << 15))
|
||||
pRedactAnnot->SetQuadPoints(pPr->GetQuadPoints());
|
||||
if (nFlags & (1 << 16))
|
||||
pRedactAnnot->SetIC(pPr->GetIC());
|
||||
if (nFlags & (1 << 17))
|
||||
pRedactAnnot->SetOverlayText(pPr->GetOverlayText());
|
||||
if (nFlags & (1 << 18))
|
||||
pRedactAnnot->SetRepeat(true);
|
||||
if (nFlags & (1 << 19))
|
||||
pRedactAnnot->SetQ(pPr->GetQ());
|
||||
if (nFlags & (1 << 20))
|
||||
{
|
||||
std::wstring wsFontName = pPr->GetFontName();
|
||||
int nStyle = pPr->GetFontStyle();
|
||||
double dFontSize = pPr->GetFontSize();
|
||||
PdfWriter::CFontTrueType* pFontTT = NULL;
|
||||
|
||||
put_FontName(wsFontName);
|
||||
put_FontStyle(nStyle);
|
||||
put_FontSize(dFontSize);
|
||||
|
||||
if (m_bNeedUpdateTextFont)
|
||||
UpdateFont();
|
||||
if (m_pFont)
|
||||
pFontTT = m_pDocument->CreateTrueTypeFont(m_pFont);
|
||||
pRedactAnnot->SetDA(pFontTT, dFontSize, pPr->GetFontColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (oInfo.IsPopup())
|
||||
{
|
||||
|
||||
@ -1206,6 +1206,65 @@ namespace PdfWriter
|
||||
return m_pAPStream;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
// CRedactAnnotation
|
||||
//----------------------------------------------------------------------------------------
|
||||
CRedactAnnotation::CRedactAnnotation(CXref* pXref) : CMarkupAnnotation(pXref, AnnotRedact)
|
||||
{
|
||||
}
|
||||
void CRedactAnnotation::SetDA(CFontDict* pFont, const double& dFontSize, const std::vector<double>& arrC)
|
||||
{
|
||||
const char* sFontName = NULL;
|
||||
if (pFont)
|
||||
{
|
||||
CResourcesDict* pFieldsResources = m_pDocument->GetFieldsResources();
|
||||
sFontName = pFieldsResources->GetFontName(pFont);
|
||||
}
|
||||
|
||||
std::vector<double> _arrC = arrC;
|
||||
if (arrC.empty())
|
||||
_arrC = {0};
|
||||
std::string sDA = GetColor(_arrC, false);
|
||||
if (sFontName)
|
||||
{
|
||||
sDA.append(" /");
|
||||
sDA.append(sFontName);
|
||||
|
||||
sDA.append(" ");
|
||||
sDA.append(std::to_string(dFontSize));
|
||||
sDA.append(" Tf");
|
||||
}
|
||||
|
||||
Add("DA", new CStringObject(sDA.c_str()));
|
||||
}
|
||||
void CRedactAnnotation::SetRepeat(bool bRepeat)
|
||||
{
|
||||
Add("Repeat", bRepeat);
|
||||
}
|
||||
void CRedactAnnotation::SetQ(BYTE nQ)
|
||||
{
|
||||
Add("Q", (int)nQ);
|
||||
}
|
||||
void CRedactAnnotation::SetOverlayText(const std::wstring& wsOverlayText)
|
||||
{
|
||||
std::string sValue = U_TO_UTF8(wsOverlayText);
|
||||
Add("OverlayText", new CStringObject(sValue.c_str(), true));
|
||||
}
|
||||
void CRedactAnnotation::SetIC(const std::vector<double>& arrIC)
|
||||
{
|
||||
AddToVectorD(this, "IC", arrIC);
|
||||
}
|
||||
void CRedactAnnotation::SetQuadPoints(const std::vector<double>& arrQuadPoints)
|
||||
{
|
||||
CArrayObject* pArray = new CArrayObject();
|
||||
if (!pArray)
|
||||
return;
|
||||
|
||||
Add("QuadPoints", pArray);
|
||||
|
||||
for (int i = 0; i < arrQuadPoints.size(); ++i)
|
||||
pArray->Add(i % 2 == 0 ? (arrQuadPoints[i] + m_dPageX) : (m_dPageH - arrQuadPoints[i]));
|
||||
}
|
||||
//----------------------------------------------------------------------------------------
|
||||
// CWidgetAnnotation
|
||||
//----------------------------------------------------------------------------------------
|
||||
CWidgetAnnotation::CWidgetAnnotation(CXref* pXref, EAnnotType eType) : CAnnotation(pXref, eType)
|
||||
|
||||
@ -416,6 +416,23 @@ namespace PdfWriter
|
||||
|
||||
CDictObject* GetAPStream();
|
||||
};
|
||||
class CRedactAnnotation : public CMarkupAnnotation
|
||||
{
|
||||
public:
|
||||
CRedactAnnotation(CXref* pXref);
|
||||
EAnnotType GetAnnotationType() const override
|
||||
{
|
||||
return AnnotRedact;
|
||||
}
|
||||
|
||||
void SetDA(CFontDict* pFont, const double& dFontSize, const std::vector<double>& arrC);
|
||||
|
||||
void SetRepeat(bool bRepeat);
|
||||
void SetQ(BYTE nQ);
|
||||
void SetOverlayText(const std::wstring& wsOverlayText);
|
||||
void SetIC(const std::vector<double>& arrIC);
|
||||
void SetQuadPoints(const std::vector<double>& arrQuadPoints);
|
||||
};
|
||||
class CWidgetAnnotation : public CAnnotation
|
||||
{
|
||||
protected:
|
||||
|
||||
@ -79,7 +79,8 @@ namespace PdfWriter
|
||||
AnnotPolygon = 15,
|
||||
AnnotPolyLine = 16,
|
||||
AnnotCaret = 17,
|
||||
AnnotWidget = 18
|
||||
AnnotWidget = 18,
|
||||
AnnotRedact = 25
|
||||
};
|
||||
enum EWidgetType
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user