From fc7d427407dc56d30cc71a37e68d62f8987536e2 Mon Sep 17 00:00:00 2001 From: Kulikova Svetlana Date: Fri, 29 Oct 2021 14:21:21 +0300 Subject: [PATCH] pdf fix links --- .../pro/js/wasm/js/drawingfile_base.js | 49 ++++++++++++++----- .../graphics/pro/js/wasm/src/drawingfile.cpp | 8 +-- PdfReader/PdfReader.cpp | 6 ++- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js index f7ab805713..c44c245867 100644 --- a/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js +++ b/DesktopEditor/graphics/pro/js/wasm/js/drawingfile_base.js @@ -123,8 +123,10 @@ { this.nativeFile = 0; this.stream = -1; + this.stream_size = 0; this.type = -1; this.pages = []; + this._isNeedPassword = false; } CFile.prototype["loadFromData"] = function(arrayBuffer) @@ -132,21 +134,44 @@ var data = new Uint8Array(arrayBuffer); var _stream = Module["_malloc"](data.length); Module["HEAP8"].set(data, _stream); - this.nativeFile = Module["_Open"](_stream, data.length); - var nCodeError = Module["_GetErrorCode"](this.nativeFile); - // 4 - нужен пароль - if (nCodeError == 4) - return null; - // 0 - ошибки нет - if (nCodeError != 0) - { - this.close(); - return null; - } + this.nativeFile = Module["_Open"](_stream, data.length, 0); + var error = Module["_GetErrorCode"](this.nativeFile); this.stream = _stream; + this.stream_size = data.length; this.type = Module["_GetType"](_stream, data.length); self.drawingFile = this; - return this.getInfo(); + this.getInfo(); + this._isNeedPassword = (4 === error) ? true : false; + + // 0 - ok + // 4 - password + // else - error + return error; + }; + CFile.prototype["loadFromDataWithPassword"] = function(password) + { + if (0 != this.nativeFile) + Module["_Close"](this.nativeFile); + + var passBuffer = password.toUtf8(); + var passPointer = Module["_malloc"](passBuffer.length); + Module["HEAP8"].set(passBuffer, passPointer); + this.nativeFile = Module["_Open"](this.stream, this.stream_size, passPointer); + Module["_free"](passPointer); + var error = Module["_GetErrorCode"](this.nativeFile); + this.type = Module["_GetType"](this.stream, this.stream_size); + self.drawingFile = this; + this.getInfo(); + this._isNeedPassword = (4 === error) ? true : false; + + // 0 - ok + // 4 - password + // else - error + return error; + }; + CFile.prototype["isNeedPassword"] = function() + { + return this._isNeedPassword; }; CFile.prototype["getInfo"] = function() { diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp index d2a3f2b1d2..a2577cdfce 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile.cpp @@ -149,14 +149,14 @@ static DWORD GetLength(BYTE* x) int main() { -#define XPS_TEST 1 +#define XPS_TEST 0 #define DJVU_TEST 0 -#define PDF_TEST 0 +#define PDF_TEST 1 #if PDF_TEST BYTE* pPdfData = NULL; DWORD nPdfBytesCount; NSFile::CFileBinary oFile; - if (!oFile.ReadAllBytes(NSFile::GetProcessDirectory() + L"/test2.pdf", &pPdfData, nPdfBytesCount)) + if (!oFile.ReadAllBytes(NSFile::GetProcessDirectory() + L"/test.pdf", &pPdfData, nPdfBytesCount)) { RELEASEARRAYOBJECTS(pPdfData); return 1; @@ -181,7 +181,7 @@ int main() } int* info = GetInfo(test); int pages_count = *info; - int test_page = 0; + int test_page = 1; int width = info[test_page * 3 + 1]; int height = info[test_page * 3 + 2]; std::cout << "Page " << test_page << " width " << width << " height " << height << std::endl; diff --git a/PdfReader/PdfReader.cpp b/PdfReader/PdfReader.cpp index b98b7da910..cb7f36c294 100644 --- a/PdfReader/PdfReader.cpp +++ b/PdfReader/PdfReader.cpp @@ -652,7 +652,11 @@ return 0; if (!sLink) continue; std::string link(sLink->getCString(), sLink->getLength()); - size_t find = link.find("http"); + size_t find = link.find("http://"); + if (find == std::string::npos) + find = link.find("https://"); + if (find == std::string::npos) + find = link.find("www."); if (find != std::string::npos) { link.erase(0, find);