Skip to content

Commit

Permalink
Feature/image bullet (#2498)
Browse files Browse the repository at this point in the history
* test push

* refactor: replace part of code in readUniFill and writeUniFill methods readBlipFill and writeBlipFill

* reset commit: thoughts about image bullet

* feat: calculate images for presentation image bullet

* feat: add require methods for BuBlip

* fix: add changes in write logic of Blip

* refactor: BuBlip class

* fix(pe): add calculate FontSlot for blip bullet in Measure method

* refactor(pe): set braces with new line

* fix: try to repair unit tests

* fix: add new adding unit

* feat: add test upload methods for image bullets in api

* fix: get font by first symbol and method copy

* fix: add export for type BULLET_TYPE_BULLET_BLIP

* fix: compare method in CBuBlip class

* fix: add return for cases, when image not available

* fix: add Write_ToBinary and Read_FromBinary for new fields

* feat: add plug for change image bullet settings and method for get rasterImageId from bullet

* refactor: delete unusual for image bullet in presentation

* feat: add images for collaborative mode

* [imageBullet] fix image loading on coauthoring

* fix: recalculate image bullet drawing

* fix: add BuBlip isEqual method

* fix: load images to server from url blipFill

* fix: indents in image bullets

* fix: koef for image size of image bullet

* fix: check load images from url for errors

* refactor: delete unusual console.log

* docs: comment mock method

* refactor: delete unusual font pickers

* [imageBullet] fix loading images in spreadsheets, fix copy/paste

Co-authored-by: Vladimir Privezenov <[email protected]>
  • Loading branch information
SergeyLuzyanin and Vladimir Privezenov authored Jan 20, 2022
1 parent f3f28ad commit d973d4c
Show file tree
Hide file tree
Showing 14 changed files with 692 additions and 306 deletions.
16 changes: 15 additions & 1 deletion common/Drawings/CommonController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11551,8 +11551,21 @@ function CalcLiterByLength(aAlphaBet, nLength)
return numberingType;
}

function fFillImageBullet(bullet, url) {
var buBlip = new AscFormat.CBuBlip();
var blip = CreateBlipFillUniFillFromUrl(url);
buBlip.setBlip(blip);
bullet.bulletType = new AscFormat.CBulletType();
bullet.bulletType.type = AscFormat.BULLET_TYPE_BULLET_BLIP;
bullet.bulletType.setBlip(buBlip);
}


