mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Fix test Redact
This commit is contained in:
@ -1226,13 +1226,6 @@ bool CWidgetsInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafil
|
|||||||
CRedact::CRedact() : IAdvancedCommand(AdvancedCommandType::Redact) {}
|
CRedact::CRedact() : IAdvancedCommand(AdvancedCommandType::Redact) {}
|
||||||
CRedact::~CRedact() {}
|
CRedact::~CRedact() {}
|
||||||
int CRedact::GetFlag() const { return m_nFlag; }
|
int CRedact::GetFlag() const { return m_nFlag; }
|
||||||
void CRedact::GetBounds(double& dX1, double& dY1, double& dX2, double& dY2)
|
|
||||||
{
|
|
||||||
dX1 = m_dX1;
|
|
||||||
dY1 = m_dY1;
|
|
||||||
dX2 = m_dX2;
|
|
||||||
dY2 = m_dY2;
|
|
||||||
}
|
|
||||||
const std::vector<double>& CRedact::GetQuadPoints() { return m_arrQuadPoints; }
|
const std::vector<double>& CRedact::GetQuadPoints() { return m_arrQuadPoints; }
|
||||||
BYTE* CRedact::GetRender(LONG& nLen)
|
BYTE* CRedact::GetRender(LONG& nLen)
|
||||||
{
|
{
|
||||||
@ -1252,11 +1245,6 @@ bool CRedact::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRe
|
|||||||
m_nFlag = pReader->ReadInt();
|
m_nFlag = pReader->ReadInt();
|
||||||
if (m_nFlag & (1 << 0))
|
if (m_nFlag & (1 << 0))
|
||||||
{
|
{
|
||||||
m_dX1 = pReader->ReadDouble();
|
|
||||||
m_dY1 = pReader->ReadDouble();
|
|
||||||
m_dX2 = pReader->ReadDouble();
|
|
||||||
m_dY2 = pReader->ReadDouble();
|
|
||||||
|
|
||||||
m_nRenderLen = pReader->ReadInt() - 4;
|
m_nRenderLen = pReader->ReadInt() - 4;
|
||||||
m_pRender = pReader->GetCurrentBuffer();
|
m_pRender = pReader->GetCurrentBuffer();
|
||||||
pReader->Skip(m_nRenderLen);
|
pReader->Skip(m_nRenderLen);
|
||||||
|
|||||||
@ -638,7 +638,6 @@ public:
|
|||||||
virtual ~CRedact();
|
virtual ~CRedact();
|
||||||
|
|
||||||
int GetFlag() const;
|
int GetFlag() const;
|
||||||
void GetBounds(double& dX1, double& dY1, double& dX2, double& dY2);
|
|
||||||
const std::vector<double>& GetQuadPoints();
|
const std::vector<double>& GetQuadPoints();
|
||||||
BYTE* GetRender(LONG& nLen);
|
BYTE* GetRender(LONG& nLen);
|
||||||
|
|
||||||
@ -646,10 +645,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int m_nFlag;
|
int m_nFlag;
|
||||||
double m_dX1;
|
|
||||||
double m_dY1;
|
|
||||||
double m_dX2;
|
|
||||||
double m_dY2;
|
|
||||||
LONG m_nRenderLen;
|
LONG m_nRenderLen;
|
||||||
BYTE* m_pRender;
|
BYTE* m_pRender;
|
||||||
std::vector<double> m_arrQuadPoints;
|
std::vector<double> m_arrQuadPoints;
|
||||||
|
|||||||
@ -247,8 +247,7 @@ namespace NSOnlineOfficeBinToPdf
|
|||||||
}
|
}
|
||||||
case AddCommandType::SetType:
|
case AddCommandType::SetType:
|
||||||
{
|
{
|
||||||
int nType = oReader.ReadInt();
|
pPdf->SetEditType(1);
|
||||||
pPdf->SetEditType(nType);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -3528,13 +3528,70 @@ bool CPdfEditor::IsBase14(const std::wstring& wsFontName, bool& bBold, bool& bIt
|
|||||||
}
|
}
|
||||||
void CPdfEditor::Redact(IAdvancedCommand* _pCommand)
|
void CPdfEditor::Redact(IAdvancedCommand* _pCommand)
|
||||||
{
|
{
|
||||||
CRedact* pCommand = (CRedact*)_pCommand;
|
|
||||||
PdfWriter::CDocument* pDoc = m_pWriter->GetDocument();
|
PdfWriter::CDocument* pDoc = m_pWriter->GetDocument();
|
||||||
Redact(pCommand->GetQuadPoints());
|
int nOriginIndex = m_nEditPage;
|
||||||
|
if (m_nMode == Mode::WriteNew)
|
||||||
|
{
|
||||||
|
PdfWriter::CPageTree* pPageTree = pDoc->GetPageTree();
|
||||||
|
PdfWriter::CObjectBase* pObj = pPageTree->GetObj(m_nEditPage);
|
||||||
|
PdfWriter::CFakePage* pFakePage = NULL;
|
||||||
|
if (pObj)
|
||||||
|
pFakePage = dynamic_cast<PdfWriter::CFakePage*>(pObj);
|
||||||
|
if (pFakePage)
|
||||||
|
nOriginIndex = pFakePage->GetOriginIndex();
|
||||||
|
}
|
||||||
|
PDFDoc* pPDFDocument = NULL;
|
||||||
|
int nPageIndex = m_pReader->GetPageIndex(nOriginIndex, &pPDFDocument);
|
||||||
|
if (nPageIndex < 0 || !pPDFDocument)
|
||||||
|
return;
|
||||||
|
Page* pPage = pPDFDocument->getCatalog()->getPage(nPageIndex);
|
||||||
|
PDFRectangle* cropBox = pPage->getCropBox();
|
||||||
|
|
||||||
|
CRedact* pCommand = (CRedact*)_pCommand;
|
||||||
|
std::vector<double> arrQuads = pCommand->GetQuadPoints();
|
||||||
|
for (int i = 0; i < arrQuads.size() / 4; ++i)
|
||||||
|
{
|
||||||
|
arrQuads[i * 4 + 0] += cropBox->x1;
|
||||||
|
double dQ = arrQuads[i * 4 + 1];
|
||||||
|
arrQuads[i * 4 + 1] = cropBox->y2 - arrQuads[i * 4 + 3];
|
||||||
|
arrQuads[i * 4 + 2] += cropBox->x1;
|
||||||
|
arrQuads[i * 4 + 3] = cropBox->y2 - dQ;
|
||||||
|
}
|
||||||
|
|
||||||
|
Redact(arrQuads);
|
||||||
|
|
||||||
int nFlags = pCommand->GetFlag();
|
int nFlags = pCommand->GetFlag();
|
||||||
if (nFlags & (1 << 0))
|
if (nFlags & (1 << 0))
|
||||||
{
|
{
|
||||||
|
m_pWriter->SetTransform(1, 0, 0, 1, 0, 0);
|
||||||
|
LONG nLenRender = 0;
|
||||||
|
BYTE* pRender = pCommand->GetRender(nLenRender);
|
||||||
|
|
||||||
|
BYTE* pMemory = pRender;
|
||||||
|
int ret = *((int*)pMemory);
|
||||||
|
pMemory += 4;
|
||||||
|
double R = ret / 100000.0;
|
||||||
|
ret = *((int*)pMemory);
|
||||||
|
pMemory += 4;
|
||||||
|
double G = ret / 100000.0;
|
||||||
|
ret = *((int*)pMemory);
|
||||||
|
double B = ret / 100000.0;
|
||||||
|
LONG lColor = (LONG)(((LONG)(R * 255)) | ((LONG)(G * 255) << 8) | ((LONG)(B * 255) << 16) | ((LONG)255 << 24));
|
||||||
|
|
||||||
|
for (int i = 0; i < arrQuads.size() / 4; ++i)
|
||||||
|
{
|
||||||
|
m_pWriter->PathCommandEnd();
|
||||||
|
m_pWriter->put_BrushColor1(lColor);
|
||||||
|
m_pWriter->PathCommandMoveTo(PdfReader::PDFCoordsToMM(arrQuads[i * 4 + 0] - cropBox->x1), PdfReader::PDFCoordsToMM(cropBox->y2 - arrQuads[i * 4 + 1]));
|
||||||
|
m_pWriter->PathCommandLineTo(PdfReader::PDFCoordsToMM(arrQuads[i * 4 + 0] - cropBox->x1), PdfReader::PDFCoordsToMM(cropBox->y2 - arrQuads[i * 4 + 3]));
|
||||||
|
m_pWriter->PathCommandLineTo(PdfReader::PDFCoordsToMM(arrQuads[i * 4 + 2] - cropBox->x1), PdfReader::PDFCoordsToMM(cropBox->y2 - arrQuads[i * 4 + 3]));
|
||||||
|
m_pWriter->PathCommandLineTo(PdfReader::PDFCoordsToMM(arrQuads[i * 4 + 2] - cropBox->x1), PdfReader::PDFCoordsToMM(cropBox->y2 - arrQuads[i * 4 + 1]));
|
||||||
|
m_pWriter->PathCommandClose();
|
||||||
|
m_pWriter->DrawPath(NULL, L"", c_nWindingFillMode);
|
||||||
|
m_pWriter->PathCommandEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
PdfWriter::CPage* pCurPage = m_pWriter->GetPage();
|
PdfWriter::CPage* pCurPage = m_pWriter->GetPage();
|
||||||
pDoc->FixEditPage(pCurPage);
|
pDoc->FixEditPage(pCurPage);
|
||||||
PdfWriter::CPage* pFakePage = new PdfWriter::CPage(pDoc);
|
PdfWriter::CPage* pFakePage = new PdfWriter::CPage(pDoc);
|
||||||
@ -3546,9 +3603,6 @@ void CPdfEditor::Redact(IAdvancedCommand* _pCommand)
|
|||||||
pFakePage->SetStream(pCurPage->GetStream());
|
pFakePage->SetStream(pCurPage->GetStream());
|
||||||
pFakePage->Add("Resources", pCurPage->Get("Resources"));
|
pFakePage->Add("Resources", pCurPage->Get("Resources"));
|
||||||
|
|
||||||
LONG nLenRender = 0;
|
|
||||||
BYTE* pRender = pCommand->GetRender(nLenRender);
|
|
||||||
|
|
||||||
IMetafileToRenderter* pCorrector = new IMetafileToRenderter(m_pWriter->GetRenderer());
|
IMetafileToRenderter* pCorrector = new IMetafileToRenderter(m_pWriter->GetRenderer());
|
||||||
NSOnlineOfficeBinToPdf::ConvertBufferToRenderer(pRender, nLenRender, pCorrector);
|
NSOnlineOfficeBinToPdf::ConvertBufferToRenderer(pRender, nLenRender, pCorrector);
|
||||||
RELEASEOBJECT(pCorrector);
|
RELEASEOBJECT(pCorrector);
|
||||||
@ -3556,6 +3610,7 @@ void CPdfEditor::Redact(IAdvancedCommand* _pCommand)
|
|||||||
m_pWriter->SetPage(pCurPage);
|
m_pWriter->SetPage(pCurPage);
|
||||||
pDoc->SetCurPage(pCurPage);
|
pDoc->SetCurPage(pCurPage);
|
||||||
RELEASEOBJECT(pFakePage);
|
RELEASEOBJECT(pFakePage);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CPdfEditor::Redact(const std::vector<double>& arrQuadPoints)
|
void CPdfEditor::Redact(const std::vector<double>& arrQuadPoints)
|
||||||
@ -3578,9 +3633,15 @@ void CPdfEditor::Redact(const std::vector<double>& arrQuadPoints)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
#ifndef BUILDING_WASM_MODULE
|
#ifndef BUILDING_WASM_MODULE
|
||||||
|
globalParams->setDrawFormFields(gFalse);
|
||||||
|
globalParams->setDrawAnnotations(gFalse);
|
||||||
|
|
||||||
PdfWriter::RedactOutputDev oRedactOut(m_pWriter);
|
PdfWriter::RedactOutputDev oRedactOut(m_pWriter);
|
||||||
oRedactOut.NewPDF(pPDFDocument->getXRef());
|
oRedactOut.NewPDF(pPDFDocument->getXRef());
|
||||||
oRedactOut.SetRedact(arrQuadPoints);
|
oRedactOut.SetRedact(arrQuadPoints);
|
||||||
pPDFDocument->displayPage(&oRedactOut, nPageIndex, 72.0, 72.0, 0, gTrue, gFalse, gFalse);
|
pPDFDocument->displayPage(&oRedactOut, nPageIndex, 72.0, 72.0, 0, gTrue, gFalse, gFalse);
|
||||||
|
|
||||||
|
globalParams->setDrawFormFields(gTrue);
|
||||||
|
globalParams->setDrawAnnotations(gTrue);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@ -775,10 +775,10 @@ bool CPdfReader::RedactPage(int _nPageIndex, double* arrRedactBox, int nLengthX4
|
|||||||
pRedact->m_nPageIndex = _nPageIndex;
|
pRedact->m_nPageIndex = _nPageIndex;
|
||||||
for (int i = 0; i < nLengthX4; ++i)
|
for (int i = 0; i < nLengthX4; ++i)
|
||||||
{
|
{
|
||||||
pRedact->m_arrRedactBox.push_back(arrRedactBox[i + 0] + cropBox->x1);
|
pRedact->m_arrRedactBox.push_back(arrRedactBox[i * 4 + 0] + cropBox->x1);
|
||||||
pRedact->m_arrRedactBox.push_back(cropBox->y2 - arrRedactBox[i + 3]);
|
pRedact->m_arrRedactBox.push_back(cropBox->y2 - arrRedactBox[i * 4 + 3]);
|
||||||
pRedact->m_arrRedactBox.push_back(arrRedactBox[i + 2] + cropBox->x1);
|
pRedact->m_arrRedactBox.push_back(arrRedactBox[i * 4 + 2] + cropBox->x1);
|
||||||
pRedact->m_arrRedactBox.push_back(cropBox->y2 - arrRedactBox[i + 1]);
|
pRedact->m_arrRedactBox.push_back(cropBox->y2 - arrRedactBox[i * 4 + 1]);
|
||||||
}
|
}
|
||||||
pRedact->m_pChanges = pChanges;
|
pRedact->m_pChanges = pChanges;
|
||||||
pRedact->m_nChangeLength = nLength;
|
pRedact->m_nChangeLength = nLength;
|
||||||
@ -827,7 +827,6 @@ void CPdfReader::DrawPageOnRenderer(IRenderer* pRenderer, int _nPageIndex, bool*
|
|||||||
{
|
{
|
||||||
if (m_vRedact[i]->m_nPageIndex == _nPageIndex)
|
if (m_vRedact[i]->m_nPageIndex == _nPageIndex)
|
||||||
{
|
{
|
||||||
// TODO нужно сбросить все матрицы и т.п.
|
|
||||||
BYTE* pMemory = m_vRedact[i]->m_pChanges;
|
BYTE* pMemory = m_vRedact[i]->m_pChanges;
|
||||||
int ret = *((int*)pMemory);
|
int ret = *((int*)pMemory);
|
||||||
pMemory += 4;
|
pMemory += 4;
|
||||||
|
|||||||
@ -39,8 +39,6 @@
|
|||||||
#include "../lib/pathkit/include/core/SkPath.h"
|
#include "../lib/pathkit/include/core/SkPath.h"
|
||||||
#include "../lib/pathkit/include/pathops/SkPathOps.h"
|
#include "../lib/pathkit/include/pathops/SkPathOps.h"
|
||||||
|
|
||||||
#include "../../DesktopEditor/graphics/GraphicsPath.h"
|
|
||||||
|
|
||||||
namespace PdfWriter
|
namespace PdfWriter
|
||||||
{
|
{
|
||||||
void Transform(double* pMatrix, double dUserX, double dUserY, double* pdDeviceX, double* pdDeviceY)
|
void Transform(double* pMatrix, double dUserX, double dUserY, double* pdDeviceX, double* pdDeviceY)
|
||||||
@ -389,21 +387,61 @@ void RedactOutputDev::drawChar(GfxState *pGState, double dX, double dY, double d
|
|||||||
{
|
{
|
||||||
double* pCTM = pGState->getCTM();
|
double* pCTM = pGState->getCTM();
|
||||||
double* pTm = pGState->getTextMat();
|
double* pTm = pGState->getTextMat();
|
||||||
double arrMatrix[6];
|
double pNewTm[6], arrMatrix[6];
|
||||||
|
|
||||||
arrMatrix[0] = pTm[0] * pCTM[0] + pTm[1] * pCTM[2];
|
double dTextScale = std::min(sqrt(pTm[2] * pTm[2] + pTm[3] * pTm[3]), sqrt(pTm[0] * pTm[0] + pTm[1] * pTm[1]));
|
||||||
arrMatrix[1] = pTm[0] * pCTM[1] + pTm[1] * pCTM[3];
|
double dITextScale = 1 / dTextScale;
|
||||||
arrMatrix[2] = pTm[2] * pCTM[0] + pTm[3] * pCTM[2];
|
double dOldSize = 10.0;
|
||||||
arrMatrix[3] = pTm[2] * pCTM[1] + pTm[3] * pCTM[3];
|
m_pRenderer->get_FontSize(&dOldSize);
|
||||||
arrMatrix[4] = pTm[4] * pCTM[0] + pTm[5] * pCTM[2] + pCTM[4];
|
if (dOldSize * dTextScale > 0)
|
||||||
arrMatrix[5] = pTm[4] * pCTM[1] + pTm[5] * pCTM[3] + pCTM[5];
|
|
||||||
|
|
||||||
if (arrMatrix[0] != m_arrMatrix[0] || arrMatrix[1] != m_arrMatrix[1] || arrMatrix[2] != m_arrMatrix[2] ||
|
|
||||||
arrMatrix[3] != m_arrMatrix[3] || arrMatrix[4] != m_arrMatrix[4] || arrMatrix[5] != m_arrMatrix[5])
|
|
||||||
{
|
{
|
||||||
double dShiftX = 0, dShiftY = 0;
|
m_pRenderer->put_FontSize(dOldSize * dTextScale);
|
||||||
DoTransform(arrMatrix, &dShiftX, &dShiftY, true);
|
|
||||||
|
pNewTm[0] = pTm[0] * dITextScale * pGState->getHorizScaling();
|
||||||
|
pNewTm[1] = pTm[1] * dITextScale * pGState->getHorizScaling();
|
||||||
|
pNewTm[2] = pTm[2] * dITextScale;
|
||||||
|
pNewTm[3] = pTm[3] * dITextScale;
|
||||||
|
pNewTm[4] = dX - dOriginX;
|
||||||
|
pNewTm[5] = dY - dOriginY;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_pRenderer->put_FontSize(-dOldSize * dTextScale);
|
||||||
|
|
||||||
|
pNewTm[0] = pTm[0] * dITextScale * pGState->getHorizScaling();
|
||||||
|
pNewTm[1] = pTm[1] * dITextScale * pGState->getHorizScaling();
|
||||||
|
pNewTm[2] = pTm[2] * dITextScale;
|
||||||
|
pNewTm[3] = pTm[3] * dITextScale;
|
||||||
|
pNewTm[4] = dX;
|
||||||
|
pNewTm[5] = dY;
|
||||||
|
}
|
||||||
|
|
||||||
|
arrMatrix[0] = pNewTm[0] * pCTM[0] + pNewTm[1] * pCTM[2];
|
||||||
|
arrMatrix[1] = pNewTm[0] * pCTM[1] + pNewTm[1] * pCTM[3];
|
||||||
|
arrMatrix[2] = pNewTm[2] * pCTM[0] + pNewTm[3] * pCTM[2];
|
||||||
|
arrMatrix[3] = pNewTm[2] * pCTM[1] + pNewTm[3] * pCTM[3];
|
||||||
|
arrMatrix[4] = pNewTm[4] * pCTM[0] + pNewTm[5] * pCTM[2] + pCTM[4];
|
||||||
|
arrMatrix[5] = pNewTm[4] * pCTM[1] + pNewTm[5] * pCTM[3] + pCTM[5];
|
||||||
|
|
||||||
|
double dSize = 1;
|
||||||
|
if (true)
|
||||||
|
{
|
||||||
|
double dNorma = std::min(sqrt(arrMatrix[0] * arrMatrix[0] + arrMatrix[1] * arrMatrix[1]), sqrt(arrMatrix[2] * arrMatrix[2] + arrMatrix[3] * arrMatrix[3]));
|
||||||
|
if (dNorma > 0 && dNorma != 1)
|
||||||
|
{
|
||||||
|
arrMatrix[0] /= dNorma;
|
||||||
|
arrMatrix[1] /= dNorma;
|
||||||
|
arrMatrix[2] /= dNorma;
|
||||||
|
arrMatrix[3] /= dNorma;
|
||||||
|
|
||||||
|
m_pRenderer->get_FontSize(&dSize);
|
||||||
|
dSize *= dNorma;
|
||||||
|
m_pRenderer->put_FontSize(dSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double dShiftX = 0, dShiftY = 0;
|
||||||
|
DoTransform(arrMatrix, &dShiftX, &dShiftY, true);
|
||||||
|
|
||||||
double dDiff = dX + dDx / 2.0;
|
double dDiff = dX + dDx / 2.0;
|
||||||
for (int i = 0; i < m_arrQuadPoints.size(); i += 4)
|
for (int i = 0; i < m_arrQuadPoints.size(); i += 4)
|
||||||
@ -423,7 +461,7 @@ void RedactOutputDev::drawChar(GfxState *pGState, double dX, double dY, double d
|
|||||||
|
|
||||||
m_pRenderer->m_oCommandManager.SetTransform(m_arrMatrix[0], m_arrMatrix[1], m_arrMatrix[2], m_arrMatrix[3], m_arrMatrix[4], m_arrMatrix[5]);
|
m_pRenderer->m_oCommandManager.SetTransform(m_arrMatrix[0], m_arrMatrix[1], m_arrMatrix[2], m_arrMatrix[3], m_arrMatrix[4], m_arrMatrix[5]);
|
||||||
|
|
||||||
CRendererTextCommand* pText = m_pRenderer->m_oCommandManager.AddText(pCodes, 2, dOriginX, dOriginY);
|
CRendererTextCommand* pText = m_pRenderer->m_oCommandManager.AddText(pCodes, 2, dShiftX, dShiftY);
|
||||||
pText->SetName(m_pRenderer->m_oFont.GetName());
|
pText->SetName(m_pRenderer->m_oFont.GetName());
|
||||||
pText->SetSize(m_pRenderer->m_oFont.GetSize());
|
pText->SetSize(m_pRenderer->m_oFont.GetSize());
|
||||||
int nDColor2Size;
|
int nDColor2Size;
|
||||||
|
|||||||
Reference in New Issue
Block a user