2014-06-29 18:29:45 +00:00
|
|
|
function hex2RGB(h) {
|
|
|
|
var o = h.substr(h[0]==="#"?1:0,6);
|
2017-03-13 06:46:37 +00:00
|
|
|
return [parseInt(o.substr(0,2),16),parseInt(o.substr(2,2),16),parseInt(o.substr(4,2),16)];
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
|
|
|
function rgb2Hex(rgb) {
|
2014-06-02 05:19:07 +00:00
|
|
|
for(var i=0,o=1; i!=3; ++i) o = o*256 + (rgb[i]>255?255:rgb[i]<0?0:rgb[i]);
|
|
|
|
return o.toString(16).toUpperCase().substr(1);
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-06-02 05:19:07 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
function rgb2HSL(rgb) {
|
2014-06-02 05:19:07 +00:00
|
|
|
var R = rgb[0]/255, G = rgb[1]/255, B=rgb[2]/255;
|
|
|
|
var M = Math.max(R, G, B), m = Math.min(R, G, B), C = M - m;
|
|
|
|
if(C === 0) return [0, 0, R];
|
|
|
|
|
|
|
|
var H6 = 0, S = 0, L2 = (M + m);
|
|
|
|
S = C / (L2 > 1 ? 2 - L2 : L2);
|
|
|
|
switch(M){
|
|
|
|
case R: H6 = ((G - B) / C + 6)%6; break;
|
|
|
|
case G: H6 = ((B - R) / C + 2); break;
|
|
|
|
case B: H6 = ((R - G) / C + 4); break;
|
|
|
|
}
|
|
|
|
return [H6 / 6, S, L2 / 2];
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-06-02 05:19:07 +00:00
|
|
|
|
2014-06-29 18:29:45 +00:00
|
|
|
function hsl2RGB(hsl){
|
2014-06-02 05:19:07 +00:00
|
|
|
var H = hsl[0], S = hsl[1], L = hsl[2];
|
|
|
|
var C = S * 2 * (L < 0.5 ? L : 1 - L), m = L - C/2;
|
|
|
|
var rgb = [m,m,m], h6 = 6*H;
|
|
|
|
|
|
|
|
var X;
|
|
|
|
if(S !== 0) switch(h6|0) {
|
|
|
|
case 0: case 6: X = C * h6; rgb[0] += C; rgb[1] += X; break;
|
|
|
|
case 1: X = C * (2 - h6); rgb[0] += X; rgb[1] += C; break;
|
|
|
|
case 2: X = C * (h6 - 2); rgb[1] += C; rgb[2] += X; break;
|
|
|
|
case 3: X = C * (4 - h6); rgb[1] += X; rgb[2] += C; break;
|
|
|
|
case 4: X = C * (h6 - 4); rgb[2] += C; rgb[0] += X; break;
|
|
|
|
case 5: X = C * (6 - h6); rgb[2] += X; rgb[0] += C; break;
|
|
|
|
}
|
|
|
|
for(var i = 0; i != 3; ++i) rgb[i] = Math.round(rgb[i]*255);
|
|
|
|
return rgb;
|
2014-06-29 18:29:45 +00:00
|
|
|
}
|
2014-06-02 05:19:07 +00:00
|
|
|
|
|
|
|
/* 18.8.3 bgColor tint algorithm */
|
|
|
|
function rgb_tint(hex, tint) {
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 18.3.1.13 width calculations */
|
2017-03-20 09:02:25 +00:00
|
|
|
/* [MS-OI29500] 2.1.595 Column Width & Formatting */
|
2017-03-28 22:03:03 +00:00
|
|
|
var DEF_MDW = 6, MAX_MDW = 15, MIN_MDW = 1, MDW = DEF_MDW;
|
2017-03-20 09:02:25 +00:00
|
|
|
function width2px(width) { return Math.floor(( width + (Math.round(128/MDW))/256 )* MDW ); }
|
|
|
|
function px2char(px) { return (Math.floor((px - 5)/MDW * 100 + 0.5))/100; }
|
|
|
|
function char2width(chr) { return (Math.round((chr * MDW + 5)/MDW*256))/256; }
|
|
|
|
function px2char_(px) { return (((px - 5)/MDW * 100 + 0.5))/100; }
|
|
|
|
function char2width_(chr) { return (((chr * MDW + 5)/MDW*256))/256; }
|
2014-06-02 05:19:07 +00:00
|
|
|
function cycle_width(collw) { return char2width(px2char(width2px(collw))); }
|
2017-03-20 09:02:25 +00:00
|
|
|
/* XLSX/XLSB/XLS specify width in units of MDW */
|
|
|
|
function find_mdw_colw(collw) {
|
2017-06-10 01:47:42 +00:00
|
|
|
var delta = Math.abs(collw - cycle_width(collw)), _MDW = MDW;
|
|
|
|
if(delta > 0.005) for(MDW=MIN_MDW; MDW<MAX_MDW; ++MDW) if(Math.abs(collw - cycle_width(collw)) <= delta) { delta = Math.abs(collw - cycle_width(collw)); _MDW = MDW; }
|
2017-03-20 09:02:25 +00:00
|
|
|
MDW = _MDW;
|
|
|
|
}
|
|
|
|
/* XLML specifies width in terms of pixels */
|
|
|
|
function find_mdw_wpx(wpx) {
|
|
|
|
var delta = Infinity, guess = 0, _MDW = MIN_MDW;
|
|
|
|
for(MDW=MIN_MDW; MDW<MAX_MDW; ++MDW) {
|
|
|
|
guess = char2width_(px2char_(wpx))*256;
|
|
|
|
guess = (guess) % 1;
|
|
|
|
if(guess > 0.5) guess--;
|
|
|
|
if(Math.abs(guess) < delta) { delta = Math.abs(guess); _MDW = MDW; }
|
|
|
|
}
|
|
|
|
MDW = _MDW;
|
|
|
|
}
|
|
|
|
|
|
|
|
function process_col(coll/*:ColInfo*/) {
|
|
|
|
if(coll.width) {
|
|
|
|
coll.wpx = width2px(coll.width);
|
|
|
|
coll.wch = px2char(coll.wpx);
|
|
|
|
coll.MDW = MDW;
|
|
|
|
} else if(coll.wpx) {
|
|
|
|
coll.wch = px2char(coll.wpx);
|
|
|
|
coll.width = char2width(coll.wch);
|
|
|
|
coll.MDW = MDW;
|
2017-04-28 07:28:03 +00:00
|
|
|
} else if(typeof coll.wch == 'number') {
|
|
|
|
coll.width = char2width(coll.wch);
|
|
|
|
coll.wpx = width2px(coll.width);
|
|
|
|
coll.MDW = MDW;
|
2014-06-02 05:19:07 +00:00
|
|
|
}
|
2017-03-20 09:02:25 +00:00
|
|
|
if(coll.customWidth) delete coll.customWidth;
|
2014-06-02 05:19:07 +00:00
|
|
|
}
|
2015-04-02 20:32:22 +00:00
|
|
|
|
2017-04-28 07:28:03 +00:00
|
|
|
var DEF_PPI = 96, PPI = DEF_PPI;
|
|
|
|
function px2pt(px) { return px * 96 / PPI; }
|
|
|
|
function pt2px(pt) { return pt * PPI / 96; }
|
2017-03-31 03:57:11 +00:00
|
|
|
|
2015-04-02 20:32:22 +00:00
|
|
|
/* [MS-EXSPXML3] 2.4.54 ST_enmPattern */
|
|
|
|
var XLMLPatternTypeMap = {
|
|
|
|
"None": "none",
|
|
|
|
"Solid": "solid",
|
|
|
|
"Gray50": "mediumGray",
|
|
|
|
"Gray75": "darkGray",
|
|
|
|
"Gray25": "lightGray",
|
|
|
|
"HorzStripe": "darkHorizontal",
|
|
|
|
"VertStripe": "darkVertical",
|
|
|
|
"ReverseDiagStripe": "darkDown",
|
|
|
|
"DiagStripe": "darkUp",
|
|
|
|
"DiagCross": "darkGrid",
|
|
|
|
"ThickDiagCross": "darkTrellis",
|
|
|
|
"ThinHorzStripe": "lightHorizontal",
|
|
|
|
"ThinVertStripe": "lightVertical",
|
|
|
|
"ThinReverseDiagStripe": "lightDown",
|
|
|
|
"ThinHorzCross": "lightGrid"
|
|
|
|
};
|
|
|
|
|