From 8d4e2168520cd1fdc2fac53f11deb60018fb65be Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Wed, 18 Mar 2026 10:42:20 +0300 Subject: [PATCH] Link RD read and write --- DesktopEditor/graphics/commands/AnnotField.cpp | 8 ++++++++ DesktopEditor/graphics/commands/AnnotField.h | 2 ++ .../graphics/pro/js/wasm/js/drawingfile.js | 9 ++++++++- .../pro/js/wasm/src/drawingfile_test.cpp | 11 +++++++++++ PdfFile/PdfWriter.cpp | 6 ++++++ PdfFile/SrcReader/PdfAnnot.cpp | 16 ++++++++++++++++ PdfFile/SrcReader/PdfAnnot.h | 1 + PdfFile/SrcWriter/Annotation.cpp | 4 ++++ PdfFile/SrcWriter/Annotation.h | 1 + 9 files changed, 57 insertions(+), 1 deletion(-) diff --git a/DesktopEditor/graphics/commands/AnnotField.cpp b/DesktopEditor/graphics/commands/AnnotField.cpp index 3010eaaf99..f68acf39c2 100644 --- a/DesktopEditor/graphics/commands/AnnotField.cpp +++ b/DesktopEditor/graphics/commands/AnnotField.cpp @@ -864,6 +864,7 @@ CAnnotFieldInfo::CLinkAnnotPr::~CLinkAnnotPr() } BYTE CAnnotFieldInfo::CLinkAnnotPr::GetH() const { return m_nH; } int CAnnotFieldInfo::CLinkAnnotPr::GetFlags() const { return m_nFlags; } +void CAnnotFieldInfo::CLinkAnnotPr::GetRD(double& dRD1, double& dRD2, double& dRD3, double& dRD4) { dRD1 = m_dRD[0]; dRD2 = m_dRD[1]; dRD3 = m_dRD[2]; dRD4 = m_dRD[3]; } const std::vector& CAnnotFieldInfo::CLinkAnnotPr::GetQuadPoints() { return m_arrQuadPoints; } CAnnotFieldInfo::CActionFieldPr* CAnnotFieldInfo::CLinkAnnotPr::GetA() { return m_pAction; } CAnnotFieldInfo::CActionFieldPr* CAnnotFieldInfo::CLinkAnnotPr::GetPA() { return m_pPA; } @@ -889,6 +890,13 @@ void CAnnotFieldInfo::CLinkAnnotPr::Read(NSOnlineOfficeBinToPdf::CBufferReader* for (int i = 0; i < n; ++i) m_arrQuadPoints.push_back(pReader->ReadDouble()); } + if (m_nFlags & (1 << 4)) + { + m_dRD[0] = pReader->ReadDouble(); + m_dRD[1] = pReader->ReadDouble(); + m_dRD[2] = pReader->ReadDouble(); + m_dRD[3] = pReader->ReadDouble(); + } } CAnnotFieldInfo::CFileAttachmentAnnotPr::CFileAttachmentAnnotPr() diff --git a/DesktopEditor/graphics/commands/AnnotField.h b/DesktopEditor/graphics/commands/AnnotField.h index 837ce2c75d..34170387cc 100644 --- a/DesktopEditor/graphics/commands/AnnotField.h +++ b/DesktopEditor/graphics/commands/AnnotField.h @@ -489,6 +489,7 @@ public: BYTE GetH() const; int GetFlags() const; + void GetRD(double& dRD1, double& dRD2, double& dRD3, double& dRD4); const std::vector& GetQuadPoints(); CActionFieldPr* GetA(); CActionFieldPr* GetPA(); @@ -498,6 +499,7 @@ public: private: BYTE m_nH; int m_nFlags; + double m_dRD[4]{}; std::vector m_arrQuadPoints; CActionFieldPr* m_pAction; CActionFieldPr* m_pPA; diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js index 9dd82a2700..a7669cfb36 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile.js @@ -1085,8 +1085,15 @@ function readAnnotType(reader, rec, readDoubleFunc, readDouble2Func, readStringF for (let i = 0; i < n; ++i) rec["QuadPoints"].push(readDoubleFunc.call(reader)); } + // Rect and RD differenses + if (flags & (1 << 4)) + { + rec["RD"] = []; + for (let i = 0; i < 4; ++i) + rec["RD"].push(readDoubleFunc.call(reader)); + } } - // Link + // Screen else if (rec["type"] == 20) { flags = reader.readInt(); diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp index c9d6f1081a..427b56083f 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp @@ -2228,6 +2228,17 @@ int main(int argc, char* argv[]) } std::cout << ", "; } + if (nFlags & (1 << 4)) + { + std::cout << "RD"; + for (int j = 0; j < 4; ++j) + { + nPathLength = READ_INT(pAnnots + i); + i += 4; + std::cout << " " << (double)nPathLength / 100.0; + } + std::cout << ", "; + } } else if (sType == "Screen") { diff --git a/PdfFile/PdfWriter.cpp b/PdfFile/PdfWriter.cpp index 8d3f210913..193bca2300 100644 --- a/PdfFile/PdfWriter.cpp +++ b/PdfFile/PdfWriter.cpp @@ -2734,6 +2734,12 @@ HRESULT CPdfWriter::AddAnnotField(NSFonts::IApplicationFonts* pAppFonts, CAnnotF pLinkAnnot->SetH(pPr->GetH()); if (nFlags & (1 << 3)) pLinkAnnot->SetQuadPoints(pPr->GetQuadPoints()); + if (nFlags & (1 << 4)) + { + double dRD1, dRD2, dRD3, dRD4; + pPr->GetRD(dRD1, dRD2, dRD3, dRD4); + pLinkAnnot->SetRD(dRD1, dRD2, dRD3, dRD4); + } if (bRender) { diff --git a/PdfFile/SrcReader/PdfAnnot.cpp b/PdfFile/SrcReader/PdfAnnot.cpp index b7f9b826af..1f910dc96e 100644 --- a/PdfFile/SrcReader/PdfAnnot.cpp +++ b/PdfFile/SrcReader/PdfAnnot.cpp @@ -1247,6 +1247,17 @@ CAnnotLink::CAnnotLink(PDFDoc* pdfDoc, Object* oAnnotRef, int nPageIndex, int nS } oObj.free(); + // 4 - Различия Rect и фактического размера - RD + if (oAnnot.dictLookup("RD", &oObj)->isArray() && oObj.arrayGetLength() == 4) + { + m_unFlags |= (1 << 4); + m_pRD[0] = ArrGetNum(&oObj, 0); + m_pRD[3] = ArrGetNum(&oObj, 1); + m_pRD[2] = ArrGetNum(&oObj, 2); + m_pRD[1] = ArrGetNum(&oObj, 3); + } + oObj.free(); + oAnnot.free(); } CAnnotLink::~CAnnotLink() @@ -4060,6 +4071,11 @@ void CAnnotLink::ToWASM(NSWasm::CData& oRes) for (int i = 0; i < m_arrQuadPoints.size(); ++i) oRes.AddDouble(m_arrQuadPoints[i]); } + if (m_unFlags & (1 << 4)) + { + for (int i = 0; i < 4; ++i) + oRes.AddDouble(m_pRD[i]); + } } void CAnnotScreen::ToWASM(NSWasm::CData& oRes) { diff --git a/PdfFile/SrcReader/PdfAnnot.h b/PdfFile/SrcReader/PdfAnnot.h index 18d1ac05c0..3357104b17 100644 --- a/PdfFile/SrcReader/PdfAnnot.h +++ b/PdfFile/SrcReader/PdfAnnot.h @@ -351,6 +351,7 @@ public: private: BYTE m_nH; // Режим выделения - H + double m_pRD[4]{}; // Различия Rect и фактического размера std::vector m_arrQuadPoints; // Координаты - QuadPoints CAction* m_pAction; // Действие - A&Dest CAction* m_pPA; // URI действие - PA diff --git a/PdfFile/SrcWriter/Annotation.cpp b/PdfFile/SrcWriter/Annotation.cpp index cb948c3b49..85ea0e1770 100644 --- a/PdfFile/SrcWriter/Annotation.cpp +++ b/PdfFile/SrcWriter/Annotation.cpp @@ -836,6 +836,10 @@ namespace PdfWriter } Add("H", sValue.c_str()); } + void CLinkAnnotation::SetRD(const double& dRD1, const double& dRD2, const double& dRD3, const double& dRD4) + { + AddRD(this, dRD1, dRD2, dRD3, dRD4); + } void CLinkAnnotation::SetQuadPoints(const std::vector& arrQuadPoints) { CArrayObject* pArray = new CArrayObject(); diff --git a/PdfFile/SrcWriter/Annotation.h b/PdfFile/SrcWriter/Annotation.h index 3b8d96ab3a..98a91dcf4f 100644 --- a/PdfFile/SrcWriter/Annotation.h +++ b/PdfFile/SrcWriter/Annotation.h @@ -235,6 +235,7 @@ namespace PdfWriter } void SetH(BYTE nH); + void SetRD(const double& dRD1, const double& dRD2, const double& dRD3, const double& dRD4); void SetQuadPoints(const std::vector& arrQuadPoints); void SetA(CAction* pAction); void SetPA(CAction* pAction);