Skip to content

Commit

Permalink
Fix/pdf (#2277)
Browse files Browse the repository at this point in the history
* Developint not embedded fonts

* Developing not embedded fonts

* .

* Insert native viewer

* Fix load file

* Fix for emty document/null-width thumbnails panel

* Add navigation method

* Fix test for viewer

* Fix bugs

* Refactoring

* Viewer developing

* Fix bug with page number on resize

* Fix zoom/resize

* Fix minimize

* Support old viewer

* Add licence

* Add licence

* New lines

* Fix crash builder tests
  • Loading branch information
K0R0L authored Oct 15, 2021
1 parent d922928 commit 3dc1369
Show file tree
Hide file tree
Showing 23 changed files with 929 additions and 978 deletions.
6 changes: 6 additions & 0 deletions build/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ module.exports = function(grunt) {
cwd: '../slide/themes',
src: '**/**',
dest: path.join(slide, 'themes')
},
{
expand: true,
cwd: '../pdf/',
src: 'src/engine/*',
dest: path.join(deploy, 'pdf')
}
]
}
Expand Down
9 changes: 9 additions & 0 deletions common/Drawings/Externals.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@ function CFontFileLoader(id)
var _count_decode = Math.min(32, _stream.size);
for (var i = 0; i < _count_decode; ++i)
_data[i] ^= guidOdttf[i % 16];

if (null != oThis.callback)
oThis.callback();
};
xhr.onerror = function()
{
Expand Down Expand Up @@ -594,6 +597,12 @@ CFontFileLoader.prototype.LoadFontAsync = function(basePath, _callback, isEmbed)
return false;
};

CFontFileLoader.prototype["LoadFontAsync"] = CFontFileLoader.prototype.LoadFontAsync;
CFontFileLoader.prototype["GetID"] = function() { return this.Id; };
CFontFileLoader.prototype["GetStatus"] = function() { return this.Status; };
CFontFileLoader.prototype["GetStreamIndex"] = function() { return this.stream_index; };


var FONT_TYPE_ADDITIONAL = 0;
var FONT_TYPE_STANDART = 1;
var FONT_TYPE_EMBEDDED = 2;
Expand Down
30 changes: 27 additions & 3 deletions common/apiBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@
this.Shortcuts = new AscCommon.CShortcuts();
this.initDefaultShortcuts();

this.isUseNativeViewer = true;

return this;
}

Expand Down Expand Up @@ -687,6 +689,21 @@
"lcid" : locale,
"nobase64" : true
};

if (this.isUseNativeViewer)
{
switch (this.documentFormat)
{
case "pdf":
case "xps":
case "djvu":
rData["convertToOrigin"] = true;
break;
default:
break;
}
}

if (versionHistory)
{
rData["serverVersion"] = versionHistory.serverVersion;
Expand Down Expand Up @@ -819,6 +836,10 @@

if (window["AscDesktopEditor"] && window["AscDesktopEditor"]["onDocumentContentReady"])
window["AscDesktopEditor"]["onDocumentContentReady"]();

// теперь на старте нельзя удалить бинарник для подбора - он может пригодиться в nativeViewer
if (!this.disableRemoveFonts)
delete window["g_fonts_selection_bin"];
};
// Save
baseEditorsApi.prototype.processSavedFile = function(url, downloadType, filetype)
Expand Down Expand Up @@ -1298,15 +1319,18 @@
case "ok":
var urls = input["data"];
AscCommon.g_oDocumentUrls.init(urls);
if (null != urls['Editor.bin']) {
var documentUrl = urls['Editor.bin'];
if (t.isUseNativeViewer && !documentUrl)
documentUrl = urls['origin.pdf'] || urls['origin.xps'] || urls['origin.djvu'];
if (null != documentUrl) {
if ('ok' === input["status"] || t.getViewMode()) {
t._onOpenCommand(urls['Editor.bin']);
t._onOpenCommand(documentUrl);
} else {
t.sendEvent("asc_onDocumentUpdateVersion", function () {
if (t.isCoAuthoringEnable) {
t.asc_coAuthoringDisconnect();
}
t._onOpenCommand(urls['Editor.bin']);
t._onOpenCommand(documentUrl);
})
}
} else {
Expand Down
19 changes: 18 additions & 1 deletion common/libfont/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ CFontSelectList.prototype =
_fs.m_wsFontName = "ASCW3";
this.List.push(_fs);

delete window["g_fonts_selection_bin"];
//delete window["g_fonts_selection_bin"];
},

isEnglishChar : function(_code)
Expand Down Expand Up @@ -3204,4 +3204,21 @@ var g_fontApplication = new CApplicationFonts();
window['AscFonts'].LanguagesFontSelectTypes = LanguagesFontSelectTypes;

window['AscFonts'].g_fontApplication = g_fontApplication;

window['AscFonts']['pickFont'] = function(name, style) {
var info = AscFonts.g_fontApplication.GetFontInfo(name, style);
var fontId = info.GetFontID(AscCommon.g_font_loader, style);
return fontId.file;
};
window['AscFonts']['getFontStreams'] = function() {
return AscFonts.g_fonts_streams;
};
window['AscFonts']['getFontStream'] = function(index) {
var s = AscFonts.g_fonts_streams[index];
return {
"data" : s.data,
"size" : s.size
};
};

})(window);
3 changes: 3 additions & 0 deletions configs/word.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@
"word/Drawing/Rulers.js",
"word/Drawing/HtmlPage.js",
"word/Drawing/documentrenderer.js",
"pdf/src/thumbnails.js",
"pdf/src/viewer.js",
"pdf/src/file.js",
"word/document/empty.js",
"word/Math/mathTypes.js",
"word/Math/mathText.js",
Expand Down
234 changes: 198 additions & 36 deletions pdf/src/engine/drawingfile.js

