From 5ce26e6dcae86deadd2a59430984533d74189bcd Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Mon, 9 Oct 2023 16:08:06 +0300 Subject: [PATCH] Add StartID, AP.have. Fix color for Text annot --- DesktopEditor/graphics/MetafileToRenderer.h | 1 + .../graphics/commands/AnnotField.cpp | 3 ++- .../graphics/pro/js/qt/nativegraphics.pro | 1 - .../pro/js/wasm/js/drawingfile_base.js | 9 +++++++ .../graphics/pro/js/wasm/src/drawingfile.cpp | 24 ++++++++++++------- .../graphics/pro/js/wasm/src/drawingfile.h | 6 +++++ PdfFile/OnlineOfficeBinToPdf.cpp | 3 +-- PdfFile/PdfFile.cpp | 7 ++++++ PdfFile/PdfFile.h | 1 + PdfFile/PdfReader.cpp | 7 ++++++ PdfFile/PdfReader.h | 1 + PdfFile/SrcReader/PdfAnnot.cpp | 12 +++++++++- PdfFile/SrcWriter/Annotation.cpp | 5 +++- 13 files changed, 66 insertions(+), 14 deletions(-) diff --git a/DesktopEditor/graphics/MetafileToRenderer.h b/DesktopEditor/graphics/MetafileToRenderer.h index dfafbba977..ebabee8400 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.h +++ b/DesktopEditor/graphics/MetafileToRenderer.h @@ -181,6 +181,7 @@ namespace NSOnlineOfficeBinToPdf ctFormField = 162, ctDocInfo = 163, ctAnnotField = 164, + ctAnnotFieldDelete = 165, ctPageWidth = 200, ctPageHeight = 201, diff --git a/DesktopEditor/graphics/commands/AnnotField.cpp b/DesktopEditor/graphics/commands/AnnotField.cpp index 206ba9e370..493c24cfdb 100644 --- a/DesktopEditor/graphics/commands/AnnotField.cpp +++ b/DesktopEditor/graphics/commands/AnnotField.cpp @@ -590,7 +590,8 @@ bool CAnnotFieldInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMeta pPr->SetSubtype(nType); std::vector arrQuadPoints; - for (int i = 0; i < 8; ++i) + int n = pReader->ReadInt(); + for (int i = 0; i < n; ++i) arrQuadPoints.push_back(pReader->ReadDouble()); pPr->SetQuadPoints(arrQuadPoints); } diff --git a/DesktopEditor/graphics/pro/js/qt/nativegraphics.pro b/DesktopEditor/graphics/pro/js/qt/nativegraphics.pro index e0cc2f5830..a169056047 100644 --- a/DesktopEditor/graphics/pro/js/qt/nativegraphics.pro +++ b/DesktopEditor/graphics/pro/js/qt/nativegraphics.pro @@ -164,7 +164,6 @@ SOURCES += \ \ ../../../../raster/JBig2/source/JBig2File.cpp \ \ - ../../../../raster/Metafile/StarView/SvmClip.cpp \ ../../../../raster/Metafile/StarView/SvmFile.cpp \ ../../../../raster/Metafile/StarView/SvmObjects.cpp \ ../../../../raster/Metafile/StarView/SvmPlayer.cpp diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js index cbea5d2de7..9d0acf7f7c 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js @@ -241,6 +241,8 @@ let buffer = new Uint8Array(Module["HEAP8"].buffer, _info + 4, len); let reader = new CBinaryReader(buffer, 0, len); + this.StartID = reader.readInt(); + let _pages = reader.readInt(); for (let i = 0; i < _pages; i++) { @@ -268,6 +270,7 @@ this.nativeFile = 0; this.pages = []; this.info = null; + this.StartID = null; if (this.stream > 0) Module["_free"](this.stream); this.stream = -1; @@ -288,6 +291,11 @@ { return this.info; }; + + CFile.prototype["getStartID"] = function() + { + return this.StartID; + }; CFile.prototype["getPagePixmap"] = function(pageIndex, width, height, backgroundColor) { @@ -563,6 +571,7 @@ // Дата последнего изменения - M if (flags & (1 << 5)) rec["LastModified"] = reader.readString(); + rec["AP"]["have"] = (flags >> 6) & 1; } function readAnnotAP(reader, AP) { diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp index 4a55aa8bc5..e58cb24280 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp @@ -113,6 +113,8 @@ WASM_EXPORT BYTE* GetInfo (CGraphicsFileDrawing* pGraphics) NSWasm::CData oRes; oRes.SkipLen(); + oRes.AddInt(pGraphics->GetMaxRefID()); + int pages_count = pGraphics->GetPagesCount(); oRes.AddInt(pages_count); for (int page = 0; page < pages_count; ++page) @@ -474,6 +476,10 @@ void ReadAnnot(BYTE* pWidgets, int& i) std::cout << "Last modified " << std::string((char*)(pWidgets + i), nPathLength) << ", "; i += nPathLength; } + if (nFlags & (1 << 6)) + std::cout << "YES AP, "; + else + std::cout << "NO AP, "; } void ReadInteractiveForms(BYTE* pWidgets, int& i) @@ -977,19 +983,21 @@ int main(int argc, char* argv[]) if (nLength > 0) { - nPagesCount = READ_INT(pInfo + 4); + std::cout << "MaxID " << READ_INT(pInfo + 4); + + nPagesCount = READ_INT(pInfo + 8); if (nPagesCount > 0) { - nWidth = READ_INT(pInfo + nTestPage * 16 + 8); - nHeight = READ_INT(pInfo + nTestPage * 16 + 12); - int dpi = READ_INT(pInfo + nTestPage * 16 + 16); - int rotate = READ_INT(pInfo + nTestPage * 16 + 20); + nWidth = READ_INT(pInfo + nTestPage * 16 + 12); + nHeight = READ_INT(pInfo + nTestPage * 16 + 16); + int dpi = READ_INT(pInfo + nTestPage * 16 + 20); + int rotate = READ_INT(pInfo + nTestPage * 16 + 24); //nWidth *= 2; //nHeight *= 2; - std::cout << "Page " << nTestPage << " width " << nWidth << " height " << nHeight << " dpi " << dpi << " rotate " << rotate << std::endl; + std::cout << " Page " << nTestPage << " width " << nWidth << " height " << nHeight << " dpi " << dpi << " rotate " << rotate << std::endl; - nLength = READ_INT(pInfo + nPagesCount * 16 + 8); - std::cout << "json "<< std::string((char*)(pInfo + nPagesCount * 16 + 12), nLength) << std::endl;; + nLength = READ_INT(pInfo + nPagesCount * 16 + 12); + std::cout << "json "<< std::string((char*)(pInfo + nPagesCount * 16 + 16), nLength) << std::endl;; } } diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h index 3940e18f6a..f7c3814a65 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.h @@ -73,6 +73,12 @@ public: { return pReader->GetPagesCount(); } + int GetMaxRefID() + { + if (nType == 0) + return ((CPdfFile*)pReader)->GetMaxRefID(); + return 0; + } void GetPageInfo(int nPageIndex, int& nWidth, int& nHeight, int& nPageDpiX, int& nRotate) { double dPageDpiX, dPageDpiY; diff --git a/PdfFile/OnlineOfficeBinToPdf.cpp b/PdfFile/OnlineOfficeBinToPdf.cpp index 3a6b8e9718..8e2c2d94fa 100644 --- a/PdfFile/OnlineOfficeBinToPdf.cpp +++ b/PdfFile/OnlineOfficeBinToPdf.cpp @@ -146,10 +146,9 @@ namespace NSOnlineOfficeBinToPdf enum class AddCommandType { - Annotation = 0, + Annotation = 0, // EditPage AddPage = 1, RemovePage = 2, - RemoveAnnotation = 3, Undefined = 255 }; diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 2a82331315..0d47640915 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -996,6 +996,13 @@ int CPdfFile::GetRotate(int nPageIndex) #endif return m_pInternal->pReader->GetRotate(nPageIndex); } +int CPdfFile::GetMaxRefID() +{ + if (!m_pInternal->pReader) + return 0; + + return m_pInternal->pReader->GetMaxRefID(); +} void CPdfFile::DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak) { if (!m_pInternal->pReader) diff --git a/PdfFile/PdfFile.h b/PdfFile/PdfFile.h index c850b6408b..e05145d816 100644 --- a/PdfFile/PdfFile.h +++ b/PdfFile/PdfFile.h @@ -126,6 +126,7 @@ public: virtual BYTE* GetStructure(); virtual BYTE* GetLinks(int nPageIndex); int GetRotate(int nPageIndex); + int GetMaxRefID(); BYTE* GetWidgets(); BYTE* GetAnnots (int nPageIndex = -1); BYTE* VerifySign (const std::wstring& sFile, ICertificate* pCertificate, int nWidget = -1); diff --git a/PdfFile/PdfReader.cpp b/PdfFile/PdfReader.cpp index f13fa84889..ac02289788 100644 --- a/PdfFile/PdfReader.cpp +++ b/PdfFile/PdfReader.cpp @@ -365,6 +365,13 @@ int CPdfReader::GetRotate(int _nPageIndex) return m_pPDFDocument->getPageRotate(nPageIndex); } +int CPdfReader::GetMaxRefID() +{ + if (!m_pPDFDocument) + return 0; + XRef* xref = m_pPDFDocument->getXRef(); + return xref->getNumObjects(); +} void CPdfReader::DrawPageOnRenderer(IRenderer* pRenderer, int _nPageIndex, bool* pbBreak) { int nPageIndex = _nPageIndex + 1; diff --git a/PdfFile/PdfReader.h b/PdfFile/PdfReader.h index 5022a9b6e9..642bccd0f3 100644 --- a/PdfFile/PdfReader.h +++ b/PdfFile/PdfReader.h @@ -59,6 +59,7 @@ public: void SetCMapFile(const std::wstring& sFile); int GetRotate(int nPageIndex); + int GetMaxRefID(); void GetPageInfo(int nPageIndex, double* pdWidth, double* pdHeight, double* pdDpiX, double* pdDpiY); void DrawPageOnRenderer(IRenderer* pRenderer, int nPageIndex, bool* pBreak); std::wstring GetInfo(); diff --git a/PdfFile/SrcReader/PdfAnnot.cpp b/PdfFile/SrcReader/PdfAnnot.cpp index a9b453eab1..5bc3f9fec7 100644 --- a/PdfFile/SrcReader/PdfAnnot.cpp +++ b/PdfFile/SrcReader/PdfAnnot.cpp @@ -1661,6 +1661,11 @@ CAnnot::CAnnot(PDFDoc* pdfDoc, AcroFormField* pField) delete s; } oObj.free(); + + // 7 - Наличие/Отсутствие внешнего вида + if (pField->fieldLookup("AP", &oObj)->isDict() && oObj.dictGetLength()) + m_unAFlags |= (1 << 6); + oObj.free(); } CAnnot::CAnnot(PDFDoc* pdfDoc, Object* oAnnotRef, int nPageIndex) @@ -1782,6 +1787,11 @@ CAnnot::CAnnot(PDFDoc* pdfDoc, Object* oAnnotRef, int nPageIndex) } oObj.free(); + // 7 - Наличие/Отсутствие внешнего вида + if (oAnnot.dictLookup("AP", &oObj)->isDict() && oObj.dictGetLength()) + m_unAFlags |= (1 << 6); + oObj.free(); + oAnnot.free(); } @@ -1858,7 +1868,7 @@ CAnnotAP::CAnnotAP(PDFDoc* pdfDoc, NSFonts::IFontManager* pFontManager, CFontLis m_pRenderer = NULL; Object oAP; - if (pField->fieldLookup("AP", &oAP)->isDict()) + if (pField->fieldLookup("AP", &oAP)->isDict() && oAP.dictGetLength()) { Init(pField); Init(pdfDoc, pFontManager, pFontList, nRasterW, nRasterH, nBackgroundColor, nPageIndex); diff --git a/PdfFile/SrcWriter/Annotation.cpp b/PdfFile/SrcWriter/Annotation.cpp index 4b62a3a398..68f97d6146 100644 --- a/PdfFile/SrcWriter/Annotation.cpp +++ b/PdfFile/SrcWriter/Annotation.cpp @@ -181,7 +181,7 @@ namespace PdfWriter void CAnnotation::SetContents(const std::wstring& wsText) { std::string sValue = U_TO_UTF8(wsText); - Add("Contents", new CStringObject(sValue.c_str())); + Add("Contents", new CStringObject(sValue.c_str(), true)); } void CAnnotation::SetNM(const std::wstring& wsNM) { @@ -315,6 +315,9 @@ namespace PdfWriter CTextAnnotation::CTextAnnotation(CXref* pXref) : CMarkupAnnotation(pXref, AnnotText) { Add("Name", "Comment"); + + if (!Get("C")) + SetC({ 1.0, 0.8, 0.0 }); } void CTextAnnotation::SetOpen(bool bOpen) {