Skip to content

Commit

Permalink
Fix bug 58594
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Privezenov committed Aug 19, 2022
1 parent f47333f commit 2a5eda3
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 55 deletions.
51 changes: 43 additions & 8 deletions common/Charts/DrawingObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -2170,32 +2170,32 @@ 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;
drawingObject.graphicObject.setDrawingBase(drawingObject);
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;
Expand All @@ -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()
{
Expand Down
2 changes: 2 additions & 0 deletions common/Drawings/Format/ChartFormat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 18 additions & 1 deletion common/Drawings/Format/DrawingContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions common/Drawings/Format/Format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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 = [];
Expand Down
2 changes: 2 additions & 0 deletions common/Drawings/Format/GraphicObjectBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,8 @@
};
CGraphicObjectBase.prototype.getAllRasterImages = function(mapUrl){
};
CGraphicObjectBase.prototype.getImageFromBulletsMap = function(oImages) {};
CGraphicObjectBase.prototype.getDocContentsWithImageBullets = function (arrContents) {};
CGraphicObjectBase.prototype.getAllSlicerViews = function(aSlicerView) {

};
Expand Down
14 changes: 14 additions & 0 deletions common/Drawings/Format/GroupShape.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
65 changes: 43 additions & 22 deletions common/Drawings/Format/Shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -6101,7 +6122,7 @@ CShape.prototype.getAllRasterImages = function(images)
}
else
{
getBulletImages(oContent, images);
oContent.getBulletImages(images);
}
var fCallback = function(oRun)
{
Expand Down
32 changes: 8 additions & 24 deletions common/GlobalLoaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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++)
{
Expand All @@ -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);
Expand All @@ -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---------------------------------------------------
Expand Down

0 comments on commit 2a5eda3

Please sign in to comment.