Large diffs are not rendered by default.

Binary file modified pdf/src/engine/drawingfile.js.mem
Binary file not shown.
Binary file modified pdf/src/engine/drawingfile.wasm
Binary file not shown.
278 changes: 220 additions & 58 deletions pdf/src/engine/drawingfile_ie.js

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions pdf/src/file.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
/*
* (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 supportImageDataConstructor = (AscCommon.AscBrowser.isIE && !AscCommon.AscBrowser.isIeEdge) ? false : true;
Expand Down Expand Up @@ -412,7 +444,19 @@ void main() {\n\
file.nativeFile = new window["AscViewer"]["CDrawingFile"]();
if (file.nativeFile["loadFromData"](data))
{
file.nativeFile.onRepaintPages = function(pages) {
file.onRepaintPages && file.onRepaintPages(pages);
};
file.pages = file.nativeFile["getPages"]();

for (var i = 0, len = file.pages.length; i < len; i++)
{
var page = file.pages[i];
page.W = page["W"];
page.H = page["H"];
page.Dpi = page["Dpi"];
}

file.cacheManager = new AscCommon.CCacheManager();
return file;
}
Expand Down
116 changes: 0 additions & 116 deletions pdf/src/pdf/pdf.js

This file was deleted.

Binary file removed pdf/src/pdf/pdf.wasm
Binary file not shown.
74 changes: 65 additions & 9 deletions pdf/src/thumbnails.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
/*
* (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(){

// SKIN
Expand Down Expand Up @@ -31,6 +63,8 @@
};

PageStyle.numberFontHeight = (function(){
if (window["NATIVE_EDITOR_ENJINE"])
return 7;
var testCanvas = document.createElement("canvas");
var w = 100;
var h = 100;
Expand Down Expand Up @@ -288,6 +322,11 @@
{
this._resize(isZoomUpdated);
};
CDocument.prototype.setIsDrawCurrentRect = function(isDrawCurrentRect)
{
PageStyle.isDrawCurrentRect = isDrawCurrentRect;
this.repaint();
};
CDocument.prototype.setEnabled = function(isEnabled)
{
this.isEnabled = isEnabled;
Expand Down Expand Up @@ -320,6 +359,9 @@
this.canvasOverlay.style.pointerEvents = "none";

parent.onmousewheel = this.onMouseWhell.bind(this);
if (parent.addEventListener)
parent.addEventListener("DOMMouseScroll", this.onMouseWhell.bind(this), false);

AscCommon.addMouseEvent(this.canvas, "down", this.onMouseDown.bind(this));
AscCommon.addMouseEvent(this.canvas, "move", this.onMouseMove.bind(this));
AscCommon.addMouseEvent(this.canvas, "up", this.onMouseUp.bind(this));
Expand Down Expand Up @@ -401,7 +443,7 @@
if (!this.isEnabled)
return;

if (!isViewerTask)
if (!isViewerTask && -1 != this.startBlock)
{
// смотрим, какие страницы нужно перерисовать.
// делаем это по одной, так как задачи вьюера важнее
Expand Down Expand Up @@ -471,6 +513,9 @@
var ctx = this.canvas.getContext("2d");
ctx.fillStyle = ThumbnailsStyle.backgroundColor;
ctx.fillRect(0, 0, this.panelWidth, this.panelHeight);

if (-1 == this.startBlock)
return;

ctx.font = PageStyle.font();
ctx.textAlign = "center";
Expand Down Expand Up @@ -499,6 +544,9 @@
{
var element = document.getElementById(this.id);

if (0 === element.offsetWidth)
return;

// размер панели
this.panelWidth = element.offsetWidth;
this.panelHeight = element.offsetHeight;
Expand Down Expand Up @@ -546,7 +594,9 @@
{
// зум "по умолчанию"
this.zoom = this.defaultPageW / pageWidthMax;
this.defaultPageW = 0;

if (0 != this.panelWidth)
this.defaultPageW = 0;
}

// корректировка зумов
Expand Down Expand Up @@ -635,14 +685,17 @@
}
}

for (var i = this.startBlock; i < blocksCount; i++)
if (this.startBlock != -1)
{
block = this.blocks[i];
if (block.top > (this.scrollY + this.panelHeight))
for (var i = this.startBlock; i < blocksCount; i++)
{
// уже невидимый блок!
this.endBlock = i - 1;
break;
block = this.blocks[i];
if (block.top > (this.scrollY + this.panelHeight))
{
// уже невидимый блок!
this.endBlock = i - 1;
break;
}
}
}

Expand Down Expand Up @@ -731,6 +784,9 @@
return null;

var block = (pageNum / this.countPagesInBlock) >> 0;
if (!this.blocks[block])
return null;

var pageInBlock = pageNum - block * this.countPagesInBlock;
return this.blocks[block].pages[pageInBlock];
};
Expand Down Expand Up @@ -841,4 +897,4 @@
prot["setZoom"] = prot.setZoom;
prot["resize"] = prot.resize;
prot["setEnabled"] = prot.setEnabled;
})();
})();
Loading

0 comments on commit 3dc1369

Please sign in to comment.