diff --git a/apps/common/main/lib/component/ComboBoxFonts.js b/apps/common/main/lib/component/ComboBoxFonts.js index 31226d005..fe0788b38 100644 --- a/apps/common/main/lib/component/ComboBoxFonts.js +++ b/apps/common/main/lib/component/ComboBoxFonts.js @@ -90,6 +90,7 @@ define([ function CThumbnailLoader() { this.supportBinaryFormat = !(Common.Controllers.Desktop.isActive() && !Common.Controllers.Desktop.isFeatureAvailable('isSupportBinaryFontsSprite')); + // наш формат - альфамаска с сжатием типа rle для полностью прозрачных пикселов this.image = null; this.binaryFormat = null; @@ -98,6 +99,7 @@ define([ this.height = 0; this.heightOne = 0; this.count = 0; + this.offsets = null; this.load = function(url, callback) { if (!callback) @@ -123,7 +125,7 @@ define([ xhr.onload = function() { // TODO: check errors - me.binaryFormat = this.response; + me.binaryFormat = new Uint8Array(this.response); callback(); }; @@ -134,38 +136,74 @@ define([ this.openBinary = function(arrayBuffer) { //var t1 = performance.now(); - var binaryAlpha = new Uint8Array(arrayBuffer); + var binaryAlpha = this.binaryFormat; this.width = (binaryAlpha[0] << 24) | (binaryAlpha[1] << 16) | (binaryAlpha[2] << 8) | (binaryAlpha[3] << 0); this.heightOne = (binaryAlpha[4] << 24) | (binaryAlpha[5] << 16) | (binaryAlpha[6] << 8) | (binaryAlpha[7] << 0); this.count = (binaryAlpha[8] << 24) | (binaryAlpha[9] << 16) | (binaryAlpha[10] << 8) | (binaryAlpha[11] << 0); this.height = this.count * this.heightOne; - this.data = new Uint8ClampedArray(4 * this.width * this.height); + var MAX_MEMORY_SIZE = 50000000; + var memorySize = 4 * this.width * this.height; + var isOffsets = (memorySize > MAX_MEMORY_SIZE) ? true : false; + + if (!isOffsets) + this.data = new Uint8ClampedArray(memorySize); + else + this.offsets = new Array(this.count); var binaryIndex = 12; var binaryLen = binaryAlpha.length; - var imagePixels = this.data; var index = 0; var len0 = 0; var tmpValue = 0; - while (binaryIndex < binaryLen) { - tmpValue = binaryAlpha[binaryIndex++]; - if (0 == tmpValue) { - len0 = binaryAlpha[binaryIndex++]; - while (len0 > 0) { - len0--; - imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255; - imagePixels[index + 3] = 0; // this value is already 0. + + if (!isOffsets) { + var imagePixels = this.data; + while (binaryIndex < binaryLen) { + tmpValue = binaryAlpha[binaryIndex++]; + if (0 == tmpValue) { + len0 = binaryAlpha[binaryIndex++]; + while (len0 > 0) { + len0--; + imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255; + imagePixels[index + 3] = 0; // this value is already 0. + index += 4; + } + } else { + imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255 - tmpValue; + imagePixels[index + 3] = tmpValue; index += 4; } - } else { - imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255 - tmpValue; - imagePixels[index + 3] = tmpValue; - index += 4; + } + } else { + var module = this.width * this.heightOne; + var moduleCur = module - 1; + while (binaryIndex < binaryLen) { + tmpValue = binaryAlpha[binaryIndex++]; + if (0 == tmpValue) { + len0 = binaryAlpha[binaryIndex++]; + while (len0 > 0) { + len0--; + moduleCur++; + if (moduleCur === module) { + this.offsets[index++] = { pos : binaryIndex, len : len0 + 1 }; + moduleCur = 0; + } + } + } else { + moduleCur++; + if (moduleCur === module) { + this.offsets[index++] = { pos : binaryIndex - 1, len : -1 }; + moduleCur = 0; + } + } } } + if (!this.offsets) + delete this.binaryFormat; + //var t2 = performance.now(); //console.log(t2 - t1); }; @@ -185,14 +223,53 @@ define([ } if (this.supportBinaryFormat) { - if (!this.data) { + if (!this.data && !this.offsets) { this.openBinary(this.binaryFormat); - delete this.binaryFormat; } var dataTmp = ctx.createImageData(this.width, this.heightOne); var sizeImage = 4 * this.width * this.heightOne; - dataTmp.data.set(new Uint8ClampedArray(this.data.buffer, index * sizeImage, sizeImage)); + + if (!this.offsets) { + dataTmp.data.set(new Uint8ClampedArray(this.data.buffer, index * sizeImage, sizeImage)); + } else { + var binaryAlpha = this.binaryFormat; + var binaryIndex = this.offsets[index].pos; + var alphaChannel = 0; + var pixelsCount = this.width * this.heightOne; + var tmpValue = 0, len0 = 0; + var imagePixels = dataTmp.data; + if (-1 != this.offsets[index].len) { + /* + // this values is already 0. + for (var i = 0; i < this.offsets[index].len; i++) { + pixels[alphaChannel] = 0; + alphaChannel += 4; + } + */ + alphaChannel += 4 * this.offsets[index].len; + } + while (pixelsCount > 0) { + tmpValue = binaryAlpha[binaryIndex++]; + if (0 == tmpValue) { + len0 = binaryAlpha[binaryIndex++]; + if (len0 > pixelsCount) + len0 = pixelsCount; + while (len0 > 0) { + len0--; + imagePixels[alphaChannel] = imagePixels[alphaChannel + 1] = imagePixels[alphaChannel + 2] = 255; + imagePixels[alphaChannel + 3] = 0; // this value is already 0. + alphaChannel += 4; + pixelsCount--; + } + } else { + imagePixels[alphaChannel] = imagePixels[alphaChannel + 1] = imagePixels[alphaChannel + 2] = 255 - tmpValue; + imagePixels[alphaChannel + 3] = tmpValue; + alphaChannel += 4; + pixelsCount--; + } + } + } ctx.putImageData(dataTmp, 0, 0); } else { ctx.clearRect(0, 0, this.width, this.heightOne); diff --git a/apps/common/mobile/utils/CThumbnailLoader.js b/apps/common/mobile/utils/CThumbnailLoader.js index b3fb10e27..87fe5eba9 100644 --- a/apps/common/mobile/utils/CThumbnailLoader.js +++ b/apps/common/mobile/utils/CThumbnailLoader.js @@ -1,10 +1,12 @@ class CThumbnailLoader { constructor() { + this.image = null; this.binaryFormat = null; this.data = null; this.width = 0; this.heightOne = 0; + this.offsets = null; } load(url, callback) { @@ -21,53 +23,88 @@ class CThumbnailLoader { xhr.onload = e => { // TODO: check errors - this.binaryFormat = e.target.response; + this.binaryFormat = new Uint8Array(e.target.response); callback(); }; xhr.send(null); } - _openBinary(arrayBuffer) { + openBinary(arrayBuffer) { //var t1 = performance.now(); - const binaryAlpha = new Uint8Array(arrayBuffer); + const binaryAlpha = this.binaryFormat; this.width = (binaryAlpha[0] << 24) | (binaryAlpha[1] << 16) | (binaryAlpha[2] << 8) | (binaryAlpha[3] << 0); this.heightOne = (binaryAlpha[4] << 24) | (binaryAlpha[5] << 16) | (binaryAlpha[6] << 8) | (binaryAlpha[7] << 0); const count = (binaryAlpha[8] << 24) | (binaryAlpha[9] << 16) | (binaryAlpha[10] << 8) | (binaryAlpha[11] << 0); const height = count * this.heightOne; - this.data = new Uint8ClampedArray(4 * this.width * height); + const MAX_MEMORY_SIZE = 100000000; + const memorySize = 4 * this.width * height; + const isOffsets = memorySize > MAX_MEMORY_SIZE; + + if (!isOffsets) + this.data = new Uint8ClampedArray(memorySize); + else this.offsets = new Array(count); var binaryIndex = 12; - var imagePixels = this.data; + var binaryLen = binaryAlpha.length; var index = 0; var len0 = 0; var tmpValue = 0; - while (binaryIndex < binaryAlpha.length) { - tmpValue = binaryAlpha[binaryIndex++]; - if (0 == tmpValue) { - len0 = binaryAlpha[binaryIndex++]; - while (len0 > 0) { - len0--; - imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255; - imagePixels[index + 3] = 0; // this value is already 0. + + if (!isOffsets) { + var imagePixels = this.data; + while (binaryIndex < binaryLen) { + tmpValue = binaryAlpha[binaryIndex++]; + if (0 == tmpValue) { + len0 = binaryAlpha[binaryIndex++]; + while (len0 > 0) { + len0--; + imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255; + imagePixels[index + 3] = 0; // this value is already 0. + index += 4; + } + } else { + imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255 - tmpValue; + imagePixels[index + 3] = tmpValue; index += 4; } - } else { - imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255 - tmpValue; - imagePixels[index + 3] = tmpValue; - index += 4; + } + } else { + var module = this.width * this.heightOne; + var moduleCur = module - 1; + while (binaryIndex < binaryLen) { + tmpValue = binaryAlpha[binaryIndex++]; + if (0 == tmpValue) { + len0 = binaryAlpha[binaryIndex++]; + while (len0 > 0) { + len0--; + moduleCur++; + if (moduleCur === module) { + this.offsets[index++] = { pos : binaryIndex, len : len0 + 1 }; + moduleCur = 0; + } + } + } else { + moduleCur++; + if (moduleCur === module) { + this.offsets[index++] = { pos : binaryIndex - 1, len : -1 }; + moduleCur = 0; + } + } } } + if ( !this.offsets ) + delete this.binaryFormat; + //var t2 = performance.now(); //console.log(t2 - t1); }; getImage = function(index, canvas, ctx) { - //var t1 = performance.now(); if (!canvas) { canvas = document.createElement("canvas"); canvas.width = this.width; @@ -78,14 +115,53 @@ class CThumbnailLoader { ctx = canvas.getContext("2d"); } - if (!this.data) { - this._openBinary(this.binaryFormat); - delete this.binaryFormat; + if (!this.data && !this.offsets) { + this.openBinary(this.binaryFormat); } let dataTmp = ctx.createImageData(this.width, this.heightOne); const sizeImage = 4 * this.width * this.heightOne; - dataTmp.data.set(new Uint8ClampedArray(this.data.buffer, index * sizeImage, sizeImage)); + + if (!this.offsets) { + dataTmp.data.set(new Uint8ClampedArray(this.data.buffer, index * sizeImage, sizeImage)); + } else { + const binaryAlpha = this.binaryFormat; + var binaryIndex = this.offsets[index].pos; + var alphaChannel = 0; + var pixelsCount = this.width * this.heightOne; + var tmpValue = 0, len0 = 0; + let imagePixels = dataTmp.data; + if (-1 != this.offsets[index].len) { + /* + // this values is already 0. + for (var i = 0; i < this.offsets[index].len; i++) { + pixels[alphaChannel] = 0; + alphaChannel += 4; + } + */ + alphaChannel += 4 * this.offsets[index].len; + } + while (pixelsCount > 0) { + tmpValue = binaryAlpha[binaryIndex++]; + if (0 == tmpValue) { + len0 = binaryAlpha[binaryIndex++]; + if (len0 > pixelsCount) + len0 = pixelsCount; + while (len0 > 0) { + len0--; + imagePixels[alphaChannel] = imagePixels[alphaChannel + 1] = imagePixels[alphaChannel + 2] = 255; + imagePixels[alphaChannel + 3] = 0; // this value is already 0. + alphaChannel += 4; + pixelsCount--; + } + } else { + imagePixels[alphaChannel] = imagePixels[alphaChannel + 1] = imagePixels[alphaChannel + 2] = 255 - tmpValue; + imagePixels[alphaChannel + 3] = tmpValue; + alphaChannel += 4; + pixelsCount--; + } + } + } ctx.putImageData(dataTmp, 0, 0); //var t2 = performance.now(); diff --git a/apps/documenteditor/mobile/src/store/appOptions.js b/apps/documenteditor/mobile/src/store/appOptions.js index 794e650bd..2c6e25271 100644 --- a/apps/documenteditor/mobile/src/store/appOptions.js +++ b/apps/documenteditor/mobile/src/store/appOptions.js @@ -86,6 +86,7 @@ export class storeAppOptions { && (!!(config.customization.goback.url) || config.customization.goback.requestClose && this.canRequestClose); this.canBack = this.canBackToFolder === true; this.canPlugins = false; + this.canFeatureForms = !!Common.EditorApi.get().asc_isSupportFeature("forms"); AscCommon.UserInfoParser.setParser(true); AscCommon.UserInfoParser.setCurrentName(this.user.fullname); diff --git a/apps/documenteditor/mobile/src/store/textSettings.js b/apps/documenteditor/mobile/src/store/textSettings.js index 7a1d7f1ef..ad9a0972d 100644 --- a/apps/documenteditor/mobile/src/store/textSettings.js +++ b/apps/documenteditor/mobile/src/store/textSettings.js @@ -133,6 +133,10 @@ export class storeTextSettings { this.spriteThumbs = new CThumbnailLoader(); this.spriteThumbs.load(this.thumbs[this.thumbIdx].path, () => { this.spriteCols = Math.floor(this.spriteThumbs.width / (this.thumbs[this.thumbIdx].width)) || 1; + + if (!this.spriteThumbs.data && !this.spriteThumbs.offsets) { + this.spriteThumbs.openBinary(this.spriteThumbs.binaryFormat); + } }); } diff --git a/apps/documenteditor/mobile/src/view/settings/Download.jsx b/apps/documenteditor/mobile/src/view/settings/Download.jsx index 4e822fd2e..f2e82d717 100644 --- a/apps/documenteditor/mobile/src/view/settings/Download.jsx +++ b/apps/documenteditor/mobile/src/view/settings/Download.jsx @@ -8,6 +8,7 @@ const Download = props => { const _t = t("Settings", { returnObjects: true }); const storeDocumentInfo = props.storeDocumentInfo; const dataDoc = storeDocumentInfo.dataDoc; + const canFeatureForms = props.storeAppOptions.canFeatureForms; return ( @@ -17,7 +18,7 @@ const Download = props => { props.onSaveFormat(Asc.c_oAscFileType.DOCX)}> - {dataDoc.fileType === 'docxf' || dataDoc.fileType === 'docx' ? [ + {canFeatureForms && (dataDoc.fileType === 'docxf' || dataDoc.fileType === 'docx') ? [ props.onSaveFormat(Asc.c_oAscFileType.DOCXF)}> , @@ -58,4 +59,4 @@ const Download = props => { ) } -export default inject('storeDocumentInfo')(observer(Download)); \ No newline at end of file +export default inject('storeDocumentInfo', 'storeAppOptions')(observer(Download)); \ No newline at end of file diff --git a/apps/presentationeditor/mobile/src/store/textSettings.js b/apps/presentationeditor/mobile/src/store/textSettings.js index ed7e25ddd..c5ba1ba49 100644 --- a/apps/presentationeditor/mobile/src/store/textSettings.js +++ b/apps/presentationeditor/mobile/src/store/textSettings.js @@ -137,6 +137,10 @@ export class storeTextSettings { this.spriteThumbs = new CThumbnailLoader(); this.spriteThumbs.load(this.thumbs[this.thumbIdx].path, () => { this.spriteCols = Math.floor(this.spriteThumbs.width / (this.thumbs[this.thumbIdx].width)) || 1; + + if (!this.spriteThumbs.data && !this.spriteThumbs.offsets) { + this.spriteThumbs.openBinary(this.spriteThumbs.binaryFormat); + } }); } diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index f132fa985..3149428d4 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -1427,7 +1427,7 @@ define([ this.api.asc_registerCallback('asc_onDocumentModifiedChanged', _.bind(this.onDocumentModifiedChanged, this)); var printController = app.getController('Print'); - printController && this.api && printController.setApi(this.api); + printController && this.api && printController.setApi(this.api).setMode(this.appOptions); } else if (this.appOptions.isEditOle) this.api.asc_registerCallback('asc_onSendThemeColors', _.bind(this.onSendThemeColors, this)); diff --git a/apps/spreadsheeteditor/main/app/controller/Print.js b/apps/spreadsheeteditor/main/app/controller/Print.js index 4bbaaedf4..d2a21bd82 100644 --- a/apps/spreadsheeteditor/main/app/controller/Print.js +++ b/apps/spreadsheeteditor/main/app/controller/Print.js @@ -119,12 +119,19 @@ define([ this.printSettings.$previewBox.on(eventname, _.bind(this.onPreviewWheel, this)); }, + setMode: function (mode) { + this.mode = mode; + this.printSettings && this.printSettings.setMode(mode); + }, + setApi: function(o) { this.api = o; this.api.asc_registerCallback('asc_onSheetsChanged', _.bind(this.updateSheetsInfo, this)); this.api.asc_registerCallback('asc_onPrintPreviewSheetChanged', _.bind(this.onApiChangePreviewSheet, this)); this.api.asc_registerCallback('asc_onPrintPreviewPageChanged', _.bind(this.onApiChangePreviewPage, this)); this.api.asc_registerCallback('asc_onPrintPreviewSheetDataChanged', _.bind(this.onApiPreviewSheetDataChanged, this)); + + return this; }, updateSheetsInfo: function() { diff --git a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js index e36fb6a14..45132c47c 100644 --- a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js +++ b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js @@ -2247,7 +2247,7 @@ SSE.Views.FileMenuPanels.RecentFiles = Common.UI.BaseView.extend({ '', '', '', - '', + '', //'', '', '