From 98c2b08ec94b1d515506c65ee6378c1974ab77f7 Mon Sep 17 00:00:00 2001 From: Maxim Kadushkin Date: Fri, 27 May 2022 20:36:24 +0300 Subject: [PATCH] [mobile] fix bug 57315 --- .../mobile/src/store/textSettings.js | 174 ++++++++++++------ .../mobile/src/store/textSettings.js | 165 +++++++++++------ .../mobile/src/store/textSettings.js | 165 ++++++++++++----- 3 files changed, 343 insertions(+), 161 deletions(-) diff --git a/apps/documenteditor/mobile/src/store/textSettings.js b/apps/documenteditor/mobile/src/store/textSettings.js index 156f40702..fd6df3bf0 100644 --- a/apps/documenteditor/mobile/src/store/textSettings.js +++ b/apps/documenteditor/mobile/src/store/textSettings.js @@ -130,84 +130,104 @@ export class storeTextSettings { loadSprite() { function CThumbnailLoader() { - this.supportBinaryFormat = (window['AscDesktopEditor'] && !window['AscDesktopEditor']['isSupportBinaryFontsSprite']) ? false : true; - this.image = null; this.binaryFormat = null; this.data = null; this.width = 0; - this.height = 0; this.heightOne = 0; - this.count = 0; + this.offsets = null; this.load = function(url, callback) { if (!callback) return; - if (!this.supportBinaryFormat) { - this.width = thumbs[thumbIdx].width; - this.heightOne = thumbs[thumbIdx].height; + var xhr = new XMLHttpRequest(); + xhr.open('GET', url + ".bin", true); + xhr.responseType = 'arraybuffer'; - this.image = new Image(); - this.image.onload = callback; - this.image.src = thumbs[thumbIdx].path; - } else { - var me = this; - var xhr = new XMLHttpRequest(); - xhr.open('GET', url + ".bin", true); - xhr.responseType = 'arraybuffer'; + if (xhr.overrideMimeType) + xhr.overrideMimeType('text/plain; charset=x-user-defined'); + else xhr.setRequestHeader('Accept-Charset', 'x-user-defined'); - if (xhr.overrideMimeType) - xhr.overrideMimeType('text/plain; charset=x-user-defined'); - else - xhr.setRequestHeader('Accept-Charset', 'x-user-defined'); + xhr.onload = e => { + // TODO: check errors + this.binaryFormat = new Uint8Array(e.target.response); + callback(); + }; - xhr.onload = function() { - // TODO: check errors - me.binaryFormat = this.response; - callback(); - }; - - xhr.send(null); - } + xhr.send(null); }; this.openBinary = function(arrayBuffer) { - //var t1 = performance.now(); - var 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); - this.count = (binaryAlpha[8] << 24) | (binaryAlpha[9] << 16) | (binaryAlpha[10] << 8) | (binaryAlpha[11] << 0); - this.height = this.count * this.heightOne; + 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 * this.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 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); }; @@ -226,21 +246,55 @@ export class storeTextSettings { ctx = canvas.getContext("2d"); } - if (this.supportBinaryFormat) { - if (!this.data) { - 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)); - ctx.putImageData(dataTmp, 0, 0); - } else { - ctx.clearRect(0, 0, this.width, this.heightOne); - ctx.drawImage(this.image, 0, -this.heightOne * index); + if (!this.data && !this.offsets) { + this.openBinary(this.binaryFormat); } + var dataTmp = ctx.createImageData(this.width, this.heightOne); + var sizeImage = 4 * this.width * this.heightOne; + + 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(); //console.log(t2 - t1); @@ -251,6 +305,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/presentationeditor/mobile/src/store/textSettings.js b/apps/presentationeditor/mobile/src/store/textSettings.js index ccf03a07b..5f1b1857b 100644 --- a/apps/presentationeditor/mobile/src/store/textSettings.js +++ b/apps/presentationeditor/mobile/src/store/textSettings.js @@ -134,8 +134,6 @@ export class storeTextSettings { loadSprite() { function CThumbnailLoader() { - this.supportBinaryFormat = (window['AscDesktopEditor'] && !window['AscDesktopEditor']['isSupportBinaryFontsSprite']) ? false : true; - this.image = null; this.binaryFormat = null; this.data = null; @@ -143,37 +141,27 @@ export class storeTextSettings { this.height = 0; this.heightOne = 0; this.count = 0; + this.offsets = null; this.load = function(url, callback) { if (!callback) return; - if (!this.supportBinaryFormat) { - this.width = thumbs[thumbIdx].width; - this.heightOne = thumbs[thumbIdx].height; + var xhr = new XMLHttpRequest(); + xhr.open('GET', url + ".bin", true); + xhr.responseType = 'arraybuffer'; - this.image = new Image(); - this.image.onload = callback; - this.image.src = thumbs[thumbIdx].path; - } else { - var me = this; - var xhr = new XMLHttpRequest(); - xhr.open('GET', url + ".bin", true); - xhr.responseType = 'arraybuffer'; + if (xhr.overrideMimeType) + xhr.overrideMimeType('text/plain; charset=x-user-defined'); + else xhr.setRequestHeader('Accept-Charset', 'x-user-defined'); - if (xhr.overrideMimeType) - xhr.overrideMimeType('text/plain; charset=x-user-defined'); - else - xhr.setRequestHeader('Accept-Charset', 'x-user-defined'); + xhr.onload = e => { + // TODO: check errors + this.binaryFormat = new Uint8Array(e.target.response); + callback(); + }; - xhr.onload = function() { - // TODO: check errors - me.binaryFormat = this.response; - callback(); - }; - - xhr.send(null); - } + xhr.send(null); }; this.openBinary = function(arrayBuffer) { @@ -186,32 +174,67 @@ export class storeTextSettings { 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); + const MAX_MEMORY_SIZE = 100000000; + const memorySize = 4 * this.width * this.height; + const isOffsets = memorySize > MAX_MEMORY_SIZE; + + 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); }; @@ -230,21 +253,55 @@ export class storeTextSettings { ctx = canvas.getContext("2d"); } - if (this.supportBinaryFormat) { - if (!this.data) { - 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)); - ctx.putImageData(dataTmp, 0, 0); - } else { - ctx.clearRect(0, 0, this.width, this.heightOne); - ctx.drawImage(this.image, 0, -this.heightOne * index); + if (!this.data && !this.offsets) { + this.openBinary(this.binaryFormat); } + var dataTmp = ctx.createImageData(this.width, this.heightOne); + var sizeImage = 4 * this.width * this.heightOne; + + 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(); //console.log(t2 - t1); @@ -255,6 +312,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/mobile/src/store/textSettings.js b/apps/spreadsheeteditor/mobile/src/store/textSettings.js index 25d7c1d46..8df7c95fd 100644 --- a/apps/spreadsheeteditor/mobile/src/store/textSettings.js +++ b/apps/spreadsheeteditor/mobile/src/store/textSettings.js @@ -134,7 +134,7 @@ export class storeTextSettings { loadSprite() { function CThumbnailLoader() { - this.supportBinaryFormat = (window['AscDesktopEditor'] && !window['AscDesktopEditor']['isSupportBinaryFontsSprite']) ? false : true; + this.supportBinaryFormat = true; this.image = null; this.binaryFormat = null; @@ -143,37 +143,27 @@ export class storeTextSettings { this.height = 0; this.heightOne = 0; this.count = 0; + this.offsets = null; this.load = function(url, callback) { if (!callback) return; - if (!this.supportBinaryFormat) { - this.width = thumbs[thumbIdx].width; - this.heightOne = thumbs[thumbIdx].height; + var xhr = new XMLHttpRequest(); + xhr.open('GET', url + ".bin", true); + xhr.responseType = 'arraybuffer'; - this.image = new Image(); - this.image.onload = callback; - this.image.src = thumbs[thumbIdx].path; - } else { - var me = this; - var xhr = new XMLHttpRequest(); - xhr.open('GET', url + ".bin", true); - xhr.responseType = 'arraybuffer'; + if (xhr.overrideMimeType) + xhr.overrideMimeType('text/plain; charset=x-user-defined'); + else xhr.setRequestHeader('Accept-Charset', 'x-user-defined'); - if (xhr.overrideMimeType) - xhr.overrideMimeType('text/plain; charset=x-user-defined'); - else - xhr.setRequestHeader('Accept-Charset', 'x-user-defined'); + xhr.onload = e => { + // TODO: check errors + this.binaryFormat = new Uint8Array(e.target.response); + callback(); + }; - xhr.onload = function() { - // TODO: check errors - me.binaryFormat = this.response; - callback(); - }; - - xhr.send(null); - } + xhr.send(null); }; this.openBinary = function(arrayBuffer) { @@ -186,32 +176,67 @@ export class storeTextSettings { 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); + const MAX_MEMORY_SIZE = 100000000; + const memorySize = 4 * this.width * this.height; + const isOffsets = memorySize > MAX_MEMORY_SIZE; + + 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); }; @@ -230,21 +255,55 @@ export class storeTextSettings { ctx = canvas.getContext("2d"); } - if (this.supportBinaryFormat) { - if (!this.data) { - 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)); - ctx.putImageData(dataTmp, 0, 0); - } else { - ctx.clearRect(0, 0, this.width, this.heightOne); - ctx.drawImage(this.image, 0, -this.heightOne * index); + if (!this.data && !this.offsets) { + this.openBinary(this.binaryFormat); } + var dataTmp = ctx.createImageData(this.width, this.heightOne); + var sizeImage = 4 * this.width * this.heightOne; + + 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(); //console.log(t2 - t1); @@ -255,6 +314,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); + } }); }