[mobile] fix bug 57315
This commit is contained in:
parent
fe1e736ae4
commit
98c2b08ec9
|
@ -130,84 +130,104 @@ export class storeTextSettings {
|
||||||
|
|
||||||
loadSprite() {
|
loadSprite() {
|
||||||
function CThumbnailLoader() {
|
function CThumbnailLoader() {
|
||||||
this.supportBinaryFormat = (window['AscDesktopEditor'] && !window['AscDesktopEditor']['isSupportBinaryFontsSprite']) ? false : true;
|
|
||||||
|
|
||||||
this.image = null;
|
this.image = null;
|
||||||
this.binaryFormat = null;
|
this.binaryFormat = null;
|
||||||
this.data = null;
|
this.data = null;
|
||||||
this.width = 0;
|
this.width = 0;
|
||||||
this.height = 0;
|
|
||||||
this.heightOne = 0;
|
this.heightOne = 0;
|
||||||
this.count = 0;
|
this.offsets = null;
|
||||||
|
|
||||||
this.load = function(url, callback) {
|
this.load = function(url, callback) {
|
||||||
if (!callback)
|
if (!callback)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!this.supportBinaryFormat) {
|
var xhr = new XMLHttpRequest();
|
||||||
this.width = thumbs[thumbIdx].width;
|
xhr.open('GET', url + ".bin", true);
|
||||||
this.heightOne = thumbs[thumbIdx].height;
|
xhr.responseType = 'arraybuffer';
|
||||||
|
|
||||||
this.image = new Image();
|
if (xhr.overrideMimeType)
|
||||||
this.image.onload = callback;
|
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||||||
this.image.src = thumbs[thumbIdx].path;
|
else xhr.setRequestHeader('Accept-Charset', 'x-user-defined');
|
||||||
} else {
|
|
||||||
var me = this;
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.open('GET', url + ".bin", true);
|
|
||||||
xhr.responseType = 'arraybuffer';
|
|
||||||
|
|
||||||
if (xhr.overrideMimeType)
|
xhr.onload = e => {
|
||||||
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
// TODO: check errors
|
||||||
else
|
this.binaryFormat = new Uint8Array(e.target.response);
|
||||||
xhr.setRequestHeader('Accept-Charset', 'x-user-defined');
|
callback();
|
||||||
|
};
|
||||||
|
|
||||||
xhr.onload = function() {
|
xhr.send(null);
|
||||||
// TODO: check errors
|
|
||||||
me.binaryFormat = this.response;
|
|
||||||
callback();
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.send(null);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.openBinary = function(arrayBuffer) {
|
this.openBinary = function(arrayBuffer) {
|
||||||
|
|
||||||
//var t1 = performance.now();
|
//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.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.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);
|
const count = (binaryAlpha[8] << 24) | (binaryAlpha[9] << 16) | (binaryAlpha[10] << 8) | (binaryAlpha[11] << 0);
|
||||||
this.height = this.count * this.heightOne;
|
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 binaryIndex = 12;
|
||||||
var binaryLen = binaryAlpha.length;
|
var binaryLen = binaryAlpha.length;
|
||||||
var imagePixels = this.data;
|
|
||||||
var index = 0;
|
var index = 0;
|
||||||
|
|
||||||
var len0 = 0;
|
var len0 = 0;
|
||||||
var tmpValue = 0;
|
var tmpValue = 0;
|
||||||
while (binaryIndex < binaryLen) {
|
|
||||||
tmpValue = binaryAlpha[binaryIndex++];
|
if (!isOffsets) {
|
||||||
if (0 == tmpValue) {
|
var imagePixels = this.data;
|
||||||
len0 = binaryAlpha[binaryIndex++];
|
while (binaryIndex < binaryLen) {
|
||||||
while (len0 > 0) {
|
tmpValue = binaryAlpha[binaryIndex++];
|
||||||
len0--;
|
if (0 == tmpValue) {
|
||||||
imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255;
|
len0 = binaryAlpha[binaryIndex++];
|
||||||
imagePixels[index + 3] = 0; // this value is already 0.
|
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;
|
index += 4;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255 - tmpValue;
|
} else {
|
||||||
imagePixels[index + 3] = tmpValue;
|
var module = this.width * this.heightOne;
|
||||||
index += 4;
|
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();
|
//var t2 = performance.now();
|
||||||
//console.log(t2 - t1);
|
//console.log(t2 - t1);
|
||||||
};
|
};
|
||||||
|
@ -226,21 +246,55 @@ export class storeTextSettings {
|
||||||
ctx = canvas.getContext("2d");
|
ctx = canvas.getContext("2d");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.supportBinaryFormat) {
|
if (!this.data && !this.offsets) {
|
||||||
if (!this.data) {
|
this.openBinary(this.binaryFormat);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
//var t2 = performance.now();
|
||||||
//console.log(t2 - t1);
|
//console.log(t2 - t1);
|
||||||
|
|
||||||
|
@ -251,6 +305,10 @@ export class storeTextSettings {
|
||||||
this.spriteThumbs = new CThumbnailLoader();
|
this.spriteThumbs = new CThumbnailLoader();
|
||||||
this.spriteThumbs.load(this.thumbs[this.thumbIdx].path, () => {
|
this.spriteThumbs.load(this.thumbs[this.thumbIdx].path, () => {
|
||||||
this.spriteCols = Math.floor(this.spriteThumbs.width / (this.thumbs[this.thumbIdx].width)) || 1;
|
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);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,8 +134,6 @@ export class storeTextSettings {
|
||||||
|
|
||||||
loadSprite() {
|
loadSprite() {
|
||||||
function CThumbnailLoader() {
|
function CThumbnailLoader() {
|
||||||
this.supportBinaryFormat = (window['AscDesktopEditor'] && !window['AscDesktopEditor']['isSupportBinaryFontsSprite']) ? false : true;
|
|
||||||
|
|
||||||
this.image = null;
|
this.image = null;
|
||||||
this.binaryFormat = null;
|
this.binaryFormat = null;
|
||||||
this.data = null;
|
this.data = null;
|
||||||
|
@ -143,37 +141,27 @@ export class storeTextSettings {
|
||||||
this.height = 0;
|
this.height = 0;
|
||||||
this.heightOne = 0;
|
this.heightOne = 0;
|
||||||
this.count = 0;
|
this.count = 0;
|
||||||
|
this.offsets = null;
|
||||||
|
|
||||||
this.load = function(url, callback) {
|
this.load = function(url, callback) {
|
||||||
if (!callback)
|
if (!callback)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!this.supportBinaryFormat) {
|
var xhr = new XMLHttpRequest();
|
||||||
this.width = thumbs[thumbIdx].width;
|
xhr.open('GET', url + ".bin", true);
|
||||||
this.heightOne = thumbs[thumbIdx].height;
|
xhr.responseType = 'arraybuffer';
|
||||||
|
|
||||||
this.image = new Image();
|
if (xhr.overrideMimeType)
|
||||||
this.image.onload = callback;
|
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||||||
this.image.src = thumbs[thumbIdx].path;
|
else xhr.setRequestHeader('Accept-Charset', 'x-user-defined');
|
||||||
} else {
|
|
||||||
var me = this;
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.open('GET', url + ".bin", true);
|
|
||||||
xhr.responseType = 'arraybuffer';
|
|
||||||
|
|
||||||
if (xhr.overrideMimeType)
|
xhr.onload = e => {
|
||||||
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
// TODO: check errors
|
||||||
else
|
this.binaryFormat = new Uint8Array(e.target.response);
|
||||||
xhr.setRequestHeader('Accept-Charset', 'x-user-defined');
|
callback();
|
||||||
|
};
|
||||||
|
|
||||||
xhr.onload = function() {
|
xhr.send(null);
|
||||||
// TODO: check errors
|
|
||||||
me.binaryFormat = this.response;
|
|
||||||
callback();
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.send(null);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.openBinary = function(arrayBuffer) {
|
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.count = (binaryAlpha[8] << 24) | (binaryAlpha[9] << 16) | (binaryAlpha[10] << 8) | (binaryAlpha[11] << 0);
|
||||||
this.height = this.count * this.heightOne;
|
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 binaryIndex = 12;
|
||||||
var binaryLen = binaryAlpha.length;
|
var binaryLen = binaryAlpha.length;
|
||||||
var imagePixels = this.data;
|
|
||||||
var index = 0;
|
var index = 0;
|
||||||
|
|
||||||
var len0 = 0;
|
var len0 = 0;
|
||||||
var tmpValue = 0;
|
var tmpValue = 0;
|
||||||
while (binaryIndex < binaryLen) {
|
|
||||||
tmpValue = binaryAlpha[binaryIndex++];
|
if (!isOffsets) {
|
||||||
if (0 == tmpValue) {
|
var imagePixels = this.data;
|
||||||
len0 = binaryAlpha[binaryIndex++];
|
while (binaryIndex < binaryLen) {
|
||||||
while (len0 > 0) {
|
tmpValue = binaryAlpha[binaryIndex++];
|
||||||
len0--;
|
if (0 == tmpValue) {
|
||||||
imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255;
|
len0 = binaryAlpha[binaryIndex++];
|
||||||
imagePixels[index + 3] = 0; // this value is already 0.
|
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;
|
index += 4;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255 - tmpValue;
|
} else {
|
||||||
imagePixels[index + 3] = tmpValue;
|
var module = this.width * this.heightOne;
|
||||||
index += 4;
|
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();
|
//var t2 = performance.now();
|
||||||
//console.log(t2 - t1);
|
//console.log(t2 - t1);
|
||||||
};
|
};
|
||||||
|
@ -230,21 +253,55 @@ export class storeTextSettings {
|
||||||
ctx = canvas.getContext("2d");
|
ctx = canvas.getContext("2d");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.supportBinaryFormat) {
|
if (!this.data && !this.offsets) {
|
||||||
if (!this.data) {
|
this.openBinary(this.binaryFormat);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
//var t2 = performance.now();
|
||||||
//console.log(t2 - t1);
|
//console.log(t2 - t1);
|
||||||
|
|
||||||
|
@ -255,6 +312,10 @@ export class storeTextSettings {
|
||||||
this.spriteThumbs = new CThumbnailLoader();
|
this.spriteThumbs = new CThumbnailLoader();
|
||||||
this.spriteThumbs.load(this.thumbs[this.thumbIdx].path, () => {
|
this.spriteThumbs.load(this.thumbs[this.thumbIdx].path, () => {
|
||||||
this.spriteCols = Math.floor(this.spriteThumbs.width / (this.thumbs[this.thumbIdx].width)) || 1;
|
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);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -134,7 +134,7 @@ export class storeTextSettings {
|
||||||
|
|
||||||
loadSprite() {
|
loadSprite() {
|
||||||
function CThumbnailLoader() {
|
function CThumbnailLoader() {
|
||||||
this.supportBinaryFormat = (window['AscDesktopEditor'] && !window['AscDesktopEditor']['isSupportBinaryFontsSprite']) ? false : true;
|
this.supportBinaryFormat = true;
|
||||||
|
|
||||||
this.image = null;
|
this.image = null;
|
||||||
this.binaryFormat = null;
|
this.binaryFormat = null;
|
||||||
|
@ -143,37 +143,27 @@ export class storeTextSettings {
|
||||||
this.height = 0;
|
this.height = 0;
|
||||||
this.heightOne = 0;
|
this.heightOne = 0;
|
||||||
this.count = 0;
|
this.count = 0;
|
||||||
|
this.offsets = null;
|
||||||
|
|
||||||
this.load = function(url, callback) {
|
this.load = function(url, callback) {
|
||||||
if (!callback)
|
if (!callback)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!this.supportBinaryFormat) {
|
var xhr = new XMLHttpRequest();
|
||||||
this.width = thumbs[thumbIdx].width;
|
xhr.open('GET', url + ".bin", true);
|
||||||
this.heightOne = thumbs[thumbIdx].height;
|
xhr.responseType = 'arraybuffer';
|
||||||
|
|
||||||
this.image = new Image();
|
if (xhr.overrideMimeType)
|
||||||
this.image.onload = callback;
|
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||||||
this.image.src = thumbs[thumbIdx].path;
|
else xhr.setRequestHeader('Accept-Charset', 'x-user-defined');
|
||||||
} else {
|
|
||||||
var me = this;
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.open('GET', url + ".bin", true);
|
|
||||||
xhr.responseType = 'arraybuffer';
|
|
||||||
|
|
||||||
if (xhr.overrideMimeType)
|
xhr.onload = e => {
|
||||||
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
// TODO: check errors
|
||||||
else
|
this.binaryFormat = new Uint8Array(e.target.response);
|
||||||
xhr.setRequestHeader('Accept-Charset', 'x-user-defined');
|
callback();
|
||||||
|
};
|
||||||
|
|
||||||
xhr.onload = function() {
|
xhr.send(null);
|
||||||
// TODO: check errors
|
|
||||||
me.binaryFormat = this.response;
|
|
||||||
callback();
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.send(null);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.openBinary = function(arrayBuffer) {
|
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.count = (binaryAlpha[8] << 24) | (binaryAlpha[9] << 16) | (binaryAlpha[10] << 8) | (binaryAlpha[11] << 0);
|
||||||
this.height = this.count * this.heightOne;
|
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 binaryIndex = 12;
|
||||||
var binaryLen = binaryAlpha.length;
|
var binaryLen = binaryAlpha.length;
|
||||||
var imagePixels = this.data;
|
|
||||||
var index = 0;
|
var index = 0;
|
||||||
|
|
||||||
var len0 = 0;
|
var len0 = 0;
|
||||||
var tmpValue = 0;
|
var tmpValue = 0;
|
||||||
while (binaryIndex < binaryLen) {
|
|
||||||
tmpValue = binaryAlpha[binaryIndex++];
|
if (!isOffsets) {
|
||||||
if (0 == tmpValue) {
|
var imagePixels = this.data;
|
||||||
len0 = binaryAlpha[binaryIndex++];
|
while (binaryIndex < binaryLen) {
|
||||||
while (len0 > 0) {
|
tmpValue = binaryAlpha[binaryIndex++];
|
||||||
len0--;
|
if (0 == tmpValue) {
|
||||||
imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255;
|
len0 = binaryAlpha[binaryIndex++];
|
||||||
imagePixels[index + 3] = 0; // this value is already 0.
|
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;
|
index += 4;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
imagePixels[index] = imagePixels[index + 1] = imagePixels[index + 2] = 255 - tmpValue;
|
} else {
|
||||||
imagePixels[index + 3] = tmpValue;
|
var module = this.width * this.heightOne;
|
||||||
index += 4;
|
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();
|
//var t2 = performance.now();
|
||||||
//console.log(t2 - t1);
|
//console.log(t2 - t1);
|
||||||
};
|
};
|
||||||
|
@ -230,21 +255,55 @@ export class storeTextSettings {
|
||||||
ctx = canvas.getContext("2d");
|
ctx = canvas.getContext("2d");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.supportBinaryFormat) {
|
if (!this.data && !this.offsets) {
|
||||||
if (!this.data) {
|
this.openBinary(this.binaryFormat);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
//var t2 = performance.now();
|
||||||
//console.log(t2 - t1);
|
//console.log(t2 - t1);
|
||||||
|
|
||||||
|
@ -255,6 +314,10 @@ export class storeTextSettings {
|
||||||
this.spriteThumbs = new CThumbnailLoader();
|
this.spriteThumbs = new CThumbnailLoader();
|
||||||
this.spriteThumbs.load(this.thumbs[this.thumbIdx].path, () => {
|
this.spriteThumbs.load(this.thumbs[this.thumbIdx].path, () => {
|
||||||
this.spriteCols = Math.floor(this.spriteThumbs.width / (this.thumbs[this.thumbIdx].width)) || 1;
|
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);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue