forked from sheetjs/sheetjs
Correct hex2RGB coding, apply tints
This commit is contained in:
parent
89066b45b6
commit
5dbf215c9c
@ -1,6 +1,6 @@
|
||||
function hex2RGB(h) {
|
||||
var o = h.substr(h[0]==="#"?1:0,6);
|
||||
return [parseInt(o.substr(0,2),16),parseInt(o.substr(0,2),16),parseInt(o.substr(0,2),16)];
|
||||
return [parseInt(o.substr(0,2),16),parseInt(o.substr(2,2),16),parseInt(o.substr(4,2),16)];
|
||||
}
|
||||
function rgb2Hex(rgb) {
|
||||
for(var i=0,o=1; i!=3; ++i) o = o*256 + (rgb[i]>255?255:rgb[i]<0?0:rgb[i]);
|
||||
@ -42,11 +42,12 @@ function hsl2RGB(hsl){
|
||||
|
||||
/* 18.8.3 bgColor tint algorithm */
|
||||
function rgb_tint(hex, tint) {
|
||||
if(tint === 0) return hex;
|
||||
if(tint == 0) return hex;
|
||||
var hsl = rgb2HSL(hex2RGB(hex));
|
||||
if (tint < 0) hsl[2] = hsl[2] * (1 + tint);
|
||||
else hsl[2] = 1 - (1 - hsl[2]) * (1 - tint);
|
||||
return rgb2Hex(hsl2RGB(hsl));
|
||||
var rev =rgb2Hex(hsl2RGB(hsl))
|
||||
return rev;
|
||||
}
|
||||
|
||||
/* 18.3.1.13 width calculations */
|
||||
|
@ -35,8 +35,8 @@ function parse_fills(t, opts) {
|
||||
|
||||
|
||||
if (y.theme && themes.themeElements && themes.themeElements.clrScheme) {
|
||||
fill.bgColor.rgb = rgb_tint(themes.themeElements.clrScheme[fill.bgColor.theme].rgb, 0) ; //fill.fgColor.tint || 0);
|
||||
if (opts.WTF) fill.bgColor.raw_rgb = fill.bgColor.rgb;
|
||||
fill.bgColor.rgb = rgb_tint(themes.themeElements.clrScheme[fill.bgColor.theme].rgb, fill.bgColor.tint || 0);
|
||||
if (opts.WTF) fill.bgColor.raw_rgb = rgb_tint(themes.themeElements.clrScheme[fill.bgColor.theme].rgb,0);
|
||||
}
|
||||
/* Excel uses ARGB strings */
|
||||
if (y.rgb) fill.bgColor.rgb = y.rgb;//.substring(y.rgb.length - 6);
|
||||
@ -52,8 +52,8 @@ function parse_fills(t, opts) {
|
||||
if (y.tint) fill.fgColor.tint = parseFloat(y.tint);
|
||||
|
||||
if (y.theme && themes.themeElements && themes.themeElements.clrScheme) {
|
||||
fill.fgColor.rgb = rgb_tint(themes.themeElements.clrScheme[fill.fgColor.theme].rgb, 0); //fill.fgColor.tint || 0);
|
||||
if (opts.WTF) fill.fgColor.raw_rgb = fill.fgColor.rgb;
|
||||
fill.fgColor.rgb = rgb_tint(themes.themeElements.clrScheme[fill.fgColor.theme].rgb, fill.fgColor.tint || 0);
|
||||
if (opts.WTF) fill.fgColor.raw_rgb = rgb_tint(themes.themeElements.clrScheme[fill.fgColor.theme].rgb,0);
|
||||
}
|
||||
|
||||
/* Excel uses ARGB strings */
|
||||
|
33
test.js
33
test.js
@ -766,32 +766,31 @@ describe('parse features', function() {
|
||||
'H1:J4', 'H10' /* blocks */
|
||||
];
|
||||
|
||||
|
||||
var exp = [
|
||||
{ patternType: 'darkHorizontal',
|
||||
fgColor: { theme: 9, "tint":-0.249977111117893, rgb: 'F79646' },
|
||||
bgColor: { theme: 5, "tint":0.3999755851924192, rgb: 'C0504D' } },
|
||||
fgColor: { theme: 9, "tint":-0.249977111117893, rgb_raw: 'F79646', rgb: "E46C0A"},
|
||||
bgColor: { theme: 5, "tint":0.3999755851924192, rgb_raw: 'C0504D', rgb: "D99694" } },
|
||||
{ patternType: 'darkUp',
|
||||
fgColor: { theme: 3, "tint":-0.249977111117893, rgb: 'EEECE1' },
|
||||
bgColor: { theme: 7, "tint":0.3999755851924192, rgb: '8064A2' } },
|
||||
fgColor: { theme: 3, "tint":-0.249977111117893, rgb_raw: 'EEECE1', rgb: "C4BD97" },
|
||||
bgColor: { theme: 7, "tint":0.3999755851924192, rgb_raw: '8064A2', rgb: "B3A2C7" } },
|
||||
{ patternType: 'darkGray',
|
||||
fgColor: { theme: 3, rgb: 'EEECE1' },
|
||||
bgColor: { theme: 1, rgb: 'FFFFFF' } },
|
||||
fgColor: { theme: 3, rgb_raw: 'EEECE1', rgb: "EEECE1" },
|
||||
bgColor: { theme: 1, rgb_raw: 'FFFFFF', rgb: "FFFFFF" } },
|
||||
{ patternType: 'lightGray',
|
||||
fgColor: { theme: 6, "tint":0.3999755851924192, rgb: '9BBB59' },
|
||||
bgColor: { theme: 2, "tint":-0.499984740745262, rgb: '1F497D' } },
|
||||
fgColor: { theme: 6, "tint":0.3999755851924192, rgb_raw: '9BBB59', rgb: "C3D69B" },
|
||||
bgColor: { theme: 2, "tint":-0.499984740745262, rgb_raw: '1F497D', rgb: "10253F" } },
|
||||
{ patternType: 'lightDown',
|
||||
fgColor: { theme: 4, rgb: '4F81BD' },
|
||||
bgColor: { theme: 7, rgb: '8064A2' } },
|
||||
fgColor: { theme: 4, "tint":-0.249977111117893, rgb_raw: '4F81BD', rgb: "376092" },
|
||||
bgColor: { theme: 7, "tint":-0.249977111117893, rgb_raw: '8064A2', rgb: "604A7B" } },
|
||||
{ patternType: 'lightGrid',
|
||||
fgColor: { theme: 6, "tint":-0.249977111117893, rgb: '9BBB59' },
|
||||
bgColor: { theme: 9, "tint":-0.249977111117893, rgb: 'F79646' } },
|
||||
fgColor: { theme: 6, "tint":-0.249977111117893, rgb_raw: '9BBB59', rgb: "77933C" },
|
||||
bgColor: { theme: 9, "tint":-0.249977111117893, rgb_raw: 'F79646', rgb: "E46C0A" } },
|
||||
{ patternType: 'lightGrid',
|
||||
fgColor: { theme: 4, rgb: '4F81BD' },
|
||||
bgColor: { theme: 2, "tint":-0.749992370372631, rgb: '1F497D' } },
|
||||
fgColor: { theme: 4, rgb_raw: '4F81BD' , rgb: "4F81BD"},
|
||||
bgColor: { theme: 2, "tint":-0.749992370372631, rgb_raw: '1F497D', rgb: "08121F" } },
|
||||
{ patternType: 'lightVertical',
|
||||
fgColor: { theme: 3, "tint":0.3999755851924192, rgb: 'EEECE1' },
|
||||
bgColor: { theme: 7, "tint":0.3999755851924192, rgb: '8064A2' } }
|
||||
fgColor: { theme: 3, "tint":0.3999755851924192, rgb_raw: 'EEECE1', rgb: "F5F4ED" },
|
||||
bgColor: { theme: 7, "tint":0.3999755851924192, rgb_raw: '8064A2', rgb: "B3A2C7" } }
|
||||
];
|
||||
ranges.forEach(function(rng) {
|
||||
it('XLS | ' + rng,function(){cmparr(rn2(rng).map(function(x){ return wsxls[x].s; }));});
|
||||
|
15
xlsx.js
15
xlsx.js
@ -4548,7 +4548,7 @@ function parse_FilePass(blob, length, opts) {
|
||||
|
||||
function hex2RGB(h) {
|
||||
var o = h.substr(h[0]==="#"?1:0,6);
|
||||
return [parseInt(o.substr(0,2),16),parseInt(o.substr(0,2),16),parseInt(o.substr(0,2),16)];
|
||||
return [parseInt(o.substr(0,2),16),parseInt(o.substr(2,2),16),parseInt(o.substr(4,2),16)];
|
||||
}
|
||||
function rgb2Hex(rgb) {
|
||||
for(var i=0,o=1; i!=3; ++i) o = o*256 + (rgb[i]>255?255:rgb[i]<0?0:rgb[i]);
|
||||
@ -4590,11 +4590,12 @@ function hsl2RGB(hsl){
|
||||
|
||||
/* 18.8.3 bgColor tint algorithm */
|
||||
function rgb_tint(hex, tint) {
|
||||
if(tint === 0) return hex;
|
||||
if(tint == 0) return hex;
|
||||
var hsl = rgb2HSL(hex2RGB(hex));
|
||||
if (tint < 0) hsl[2] = hsl[2] * (1 + tint);
|
||||
else hsl[2] = 1 - (1 - hsl[2]) * (1 - tint);
|
||||
return rgb2Hex(hsl2RGB(hsl));
|
||||
var rev =rgb2Hex(hsl2RGB(hsl))
|
||||
return rev;
|
||||
}
|
||||
|
||||
/* 18.3.1.13 width calculations */
|
||||
@ -4671,8 +4672,8 @@ function parse_fills(t, opts) {
|
||||
|
||||
|
||||
if (y.theme && themes.themeElements && themes.themeElements.clrScheme) {
|
||||
fill.bgColor.rgb = rgb_tint(themes.themeElements.clrScheme[fill.bgColor.theme].rgb, 0) ; //fill.fgColor.tint || 0);
|
||||
if (opts.WTF) fill.bgColor.raw_rgb = fill.bgColor.rgb;
|
||||
fill.bgColor.rgb = rgb_tint(themes.themeElements.clrScheme[fill.bgColor.theme].rgb, fill.bgColor.tint || 0);
|
||||
if (opts.WTF) fill.bgColor.raw_rgb = rgb_tint(themes.themeElements.clrScheme[fill.bgColor.theme].rgb,0);
|
||||
}
|
||||
/* Excel uses ARGB strings */
|
||||
if (y.rgb) fill.bgColor.rgb = y.rgb;//.substring(y.rgb.length - 6);
|
||||
@ -4688,8 +4689,8 @@ function parse_fills(t, opts) {
|
||||
if (y.tint) fill.fgColor.tint = parseFloat(y.tint);
|
||||
|
||||
if (y.theme && themes.themeElements && themes.themeElements.clrScheme) {
|
||||
fill.fgColor.rgb = rgb_tint(themes.themeElements.clrScheme[fill.fgColor.theme].rgb, 0); //fill.fgColor.tint || 0);
|
||||
if (opts.WTF) fill.fgColor.raw_rgb = fill.fgColor.rgb;
|
||||
fill.fgColor.rgb = rgb_tint(themes.themeElements.clrScheme[fill.fgColor.theme].rgb, fill.fgColor.tint || 0);
|
||||
if (opts.WTF) fill.fgColor.raw_rgb = rgb_tint(themes.themeElements.clrScheme[fill.fgColor.theme].rgb,0);
|
||||
}
|
||||
|
||||
/* Excel uses ARGB strings */
|
||||
|
Loading…
Reference in New Issue
Block a user