diff --git a/common/Charts/DrawingObjects.js b/common/Charts/DrawingObjects.js index a5589825a0..33f16ff05d 100644 --- a/common/Charts/DrawingObjects.js +++ b/common/Charts/DrawingObjects.js @@ -2151,7 +2151,7 @@ CSparklineView.prototype.setMinMaxValAx = function(minVal, maxVal, oSparklineGro _this.init = function(currentSheet) { - var api = window["Asc"]["editor"]; + const api = window["Asc"]["editor"]; worksheet = currentSheet; drawingCtx = currentSheet.drawingGraphicCtx; @@ -2170,12 +2170,11 @@ CSparklineView.prototype.setMinMaxValAx = function(minVal, maxVal, oSparklineGro aImagesSync = []; - var i; aObjects = currentSheet.model.Drawings; - for (i = 0; currentSheet.model.Drawings && (i < currentSheet.model.Drawings.length); i++) + for (let i = 0; currentSheet.model.Drawings && (i < currentSheet.model.Drawings.length); i++) { aObjects[i] = _this.cloneDrawingObject(aObjects[i]); - var drawingObject = aObjects[i]; + const drawingObject = aObjects[i]; // Check drawing area drawingObject.drawingArea = _this.drawingArea; drawingObject.worksheet = currentSheet; @@ -2183,19 +2182,20 @@ CSparklineView.prototype.setMinMaxValAx = function(minVal, maxVal, oSparklineGro drawingObject.graphicObject.setDrawingObjects(_this); drawingObject.graphicObject.getAllRasterImages(aImagesSync); } + aImagesSync = _this.checkImageBullets(currentSheet, aImagesSync); - for(i = 0; i < aImagesSync.length; ++i) + for(let i = 0; i < aImagesSync.length; ++i) { - var localUrl = aImagesSync[i]; + const localUrl = aImagesSync[i]; if(api.DocInfo && api.DocInfo.get_OfflineApp()) { - AscCommon.g_oDocumentUrls.addImageUrl(localUrl, "/sdkjs/cell/document/media/" + localUrl); + AscCommon.g_oDocumentUrls.addImageUrl(localUrl, api.documentUrl + "media/" + localUrl); } aImagesSync[i] = AscCommon.getFullImageSrc2(localUrl); } if(aImagesSync.length > 0) { - var old_val = api.ImageLoader.bIsAsyncLoadDocumentImages; + const old_val = api.ImageLoader.bIsAsyncLoadDocumentImages; api.ImageLoader.bIsAsyncLoadDocumentImages = true; api.ImageLoader.LoadDocumentImages(aImagesSync); api.ImageLoader.bIsAsyncLoadDocumentImages = old_val; @@ -2204,6 +2204,41 @@ CSparklineView.prototype.setMinMaxValAx = function(minVal, maxVal, oSparklineGro worksheet.model.Drawings = aObjects; }; + _this.checkImageBullets = function (currentSheet, arrImages) { + const aObjects = currentSheet.model.Drawings; + const arrContentsWithImageBullet = []; + const oBulletImages = {}; + const arrBulletImagesAsync = []; + + for (let i = 0; aObjects && (i < aObjects.length); i += 1) { + const drawingObject = aObjects[i]; + drawingObject.graphicObject.getDocContentsWithImageBullets(arrContentsWithImageBullet); + drawingObject.graphicObject.getImageFromBulletsMap(oBulletImages); + } + + for (let localUrl in oBulletImages) { + if(api.DocInfo && api.DocInfo.get_OfflineApp()) { + AscCommon.g_oDocumentUrls.addImageUrl(localUrl, api.documentUrl + "media/" + localUrl); + } + const fullUrl = AscCommon.getFullImageSrc2(localUrl); + arrBulletImagesAsync.push(fullUrl); + } + + api.ImageLoader.LoadImagesWithCallback(arrBulletImagesAsync, function () { + for (let i = 0; i < arrContentsWithImageBullet.length; i += 1) { + const oContent = arrContentsWithImageBullet[i]; + oContent.Recalculate(); + _this.showDrawingObjects(); + } + }); + + const arrImagesWithoutImageBullets = arrImages.filter(function (sImageId) { + return !oBulletImages[sImageId]; + }); + + return arrImagesWithoutImageBullets; + } + _this.getSelectedDrawingsRange = function() { diff --git a/common/Drawings/Format/ChartFormat.js b/common/Drawings/Format/ChartFormat.js index bbda7a775a..144a59fc09 100644 --- a/common/Drawings/Format/ChartFormat.js +++ b/common/Drawings/Format/ChartFormat.js @@ -2210,6 +2210,8 @@ oResultSpPr.setLn(oLn); return oResultSpPr; }; + CBaseChartObject.prototype.getDocContentsWithImageBullets = function (arrContents) {}; + CBaseChartObject.prototype.getImageFromBulletsMap = function(oImages) {}; CBaseChartObject.prototype.getTxPrFormStyleEntry = function(oStyleEntry, aColors, nIdx) { var oFontRef = oStyleEntry.fontRef; var oParaPr = new AscCommonWord.CParaPr(); diff --git a/common/Drawings/Format/DrawingContent.js b/common/Drawings/Format/DrawingContent.js index 0edf08b1d5..28a08423fa 100644 --- a/common/Drawings/Format/DrawingContent.js +++ b/common/Drawings/Format/DrawingContent.js @@ -71,7 +71,24 @@ }, 0); return maxFontSizeInParagraph > pAcc ? maxFontSizeInParagraph : pAcc; }, 0); - } + }; + + CDrawingDocContent.prototype.getBulletImages = function (arrImages) { + var aParagraphs = this.Content; + var sImageId; + for(var nPar = 0; nPar < aParagraphs.length; ++nPar) + { + var oPr = aParagraphs[nPar].Pr; + if(oPr.Bullet) + { + sImageId = oPr.Bullet.getImageBulletURL(); + if(sImageId) + { + arrImages.push(sImageId); + } + } + } + }; CDrawingDocContent.prototype.GetFieldByType = function (sType) { var sType_ = sType.toLowerCase(); diff --git a/common/Drawings/Format/Format.js b/common/Drawings/Format/Format.js index e3b03be3f0..cc624a065a 100644 --- a/common/Drawings/Format/Format.js +++ b/common/Drawings/Format/Format.js @@ -177,6 +177,8 @@ History.CanAddChanges() && History.Add(new CChangesDrawingsObject(this, AscDFH.historyitem_CommonChartFormat_SetParent, this.parent, oParent)); this.parent = oParent; }; + CBaseFormatObject.prototype.getImageFromBulletsMap = function(oImages) {}; + CBaseFormatObject.prototype.getDocContentsWithImageBullets = function (arrContents) {}; CBaseFormatObject.prototype.setParentToChild = function (oChild) { if (oChild && oChild.setParent) { oChild.setParent(this); @@ -11991,6 +11993,8 @@ FmtScheme.prototype.addBgFillToStyleLst = function (pr) { this.bgFillStyleLst.push(pr); }; + FmtScheme.prototype.getImageFromBulletsMap = function(oImages) {}; + FmtScheme.prototype.getDocContentsWithImageBullets = function (arrContents) {}; FmtScheme.prototype.getAllRasterImages = function(aImages) { for(let nIdx = 0; nIdx < this.fillStyleLst.length; ++nIdx) { let oUnifill = this.fillStyleLst[nIdx]; @@ -12385,6 +12389,8 @@ this.themeElements.fmtScheme.getAllRasterImages(aImages); } }; + CTheme.prototype.getImageFromBulletsMap = function(oImages) {}; + CTheme.prototype.getDocContentsWithImageBullets = function (arrContents) {}; CTheme.prototype.Reassign_ImageUrls = function(images_rename) { if(this.themeElements && this.themeElements.fmtScheme) { let aImages = []; diff --git a/common/Drawings/Format/GraphicObjectBase.js b/common/Drawings/Format/GraphicObjectBase.js index f1ea6c33ae..9db8825108 100644 --- a/common/Drawings/Format/GraphicObjectBase.js +++ b/common/Drawings/Format/GraphicObjectBase.js @@ -1190,6 +1190,8 @@ }; CGraphicObjectBase.prototype.getAllRasterImages = function(mapUrl){ }; + CGraphicObjectBase.prototype.getImageFromBulletsMap = function(oImages) {}; + CGraphicObjectBase.prototype.getDocContentsWithImageBullets = function (arrContents) {}; CGraphicObjectBase.prototype.getAllSlicerViews = function(aSlicerView) { }; diff --git a/common/Drawings/Format/GroupShape.js b/common/Drawings/Format/GroupShape.js index 61903c1174..6c92b687ed 100644 --- a/common/Drawings/Format/GroupShape.js +++ b/common/Drawings/Format/GroupShape.js @@ -129,6 +129,20 @@ AscFormat.InitClass(CGroupShape, AscFormat.CGraphicObjectBase, AscDFH.historyite this.spTree[i].documentGetAllFontNames(allFonts); } }; + CGroupShape.prototype.getImageFromBulletsMap = function(oImages) { + for(var i = 0; i < this.spTree.length; ++i) + { + if(this.spTree[i].getImageFromBulletsMap) + this.spTree[i].getImageFromBulletsMap(oImages); + } + }; + CGroupShape.prototype.getDocContentsWithImageBullets = function (arrContents) { + for(var i = 0; i < this.spTree.length; ++i) + { + if(this.spTree[i].getDocContentsWithImageBullets) + this.spTree[i].getDocContentsWithImageBullets(arrContents); + } + }; CGroupShape.prototype.handleAllContents = function(fCallback) { for(var i = 0; i < this.spTree.length; ++i) diff --git a/common/Drawings/Format/Shape.js b/common/Drawings/Format/Shape.js index 7f0801a39b..969ed5c561 100644 --- a/common/Drawings/Format/Shape.js +++ b/common/Drawings/Format/Shape.js @@ -990,26 +990,6 @@ function SetXfrmFromMetrics(oDrawing, metrics) } }; - function getBulletImages(oContent, aImages) { - if(!oContent) { - return; - } - var aParagraphs = oContent.Content; - var sImageId; - for(var nPar = 0; nPar < aParagraphs.length; ++nPar) - { - var oPr = aParagraphs[nPar].Pr; - if(oPr.Bullet) - { - sImageId = oPr.Bullet.getImageBulletURL(); - if(sImageId) - { - aImages.push(sImageId); - } - } - } - } - function CSignatureLine(){ this.id = null; this.signer = null; @@ -1828,7 +1808,10 @@ CShape.prototype.getAllImages = function (images) { if (this.spPr && this.spPr.Fill && this.spPr.Fill.fill instanceof AscFormat.CBlipFill && typeof this.spPr.Fill.fill.RasterImageId === "string") { images[AscCommon.getFullImageSrc2(this.spPr.Fill.fill.RasterImageId)] = true; } - getBulletImages(this.getDocContent && this.getDocContent(), images); + const oContent = this.getDocContent && this.getDocContent(); + if (oContent) { + oContent.getBulletImages(images); + } }; CShape.prototype.getAllFonts = function (fonts) { @@ -6072,6 +6055,44 @@ CShape.prototype.getParagraphTextPr = function () { return null; }; +CShape.prototype.getImageFromBulletsMap = function (oImages) { + const oContent = this.getDocContent(); + if(!oContent) { + return; + } + const aParagraphs = oContent.Content; + for(let nPar = 0; nPar < aParagraphs.length; ++nPar) { + var oPr = aParagraphs[nPar].Pr; + if(oPr.Bullet) { + const sImageId = oPr.Bullet.getImageBulletURL(); + if(sImageId) { + oImages[sImageId] = true; + } + } + } +}; + +CShape.prototype.getDocContentsWithImageBullets = function (arrContents) { + const oContent = this.getDocContent(); + if(!oContent) { + return; + } + const aParagraphs = oContent.Content; + for(let nPar = 0; nPar < aParagraphs.length; ++nPar) + { + var oPr = aParagraphs[nPar].Pr; + if(oPr.Bullet) + { + const sImageId = oPr.Bullet.getImageBulletURL(); + if(sImageId) + { + arrContents.push(oContent); + break; + } + } + } +} + CShape.prototype.getAllRasterImages = function(images) { if(this.spPr && this.spPr.Fill && this.spPr.Fill.fill && typeof (this.spPr.Fill.fill.RasterImageId) === "string" && this.spPr.Fill.fill.RasterImageId.length > 0) @@ -6101,7 +6122,7 @@ CShape.prototype.getAllRasterImages = function(images) } else { - getBulletImages(oContent, images); + oContent.getBulletImages(images); } var fCallback = function(oRun) { diff --git a/common/GlobalLoaders.js b/common/GlobalLoaders.js index 2958365b20..af3c1d824a 100644 --- a/common/GlobalLoaders.js +++ b/common/GlobalLoaders.js @@ -457,11 +457,6 @@ this.bIsLoadDocumentImagesNoByOrder = true; this.nNoByOrderCounter = 0; - this.loadImageCallBackCounter = 0; - this.loadImageCallBackCounterMax = 0; - this.loadImageCallBack = null; - this.loadImageCallBackArgs = null; - this.isBlockchainSupport = false; var oThis = this; @@ -732,10 +727,8 @@ return; } - this.loadImageCallBackCounter = 0; - this.loadImageCallBackCounterMax = arrAsync.length; - this.loadImageCallBack = loadImageCallBack; - this.loadImageCallBackArgs = loadImageCallBackArgs; + let asyncImageCounter = arrAsync.length; + const callback = loadImageCallBack.bind(this.Api, loadImageCallBackArgs); for (i = 0; i < arrAsync.length; i++) { @@ -748,19 +741,19 @@ oImage.Image.onload = function () { this.parentImage.Status = ImageLoadStatus.Complete; - oThis.loadImageCallBackCounter++; + asyncImageCounter--; - if (oThis.loadImageCallBackCounter == oThis.loadImageCallBackCounterMax) - oThis.LoadImagesWithCallbackEnd(); + if (asyncImageCounter === 0) + callback(); }; oImage.Image.onerror = function () { this.parentImage.Image = null; this.parentImage.Status = ImageLoadStatus.Complete; - oThis.loadImageCallBackCounter++; + asyncImageCounter--; - if (oThis.loadImageCallBackCounter == oThis.loadImageCallBackCounterMax) - oThis.LoadImagesWithCallbackEnd(); + if (asyncImageCounter === 0) + callback(); }; AscCommon.backoffOnErrorImg(oImage.Image, function(img) { oThis.loadImageByUrl(img, img.src); @@ -769,15 +762,6 @@ this.loadImageByUrl(oImage.Image, oImage.src, isDisableCrypto); } }; - - this.LoadImagesWithCallbackEnd = function() - { - this.loadImageCallBack.call(this.Api, this.loadImageCallBackArgs); - this.loadImageCallBack = null; - this.loadImageCallBackArgs = null; - this.loadImageCallBackCounterMax = 0; - this.loadImageCallBackCounter = 0; - }; } //---------------------------------------------------------export---------------------------------------------------