mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
pdf fix js implementation
This commit is contained in:
@ -75,7 +75,7 @@ libUnicodeConverter_src_path = "../../../../UnicodeConverter/"
|
|||||||
input_unicodeconverter_sources = ["UnicodeConverter.cpp"]
|
input_unicodeconverter_sources = ["UnicodeConverter.cpp"]
|
||||||
|
|
||||||
libIcu_src_path = "../../../../Common/3dParty/icu/icu/source/common/"
|
libIcu_src_path = "../../../../Common/3dParty/icu/icu/source/common/"
|
||||||
input_icu_sources = ["ucnv.c", "ustr_wcs.cpp", "ucnv_err.c", "ucnv_bld.cpp", "ustrtrns.cpp", "ucnv_cb.c", "udata.cpp", "ucnv_io.cpp", "uhash.c", "udatamem.c", "cmemory.c", "ustring.cpp", "umutex.cpp", "putil.cpp", "ustr_cnv.cpp", "ucnvmbcs.cpp", "ucnvlat1.c", "ucnv_u16.c", "ucnv_u8.c", "ucnv_u32.c", "ucnv_u7.c", "ucln_cmn.cpp", "ucnv2022.cpp", "ucnv_lmb.c", "ucnvhz.c", "ucnvscsu.c", "ucnvisci.c", "ucnvbocu.cpp", "ucnv_ct.c", "ucnv_cnv.c", "stringpiece.cpp", "charstr.cpp", "umapfile.c", "ucmndata.c", "ucnv_ext.cpp", "uobject.cpp", "umath.c"]
|
input_icu_sources = ["ucnv.c", "ustr_wcs.cpp", "ucnv_err.c", "ucnv_bld.cpp", "ustrtrns.cpp", "ucnv_cb.c", "udata.cpp", "ucnv_io.cpp", "uhash.c", "udatamem.c", "cmemory.c", "ustring.cpp", "umutex.cpp", "putil.cpp", "ustr_cnv.cpp", "ucnvmbcs.cpp", "ucnvlat1.c", "ucnv_u16.c", "ucnv_u8.c", "ucnv_u32.c", "ucnv_u7.c", "ucln_cmn.cpp", "ucnv2022.cpp", "ucnv_lmb.c", "ucnvhz.c", "ucnvscsu.c", "ucnvisci.c", "ucnvbocu.cpp", "ucnv_ct.c", "ucnv_cnv.c", "stringpiece.cpp", "charstr.cpp", "umapfile.c", "ucmndata.c", "ucnv_ext.cpp", "uobject.cpp", "umath.c", "ubidi_props.c", "uchar.c", "uinvchar.c", "usprep.cpp", "unistr.cpp", "uniset_props.cpp", "loadednormalizer2impl.cpp", "filterednormalizer2.cpp", "utrie2.cpp", "normalizer2.cpp", "normalizer2impl.cpp", "utrie.cpp", "ucase.cpp", "uniset.cpp", "ruleiter.cpp", "parsepos.cpp", "util.cpp", "uprops.cpp", "uvector.cpp", "unames.cpp", "propname.cpp", "utrie2_builder.cpp", "unifunct.cpp", "bmpset.cpp", "unisetspan.cpp", "unifilt.cpp", "patternprops.cpp", "utf_impl.c", "ustrcase.cpp", "cstring.c", "bytestrie.cpp"]
|
||||||
|
|
||||||
libXps_src_path = "../../../../XpsFile/XpsLib/"
|
libXps_src_path = "../../../../XpsFile/XpsLib/"
|
||||||
input_xps_sources = ["Document.cpp", "XpsPage.cpp", "StaticResources.cpp", "Utils.cpp", "WString.cpp", "ContextState.cpp"]
|
input_xps_sources = ["Document.cpp", "XpsPage.cpp", "StaticResources.cpp", "Utils.cpp", "WString.cpp", "ContextState.cpp"]
|
||||||
@ -167,32 +167,32 @@ if base.host_platform() == "windows":
|
|||||||
libs += ("temp/" + os.path.basename(item) + ".o ")
|
libs += ("temp/" + os.path.basename(item) + ".o ")
|
||||||
|
|
||||||
for item in input_icu_sources:
|
for item in input_icu_sources:
|
||||||
windows_bat.append("call emcc -o temp/" + item + ".o -c " + arguments + libIcu_src_path + item)
|
windows_bat.append("call emcc -o temp/" + os.path.splitext(item)[0] + ".o -c " + arguments + libIcu_src_path + item)
|
||||||
libs += ("temp/" + item + ".o ")
|
libs += ("temp/" + os.path.splitext(item)[0] + ".o ")
|
||||||
|
|
||||||
for item in input_xps_sources:
|
for item in input_xps_sources:
|
||||||
windows_bat.append("call emcc -o temp/" + item + ".o -c " + arguments + libXps_src_path + item)
|
windows_bat.append("call emcc -o temp/" + os.path.splitext(item)[0] + ".o -c " + arguments + libXps_src_path + item)
|
||||||
libs += ("temp/" + item + ".o ")
|
libs += ("temp/" + os.path.splitext(item)[0] + ".o ")
|
||||||
|
|
||||||
for item in input_djvu_sources:
|
for item in input_djvu_sources:
|
||||||
windows_bat.append("call emcc -o temp/" + item + ".o -c " + arguments + libDjVu_src_path + item)
|
windows_bat.append("call emcc -o temp/" + os.path.splitext(item)[0] + ".o -c " + arguments + libDjVu_src_path + item)
|
||||||
libs += ("temp/" + item + ".o ")
|
libs += ("temp/" + os.path.splitext(item)[0] + ".o ")
|
||||||
|
|
||||||
for item in input_minizip_sources:
|
for item in input_minizip_sources:
|
||||||
windows_bat.append("call emcc -o temp/" + item + ".o -c " + arguments + libMinizip_src_path + item)
|
windows_bat.append("call emcc -o temp/" + os.path.splitext(item)[0] + ".o -c " + arguments + libMinizip_src_path + item)
|
||||||
libs += ("temp/" + item + ".o ")
|
libs += ("temp/" + os.path.splitext(item)[0] + ".o ")
|
||||||
|
|
||||||
for item in input_zlib_sources:
|
for item in input_zlib_sources:
|
||||||
windows_bat.append("call emcc -o temp/" + item + ".o -c " + arguments + libZlib_src_path + item)
|
windows_bat.append("call emcc -o temp/" + os.path.splitext(item)[0] + ".o -c " + arguments + libZlib_src_path + item)
|
||||||
libs += ("temp/" + item + ".o ")
|
libs += ("temp/" + os.path.splitext(item)[0] + ".o ")
|
||||||
|
|
||||||
for item in input_cryptopp_sources:
|
for item in input_cryptopp_sources:
|
||||||
windows_bat.append("call emcc -o temp/" + item + ".o -c " + arguments + libCryptoPP_src_path + item)
|
windows_bat.append("call emcc -o temp/" + os.path.splitext(item)[0] + ".o -c " + arguments + libCryptoPP_src_path + item)
|
||||||
libs += ("temp/" + item + ".o ")
|
libs += ("temp/" + os.path.splitext(item)[0] + ".o ")
|
||||||
|
|
||||||
for item in input_pdfreader_sources:
|
for item in input_pdfreader_sources:
|
||||||
windows_bat.append("call emcc -o temp/" + item + ".o -c " + arguments + libPdfReader_src_path + item)
|
windows_bat.append("call emcc -o temp/" + os.path.splitext(item)[0] + ".o -c " + arguments + libPdfReader_src_path + item)
|
||||||
libs += ("temp/" + item + ".o ")
|
libs += ("temp/" + os.path.splitext(item)[0] + ".o ")
|
||||||
|
|
||||||
arguments += "-s EXPORTED_FUNCTIONS=\"["
|
arguments += "-s EXPORTED_FUNCTIONS=\"["
|
||||||
for item in exported_functions:
|
for item in exported_functions:
|
||||||
@ -203,7 +203,7 @@ if base.host_platform() == "windows":
|
|||||||
for item in sources:
|
for item in sources:
|
||||||
arguments += (item + " ")
|
arguments += (item + " ")
|
||||||
|
|
||||||
windows_bat.append("call emcc -o xps_djvu.js " + arguments + libs)
|
windows_bat.append("call emcc -o xps_djvu_pdf.js " + arguments + libs)
|
||||||
else:
|
else:
|
||||||
windows_bat.append("#!/bin/bash")
|
windows_bat.append("#!/bin/bash")
|
||||||
windows_bat.append("source ./emsdk/emsdk_env.sh")
|
windows_bat.append("source ./emsdk/emsdk_env.sh")
|
||||||
@ -250,14 +250,14 @@ else:
|
|||||||
for item in sources:
|
for item in sources:
|
||||||
arguments += (item + " ")
|
arguments += (item + " ")
|
||||||
|
|
||||||
windows_bat.append("emcc -o xps_djvu.js " + arguments + libs)
|
windows_bat.append("emcc -o xps_djvu_pdf.js " + arguments + libs)
|
||||||
base.replaceInFile("../../../../Common/3dParty/icu/icu/source/common/udata.cpp", "\n{\n UDataMemory tData;", "\n{\n#ifdef BUILDING_WASM_MODULE\nreturn NULL;\n#endif\n UDataMemory tData;")
|
base.replaceInFile("../../../../Common/3dParty/icu/icu/source/common/udata.cpp", "\n{\n UDataMemory tData;", "\n{\n#ifdef BUILDING_WASM_MODULE\nreturn NULL;\n#endif\n UDataMemory tData;")
|
||||||
base.run_as_bat(windows_bat)
|
base.run_as_bat(windows_bat)
|
||||||
base.replaceInFile("../../../../Common/3dParty/icu/icu/source/common/udata.cpp", "\n{\n#ifdef BUILDING_WASM_MODULE\nreturn NULL;\n#endif\n UDataMemory tData;", "\n{\n UDataMemory tData;")
|
base.replaceInFile("../../../../Common/3dParty/icu/icu/source/common/udata.cpp", "\n{\n#ifdef BUILDING_WASM_MODULE\nreturn NULL;\n#endif\n UDataMemory tData;", "\n{\n UDataMemory tData;")
|
||||||
|
|
||||||
# finalize
|
# finalize
|
||||||
base.replaceInFile("./xps_djvu.js", "function getBinaryPromise(){", "function getBinaryPromise2(){")
|
base.replaceInFile("./xps_djvu_pdf.js", "function getBinaryPromise(){", "function getBinaryPromise2(){")
|
||||||
graphics_js_content = base.readFile("./xps_djvu.js")
|
graphics_js_content = base.readFile("./xps_djvu_pdf.js")
|
||||||
engine_base_js_content = base.readFile("./wasm/js/xps_base.js")
|
engine_base_js_content = base.readFile("./wasm/js/xps_base.js")
|
||||||
string_utf8_content = base.readFile("./../../../../Common/js/string_utf8.js")
|
string_utf8_content = base.readFile("./../../../../Common/js/string_utf8.js")
|
||||||
engine_js_content = engine_base_js_content.replace("//module", graphics_js_content)
|
engine_js_content = engine_base_js_content.replace("//module", graphics_js_content)
|
||||||
@ -265,14 +265,18 @@ engine_js_content = engine_js_content.replace("//string_utf8", string_utf8_conte
|
|||||||
engine_base_js_content = base.readFile("./../../../../DjVuFile/wasm/djvu_base.js")
|
engine_base_js_content = base.readFile("./../../../../DjVuFile/wasm/djvu_base.js")
|
||||||
djvu_js_content = engine_base_js_content.replace("//module", graphics_js_content)
|
djvu_js_content = engine_base_js_content.replace("//module", graphics_js_content)
|
||||||
djvu_js_content = djvu_js_content.replace("//string_utf8", string_utf8_content)
|
djvu_js_content = djvu_js_content.replace("//string_utf8", string_utf8_content)
|
||||||
|
engine_base_js_content = base.readFile("./wasm/js/pdf_base.js")
|
||||||
|
pdf_js_content = engine_base_js_content.replace("//module", graphics_js_content)
|
||||||
|
pdf_js_content = pdf_js_content.replace("//string_utf8", string_utf8_content)
|
||||||
|
|
||||||
# write new version
|
# write new version
|
||||||
base.writeFile("./deploy/xps.js", engine_js_content)
|
base.writeFile("./deploy/xps.js", engine_js_content)
|
||||||
base.writeFile("./deploy/djvu.js", djvu_js_content)
|
base.writeFile("./deploy/djvu.js", djvu_js_content)
|
||||||
base.copy_file("./xps_djvu.wasm", "./deploy/xps_djvu.wasm")
|
base.writeFile("./deploy/pdf.js", pdf_js_content)
|
||||||
|
base.copy_file("./xps_djvu_pdf.wasm", "./deploy/xps_djvu_pdf.wasm")
|
||||||
|
|
||||||
base.delete_file("xps_djvu.js")
|
base.delete_file("xps_djvu_pdf.js")
|
||||||
base.delete_file("xps_djvu.wasm")
|
base.delete_file("xps_djvu_pdf.wasm")
|
||||||
base.delete_dir("./temp")
|
base.delete_dir("./temp")
|
||||||
base.delete_dir("./xml")
|
base.delete_dir("./xml")
|
||||||
# base.delete_file("raster.o")
|
# base.delete_file("raster.o")
|
||||||
150
DesktopEditor/graphics/pro/js/wasm/js/pdf_base.js
Normal file
150
DesktopEditor/graphics/pro/js/wasm/js/pdf_base.js
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
/*
|
||||||
|
* (c) Copyright Ascensio System SIA 2010-2019
|
||||||
|
*
|
||||||
|
* This program is a free software product. You can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Affero General Public License (AGPL)
|
||||||
|
* version 3 as published by the Free Software Foundation. In accordance with
|
||||||
|
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
|
||||||
|
* that Ascensio System SIA expressly excludes the warranty of non-infringement
|
||||||
|
* of any third-party rights.
|
||||||
|
*
|
||||||
|
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
|
||||||
|
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
||||||
|
*
|
||||||
|
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
||||||
|
* street, Riga, Latvia, EU, LV-1050.
|
||||||
|
*
|
||||||
|
* The interactive user interfaces in modified source and object code versions
|
||||||
|
* of the Program must display Appropriate Legal Notices, as required under
|
||||||
|
* Section 5 of the GNU AGPL version 3.
|
||||||
|
*
|
||||||
|
* Pursuant to Section 7(b) of the License you must retain the original Product
|
||||||
|
* logo when distributing the program. Pursuant to Section 7(e) we decline to
|
||||||
|
* grant you any rights under trademark law for use of our trademarks.
|
||||||
|
*
|
||||||
|
* All the Product's GUI elements, including illustrations and icon sets, as
|
||||||
|
* well as technical writing content are licensed under the terms of the
|
||||||
|
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
|
||||||
|
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function(window, undefined) {
|
||||||
|
|
||||||
|
var printErr = undefined;
|
||||||
|
var FS = undefined;
|
||||||
|
var print = undefined;
|
||||||
|
|
||||||
|
var getBinaryPromise = null;
|
||||||
|
if (window["AscDesktopEditor"] && document.currentScript && 0 == document.currentScript.src.indexOf("file:///"))
|
||||||
|
{
|
||||||
|
// fetch not support file:/// scheme
|
||||||
|
window.fetch = undefined;
|
||||||
|
|
||||||
|
getBinaryPromise = function() {
|
||||||
|
|
||||||
|
var wasmPath = "ascdesktop://fonts/" + wasmBinaryFile.substr(8);
|
||||||
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open('GET', wasmPath, true);
|
||||||
|
xhr.responseType = 'arraybuffer';
|
||||||
|
|
||||||
|
if (xhr.overrideMimeType)
|
||||||
|
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||||||
|
else
|
||||||
|
xhr.setRequestHeader('Accept-Charset', 'x-user-defined');
|
||||||
|
|
||||||
|
xhr.onload = function () {
|
||||||
|
if (this.status == 200) {
|
||||||
|
resolve(new Uint8Array(this.response));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.send(null);
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
getBinaryPromise = function() {
|
||||||
|
return getBinaryPromise2();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//string_utf8
|
||||||
|
|
||||||
|
//module
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param config
|
||||||
|
* @constructor
|
||||||
|
* @extends {AscViewer.IFile}
|
||||||
|
*/
|
||||||
|
function CFile()
|
||||||
|
{
|
||||||
|
AscViewer.IFile.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
CFile.prototype = Object.create(AscViewer.IFile.prototype);
|
||||||
|
CFile.prototype.constructor = CFile;
|
||||||
|
|
||||||
|
CFile.prototype.loadFromData = function(arrayBuffer)
|
||||||
|
{
|
||||||
|
var data = new Uint8Array(arrayBuffer);
|
||||||
|
var _stream = Module["_malloc"](data.length);
|
||||||
|
Module["HEAP8"].set(data, _stream);
|
||||||
|
this.nativeFile = Module["_PDF_Load"](_stream, data.length);
|
||||||
|
this.stream = _stream;
|
||||||
|
return this.getInfo();
|
||||||
|
};
|
||||||
|
CFile.prototype.getInfo = function()
|
||||||
|
{
|
||||||
|
if (!this.nativeFile)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var _info = Module["_XPS_GetInfo"](this.nativeFile);
|
||||||
|
if (!_info)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var _pages = Module["HEAP32"][_info >> 2];
|
||||||
|
var _buffer = new Int32Array(Module["HEAP8"].buffer, _info, 1 + 3 * _pages);
|
||||||
|
|
||||||
|
var _cur = 1;
|
||||||
|
for (var i = 0; i < _pages; i++)
|
||||||
|
{
|
||||||
|
this.pages.push({ W : _buffer[_cur++], H : _buffer[_cur++], Dpi : _buffer[_cur++] });
|
||||||
|
}
|
||||||
|
|
||||||
|
this.free(_info);
|
||||||
|
return this.pages.length > 0;
|
||||||
|
};
|
||||||
|
CFile.prototype.getPagePixmap = function(pageIndex, width, height)
|
||||||
|
{
|
||||||
|
return Module["_XPS_GetPixmap"](this.nativeFile, pageIndex, width, height);
|
||||||
|
};
|
||||||
|
|
||||||
|
CFile.prototype.close = function()
|
||||||
|
{
|
||||||
|
Module["_XPS_Close"](this.nativeFile);
|
||||||
|
this.nativeFile = 0;
|
||||||
|
this.pages = [];
|
||||||
|
if (this.stream > 0)
|
||||||
|
Module["_free"](this.stream);
|
||||||
|
this.stream = -1;
|
||||||
|
};
|
||||||
|
CFile.prototype.memory = function()
|
||||||
|
{
|
||||||
|
return Module["HEAP8"];
|
||||||
|
};
|
||||||
|
CFile.prototype.free = function(pointer)
|
||||||
|
{
|
||||||
|
Module["_XPS_Delete"](pointer);
|
||||||
|
};
|
||||||
|
|
||||||
|
window["AscViewer"].PdfFile = CFile;
|
||||||
|
|
||||||
|
})(window, undefined);
|
||||||
@ -6,9 +6,9 @@
|
|||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=IE8">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=IE8">
|
||||||
<script src="./code.js"></script>
|
<script src="./code.js"></script>
|
||||||
<script src="./file.js"></script>
|
<script src="./file.js"></script>
|
||||||
<script src="./xps_djvu/djvu.js"></script>
|
<script src="./djvu.js"></script>
|
||||||
<script src="./pdf/pdf.js"></script>
|
<script src="./pdf.js"></script>
|
||||||
<script src="./xps_djvu/xps.js"></script>
|
<script src="./xps.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body style="width:100%;height:100%;margin:0;padding:0;overflow-x:scroll;overflow-y:scroll;">
|
<body style="width:100%;height:100%;margin:0;padding:0;overflow-x:scroll;overflow-y:scroll;">
|
||||||
<div id="pos" style="position:absolute;margin:0;padding:0;left:0px;top:0px;width:0px;height:0px;"></div>
|
<div id="pos" style="position:absolute;margin:0;padding:0;left:0px;top:0px;width:0px;height:0px;"></div>
|
||||||
|
|||||||
@ -9,19 +9,20 @@ base.configure_common_apps()
|
|||||||
if base.is_dir("./deploy"):
|
if base.is_dir("./deploy"):
|
||||||
base.delete_dir("./deploy")
|
base.delete_dir("./deploy")
|
||||||
base.create_dir("./deploy")
|
base.create_dir("./deploy")
|
||||||
base.create_dir("./deploy/xps_djvu")
|
|
||||||
|
|
||||||
# command
|
# command
|
||||||
base.cmd_in_dir("./../../DesktopEditor/graphics/pro/js", "python", ["xps_djvu_make.py"])
|
base.cmd_in_dir("./../../DesktopEditor/graphics/pro/js", "python", ["make.py"])
|
||||||
|
|
||||||
# finalize
|
# finalize
|
||||||
if base.is_exist("./../../DesktopEditor/graphics/pro/js/deploy/xps_djvu.wasm"):
|
if base.is_exist("./../../DesktopEditor/graphics/pro/js/deploy/xps_djvu_pdf.wasm"):
|
||||||
base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/xps.js", "./deploy/xps_djvu/xps.js")
|
base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/xps.js", "./deploy/xps.js")
|
||||||
base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/djvu.js", "./deploy/xps_djvu/djvu.js")
|
base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/djvu.js", "./deploy/djvu.js")
|
||||||
base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/xps_djvu.wasm", "./deploy/xps_djvu/xps_djvu.wasm")
|
base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/pdf.js", "./deploy/pdf.js")
|
||||||
|
base.copy_file("./../../DesktopEditor/graphics/pro/js/deploy/xps_djvu_pdf.wasm", "./deploy/xps_djvu_pdf.wasm")
|
||||||
else:
|
else:
|
||||||
print("xps_djvu_make.py error")
|
print("make.py error")
|
||||||
base.copy_dir("./all_files_test/xps_djvu", "./deploy/xps_djvu")
|
base.copy_dir("./all_files_test/xps_djvu", "./deploy")
|
||||||
|
base.copy_dir("./all_files_test/pdf", "./deploy")
|
||||||
|
|
||||||
# write new version
|
# write new version
|
||||||
base.copy_file("./all_files_test/index.html", "./deploy/index.html")
|
base.copy_file("./all_files_test/index.html", "./deploy/index.html")
|
||||||
|
|||||||
Reference in New Issue
Block a user