function fFillBullet(NumInfo, bullet) {
if (NumInfo.Blip) {
fFillImageBullet(bullet, NumInfo.Blip.url);
return;
}
if(NumInfo.SubType < 0)
{
bullet.bulletType = new AscFormat.CBulletType();
Expand Down Expand Up @@ -11653,7 +11666,7 @@ function CalcLiterByLength(aAlphaBet, nLength)
}
}
function fGetPresentationBulletByNumInfo(NumInfo){
if(!AscFormat.isRealNumber(NumInfo.Type) && !AscFormat.isRealNumber(NumInfo.SubType))
if(!AscFormat.isRealNumber(NumInfo.Type) && !AscFormat.isRealNumber(NumInfo.SubType) && !(NumInfo.Blip instanceof Asc.asc_CFillBlip))
{
return null;
}
Expand Down Expand Up @@ -11996,6 +12009,7 @@ function CalcLiterByLength(aAlphaBet, nLength)
window['AscFormat'].fGetDefaultShapeExtents = fGetDefaultShapeExtents;
window['AscFormat'].HitToRect = HitToRect;
window['AscFormat'].drawingsUpdateForeignCursor = drawingsUpdateForeignCursor;
window['AscFormat'].fFillImageBullet = fFillImageBullet;

window['AscCommon'] = window['AscCommon'] || {};
window["AscCommon"].CDrawTask = CDrawTask;
Expand Down
247 changes: 245 additions & 2 deletions common/Drawings/Format/Format.js
Original file line number Diff line number Diff line change
Expand Up @@ -5401,6 +5401,10 @@ function FormatRGBAColor()
{
return this.IsIdentical(unfill);
};
CUniFill.prototype.isEqual = function(unfill)
{
return this.IsIdentical(unfill);
};
CUniFill.prototype.compare = function(unifill)
{
if(unifill == null)
Expand Down Expand Up @@ -5432,6 +5436,78 @@ function FormatRGBAColor()
return this.fill && this.fill.type !== window['Asc'].c_oAscFill.FILL_TYPE_NOFILL;
};


function CBuBlip() {
this.blip = null;
}

CBuBlip.prototype.setBlip = function (oPr) {
this.blip = oPr;
};

CBuBlip.prototype.fillObject = function (oCopy, oIdMap) {
if (this.blip) {
oCopy.setBlip(this.blip.createDuplicate(oIdMap));
}
};

CBuBlip.prototype.createDuplicate = function () {
var oCopy = new CBuBlip();
this.fillObject(oCopy, {});
return oCopy;
};

CBuBlip.prototype.getChildren = function () {
return [this.blip];
};

CBuBlip.prototype.isEqual = function (oBlip) {
return this.blip.isEqual(oBlip.blip);
};

CBuBlip.prototype.toPPTY = function (pWriter) {
var _src = this.blip.fill.RasterImageId;
var imageLocal = AscCommon.g_oDocumentUrls.getImageLocal(_src);
if(imageLocal)
_src = imageLocal;

pWriter.image_map[_src] = true;

_src = pWriter.prepareRasterImageIdForWrite(_src);
pWriter.WriteBlip(this.blip.fill, _src);
};

CBuBlip.prototype.fromPPTY = function (pReader, oParagraph, oBullet) {
this.setBlip(new AscFormat.CUniFill());
this.blip.setFill(new AscFormat.CBlipFill());
pReader.ReadBlip(this.blip, undefined, undefined, undefined, oParagraph, oBullet);
};

CBuBlip.prototype.Read_FromBinary = function (r) {
if (r.GetBool()) {
this.blip = new CUniFill();
this.blip.Read_FromBinary(r);
}
};

CBuBlip.prototype.Write_ToBinary = function (w) {
w.WriteBool(isRealObject(this.blip));
if (isRealObject(this.blip)) {
this.blip.Write_ToBinary(w);
}
};

CBuBlip.prototype.compare = function (compareObj) {
var ret = null;
if (compareObj instanceof CBuBlip) {
ret = new CBuBlip();
if (this.blip) {
ret.setBlip(this.blip.compare(compareObj.blip));
}
}
return ret;
};

function CompareUniFill(unifill_1, unifill_2)
{

Expand Down Expand Up @@ -10832,7 +10908,9 @@ function CompareBullets(bullet1, bullet2)
}
case AscFormat.BULLET_TYPE_BULLET_BLIP:
{
ret.bulletType.type = AscFormat.BULLET_TYPE_BULLET_CHAR; //TODO: в меню отдаем, что символьный.
ret.bulletType.type = AscFormat.BULLET_TYPE_BULLET_BLIP;
var compareBlip = bullet1.bulletType.Blip && bullet1.bulletType.Blip.compare(bullet2.bulletType.Blip);
ret.bulletType.Blip = compareBlip;
break;
}
case AscFormat.BULLET_TYPE_BULLET_AUTONUM:
Expand Down Expand Up @@ -11131,8 +11209,135 @@ function CompareBullets(bullet1, bullet2)
}
return true;
};
CBullet.prototype.fillBulletImage = function (url) {
if (!this.bulletType) {
this.bulletType = new CBulletType();
}
if (!this.bulletType.Blip) {
this.bulletType.Blip = new AscFormat.CBuBlip();
}
this.bulletType.Type = AscFormat.BULLET_TYPE_BULLET_BLIP;
this.bulletType.Blip.setBlip(AscFormat.CreateBlipFillUniFillFromUrl(url));

}
CBullet.prototype.getImageBulletURL = function () {
return (this.bulletType
&& this.bulletType.Blip
&& this.bulletType.Blip.blip
&& this.bulletType.Blip.blip.fill
&& this.bulletType.Blip.blip.fill.RasterImageId);
}

