Skip to content

Commit

Permalink
refactoring: add parameters to CColorMod constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyLuzyanin committed Oct 18, 2023
1 parent 4e90ff6 commit 53f2995
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 81 deletions.
16 changes: 3 additions & 13 deletions common/Charts/ChartsDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions common/Drawings/Format/ChartSpace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
89 changes: 47 additions & 42 deletions common/Drawings/Format/Format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
}
Expand All @@ -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];
Expand Down Expand Up @@ -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_);
}
}
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 3 additions & 9 deletions common/Shapes/EditorSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions common/Shapes/SerializeWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
10 changes: 2 additions & 8 deletions word/Editor/Serialize2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 53f2995

Please sign in to comment.