Merge pull request 'feature/diagram-default-theme' (#1335) from feature/diagram-default-theme into feature/diagram

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/sdkjs/pulls/1335
This commit is contained in:
Sergey Konovalov
2025-08-15 12:49:20 +00:00
6 changed files with 188 additions and 34 deletions

View File

@ -496,9 +496,6 @@
case 7:
this.snapExtensions = stream.GetLong();
break;
case 8:
this.snapAngles = stream.GetLong();
break;
case 9:
this.dynamicGridEnabled = stream.GetBool();
break;
@ -530,6 +527,38 @@
return true;
};
/**
* Read children from stream for DocumentSettings_Type
*
* @param {number} attrType - The type of attribute
* @param {BinaryVSDYLoader} pReader - The binary reader
* @returns {boolean} - True if attribute was handled, false otherwise
*/
AscVisio.DocumentSettings_Type.prototype.readChild = function(elementType, pReader) {
const t = this;
switch (elementType) {
case 0:
// Read Shape_Type
AscFormat.CBaseFormatNoIdObject.prototype.fromPPTY.call({
readChildren: AscFormat.CBaseFormatNoIdObject.prototype.readChildren,
readChild: function(elementType, pReader) {
if (elementType === 0) {
const snapAngle = new AscVisio.SnapAngle_Type();
snapAngle.fromPPTY(pReader);
t.snapAngles.push(snapAngle);
return true;
}
return false;
}
}, pReader);
break;
default:
return false;
}
return true;
};
/**
* Read attributes from stream for ColorEntry_Type
*
@ -1564,9 +1593,6 @@
case 24:
this.snapExtensions = stream.GetULong();
return true;
case 25:
this.snapAngles = stream.GetBool();
return true;
case 26:
this.dynamicGridEnabled = stream.GetBool();
return true;
@ -1584,6 +1610,56 @@
return false;
};
/**
* Read children from stream for DocumentSettings_Type
*
* @param {number} attrType - The type of attribute
* @param {BinaryVSDYLoader} pReader - The binary reader
* @returns {boolean} - True if attribute was handled, false otherwise
*/
AscVisio.Window_Type.prototype.readChild = function(elementType, pReader) {
const t = this;
switch (elementType) {
case 0:
// Read Shape_Type
AscFormat.CBaseFormatNoIdObject.prototype.fromPPTY.call({
readChildren: AscFormat.CBaseFormatNoIdObject.prototype.readChildren,
readChild: function(elementType, pReader) {
if (elementType === 0) {
const snapAngle = new AscVisio.SnapAngle_Type();
snapAngle.fromPPTY(pReader);
t.snapAngles.push(snapAngle);
return true;
}
return false;
}
}, pReader);
break;
default:
return false;
}
return true;
};
/**
* Read attributes from stream for Window_Type
*
* @param {number} attrType - The type of attribute
* @param {BinaryVSDYLoader} pReader - The binary reader
* @returns {boolean} - True if attribute was handled, false otherwise
*/
AscVisio.SnapAngle_Type.prototype.readAttribute = function(attrType, pReader) {
const stream = pReader.stream;
switch (attrType) {
case 0:
this.value = stream.GetDouble();
return true;
}
return false;
};
/**
* Read attributes from stream for DocumentSheet_Type
*

View File

@ -228,9 +228,13 @@
if (this.themes) {
for (let i = 0; i < this.themes.length; i++) {
pWriter.StartRecord(15);
pWriter.WriteTheme(this.themes[i]);
pWriter.EndRecord();
let theme = this.themes[i];
// theme with id 0 is default theme (no theme in visio) - this theme should not be saved
if (theme.themeElements.themeExt.themeSchemeSchemeEnum !== "0") {
pWriter.StartRecord(15);
pWriter.WriteTheme(theme);
pWriter.EndRecord();
}
}
}
//todo VbaProject
@ -977,13 +981,28 @@
pWriter._WriteUInt2(22, this.glueSettings);
pWriter._WriteUInt2(23, this.snapSettings);
pWriter._WriteUInt2(24, this.snapExtensions);
pWriter._WriteBool2(25, this.snapAngles);
pWriter._WriteBool2(26, this.dynamicGridEnabled);
pWriter._WriteDoubleReal2(27, this.tabSplitterPos);
pWriter._WriteUInt2(28, this.stencilGroup);
pWriter._WriteUInt2(29, this.stencilGroupPos);
};
/**
* Write children to stream for Window_Type
*
* @param {CBinaryFileWriter} pWriter - The binary writer
*/
AscVisio.Window_Type.prototype.writeChildren = function (pWriter) {
// Write content if present
if (this.snapAngles && this.snapAngles.length > 0) {
pWriter.StartRecord(0);
for (let i = 0; i < this.snapAngles.length; i++) {
pWriter.WriteRecordPPTY(0, this.snapAngles[i]);
}
pWriter.EndRecord();
}
};
/**
* Write attributes to stream for Page_Type
*
@ -1239,7 +1258,6 @@
pWriter._WriteInt2(5, this.glueSettings);
pWriter._WriteInt2(6, this.snapSettings);
pWriter._WriteInt2(7, this.snapExtensions);
pWriter._WriteInt2(8, this.snapAngles);
pWriter._WriteBool2(9, this.dynamicGridEnabled);
pWriter._WriteBool2(10, this.protectStyles);
pWriter._WriteBool2(11, this.protectShapes);
@ -1250,6 +1268,31 @@
pWriter._WriteString2(16, this.attachedToolbars);
};
/**
* Write children to stream for DocumentSettings_Type
*
* @param {CBinaryFileWriter} pWriter - The binary writer
*/
AscVisio.DocumentSettings_Type.prototype.writeChildren = function (pWriter) {
// Write content if present
if (this.snapAngles && this.snapAngles.length > 0) {
pWriter.StartRecord(0);
for (let i = 0; i < this.snapAngles.length; i++) {
pWriter.WriteRecordPPTY(0, this.snapAngles[i]);
}
pWriter.EndRecord();
}
};
/**
* Write attributes to stream for SnapAngle_Type
*
* @param {CBinaryFileWriter} pWriter - The binary writer
*/
AscVisio.SnapAngle_Type.prototype.privateWriteAttributes = function (pWriter) {
pWriter._WriteDoubleReal2(0, this.value);
};
/**
* Write attributes to stream for Section_Type
*

View File

@ -268,7 +268,6 @@ AscDFH.historyitem_type_VisioWindow = 328;
let thumbNailPart = filePart.addPart(AscCommon.openXml.Types.thumbnail);
let windowsPart = docPart.part.addPart(AscCommon.openXml.Types.visioDocumentWindows);
let mastersPart = docPart.part.addPart(AscCommon.openXml.Types.masters);
let themesPart = docPart.part.addPart(AscCommon.openXml.Types.theme);
let commentsPart = docPart.part.addPart(AscCommon.openXml.Types.visioComments);
let extensionsPart = docPart.part.addPart(AscCommon.openXml.Types.visioExtensions);
let dataConnectionsPart = docPart.part.addPart(AscCommon.openXml.Types.visioDataConnections);
@ -306,6 +305,14 @@ AscDFH.historyitem_type_VisioWindow = 328;
}
}
for (let i = 0; i < this.themes.length; i++) {
let theme = this.themes[i];
if (theme.themeElements.themeExt.themeSchemeSchemeEnum !== "0") {
let themeContent = docPart.part.addPart(AscCommon.openXml.Types.theme);
themeContent.part.setDataXml(theme, memory);
}
}
// Not realized, file defines schema and data of that schema
for (let i = 0; i < this.solutionXMLs.length; i++) {
let solutionContent = solutionsPart.part.addPart(AscCommon.openXml.Types.solution);
@ -330,10 +337,6 @@ AscDFH.historyitem_type_VisioWindow = 328;
mastersPart.part.setDataXml(this.masters, memory);
}
pagesPart.part.setDataXml(this.pages, memory);
for (let i = 0; i < this.themes.length; i++) {
let themeContent = themesPart.part.addPart(AscCommon.openXml.Types.theme);
themeContent.part.setDataXml(this.themes[i], memory);
}
if (this.commentsPart) {
commentsPart.part.setDataXml(this.commentsPart, memory);
}
@ -358,7 +361,7 @@ AscDFH.historyitem_type_VisioWindow = 328;
CVisioDocument.prototype.AfterOpenDocument = function(zip, context) {
if (!this.themes.length) {
AscCommon.consoleLog("No themes found by filenames. Creating default theme");
this.themes.push(AscFormat.GenerateDefaultTheme(null, null));
this.themes.push(AscFormat.GetDefaultTheme());
}
};

View File

@ -51,8 +51,8 @@ AscFormat.CShape.prototype.getParentObjects = function ()
if (this.parent) {
oTheme = this.parent.themes[0];
} else {
AscCommon.consoleLog("Parent was not set for shape/group. GenerateDefaultTheme is used. shape/group:", this);
oTheme = AscFormat.GenerateDefaultTheme(null, null);
AscCommon.consoleLog("Parent was not set for shape/group. GetDefaultTheme will be used. shape/group:", this);
oTheme = AscFormat.GetDefaultTheme();
}
return {slide: null, layout: null, master: null, theme: oTheme};
};
@ -156,20 +156,22 @@ AscFormat.CTheme.prototype.getFillStyle = function (idx, unicolor, isConnectorSh
let fmtScheme = (isConnectorShape && this.themeElements.themeExt) ?
this.themeElements.themeExt.fmtConnectorScheme :
this.themeElements.fmtScheme;
if (idx >= 1 && idx <= 999) {
if (fmtScheme.fillStyleLst[idx - 1]) {
ret = fmtScheme.fillStyleLst[idx - 1].createDuplicate();
if (ret) {
ret.checkPhColor(unicolor, false);
return ret;
if (fmtScheme) {
if (idx >= 1 && idx <= 999) {
if (fmtScheme.fillStyleLst[idx - 1]) {
ret = fmtScheme.fillStyleLst[idx - 1].createDuplicate();
if (ret) {
ret.checkPhColor(unicolor, false);
return ret;
}
}
}
} else if (idx >= 1001) {
if (fmtScheme.bgFillStyleLst[idx - 1001]) {
ret = fmtScheme.bgFillStyleLst[idx - 1001].createDuplicate();
if (ret) {
ret.checkPhColor(unicolor, false);
return ret;
} else if (idx >= 1001) {
if (fmtScheme.bgFillStyleLst[idx - 1001]) {
ret = fmtScheme.bgFillStyleLst[idx - 1001].createDuplicate();
if (ret) {
ret.checkPhColor(unicolor, false);
return ret;
}
}
}
}
@ -815,6 +817,8 @@ AscCommonWord.CPresentationField.prototype.private_GetString = function()
return sStr;
};
AscFormat.GenerateDefaultTheme = AscFormat.GenerateDefaultVisioTheme;
//todo CMobileDelegateEditorDiagram
AscCommon.CMobileDelegateEditorPresentation.prototype.GetObjectTrack = function(x, y, page, bSelected, bText) { return false; }
AscCommon.CMobileDelegateEditorPresentation.prototype.GetSelectionRectsBounds = function () { return null; }

View File

@ -434,7 +434,8 @@
result = getMedifiersResult && getMedifiersResult.fontPropsObject.color;
} else if (cellName === "FillForegnd" || cellName === "FillBkgnd") {
//leave result because it is fill
if (getMedifiersResult.fill.type === Asc.c_oAscFill.FILL_TYPE_PATT) {
if (getMedifiersResult && getMedifiersResult.fill &&
getMedifiersResult.fill.type === Asc.c_oAscFill.FILL_TYPE_PATT) {
let uniColor;
if (cellName === "FillForegnd") {
uniColor = getMedifiersResult.fill.fgClr;