diff --git a/common/Charts/ChartsDrawer.js b/common/Charts/ChartsDrawer.js index 6cf2072ceb..40d8243d56 100644 --- a/common/Charts/ChartsDrawer.js +++ b/common/Charts/ChartsDrawer.js @@ -10146,10 +10146,7 @@ drawHBarChart.prototype = { _applyColorModeByBrush: function (brushFill, val) { var props = this.cChartSpace.getParentObjects(); var duplicateBrush = brushFill.createDuplicate(); - var cColorMod = new AscFormat.CColorMod; - cColorMod.val = val; - - cColorMod.name = "shade"; + var cColorMod = new AscFormat.CColorMod("shade", val); duplicateBrush.addColorMod(cColorMod); duplicateBrush.calculate(props.theme, props.slide, props.layout, props.master, new AscFormat.CUniColor().RGBA, this.cChartSpace.clrMapOvr); @@ -11310,11 +11307,7 @@ drawPieChart.prototype = { if (brush) { var props = t.cChartSpace.getParentObjects(); var duplicateBrush = brush.createDuplicate(); - var cColorMod = new AscFormat.CColorMod; - - cColorMod.val = shadeValue; - cColorMod.name = shade; - + var cColorMod = new AscFormat.CColorMod(shade, shadeValue); if (duplicateBrush) { duplicateBrush.addColorMod(cColorMod); duplicateBrush.calculate(props.theme, props.slide, props.layout, props.master, new AscFormat.CUniColor().RGBA, t.cChartSpace.clrMapOvr); @@ -11905,10 +11898,7 @@ drawPieChart.prototype = { var duplicateBrush = brush; if (n !== this.paths.series.length - 1) { duplicateBrush = brush.createDuplicate(); - var cColorMod = new AscFormat.CColorMod; - - cColorMod.val = 35000; - cColorMod.name = "shade"; + var cColorMod = new AscFormat.CColorMod("shade", 35000); duplicateBrush.addColorMod(cColorMod); duplicateBrush.calculate(props.theme, props.slide, props.layout, props.master, new AscFormat.CUniColor().RGBA, this.cChartSpace.clrMapOvr); diff --git a/common/Drawings/Format/ChartSpace.js b/common/Drawings/Format/ChartSpace.js index fcdc5c8223..a6c7b7f983 100644 --- a/common/Drawings/Format/ChartSpace.js +++ b/common/Drawings/Format/ChartSpace.js @@ -9521,15 +9521,11 @@ function(window, undefined) { effectVal *= 100000.0; if (!unicolor.Mods) unicolor.setMods(new AscFormat.CColorModifiers()); - var mod = new AscFormat.CColorMod(); if (effectVal > 0) { - mod.setName("tint"); - mod.setVal(effectVal); + unicolor.Mods.addMod("tint", effectVal); } else { - mod.setName("shade"); - mod.setVal(Math.abs(effectVal)); + unicolor.Mods.addMod("shade", Math.abs(effectVal)); } - unicolor.Mods.addMod(mod); } return ret; } diff --git a/common/Drawings/Format/Format.js b/common/Drawings/Format/Format.js index 0c7397a42d..eafd967fc1 100644 --- a/common/Drawings/Format/Format.js +++ b/common/Drawings/Format/Format.js @@ -1289,9 +1289,9 @@ map_prst_color["yellow"] = 0xFFFF00; map_prst_color["yellowGreen"] = 0x9ACD32; - function CColorMod() { - this.name = ""; - this.val = 0; + function CColorMod(sName, nVal) { + this.name = sName ? sName : ""; + this.val = AscFormat.isRealNumber(nVal) ? nVal : 0; } CColorMod.prototype.setName = function (name) { @@ -1321,10 +1321,18 @@ CColorModifiers.prototype.isUsePow = (!AscCommon.AscBrowser.isSailfish || !AscCommon.AscBrowser.isEmulateDevicePixelRatio); CColorModifiers.prototype.getModValue = function (sName) { + let oMod = this.getMod(); + if(oMod) { + return oMod.val; + } + return null; + }; + CColorModifiers.prototype.getMod = function (sName) { if (Array.isArray(this.Mods)) { - for (var i = 0; i < this.Mods.length; ++i) { - if (this.Mods[i] && this.Mods[i].name === sName) { - return this.Mods[i].val; + for (let nMod = 0; nMod < this.Mods.length; ++nMod) { + let oMod = this.Mods[nMod]; + if (oMod && oMod.name === sName) { + return oMod; } } } @@ -1347,7 +1355,20 @@ } }; CColorModifiers.prototype.addMod = function (mod) { - this.Mods.push(mod); + let oModForAdd; + if(arguments.length === 1) { + if(arguments[0] instanceof CColorMod) { + oModForAdd = arguments[0]; + } + } + else if(arguments.length === 2) { + if(typeof arguments[0] === "string" && AscFormat.isRealNumber(arguments[1])) { + oModForAdd = new CColorMod(arguments[0], arguments[1]); + } + } + if(oModForAdd) { + this.Mods.push(oModForAdd); + } }; CColorModifiers.prototype.removeMod = function (pos) { this.Mods.splice(pos, 1)[0]; @@ -2420,22 +2441,14 @@ if (this.checkWordMods()) { var val_, mod_; if (this.Mods.Mods[0].name === "wordShade") { - mod_ = new CColorMod(); - mod_.setName("lumMod"); - mod_.setVal(((this.Mods.Mods[0].val / 255) * 100000) >> 0); + mod_ = new CColorMod("lumMod", ((this.Mods.Mods[0].val / 255) * 100000) >> 0); this.Mods.Mods.splice(0, this.Mods.Mods.length); this.Mods.Mods.push(mod_); } else { val_ = ((this.Mods.Mods[0].val / 255) * 100000) >> 0; this.Mods.Mods.splice(0, this.Mods.Mods.length); - mod_ = new CColorMod(); - mod_.setName("lumMod"); - mod_.setVal(val_); - this.Mods.Mods.push(mod_); - mod_ = new CColorMod(); - mod_.setName("lumOff"); - mod_.setVal(100000 - val_); - this.Mods.Mods.push(mod_); + this.Mods.addMod("lumMod", val_); + this.Mods.addMod("lumOff", 100000 - val_); } } }; @@ -4210,11 +4223,17 @@ if(!this.color) { return; } - this.color.Mods = new CColorModifiers(); - const oMod = new CColorMod(); - oMod.name = "alpha"; - oMod.val = (100 - nVal) * 1000 + 0.5 >> 0; - this.color.Mods.Mods.push(oMod); + if(!this.color.Mods) { + this.color.Mods = new CColorModifiers(); + } + let oMod = this.color.Mods.getMod("alpha"); + if(!oMod) { + oMod = new CColorMod("alpha", (100 - nVal) * 1000 + 0.5 >> 0); + this.color.addMod(oMod); + } + else { + oMod.setVal((100 - nVal) * 1000 + 0.5 >> 0); + } }; asc_CShadowProperty.prototype.getSize = function() { let nSX = this.sx !== null ? this.sx : 100000; @@ -7285,11 +7304,8 @@ unicolor = new CUniColor(); unicolor.setColor(new CSchemeColor()); unicolor.color.setId(g_clr_accent1); - var mod = new CColorMod(); - mod.setName("shade"); - mod.setVal(50000); unicolor.setMods(new CColorModifiers()); - unicolor.Mods.addMod(mod); + unicolor.Mods.addMod("shade", 50000); lnRef.setColor(unicolor); style.setLnRef(lnRef); @@ -13755,9 +13771,7 @@ oColor.color.id = id; for(let nMod = 0; nMod < aMods.length; ++nMod) { let oModObject = aMods[nMod]; - let oMod = new CColorMod(); - oMod.name = oModObject.name; - oMod.val = oModObject.val; + let oMod = new CColorMod(oModObject.name, oModObject.val); oColor.addColorMod(oMod); } return oColor; @@ -13885,14 +13899,8 @@ pen.Fill.fill.color.color.setId(phClr); pen.Fill.fill.color.setMods(new CColorModifiers()); - var mod = new CColorMod(); - mod.setName("shade"); - mod.setVal(95000); - pen.Fill.fill.color.Mods.addMod(mod); - mod = new CColorMod(); - mod.setName("satMod"); - mod.setVal(105000); - pen.Fill.fill.color.Mods.addMod(mod); + pen.Fill.fill.color.Mods.addMod("shade", 95000); + pen.Fill.fill.color.Mods.addMod("satMod", 105000); theme.themeElements.fmtScheme.lnStyleLst.push(pen); pen = new CLn(); @@ -13959,11 +13967,8 @@ unicolor.setColor(new CSchemeColor()); unicolor.color.setId(g_clr_accent1); - var mod = new CColorMod(); - mod.setName("shade"); - mod.setVal(50000); unicolor.setMods(new CColorModifiers()); - unicolor.Mods.addMod(mod); + unicolor.Mods.addMod("shade", 50000); lnRef.setColor(unicolor); style.setLnRef(lnRef); diff --git a/common/Shapes/EditorSettings.js b/common/Shapes/EditorSettings.js index 60dcfa505b..4fadcc5470 100644 --- a/common/Shapes/EditorSettings.js +++ b/common/Shapes/EditorSettings.js @@ -224,16 +224,12 @@ function GetDefaultMods(r, g, b, pos, editor_id) if (_obj.lumMod !== -1) { - _mod = new AscFormat.CColorMod(); - _mod["name"] = "lumMod"; - _mod["val"] = _obj.lumMod; + _mod = new AscFormat.CColorMod("lumMod", _obj.lumMod); _mods.push(_mod); } if (_obj.lumOff !== -1) { - _mod = new AscFormat.CColorMod(); - _mod.name = "lumOff"; - _mod.val = _obj.lumOff; + _mod = new AscFormat.CColorMod("lumOff", _obj.lumOff); _mods.push(_mod); } @@ -243,9 +239,7 @@ function GetDefaultMods(r, g, b, pos, editor_id) { _obj = g_oThemeColorsDefaultModsWord[index][pos - 1]; - _mod = new AscFormat.CColorMod(); - _mod.name = _obj.name; - _mod.val = _obj.val /** 100000 / 255) >> 0*/; + _mod = new AscFormat.CColorMod(_obj.name, _obj.val); _mods.push(_mod); return _mods; diff --git a/common/Shapes/SerializeWriter.js b/common/Shapes/SerializeWriter.js index 4277a97471..a8698b081e 100644 --- a/common/Shapes/SerializeWriter.js +++ b/common/Shapes/SerializeWriter.js @@ -2308,9 +2308,7 @@ function CBinaryFileWriter() mods.splice(nIndex, 1); } - mods[_len] = new AscFormat.CColorMod(); - mods[_len].name = "alpha"; - mods[_len].val = (trans * 100000 / 255) >> 0; + mods[_len] = new AscFormat.CColorMod("alpha", (trans * 100000 / 255) >> 0); } }; diff --git a/word/Editor/Serialize2.js b/word/Editor/Serialize2.js index eb7bcd362f..b9158ba484 100644 --- a/word/Editor/Serialize2.js +++ b/word/Editor/Serialize2.js @@ -1408,16 +1408,10 @@ function CreateThemeUnifill(color, tint, shade){ ret.fill.color.setMods(new AscFormat.CColorModifiers()); var mod; if(null != tint){ - mod = new AscFormat.CColorMod(); - mod.setName("wordTint"); - mod.setVal(tint /** 100000.0 / 0xff*/); - ret.fill.color.Mods.addMod(mod); + ret.fill.color.Mods.addMod("wordTint", tint); } if(null != shade){ - mod = new AscFormat.CColorMod(); - mod.setName("wordShade"); - mod.setVal(shade /** 100000.0 / 0xff*/); - ret.fill.color.Mods.addMod(mod); + ret.fill.color.Mods.addMod("wordShade", shade); } } }