CBullet.prototype.drawSquareImage = function () {
var url = this.getImageBulletURL();
if(!url || !editor){
return;
}
var oDiv = document.getElementById(this.DivId);
if(!oDiv){
return;
}
var aChildren = oDiv.children;
var oCanvas = null;
for(var i = 0; i < aChildren.length; ++i){
if(aChildren[i].nodeName && aChildren[i].nodeName.toUpperCase() === 'CANVAS'){
oCanvas = aChildren[i];
break;
}
}
var nWidth = oDiv.clientWidth;
var nHeight = oDiv.clientHeight;
if (nWidth !== nHeight) {
return;
}
if(null === oCanvas){
oCanvas = document.createElement('canvas');
oCanvas.width = parseInt(nWidth);
oCanvas.height = parseInt(nHeight);
oDiv.appendChild(oCanvas);
}
var oContext = oCanvas.getContext('2d');
oContext.clearRect(0, 0, oCanvas.width, oCanvas.height);
var _img = this.Api.ImageLoader.map_image_index[AscCommon.getFullImageSrc2(url)];
if (_img != undefined && _img.Image != null && _img.Status != AscFonts.ImageLoadStatus.Loading)
{
var indent = nWidth * 0.125;
var _x = indent;
var _y = indent;
var _w = nWidth - indent;
var _h = nHeight - indent;
oContext.drawImage(_img.Image, _x, _y, _w, _h);
}
}
//interface methods
var prot = CBullet.prototype;
prot.put_ImageUrl = function (sUrl, token) {
var _this = this;
var Api = editor;
if(!Api)
{
return;
}
AscCommon.sendImgUrls(Api, [sUrl], function(data) {
if (data && data[0] && data[0].url !== "error")
{
var url = AscCommon.g_oDocumentUrls.imagePath2Local(data[0].path);
Api.ImageLoader.LoadImagesWithCallback([AscCommon.getFullImageSrc2(url)], function(){
_this.fillBulletImage(url);
//_this.drawSquareImage();
_this.Api.sendEvent("asc_onBulletImageLoaded");
});
}
}, false, false, token);
}
prot["put_ImageUrl"] = prot["asc_putImageUrl"] = CBullet.prototype.put_ImageUrl;
prot.showFileDialog = function () {
if(!editor){
return;
}
var t = editor;
var _this = this;
AscCommon.ShowImageFileDialog(t.documentId, t.documentUserId, t.CoAuthoringApi.get_jwt(), function(error, files)
{
if (Asc.c_oAscError.ID.No !== error)
{
t.sendEvent("asc_onError", error, Asc.c_oAscError.Level.NoCritical);
}
else
{
t.sync_StartAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.UploadImage);
AscCommon.UploadImageFiles(files, t.documentId, t.documentUserId, t.CoAuthoringApi.get_jwt(), function(error, urls)
{
if (Asc.c_oAscError.ID.No !== error)
{
t.sendEvent("asc_onError", error, Asc.c_oAscError.Level.NoCritical);
t.sync_EndAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.UploadImage);
}
else
{
t.ImageLoader.LoadImagesWithCallback(urls, function(){
if(urls.length > 0)
{
_this.fillBulletImage(urls[0]);
//_this.drawSquareImage();
t.sendEvent("asc_onBulletImageLoaded");
}
t.sync_EndAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.UploadImage);
});
}
});
}
},
function(error)
{
if (Asc.c_oAscError.ID.No !== error)
{
t.sendEvent("asc_onError", error, Asc.c_oAscError.Level.NoCritical);
}
t.sync_StartAction(Asc.c_oAscAsyncActionType.BlockInteraction, Asc.c_oAscAsyncAction.UploadImage);
});
}
prot["showFileDialog"] = prot["asc_showFileDialog"] = CBullet.prototype.showFileDialog;
prot.asc_getSize = function () {
var nRet = 100;
if(this.bulletSize) {
Expand Down Expand Up @@ -11502,6 +11707,7 @@ function CBulletType()
this.type = null;//BULLET_TYPE_BULLET_NONE;
this.Char = null;
this.AutoNumType = null;
this.Blip = null;
this.startAt = null;
}

Expand All @@ -11521,7 +11727,8 @@ CBulletType.prototype =
return this.type === oBulletType.type
&& this.Char === oBulletType.Char
&& this.AutoNumType === oBulletType.AutoNumType
&& this.startAt === oBulletType.startAt;
&& this.startAt === oBulletType.startAt
&& ((this.Blip && this.Blip.isEqual(oBulletType.Blip)) || this.Blip === oBulletType.Blip);
},

