Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/image bullet #2498

Merged
merged 37 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d23bf65
test push
Dec 28, 2021
dcc7657
Merge branch 'develop' of https://github.com/ONLYOFFICE/sdkjs into fe…
Dec 28, 2021
2384999
refactor: replace part of code in readUniFill and writeUniFill method…
Dec 28, 2021
ea328f5
Merge branch 'develop' of https://github.com/ONLYOFFICE/sdkjs into fe…
Dec 28, 2021
4840375
reset commit: thoughts about image bullet
Dec 29, 2021
62e16f8
feat: calculate images for presentation image bullet
Jan 10, 2022
47bc4cd
feat: add require methods for BuBlip
Jan 10, 2022
15929c7
fix: add changes in write logic of Blip
Jan 10, 2022
98b98f1
Merge branch 'develop' of https://github.com/ONLYOFFICE/sdkjs into fe…
Jan 10, 2022
631a9d6
Merge branch 'develop' of https://github.com/ONLYOFFICE/sdkjs into fe…
Jan 11, 2022
3d679f3
refactor: BuBlip class
Jan 11, 2022
c5b2e32
fix(pe): add calculate FontSlot for blip bullet in Measure method
Jan 11, 2022
bb22b96
refactor(pe): set braces with new line
Jan 11, 2022
cea56f7
fix: try to repair unit tests
Jan 11, 2022
b4d6ec1
fix: add new adding unit
Jan 11, 2022
a4c07c3
feat: add test upload methods for image bullets in api
Jan 17, 2022
6bb3d1e
fix: get font by first symbol and method copy
Jan 17, 2022
702632c
Merge branch 'develop' of https://github.com/ONLYOFFICE/sdkjs into fe…
Jan 17, 2022
dc424cf
fix: add export for type BULLET_TYPE_BULLET_BLIP
Jan 17, 2022
06a8ee3
fix: compare method in CBuBlip class
Jan 17, 2022
4637833
fix: add return for cases, when image not available
Jan 18, 2022
cc9300f
fix: add Write_ToBinary and Read_FromBinary for new fields
Jan 18, 2022
15beb97
feat: add plug for change image bullet settings and method for get ra…
Jan 18, 2022
2793a6a
refactor: delete unusual for image bullet in presentation
Jan 18, 2022
0cd2b85
feat: add images for collaborative mode
Jan 18, 2022
8eb1926
[imageBullet] fix image loading on coauthoring
SergeyLuzyanin Jan 18, 2022
eddf87a
fix: recalculate image bullet drawing
Jan 19, 2022
3dc0b97
fix: add BuBlip isEqual method
Jan 19, 2022
861e7d7
fix: load images to server from url blipFill
Jan 19, 2022
3db4217
fix: indents in image bullets
Jan 19, 2022
09e75e3
fix: koef for image size of image bullet
Jan 20, 2022
929abe9
fix: check load images from url for errors
Jan 20, 2022
9c3643f
refactor: delete unusual console.log
Jan 20, 2022
01ce224
docs: comment mock method
Jan 20, 2022
43b1853
refactor: delete unusual font pickers
Jan 20, 2022
e853997
[imageBullet] fix loading images in spreadsheets, fix copy/paste
SergeyLuzyanin Jan 20, 2022
f955bdc
Merge remote-tracking branch 'remotes/origin/develop' into feature/im…
SergeyLuzyanin Jan 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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