merge: function(oBulletType)
Expand All @@ -11536,6 +11743,9 @@ CBulletType.prototype =
this.Char = oBulletType.Char;
this.AutoNumType = oBulletType.AutoNumType;
this.startAt = oBulletType.startAt;
if (oBulletType.Blip) {
this.Blip = oBulletType.Blip.createDuplicate();
}
}
else
{
Expand All @@ -11550,6 +11760,12 @@ CBulletType.prototype =
}
}
}
if(this.type === AscFormat.BULLET_TYPE_BULLET_BLIP)
{
if (this.Blip instanceof AscFormat.CBuBlip && this.Blip !== oBulletType.Blip) {
this.Blip = oBulletType.Blip.createDuplicate();
}
}
if(this.type === AscFormat.BULLET_TYPE_BULLET_AUTONUM)
{
if(oBulletType.AutoNumType !== null && this.AutoNumType !== oBulletType.AutoNumType)
Expand All @@ -11572,9 +11788,16 @@ CBulletType.prototype =
d.Char = this.Char;
d.AutoNumType = this.AutoNumType;
d.startAt = this.startAt;
if (this.Blip) {
d.Blip = this.Blip.createDuplicate();
}
return d;
},

setBlip: function (oPr) {
this.Blip = oPr;
},

Write_ToBinary: function(w)
{
w.WriteBool(isRealNumber(this.type));
Expand All @@ -11600,6 +11823,10 @@ CBulletType.prototype =
{
w.WriteLong(this.startAt);
}
w.WriteBool(isRealObject(this.Blip));
if (isRealObject(this.Blip)) {
this.Blip.Write_ToBinary(w);
}
},

Read_FromBinary: function(r)
Expand All @@ -11624,6 +11851,20 @@ CBulletType.prototype =
{
(this.startAt) = r.GetLong();
}
if (r.GetBool()) {
this.Blip = new CBuBlip();
this.Blip.Read_FromBinary(r);

var oUnifill = this.Blip.blip;
var sRasterImageId = oUnifill && oUnifill.fill && oUnifill.fill.RasterImageId;
if(typeof AscCommon.CollaborativeEditing !== "undefined")
{
if(typeof sRasterImageId === "string" && sRasterImageId.length > 0)
{
AscCommon.CollaborativeEditing.Add_NewImage(sRasterImageId);
}
}
}
}
};

Expand Down Expand Up @@ -13565,6 +13806,7 @@ function CorrectUniColor(asc_color, unicolor, flag)
window['AscFormat'].CHyperlink = CHyperlink;
window['AscFormat'].CTextParagraphPr = CTextParagraphPr;
window['AscFormat'].CompareBullets = CompareBullets;
window['AscFormat'].CBuBlip = CBuBlip;
window['AscFormat'].CBullet = CBullet;
window['AscFormat'].CBulletColor = CBulletColor;
window['AscFormat'].CBulletSize = CBulletSize;
Expand Down Expand Up @@ -13767,6 +14009,7 @@ function CorrectUniColor(asc_color, unicolor, flag)
window['AscFormat'].InitClass = InitClass;
window['AscFormat'].CBaseObject = CBaseObject;
window['AscFormat'].CBaseFormatObject = CBaseFormatObject;
window['AscFormat'].checkRasterImageId = checkRasterImageId;

window['AscFormat'].DEFAULT_COLOR_MAP = GenerateDefaultColorMap();
})(window);
Loading

0 comments on commit d973d4c

Please sign in to comment.